@platforma-sdk/ui-vue 1.44.5 → 1.44.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +33 -35
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/AgGridVue/createAgGridColDef.js +2 -3
- package/dist/AgGridVue/createAgGridColDef.js.map +1 -1
- package/dist/AgGridVue/useAgGridOptions.js +2 -3
- package/dist/AgGridVue/useAgGridOptions.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js +2 -3
- package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js +2 -3
- package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js.map +1 -1
- package/dist/components/PlAgDataTable/PlAgRowCount.vue.js +7 -8
- package/dist/components/PlAgDataTable/PlAgRowCount.vue.js.map +1 -1
- package/dist/components/PlAgDataTable/sources/focus-row.js +20 -21
- package/dist/components/PlAgDataTable/sources/focus-row.js.map +1 -1
- package/dist/components/PlAgDataTable/sources/table-source-v2.js +2 -3
- package/dist/components/PlAgDataTable/sources/table-source-v2.js.map +1 -1
- package/dist/components/PlAgDataTable/sources/table-state-v2.js +2 -3
- package/dist/components/PlAgDataTable/sources/table-state-v2.js.map +1 -1
- package/dist/components/PlAgDataTable/types.js +9 -10
- package/dist/components/PlAgDataTable/types.js.map +1 -1
- package/dist/components/PlAgRowNumCheckbox/PlAgRowNumCheckbox.vue.js +9 -10
- package/dist/components/PlAgRowNumCheckbox/PlAgRowNumCheckbox.vue.js.map +1 -1
- package/dist/components/PlAgRowNumHeader.vue.js +2 -3
- package/dist/components/PlAgRowNumHeader.vue.js.map +1 -1
- package/dist/components/PlAnnotations/components/AnnotationsSidebar.vue2.js +2 -3
- package/dist/components/PlAnnotations/components/AnnotationsSidebar.vue2.js.map +1 -1
- package/dist/components/PlAnnotations/components/DynamicForm.vue2.js +2 -3
- package/dist/components/PlAnnotations/components/DynamicForm.vue2.js.map +1 -1
- package/dist/components/PlAnnotations/components/FilterSidebar.vue2.js +2 -3
- package/dist/components/PlAnnotations/components/FilterSidebar.vue2.js.map +1 -1
- package/dist/components/PlAnnotations/components/PlAnnotationsModal.vue2.js +9 -10
- package/dist/components/PlAnnotations/components/PlAnnotationsModal.vue2.js.map +1 -1
- package/dist/components/PlMultiSequenceAlignment/PlMultiSequenceAlignment.vue2.js +2 -3
- package/dist/components/PlMultiSequenceAlignment/PlMultiSequenceAlignment.vue2.js.map +1 -1
- package/dist/components/PlMultiSequenceAlignment/Toolbar.vue2.js +2 -3
- package/dist/components/PlMultiSequenceAlignment/Toolbar.vue2.js.map +1 -1
- package/dist/components/PlMultiSequenceAlignment/data.js +8 -9
- package/dist/components/PlMultiSequenceAlignment/data.js.map +1 -1
- package/dist/components/PlTableFilters/PlTableAddFilterV2.vue.js +2 -3
- package/dist/components/PlTableFilters/PlTableAddFilterV2.vue.js.map +1 -1
- package/dist/components/PlTableFilters/PlTableFilterEntryV2.vue.js +2 -3
- package/dist/components/PlTableFilters/PlTableFilterEntryV2.vue.js.map +1 -1
- package/dist/components/PlTableFilters/PlTableFiltersV2.vue2.js +2 -3
- package/dist/components/PlTableFilters/PlTableFiltersV2.vue2.js.map +1 -1
- package/dist/components/PlTableFilters/filters-state.js +9 -10
- package/dist/components/PlTableFilters/filters-state.js.map +1 -1
- package/dist/composition/fileContent.js +0 -1
- package/dist/composition/fileContent.js.map +1 -1
- package/dist/createModel.js +2 -3
- package/dist/createModel.js.map +1 -1
- package/dist/defineApp.js +8 -9
- package/dist/defineApp.js.map +1 -1
- package/dist/internal/UpdateSerializer.js +10 -11
- package/dist/internal/UpdateSerializer.js.map +1 -1
- package/dist/internal/createAppModel.js +11 -12
- package/dist/internal/createAppModel.js.map +1 -1
- package/dist/internal/createAppV1.js +2 -3
- package/dist/internal/createAppV1.js.map +1 -1
- package/dist/internal/createAppV2.js +31 -32
- package/dist/internal/createAppV2.js.map +1 -1
- package/package.json +5 -5
- package/dist/lib/util/helpers/dist/parse.js +0 -24
- package/dist/lib/util/helpers/dist/parse.js.map +0 -1
- package/dist/lib/util/helpers/dist/test_timeouts.js +0 -9
- package/dist/lib/util/helpers/dist/test_timeouts.js.map +0 -1
package/dist/createModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createModel.js","sources":["../src/createModel.ts"],"sourcesContent":["import { reactive, computed, ref, watch, unref } from 'vue';\nimport type { ModelOptions, Model } from './types';\nimport { deepClone, isJsonEqual } from '@milaboratories/helpers';\nimport { identity, ensureError, isZodError, formatZodError } from './utils';\n\nexport function createModel<M, V = unknown>(options: ModelOptions<M, V>): Model<M> {\n const validate = options.validate ?? identity;\n\n const { autoSave } = options;\n\n const error = ref<Error | undefined>();\n\n const local = ref<{ model: M }>();\n\n const setSource = (v: M) => {\n local.value = {\n model: deepClone(v),\n };\n };\n\n watch(\n () => options.get(),\n (v) => setSource(v),\n { immediate: true },\n );\n\n const save = () => {\n options.onSave(validate(deepClone(local.value?.model)));\n };\n\n const revert = () => {\n setSource(options.get());\n error.value = undefined;\n };\n\n const setError = (cause: unknown) => {\n const err = ensureError(cause);\n if (isZodError(err)) {\n error.value = Error(formatZodError(err)); // @todo temp\n } else {\n error.value = err;\n }\n };\n\n const setValue = (v: M) => {\n error.value = undefined;\n try {\n validate(v);\n if (autoSave) {\n save();\n }\n } catch (cause: unknown) {\n setError(cause);\n }\n };\n\n const model = computed<M>({\n get: () => {\n return local.value?.model as M;\n },\n set(v) {\n setSource(v);\n setValue(v);\n },\n });\n\n watch(\n local,\n (n, o) => {\n if (n && n === o) {\n setValue(n.model);\n }\n },\n { deep: true },\n );\n\n const valid = computed(() => !error.value);\n\n const isChanged = computed(() => {\n return !isJsonEqual(options.get(), unref(local));\n });\n\n const errorString = computed(() => (error.value ? error.value.message : ''));\n\n return reactive({\n model,\n valid,\n isChanged,\n error,\n errorString,\n save,\n revert,\n setError,\n });\n}\n"],"names":["createModel","options","validate","identity","autoSave","error","ref","local","setSource","v","deepClone","watch","save","_a","revert","setError","cause","err","ensureError","isZodError","formatZodError","setValue","model","computed","n","o","valid","isChanged","isJsonEqual","unref","errorString","reactive"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createModel.js","sources":["../src/createModel.ts"],"sourcesContent":["import { reactive, computed, ref, watch, unref } from 'vue';\nimport type { ModelOptions, Model } from './types';\nimport { deepClone, isJsonEqual } from '@milaboratories/helpers';\nimport { identity, ensureError, isZodError, formatZodError } from './utils';\n\nexport function createModel<M, V = unknown>(options: ModelOptions<M, V>): Model<M> {\n const validate = options.validate ?? identity;\n\n const { autoSave } = options;\n\n const error = ref<Error | undefined>();\n\n const local = ref<{ model: M }>();\n\n const setSource = (v: M) => {\n local.value = {\n model: deepClone(v),\n };\n };\n\n watch(\n () => options.get(),\n (v) => setSource(v),\n { immediate: true },\n );\n\n const save = () => {\n options.onSave(validate(deepClone(local.value?.model)));\n };\n\n const revert = () => {\n setSource(options.get());\n error.value = undefined;\n };\n\n const setError = (cause: unknown) => {\n const err = ensureError(cause);\n if (isZodError(err)) {\n error.value = Error(formatZodError(err)); // @todo temp\n } else {\n error.value = err;\n }\n };\n\n const setValue = (v: M) => {\n error.value = undefined;\n try {\n validate(v);\n if (autoSave) {\n save();\n }\n } catch (cause: unknown) {\n setError(cause);\n }\n };\n\n const model = computed<M>({\n get: () => {\n return local.value?.model as M;\n },\n set(v) {\n setSource(v);\n setValue(v);\n },\n });\n\n watch(\n local,\n (n, o) => {\n if (n && n === o) {\n setValue(n.model);\n }\n },\n { deep: true },\n );\n\n const valid = computed(() => !error.value);\n\n const isChanged = computed(() => {\n return !isJsonEqual(options.get(), unref(local));\n });\n\n const errorString = computed(() => (error.value ? error.value.message : ''));\n\n return reactive({\n model,\n valid,\n isChanged,\n error,\n errorString,\n save,\n revert,\n setError,\n });\n}\n"],"names":["createModel","options","validate","identity","autoSave","error","ref","local","setSource","v","deepClone","watch","save","_a","revert","setError","cause","err","ensureError","isZodError","formatZodError","setValue","model","computed","n","o","valid","isChanged","isJsonEqual","unref","errorString","reactive"],"mappings":";;;AAKO,SAASA,EAA4BC,GAAuC;AACjF,QAAMC,IAAWD,EAAQ,YAAYE,GAE/B,EAAE,UAAAC,MAAaH,GAEfI,IAAQC,EAAA,GAERC,IAAQD,EAAA,GAERE,IAAY,CAACC,MAAS;AAC1B,IAAAF,EAAM,QAAQ;AAAA,MACZ,OAAOG,EAAUD,CAAC;AAAA,IAAA;AAAA,EAEtB;AAEA,EAAAE;AAAA,IACE,MAAMV,EAAQ,IAAA;AAAA,IACd,CAACQ,MAAMD,EAAUC,CAAC;AAAA,IAClB,EAAE,WAAW,GAAA;AAAA,EAAK;AAGpB,QAAMG,IAAO,MAAM;;AACjB,IAAAX,EAAQ,OAAOC,EAASQ,GAAUG,IAAAN,EAAM,UAAN,gBAAAM,EAAa,KAAK,CAAC,CAAC;AAAA,EACxD,GAEMC,IAAS,MAAM;AACnB,IAAAN,EAAUP,EAAQ,KAAK,GACvBI,EAAM,QAAQ;AAAA,EAChB,GAEMU,IAAW,CAACC,MAAmB;AACnC,UAAMC,IAAMC,EAAYF,CAAK;AAC7B,IAAIG,EAAWF,CAAG,IAChBZ,EAAM,QAAQ,MAAMe,EAAeH,CAAG,CAAC,IAEvCZ,EAAM,QAAQY;AAAA,EAElB,GAEMI,IAAW,CAACZ,MAAS;AACzB,IAAAJ,EAAM,QAAQ;AACd,QAAI;AACF,MAAAH,EAASO,CAAC,GACNL,KACFQ,EAAA;AAAA,IAEJ,SAASI,GAAgB;AACvB,MAAAD,EAASC,CAAK;AAAA,IAChB;AAAA,EACF,GAEMM,IAAQC,EAAY;AAAA,IACxB,KAAK,MAAM;;AACT,cAAOV,IAAAN,EAAM,UAAN,gBAAAM,EAAa;AAAA,IACtB;AAAA,IACA,IAAIJ,GAAG;AACL,MAAAD,EAAUC,CAAC,GACXY,EAASZ,CAAC;AAAA,IACZ;AAAA,EAAA,CACD;AAED,EAAAE;AAAA,IACEJ;AAAA,IACA,CAACiB,GAAGC,MAAM;AACR,MAAID,KAAKA,MAAMC,KACbJ,EAASG,EAAE,KAAK;AAAA,IAEpB;AAAA,IACA,EAAE,MAAM,GAAA;AAAA,EAAK;AAGf,QAAME,IAAQH,EAAS,MAAM,CAAClB,EAAM,KAAK,GAEnCsB,IAAYJ,EAAS,MAClB,CAACK,EAAY3B,EAAQ,OAAO4B,EAAMtB,CAAK,CAAC,CAChD,GAEKuB,IAAcP,EAAS,MAAOlB,EAAM,QAAQA,EAAM,MAAM,UAAU,EAAG;AAE3E,SAAO0B,EAAS;AAAA,IACd,OAAAT;AAAA,IACA,OAAAI;AAAA,IACA,WAAAC;AAAA,IACA,OAAAtB;AAAA,IACA,aAAAyB;AAAA,IACA,MAAAlB;AAAA,IACA,QAAAE;AAAA,IACA,UAAAC;AAAA,EAAA,CACD;AACH;"}
|
package/dist/defineApp.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { notEmpty as V } from "./lib/util/helpers/dist/utils.js";
|
|
2
|
-
import "./lib/util/helpers/dist/test_timeouts.js";
|
|
3
2
|
import { getPlatformaApiVersion as g, unwrapResult as k } from "@platforma-sdk/model";
|
|
4
3
|
import { inject as h, reactive as j, markRaw as f } from "vue";
|
|
5
4
|
import { createAppV1 as w } from "./internal/createAppV1.js";
|
|
6
5
|
import { createAppV2 as y } from "./internal/createAppV2.js";
|
|
7
6
|
import { activateAgGrid as O } from "./aggrid.js";
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
return h(
|
|
7
|
+
const b = Symbol("sdk-vue");
|
|
8
|
+
function q() {
|
|
9
|
+
return h(b);
|
|
11
10
|
}
|
|
12
|
-
function
|
|
11
|
+
function $(e, p, l = {}) {
|
|
13
12
|
let u;
|
|
14
13
|
O();
|
|
15
|
-
const d = e.apiVersion ?? 1, A = g(),
|
|
14
|
+
const d = e.apiVersion ?? 1, A = g(), m = async () => {
|
|
16
15
|
if (A !== d)
|
|
17
16
|
throw new Error(`Block requested API version ${A} but runtime API version is ${d}.
|
|
18
17
|
Please update the desktop app to use the latest API version.`);
|
|
@@ -56,7 +55,7 @@ function G(e, p, l = {}) {
|
|
|
56
55
|
// @todo type portability issue with Vue
|
|
57
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
57
|
install(r) {
|
|
59
|
-
r.provide(
|
|
58
|
+
r.provide(b, this), m().catch((t) => {
|
|
60
59
|
console.error("load initial state error", t), c.error = t;
|
|
61
60
|
});
|
|
62
61
|
}
|
|
@@ -64,7 +63,7 @@ function G(e, p, l = {}) {
|
|
|
64
63
|
return c;
|
|
65
64
|
}
|
|
66
65
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
$ as defineApp,
|
|
67
|
+
q as useSdkPlugin
|
|
69
68
|
};
|
|
70
69
|
//# sourceMappingURL=defineApp.js.map
|
package/dist/defineApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineApp.js","sources":["../src/defineApp.ts"],"sourcesContent":["import { notEmpty } from '@milaboratories/helpers';\nimport type { PlatformaV1, PlatformaV2 } from '@platforma-sdk/model';\nimport { getPlatformaApiVersion, unwrapResult, type BlockOutputsBase, type Platforma } from '@platforma-sdk/model';\nimport type { Component, Reactive } from 'vue';\nimport { inject, markRaw, reactive } from 'vue';\nimport { createAppV1, type BaseAppV1 } from './internal/createAppV1';\nimport { createAppV2, type BaseAppV2 } from './internal/createAppV2';\nimport type { AppSettings, ExtendSettings, Routes } from './types';\nimport { activateAgGrid } from './aggrid';\n\nconst pluginKey = Symbol('sdk-vue');\n\nexport function useSdkPlugin(): SdkPlugin {\n return inject(pluginKey)!;\n}\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: PlatformaV1<Args, Outputs, UiState, Href>,\n extendApp: (app: BaseAppV1<Args, Outputs, UiState, Href>) => Extend,\n settings?: AppSettings,\n): SdkPluginV1<Args, Outputs, UiState, Href, Extend>;\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: PlatformaV2<Args, Outputs, UiState, Href>,\n extendApp: (app: BaseAppV2<Args, Outputs, UiState, Href>) => Extend,\n settings?: AppSettings,\n): SdkPluginV2<Args, Outputs, UiState, Href, Extend>;\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: Platforma<Args, Outputs, UiState, Href>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n extendApp: (app: any) => Extend,\n settings: AppSettings = {},\n): SdkPlugin<Args, Outputs, UiState, Href, Extend> {\n let app: undefined | AppV1<Args, Outputs, UiState, Href, Extend> | AppV2<Args, Outputs, UiState, Href, Extend> = undefined;\n\n activateAgGrid();\n\n const runtimeApiVersion = platforma.apiVersion ?? 1; // undefined means 1 (backward compatibility)\n\n const blockRequestedApiVersion = getPlatformaApiVersion();\n\n const loadApp = async () => {\n if (blockRequestedApiVersion !== runtimeApiVersion) {\n throw new Error(`Block requested API version ${blockRequestedApiVersion} but runtime API version is ${runtimeApiVersion}.\n Please update the desktop app to use the latest API version.`);\n }\n\n if (platforma.apiVersion === undefined || platforma.apiVersion === 1) {\n await platforma\n .loadBlockState()\n .then((state) => {\n plugin.loaded = true;\n const baseApp = createAppV1<Args, Outputs, UiState, Href>(state, platforma, settings);\n\n const localState = extendApp(baseApp);\n\n const routes = Object.fromEntries(\n Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {\n const c = typeof component === 'function' ? component() : component;\n return [href, markRaw(c as Component)];\n }),\n );\n\n app = Object.assign(baseApp, {\n ...localState,\n getRoute(href: Href): Component | undefined {\n return routes[href];\n },\n } as unknown as AppV1<Args, Outputs, UiState, Href, Extend>);\n });\n } else if (platforma.apiVersion === 2) {\n await platforma\n .loadBlockState()\n .then((stateOrError) => {\n const state = unwrapResult(stateOrError);\n plugin.loaded = true;\n const baseApp = createAppV2<Args, Outputs, UiState, Href>(state, platforma, settings);\n\n const localState = extendApp(baseApp);\n\n const routes = Object.fromEntries(\n Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {\n const c = typeof component === 'function' ? component() : component;\n return [href, markRaw(c as Component)];\n }),\n );\n\n app = Object.assign(baseApp, {\n ...localState,\n getRoute(href: Href): Component | undefined {\n return routes[href];\n },\n } as unknown as AppV2<Args, Outputs, UiState, Href, Extend>);\n });\n }\n };\n\n const plugin = reactive({\n loaded: false,\n error: undefined as unknown,\n // Href to get typed query parameters for a specific route\n useApp<PageHref extends Href = Href>() {\n return notEmpty(app, 'App is not loaded') as App<Args, Outputs, UiState, PageHref, Extend>;\n },\n // @todo type portability issue with Vue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n install(app: any) {\n app.provide(pluginKey, this);\n loadApp().catch((err) => {\n console.error('load initial state error', err);\n plugin.error = err;\n });\n },\n });\n\n return plugin as SdkPlugin<Args, Outputs, UiState, Href, Extend>;\n}\n\nexport type AppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = (BaseAppV1<Args, Outputs, UiState, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };\n\nexport type AppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = (BaseAppV2<Args, Outputs, UiState, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };\n\nexport type App<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = AppV1<Args, Outputs, UiState, Href, Local> | AppV2<Args, Outputs, UiState, Href, Local>;\n\nexport type SdkPluginV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = {\n loaded: boolean;\n error: unknown;\n useApp<PageHref extends Href = Href>(): AppV1<Args, Outputs, UiState, PageHref, Local>;\n install(app: unknown): void;\n};\n\nexport type SdkPluginV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = {\n loaded: boolean;\n error: unknown;\n useApp<PageHref extends Href = Href>(): AppV2<Args, Outputs, UiState, PageHref, Local>;\n install(app: unknown): void;\n};\n\nexport type SdkPlugin<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = SdkPluginV1<Args, Outputs, UiState, Href, Local> | SdkPluginV2<Args, Outputs, UiState, Href, Local>;\n"],"names":["pluginKey","useSdkPlugin","inject","defineApp","platforma","extendApp","settings","app","activateAgGrid","runtimeApiVersion","blockRequestedApiVersion","getPlatformaApiVersion","loadApp","state","plugin","baseApp","createAppV1","localState","routes","href","component","c","markRaw","stateOrError","unwrapResult","createAppV2","reactive","notEmpty","err"],"mappings":"
|
|
1
|
+
{"version":3,"file":"defineApp.js","sources":["../src/defineApp.ts"],"sourcesContent":["import { notEmpty } from '@milaboratories/helpers';\nimport type { PlatformaV1, PlatformaV2 } from '@platforma-sdk/model';\nimport { getPlatformaApiVersion, unwrapResult, type BlockOutputsBase, type Platforma } from '@platforma-sdk/model';\nimport type { Component, Reactive } from 'vue';\nimport { inject, markRaw, reactive } from 'vue';\nimport { createAppV1, type BaseAppV1 } from './internal/createAppV1';\nimport { createAppV2, type BaseAppV2 } from './internal/createAppV2';\nimport type { AppSettings, ExtendSettings, Routes } from './types';\nimport { activateAgGrid } from './aggrid';\n\nconst pluginKey = Symbol('sdk-vue');\n\nexport function useSdkPlugin(): SdkPlugin {\n return inject(pluginKey)!;\n}\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: PlatformaV1<Args, Outputs, UiState, Href>,\n extendApp: (app: BaseAppV1<Args, Outputs, UiState, Href>) => Extend,\n settings?: AppSettings,\n): SdkPluginV1<Args, Outputs, UiState, Href, Extend>;\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: PlatformaV2<Args, Outputs, UiState, Href>,\n extendApp: (app: BaseAppV2<Args, Outputs, UiState, Href>) => Extend,\n settings?: AppSettings,\n): SdkPluginV2<Args, Outputs, UiState, Href, Extend>;\n\nexport function defineApp<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Extend extends ExtendSettings<Href> = ExtendSettings<Href>,\n>(\n platforma: Platforma<Args, Outputs, UiState, Href>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n extendApp: (app: any) => Extend,\n settings: AppSettings = {},\n): SdkPlugin<Args, Outputs, UiState, Href, Extend> {\n let app: undefined | AppV1<Args, Outputs, UiState, Href, Extend> | AppV2<Args, Outputs, UiState, Href, Extend> = undefined;\n\n activateAgGrid();\n\n const runtimeApiVersion = platforma.apiVersion ?? 1; // undefined means 1 (backward compatibility)\n\n const blockRequestedApiVersion = getPlatformaApiVersion();\n\n const loadApp = async () => {\n if (blockRequestedApiVersion !== runtimeApiVersion) {\n throw new Error(`Block requested API version ${blockRequestedApiVersion} but runtime API version is ${runtimeApiVersion}.\n Please update the desktop app to use the latest API version.`);\n }\n\n if (platforma.apiVersion === undefined || platforma.apiVersion === 1) {\n await platforma\n .loadBlockState()\n .then((state) => {\n plugin.loaded = true;\n const baseApp = createAppV1<Args, Outputs, UiState, Href>(state, platforma, settings);\n\n const localState = extendApp(baseApp);\n\n const routes = Object.fromEntries(\n Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {\n const c = typeof component === 'function' ? component() : component;\n return [href, markRaw(c as Component)];\n }),\n );\n\n app = Object.assign(baseApp, {\n ...localState,\n getRoute(href: Href): Component | undefined {\n return routes[href];\n },\n } as unknown as AppV1<Args, Outputs, UiState, Href, Extend>);\n });\n } else if (platforma.apiVersion === 2) {\n await platforma\n .loadBlockState()\n .then((stateOrError) => {\n const state = unwrapResult(stateOrError);\n plugin.loaded = true;\n const baseApp = createAppV2<Args, Outputs, UiState, Href>(state, platforma, settings);\n\n const localState = extendApp(baseApp);\n\n const routes = Object.fromEntries(\n Object.entries(localState.routes as Routes<Href>).map(([href, component]) => {\n const c = typeof component === 'function' ? component() : component;\n return [href, markRaw(c as Component)];\n }),\n );\n\n app = Object.assign(baseApp, {\n ...localState,\n getRoute(href: Href): Component | undefined {\n return routes[href];\n },\n } as unknown as AppV2<Args, Outputs, UiState, Href, Extend>);\n });\n }\n };\n\n const plugin = reactive({\n loaded: false,\n error: undefined as unknown,\n // Href to get typed query parameters for a specific route\n useApp<PageHref extends Href = Href>() {\n return notEmpty(app, 'App is not loaded') as App<Args, Outputs, UiState, PageHref, Extend>;\n },\n // @todo type portability issue with Vue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n install(app: any) {\n app.provide(pluginKey, this);\n loadApp().catch((err) => {\n console.error('load initial state error', err);\n plugin.error = err;\n });\n },\n });\n\n return plugin as SdkPlugin<Args, Outputs, UiState, Href, Extend>;\n}\n\nexport type AppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = (BaseAppV1<Args, Outputs, UiState, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };\n\nexport type AppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = (BaseAppV2<Args, Outputs, UiState, Href>) & Reactive<Omit<Local, 'routes'>> & { getRoute(href: Href): Component | undefined };\n\nexport type App<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = AppV1<Args, Outputs, UiState, Href, Local> | AppV2<Args, Outputs, UiState, Href, Local>;\n\nexport type SdkPluginV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = {\n loaded: boolean;\n error: unknown;\n useApp<PageHref extends Href = Href>(): AppV1<Args, Outputs, UiState, PageHref, Local>;\n install(app: unknown): void;\n};\n\nexport type SdkPluginV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = {\n loaded: boolean;\n error: unknown;\n useApp<PageHref extends Href = Href>(): AppV2<Args, Outputs, UiState, PageHref, Local>;\n install(app: unknown): void;\n};\n\nexport type SdkPlugin<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n Local extends ExtendSettings<Href> = ExtendSettings<Href>,\n> = SdkPluginV1<Args, Outputs, UiState, Href, Local> | SdkPluginV2<Args, Outputs, UiState, Href, Local>;\n"],"names":["pluginKey","useSdkPlugin","inject","defineApp","platforma","extendApp","settings","app","activateAgGrid","runtimeApiVersion","blockRequestedApiVersion","getPlatformaApiVersion","loadApp","state","plugin","baseApp","createAppV1","localState","routes","href","component","c","markRaw","stateOrError","unwrapResult","createAppV2","reactive","notEmpty","err"],"mappings":";;;;;;AAUA,MAAMA,IAAY,OAAO,SAAS;AAE3B,SAASC,IAA0B;AACxC,SAAOC,EAAOF,CAAS;AACzB;AA0BO,SAASG,EAOdC,GAEAC,GACAC,IAAwB,CAAA,GACyB;AACjD,MAAIC;AAEJ,EAAAC,EAAA;AAEA,QAAMC,IAAoBL,EAAU,cAAc,GAE5CM,IAA2BC,EAAA,GAE3BC,IAAU,YAAY;AAC1B,QAAIF,MAA6BD;AAC/B,YAAM,IAAI,MAAM,+BAA+BC,CAAwB,+BAA+BD,CAAiB;AAAA,mEAC1D;AAG/D,IAAIL,EAAU,eAAe,UAAaA,EAAU,eAAe,IACjE,MAAMA,EACH,eAAA,EACA,KAAK,CAACS,MAAU;AACf,MAAAC,EAAO,SAAS;AAChB,YAAMC,IAAUC,EAA0CH,GAAOT,GAAWE,CAAQ,GAE9EW,IAAaZ,EAAUU,CAAO,GAE9BG,IAAS,OAAO;AAAA,QACpB,OAAO,QAAQD,EAAW,MAAsB,EAAE,IAAI,CAAC,CAACE,GAAMC,CAAS,MAAM;AAC3E,gBAAMC,IAAI,OAAOD,KAAc,aAAaA,MAAcA;AAC1D,iBAAO,CAACD,GAAMG,EAAQD,CAAc,CAAC;AAAA,QACvC,CAAC;AAAA,MAAA;AAGH,MAAAd,IAAM,OAAO,OAAOQ,GAAS;AAAA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
|
var i = (e, t, r) => c(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { delay as a } from "../lib/util/helpers/dist/utils.js";
|
|
5
|
-
import "../lib/util/helpers/dist/test_timeouts.js";
|
|
6
5
|
import { hasAbortError as h } from "@platforma-sdk/model";
|
|
7
|
-
class
|
|
6
|
+
class y {
|
|
8
7
|
constructor(t = {}) {
|
|
9
8
|
i(this, "ongoingRun", Promise.resolve(!0));
|
|
10
9
|
i(this, "ongoingOperation", Promise.resolve());
|
|
@@ -19,16 +18,16 @@ class d {
|
|
|
19
18
|
while (!t);
|
|
20
19
|
}
|
|
21
20
|
async retry(t, r) {
|
|
22
|
-
const
|
|
21
|
+
const o = {
|
|
23
22
|
i: 0
|
|
24
23
|
};
|
|
25
24
|
for (; ; )
|
|
26
25
|
try {
|
|
27
|
-
return
|
|
28
|
-
} catch (
|
|
29
|
-
const { delayMs: s } = r(
|
|
30
|
-
if (h(
|
|
31
|
-
throw
|
|
26
|
+
return o.i++, await t();
|
|
27
|
+
} catch (n) {
|
|
28
|
+
const { delayMs: s } = r(n, o);
|
|
29
|
+
if (h(n))
|
|
30
|
+
throw n;
|
|
32
31
|
await a(s);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -52,14 +51,14 @@ class d {
|
|
|
52
51
|
}
|
|
53
52
|
if (this.counter !== r)
|
|
54
53
|
return !1;
|
|
55
|
-
const
|
|
54
|
+
const o = this.retry(() => t(), (n) => (console.warn("UpdateSerializer.run error, retrying...", n), {
|
|
56
55
|
delayMs: 100
|
|
57
56
|
// TODO: flexible delay
|
|
58
57
|
}));
|
|
59
|
-
return this.ongoingOperation =
|
|
58
|
+
return this.ongoingOperation = o, await o, !0;
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
export {
|
|
63
|
-
|
|
62
|
+
y as UpdateSerializer
|
|
64
63
|
};
|
|
65
64
|
//# sourceMappingURL=UpdateSerializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateSerializer.js","sources":["../../src/internal/UpdateSerializer.ts"],"sourcesContent":["import { delay } from '@milaboratories/helpers';\nimport { hasAbortError } from '@platforma-sdk/model';\n\nexport type RetryState = {\n i: number;\n};\n\nexport type OnNext = (e: unknown, state: RetryState) => { delayMs: number };\n\nexport class UpdateSerializer {\n private ongoingRun: Promise<boolean> = Promise.resolve(true);\n private ongoingOperation: Promise<void> = Promise.resolve();\n private counter = 0;\n\n constructor(private readonly options: {\n debounceSpan?: number;\n } = {}) {}\n\n async allSettled(): Promise<void> {\n await delay(this.options.debounceSpan ?? 0);\n let completed = false;\n do {\n await delay(0);\n completed = await this.ongoingRun.then(() => {\n return true;\n }).catch((e) => {\n console.log('ongoingRun error', e);\n return false;\n });\n } while (!completed);\n }\n\n async retry<T>(\n op: () => Promise<T>,\n onNext: OnNext,\n ): Promise<T> {\n const state: RetryState = {\n i: 0,\n };\n\n while (true) {\n try {\n state.i++;\n return await op();\n } catch (e: unknown) {\n const { delayMs } = onNext(e, state);\n\n if (hasAbortError(e)) {\n throw e;\n }\n\n await delay(delayMs);\n }\n }\n }\n\n /**\n * @returns true if operation succeeded, or false if operation was evicted by a more recent call\n */\n public async run(op: () => Promise<void>): Promise<boolean> {\n return this.ongoingRun = this._run(op);\n }\n\n /**\n * @returns true if operation succeeded, or false if operation was evicted by a more recent call\n */\n private async _run(op: () => Promise<void>): Promise<boolean> {\n // assigning a sequential update id to the call\n this.counter++;\n const myId = this.counter;\n\n if (this.options.debounceSpan) {\n await delay(this.options.debounceSpan);\n }\n\n // checking that this update is still the most recent\n if (this.counter !== myId) {\n // operation was canceled, because another operation was queued\n // after we started waiting for previous operation to finish\n return false;\n }\n\n // awaiting previous operation to finish\n try {\n await this.ongoingOperation;\n } catch (_err: unknown) {\n // ignoring the error here, original caller will receive any rejections\n }\n\n // checking that this update is still the most recent\n if (this.counter !== myId) {\n // operation was canceled, because another operation was queued\n // after we started waiting for previous operation to finish\n return false;\n }\n\n // asynchronously starting the operation\n const opPromise = this.retry(() => op(), (e) => {\n console.warn('UpdateSerializer.run error, retrying...', e);\n return {\n delayMs: 100, // TODO: flexible delay\n };\n });\n // publishing the promise for the next operation to await\n this.ongoingOperation = opPromise;\n // actually awaiting for the operation result, any rejections will be thrown here\n await opPromise;\n\n // operation was successfully called\n return true;\n }\n}\n"],"names":["UpdateSerializer","options","__publicField","delay","completed","e","op","onNext","state","delayMs","hasAbortError","myId","opPromise"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UpdateSerializer.js","sources":["../../src/internal/UpdateSerializer.ts"],"sourcesContent":["import { delay } from '@milaboratories/helpers';\nimport { hasAbortError } from '@platforma-sdk/model';\n\nexport type RetryState = {\n i: number;\n};\n\nexport type OnNext = (e: unknown, state: RetryState) => { delayMs: number };\n\nexport class UpdateSerializer {\n private ongoingRun: Promise<boolean> = Promise.resolve(true);\n private ongoingOperation: Promise<void> = Promise.resolve();\n private counter = 0;\n\n constructor(private readonly options: {\n debounceSpan?: number;\n } = {}) {}\n\n async allSettled(): Promise<void> {\n await delay(this.options.debounceSpan ?? 0);\n let completed = false;\n do {\n await delay(0);\n completed = await this.ongoingRun.then(() => {\n return true;\n }).catch((e) => {\n console.log('ongoingRun error', e);\n return false;\n });\n } while (!completed);\n }\n\n async retry<T>(\n op: () => Promise<T>,\n onNext: OnNext,\n ): Promise<T> {\n const state: RetryState = {\n i: 0,\n };\n\n while (true) {\n try {\n state.i++;\n return await op();\n } catch (e: unknown) {\n const { delayMs } = onNext(e, state);\n\n if (hasAbortError(e)) {\n throw e;\n }\n\n await delay(delayMs);\n }\n }\n }\n\n /**\n * @returns true if operation succeeded, or false if operation was evicted by a more recent call\n */\n public async run(op: () => Promise<void>): Promise<boolean> {\n return this.ongoingRun = this._run(op);\n }\n\n /**\n * @returns true if operation succeeded, or false if operation was evicted by a more recent call\n */\n private async _run(op: () => Promise<void>): Promise<boolean> {\n // assigning a sequential update id to the call\n this.counter++;\n const myId = this.counter;\n\n if (this.options.debounceSpan) {\n await delay(this.options.debounceSpan);\n }\n\n // checking that this update is still the most recent\n if (this.counter !== myId) {\n // operation was canceled, because another operation was queued\n // after we started waiting for previous operation to finish\n return false;\n }\n\n // awaiting previous operation to finish\n try {\n await this.ongoingOperation;\n } catch (_err: unknown) {\n // ignoring the error here, original caller will receive any rejections\n }\n\n // checking that this update is still the most recent\n if (this.counter !== myId) {\n // operation was canceled, because another operation was queued\n // after we started waiting for previous operation to finish\n return false;\n }\n\n // asynchronously starting the operation\n const opPromise = this.retry(() => op(), (e) => {\n console.warn('UpdateSerializer.run error, retrying...', e);\n return {\n delayMs: 100, // TODO: flexible delay\n };\n });\n // publishing the promise for the next operation to await\n this.ongoingOperation = opPromise;\n // actually awaiting for the operation result, any rejections will be thrown here\n await opPromise;\n\n // operation was successfully called\n return true;\n }\n}\n"],"names":["UpdateSerializer","options","__publicField","delay","completed","e","op","onNext","state","delayMs","hasAbortError","myId","opPromise"],"mappings":";;;;;AASO,MAAMA,EAAiB;AAAA,EAK5B,YAA6BC,IAEzB,IAAI;AANA,IAAAC,EAAA,oBAA+B,QAAQ,QAAQ,EAAI;AACnD,IAAAA,EAAA,0BAAkC,QAAQ,QAAA;AAC1C,IAAAA,EAAA,iBAAU;AAEW,SAAA,UAAAD;AAAA,EAEpB;AAAA,EAET,MAAM,aAA4B;AAChC,UAAME,EAAM,KAAK,QAAQ,gBAAgB,CAAC;AAC1C,QAAIC,IAAY;AAChB;AACE,YAAMD,EAAM,CAAC,GACbC,IAAY,MAAM,KAAK,WAAW,KAAK,MAC9B,EACR,EAAE,MAAM,CAACC,OACR,QAAQ,IAAI,oBAAoBA,CAAC,GAC1B,GACR;AAAA,WACM,CAACD;AAAA,EACZ;AAAA,EAEA,MAAM,MACJE,GACAC,GACY;AACZ,UAAMC,IAAoB;AAAA,MACxB,GAAG;AAAA,IAAA;AAGL;AACE,UAAI;AACF,eAAAA,EAAM,KACC,MAAMF,EAAA;AAAA,MACf,SAASD,GAAY;AACnB,cAAM,EAAE,SAAAI,EAAA,IAAYF,EAAOF,GAAGG,CAAK;AAEnC,YAAIE,EAAcL,CAAC;AACjB,gBAAMA;AAGR,cAAMF,EAAMM,CAAO;AAAA,MACrB;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,IAAIH,GAA2C;AAC1D,WAAO,KAAK,aAAa,KAAK,KAAKA,CAAE;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,KAAKA,GAA2C;AAE5D,SAAK;AACL,UAAMK,IAAO,KAAK;AAOlB,QALI,KAAK,QAAQ,gBACf,MAAMR,EAAM,KAAK,QAAQ,YAAY,GAInC,KAAK,YAAYQ;AAGnB,aAAO;AAIT,QAAI;AACF,YAAM,KAAK;AAAA,IACb,QAAwB;AAAA,IAExB;AAGA,QAAI,KAAK,YAAYA;AAGnB,aAAO;AAIT,UAAMC,IAAY,KAAK,MAAM,MAAMN,EAAA,GAAM,CAACD,OACxC,QAAQ,KAAK,2CAA2CA,CAAC,GAClD;AAAA,MACL,SAAS;AAAA;AAAA,IAAA,EAEZ;AAED,gBAAK,mBAAmBO,GAExB,MAAMA,GAGC;AAAA,EACT;AACF;"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { ref as d, watch as m, computed as s, unref as w, reactive as Z } from "vue";
|
|
2
2
|
import { isJsonEqual as _, deepClone as g } from "../lib/util/helpers/dist/objects.js";
|
|
3
|
-
import "../lib/util/helpers/dist/test_timeouts.js";
|
|
4
3
|
import { identity as j, isZodError as q, ensureError as x, formatZodError as A } from "../utils.js";
|
|
5
|
-
function
|
|
6
|
-
const c =
|
|
7
|
-
|
|
4
|
+
function k(a, f, J) {
|
|
5
|
+
const c = a.validate ?? j, { autoSave: E } = a, t = d(), o = d(), n = (e) => {
|
|
6
|
+
o.value = {
|
|
8
7
|
model: Object.assign(g(e), f ?? {}),
|
|
9
8
|
stage: Symbol()
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
11
|
m(
|
|
13
|
-
() =>
|
|
12
|
+
() => a.get(),
|
|
14
13
|
(e) => n(e),
|
|
15
14
|
{ immediate: !0 }
|
|
16
15
|
);
|
|
17
16
|
const v = () => {
|
|
18
17
|
var e;
|
|
19
|
-
return
|
|
18
|
+
return a.onSave(c(g((e = o.value) == null ? void 0 : e.model)));
|
|
20
19
|
}, p = () => {
|
|
21
|
-
n(
|
|
20
|
+
n(a.get()), t.value = void 0;
|
|
22
21
|
}, i = (e) => {
|
|
23
22
|
const r = x(e);
|
|
24
23
|
q(r) ? t.value = Error(A(r)) : t.value = r;
|
|
@@ -32,7 +31,7 @@ function z(o, f, J) {
|
|
|
32
31
|
}, l = s({
|
|
33
32
|
get: () => {
|
|
34
33
|
var e;
|
|
35
|
-
return (e =
|
|
34
|
+
return (e = o.value) == null ? void 0 : e.model;
|
|
36
35
|
},
|
|
37
36
|
set() {
|
|
38
37
|
throw Error("Cannot replace base model");
|
|
@@ -41,7 +40,7 @@ function z(o, f, J) {
|
|
|
41
40
|
m(
|
|
42
41
|
[() => ({ args: l.value.args, ui: l.value.ui }), () => {
|
|
43
42
|
var e;
|
|
44
|
-
return (e =
|
|
43
|
+
return (e = o.value) == null ? void 0 : e.stage;
|
|
45
44
|
}],
|
|
46
45
|
([e, r], [u, C]) => {
|
|
47
46
|
r === C && S(e);
|
|
@@ -50,8 +49,8 @@ function z(o, f, J) {
|
|
|
50
49
|
);
|
|
51
50
|
const h = s(() => !t.value), b = s(() => {
|
|
52
51
|
var u;
|
|
53
|
-
const { args: e, ui: r } = ((u = w(
|
|
54
|
-
return !_(
|
|
52
|
+
const { args: e, ui: r } = ((u = w(o)) == null ? void 0 : u.model) ?? {};
|
|
53
|
+
return !_(a.get(), { args: e, ui: r });
|
|
55
54
|
}), y = s(() => t.value ? t.value.message : "");
|
|
56
55
|
return Z({
|
|
57
56
|
model: l,
|
|
@@ -65,6 +64,6 @@ function z(o, f, J) {
|
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
66
|
export {
|
|
68
|
-
|
|
67
|
+
k as createAppModel
|
|
69
68
|
};
|
|
70
69
|
//# sourceMappingURL=createAppModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppModel.js","sources":["../../src/internal/createAppModel.ts"],"sourcesContent":["import { reactive, computed, ref, watch, unref, type ComputedRef, type UnwrapNestedRefs } from 'vue';\nimport type { ModelOptions, Model, AppSettings } from '../types';\nimport { deepClone, isJsonEqual } from '@milaboratories/helpers';\nimport { identity, ensureError, isZodError, formatZodError } from '../utils';\n\nexport function createAppModel<\n M extends { args: unknown; ui: unknown },\n V = unknown,\n E extends Record<string, ComputedRef<unknown>> = Record<string, ComputedRef<unknown>>,\n>(options: ModelOptions<M, V>, extended: E, _settings: AppSettings): Model<M & UnwrapNestedRefs<E>> {\n type R = M & UnwrapNestedRefs<E>;\n\n const validate = options.validate ?? identity;\n\n const { autoSave } = options;\n\n const error = ref<Error | undefined>();\n\n const local = ref<{ model: R; readonly stage: symbol }>();\n\n const setSource = (v: M) => {\n local.value = {\n model: Object.assign(deepClone(v), extended ?? {}) as R,\n stage: Symbol(),\n };\n };\n\n watch(\n () => options.get(),\n (v) => setSource(v),\n { immediate: true },\n );\n\n const save = () => options.onSave(validate(deepClone(local.value?.model)));\n\n const revert = () => {\n setSource(options.get());\n error.value = undefined;\n };\n\n const setError = (cause: unknown) => {\n const err = ensureError(cause);\n if (isZodError(err)) {\n error.value = Error(formatZodError(err)); // @todo temp\n } else {\n error.value = err;\n }\n };\n\n const setValue = (v: M) => {\n error.value = undefined;\n try {\n validate(v);\n if (autoSave) {\n save();\n }\n } catch (cause: unknown) {\n setError(cause);\n }\n };\n\n const model = computed<R>({\n get: () => {\n return local.value?.model as R;\n },\n set() {\n throw Error('Cannot replace base model');\n },\n });\n\n watch(\n [() => ({ args: model.value.args, ui: model.value.ui }), () => local.value?.stage],\n ([n, newStage], [_, oldStage]) => {\n if (newStage === oldStage) {\n setValue(n as M);\n }\n },\n { deep: true },\n );\n\n const valid = computed(() => !error.value);\n\n const isChanged = computed(() => {\n const { args, ui } = unref(local)?.model ?? {};\n return !isJsonEqual(options.get(), { args, ui });\n });\n\n const errorString = computed(() => (error.value ? error.value.message : ''));\n\n return reactive({\n model,\n valid,\n isChanged,\n error,\n errorString,\n save,\n revert,\n setError,\n });\n}\n"],"names":["createAppModel","options","extended","_settings","validate","identity","autoSave","error","ref","local","setSource","v","deepClone","watch","save","_a","revert","setError","cause","err","ensureError","isZodError","formatZodError","setValue","model","computed","n","newStage","_","oldStage","valid","isChanged","args","ui","unref","isJsonEqual","errorString","reactive"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createAppModel.js","sources":["../../src/internal/createAppModel.ts"],"sourcesContent":["import { reactive, computed, ref, watch, unref, type ComputedRef, type UnwrapNestedRefs } from 'vue';\nimport type { ModelOptions, Model, AppSettings } from '../types';\nimport { deepClone, isJsonEqual } from '@milaboratories/helpers';\nimport { identity, ensureError, isZodError, formatZodError } from '../utils';\n\nexport function createAppModel<\n M extends { args: unknown; ui: unknown },\n V = unknown,\n E extends Record<string, ComputedRef<unknown>> = Record<string, ComputedRef<unknown>>,\n>(options: ModelOptions<M, V>, extended: E, _settings: AppSettings): Model<M & UnwrapNestedRefs<E>> {\n type R = M & UnwrapNestedRefs<E>;\n\n const validate = options.validate ?? identity;\n\n const { autoSave } = options;\n\n const error = ref<Error | undefined>();\n\n const local = ref<{ model: R; readonly stage: symbol }>();\n\n const setSource = (v: M) => {\n local.value = {\n model: Object.assign(deepClone(v), extended ?? {}) as R,\n stage: Symbol(),\n };\n };\n\n watch(\n () => options.get(),\n (v) => setSource(v),\n { immediate: true },\n );\n\n const save = () => options.onSave(validate(deepClone(local.value?.model)));\n\n const revert = () => {\n setSource(options.get());\n error.value = undefined;\n };\n\n const setError = (cause: unknown) => {\n const err = ensureError(cause);\n if (isZodError(err)) {\n error.value = Error(formatZodError(err)); // @todo temp\n } else {\n error.value = err;\n }\n };\n\n const setValue = (v: M) => {\n error.value = undefined;\n try {\n validate(v);\n if (autoSave) {\n save();\n }\n } catch (cause: unknown) {\n setError(cause);\n }\n };\n\n const model = computed<R>({\n get: () => {\n return local.value?.model as R;\n },\n set() {\n throw Error('Cannot replace base model');\n },\n });\n\n watch(\n [() => ({ args: model.value.args, ui: model.value.ui }), () => local.value?.stage],\n ([n, newStage], [_, oldStage]) => {\n if (newStage === oldStage) {\n setValue(n as M);\n }\n },\n { deep: true },\n );\n\n const valid = computed(() => !error.value);\n\n const isChanged = computed(() => {\n const { args, ui } = unref(local)?.model ?? {};\n return !isJsonEqual(options.get(), { args, ui });\n });\n\n const errorString = computed(() => (error.value ? error.value.message : ''));\n\n return reactive({\n model,\n valid,\n isChanged,\n error,\n errorString,\n save,\n revert,\n setError,\n });\n}\n"],"names":["createAppModel","options","extended","_settings","validate","identity","autoSave","error","ref","local","setSource","v","deepClone","watch","save","_a","revert","setError","cause","err","ensureError","isZodError","formatZodError","setValue","model","computed","n","newStage","_","oldStage","valid","isChanged","args","ui","unref","isJsonEqual","errorString","reactive"],"mappings":";;;AAKO,SAASA,EAIdC,GAA6BC,GAAaC,GAAwD;AAGlG,QAAMC,IAAWH,EAAQ,YAAYI,GAE/B,EAAE,UAAAC,MAAaL,GAEfM,IAAQC,EAAA,GAERC,IAAQD,EAAA,GAERE,IAAY,CAACC,MAAS;AAC1B,IAAAF,EAAM,QAAQ;AAAA,MACZ,OAAO,OAAO,OAAOG,EAAUD,CAAC,GAAGT,KAAY,EAAE;AAAA,MACjD,OAAO,OAAA;AAAA,IAAO;AAAA,EAElB;AAEA,EAAAW;AAAA,IACE,MAAMZ,EAAQ,IAAA;AAAA,IACd,CAACU,MAAMD,EAAUC,CAAC;AAAA,IAClB,EAAE,WAAW,GAAA;AAAA,EAAK;AAGpB,QAAMG,IAAO;;AAAM,WAAAb,EAAQ,OAAOG,EAASQ,GAAUG,IAAAN,EAAM,UAAN,gBAAAM,EAAa,KAAK,CAAC,CAAC;AAAA,KAEnEC,IAAS,MAAM;AACnB,IAAAN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AAM,QAAQA,EAAM,MAAM,UAAU,EAAG;AAE3E,SAAO8B,EAAS;AAAA,IACd,OAAAb;AAAA,IACA,OAAAM;AAAA,IACA,WAAAC;AAAA,IACA,OAAAxB;AAAA,IACA,aAAA6B;AAAA,IACA,MAAAtB;AAAA,IACA,QAAAE;AAAA,IACA,UAAAC;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { tap as M } from "../lib/util/helpers/dist/utils.js";
|
|
2
2
|
import { isJsonEqual as n, deepClone as v } from "../lib/util/helpers/dist/objects.js";
|
|
3
|
-
import "../lib/util/helpers/dist/test_timeouts.js";
|
|
4
3
|
import { reactive as f, nextTick as h, computed as s, watch as E } from "vue";
|
|
5
4
|
import { createModel as m } from "../createModel.js";
|
|
6
5
|
import { createAppModel as x } from "./createAppModel.js";
|
|
7
6
|
import { parseQuery as N } from "../urls.js";
|
|
8
7
|
import { MultiError as q, unwrapValueOrErrors as T } from "../utils.js";
|
|
9
8
|
import { useDebounceFn as S } from "@vueuse/core";
|
|
10
|
-
function
|
|
9
|
+
function D(i, a, g) {
|
|
11
10
|
const c = (e, ...t) => {
|
|
12
11
|
g.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", ...t);
|
|
13
12
|
}, r = f({
|
|
@@ -165,6 +164,6 @@ function G(i, a, g) {
|
|
|
165
164
|
return f(Object.assign(y, w, B));
|
|
166
165
|
}
|
|
167
166
|
export {
|
|
168
|
-
|
|
167
|
+
D as createAppV1
|
|
169
168
|
};
|
|
170
169
|
//# sourceMappingURL=createAppV1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppV1.js","sources":["../../src/internal/createAppV1.ts"],"sourcesContent":["import { deepClone, isJsonEqual, tap } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV1 } from '@platforma-sdk/model';\nimport { reactive, nextTick, computed, watch } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OptionalResult, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { createAppModel } from './createAppModel';\nimport { parseQuery } from '../urls';\nimport { MultiError, unwrapValueOrErrors } from '../utils';\nimport { useDebounceFn } from '@vueuse/core';\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 createAppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: BlockState<Args, Outputs, UiState, Href>,\n platforma: PlatformaV1<Args, Outputs, UiState, Href>,\n settings: AppSettings,\n) {\n type AppModel = {\n args: Args;\n ui: UiState;\n };\n\n const log = (msg: string, ...rest: unknown[]) => {\n if (settings.debug) {\n console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', ...rest);\n }\n };\n\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = reactive({\n args: Object.freeze(state.args),\n outputs: Object.freeze(state.outputs),\n ui: Object.freeze(state.ui),\n navigationState: Object.freeze(state.navigationState) as NavigationState<Href>,\n }) as {\n args: Readonly<Args>;\n outputs: Partial<Readonly<Outputs>>;\n ui: Readonly<UiState>;\n navigationState: Readonly<NavigationState<Href>>;\n };\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const maxWait = tap(settings.debounceMaxWait ?? 0, (v) => v < 20_000 ? 20_000 : v < debounceSpan ? debounceSpan * 100 : v);\n\n const setBlockArgs = useDebounceFn((args: Args) => {\n if (!isJsonEqual(args, snapshot.args)) {\n platforma.setBlockArgs(args);\n }\n }, debounceSpan, { maxWait });\n\n const setBlockUiState = useDebounceFn((ui: UiState) => {\n if (!isJsonEqual(ui, snapshot.ui)) {\n platforma.setBlockUiState(ui);\n }\n }, debounceSpan, { maxWait });\n\n const setBlockArgsAndUiState = useDebounceFn((args: Args, ui: UiState) => {\n if (!isJsonEqual(args, snapshot.args) || !isJsonEqual(ui, snapshot.ui)) {\n platforma.setBlockArgsAndUiState(args, ui);\n }\n }, debounceSpan, { maxWait });\n\n (platforma as unknown as PlatformaV1<Args, Outputs, UiState, Href>).onStateUpdates(async (updates) => {\n updates.forEach((patch) => {\n if (patch.key === 'args' && !isJsonEqual(snapshot.args, patch.value)) {\n snapshot.args = Object.freeze(patch.value);\n log('args patch', snapshot.args);\n }\n\n if (patch.key === 'ui' && !isJsonEqual(snapshot.ui, patch.value)) {\n snapshot.ui = Object.freeze(patch.value);\n log('ui patch', snapshot.ui);\n }\n\n if (patch.key === 'outputs' && !isJsonEqual(snapshot.outputs, patch.value)) {\n snapshot.outputs = Object.freeze(patch.value);\n log('outputs patch', snapshot.outputs);\n }\n\n if (patch.key === 'navigationState' && !isJsonEqual(snapshot.navigationState, patch.value)) {\n snapshot.navigationState = Object.freeze(patch.value);\n log('navigationState patch', snapshot.navigationState);\n }\n });\n\n await nextTick();\n });\n\n const cloneArgs = () => deepClone(snapshot.args) as Args;\n const cloneUiState = () => deepClone(snapshot.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n createArgsModel<T = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.args);\n }\n\n return snapshot.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setBlockArgs(newArgs);\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.ui);\n }\n\n return (snapshot.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setBlockUiState(newData);\n },\n });\n },\n /**\n * Note: Don't forget to list the output names, like: useOutputs('output1', 'output2', ...etc)\n * @param keys - List of output names\n * @returns {OptionalResult<UnwrapOutputs<Outputs, K>>}\n */\n useOutputs<K extends keyof Outputs>(...keys: K[]): OptionalResult<UnwrapOutputs<Outputs, K>> {\n const data = reactive({\n errors: undefined,\n value: undefined,\n });\n\n watch(\n () => snapshot.outputs,\n () => {\n try {\n Object.assign(data, {\n value: this.unwrapOutputs<K>(...keys),\n errors: undefined,\n });\n } catch (error) {\n Object.assign(data, {\n value: undefined,\n errors: [String(error)],\n });\n }\n },\n { immediate: true, deep: true },\n );\n\n return data as OptionalResult<UnwrapOutputs<Outputs, K>>;\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.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) {\n const newArgs = cloneArgs();\n cb(newArgs);\n return platforma.setBlockArgs(newArgs);\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<void> {\n const newUiState = cloneUiState();\n return platforma.setBlockUiState(cb(newUiState));\n },\n /**\n * Updates the navigation state by applying a callback.\n *\n * @param cb - Callback to modify the current navigation state.\n * @returns A promise resolving after the update is applied.\n */\n updateNavigationState(cb: (args: Mutable<NavigationState<Href>>) => void) {\n const newState = cloneNavigationState();\n cb(newState);\n return platforma.setNavigationState(newState);\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 platforma.setNavigationState(newState);\n },\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.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.outputs).map(([k, vOrErr]) => [k, vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const getters = {\n snapshot,\n queryParams: computed(() => parseQuery<Href>(snapshot.navigationState.href)),\n href: computed(() => snapshot.navigationState.href),\n hasErrors: computed(() => Object.values(snapshot.outputs).some((v) => !v?.ok)),\n };\n\n const model = createAppModel(\n {\n get() {\n return { args: snapshot.args, ui: snapshot.ui } as AppModel;\n },\n autoSave: true,\n onSave(newData: AppModel) {\n setBlockArgsAndUiState(newData.args, newData.ui);\n },\n },\n {\n outputs,\n outputErrors,\n },\n settings,\n );\n\n return reactive(Object.assign(model, methods, getters));\n}\n\nexport type BaseAppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV1<Args, Outputs, UiState, Href>>;\n"],"names":["createAppV1","state","platforma","settings","log","msg","rest","snapshot","reactive","debounceSpan","maxWait","tap","v","setBlockArgs","useDebounceFn","args","isJsonEqual","setBlockUiState","ui","setBlockArgsAndUiState","updates","patch","nextTick","cloneArgs","deepClone","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","newData","keys","data","watch","error","outputs","entries","key","unwrapValueOrErrors","cb","newUiState","newState","href","computed","k","vOrErr","outputErrors","MultiError","getters","parseQuery","model","createAppModel"],"mappings":";;;;;;;;;AAwBO,SAASA,EAMdC,GACAC,GACAC,GACA;AAMA,QAAMC,IAAM,CAACC,MAAgBC,MAAoB;AAC/C,IAAIH,EAAS,SACX,QAAQ,IAAI,WAAWE,CAAG,IAAI,oCAAoC,iBAAiB,GAAGC,CAAI;AAAA,EAE9F,GAKMC,IAAWC,EAAS;AAAA,IACxB,MAAM,OAAO,OAAOP,EAAM,IAAI;AAAA,IAC9B,SAAS,OAAO,OAAOA,EAAM,OAAO;AAAA,IACpC,IAAI,OAAO,OAAOA,EAAM,EAAE;AAAA,IAC1B,iBAAiB,OAAO,OAAOA,EAAM,eAAe;AAAA,EAAA,CACrD,GAOKQ,IAAeN,EAAS,gBAAgB,KAExCO,IAAUC,EAAIR,EAAS,mBAAmB,GAAG,CAACS,MAAMA,IAAI,MAAS,MAASA,IAAIH,IAAeA,IAAe,MAAMG,CAAC,GAEnHC,IAAeC,EAAc,CAACC,MAAe;AACjD,IAAKC,EAAYD,GAAMR,EAAS,IAAI,KAClCL,EAAU,aAAaa,CAAI;AAAA,EAE/B,GAAGN,GAAc,EAAE,SAAAC,GAAS,GAEtBO,IAAkBH,EAAc,CAACI,MAAgB;AACrD,IAAKF,EAAYE,GAAIX,EAAS,EAAE,KAC9BL,EAAU,gBAAgBgB,CAAE;AAAA,EAEhC,GAAGT,GAAc,EAAE,SAAAC,GAAS,GAEtBS,IAAyBL,EAAc,CAACC,GAAYG,MAAgB;AACxE,KAAI,CAACF,EAAYD,GAAMR,EAAS,IAAI,KAAK,CAACS,EAAYE,GAAIX,EAAS,EAAE,MACnEL,EAAU,uBAAuBa,GAAMG,CAAE;AAAA,EAE7C,GAAGT,GAAc,EAAE,SAAAC,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EAAG,GAAE,CAAC;AAAA,EAAA,GAGzEwC,IAAQC;AAAA,IACZ;AAAA,MACE,MAAM;AACJ,eAAO,EAAE,MAAM9C,EAAS,MAAM,IAAIA,EAAS,GAAA;AAAA,MAC7C;AAAA,MACA,UAAU;AAAA,MACV,OAAOyB,GAAmB;AACxB,QAAAb,EAAuBa,EAAQ,MAAMA,EAAQ,EAAE;AAAA,MACjD;AAAA,IAAA;AAAA,IAEF;AAAA,MACE,SAAAK;AAAA,MACA,cAAAW;AAAA,IAAA;AAAA,EAGJ;AAEA,SAAOxC,EAAS,OAAO,OAAO4C,GAAOzB,GAASuB,CAAO,CAAC;AACxD;"}
|
|
1
|
+
{"version":3,"file":"createAppV1.js","sources":["../../src/internal/createAppV1.ts"],"sourcesContent":["import { deepClone, isJsonEqual, tap } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV1 } from '@platforma-sdk/model';\nimport { reactive, nextTick, computed, watch } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OptionalResult, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { createAppModel } from './createAppModel';\nimport { parseQuery } from '../urls';\nimport { MultiError, unwrapValueOrErrors } from '../utils';\nimport { useDebounceFn } from '@vueuse/core';\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 createAppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: BlockState<Args, Outputs, UiState, Href>,\n platforma: PlatformaV1<Args, Outputs, UiState, Href>,\n settings: AppSettings,\n) {\n type AppModel = {\n args: Args;\n ui: UiState;\n };\n\n const log = (msg: string, ...rest: unknown[]) => {\n if (settings.debug) {\n console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', ...rest);\n }\n };\n\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = reactive({\n args: Object.freeze(state.args),\n outputs: Object.freeze(state.outputs),\n ui: Object.freeze(state.ui),\n navigationState: Object.freeze(state.navigationState) as NavigationState<Href>,\n }) as {\n args: Readonly<Args>;\n outputs: Partial<Readonly<Outputs>>;\n ui: Readonly<UiState>;\n navigationState: Readonly<NavigationState<Href>>;\n };\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const maxWait = tap(settings.debounceMaxWait ?? 0, (v) => v < 20_000 ? 20_000 : v < debounceSpan ? debounceSpan * 100 : v);\n\n const setBlockArgs = useDebounceFn((args: Args) => {\n if (!isJsonEqual(args, snapshot.args)) {\n platforma.setBlockArgs(args);\n }\n }, debounceSpan, { maxWait });\n\n const setBlockUiState = useDebounceFn((ui: UiState) => {\n if (!isJsonEqual(ui, snapshot.ui)) {\n platforma.setBlockUiState(ui);\n }\n }, debounceSpan, { maxWait });\n\n const setBlockArgsAndUiState = useDebounceFn((args: Args, ui: UiState) => {\n if (!isJsonEqual(args, snapshot.args) || !isJsonEqual(ui, snapshot.ui)) {\n platforma.setBlockArgsAndUiState(args, ui);\n }\n }, debounceSpan, { maxWait });\n\n (platforma as unknown as PlatformaV1<Args, Outputs, UiState, Href>).onStateUpdates(async (updates) => {\n updates.forEach((patch) => {\n if (patch.key === 'args' && !isJsonEqual(snapshot.args, patch.value)) {\n snapshot.args = Object.freeze(patch.value);\n log('args patch', snapshot.args);\n }\n\n if (patch.key === 'ui' && !isJsonEqual(snapshot.ui, patch.value)) {\n snapshot.ui = Object.freeze(patch.value);\n log('ui patch', snapshot.ui);\n }\n\n if (patch.key === 'outputs' && !isJsonEqual(snapshot.outputs, patch.value)) {\n snapshot.outputs = Object.freeze(patch.value);\n log('outputs patch', snapshot.outputs);\n }\n\n if (patch.key === 'navigationState' && !isJsonEqual(snapshot.navigationState, patch.value)) {\n snapshot.navigationState = Object.freeze(patch.value);\n log('navigationState patch', snapshot.navigationState);\n }\n });\n\n await nextTick();\n });\n\n const cloneArgs = () => deepClone(snapshot.args) as Args;\n const cloneUiState = () => deepClone(snapshot.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n createArgsModel<T = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.args);\n }\n\n return snapshot.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setBlockArgs(newArgs);\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.ui);\n }\n\n return (snapshot.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setBlockUiState(newData);\n },\n });\n },\n /**\n * Note: Don't forget to list the output names, like: useOutputs('output1', 'output2', ...etc)\n * @param keys - List of output names\n * @returns {OptionalResult<UnwrapOutputs<Outputs, K>>}\n */\n useOutputs<K extends keyof Outputs>(...keys: K[]): OptionalResult<UnwrapOutputs<Outputs, K>> {\n const data = reactive({\n errors: undefined,\n value: undefined,\n });\n\n watch(\n () => snapshot.outputs,\n () => {\n try {\n Object.assign(data, {\n value: this.unwrapOutputs<K>(...keys),\n errors: undefined,\n });\n } catch (error) {\n Object.assign(data, {\n value: undefined,\n errors: [String(error)],\n });\n }\n },\n { immediate: true, deep: true },\n );\n\n return data as OptionalResult<UnwrapOutputs<Outputs, K>>;\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.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) {\n const newArgs = cloneArgs();\n cb(newArgs);\n return platforma.setBlockArgs(newArgs);\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<void> {\n const newUiState = cloneUiState();\n return platforma.setBlockUiState(cb(newUiState));\n },\n /**\n * Updates the navigation state by applying a callback.\n *\n * @param cb - Callback to modify the current navigation state.\n * @returns A promise resolving after the update is applied.\n */\n updateNavigationState(cb: (args: Mutable<NavigationState<Href>>) => void) {\n const newState = cloneNavigationState();\n cb(newState);\n return platforma.setNavigationState(newState);\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 platforma.setNavigationState(newState);\n },\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.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.outputs).map(([k, vOrErr]) => [k, vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const getters = {\n snapshot,\n queryParams: computed(() => parseQuery<Href>(snapshot.navigationState.href)),\n href: computed(() => snapshot.navigationState.href),\n hasErrors: computed(() => Object.values(snapshot.outputs).some((v) => !v?.ok)),\n };\n\n const model = createAppModel(\n {\n get() {\n return { args: snapshot.args, ui: snapshot.ui } as AppModel;\n },\n autoSave: true,\n onSave(newData: AppModel) {\n setBlockArgsAndUiState(newData.args, newData.ui);\n },\n },\n {\n outputs,\n outputErrors,\n },\n settings,\n );\n\n return reactive(Object.assign(model, methods, getters));\n}\n\nexport type BaseAppV1<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV1<Args, Outputs, UiState, Href>>;\n"],"names":["createAppV1","state","platforma","settings","log","msg","rest","snapshot","reactive","debounceSpan","maxWait","tap","v","setBlockArgs","useDebounceFn","args","isJsonEqual","setBlockUiState","ui","setBlockArgsAndUiState","updates","patch","nextTick","cloneArgs","deepClone","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","newData","keys","data","watch","error","outputs","entries","key","unwrapValueOrErrors","cb","newUiState","newState","href","computed","k","vOrErr","outputErrors","MultiError","getters","parseQuery","model","createAppModel"],"mappings":";;;;;;;;AAwBO,SAASA,EAMdC,GACAC,GACAC,GACA;AAMA,QAAMC,IAAM,CAACC,MAAgBC,MAAoB;AAC/C,IAAIH,EAAS,SACX,QAAQ,IAAI,WAAWE,CAAG,IAAI,oCAAoC,iBAAiB,GAAGC,CAAI;AAAA,EAE9F,GAKMC,IAAWC,EAAS;AAAA,IACxB,MAAM,OAAO,OAAOP,EAAM,IAAI;AAAA,IAC9B,SAAS,OAAO,OAAOA,EAAM,OAAO;AAAA,IACpC,IAAI,OAAO,OAAOA,EAAM,EAAE;AAAA,IAC1B,iBAAiB,OAAO,OAAOA,EAAM,eAAe;AAAA,EAAA,CACrD,GAOKQ,IAAeN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C,EAAO,MAAMA,EAAO,UAAU,SAAYA,EAAO,QAAQ,MAAS,CAAC;AAC7I,WAAO,OAAO,YAAYT,CAAO;AAAA,EACnC,CAAC,GAEKU,IAAeH,EAAgC,MAAM;AACzD,UAAMP,IAAU,OAAO,QAAQ/B,EAAS,OAAO,EAAE,IAAI,CAAC,CAACuC,GAAGC,CAAM,MAAM,CAACD,GAAGC,KAAUA,EAAO,OAAO,KAAQ,IAAIE,EAAWF,EAAO,MAAM,IAAI,MAAS,CAAC;AACpJ,WAAO,OAAO,YAAYT,CAAO;AAAA,EACnC,CAAC,GAEKY,IAAU;AAAA,IACd,UAAA3C;AAAA,IACA,aAAasC,EAAS,MAAMM,EAAiB5C,EAAS,gBAAgB,IAAI,CAAC;AAAA,IAC3E,MAAMsC,EAAS,MAAMtC,EAAS,gBAAgB,IAAI;AAAA,IAClD,WAAWsC,EAAS,MAAM,OAAO,OAAOtC,EAAS,OAAO,EAAE,KAAK,CAACK,MAAM,EAACA,KAAA,QAAAA,EAAG,GAAE,CAAC;AAAA,EAAA,GAGzEwC,IAAQC;AAAA,IACZ;AAAA,MACE,MAAM;AACJ,eAAO,EAAE,MAAM9C,EAAS,MAAM,IAAIA,EAAS,GAAA;AAAA,MAC7C;AAAA,MACA,UAAU;AAAA,MACV,OAAOyB,GAAmB;AACxB,QAAAb,EAAuBa,EAAQ,MAAMA,EAAQ,EAAE;AAAA,MACjD;AAAA,IAAA;AAAA,IAEF;AAAA,MACE,SAAAK;AAAA,MACA,cAAAW;AAAA,IAAA;AAAA,EAGJ;AAEA,SAAOxC,EAAS,OAAO,OAAO4C,GAAOzB,GAASuB,CAAO,CAAC;AACxD;"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { delay as L } from "../lib/util/helpers/dist/utils.js";
|
|
2
2
|
import { uniqueId as R } from "../lib/util/helpers/dist/strings.js";
|
|
3
3
|
import { deepClone as i } from "../lib/util/helpers/dist/objects.js";
|
|
4
|
-
import "../lib/util/helpers/dist/test_timeouts.js";
|
|
5
4
|
import { unwrapResult as c, hasAbortError as G } from "@platforma-sdk/model";
|
|
6
|
-
import { ref as A, computed as
|
|
5
|
+
import { ref as A, computed as p, reactive as N } from "vue";
|
|
7
6
|
import { createModel as O } from "../createModel.js";
|
|
8
7
|
import { parseQuery as H } from "../urls.js";
|
|
9
8
|
import { MultiError as K, unwrapValueOrErrors as W } from "../utils.js";
|
|
@@ -23,26 +22,26 @@ const V = 150, Y = (n) => ({
|
|
|
23
22
|
};
|
|
24
23
|
function de(n, u, m) {
|
|
25
24
|
const r = (e, ...t) => {
|
|
26
|
-
m.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", ...t.map((
|
|
25
|
+
m.debug && console.log(`%c>>> %c${e}`, "color: orange; font-weight: bold", "color: orange", ...t.map((a) => _(a)));
|
|
27
26
|
}, b = (e, ...t) => {
|
|
28
|
-
console.error(`%c>>> %c${e}`, "color: red; font-weight: bold", "color: red", ...t.map((
|
|
27
|
+
console.error(`%c>>> %c${e}`, "color: red; font-weight: bold", "color: red", ...t.map((a) => _(a)));
|
|
29
28
|
}, s = {
|
|
30
29
|
isExternalSnapshot: !1,
|
|
31
30
|
author: {
|
|
32
31
|
authorId: R(),
|
|
33
32
|
localVersion: 0
|
|
34
33
|
}
|
|
35
|
-
}, f = () => (s.author = Y(s.author), r("nextAuthorMarker", s.author), s.author), g = A(!1), S = A(n.uTag), h = m.debounceSpan ?? 200, y = new v({ debounceSpan: h }), U = new v({ debounceSpan: h }), M = new v({ debounceSpan: h }), k = new v({ debounceSpan: h }),
|
|
36
|
-
const e = Object.entries(
|
|
34
|
+
}, f = () => (s.author = Y(s.author), r("nextAuthorMarker", s.author), s.author), g = A(!1), S = A(n.uTag), h = m.debounceSpan ?? 200, y = new v({ debounceSpan: h }), U = new v({ debounceSpan: h }), M = new v({ debounceSpan: h }), k = new v({ debounceSpan: h }), o = A(n.value), T = async (e) => u.setBlockArgs(e, f()), E = async (e) => u.setBlockUiState(e, f()), D = async (e, t) => u.setBlockArgsAndUiState(e, t, f()), q = async (e) => u.setNavigationState(e), C = p(() => {
|
|
35
|
+
const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a.ok && a.value !== void 0 ? a.value : void 0]);
|
|
37
36
|
return Object.fromEntries(e);
|
|
38
|
-
}), $ =
|
|
39
|
-
const e = Object.entries(
|
|
37
|
+
}), $ = p(() => {
|
|
38
|
+
const e = Object.entries(o.value.outputs).map(([t, a]) => [t, a && a.ok === !1 ? new K(a.errors) : void 0]);
|
|
40
39
|
return Object.fromEntries(e);
|
|
41
40
|
}), l = N({
|
|
42
41
|
error: "",
|
|
43
42
|
model: {
|
|
44
|
-
args: i(
|
|
45
|
-
ui: i(
|
|
43
|
+
args: i(o.value.args),
|
|
44
|
+
ui: i(o.value.ui),
|
|
46
45
|
outputs: C,
|
|
47
46
|
outputErrors: $
|
|
48
47
|
}
|
|
@@ -59,34 +58,34 @@ function de(n, u, m) {
|
|
|
59
58
|
(async () => {
|
|
60
59
|
var e, t;
|
|
61
60
|
for (window.addEventListener("beforeunload", () => {
|
|
62
|
-
g.value = !0, u.dispose().then(c).catch((
|
|
63
|
-
b("error in dispose",
|
|
61
|
+
g.value = !0, u.dispose().then(c).catch((a) => {
|
|
62
|
+
b("error in dispose", a);
|
|
64
63
|
});
|
|
65
64
|
}); !g.value; )
|
|
66
65
|
try {
|
|
67
|
-
const
|
|
68
|
-
if (r("patches.length",
|
|
66
|
+
const a = await u.getPatches(S.value).then(c);
|
|
67
|
+
if (r("patches.length", a.value.length), r("uTagRef.value", S.value), r("patches.uTag", a.uTag), r("patches.author", a.author), r("data.author", s.author), S.value = a.uTag, a.value.length === 0) {
|
|
69
68
|
await new Promise((w) => setTimeout(w, V));
|
|
70
69
|
continue;
|
|
71
70
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
})) : (r("outputs changed",
|
|
76
|
-
|
|
71
|
+
const d = ((e = s.author) == null ? void 0 : e.authorId) !== ((t = a.author) == null ? void 0 : t.authorId);
|
|
72
|
+
d || s.isExternalSnapshot ? (r("got external changes, applying them to the snapshot", a.value), x(() => {
|
|
73
|
+
o.value = Q(o.value, a.value, !1, !1).newDocument, z({ args: o.value.args, ui: o.value.ui }), s.isExternalSnapshot = d;
|
|
74
|
+
})) : (r("outputs changed", a.value), x(() => {
|
|
75
|
+
o.value = Q(o.value, a.value).newDocument;
|
|
77
76
|
})), await new Promise((w) => setTimeout(w, V));
|
|
78
|
-
} catch (
|
|
79
|
-
G(
|
|
77
|
+
} catch (a) {
|
|
78
|
+
G(a) ? (r("patches loop aborted"), g.value = !0) : (b("error in patches loop", a), await new Promise((d) => setTimeout(d, 1e3)));
|
|
80
79
|
}
|
|
81
80
|
})();
|
|
82
|
-
const j = () => i(l.model.args), I = () => i(l.model.ui), P = () => i(
|
|
81
|
+
const j = () => i(l.model.args), I = () => i(l.model.ui), P = () => i(o.value.navigationState), F = {
|
|
83
82
|
cloneArgs: j,
|
|
84
83
|
cloneUiState: I,
|
|
85
84
|
cloneNavigationState: P,
|
|
86
85
|
createArgsModel(e = {}) {
|
|
87
86
|
return O({
|
|
88
87
|
get() {
|
|
89
|
-
return e.transform ? e.transform(
|
|
88
|
+
return e.transform ? e.transform(o.value.args) : o.value.args;
|
|
90
89
|
},
|
|
91
90
|
validate: e.validate,
|
|
92
91
|
autoSave: !0,
|
|
@@ -101,12 +100,12 @@ function de(n, u, m) {
|
|
|
101
100
|
createUiModel(e = {}, t) {
|
|
102
101
|
return O({
|
|
103
102
|
get() {
|
|
104
|
-
return e.transform ? e.transform(
|
|
103
|
+
return e.transform ? e.transform(o.value.ui) : o.value.ui ?? t();
|
|
105
104
|
},
|
|
106
105
|
validate: e.validate,
|
|
107
106
|
autoSave: !0,
|
|
108
|
-
onSave(
|
|
109
|
-
U.run(() => E(
|
|
107
|
+
onSave(a) {
|
|
108
|
+
U.run(() => E(a).then(c));
|
|
110
109
|
}
|
|
111
110
|
});
|
|
112
111
|
},
|
|
@@ -119,8 +118,8 @@ function de(n, u, m) {
|
|
|
119
118
|
* @returns An object with unwrapped output values.
|
|
120
119
|
*/
|
|
121
120
|
unwrapOutputs(...e) {
|
|
122
|
-
const t =
|
|
123
|
-
return Object.fromEntries(
|
|
121
|
+
const t = o.value.outputs, a = e.map((d) => [d, W(t[d])]);
|
|
122
|
+
return Object.fromEntries(a);
|
|
124
123
|
},
|
|
125
124
|
/**
|
|
126
125
|
* Updates the arguments state by applying a callback.
|
|
@@ -158,10 +157,10 @@ function de(n, u, m) {
|
|
|
158
157
|
}
|
|
159
158
|
}, J = {
|
|
160
159
|
closedRef: g,
|
|
161
|
-
snapshot:
|
|
162
|
-
queryParams:
|
|
163
|
-
href:
|
|
164
|
-
hasErrors:
|
|
160
|
+
snapshot: o,
|
|
161
|
+
queryParams: p(() => H(o.value.navigationState.href)),
|
|
162
|
+
href: p(() => o.value.navigationState.href),
|
|
163
|
+
hasErrors: p(() => Object.values(o.value.outputs).some((e) => !(e != null && e.ok)))
|
|
165
164
|
}, B = N(Object.assign(l, F, J));
|
|
166
165
|
return m.debug && (globalThis.__block_app__ = B), B;
|
|
167
166
|
}
|