@platforma-sdk/ui-vue 1.49.0 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -12
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/components/PlAnnotations/components/PlAnnotations.vue2.js.map +1 -1
- package/dist/defineApp.d.ts +3 -3
- package/dist/defineApp.d.ts.map +1 -1
- package/dist/defineApp.js.map +1 -1
- package/dist/index.js +79 -81
- package/dist/index.js.map +1 -1
- package/dist/internal/createAppV1.d.ts +2 -2
- package/dist/internal/createAppV1.d.ts.map +1 -1
- package/dist/internal/createAppV1.js +29 -27
- package/dist/internal/createAppV1.js.map +1 -1
- package/dist/internal/createAppV2.d.ts +2 -2
- package/dist/internal/createAppV2.d.ts.map +1 -1
- package/dist/internal/createAppV2.js +68 -66
- package/dist/internal/createAppV2.js.map +1 -1
- package/dist/internal/createAppV2.test.d.ts +2 -2
- package/dist/internal/createAppV2.test.d.ts.map +1 -1
- package/dist/internal/v1.static-test.d.ts.map +1 -1
- package/dist/internal/v2.static-test.d.ts.map +1 -1
- package/dist/lib.d.ts +0 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +11 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -34
- package/dist/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/defineApp.ts +4 -4
- package/src/internal/createAppV1.ts +9 -5
- package/src/internal/createAppV2.test.ts +40 -6
- package/src/internal/createAppV2.ts +9 -5
- package/src/internal/v1.static-test.ts +2 -2
- package/src/internal/v2.static-test.ts +2 -2
- package/src/lib.ts +0 -1
- package/src/types.ts +6 -5
- package/src/utils.ts +16 -13
- package/dist/components/ValueOrErrorsComponent.vue.d.ts +0 -27
- package/dist/components/ValueOrErrorsComponent.vue.d.ts.map +0 -1
- package/dist/components/ValueOrErrorsComponent.vue.js +0 -22
- package/dist/components/ValueOrErrorsComponent.vue.js.map +0 -1
- package/dist/components/ValueOrErrorsComponent.vue2.js +0 -5
- package/dist/components/ValueOrErrorsComponent.vue2.js.map +0 -1
- package/src/components/ValueOrErrorsComponent.vue +0 -28
|
@@ -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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O,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
|
+
{"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, PlatformaExtended } 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 { ensureOutputHasStableFlag, MultiError, unwrapOutput } 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: PlatformaExtended<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, unwrapOutput(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)\n .map(([k, outputWithStatus]) => platforma.blockModelInfo.outputs[k].withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [k, outputWithStatus.ok && outputWithStatus.value !== undefined ? outputWithStatus.value : undefined],\n );\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","unwrapOutput","cb","newUiState","newState","href","computed","k","outputWithStatus","ensureOutputHasStableFlag","outputErrors","vOrErr","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,GAAS;AAE3B,EAAAR,EAAmE,eAAe,OA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AAO,OAAOtC,EAAS,OAAO,EAAE,KAAK,CAACK,MAAM,EAACA,KAAA,QAAAA,EAAG,GAAE,CAAC;AAAA,EAAA,GAGzE0C,IAAQC;AAAA,IACZ;AAAA,MACE,MAAM;AACJ,eAAO,EAAE,MAAMhD,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,cAAAY;AAAA,IAAA;AAAA,EAGJ;AAEA,SAAOzC,EAAS,OAAO,OAAO8C,GAAO3B,GAASyB,CAAO,CAAC;AACxD;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mutable } from '@milaboratories/helpers';
|
|
2
|
-
import { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker } from '@platforma-sdk/model';
|
|
2
|
+
import { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker, PlatformaExtended } from '@platforma-sdk/model';
|
|
3
3
|
import { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';
|
|
4
4
|
export declare const patchPoolingDelay = 150;
|
|
5
5
|
export declare const createNextAuthorMarker: (marker: AuthorMarker | undefined) => AuthorMarker;
|
|
@@ -17,7 +17,7 @@ export declare const createNextAuthorMarker: (marker: AuthorMarker | undefined)
|
|
|
17
17
|
*
|
|
18
18
|
* @returns A reactive application object with methods, getters, and state.
|
|
19
19
|
*/
|
|
20
|
-
export declare function createAppV2<Args = unknown, Outputs extends BlockOutputsBase = BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`>(state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>, platforma: PlatformaV2<Args, Outputs, UiState, Href
|
|
20
|
+
export declare function createAppV2<Args = unknown, Outputs extends BlockOutputsBase = BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`>(state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>, platforma: PlatformaExtended<PlatformaV2<Args, Outputs, UiState, Href>>, settings: AppSettings): {
|
|
21
21
|
error: string;
|
|
22
22
|
model: {
|
|
23
23
|
args: import('vue').UnwrapRef<Args>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppV2.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"createAppV2.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIvJ,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ1G,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,eAAO,MAAM,sBAAsB,WAAY,YAAY,GAAG,SAAS,KAAG,YAGxE,CAAC;AAUH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,EAExC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,EAC9D,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,EACvE,QAAQ,EAAE,WAAW;WA0FZ,MAAM;;;;;;;qBAoF2C,IAAI;wBACH,OAAO;gCACc,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;sBAM5F,CAAC,SAAS,IAAI,mBAAkB,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC;oBAmB5D,CAAC,SAAS,OAAO,qBAAqB,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,8BAAuB,MAAM,OAAO;oBAwBvG,CAAC,SAAS,MAAM,OAAO,WAAW,CAAC,EAAE,KAAG,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;qBAWhE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,KAAG,OAAO,CAAC,OAAO,CAAC;wBAcpC,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC;uBAY9C,IAAI;;;;cAzNf,IAAI;iBACD,OAAO,CAAC,OAAO,CAAC;YACrB,OAAO;yBACM,eAAe,CAAC,IAAI,CAAC;;;;;EAiPzC;AAED,MAAM,MAAM,SAAS,CACnB,IAAI,GAAG,OAAO,EACd,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EACnD,OAAO,GAAG,OAAO,EACjB,IAAI,SAAS,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,IACtC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -1,91 +1,93 @@
|
|
|
1
|
-
import { delay as
|
|
2
|
-
import { uniqueId as
|
|
1
|
+
import { delay as J } from "../lib/util/helpers/dist/utils.js";
|
|
2
|
+
import { uniqueId as V } from "../lib/util/helpers/dist/strings.js";
|
|
3
3
|
import { deepClone as i } from "../lib/util/helpers/dist/objects.js";
|
|
4
|
-
import { unwrapResult as c, hasAbortError as
|
|
5
|
-
import { ref as A, computed as
|
|
6
|
-
import { createModel as
|
|
7
|
-
import { parseQuery as
|
|
8
|
-
import {
|
|
4
|
+
import { unwrapResult as c, hasAbortError as L } from "@platforma-sdk/model";
|
|
5
|
+
import { ref as A, computed as g, reactive as B } from "vue";
|
|
6
|
+
import { createModel as N } from "../createModel.js";
|
|
7
|
+
import { parseQuery as G } from "../urls.js";
|
|
8
|
+
import { ensureOutputHasStableFlag as K, MultiError as X, unwrapOutput as Y } from "../utils.js";
|
|
9
9
|
import "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.js";
|
|
10
10
|
import { UpdateSerializer as v } from "./UpdateSerializer.js";
|
|
11
|
-
import { watchIgnorable as
|
|
11
|
+
import { watchIgnorable as Z } from "@vueuse/core";
|
|
12
12
|
import { applyPatch as Q } from "../node_modules/.pnpm/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.js";
|
|
13
|
-
const
|
|
14
|
-
authorId: (n == null ? void 0 : n.authorId) ??
|
|
13
|
+
const _ = 150, W = (n) => ({
|
|
14
|
+
authorId: (n == null ? void 0 : n.authorId) ?? V(),
|
|
15
15
|
localVersion: ((n == null ? void 0 : n.localVersion) ?? 0) + 1
|
|
16
|
-
}),
|
|
16
|
+
}), R = (n) => {
|
|
17
17
|
try {
|
|
18
18
|
return JSON.stringify(n, null, 2);
|
|
19
19
|
} catch (u) {
|
|
20
20
|
return u instanceof Error ? u.message : String(u);
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
function
|
|
23
|
+
function ge(n, u, m) {
|
|
24
24
|
const r = (e, ...t) => {
|
|
25
|
-
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((o) => R(o)));
|
|
26
26
|
}, b = (e, ...t) => {
|
|
27
|
-
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((o) => R(o)));
|
|
28
28
|
}, s = {
|
|
29
29
|
isExternalSnapshot: !1,
|
|
30
30
|
author: {
|
|
31
|
-
authorId:
|
|
31
|
+
authorId: V(),
|
|
32
32
|
localVersion: 0
|
|
33
33
|
}
|
|
34
|
-
}, f = () => (s.author =
|
|
35
|
-
const e = Object.entries(
|
|
34
|
+
}, f = () => (s.author = W(s.author), r("nextAuthorMarker", s.author), s.author), p = 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 }), D = new v({ debounceSpan: h }), a = A(n.value), T = async (e) => u.setBlockArgs(e, f()), E = async (e) => u.setBlockUiState(e, f()), k = async (e, t) => u.setBlockArgsAndUiState(e, t, f()), q = async (e) => u.setNavigationState(e), C = g(() => {
|
|
35
|
+
const e = Object.entries(a.value.outputs).map(
|
|
36
|
+
([t, o]) => u.blockModelInfo.outputs[t].withStatus ? [t, K(o)] : [t, o.ok && o.value !== void 0 ? o.value : void 0]
|
|
37
|
+
);
|
|
36
38
|
return Object.fromEntries(e);
|
|
37
|
-
}),
|
|
38
|
-
const e = Object.entries(
|
|
39
|
+
}), F = g(() => {
|
|
40
|
+
const e = Object.entries(a.value.outputs).map(([t, o]) => [t, o && o.ok === !1 ? new X(o.errors) : void 0]);
|
|
39
41
|
return Object.fromEntries(e);
|
|
40
|
-
}), l =
|
|
42
|
+
}), l = B({
|
|
41
43
|
error: "",
|
|
42
44
|
model: {
|
|
43
|
-
args: i(
|
|
44
|
-
ui: i(
|
|
45
|
+
args: i(a.value.args),
|
|
46
|
+
ui: i(a.value.ui),
|
|
45
47
|
outputs: C,
|
|
46
|
-
outputErrors:
|
|
48
|
+
outputErrors: F
|
|
47
49
|
}
|
|
48
|
-
}), { ignoreUpdates:
|
|
50
|
+
}), { ignoreUpdates: O } = Z(
|
|
49
51
|
() => l.model,
|
|
50
52
|
(e) => {
|
|
51
53
|
const t = i(e);
|
|
52
|
-
r("setArgsAndUiStateQueue appModel.model, args", t.args, "ui", t.ui), M.run(() =>
|
|
54
|
+
r("setArgsAndUiStateQueue appModel.model, args", t.args, "ui", t.ui), M.run(() => k(t.args, t.ui).then(c));
|
|
53
55
|
},
|
|
54
56
|
{ deep: !0 }
|
|
55
|
-
),
|
|
57
|
+
), $ = (e) => {
|
|
56
58
|
r("updateAppModel", e), l.model.args = i(e.args), l.model.ui = i(e.ui);
|
|
57
59
|
};
|
|
58
60
|
(async () => {
|
|
59
61
|
var e, t;
|
|
60
62
|
for (window.addEventListener("beforeunload", () => {
|
|
61
|
-
|
|
62
|
-
b("error in dispose",
|
|
63
|
+
p.value = !0, u.dispose().then(c).catch((o) => {
|
|
64
|
+
b("error in dispose", o);
|
|
63
65
|
});
|
|
64
|
-
}); !
|
|
66
|
+
}); !p.value; )
|
|
65
67
|
try {
|
|
66
|
-
const
|
|
67
|
-
if (r("patches.length",
|
|
68
|
-
await new Promise((w) => setTimeout(w,
|
|
68
|
+
const o = await u.getPatches(S.value).then(c);
|
|
69
|
+
if (r("patches.length", o.value.length), r("uTagRef.value", S.value), r("patches.uTag", o.uTag), r("patches.author", o.author), r("data.author", s.author), S.value = o.uTag, o.value.length === 0) {
|
|
70
|
+
await new Promise((w) => setTimeout(w, _));
|
|
69
71
|
continue;
|
|
70
72
|
}
|
|
71
|
-
const d = ((e = s.author) == null ? void 0 : e.authorId) !== ((t =
|
|
72
|
-
d || s.isExternalSnapshot ? (r("got external changes, applying them to the snapshot",
|
|
73
|
-
|
|
74
|
-
})) : (r("outputs changed",
|
|
75
|
-
|
|
76
|
-
})), await new Promise((w) => setTimeout(w,
|
|
77
|
-
} catch (
|
|
78
|
-
|
|
73
|
+
const d = ((e = s.author) == null ? void 0 : e.authorId) !== ((t = o.author) == null ? void 0 : t.authorId);
|
|
74
|
+
d || s.isExternalSnapshot ? (r("got external changes, applying them to the snapshot", o.value), O(() => {
|
|
75
|
+
a.value = Q(a.value, o.value, !1, !1).newDocument, $({ args: a.value.args, ui: a.value.ui }), s.isExternalSnapshot = d;
|
|
76
|
+
})) : (r("outputs changed", o.value), O(() => {
|
|
77
|
+
a.value = Q(a.value, o.value).newDocument;
|
|
78
|
+
})), await new Promise((w) => setTimeout(w, _));
|
|
79
|
+
} catch (o) {
|
|
80
|
+
L(o) ? (r("patches loop aborted"), p.value = !0) : (b("error in patches loop", o), await new Promise((d) => setTimeout(d, 1e3)));
|
|
79
81
|
}
|
|
80
82
|
})();
|
|
81
|
-
const
|
|
82
|
-
cloneArgs:
|
|
83
|
+
const x = () => i(l.model.args), I = () => i(l.model.ui), j = () => i(a.value.navigationState), z = {
|
|
84
|
+
cloneArgs: x,
|
|
83
85
|
cloneUiState: I,
|
|
84
|
-
cloneNavigationState:
|
|
86
|
+
cloneNavigationState: j,
|
|
85
87
|
createArgsModel(e = {}) {
|
|
86
|
-
return
|
|
88
|
+
return N({
|
|
87
89
|
get() {
|
|
88
|
-
return e.transform ? e.transform(
|
|
90
|
+
return e.transform ? e.transform(a.value.args) : a.value.args;
|
|
89
91
|
},
|
|
90
92
|
validate: e.validate,
|
|
91
93
|
autoSave: !0,
|
|
@@ -98,14 +100,14 @@ function de(n, u, m) {
|
|
|
98
100
|
* defaultUiState is temporarily here, remove it after implementing initialUiState
|
|
99
101
|
*/
|
|
100
102
|
createUiModel(e = {}, t) {
|
|
101
|
-
return
|
|
103
|
+
return N({
|
|
102
104
|
get() {
|
|
103
|
-
return e.transform ? e.transform(
|
|
105
|
+
return e.transform ? e.transform(a.value.ui) : a.value.ui ?? t();
|
|
104
106
|
},
|
|
105
107
|
validate: e.validate,
|
|
106
108
|
autoSave: !0,
|
|
107
|
-
onSave(
|
|
108
|
-
U.run(() => E(
|
|
109
|
+
onSave(o) {
|
|
110
|
+
U.run(() => E(o).then(c));
|
|
109
111
|
}
|
|
110
112
|
});
|
|
111
113
|
},
|
|
@@ -118,8 +120,8 @@ function de(n, u, m) {
|
|
|
118
120
|
* @returns An object with unwrapped output values.
|
|
119
121
|
*/
|
|
120
122
|
unwrapOutputs(...e) {
|
|
121
|
-
const t =
|
|
122
|
-
return Object.fromEntries(
|
|
123
|
+
const t = a.value.outputs, o = e.map((d) => [d, Y(t[d])]);
|
|
124
|
+
return Object.fromEntries(o);
|
|
123
125
|
},
|
|
124
126
|
/**
|
|
125
127
|
* Updates the arguments state by applying a callback.
|
|
@@ -128,7 +130,7 @@ function de(n, u, m) {
|
|
|
128
130
|
* @returns A promise resolving after the update is applied.
|
|
129
131
|
*/
|
|
130
132
|
updateArgs(e) {
|
|
131
|
-
const t =
|
|
133
|
+
const t = x();
|
|
132
134
|
return e(t), r("updateArgs", t), l.model.args = t, y.run(() => T(t).then(c));
|
|
133
135
|
},
|
|
134
136
|
/**
|
|
@@ -149,24 +151,24 @@ function de(n, u, m) {
|
|
|
149
151
|
* @returns A promise resolving after the navigation state is updated.
|
|
150
152
|
*/
|
|
151
153
|
navigateTo(e) {
|
|
152
|
-
const t =
|
|
153
|
-
return t.href = e,
|
|
154
|
+
const t = j();
|
|
155
|
+
return t.href = e, D.run(() => q(t).then(c));
|
|
154
156
|
},
|
|
155
157
|
async allSettled() {
|
|
156
|
-
return await
|
|
158
|
+
return await J(0), M.allSettled();
|
|
157
159
|
}
|
|
158
|
-
},
|
|
159
|
-
closedRef:
|
|
160
|
-
snapshot:
|
|
161
|
-
queryParams:
|
|
162
|
-
href:
|
|
163
|
-
hasErrors:
|
|
164
|
-
},
|
|
165
|
-
return m.debug && (globalThis.__block_app__ =
|
|
160
|
+
}, H = {
|
|
161
|
+
closedRef: p,
|
|
162
|
+
snapshot: a,
|
|
163
|
+
queryParams: g(() => G(a.value.navigationState.href)),
|
|
164
|
+
href: g(() => a.value.navigationState.href),
|
|
165
|
+
hasErrors: g(() => Object.values(a.value.outputs).some((e) => !(e != null && e.ok)))
|
|
166
|
+
}, P = B(Object.assign(l, z, H));
|
|
167
|
+
return m.debug && (globalThis.__block_app__ = P), P;
|
|
166
168
|
}
|
|
167
169
|
export {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
ge as createAppV2,
|
|
171
|
+
W as createNextAuthorMarker,
|
|
172
|
+
_ as patchPoolingDelay
|
|
171
173
|
};
|
|
172
174
|
//# sourceMappingURL=createAppV2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppV2.js","sources":["../../src/internal/createAppV2.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker } from '@platforma-sdk/model';\nimport { hasAbortError, unwrapResult } from '@platforma-sdk/model';\nimport type { Ref } from 'vue';\nimport { reactive, computed, ref } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { parseQuery } from '../urls';\nimport { MultiError, unwrapValueOrErrors } from '../utils';\nimport { applyPatch } from 'fast-json-patch';\nimport { UpdateSerializer } from './UpdateSerializer';\nimport { watchIgnorable } from '@vueuse/core';\n\nexport const patchPoolingDelay = 150;\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\n});\n\nconst stringifyForDebug = (v: unknown) => {\n try {\n return JSON.stringify(v, null, 2);\n } catch (err) {\n return err instanceof Error ? err.message : String(err);\n }\n};\n\n/**\n * Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.\n *\n * @template Args - The type of arguments used in the application.\n * @template Outputs - The type of block outputs extending `BlockOutputsBase`.\n * @template UiState - The type of the UI state.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>,\n platforma: PlatformaV2<Args, Outputs, UiState, Href>,\n settings: AppSettings,\n) {\n const debug = (msg: string, ...rest: unknown[]) => {\n if (settings.debug) {\n console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', ...rest.map((r) => stringifyForDebug(r)));\n }\n };\n\n const error = (msg: string, ...rest: unknown[]) => {\n console.error(`%c>>> %c${msg}`, 'color: red; font-weight: bold', 'color: red', ...rest.map((r) => stringifyForDebug(r)));\n };\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug('nextAuthorMarker', data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setArgsQueue = new UpdateSerializer({ debounceSpan });\n const setUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setArgsAndUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>;\n\n const setBlockArgs = async (args: Args) => {\n return platforma.setBlockArgs(args, nextAuthorMarker());\n };\n\n const setBlockUiState = async (ui: UiState) => {\n return platforma.setBlockUiState(ui, nextAuthorMarker());\n };\n\n const setBlockArgsAndUiState = async (args: Args, ui: UiState) => {\n return platforma.setBlockArgsAndUiState(args, ui, nextAuthorMarker());\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr.ok && vOrErr.value !== undefined ? vOrErr.value : undefined]);\n return Object.fromEntries(entries);\n });\n\n const outputErrors = computed<OutputErrors<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>).map(([k, vOrErr]) => [k, vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n error: '',\n model: {\n args: deepClone(snapshot.value.args) as Args,\n ui: deepClone(snapshot.value.ui) as UiState,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n args: Args;\n ui: UiState;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug('setArgsAndUiStateQueue appModel.model, args', newData.args, 'ui', newData.ui);\n setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: {\n args: Args;\n ui: UiState;\n }) => {\n debug('updateAppModel', newData);\n appModel.model.args = deepClone(newData.args) as Args;\n appModel.model.ui = deepClone(newData.ui) as UiState;\n };\n\n (async () => {\n window.addEventListener('beforeunload', () => {\n closedRef.value = true;\n platforma.dispose().then(unwrapResult).catch((err) => {\n error('error in dispose', err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug('patches.length', patches.value.length);\n debug('uTagRef.value', uTagRef.value);\n debug('patches.uTag', patches.uTag);\n debug('patches.author', patches.author);\n debug('data.author', data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug('got external changes, applying them to the snapshot', patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ args: snapshot.value.args, ui: snapshot.value.ui });\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 cloneArgs = () => deepClone(appModel.model.args) as Args;\n const cloneUiState = () => deepClone(appModel.model.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneArgs,\n cloneUiState,\n cloneNavigationState,\n createArgsModel<T extends Args = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.args as Args);\n }\n\n return snapshot.value.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T extends UiState = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.ui as UiState);\n }\n\n return (snapshot.value.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setUiStateQueue.run(() => setBlockUiState(newData).then(unwrapResult));\n },\n });\n },\n /**\n * Retrieves the unwrapped values of outputs for the given keys.\n *\n * @template K - Keys of the outputs to unwrap.\n * @param keys - List of output names.\n * @throws Error if the outputs contain errors.\n * @returns An object with unwrapped output values.\n */\n unwrapOutputs<K extends keyof Outputs>(...keys: K[]): UnwrapOutputs<Outputs, K> {\n const outputs = snapshot.value.outputs as Partial<Readonly<Outputs>>;\n const entries = keys.map((key) => [key, unwrapValueOrErrors(outputs[key])]);\n return Object.fromEntries(entries);\n },\n /**\n * Updates the arguments state by applying a callback.\n *\n * @param cb - Callback to modify the current arguments.\n * @returns A promise resolving after the update is applied.\n */\n updateArgs(cb: (args: Args) => void): Promise<boolean> {\n const newArgs = cloneArgs();\n cb(newArgs);\n debug('updateArgs', newArgs);\n appModel.model.args = newArgs;\n return setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateUiState(cb: (args: UiState) => UiState): Promise<boolean> {\n const newUiState = cb(cloneUiState());\n debug('updateUiState', newUiState);\n appModel.model.ui = newUiState;\n return setUiStateQueue.run(() => setBlockUiState(newUiState).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n return setArgsAndUiStateQueue.allSettled();\n },\n };\n\n const getters = {\n closedRef,\n snapshot,\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() => Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok)),\n };\n\n const app = reactive(Object.assign(appModel, methods, getters));\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n return app;\n}\n\nexport type BaseAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV2<Args, Outputs, UiState, Href>>;\n"],"names":["patchPoolingDelay","createNextAuthorMarker","marker","uniqueId","stringifyForDebug","v","err","createAppV2","state","platforma","settings","debug","msg","rest","r","error","data","nextAuthorMarker","closedRef","ref","uTagRef","debounceSpan","setArgsQueue","UpdateSerializer","setUiStateQueue","setArgsAndUiStateQueue","setNavigationStateQueue","snapshot","setBlockArgs","args","setBlockUiState","ui","setBlockArgsAndUiState","setNavigationState","outputs","computed","entries","k","vOrErr","outputErrors","MultiError","appModel","reactive","deepClone","ignoreUpdates","watchIgnorable","_newData","newData","unwrapResult","updateAppModel","patches","resolve","isAuthorChanged","_a","_b","applyPatch","hasAbortError","cloneArgs","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","keys","key","unwrapValueOrErrors","cb","newUiState","href","newState","delay","getters","parseQuery","app"],"mappings":";;;;;;;;;;;;AAcO,MAAMA,IAAoB,KAEpBC,IAAyB,CAACC,OAAoD;AAAA,EACzF,WAAUA,KAAA,gBAAAA,EAAQ,aAAYC,EAAA;AAAA,EAC9B,gBAAeD,KAAA,gBAAAA,EAAQ,iBAAgB,KAAK;AAC9C,IAEME,IAAoB,CAACC,MAAe;AACxC,MAAI;AACF,WAAO,KAAK,UAAUA,GAAG,MAAM,CAAC;AAAA,EAClC,SAASC,GAAK;AACZ,WAAOA,aAAe,QAAQA,EAAI,UAAU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AO,OAAOR,EAAS,MAAM,OAAqC,EAAE,KAAK,CAACtB,MAAM,EAACA,KAAA,QAAAA,EAAG,GAAE,CAAC;AAAA,EAAA,GAG7GsE,IAAMjC,EAAS,OAAO,OAAOD,GAAUmB,GAASa,CAAO,CAAC;AAE9D,SAAI/D,EAAS,UAEX,WAAW,gBAAgBiE,IAGtBA;AACT;"}
|
|
1
|
+
{"version":3,"file":"createAppV2.js","sources":["../../src/internal/createAppV2.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from '@milaboratories/helpers';\nimport type { Mutable } from '@milaboratories/helpers';\nimport type { NavigationState, BlockOutputsBase, BlockState, PlatformaV2, ValueWithUTag, AuthorMarker, PlatformaExtended } from '@platforma-sdk/model';\nimport { hasAbortError, unwrapResult } from '@platforma-sdk/model';\nimport type { Ref } from 'vue';\nimport { reactive, computed, ref } from 'vue';\nimport type { StateModelOptions, UnwrapOutputs, OutputValues, OutputErrors, AppSettings } from '../types';\nimport { createModel } from '../createModel';\nimport { parseQuery } from '../urls';\nimport { ensureOutputHasStableFlag, MultiError, unwrapOutput } from '../utils';\nimport { applyPatch } from 'fast-json-patch';\nimport { UpdateSerializer } from './UpdateSerializer';\nimport { watchIgnorable } from '@vueuse/core';\n\nexport const patchPoolingDelay = 150;\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\n});\n\nconst stringifyForDebug = (v: unknown) => {\n try {\n return JSON.stringify(v, null, 2);\n } catch (err) {\n return err instanceof Error ? err.message : String(err);\n }\n};\n\n/**\n * Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.\n *\n * @template Args - The type of arguments used in the application.\n * @template Outputs - The type of block outputs extending `BlockOutputsBase`.\n * @template UiState - The type of the UI state.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n>(\n state: ValueWithUTag<BlockState<Args, Outputs, UiState, Href>>,\n platforma: PlatformaExtended<PlatformaV2<Args, Outputs, UiState, Href>>,\n settings: AppSettings,\n) {\n const debug = (msg: string, ...rest: unknown[]) => {\n if (settings.debug) {\n console.log(`%c>>> %c${msg}`, 'color: orange; font-weight: bold', 'color: orange', ...rest.map((r) => stringifyForDebug(r)));\n }\n };\n\n const error = (msg: string, ...rest: unknown[]) => {\n console.error(`%c>>> %c${msg}`, 'color: red; font-weight: bold', 'color: red', ...rest.map((r) => stringifyForDebug(r)));\n };\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug('nextAuthorMarker', data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setArgsQueue = new UpdateSerializer({ debounceSpan });\n const setUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setArgsAndUiStateQueue = new UpdateSerializer({ debounceSpan });\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n args: Args;\n outputs: Partial<Outputs>;\n ui: UiState;\n navigationState: NavigationState<Href>;\n }>;\n\n const setBlockArgs = async (args: Args) => {\n return platforma.setBlockArgs(args, nextAuthorMarker());\n };\n\n const setBlockUiState = async (ui: UiState) => {\n return platforma.setBlockUiState(ui, nextAuthorMarker());\n };\n\n const setBlockArgsAndUiState = async (args: Args, ui: UiState) => {\n return platforma.setBlockArgsAndUiState(args, ui, nextAuthorMarker());\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>)\n .map(([k, outputWithStatus]) => platforma.blockModelInfo.outputs[k].withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [k, outputWithStatus.ok && outputWithStatus.value !== undefined ? outputWithStatus.value : undefined],\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>>).map(([k, vOrErr]) => [k, vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n error: '',\n model: {\n args: deepClone(snapshot.value.args) as Args,\n ui: deepClone(snapshot.value.ui) as UiState,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n args: Args;\n ui: UiState;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug('setArgsAndUiStateQueue appModel.model, args', newData.args, 'ui', newData.ui);\n setArgsAndUiStateQueue.run(() => setBlockArgsAndUiState(newData.args, newData.ui).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: {\n args: Args;\n ui: UiState;\n }) => {\n debug('updateAppModel', newData);\n appModel.model.args = deepClone(newData.args) as Args;\n appModel.model.ui = deepClone(newData.ui) as UiState;\n };\n\n (async () => {\n window.addEventListener('beforeunload', () => {\n closedRef.value = true;\n platforma.dispose().then(unwrapResult).catch((err) => {\n error('error in dispose', err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug('patches.length', patches.value.length);\n debug('uTagRef.value', uTagRef.value);\n debug('patches.uTag', patches.uTag);\n debug('patches.author', patches.author);\n debug('data.author', data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug('got external changes, applying them to the snapshot', patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ args: snapshot.value.args, ui: snapshot.value.ui });\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 cloneArgs = () => deepClone(appModel.model.args) as Args;\n const cloneUiState = () => deepClone(appModel.model.ui) as UiState;\n const cloneNavigationState = () => deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneArgs,\n cloneUiState,\n cloneNavigationState,\n createArgsModel<T extends Args = Args>(options: StateModelOptions<Args, T> = {}) {\n return createModel<T, Args>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.args as Args);\n }\n\n return snapshot.value.args as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newArgs) {\n setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n });\n },\n /**\n * defaultUiState is temporarily here, remove it after implementing initialUiState\n */\n createUiModel<T extends UiState = UiState>(options: StateModelOptions<UiState, T> = {}, defaultUiState: () => UiState) {\n return createModel<T, UiState>({\n get() {\n if (options.transform) {\n return options.transform(snapshot.value.ui as UiState);\n }\n\n return (snapshot.value.ui ?? defaultUiState()) as T;\n },\n validate: options.validate,\n autoSave: true,\n onSave(newData) {\n setUiStateQueue.run(() => setBlockUiState(newData).then(unwrapResult));\n },\n });\n },\n /**\n * Retrieves the unwrapped values of outputs for the given keys.\n *\n * @template K - Keys of the outputs to unwrap.\n * @param keys - List of output names.\n * @throws Error if the outputs contain errors.\n * @returns An object with unwrapped output values.\n */\n unwrapOutputs<K extends keyof Outputs>(...keys: K[]): UnwrapOutputs<Outputs, K> {\n const outputs = snapshot.value.outputs as Partial<Readonly<Outputs>>;\n const entries = keys.map((key) => [key, unwrapOutput(outputs[key])]);\n return Object.fromEntries(entries);\n },\n /**\n * Updates the arguments state by applying a callback.\n *\n * @param cb - Callback to modify the current arguments.\n * @returns A promise resolving after the update is applied.\n */\n updateArgs(cb: (args: Args) => void): Promise<boolean> {\n const newArgs = cloneArgs();\n cb(newArgs);\n debug('updateArgs', newArgs);\n appModel.model.args = newArgs;\n return setArgsQueue.run(() => setBlockArgs(newArgs).then(unwrapResult));\n },\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateUiState(cb: (args: UiState) => UiState): Promise<boolean> {\n const newUiState = cb(cloneUiState());\n debug('updateUiState', newUiState);\n appModel.model.ui = newUiState;\n return setUiStateQueue.run(() => setBlockUiState(newUiState).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n return setArgsAndUiStateQueue.allSettled();\n },\n };\n\n const getters = {\n closedRef,\n snapshot,\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() => Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok)),\n };\n\n const app = reactive(Object.assign(appModel, methods, getters));\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n return app;\n}\n\nexport type BaseAppV2<\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n UiState = unknown,\n Href extends `/${string}` = `/${string}`,\n> = ReturnType<typeof createAppV2<Args, Outputs, UiState, Href>>;\n"],"names":["patchPoolingDelay","createNextAuthorMarker","marker","uniqueId","stringifyForDebug","v","err","createAppV2","state","platforma","settings","debug","msg","rest","r","error","data","nextAuthorMarker","closedRef","ref","uTagRef","debounceSpan","setArgsQueue","UpdateSerializer","setUiStateQueue","setArgsAndUiStateQueue","setNavigationStateQueue","snapshot","setBlockArgs","args","setBlockUiState","ui","setBlockArgsAndUiState","setNavigationState","outputs","computed","entries","k","outputWithStatus","ensureOutputHasStableFlag","outputErrors","vOrErr","MultiError","appModel","reactive","deepClone","ignoreUpdates","watchIgnorable","_newData","newData","unwrapResult","updateAppModel","patches","resolve","isAuthorChanged","_a","_b","applyPatch","hasAbortError","cloneArgs","cloneUiState","cloneNavigationState","methods","options","createModel","newArgs","defaultUiState","keys","key","unwrapOutput","cb","newUiState","href","newState","delay","getters","parseQuery","app"],"mappings":";;;;;;;;;;;;AAcO,MAAMA,IAAoB,KAEpBC,IAAyB,CAACC,OAAoD;AAAA,EACzF,WAAUA,KAAA,gBAAAA,EAAQ,aAAYC,EAAA;AAAA,EAC9B,gBAAeD,KAAA,gBAAAA,EAAQ,iBAAgB,KAAK;AAC9C,IAEME,IAAoB,CAACC,MAAe;AACxC,MAAI;AACF,WAAO,KAAK,UAAUA,GAAG,MAAM,CAAC;AAAA,EAClC,SAASC,GAAK;AACZ,WAAOA,aAAe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M,gBAAgB,IAAY,CAAC;AAAA,IACzF,MAAMQ,EAAS,MAAMR,EAAS,MAAM,gBAAgB,IAAI;AAAA,IACxD,WAAWQ,EAAS,MAAM,OAAO,OAAOR,EAAS,MAAM,OAAqC,EAAE,KAAK,CAACtB,MAAM,EAACA,KAAA,QAAAA,EAAG,GAAE,CAAC;AAAA,EAAA,GAG7GwE,IAAMjC,EAAS,OAAO,OAAOD,GAAUmB,GAASa,CAAO,CAAC;AAE9D,SAAIjE,EAAS,UAEX,WAAW,gBAAgBmE,IAGtBA;AACT;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputWithStatus } from '@platforma-sdk/model';
|
|
2
2
|
type Args = {
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
@@ -8,7 +8,7 @@ type UiState = {
|
|
|
8
8
|
delay?: number;
|
|
9
9
|
};
|
|
10
10
|
type Outputs = {
|
|
11
|
-
sum:
|
|
11
|
+
sum: OutputWithStatus<number>;
|
|
12
12
|
};
|
|
13
13
|
export declare const platforma: import('@platforma-sdk/model').PlatformaV2<Args, Outputs, UiState, `/${string}`>;
|
|
14
14
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppV2.test.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV2.test.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"createAppV2.test.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV2.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,sBAAsB,CAAC;AAQ3E,KAAK,IAAI,GAAG;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAOF,KAAK,OAAO,GAAG;IACb,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC;AAuBF,eAAO,MAAM,SAAS,kFAAsE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.static-test.d.ts","sourceRoot":"","sources":["../../src/internal/v1.static-test.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"v1.static-test.d.ts","sourceRoot":"","sources":["../../src/internal/v1.static-test.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAoB,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3H,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,eAAe,CAAC;AAoC5D,KAAK,SAAS,CAAC,EAAE,SAAS,SAAS,IAAI,EAAE,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AACvF,KAAK,YAAY,CAAC,EAAE,SAAS,SAAS,IAAI,EAAE,SAAS,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC;AAE3H,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,IAAI,UAAU,CAAC,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2.static-test.d.ts","sourceRoot":"","sources":["../../src/internal/v2.static-test.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"v2.static-test.d.ts","sourceRoot":"","sources":["../../src/internal/v2.static-test.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAoB,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3H,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,eAAe,CAAC;AAoC5D,KAAK,SAAS,CAAC,EAAE,SAAS,SAAS,IAAI,EAAE,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AACvF,KAAK,YAAY,CAAC,EAAE,SAAS,SAAS,IAAI,EAAE,SAAS,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC;AAE3H,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,IAAI,UAAU,CAAC,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/lib.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export { default as BlockLayout } from './components/BlockLayout.vue';
|
|
|
2
2
|
export { default as PlAgDataTableV2 } from './components/PlAgDataTable/PlAgDataTableV2.vue';
|
|
3
3
|
export { default as PlAgOverlayLoading } from './components/PlAgDataTable/PlAgOverlayLoading.vue';
|
|
4
4
|
export { default as PlAgOverlayNoRows } from './components/PlAgDataTable/PlAgOverlayNoRows.vue';
|
|
5
|
-
export { default as ValueOrErrorsComponent } from './components/ValueOrErrorsComponent.vue';
|
|
6
5
|
export type { ListOptionBase } from '@platforma-sdk/model';
|
|
7
6
|
export * from './AgGridVue';
|
|
8
7
|
export * from './components/PlAgColumnHeader';
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":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U,CAAC;AAEzB,cAAc,SAAS,CAAC;AAExB,cAAc,cAAc,CAAC;AAE7B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,2BAA2B,CAAC;AAE1C,cAAc,uBAAuB,CAAC;AAEtC,mBAAmB,uBAAuB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OmitOverUnion } from '@milaboratories/helpers';
|
|
2
|
+
import { BlockOutputsBase, ErrorLike } from '@platforma-sdk/model';
|
|
2
3
|
import { Component, ComputedGetter } from 'vue';
|
|
3
|
-
export type UnwrapValueOrErrors<R extends ValueOrErrors<unknown>> = Extract<R, {
|
|
4
|
-
ok: true;
|
|
5
|
-
}>['value'];
|
|
6
4
|
export interface StateModelOptions<A, T = A> {
|
|
7
5
|
transform?: (v: A) => T;
|
|
8
6
|
validate?: (v: unknown) => A;
|
|
@@ -94,7 +92,9 @@ export type ModelResult<T, E = unknown> = {
|
|
|
94
92
|
error: E;
|
|
95
93
|
};
|
|
96
94
|
export type OutputValues<Outputs extends BlockOutputsBase> = {
|
|
97
|
-
[P in keyof Outputs]
|
|
95
|
+
[P in keyof Outputs]: Outputs[P] extends {
|
|
96
|
+
__unwrap: true;
|
|
97
|
+
} ? UnwrapValueOrError<Outputs[P]> | undefined : OmitOverUnion<Outputs[P], '__unwrap'>;
|
|
98
98
|
};
|
|
99
99
|
export type OutputErrors<Outputs extends BlockOutputsBase> = {
|
|
100
100
|
[P in keyof Outputs]?: Error;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE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,GACvD,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAC1C,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,gBAAgB,IAAI;KAC1D,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,KAAK;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IACxB;IACA,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,CAAC;CACX,GACC;IACA,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorLike,
|
|
1
|
+
import { ErrorLike, OutputWithStatus } from '@platforma-sdk/model';
|
|
2
2
|
import { OptionalResult } from './types';
|
|
3
3
|
import { ZodError } from 'zod';
|
|
4
4
|
export declare class UnresolvedError extends Error {
|
|
@@ -10,8 +10,16 @@ export declare class MultiError extends Error {
|
|
|
10
10
|
readonly fullMessage: string;
|
|
11
11
|
constructor(errors: (ErrorLike | string)[]);
|
|
12
12
|
}
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
13
|
+
export declare function unwrapOutput<V>(output?: OutputWithStatus<V>): V;
|
|
14
|
+
export declare function ensureOutputHasStableFlag<T>(output?: OutputWithStatus<T>): {
|
|
15
|
+
ok: false;
|
|
16
|
+
errors: ErrorLike[];
|
|
17
|
+
moreErrors: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
ok: true;
|
|
20
|
+
value: T;
|
|
21
|
+
stable: boolean;
|
|
22
|
+
};
|
|
15
23
|
export declare function wrapOptionalResult<V>(value: V): OptionalResult<V>;
|
|
16
24
|
export declare function isDefined<T>(v: T | undefined): v is T;
|
|
17
25
|
export declare const identity: <T, V = T>(v: T) => V;
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,SAAqB;CAC1B;AAOD,qBAAa,UAAW,SAAQ,KAAK;aAKP,MAAM,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE;IAJ1D,IAAI,SAAgB;IAEpB,SAAgB,WAAW,EAAE,MAAM,CAAC;gBAER,MAAM,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE;CAY3D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAU/D;AAED,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;;;;;EAQxE;AAID,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAKjE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,IAAI,CAAC,CAErD;AAED,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,SAAS,CAAC,KAAG,CAAsB,CAAC;AAEjE,eAAO,MAAM,WAAW,UAAW,OAAO,UAMzC,CAAC;AAEF,eAAO,MAA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