@platforma-sdk/ui-vue 1.75.6 → 1.75.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.
@@ -1,6 +1,6 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.75.6 build /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.75.8 build /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > ts-builder build --target browser-lib
5
5
 
6
6
  Building browser-lib project...
@@ -16,7 +16,7 @@ Building browser-lib project...
16
16
  rendering chunks...
17
17
 
18
18
  [vite:dts] Start generate declaration files...
19
- [vite:dts] Declaration files built in 6195ms.
19
+ [vite:dts] Declaration files built in 5276ms.
20
20
 
21
21
  computing gzip size...
22
22
  dist/components/PlAnnotations/components/PlAnnotations.vue?vue&type=style&index=0&lang.css 0.04 kB │ gzip: 0.06 kB
@@ -221,19 +221,19 @@ dist/components/PlTableFilters/PlTableFiltersV2.vue_vue_type_script_setup_true_l
221
221
  dist/components/PlBtnExportArchive/PlBtnExportArchive.vue_vue_type_script_setup_true_lang.js 5.19 kB │ gzip: 2.16 kB │ map: 10.36 kB
222
222
  dist/internal/createAppV2.js 5.26 kB │ gzip: 1.98 kB │ map: 17.78 kB
223
223
  dist/components/PlAgDataTable/sources/table-state-v2.js 5.72 kB │ gzip: 1.84 kB │ map: 19.38 kB
224
- dist/internal/createAppV3.js 5.77 kB │ gzip: 2.21 kB │ map: 20.16 kB
225
- dist/components/PlAgDataTable/sources/table-source-v2.js 6.56 kB │ gzip: 2.60 kB │ map: 22.26 kB
224
+ dist/internal/createAppV3.js 6.19 kB │ gzip: 2.34 kB │ map: 21.40 kB
225
+ dist/components/PlAgDataTable/sources/table-source-v2.js 6.61 kB │ gzip: 2.59 kB │ map: 22.42 kB
226
226
  dist/components/PlAdvancedFilter/PlAdvancedFilter.vue_vue_type_script_setup_true_lang.js 8.54 kB │ gzip: 2.59 kB │ map: 18.44 kB
227
227
  dist/components/PlAdvancedFilter/FilterEditor.vue_vue_type_script_setup_true_lang.js 10.24 kB │ gzip: 3.04 kB │ map: 23.20 kB
228
228
  dist/components/PlAgDataTable/PlAgDataTableV2.vue_vue_type_script_setup_true_lang.js 12.31 kB │ gzip: 3.90 kB │ map: 29.22 kB
229
229
 
230
230
  [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugins. Here is a breakdown:
231
- - sourcemaps (44%)
232
- - vite:dts (22%)
231
+ - sourcemaps (32%)
232
+ - vite:dts (23%)
233
233
  - vite:vue (12%)
234
- - vite:css-post (7%)
235
- - vite:css (6%)
234
+ - vite:css-post (11%)
235
+ - vite:css (7%)
236
236
  See https://rolldown.rs/options/checks#plugintimings for more details.
237
237
  
238
- ✓ built in 7.39s
238
+ ✓ built in 6.32s
239
239
  Build completed successfully
@@ -1,6 +1,6 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.75.6 formatter:check /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.75.8 formatter:check /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > ts-builder formatter --check
5
5
 
6
6
  Checking formatting...
@@ -8,5 +8,5 @@ Checking formatting...
8
8
  Checking formatting...
9
9
 
10
10
  All matched files use the correct format.
11
- Finished in 1931ms on 137 files using 8 threads.
11
+ Finished in 2296ms on 137 files using 8 threads.
12
12
  Format check completed successfully
@@ -1,10 +1,10 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.75.6 linter:check /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.75.8 linter:check /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > ts-builder linter --check
5
5
 
6
6
  Linting project...
7
7
  ↳ oxlint --config /home/runner/_work/platforma/platforma/sdk/ui-vue/.oxlintrc.json --deny-warnings
8
8
  Found 0 warnings and 0 errors.
9
- Finished in 29ms on 120 files with 98 rules using 8 threads.
9
+ Finished in 30ms on 120 files with 98 rules using 8 threads.
10
10
  Linting completed successfully
@@ -1,6 +1,6 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @platforma-sdk/ui-vue@1.75.6 types:check /home/runner/_work/platforma/platforma/sdk/ui-vue
3
+ > @platforma-sdk/ui-vue@1.75.8 types:check /home/runner/_work/platforma/platforma/sdk/ui-vue
4
4
  > ts-builder type-check --target browser-lib
5
5
 
6
6
  ↳ vue-tsc.js --noEmit --project ./tsconfig.json --customConditions ,
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @platforma-sdk/ui-vue
2
2
 
3
+ ## 1.75.8
4
+
5
+ ### Patch Changes
6
+
7
+ - dd5db77: public outputs for plugins
8
+ - Updated dependencies [dd5db77]
9
+ - @platforma-sdk/model@1.75.8
10
+ - @milaboratories/uikit@2.14.6
11
+
12
+ ## 1.75.7
13
+
14
+ ### Patch Changes
15
+
16
+ - 5a70c0f: Fix `@cell-button-clicked` not firing on PlAgDataTableV2 when the configured axis has a label column. Since the predefined-label change in 1.75.0, labelled axes are replaced in the grid by their label column, so the cell-button cellRendererSelector — which only matched `type:"axis"` ColDefs — never installed. Now also resolve the axis on single-axis label columns whose labeled axis equals `showCellButtonForAxisId`.
17
+ - Updated dependencies [5a70c0f]
18
+ - @milaboratories/uikit@2.14.5
19
+
3
20
  ## 1.75.6
4
21
 
5
22
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"table-source-v2.d.ts","sourceRoot":"","sources":["../../../../src/components/PlAgDataTable/sources/table-source-v2.ts"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sB,CAAC,GAAG;IACpF,QAAQ,EAAE,QAAQ,CAAC;CACpB,CACF,CAkHA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,gBAAgB,EACtB,YAAY,EAAE,mBAAmB,EAAE,GAAG,SAAS,EAC/C,oBAAoB,CAAC,EAAE,wBAAwB,GAC9C,MAAM,CAAC,kBAAkB,EAAE,WAAW,GAAG,YAAY,CAAC,CA+ExD"}
1
+ {"version":3,"file":"table-source-v2.d.ts","sourceRoot":"","sources":["../../../../src/components/PlAgDataTable/sources/table-source-v2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAGR,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAErB,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,mBAAmB,EAWzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,MAAM,EACN,OAAO,EAIP,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,IAAI,sBAAsB,CAExF;AA6BD,6DAA6D;AAC7D,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,QAAQ,EACR,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,GACrB,EAAE;IACD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,eAAe,EAAE,YAAY,CAAC;IAC9B,kBAAkB,EAAE,YAAY,CAAC;IACjC,mBAAmB,EAAE,gBAAgB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACnE,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACrC,oBAAoB,CAAC,EAAE,wBAAwB,CAAC;CACjD,GAAG,OAAO,CACT,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,YAAY,GAAG,sBAAsB,CAAC,GAAG;IACpF,QAAQ,EAAE,QAAQ,CAAC;CACpB,CACF,CAkHA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,gBAAgB,EACtB,YAAY,EAAE,mBAAmB,EAAE,GAAG,SAAS,EAC/C,oBAAoB,CAAC,EAAE,wBAAwB,GAC9C,MAAM,CAAC,kBAAkB,EAAE,WAAW,GAAG,YAAY,CAAC,CAkFxD"}
@@ -69,57 +69,56 @@ async function w({ generation: r, pfDriver: i, sheets: a, fullTableHandle: o, vi
69
69
  } }
70
70
  };
71
71
  }
72
- function T(t, n, o, d) {
73
- let f = u(n), p = n.type === "axis" ? n.spec.type : n.spec.valueType, m = s(n), g = {};
74
- m.fontFamily && (m.fontFamily === "monospace" ? (g.fontFamily = "Spline Sans Mono", g.fontWeight = 300) : g.fontFamily = m.fontFamily);
75
- let _ = y(n.spec, c.Label)?.trim() ?? `Unlabeled ${n.type} ${t}`;
72
+ function T(t, n, o, f) {
73
+ let p = u(n), m = n.type === "axis" ? n.spec.type : n.spec.valueType, g = s(n), _ = {};
74
+ g.fontFamily && (g.fontFamily === "monospace" ? (_.fontFamily = "Spline Sans Mono", _.fontWeight = 300) : _.fontFamily = g.fontFamily);
75
+ let v = y(n.spec, c.Label)?.trim() ?? `Unlabeled ${n.type} ${t}`;
76
76
  return {
77
- colId: f,
77
+ colId: p,
78
78
  mainMenuItems: r,
79
79
  context: n,
80
80
  field: `${t}`,
81
- headerName: _,
81
+ headerName: v,
82
82
  lockPosition: n.type === "axis" || h(n.spec) && n.spec.axesSpec.length === 1,
83
- hide: o !== void 0 && o.includes(f),
84
- valueFormatter: m.valueFormatter,
83
+ hide: o !== void 0 && o.includes(p),
84
+ valueFormatter: g.valueFormatter,
85
85
  headerComponent: i,
86
- cellRendererSelector: d?.showCellButtonForAxisId ? (t) => {
87
- if (n.type !== "axis") return;
88
- let r = t.colDef?.context?.id;
89
- if (e(r, d.showCellButtonForAxisId)) return {
86
+ cellRendererSelector: f?.showCellButtonForAxisId ? () => {
87
+ let t = n.type === "axis" ? n.id : h(n.spec) && n.spec.axesSpec.length === 1 ? d(n.spec.axesSpec[0]) : void 0;
88
+ if (t && e(t, f.showCellButtonForAxisId)) return {
90
89
  component: a,
91
90
  params: {
92
- invokeRowsOnDoubleClick: d.cellButtonInvokeRowsOnDoubleClick,
91
+ invokeRowsOnDoubleClick: f.cellButtonInvokeRowsOnDoubleClick,
93
92
  onClick: (e) => {
94
- d.trigger(e.data?.axesKey);
93
+ f.trigger(e.data?.axesKey);
95
94
  }
96
95
  }
97
96
  };
98
97
  } : void 0,
99
- cellStyle: g,
98
+ cellStyle: _,
100
99
  headerComponentParams: {
101
100
  type: (() => {
102
- switch (p) {
101
+ switch (m) {
103
102
  case l.Int:
104
103
  case l.Long:
105
104
  case l.Float:
106
105
  case l.Double: return "Number";
107
106
  case l.String:
108
107
  case l.Bytes: return "Text";
109
- default: throw Error(`unsupported data type: ${p}`);
108
+ default: throw Error(`unsupported data type: ${m}`);
110
109
  }
111
110
  })(),
112
111
  tooltip: y(n.spec, c.Description)?.trim()
113
112
  },
114
113
  cellDataType: (() => {
115
- switch (p) {
114
+ switch (m) {
116
115
  case l.Int:
117
116
  case l.Long:
118
117
  case l.Float:
119
118
  case l.Double: return "number";
120
119
  case l.String:
121
120
  case l.Bytes: return "text";
122
- default: throw Error(`unsupported data type: ${p}`);
121
+ default: throw Error(`unsupported data type: ${m}`);
123
122
  }
124
123
  })()
125
124
  };
@@ -1 +1 @@
1
- {"version":3,"file":"table-source-v2.js","names":[],"sources":["../../../../src/components/PlAgDataTable/sources/table-source-v2.ts"],"sourcesContent":["import type {\n AxesSpec,\n PTableColumnId,\n PTableColumnSpecAxis,\n PTableColumnSpecColumn,\n PTableHandle,\n PTableValue,\n} from \"@platforma-sdk/model\";\nimport {\n canonicalizeJson,\n getAxisId,\n pTableValue,\n type PFrameDriver,\n type PlDataTableSheet,\n type PTableVector,\n type AxisId,\n type PTableColumnSpec,\n type PTableKey,\n type PlTableColumnIdJson,\n isLabelColumn as isLabelColumnSpec,\n isLinkerColumn as isLinkerColumnSpec,\n isColumnHidden,\n isColumnOptional,\n matchAxisId,\n readAnnotation,\n readAnnotationJson,\n Annotation,\n ValueType,\n getPTableColumnId,\n} from \"@platforma-sdk/model\";\nimport type {\n CellStyle,\n ColDef,\n GridApi,\n ICellRendererParams,\n IServerSideDatasource,\n IServerSideGetRowsParams,\n ManagedGridOptions,\n} from \"ag-grid-enterprise\";\nimport type { PlAgHeaderComponentParams, PlAgHeaderComponentType } from \"../../PlAgColumnHeader\";\nimport { PlAgColumnHeader } from \"../../PlAgColumnHeader\";\nimport { PlAgTextAndButtonCell } from \"../../PlAgTextAndButtonCell\";\nimport type { PlAgDataTableV2Row, PlTableRowId } from \"../types\";\nimport { PTableHidden } from \"./common\";\nimport { defaultMainMenuItems } from \"./menu-items\";\nimport { makeRowNumberColDef, PlAgDataTableRowNumberColId } from \"./row-number\";\nimport { getColumnRenderingSpec } from \"./value-rendering\";\nimport type { Ref } from \"vue\";\nimport { isJsonEqual } from \"@milaboratories/helpers\";\nimport type { DeferredCircular } from \"./focus-row\";\nimport { isNil, uniq } from \"es-toolkit\";\n\nexport function isLabelColumn(column: PTableColumnSpec): column is PTableColumnSpecColumn {\n return column.type === \"column\" && isLabelColumnSpec(column.spec);\n}\n\n/** Convert columnar data from the driver to rows, used by ag-grid */\nfunction columns2rows(\n fields: number[],\n columns: PTableVector[],\n fieldResultMapping: number[],\n axesResultIndices: number[],\n): PlAgDataTableV2Row[] {\n const rowData: PlAgDataTableV2Row[] = [];\n for (let rowIdx = 0; rowIdx < columns[0].data.length; ++rowIdx) {\n const axesKey: PTableKey = axesResultIndices.map((ri) => pTableValue(columns[ri], rowIdx));\n const id = canonicalizeJson<PlTableRowId>(axesKey);\n const row = fields.reduce<PlAgDataTableV2Row>(\n (acc, field, colIdx) => {\n acc[field.toString() as `${number}`] =\n fieldResultMapping[colIdx] === -1\n ? PTableHidden\n : pTableValue(columns[fieldResultMapping[colIdx]], rowIdx);\n return acc;\n },\n { id, axesKey },\n );\n\n rowData.push(row);\n }\n return rowData;\n}\n\n/** Calculate GridOptions for selected p-table data source */\nexport async function calculateGridOptions({\n generation,\n pfDriver,\n sheets,\n fullTableHandle,\n visibleTableHandle,\n dataRenderedTracker,\n hiddenColIds,\n cellButtonAxisParams,\n}: {\n sheets: PlDataTableSheet[];\n pfDriver: PFrameDriver;\n generation: Ref<number>;\n fullTableHandle: PTableHandle;\n visibleTableHandle: PTableHandle;\n dataRenderedTracker: DeferredCircular<GridApi<PlAgDataTableV2Row>>;\n hiddenColIds?: PlTableColumnIdJson[];\n cellButtonAxisParams?: PlAgCellButtonAxisParams;\n}): Promise<\n Pick<ManagedGridOptions<PlAgDataTableV2Row>, \"columnDefs\" | \"serverSideDatasource\"> & {\n axesSpec: AxesSpec;\n }\n> {\n const stateGeneration = generation.value;\n\n // get specs of the full table\n const [tableSpecs, visibleTableSpecs] = await Promise.all([\n pfDriver.getSpec(fullTableHandle),\n pfDriver.getSpec(visibleTableHandle),\n ]);\n\n if (stateGeneration !== generation.value) throw new Error(\"table state generation changed\");\n\n // index mapping from full specs to visible subset (hidden columns → -1)\n const specsToVisibleSpecsMapping = buildSpecsToVisibleSpecsMapping(tableSpecs, visibleTableSpecs);\n\n const isPartitionedAxis = createPartitionedAxisPredicate(sheets);\n\n // label columns indexed by labeled axis (used for displayability filter)\n const getLabelColumnIndex = collectLabelColumnsByAxis(tableSpecs, isPartitionedAxis);\n\n // displayable column indices ordered: axes first, then columns by OrderPriority\n const fields = sortIndicesByTypeAndPriority(\n selectDisplayableIndices(tableSpecs, isPartitionedAxis, getLabelColumnIndex),\n tableSpecs,\n );\n\n // default hidden columns derived from Optional annotation when no saved state\n const resolvedHiddenColIds = hiddenColIds ?? computeDefaultHiddenColIds(fields, tableSpecs);\n\n const columnDefs: ColDef<PlAgDataTableV2Row, PTableValue | PTableHidden>[] = [\n makeRowNumberColDef(),\n ...fields.map((field) =>\n makeColDef(field, tableSpecs[field], resolvedHiddenColIds, cellButtonAxisParams),\n ),\n ];\n\n // axes — taken directly from visible table (always present as part of join)\n const visibleAxes = collectVisibleAxes(visibleTableSpecs);\n\n // request indices: display fields + visible axes for row selection keys.\n const { requestIndices, axesResultIndices, fieldResultMapping } = buildRequestIndices(\n fields,\n visibleAxes.map(([idx]) => idx),\n specsToVisibleSpecsMapping,\n );\n\n let rowCount = -1;\n let lastParams: IServerSideGetRowsParams | undefined = undefined;\n const serverSideDatasource: IServerSideDatasource<PlAgDataTableV2Row> = {\n getRows: async (params: IServerSideGetRowsParams) => {\n if (stateGeneration !== generation.value) return params.fail();\n try {\n if (rowCount === -1) {\n const ptShape = await pfDriver.getShape(visibleTableHandle);\n if (stateGeneration !== generation.value || params.api.isDestroyed())\n return params.fail();\n rowCount = ptShape.rows;\n }\n\n if (rowCount == 0) {\n params.success({ rowData: [], rowCount });\n // Warning: AgGrid cannot show two overlays at once,\n // so first hide loading overlay, then show no rows overlay\n params.api.setGridOption(\"loading\", false);\n params.api.showNoRowsOverlay();\n return;\n }\n\n // If sort has changed - show skeletons instead of data\n if (lastParams && !isJsonEqual(lastParams.request.sortModel, params.request.sortModel)) {\n return params.success({ rowData: [], rowCount });\n }\n lastParams = params;\n\n let length = 0;\n let rowData: PlAgDataTableV2Row[] = [];\n if (\n rowCount > 0 &&\n params.request.startRow !== undefined &&\n params.request.endRow !== undefined\n ) {\n length = Math.min(rowCount, params.request.endRow) - params.request.startRow;\n if (length > 0) {\n const data = await pfDriver.getData(visibleTableHandle, requestIndices, {\n offset: params.request.startRow,\n length,\n });\n if (stateGeneration !== generation.value || params.api.isDestroyed())\n return params.fail();\n rowData = columns2rows(fields, data, fieldResultMapping, axesResultIndices);\n }\n }\n\n params.success({ rowData, rowCount });\n params.api.autoSizeColumns(\n params.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n params.api.setGridOption(\"loading\", false);\n dataRenderedTracker.resolve(params.api);\n } catch (error: unknown) {\n if (stateGeneration !== generation.value || params.api.isDestroyed()) return params.fail();\n params.api.setGridOption(\"loading\", true);\n params.fail();\n console.trace(error);\n }\n },\n };\n\n return {\n axesSpec: visibleAxes.map(([, { spec }]) => spec),\n columnDefs,\n serverSideDatasource,\n };\n}\n\nexport type PlAgCellButtonAxisParams = {\n showCellButtonForAxisId?: AxisId;\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n trigger: (key?: PTableKey) => void;\n};\n\n/**\n * Calculates column definition for a given p-table column\n */\nexport function makeColDef(\n iCol: number,\n spec: PTableColumnSpec,\n hiddenColIds: PlTableColumnIdJson[] | undefined,\n cellButtonAxisParams?: PlAgCellButtonAxisParams,\n): ColDef<PlAgDataTableV2Row, PTableValue | PTableHidden> {\n const colId = canonicalizeJson<PTableColumnSpec>(spec);\n const valueType = spec.type === \"axis\" ? spec.spec.type : spec.spec.valueType;\n const columnRenderingSpec = getColumnRenderingSpec(spec);\n const cellStyle: CellStyle = {};\n if (columnRenderingSpec.fontFamily) {\n if (columnRenderingSpec.fontFamily === \"monospace\") {\n cellStyle.fontFamily = \"Spline Sans Mono\";\n cellStyle.fontWeight = 300;\n } else {\n cellStyle.fontFamily = columnRenderingSpec.fontFamily;\n }\n }\n const headerName =\n readAnnotation(spec.spec, Annotation.Label)?.trim() ?? `Unlabeled ${spec.type} ${iCol}`;\n\n return {\n colId,\n mainMenuItems: defaultMainMenuItems,\n context: spec,\n field: `${iCol}`,\n headerName,\n lockPosition:\n spec.type === \"axis\" || (isLabelColumnSpec(spec.spec) && spec.spec.axesSpec.length === 1),\n hide: hiddenColIds !== undefined && hiddenColIds.includes(colId),\n valueFormatter: columnRenderingSpec.valueFormatter,\n headerComponent: PlAgColumnHeader,\n cellRendererSelector: cellButtonAxisParams?.showCellButtonForAxisId\n ? (params: ICellRendererParams) => {\n if (spec.type !== \"axis\") return;\n\n const axisId = (params.colDef?.context as PTableColumnSpec)?.id as AxisId;\n if (isJsonEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {\n return {\n component: PlAgTextAndButtonCell,\n params: {\n invokeRowsOnDoubleClick: cellButtonAxisParams.cellButtonInvokeRowsOnDoubleClick,\n onClick: (params: ICellRendererParams<PlAgDataTableV2Row>) => {\n cellButtonAxisParams.trigger(params.data?.axesKey);\n },\n },\n };\n }\n }\n : undefined,\n cellStyle,\n headerComponentParams: {\n type: ((): PlAgHeaderComponentType => {\n switch (valueType) {\n case ValueType.Int:\n case ValueType.Long:\n case ValueType.Float:\n case ValueType.Double:\n return \"Number\";\n case ValueType.String:\n case ValueType.Bytes:\n return \"Text\";\n default:\n throw Error(`unsupported data type: ${valueType}`);\n }\n })(),\n tooltip: readAnnotation(spec.spec, Annotation.Description)?.trim(),\n // info: readAnnotation(spec.spec, Annotation.Table.Info)?.trim(),\n } satisfies PlAgHeaderComponentParams,\n cellDataType: (() => {\n switch (valueType) {\n case ValueType.Int:\n case ValueType.Long:\n case ValueType.Float:\n case ValueType.Double:\n return \"number\";\n case ValueType.String:\n case ValueType.Bytes:\n return \"text\";\n default:\n throw Error(`unsupported data type: ${valueType}`);\n }\n })(),\n };\n}\n\n/** Build index mapping from full tableSpecs to their position in visibleTableSpecs (missing → -1). */\nfunction buildSpecsToVisibleSpecsMapping(\n tableSpecs: PTableColumnSpec[],\n visibleTableSpecs: PTableColumnSpec[],\n): Map<number, number> {\n const specId = (spec: PTableColumnSpec) =>\n canonicalizeJson<PTableColumnId>(getPTableColumnId(spec));\n const visibleSpecsMap = new Map(\n visibleTableSpecs.entries().map(([i, spec]) => [specId(spec), i] as const),\n );\n return new Map(\n tableSpecs.entries().map(([i, spec]) => {\n const visibleSpecIdx = visibleSpecsMap.get(specId(spec));\n return [i, isNil(visibleSpecIdx) ? -1 : visibleSpecIdx];\n }),\n );\n}\n\n/** Predicate that returns true when an axis is one of the sheet partition axes. */\nfunction createPartitionedAxisPredicate(sheets: PlDataTableSheet[]): (axisId: AxisId) => boolean {\n const sheetAxesIds = sheets.map((sheet) => getAxisId(sheet.axis));\n return (axisId) => sheetAxesIds.some((id) => matchAxisId(id, axisId));\n}\n\n/**\n * Collect label columns (skipping partitioned axes and duplicates) and return a\n * lookup function that resolves labeled axisId → label column index (or -1).\n */\nfunction collectLabelColumnsByAxis(\n tableSpecs: PTableColumnSpec[],\n isPartitionedAxis: (axisId: AxisId) => boolean,\n): (axisId: AxisId) => number {\n const labelColumns: { axisId: AxisId; labelColumnIdx: number }[] = [];\n for (const [i, spec] of tableSpecs.entries()) {\n if (spec.type !== \"column\" || !isLabelColumnSpec(spec.spec)) continue;\n const labeledAxisId = getAxisId(spec.spec.axesSpec[0]);\n if (isPartitionedAxis(labeledAxisId)) continue;\n if (labelColumns.some((info) => matchAxisId(info.axisId, labeledAxisId))) {\n console.warn(`multiple label columns match axisId: ${JSON.stringify(labeledAxisId)}`);\n continue;\n }\n labelColumns.push({ axisId: labeledAxisId, labelColumnIdx: i });\n }\n return (axisId) =>\n labelColumns.find((info) => matchAxisId(info.axisId, axisId))?.labelColumnIdx ?? -1;\n}\n\n/** Indices of columns to display: drop partitioned axes, label/linker columns, hidden columns. */\nfunction selectDisplayableIndices(\n tableSpecs: PTableColumnSpec[],\n isPartitionedAxis: (axisId: AxisId) => boolean,\n getLabelColumnIndex: (axisId: AxisId) => number,\n): number[] {\n return tableSpecs\n .entries()\n .filter(([, spec]) => {\n switch (spec.type) {\n case \"axis\":\n return (\n !(getLabelColumnIndex(spec.id) > -1 ? true : isColumnHidden(spec.spec)) &&\n !isPartitionedAxis(spec.id)\n );\n case \"column\":\n return !isColumnHidden(spec.spec) && !isLinkerColumnSpec(spec.spec);\n }\n })\n .map(([i]) => i)\n .toArray();\n}\n\n/** Sort: axes first, then columns by OrderPriority annotation (higher priority = further left). */\nfunction sortIndicesByTypeAndPriority(indices: number[], tableSpecs: PTableColumnSpec[]): number[] {\n const priorityOf = (i: number): number => {\n const spec = tableSpecs[i];\n const prior =\n spec.type === \"axis\" || isLabelColumnSpec(spec.spec)\n ? Infinity\n : Number(readAnnotationJson(spec.spec, Annotation.Table.OrderPriority));\n\n return isNaN(prior) ? 0 : prior;\n };\n return [...indices].sort((a, b) => priorityOf(b) - priorityOf(a));\n}\n\n/** Default hidden col ids built from columns marked with the Optional annotation. */\nfunction computeDefaultHiddenColIds(\n fields: number[],\n tableSpecs: PTableColumnSpec[],\n): PlTableColumnIdJson[] {\n return fields.reduce<PlTableColumnIdJson[]>((acc, field) => {\n const spec = tableSpecs[field];\n return spec.type === \"column\" && isColumnOptional(spec.spec)\n ? [...acc, canonicalizeJson<PTableColumnSpec>(spec)]\n : acc;\n }, []);\n}\n\n/** Extract axis indices and specs from the visible table (always present as part of join). */\nfunction collectVisibleAxes(\n visibleTableSpecs: PTableColumnSpec[],\n): [number, PTableColumnSpecAxis][] {\n return visibleTableSpecs\n .entries()\n .filter((entry): entry is [number, PTableColumnSpecAxis] => entry[1].type === \"axis\")\n .toArray();\n}\n\n/**\n * Compose request indices for the visible table:\n * non-hidden display fields first, then visible axes (deduplicated).\n * Returns fieldResultMapping (display field → position in requestIndices, -1 if not requested)\n * and axesResultIndices (visible axis → position in requestIndices).\n */\nfunction buildRequestIndices(\n indices: number[],\n visibleAxesIndices: number[],\n specsToVisibleSpecsMapping: Map<number, number>,\n): {\n requestIndices: number[];\n axesResultIndices: number[];\n fieldResultMapping: number[];\n} {\n const resolved = indices.map((displayField) => {\n const idx = specsToVisibleSpecsMapping.get(displayField);\n return isNil(idx) || idx === -1 ? null : idx;\n });\n const requestIndices = uniq([\n ...resolved.filter((v): v is number => v !== null),\n ...visibleAxesIndices,\n ]);\n const fieldResultMapping = resolved.map((v) => (v === null ? -1 : requestIndices.indexOf(v)));\n const axesResultIndices = visibleAxesIndices.map((vi) => requestIndices.indexOf(vi));\n\n return { requestIndices, axesResultIndices, fieldResultMapping };\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAS,EACP,GACA,GACA,GACA,GACsB;CACtB,IAAM,IAAgC,EAAE;AACxC,MAAK,IAAI,IAAS,GAAG,IAAS,EAAQ,GAAG,KAAK,QAAQ,EAAE,GAAQ;EAC9D,IAAM,IAAqB,EAAkB,KAAK,MAAO,EAAY,EAAQ,IAAK,EAAO,CAAC,EACpF,IAAK,EAA+B,EAAQ,EAC5C,IAAM,EAAO,QAChB,GAAK,GAAO,OACX,EAAI,EAAM,UAAU,IAClB,EAAmB,OAAY,KAC3B,IACA,EAAY,EAAQ,EAAmB,KAAU,EAAO,EACvD,IAET;GAAE;GAAI;GAAS,CAChB;AAED,IAAQ,KAAK,EAAI;;AAEnB,QAAO;;AAIT,eAAsB,EAAqB,EACzC,eACA,aACA,WACA,oBACA,uBACA,wBACA,iBACA,2BAcA;CACA,IAAM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K,KAAK,GAChD,WACA,OAAO,EAAmB,EAAK,MAAM,EAAW,MAAM,cAAc,CAAC;AAE3E,SAAO,MAAM,EAAM,GAAG,IAAI;;AAE5B,QAAO,CAAC,GAAG,EAAQ,CAAC,MAAM,GAAG,MAAM,EAAW,EAAE,GAAG,EAAW,EAAE,CAAC;;AAInE,SAAS,EACP,GACA,GACuB;AACvB,QAAO,EAAO,QAA+B,GAAK,MAAU;EAC1D,IAAM,IAAO,EAAW;AACxB,SAAO,EAAK,SAAS,YAAY,EAAiB,EAAK,KAAK,GACxD,CAAC,GAAG,GAAK,EAAmC,EAAK,CAAC,GAClD;IACH,EAAE,CAAC;;AAIR,SAAS,EACP,GACkC;AAClC,QAAO,EACJ,SAAS,CACT,QAAQ,MAAmD,EAAM,GAAG,SAAS,OAAO,CACpF,SAAS;;AASd,SAAS,EACP,GACA,GACA,GAKA;CACA,IAAM,IAAW,EAAQ,KAAK,MAAiB;EAC7C,IAAM,IAAM,EAA2B,IAAI,EAAa;AACxD,SAAO,EAAM,EAAI,IAAI,MAAQ,KAAK,OAAO;GACzC,EACI,IAAiB,EAAK,CAC1B,GAAG,EAAS,QAAQ,MAAmB,MAAM,KAAK,EAClD,GAAG,EACJ,CAAC,EACI,IAAqB,EAAS,KAAK,MAAO,MAAM,OAAO,KAAK,EAAe,QAAQ,EAAE,CAAE;AAG7F,QAAO;EAAE;EAAgB,mBAFC,EAAmB,KAAK,MAAO,EAAe,QAAQ,EAAG,CAAC;EAExC;EAAoB"}
1
+ {"version":3,"file":"table-source-v2.js","names":[],"sources":["../../../../src/components/PlAgDataTable/sources/table-source-v2.ts"],"sourcesContent":["import type {\n AxesSpec,\n PTableColumnId,\n PTableColumnSpecAxis,\n PTableColumnSpecColumn,\n PTableHandle,\n PTableValue,\n} from \"@platforma-sdk/model\";\nimport {\n canonicalizeJson,\n getAxisId,\n pTableValue,\n type PFrameDriver,\n type PlDataTableSheet,\n type PTableVector,\n type AxisId,\n type PTableColumnSpec,\n type PTableKey,\n type PlTableColumnIdJson,\n isLabelColumn as isLabelColumnSpec,\n isLinkerColumn as isLinkerColumnSpec,\n isColumnHidden,\n isColumnOptional,\n matchAxisId,\n readAnnotation,\n readAnnotationJson,\n Annotation,\n ValueType,\n getPTableColumnId,\n} from \"@platforma-sdk/model\";\nimport type {\n CellStyle,\n ColDef,\n GridApi,\n ICellRendererParams,\n IServerSideDatasource,\n IServerSideGetRowsParams,\n ManagedGridOptions,\n} from \"ag-grid-enterprise\";\nimport type { PlAgHeaderComponentParams, PlAgHeaderComponentType } from \"../../PlAgColumnHeader\";\nimport { PlAgColumnHeader } from \"../../PlAgColumnHeader\";\nimport { PlAgTextAndButtonCell } from \"../../PlAgTextAndButtonCell\";\nimport type { PlAgDataTableV2Row, PlTableRowId } from \"../types\";\nimport { PTableHidden } from \"./common\";\nimport { defaultMainMenuItems } from \"./menu-items\";\nimport { makeRowNumberColDef, PlAgDataTableRowNumberColId } from \"./row-number\";\nimport { getColumnRenderingSpec } from \"./value-rendering\";\nimport type { Ref } from \"vue\";\nimport { isJsonEqual } from \"@milaboratories/helpers\";\nimport type { DeferredCircular } from \"./focus-row\";\nimport { isNil, uniq } from \"es-toolkit\";\n\nexport function isLabelColumn(column: PTableColumnSpec): column is PTableColumnSpecColumn {\n return column.type === \"column\" && isLabelColumnSpec(column.spec);\n}\n\n/** Convert columnar data from the driver to rows, used by ag-grid */\nfunction columns2rows(\n fields: number[],\n columns: PTableVector[],\n fieldResultMapping: number[],\n axesResultIndices: number[],\n): PlAgDataTableV2Row[] {\n const rowData: PlAgDataTableV2Row[] = [];\n for (let rowIdx = 0; rowIdx < columns[0].data.length; ++rowIdx) {\n const axesKey: PTableKey = axesResultIndices.map((ri) => pTableValue(columns[ri], rowIdx));\n const id = canonicalizeJson<PlTableRowId>(axesKey);\n const row = fields.reduce<PlAgDataTableV2Row>(\n (acc, field, colIdx) => {\n acc[field.toString() as `${number}`] =\n fieldResultMapping[colIdx] === -1\n ? PTableHidden\n : pTableValue(columns[fieldResultMapping[colIdx]], rowIdx);\n return acc;\n },\n { id, axesKey },\n );\n\n rowData.push(row);\n }\n return rowData;\n}\n\n/** Calculate GridOptions for selected p-table data source */\nexport async function calculateGridOptions({\n generation,\n pfDriver,\n sheets,\n fullTableHandle,\n visibleTableHandle,\n dataRenderedTracker,\n hiddenColIds,\n cellButtonAxisParams,\n}: {\n sheets: PlDataTableSheet[];\n pfDriver: PFrameDriver;\n generation: Ref<number>;\n fullTableHandle: PTableHandle;\n visibleTableHandle: PTableHandle;\n dataRenderedTracker: DeferredCircular<GridApi<PlAgDataTableV2Row>>;\n hiddenColIds?: PlTableColumnIdJson[];\n cellButtonAxisParams?: PlAgCellButtonAxisParams;\n}): Promise<\n Pick<ManagedGridOptions<PlAgDataTableV2Row>, \"columnDefs\" | \"serverSideDatasource\"> & {\n axesSpec: AxesSpec;\n }\n> {\n const stateGeneration = generation.value;\n\n // get specs of the full table\n const [tableSpecs, visibleTableSpecs] = await Promise.all([\n pfDriver.getSpec(fullTableHandle),\n pfDriver.getSpec(visibleTableHandle),\n ]);\n\n if (stateGeneration !== generation.value) throw new Error(\"table state generation changed\");\n\n // index mapping from full specs to visible subset (hidden columns → -1)\n const specsToVisibleSpecsMapping = buildSpecsToVisibleSpecsMapping(tableSpecs, visibleTableSpecs);\n\n const isPartitionedAxis = createPartitionedAxisPredicate(sheets);\n\n // label columns indexed by labeled axis (used for displayability filter)\n const getLabelColumnIndex = collectLabelColumnsByAxis(tableSpecs, isPartitionedAxis);\n\n // displayable column indices ordered: axes first, then columns by OrderPriority\n const fields = sortIndicesByTypeAndPriority(\n selectDisplayableIndices(tableSpecs, isPartitionedAxis, getLabelColumnIndex),\n tableSpecs,\n );\n\n // default hidden columns derived from Optional annotation when no saved state\n const resolvedHiddenColIds = hiddenColIds ?? computeDefaultHiddenColIds(fields, tableSpecs);\n\n const columnDefs: ColDef<PlAgDataTableV2Row, PTableValue | PTableHidden>[] = [\n makeRowNumberColDef(),\n ...fields.map((field) =>\n makeColDef(field, tableSpecs[field], resolvedHiddenColIds, cellButtonAxisParams),\n ),\n ];\n\n // axes — taken directly from visible table (always present as part of join)\n const visibleAxes = collectVisibleAxes(visibleTableSpecs);\n\n // request indices: display fields + visible axes for row selection keys.\n const { requestIndices, axesResultIndices, fieldResultMapping } = buildRequestIndices(\n fields,\n visibleAxes.map(([idx]) => idx),\n specsToVisibleSpecsMapping,\n );\n\n let rowCount = -1;\n let lastParams: IServerSideGetRowsParams | undefined = undefined;\n const serverSideDatasource: IServerSideDatasource<PlAgDataTableV2Row> = {\n getRows: async (params: IServerSideGetRowsParams) => {\n if (stateGeneration !== generation.value) return params.fail();\n try {\n if (rowCount === -1) {\n const ptShape = await pfDriver.getShape(visibleTableHandle);\n if (stateGeneration !== generation.value || params.api.isDestroyed())\n return params.fail();\n rowCount = ptShape.rows;\n }\n\n if (rowCount == 0) {\n params.success({ rowData: [], rowCount });\n // Warning: AgGrid cannot show two overlays at once,\n // so first hide loading overlay, then show no rows overlay\n params.api.setGridOption(\"loading\", false);\n params.api.showNoRowsOverlay();\n return;\n }\n\n // If sort has changed - show skeletons instead of data\n if (lastParams && !isJsonEqual(lastParams.request.sortModel, params.request.sortModel)) {\n return params.success({ rowData: [], rowCount });\n }\n lastParams = params;\n\n let length = 0;\n let rowData: PlAgDataTableV2Row[] = [];\n if (\n rowCount > 0 &&\n params.request.startRow !== undefined &&\n params.request.endRow !== undefined\n ) {\n length = Math.min(rowCount, params.request.endRow) - params.request.startRow;\n if (length > 0) {\n const data = await pfDriver.getData(visibleTableHandle, requestIndices, {\n offset: params.request.startRow,\n length,\n });\n if (stateGeneration !== generation.value || params.api.isDestroyed())\n return params.fail();\n rowData = columns2rows(fields, data, fieldResultMapping, axesResultIndices);\n }\n }\n\n params.success({ rowData, rowCount });\n params.api.autoSizeColumns(\n params.api\n .getAllDisplayedColumns()\n .filter((column) => column.getColId() !== PlAgDataTableRowNumberColId),\n );\n params.api.setGridOption(\"loading\", false);\n dataRenderedTracker.resolve(params.api);\n } catch (error: unknown) {\n if (stateGeneration !== generation.value || params.api.isDestroyed()) return params.fail();\n params.api.setGridOption(\"loading\", true);\n params.fail();\n console.trace(error);\n }\n },\n };\n\n return {\n axesSpec: visibleAxes.map(([, { spec }]) => spec),\n columnDefs,\n serverSideDatasource,\n };\n}\n\nexport type PlAgCellButtonAxisParams = {\n showCellButtonForAxisId?: AxisId;\n cellButtonInvokeRowsOnDoubleClick?: boolean;\n trigger: (key?: PTableKey) => void;\n};\n\n/**\n * Calculates column definition for a given p-table column\n */\nexport function makeColDef(\n iCol: number,\n spec: PTableColumnSpec,\n hiddenColIds: PlTableColumnIdJson[] | undefined,\n cellButtonAxisParams?: PlAgCellButtonAxisParams,\n): ColDef<PlAgDataTableV2Row, PTableValue | PTableHidden> {\n const colId = canonicalizeJson<PTableColumnSpec>(spec);\n const valueType = spec.type === \"axis\" ? spec.spec.type : spec.spec.valueType;\n const columnRenderingSpec = getColumnRenderingSpec(spec);\n const cellStyle: CellStyle = {};\n if (columnRenderingSpec.fontFamily) {\n if (columnRenderingSpec.fontFamily === \"monospace\") {\n cellStyle.fontFamily = \"Spline Sans Mono\";\n cellStyle.fontWeight = 300;\n } else {\n cellStyle.fontFamily = columnRenderingSpec.fontFamily;\n }\n }\n const headerName =\n readAnnotation(spec.spec, Annotation.Label)?.trim() ?? `Unlabeled ${spec.type} ${iCol}`;\n\n return {\n colId,\n mainMenuItems: defaultMainMenuItems,\n context: spec,\n field: `${iCol}`,\n headerName,\n lockPosition:\n spec.type === \"axis\" || (isLabelColumnSpec(spec.spec) && spec.spec.axesSpec.length === 1),\n hide: hiddenColIds !== undefined && hiddenColIds.includes(colId),\n valueFormatter: columnRenderingSpec.valueFormatter,\n headerComponent: PlAgColumnHeader,\n cellRendererSelector: cellButtonAxisParams?.showCellButtonForAxisId\n ? () => {\n const axisId =\n spec.type === \"axis\"\n ? spec.id\n : isLabelColumnSpec(spec.spec) && spec.spec.axesSpec.length === 1\n ? getAxisId(spec.spec.axesSpec[0])\n : undefined;\n if (axisId && isJsonEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {\n return {\n component: PlAgTextAndButtonCell,\n params: {\n invokeRowsOnDoubleClick: cellButtonAxisParams.cellButtonInvokeRowsOnDoubleClick,\n onClick: (params: ICellRendererParams<PlAgDataTableV2Row>) => {\n cellButtonAxisParams.trigger(params.data?.axesKey);\n },\n },\n };\n }\n }\n : undefined,\n cellStyle,\n headerComponentParams: {\n type: ((): PlAgHeaderComponentType => {\n switch (valueType) {\n case ValueType.Int:\n case ValueType.Long:\n case ValueType.Float:\n case ValueType.Double:\n return \"Number\";\n case ValueType.String:\n case ValueType.Bytes:\n return \"Text\";\n default:\n throw Error(`unsupported data type: ${valueType}`);\n }\n })(),\n tooltip: readAnnotation(spec.spec, Annotation.Description)?.trim(),\n // info: readAnnotation(spec.spec, Annotation.Table.Info)?.trim(),\n } satisfies PlAgHeaderComponentParams,\n cellDataType: (() => {\n switch (valueType) {\n case ValueType.Int:\n case ValueType.Long:\n case ValueType.Float:\n case ValueType.Double:\n return \"number\";\n case ValueType.String:\n case ValueType.Bytes:\n return \"text\";\n default:\n throw Error(`unsupported data type: ${valueType}`);\n }\n })(),\n };\n}\n\n/** Build index mapping from full tableSpecs to their position in visibleTableSpecs (missing → -1). */\nfunction buildSpecsToVisibleSpecsMapping(\n tableSpecs: PTableColumnSpec[],\n visibleTableSpecs: PTableColumnSpec[],\n): Map<number, number> {\n const specId = (spec: PTableColumnSpec) =>\n canonicalizeJson<PTableColumnId>(getPTableColumnId(spec));\n const visibleSpecsMap = new Map(\n visibleTableSpecs.entries().map(([i, spec]) => [specId(spec), i] as const),\n );\n return new Map(\n tableSpecs.entries().map(([i, spec]) => {\n const visibleSpecIdx = visibleSpecsMap.get(specId(spec));\n return [i, isNil(visibleSpecIdx) ? -1 : visibleSpecIdx];\n }),\n );\n}\n\n/** Predicate that returns true when an axis is one of the sheet partition axes. */\nfunction createPartitionedAxisPredicate(sheets: PlDataTableSheet[]): (axisId: AxisId) => boolean {\n const sheetAxesIds = sheets.map((sheet) => getAxisId(sheet.axis));\n return (axisId) => sheetAxesIds.some((id) => matchAxisId(id, axisId));\n}\n\n/**\n * Collect label columns (skipping partitioned axes and duplicates) and return a\n * lookup function that resolves labeled axisId → label column index (or -1).\n */\nfunction collectLabelColumnsByAxis(\n tableSpecs: PTableColumnSpec[],\n isPartitionedAxis: (axisId: AxisId) => boolean,\n): (axisId: AxisId) => number {\n const labelColumns: { axisId: AxisId; labelColumnIdx: number }[] = [];\n for (const [i, spec] of tableSpecs.entries()) {\n if (spec.type !== \"column\" || !isLabelColumnSpec(spec.spec)) continue;\n const labeledAxisId = getAxisId(spec.spec.axesSpec[0]);\n if (isPartitionedAxis(labeledAxisId)) continue;\n if (labelColumns.some((info) => matchAxisId(info.axisId, labeledAxisId))) {\n console.warn(`multiple label columns match axisId: ${JSON.stringify(labeledAxisId)}`);\n continue;\n }\n labelColumns.push({ axisId: labeledAxisId, labelColumnIdx: i });\n }\n return (axisId) =>\n labelColumns.find((info) => matchAxisId(info.axisId, axisId))?.labelColumnIdx ?? -1;\n}\n\n/** Indices of columns to display: drop partitioned axes, label/linker columns, hidden columns. */\nfunction selectDisplayableIndices(\n tableSpecs: PTableColumnSpec[],\n isPartitionedAxis: (axisId: AxisId) => boolean,\n getLabelColumnIndex: (axisId: AxisId) => number,\n): number[] {\n return tableSpecs\n .entries()\n .filter(([, spec]) => {\n switch (spec.type) {\n case \"axis\":\n return (\n !(getLabelColumnIndex(spec.id) > -1 ? true : isColumnHidden(spec.spec)) &&\n !isPartitionedAxis(spec.id)\n );\n case \"column\":\n return !isColumnHidden(spec.spec) && !isLinkerColumnSpec(spec.spec);\n }\n })\n .map(([i]) => i)\n .toArray();\n}\n\n/** Sort: axes first, then columns by OrderPriority annotation (higher priority = further left). */\nfunction sortIndicesByTypeAndPriority(indices: number[], tableSpecs: PTableColumnSpec[]): number[] {\n const priorityOf = (i: number): number => {\n const spec = tableSpecs[i];\n const prior =\n spec.type === \"axis\" || isLabelColumnSpec(spec.spec)\n ? Infinity\n : Number(readAnnotationJson(spec.spec, Annotation.Table.OrderPriority));\n\n return isNaN(prior) ? 0 : prior;\n };\n return [...indices].sort((a, b) => priorityOf(b) - priorityOf(a));\n}\n\n/** Default hidden col ids built from columns marked with the Optional annotation. */\nfunction computeDefaultHiddenColIds(\n fields: number[],\n tableSpecs: PTableColumnSpec[],\n): PlTableColumnIdJson[] {\n return fields.reduce<PlTableColumnIdJson[]>((acc, field) => {\n const spec = tableSpecs[field];\n return spec.type === \"column\" && isColumnOptional(spec.spec)\n ? [...acc, canonicalizeJson<PTableColumnSpec>(spec)]\n : acc;\n }, []);\n}\n\n/** Extract axis indices and specs from the visible table (always present as part of join). */\nfunction collectVisibleAxes(\n visibleTableSpecs: PTableColumnSpec[],\n): [number, PTableColumnSpecAxis][] {\n return visibleTableSpecs\n .entries()\n .filter((entry): entry is [number, PTableColumnSpecAxis] => entry[1].type === \"axis\")\n .toArray();\n}\n\n/**\n * Compose request indices for the visible table:\n * non-hidden display fields first, then visible axes (deduplicated).\n * Returns fieldResultMapping (display field → position in requestIndices, -1 if not requested)\n * and axesResultIndices (visible axis → position in requestIndices).\n */\nfunction buildRequestIndices(\n indices: number[],\n visibleAxesIndices: number[],\n specsToVisibleSpecsMapping: Map<number, number>,\n): {\n requestIndices: number[];\n axesResultIndices: number[];\n fieldResultMapping: number[];\n} {\n const resolved = indices.map((displayField) => {\n const idx = specsToVisibleSpecsMapping.get(displayField);\n return isNil(idx) || idx === -1 ? null : idx;\n });\n const requestIndices = uniq([\n ...resolved.filter((v): v is number => v !== null),\n ...visibleAxesIndices,\n ]);\n const fieldResultMapping = resolved.map((v) => (v === null ? -1 : requestIndices.indexOf(v)));\n const axesResultIndices = visibleAxesIndices.map((vi) => requestIndices.indexOf(vi));\n\n return { requestIndices, axesResultIndices, fieldResultMapping };\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAS,EACP,GACA,GACA,G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EACI,IAAiB,EAAK,CAC1B,GAAG,EAAS,QAAQ,MAAmB,MAAM,KAAK,EAClD,GAAG,EACJ,CAAC,EACI,IAAqB,EAAS,KAAK,MAAO,MAAM,OAAO,KAAK,EAAe,QAAQ,EAAE,CAAE;AAG7F,QAAO;EAAE;EAAgB,mBAFC,EAAmB,KAAK,MAAO,EAAe,QAAQ,EAAG,CAAC;EAExC;EAAoB"}
@@ -1,5 +1,5 @@
1
1
  import { Mutable } from '@milaboratories/helpers';
2
- import { NavigationState, BlockOutputsBase, BlockStateV3, PlatformaV3, ValueWithUTag, AuthorMarker, PlatformaExtended, InferPluginHandles, UiServices as AllUiServices } from '@platforma-sdk/model';
2
+ import { NavigationState, BlockOutputsBase, BlockStateV3, PlatformaV3, ValueWithUTag, AuthorMarker, PlatformaExtended, InferPluginUiEntries, UiServices as AllUiServices } from '@platforma-sdk/model';
3
3
  import { OutputValues, OutputErrors, AppSettings } from '../types';
4
4
  import { PluginAccess } from '../composition/usePlugin';
5
5
  export declare const patchPoolingDelay = 150;
@@ -28,11 +28,11 @@ export declare function createAppV3<Data = unknown, Args = unknown, Outputs exte
28
28
  };
29
29
  closedRef: boolean;
30
30
  snapshot: {
31
- outputs: Partial<Outputs>;
31
+ outputs: Partial<Readonly<Outputs>>;
32
32
  blockStorage: unknown;
33
33
  navigationState: NavigationState<Href>;
34
34
  };
35
- plugins: import('vue').UnwrapRef<InferPluginHandles<Plugins>>;
35
+ plugins: import('vue').UnwrapRef<InferPluginUiEntries<Plugins>>;
36
36
  services: import('vue').UnwrapRef<import('vue').Raw<UiServices>>;
37
37
  queryParams: import('../types').ParseQuery<Href>;
38
38
  href: Href;
@@ -1 +1 @@
1
- {"version":3,"file":"createAppV3.d.ts","sourceRoot":"","sources":["../../src/internal/createAppV3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,YAAY,E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AAC,CAAC"}
@@ -126,7 +126,24 @@ function C(C, w, T) {
126
126
  } }, ee = {
127
127
  closedRef: A,
128
128
  snapshot: R,
129
- plugins: Object.fromEntries(w.blockModelInfo.pluginIds.map((e) => [e, { handle: e }])),
129
+ plugins: Object.fromEntries(w.blockModelInfo.pluginIds.map((e) => {
130
+ let t = w.blockModelInfo.pluginPublicOutputs?.[e] ?? {}, n = Object.keys(t);
131
+ if (n.length === 0) return [e, {
132
+ handle: e,
133
+ publicOutputs: {}
134
+ }];
135
+ let r = Q.getOrCreatePluginState(e);
136
+ return [e, {
137
+ handle: e,
138
+ publicOutputs: f(Object.fromEntries(n.map((e) => {
139
+ let { getter: n } = t[e];
140
+ return [e, u(() => {
141
+ let e = r.model.data;
142
+ return e == null ? void 0 : n(e);
143
+ })];
144
+ })))
145
+ }];
146
+ })),
130
147
  services: d(X),
131
148
  queryParams: u(() => a(R.value.navigationState.href)),
132
149
  href: u(() => R.value.navigationState.href),
@@ -1 +1 @@
1
- {"version":3,"file":"createAppV3.js","names":[],"sources":["../../src/internal/createAppV3.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from \"@milaboratories/helpers\";\nimport type { Mutable } from \"@milaboratories/helpers\";\nimport type {\n NavigationState,\n BlockOutputsBase,\n BlockStateV3,\n PlatformaV3,\n ValueWithUTag,\n AuthorMarker,\n PlatformaExtended,\n InferPluginHandles,\n PluginHandle,\n InferFactoryData,\n InferFactoryOutputs,\n PluginFactoryLike,\n UiServices as AllUiServices,\n InferFactoryUiServices,\n} from \"@platforma-sdk/model\";\nimport {\n hasAbortError,\n unwrapResult,\n deriveDataFromStorage,\n getPluginData,\n isPluginOutputKey,\n pluginOutputPrefix,\n} from \"@platforma-sdk/model\";\nimport type { Ref } from \"vue\";\nimport { reactive, computed, ref, markRaw } from \"vue\";\nimport type { OutputValues, OutputErrors, AppSettings } from \"../types\";\nimport { parseQuery } from \"../urls\";\nimport { ensureOutputHasStableFlag, MultiError } from \"../utils\";\nimport { applyPatch } from \"fast-json-patch\";\nimport { UpdateSerializer } from \"./UpdateSerializer\";\nimport { watchIgnorable } from \"@vueuse/core\";\nimport type { PluginState, PluginAccess } from \"../composition/usePlugin\";\nimport { logDebug, logError } from \"./utils\";\nimport { getServices } from \"./getServices\";\n\nexport const patchPoolingDelay = 150;\n\n/** Internal per-plugin state with reconciliation support. */\ninterface InternalPluginState<\n Data = unknown,\n Outputs = unknown,\n Services = Record<string, unknown>,\n> extends PluginState<Data, Outputs, Services> {\n readonly ignoreUpdates: (fn: () => void) => void;\n}\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\n});\n\n/**\n * Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.\n *\n * @template Args - The type of arguments used in the application.\n * @template Outputs - The type of block outputs extending `BlockOutputsBase`.\n * @template Data - The type of the block data.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n>(\n state: ValueWithUTag<BlockStateV3<Data, Outputs, Href>>,\n platforma: PlatformaExtended<PlatformaV3<Data, Args, Outputs, Href, Plugins, UiServices>>,\n settings: AppSettings,\n) {\n const debug = settings.debug ? logDebug : () => {};\n const error = logError;\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug(\"nextAuthorMarker\", data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setDataQueue = new UpdateSerializer({ debounceSpan });\n const pluginDataQueues = new Map<PluginHandle, UpdateSerializer>();\n const getPluginDataQueue = (handle: PluginHandle): UpdateSerializer => {\n let queue = pluginDataQueues.get(handle);\n if (!queue) {\n queue = new UpdateSerializer({ debounceSpan });\n pluginDataQueues.set(handle, queue);\n }\n return queue;\n };\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n\n /** Lazily-created per-plugin reactive states. */\n const pluginStates = new Map<PluginHandle, InternalPluginState>();\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n outputs: Partial<Outputs>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n outputs: Partial<Outputs>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>;\n\n const updateData = async (value: Data) => {\n return platforma.mutateStorage({ operation: \"update-block-data\", value }, nextAuthorMarker());\n };\n\n const updatePluginData = async (handle: PluginHandle, value: unknown) => {\n return platforma.mutateStorage(\n { operation: \"update-plugin-data\", pluginId: handle, value },\n nextAuthorMarker(),\n );\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, outputWithStatus]) =>\n platforma.blockModelInfo.outputs[k]?.withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [\n k,\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined,\n ],\n );\n return Object.fromEntries(entries);\n });\n\n const outputErrors = computed<OutputErrors<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, vOrErr]) => [\n k,\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined,\n ]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n apiVersion: 3,\n error: \"\",\n model: {\n data: deepClone(deriveDataFromStorage<Data>(snapshot.value.blockStorage)) as Data,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n data: Data;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug(\"setDataQueue appModel.model, data\", newData.data);\n setDataQueue.run(() => updateData(newData.data).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: { data: Data }) => {\n debug(\"updateAppModel\", newData);\n appModel.model.data = deepClone(newData.data) as Data;\n };\n\n (async () => {\n window.addEventListener(\"beforeunload\", () => {\n closedRef.value = true;\n platforma\n .dispose()\n .then(unwrapResult)\n .catch((err) => {\n error(\"platforma error in dispose\", err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug(\"patches.length\", patches.value.length);\n debug(\"uTagRef.value\", uTagRef.value);\n debug(\"patches.uTag\", patches.uTag);\n debug(\"patches.author\", patches.author);\n debug(\"data.author\", data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug(\"got external changes, applying them to the snapshot\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });\n // Reconcile plugin data from external source\n for (const [handle, pluginState] of pluginStates) {\n pluginState.ignoreUpdates(() => {\n pluginState.model.data = deepClone(\n getPluginData(snapshot.value.blockStorage, handle),\n );\n });\n }\n data.isExternalSnapshot = isAuthorChanged;\n });\n } else {\n // Mutable behavior\n debug(\"outputs changed\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\n });\n }\n\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n } catch (err) {\n if (hasAbortError(err)) {\n debug(\"patches loop aborted\");\n closedRef.value = true;\n } else {\n error(\"error in patches loop\", err);\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n }\n }\n })();\n\n const cloneData = () => deepClone(appModel.model.data) as Data;\n const cloneNavigationState = () =>\n deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneData,\n cloneNavigationState,\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateData(cb: (data: Data) => Data): Promise<boolean> {\n const newData = cb(cloneData());\n debug(\"updateData\", newData);\n appModel.model.data = newData;\n return setDataQueue.run(() => updateData(newData).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n const allQueues = [\n setDataQueue.allSettled(),\n ...Array.from(pluginDataQueues.values()).map((q) => q.allSettled()),\n ];\n await Promise.all(allQueues);\n },\n };\n\n const services = getServices<UiServices>({ platforma });\n\n /** Creates a lazily-cached per-plugin reactive state. */\n const createPluginState = <F extends PluginFactoryLike>(\n handle: PluginHandle<F>,\n ): InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>> => {\n const prefix = pluginOutputPrefix(handle);\n\n const pluginOutputs = computed(() => {\n const result: Record<string, unknown> = {};\n for (const [key, outputWithStatus] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n const outputKey = key.slice(prefix.length);\n if (platforma.blockModelInfo.outputs[key]?.withStatus) {\n result[outputKey] = outputWithStatus\n ? ensureOutputHasStableFlag(outputWithStatus)\n : undefined;\n } else {\n result[outputKey] =\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined;\n }\n }\n return result;\n });\n\n const pluginOutputErrors = computed(() => {\n const result: Record<string, Error | undefined> = {};\n for (const [key, vOrErr] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n result[key.slice(prefix.length)] =\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined;\n }\n return result;\n });\n\n const pluginModel = reactive({\n data: deepClone(getPluginData(snapshot.value.blockStorage, handle)),\n outputs: pluginOutputs,\n outputErrors: pluginOutputErrors,\n }) as InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>>[\"model\"];\n\n const { ignoreUpdates } = watchIgnorable(\n () => pluginModel.data,\n (newData) => {\n if (newData === undefined) return;\n debug(\"plugin setData\", handle, newData);\n getPluginDataQueue(handle).run(() =>\n updatePluginData(handle, deepClone(newData)).then(unwrapResult),\n );\n },\n { deep: true },\n );\n\n return {\n model: pluginModel,\n services: markRaw(services),\n ignoreUpdates,\n };\n };\n\n /** Plugin internals — provided via separate injection key, not exposed on useApp(). */\n const pluginAccess: PluginAccess = {\n getOrCreatePluginState<F extends PluginFactoryLike>(handle: PluginHandle<F>) {\n const existing = pluginStates.get(handle);\n if (existing) {\n return existing as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n }\n const state = createPluginState(handle);\n pluginStates.set(handle, state);\n return state as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n },\n };\n\n const plugins = Object.fromEntries(\n platforma.blockModelInfo.pluginIds.map((id) => [id, { handle: id }]),\n ) as InferPluginHandles<Plugins>;\n\n const getters = {\n closedRef,\n snapshot,\n plugins,\n services: markRaw(services),\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() =>\n Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok),\n ),\n };\n\n const app = Object.assign(reactive(Object.assign(appModel, getters)), methods);\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n return { app, pluginAccess };\n}\n\nexport type BaseAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n> = ReturnType<typeof createAppV3<Data, Args, Outputs, Href, Plugins, UiServices>>[\"app\"];\n"],"mappings":";;;;;;;;;;;;;AAiDA,IAAa,KAA0B,OAAoD;CACzF,UAAU,GAAQ,YAAY,GAAU;CACxC,eAAe,GAAQ,gBAAgB,KAAK;CAC7C;AAgBD,SAAgB,EAQd,GACA,GACA,GACA;CACA,IAAM,IAAQ,EAAS,QAAQ,UAAiB,IAC1C,IAAQ,GAER,IAAO;EACX,oBAAoB;EACpB,QAAQ;GACN,UAAU,GAAU;GACpB,cAAc;GACf;EACF,EAEK,WACJ,EAAK,SAAS,EAAuB,EAAK,OAAO,EACjD,EAAM,oBAAoB,EAAK,OAAO,EAC/B,EAAK,SAGR,IAAY,EAAI,GAAM,EAEtB,IAAU,EAAI,EAAM,KAAK,EAEzB,IAAe,EAAS,gBAAgB,KAExC,IAAe,IAAI,EAAiB,EAAE,iBAAc,CAAC,EACrD,oBAAmB,IAAI,KAAqC,EAC5D,KAAsB,MA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B,KAAa,CAAC;EAC1F,MAAM,QAAe,EAAS,MAAM,gBAAgB,KAAK;EACzD,WAAW,QACT,OAAO,OAAO,EAAS,MAAM,QAAsC,CAAC,MAAM,MAAM,CAAC,GAAG,GAAG,CACxF;EACF,EAEK,IAAM,OAAO,OAAO,EAAS,OAAO,OAAO,GAAU,GAAQ,CAAC,EAAE,EAAQ;AAO9E,QALI,EAAS,UAEX,WAAW,gBAAgB,IAGtB;EAAE;EAAK;EAAc"}
1
+ {"version":3,"file":"createAppV3.js","names":[],"sources":["../../src/internal/createAppV3.ts"],"sourcesContent":["import { deepClone, delay, uniqueId } from \"@milaboratories/helpers\";\nimport type { Mutable } from \"@milaboratories/helpers\";\nimport type {\n NavigationState,\n BlockOutputsBase,\n BlockStateV3,\n PlatformaV3,\n ValueWithUTag,\n AuthorMarker,\n PlatformaExtended,\n InferPluginUiEntries,\n PluginHandle,\n InferFactoryData,\n InferFactoryOutputs,\n PluginFactoryLike,\n UiServices as AllUiServices,\n InferFactoryUiServices,\n} from \"@platforma-sdk/model\";\nimport {\n hasAbortError,\n unwrapResult,\n deriveDataFromStorage,\n getPluginData,\n isPluginOutputKey,\n pluginOutputPrefix,\n} from \"@platforma-sdk/model\";\nimport type { Ref } from \"vue\";\nimport { reactive, computed, ref, markRaw } from \"vue\";\nimport type { OutputValues, OutputErrors, AppSettings } from \"../types\";\nimport { parseQuery } from \"../urls\";\nimport { ensureOutputHasStableFlag, MultiError } from \"../utils\";\nimport { applyPatch } from \"fast-json-patch\";\nimport { UpdateSerializer } from \"./UpdateSerializer\";\nimport { watchIgnorable } from \"@vueuse/core\";\nimport type { PluginState, PluginAccess } from \"../composition/usePlugin\";\nimport { logDebug, logError } from \"./utils\";\nimport { getServices } from \"./getServices\";\n\nexport const patchPoolingDelay = 150;\n\n/** Internal per-plugin state with reconciliation support. */\ninterface InternalPluginState<\n Data = unknown,\n Outputs = unknown,\n Services = Record<string, unknown>,\n> extends PluginState<Data, Outputs, Services> {\n readonly ignoreUpdates: (fn: () => void) => void;\n}\n\nexport const createNextAuthorMarker = (marker: AuthorMarker | undefined): AuthorMarker => ({\n authorId: marker?.authorId ?? uniqueId(),\n localVersion: (marker?.localVersion ?? 0) + 1,\n});\n\n/**\n * Creates an application instance with reactive state management, outputs, and methods for state updates and navigation.\n *\n * @template Args - The type of arguments used in the application.\n * @template Outputs - The type of block outputs extending `BlockOutputsBase`.\n * @template Data - The type of the block data.\n * @template Href - The type of navigation href, defaulting to a string starting with `/`.\n *\n * @param state - Initial state of the application, including args, outputs, UI state, and navigation state.\n * @param platforma - A platform interface for interacting with block states.\n * @param settings - Application settings, such as debug flags.\n *\n * @returns A reactive application object with methods, getters, and state.\n */\nexport function createAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n>(\n state: ValueWithUTag<BlockStateV3<Data, Outputs, Href>>,\n platforma: PlatformaExtended<PlatformaV3<Data, Args, Outputs, Href, Plugins, UiServices>>,\n settings: AppSettings,\n) {\n const debug = settings.debug ? logDebug : () => {};\n const error = logError;\n\n const data = {\n isExternalSnapshot: false,\n author: {\n authorId: uniqueId(),\n localVersion: 0,\n },\n };\n\n const nextAuthorMarker = () => {\n data.author = createNextAuthorMarker(data.author);\n debug(\"nextAuthorMarker\", data.author);\n return data.author;\n };\n\n const closedRef = ref(false);\n\n const uTagRef = ref(state.uTag);\n\n const debounceSpan = settings.debounceSpan ?? 200;\n\n const setDataQueue = new UpdateSerializer({ debounceSpan });\n const pluginDataQueues = new Map<PluginHandle, UpdateSerializer>();\n const getPluginDataQueue = (handle: PluginHandle): UpdateSerializer => {\n let queue = pluginDataQueues.get(handle);\n if (!queue) {\n queue = new UpdateSerializer({ debounceSpan });\n pluginDataQueues.set(handle, queue);\n }\n return queue;\n };\n const setNavigationStateQueue = new UpdateSerializer({ debounceSpan });\n\n /** Lazily-created per-plugin reactive states. */\n const pluginStates = new Map<PluginHandle, InternalPluginState>();\n /**\n * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.\n */\n const snapshot = ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>(state.value) as Ref<{\n outputs: Partial<Readonly<Outputs>>;\n blockStorage: unknown;\n navigationState: NavigationState<Href>;\n }>;\n\n const updateData = async (value: Data) => {\n return platforma.mutateStorage({ operation: \"update-block-data\", value }, nextAuthorMarker());\n };\n\n const updatePluginData = async (handle: PluginHandle, value: unknown) => {\n return platforma.mutateStorage(\n { operation: \"update-plugin-data\", pluginId: handle, value },\n nextAuthorMarker(),\n );\n };\n\n const setNavigationState = async (state: NavigationState<Href>) => {\n return platforma.setNavigationState(state);\n };\n\n const outputs = computed<OutputValues<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, outputWithStatus]) =>\n platforma.blockModelInfo.outputs[k]?.withStatus\n ? [k, ensureOutputHasStableFlag(outputWithStatus)]\n : [\n k,\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined,\n ],\n );\n return Object.fromEntries(entries);\n });\n\n const outputErrors = computed<OutputErrors<Outputs>>(() => {\n const entries = Object.entries(snapshot.value.outputs as Partial<Readonly<Outputs>>)\n .filter(([k]) => !isPluginOutputKey(k))\n .map(([k, vOrErr]) => [\n k,\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined,\n ]);\n return Object.fromEntries(entries);\n });\n\n const appModel = reactive({\n apiVersion: 3,\n error: \"\",\n model: {\n data: deepClone(deriveDataFromStorage<Data>(snapshot.value.blockStorage)) as Data,\n outputs,\n outputErrors,\n },\n }) as {\n error: string;\n model: {\n data: Data;\n outputs: OutputValues<Outputs>;\n outputErrors: OutputErrors<Outputs>;\n };\n };\n\n const { ignoreUpdates } = watchIgnorable(\n () => appModel.model,\n (_newData) => {\n const newData = deepClone(_newData);\n debug(\"setDataQueue appModel.model, data\", newData.data);\n setDataQueue.run(() => updateData(newData.data).then(unwrapResult));\n },\n { deep: true },\n );\n\n const updateAppModel = (newData: { data: Data }) => {\n debug(\"updateAppModel\", newData);\n appModel.model.data = deepClone(newData.data) as Data;\n };\n\n (async () => {\n window.addEventListener(\"beforeunload\", () => {\n closedRef.value = true;\n platforma\n .dispose()\n .then(unwrapResult)\n .catch((err) => {\n error(\"platforma error in dispose\", err);\n });\n });\n\n while (!closedRef.value) {\n try {\n const patches = await platforma.getPatches(uTagRef.value).then(unwrapResult);\n\n debug(\"patches.length\", patches.value.length);\n debug(\"uTagRef.value\", uTagRef.value);\n debug(\"patches.uTag\", patches.uTag);\n debug(\"patches.author\", patches.author);\n debug(\"data.author\", data.author);\n\n uTagRef.value = patches.uTag;\n\n if (patches.value.length === 0) {\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n continue;\n }\n\n const isAuthorChanged = data.author?.authorId !== patches.author?.authorId;\n\n // Immutable behavior, apply external changes to the snapshot\n if (isAuthorChanged || data.isExternalSnapshot) {\n debug(\"got external changes, applying them to the snapshot\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value, false, false).newDocument;\n updateAppModel({ data: deriveDataFromStorage<Data>(snapshot.value.blockStorage) });\n // Reconcile plugin data from external source\n for (const [handle, pluginState] of pluginStates) {\n pluginState.ignoreUpdates(() => {\n pluginState.model.data = deepClone(\n getPluginData(snapshot.value.blockStorage, handle),\n );\n });\n }\n data.isExternalSnapshot = isAuthorChanged;\n });\n } else {\n // Mutable behavior\n debug(\"outputs changed\", patches.value);\n ignoreUpdates(() => {\n snapshot.value = applyPatch(snapshot.value, patches.value).newDocument;\n });\n }\n\n await new Promise((resolve) => setTimeout(resolve, patchPoolingDelay));\n } catch (err) {\n if (hasAbortError(err)) {\n debug(\"patches loop aborted\");\n closedRef.value = true;\n } else {\n error(\"error in patches loop\", err);\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n }\n }\n })();\n\n const cloneData = () => deepClone(appModel.model.data) as Data;\n const cloneNavigationState = () =>\n deepClone(snapshot.value.navigationState) as Mutable<NavigationState<Href>>;\n\n const methods = {\n cloneData,\n cloneNavigationState,\n /**\n * Updates the UI state by applying a callback.\n *\n * @param cb - Callback to modify the current UI state.\n * @returns A promise resolving after the update is applied.\n * @todo Make it mutable since there is already an initial one\n */\n updateData(cb: (data: Data) => Data): Promise<boolean> {\n const newData = cb(cloneData());\n debug(\"updateData\", newData);\n appModel.model.data = newData;\n return setDataQueue.run(() => updateData(newData).then(unwrapResult));\n },\n /**\n * Navigates to a specific href by updating the navigation state.\n *\n * @param href - The target href to navigate to.\n * @returns A promise resolving after the navigation state is updated.\n */\n navigateTo(href: Href) {\n const newState = cloneNavigationState();\n newState.href = href;\n return setNavigationStateQueue.run(() => setNavigationState(newState).then(unwrapResult));\n },\n async allSettled() {\n await delay(0);\n const allQueues = [\n setDataQueue.allSettled(),\n ...Array.from(pluginDataQueues.values()).map((q) => q.allSettled()),\n ];\n await Promise.all(allQueues);\n },\n };\n\n const services = getServices<UiServices>({ platforma });\n\n /** Creates a lazily-cached per-plugin reactive state. */\n const createPluginState = <F extends PluginFactoryLike>(\n handle: PluginHandle<F>,\n ): InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>> => {\n const prefix = pluginOutputPrefix(handle);\n\n const pluginOutputs = computed(() => {\n const result: Record<string, unknown> = {};\n for (const [key, outputWithStatus] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n const outputKey = key.slice(prefix.length);\n if (platforma.blockModelInfo.outputs[key]?.withStatus) {\n result[outputKey] = outputWithStatus\n ? ensureOutputHasStableFlag(outputWithStatus)\n : undefined;\n } else {\n result[outputKey] =\n outputWithStatus.ok && outputWithStatus.value !== undefined\n ? outputWithStatus.value\n : undefined;\n }\n }\n return result;\n });\n\n const pluginOutputErrors = computed(() => {\n const result: Record<string, Error | undefined> = {};\n for (const [key, vOrErr] of Object.entries(\n snapshot.value.outputs as Partial<Readonly<Outputs>>,\n )) {\n if (!key.startsWith(prefix)) continue;\n result[key.slice(prefix.length)] =\n vOrErr && vOrErr.ok === false ? new MultiError(vOrErr.errors) : undefined;\n }\n return result;\n });\n\n const pluginModel = reactive({\n data: deepClone(getPluginData(snapshot.value.blockStorage, handle)),\n outputs: pluginOutputs,\n outputErrors: pluginOutputErrors,\n }) as InternalPluginState<InferFactoryData<F>, InferFactoryOutputs<F>>[\"model\"];\n\n const { ignoreUpdates } = watchIgnorable(\n () => pluginModel.data,\n (newData) => {\n if (newData === undefined) return;\n debug(\"plugin setData\", handle, newData);\n getPluginDataQueue(handle).run(() =>\n updatePluginData(handle, deepClone(newData)).then(unwrapResult),\n );\n },\n { deep: true },\n );\n\n return {\n model: pluginModel,\n services: markRaw(services),\n ignoreUpdates,\n };\n };\n\n /** Plugin internals — provided via separate injection key, not exposed on useApp(). */\n const pluginAccess: PluginAccess = {\n getOrCreatePluginState<F extends PluginFactoryLike>(handle: PluginHandle<F>) {\n const existing = pluginStates.get(handle);\n if (existing) {\n return existing as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n }\n const state = createPluginState(handle);\n pluginStates.set(handle, state);\n return state as unknown as PluginState<\n InferFactoryData<F>,\n InferFactoryOutputs<F>,\n InferFactoryUiServices<F>\n >;\n },\n };\n\n const plugins = Object.fromEntries(\n platforma.blockModelInfo.pluginIds.map((id) => {\n const rawDef = platforma.blockModelInfo.pluginPublicOutputs?.[id] ?? {};\n const keys = Object.keys(rawDef);\n if (keys.length === 0) {\n return [id, { handle: id, publicOutputs: {} }];\n }\n const state = pluginAccess.getOrCreatePluginState(id);\n // reactive() ensures publicOutputs is its own proxy, so access via toRaw(app) still unwraps correctly.\n const publicOutputs = reactive(\n Object.fromEntries(\n keys.map((key) => {\n const { getter } = rawDef[key];\n return [\n key,\n computed(() => {\n const data = state.model.data;\n return data != null ? getter(data) : undefined;\n }),\n ];\n }),\n ),\n );\n return [id, { handle: id, publicOutputs }];\n }),\n ) as InferPluginUiEntries<Plugins>;\n\n const getters = {\n closedRef,\n snapshot,\n plugins,\n services: markRaw(services),\n queryParams: computed(() => parseQuery<Href>(snapshot.value.navigationState.href as Href)),\n href: computed(() => snapshot.value.navigationState.href),\n hasErrors: computed(() =>\n Object.values(snapshot.value.outputs as Partial<Readonly<Outputs>>).some((v) => !v?.ok),\n ),\n };\n\n const app = Object.assign(reactive(Object.assign(appModel, getters)), methods);\n\n if (settings.debug) {\n // @ts-expect-error (to inspect in console in debug mode)\n globalThis.__block_app__ = app;\n }\n\n return { app, pluginAccess };\n}\n\nexport type BaseAppV3<\n Data = unknown,\n Args = unknown,\n Outputs extends BlockOutputsBase = BlockOutputsBase,\n Href extends `/${string}` = `/${string}`,\n Plugins extends Record<string, unknown> = Record<string, unknown>,\n UiServices extends Partial<AllUiServices> = Partial<AllUiServices>,\n> = ReturnType<typeof createAppV3<Data, Args, Outputs, Href, Plugins, UiServices>>[\"app\"];\n"],"mappings":";;;;;;;;;;;;;AAiDA,IAAa,KAA0B,OAAoD;CACzF,UAAU,GAAQ,YAAY,GAAU;CACxC,eAAe,GAAQ,gBAAgB,KAAK;CAC7C;AAgBD,SAAgB,EAQd,GACA,GACA,GACA;CACA,IAAM,IAAQ,EAAS,QAAQ,UAAiB,IAC1C,IAAQ,GAER,IAAO;EACX,oBAAoB;EACpB,QAAQ;GACN,UAAU,GAAU;GACpB,cAAc;GACf;EACF,EAEK,WACJ,EAAK,SAAS,EAAuB,EAAK,OAAO,EACjD,EAAM,oBAAoB,EAAK,OAAO,EAC/B,EAAK,SAGR,IAAY,EAAI,GAAM,EAEtB,IAAU,EAAI,EAAM,KAAK,EAEzB,IAAe,EAAS,gBAAgB,KAExC,IAAe,IAAI,EAAiB,EAAE,iB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AO,OAAO,KAAK,EAAO;AAChC,OAAI,EAAK,WAAW,EAClB,QAAO,CAAC,GAAI;IAAE,QAAQ;IAAI,eAAe,EAAE;IAAE,CAAC;GAEhD,IAAM,IAAQ,EAAa,uBAAuB,EAAG;AAgBrD,UAAO,CAAC,GAAI;IAAE,QAAQ;IAAI,eAdJ,EACpB,OAAO,YACL,EAAK,KAAK,MAAQ;KAChB,IAAM,EAAE,cAAW,EAAO;AAC1B,YAAO,CACL,GACA,QAAe;MACb,IAAM,IAAO,EAAM,MAAM;AACzB,aAAO,KAAQ,OAAsB,KAAA,IAAf,EAAO,EAAK;OAClC,CACH;MACD,CACH,CACF;IACwC,CAAC;IAC1C,CACH;EAMC,UAAU,EAAQ,EAAS;EAC3B,aAAa,QAAe,EAAiB,EAAS,MAAM,gBAAgB,KAAa,CAAC;EAC1F,MAAM,QAAe,EAAS,MAAM,gBAAgB,KAAK;EACzD,WAAW,QACT,OAAO,OAAO,EAAS,MAAM,QAAsC,CAAC,MAAM,MAAM,CAAC,GAAG,GAAG,CACxF;EACF,EAEK,IAAM,OAAO,OAAO,EAAS,OAAO,OAAO,GAAU,GAAQ,CAAC,EAAE,EAAQ;AAO9E,QALI,EAAS,UAEX,WAAW,gBAAgB,IAGtB;EAAE;EAAK;EAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.75.6",
3
+ "version": "1.75.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -24,12 +24,12 @@
24
24
  "fast-json-patch": "^3.1.1",
25
25
  "immer": "11.1.4",
26
26
  "lru-cache": "^11.2.2",
27
- "vue": "^3.5.24",
27
+ "vue": "3.5.24",
28
28
  "zod": "~3.25.76",
29
29
  "@milaboratories/pl-model-common": "1.41.2",
30
30
  "@milaboratories/pf-spec-driver": "1.3.15",
31
- "@platforma-sdk/model": "1.75.5",
32
- "@milaboratories/uikit": "2.14.4"
31
+ "@milaboratories/uikit": "2.14.6",
32
+ "@platforma-sdk/model": "1.75.8"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@faker-js/faker": "^9.2.0",
@@ -45,9 +45,9 @@
45
45
  "typescript": "~5.9.3",
46
46
  "vite": "^8.0.6",
47
47
  "vitest": "^4.1.3",
48
- "@milaboratories/helpers": "1.14.2",
49
48
  "@milaboratories/ts-builder": "1.4.0",
50
49
  "@milaboratories/build-configs": "2.0.0",
50
+ "@milaboratories/helpers": "1.14.2",
51
51
  "@milaboratories/ts-configs": "1.2.3"
52
52
  },
53
53
  "scripts": {
@@ -262,11 +262,14 @@ export function makeColDef(
262
262
  valueFormatter: columnRenderingSpec.valueFormatter,
263
263
  headerComponent: PlAgColumnHeader,
264
264
  cellRendererSelector: cellButtonAxisParams?.showCellButtonForAxisId
265
- ? (params: ICellRendererParams) => {
266
- if (spec.type !== "axis") return;
267
-
268
- const axisId = (params.colDef?.context as PTableColumnSpec)?.id as AxisId;
269
- if (isJsonEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {
265
+ ? () => {
266
+ const axisId =
267
+ spec.type === "axis"
268
+ ? spec.id
269
+ : isLabelColumnSpec(spec.spec) && spec.spec.axesSpec.length === 1
270
+ ? getAxisId(spec.spec.axesSpec[0])
271
+ : undefined;
272
+ if (axisId && isJsonEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {
270
273
  return {
271
274
  component: PlAgTextAndButtonCell,
272
275
  params: {
@@ -74,6 +74,7 @@ describe("createApp", { timeout: 20_000 }, () => {
74
74
  },
75
75
  pluginIds: [],
76
76
  featureFlags: {},
77
+ pluginPublicOutputs: {},
77
78
  },
78
79
  },
79
80
  { debug: true, debounceSpan: 10 },
@@ -141,6 +142,7 @@ describe("createApp", { timeout: 20_000 }, () => {
141
142
  },
142
143
  pluginIds: [],
143
144
  featureFlags: {},
145
+ pluginPublicOutputs: {},
144
146
  },
145
147
  },
146
148
  { appId: "app1", debug: true, debounceSpan: 10 },
@@ -155,6 +157,7 @@ describe("createApp", { timeout: 20_000 }, () => {
155
157
  },
156
158
  pluginIds: [],
157
159
  featureFlags: {},
160
+ pluginPublicOutputs: {},
158
161
  },
159
162
  },
160
163
  { appId: "app2", debug: true, debounceSpan: 10 },
@@ -13,11 +13,18 @@ import {
13
13
  type PlatformaV3,
14
14
  type BlockModelInfo,
15
15
  type PluginHandle,
16
+ type PluginName,
17
+ type PluginRecord,
18
+ type InferFactoryData,
19
+ type InferFactoryParams,
20
+ type InferFactoryOutputs,
16
21
  createBlockStorage,
17
22
  updateStorageData,
18
23
  wrapAsyncCallback,
19
24
  pluginOutputKey,
20
25
  type PluginFactory,
26
+ PluginModel,
27
+ PluginDataModelBuilder,
21
28
  } from "@platforma-sdk/model";
22
29
  import { deepClone, delay, uniqueId } from "@milaboratories/helpers";
23
30
  import { compare, type Operation } from "fast-json-patch";
@@ -199,6 +206,7 @@ const defaultBlockModelInfo = (pluginIds: PluginHandle[] = []): BlockModelInfo =
199
206
  },
200
207
  pluginIds,
201
208
  featureFlags: {},
209
+ pluginPublicOutputs: {},
202
210
  });
203
211
 
204
212
  function createDefaultState(plugins?: Record<string, unknown>) {
@@ -299,6 +307,7 @@ describe("createAppV3", { timeout: 20_000 }, () => {
299
307
  },
300
308
  pluginIds: [pluginId],
301
309
  featureFlags: {},
310
+ pluginPublicOutputs: {},
302
311
  };
303
312
 
304
313
  const platforma = createMockApiV3<Data, Args, Outputs>(state, blockModelInfo);
@@ -338,6 +347,7 @@ describe("createAppV3", { timeout: 20_000 }, () => {
338
347
  },
339
348
  pluginIds: [pluginId],
340
349
  featureFlags: {},
350
+ pluginPublicOutputs: {},
341
351
  };
342
352
 
343
353
  const platforma = createMockApiV3<Data, Args, Outputs>(state, blockModelInfo);
@@ -505,6 +515,7 @@ describe("createAppV3", { timeout: 20_000 }, () => {
505
515
  },
506
516
  pluginIds: [pluginId],
507
517
  featureFlags: {},
518
+ pluginPublicOutputs: {},
508
519
  };
509
520
 
510
521
  const platforma = createMockApiV3<Data, Args, Outputs>(state, blockModelInfo);
@@ -547,6 +558,7 @@ describe("createAppV3", { timeout: 20_000 }, () => {
547
558
  },
548
559
  pluginIds: [pluginId],
549
560
  featureFlags: {},
561
+ pluginPublicOutputs: {},
550
562
  };
551
563
 
552
564
  const platforma = createMockApiV3<Data, Args, Outputs>(state, blockModelInfo);
@@ -593,6 +605,7 @@ describe("createAppV3", { timeout: 20_000 }, () => {
593
605
  },
594
606
  pluginIds: [pluginId],
595
607
  featureFlags: {},
608
+ pluginPublicOutputs: {},
596
609
  };
597
610
 
598
611
  const platforma = createMockApiV3<Data, Args, Outputs>(state, blockModelInfo);
@@ -616,6 +629,75 @@ describe("createAppV3", { timeout: 20_000 }, () => {
616
629
  expect(pFrame.value).toBeUndefined();
617
630
  });
618
631
 
632
+ it("should expose publicOutputs without status", async () => {
633
+ const dataChain = new PluginDataModelBuilder()
634
+ .from<PluginData, "v1">("v1")
635
+ .init(() => defaultPluginData());
636
+
637
+ const factory = PluginModel.define({
638
+ name: "testPlugin" as PluginName,
639
+ data: dataChain,
640
+ })
641
+ .publicOutput("doubled", (data: PluginData) => data.value * 2)
642
+ .build();
643
+
644
+ type F = typeof factory;
645
+ type FactoryPublicOutputs<Factory> = Factory extends {
646
+ __types?: { publicOutputs: infer PublicOutputs };
647
+ }
648
+ ? NonNullable<PublicOutputs>
649
+ : never;
650
+ type TestPlugins = {
651
+ [K in typeof pluginId]: PluginRecord<
652
+ InferFactoryData<F>,
653
+ InferFactoryParams<F>,
654
+ InferFactoryOutputs<F>,
655
+ FactoryPublicOutputs<F>
656
+ >;
657
+ };
658
+ const pluginId = "counter" as PluginHandle<F>;
659
+
660
+ const state = createDefaultState({ [pluginId]: defaultPluginData() });
661
+
662
+ const blockModelInfo: BlockModelInfo = {
663
+ outputs: {},
664
+ pluginIds: [pluginId],
665
+ featureFlags: {},
666
+ pluginPublicOutputs: { [pluginId]: factory.publicOutputDef },
667
+ };
668
+
669
+ const platforma = createMockApiV3<Data, Args, Outputs, `/${string}`, TestPlugins>(
670
+ state,
671
+ blockModelInfo,
672
+ );
673
+ const initialState = await platforma.loadBlockState();
674
+ if ("error" in initialState) throw initialState.error;
675
+
676
+ const { app } = createAppV3<Data, Args, Outputs, `/${string}`, TestPlugins>(
677
+ initialState.value,
678
+ platforma,
679
+ {
680
+ debug: false,
681
+ debounceSpan: 10,
682
+ },
683
+ );
684
+
685
+ // Initial plugin data is { value: 10 }, so doubled = 20
686
+ expect(app.plugins[pluginId].publicOutputs.doubled).toBe(20);
687
+
688
+ // Simulate external plugin data change
689
+ state.mutateStorage(
690
+ { operation: "update-plugin-data", pluginId, value: { value: 7 } },
691
+ { authorId: "external", localVersion: 1 },
692
+ );
693
+
694
+ await delay(patchPoolingDelay + 50);
695
+
696
+ expect(app.plugins[pluginId].publicOutputs.doubled).toBe(14);
697
+
698
+ app.closedRef = true;
699
+ });
700
+
619
701
  it("should navigate to href", async () => {
620
702
  const state = createDefaultState();
621
703
  const platforma = createMockApiV3<Data, Args, Outputs>(state, defaultBlockModelInfo());
@@ -8,7 +8,7 @@ import type {
8
8
  ValueWithUTag,
9
9
  AuthorMarker,
10
10
  PlatformaExtended,
11
- InferPluginHandles,
11
+ InferPluginUiEntries,
12
12
  PluginHandle,
13
13
  InferFactoryData,
14
14
  InferFactoryOutputs,
@@ -119,11 +119,11 @@ export function createAppV3<
119
119
  * Reactive snapshot of the application state, including args, outputs, UI state, and navigation state.
120
120
  */
121
121
  const snapshot = ref<{
122
- outputs: Partial<Outputs>;
122
+ outputs: Partial<Readonly<Outputs>>;
123
123
  blockStorage: unknown;
124
124
  navigationState: NavigationState<Href>;
125
125
  }>(state.value) as Ref<{
126
- outputs: Partial<Outputs>;
126
+ outputs: Partial<Readonly<Outputs>>;
127
127
  blockStorage: unknown;
128
128
  navigationState: NavigationState<Href>;
129
129
  }>;
@@ -397,8 +397,31 @@ export function createAppV3<
397
397
  };
398
398
 
399
399
  const plugins = Object.fromEntries(
400
- platforma.blockModelInfo.pluginIds.map((id) => [id, { handle: id }]),
401
- ) as InferPluginHandles<Plugins>;
400
+ platforma.blockModelInfo.pluginIds.map((id) => {
401
+ const rawDef = platforma.blockModelInfo.pluginPublicOutputs?.[id] ?? {};
402
+ const keys = Object.keys(rawDef);
403
+ if (keys.length === 0) {
404
+ return [id, { handle: id, publicOutputs: {} }];
405
+ }
406
+ const state = pluginAccess.getOrCreatePluginState(id);
407
+ // reactive() ensures publicOutputs is its own proxy, so access via toRaw(app) still unwraps correctly.
408
+ const publicOutputs = reactive(
409
+ Object.fromEntries(
410
+ keys.map((key) => {
411
+ const { getter } = rawDef[key];
412
+ return [
413
+ key,
414
+ computed(() => {
415
+ const data = state.model.data;
416
+ return data != null ? getter(data) : undefined;
417
+ }),
418
+ ];
419
+ }),
420
+ ),
421
+ );
422
+ return [id, { handle: id, publicOutputs }];
423
+ }),
424
+ ) as InferPluginUiEntries<Plugins>;
402
425
 
403
426
  const getters = {
404
427
  closedRef,