@platforma-sdk/ui-vue 1.90.20 → 1.91.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.
Files changed (30) hide show
  1. package/.turbo/turbo-build.log +12 -12
  2. package/.turbo/turbo-formatter$colon$check.log +1 -1
  3. package/.turbo/turbo-linter$colon$check.log +1 -1
  4. package/CHANGELOG.md +24 -0
  5. package/dist/components/PlAgDataTable/PlAgDataTableSheets.js.map +1 -1
  6. package/dist/components/PlAgDataTable/PlAgDataTableSheets.style.js.map +1 -1
  7. package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue.d.ts +3 -3
  8. package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue.d.ts.map +1 -1
  9. package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js +77 -20
  10. package/dist/components/PlAgDataTable/PlAgDataTableSheets.vue2.js.map +1 -1
  11. package/dist/components/PlAgDataTable/PlAgDataTableV2.js.map +1 -1
  12. package/dist/components/PlAgDataTable/PlAgDataTableV2.style.js.map +1 -1
  13. package/dist/components/PlAgDataTable/PlAgDataTableV2.vue.d.ts.map +1 -1
  14. package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js +1 -0
  15. package/dist/components/PlAgDataTable/PlAgDataTableV2.vue2.js.map +1 -1
  16. package/dist/components/PlAgDataTable/sources/table-source-v2.d.ts +4 -2
  17. package/dist/components/PlAgDataTable/sources/table-source-v2.d.ts.map +1 -1
  18. package/dist/components/PlAgDataTable/sources/table-source-v2.js +71 -68
  19. package/dist/components/PlAgDataTable/sources/table-source-v2.js.map +1 -1
  20. package/dist/components/PlAgDataTable/sources/table-state-v2.d.ts +7 -3
  21. package/dist/components/PlAgDataTable/sources/table-state-v2.d.ts.map +1 -1
  22. package/dist/components/PlAgDataTable/sources/table-state-v2.js +35 -24
  23. package/dist/components/PlAgDataTable/sources/table-state-v2.js.map +1 -1
  24. package/dist/components/PlAnnotations/components/PlAnnotations.vue2.js.map +1 -1
  25. package/package.json +3 -3
  26. package/src/components/PlAgDataTable/PlAgDataTableSheets.vue +95 -23
  27. package/src/components/PlAgDataTable/PlAgDataTableV2.vue +1 -0
  28. package/src/components/PlAgDataTable/sources/table-source-v2.ts +33 -7
  29. package/src/components/PlAgDataTable/sources/table-state-v2.test.ts +32 -0
  30. package/src/components/PlAgDataTable/sources/table-state-v2.ts +29 -12
@@ -1 +1 @@
1
- {"version":3,"file":"table-state-v2.js","names":["reduceTableState","edited","edits","applyEdit","stored","aligned","isNil","target","alignWithTarget","CACHE_DEPTH","resolveSheetsState","sheets","sheet","axisId","getAxisId","savedValue","saved","isJsonEqual","s","isSheetOption","useTableState","computed","upgradePlDataTableStateV2","tableStateDenormalized","settings","pendingEdits","shallowRef","state","commit","base","unconfirmed","edit","next","change","sourceId","current","entry","findEntry","editCurrent","gridState","sorting","hiddenColIds","sheetsState","filtersState","raw","getEmptyGroupWithMeta","normalizeFiltersState","defaultFiltersState","defaultFilters","annotateFiltersWithIds","resetDefaultFilters","id","grid","createEntry","patch","createDefaultPTableParams","option","value","randomInt","f","getEmptyGroup","annotateNodeWithIds","filters","node","getField","child"],"sources":["../../../../src/components/PlAgDataTable/sources/table-state-v2.ts"],"sourcesContent":["import {\n createDefaultPTableParams,\n getAxisId,\n upgradePlDataTableStateV2,\n type FilterSpec,\n type PlDataTableGridStateCore,\n type PlDataTableSheet,\n type PlDataTableSheetState,\n type PlDataTableStateV2,\n type PlDataTableStateV2CacheEntry,\n type PlDataTableStateV2Normalized,\n type PlDataTableFilterSpecLeaf,\n type PlDataTableFilterMeta,\n type PlDataTableFilters,\n type PlDataTableFiltersWithMeta,\n type PTableColumnId,\n type PTableSorting,\n} from \"@platforma-sdk/model\";\nimport {\n computed,\n shallowRef,\n watch,\n type ComputedRef,\n type Ref,\n type WritableComputedRef,\n} from \"vue\";\nimport type { PlDataTableSettingsV2 } from \"../types\";\nimport type { PlDataTableGridFields } from \"./grid-state\";\nimport { isJsonEqual, randomInt, getField, type Nil } from \"@milaboratories/helpers\";\nimport { isNil } from \"es-toolkit\";\n\n/** The source the table shows, as the stored state has to describe it. */\nexport type PlDataTableTarget = {\n sourceId: string;\n sheets: PlDataTableSheet[];\n};\n\n/** A change the user made to the settings of one source. */\nexport type PlDataTableEdit = {\n sourceId: string;\n patch: Partial<Omit<PlDataTableStateV2CacheEntry, \"sourceId\">>;\n};\n\n/**\n * The stored state with the edits applied and, when a source is on screen,\n * brought in line with it: the stored state points at that source, the source\n * has an entry at the recent end of the cache, and its sheet selection names a\n * value each sheet offers.\n *\n * Every write of the table state is this function's result, whether the user\n * edited something or only the source on screen changed, so a table mounted\n * on a source the stored state does not point at writes the same way a sort\n * does.\n */\nexport function reduceTableState(\n stored: PlDataTableStateV2Normalized,\n target: null | PlDataTableTarget,\n edits: PlDataTableEdit[],\n): PlDataTableStateV2Normalized {\n const edited = edits.reduce(applyEdit, stored);\n const aligned = isNil(target) ? edited : alignWithTarget(edited, target);\n return aligned.stateCache.length > CACHE_DEPTH\n ? { ...aligned, stateCache: aligned.stateCache.slice(-CACHE_DEPTH) }\n : aligned;\n}\n\n/**\n * The value shown on each sheet: the saved one while the sheet still offers it,\n * otherwise the sheet's default, otherwise its first option. Sheets without\n * options are not shown and get no entry.\n */\nexport function resolveSheetsState(\n sheets: PlDataTableSheet[],\n saved: PlDataTableSheetState[],\n): PlDataTableSheetState[] {\n return sheets\n .filter((sheet) => sheet.options.length > 0)\n .map((sheet) => {\n const axisId = getAxisId(sheet.axis);\n const savedValue = saved.find((s) => isJsonEqual(s.axisId, axisId))?.value;\n const value =\n !isNil(savedValue) && isSheetOption(sheet, savedValue)\n ? savedValue\n : !isNil(sheet.defaultValue) && isSheetOption(sheet, sheet.defaultValue)\n ? sheet.defaultValue\n : sheet.options[0].value;\n return { axisId, value };\n });\n}\n\nexport function useTableState(\n tableStateDenormalized: Ref<PlDataTableStateV2>,\n settings: Ref<PlDataTableSettingsV2>,\n defaultFilters: Ref<Nil | PlDataTableFilters>,\n): {\n /** Source whose settings the controls show and edit; `null` while there is none. */\n sourceId: ComputedRef<null | string>;\n /** The grid's own state for the source on screen, to restore the grid from */\n gridState: ComputedRef<PlDataTableGridStateCore>;\n /** Sorting the user set on the source on screen; `null` while untouched */\n sorting: ComputedRef<null | PTableSorting[]>;\n /** Columns the user hid on the source on screen; `null` while untouched */\n hiddenColIds: ComputedRef<null | PTableColumnId[]>;\n getEntry: (sourceId: string) => undefined | PlDataTableStateV2CacheEntry;\n updateGrid: (sourceId: string, grid: PlDataTableGridFields) => void;\n sheetsState: WritableComputedRef<PlDataTableSheetState[]>;\n searchString: WritableComputedRef<string>;\n filtersState: WritableComputedRef<PlDataTableFiltersWithMeta>;\n defaultFiltersState: WritableComputedRef<null | PlDataTableFiltersWithMeta>;\n resetDefaultFilters: () => void;\n} {\n const stored = computed(() => upgradePlDataTableStateV2(tableStateDenormalized.value));\n const target = computed<null | PlDataTableTarget>(() =>\n settings.value.sourceId === null\n ? null\n : { sourceId: settings.value.sourceId, sheets: settings.value.sheets },\n );\n\n // Edits are kept until the stored state reports them back. Until then the\n // platform may hand back a state that predates them: a change by another\n // author, such as a running block, replaces the whole block state with the\n // project's copy, which lacks edits still waiting to be sent. Each such push\n // would otherwise undo what the user just did.\n const pendingEdits = shallowRef<PlDataTableEdit[]>([]);\n const state = computed(() => reduceTableState(stored.value, target.value, pendingEdits.value));\n\n function commit(): void {\n const base = stored.value;\n const unconfirmed = pendingEdits.value.filter(\n (edit) =>\n !isJsonEqual(\n reduceTableState(base, target.value, [edit]),\n reduceTableState(base, target.value, []),\n ),\n );\n if (unconfirmed.length !== pendingEdits.value.length) pendingEdits.value = unconfirmed;\n\n const next = reduceTableState(base, target.value, unconfirmed);\n if (!isJsonEqual(next, base)) tableStateDenormalized.value = next;\n }\n watch([stored, target, pendingEdits], commit, { immediate: true });\n\n function edit(change: PlDataTableEdit): void {\n pendingEdits.value = [...pendingEdits.value, change];\n commit();\n }\n\n // While the model reports an error there is no source on screen; the\n // controls keep showing the last one, so a filter that caused the error can\n // still be removed.\n const sourceId = computed<null | string>(() => {\n const current = settings.value;\n if (current.sourceId !== null) return current.sourceId;\n return current.error !== null ? stored.value.pTableParams.sourceId : null;\n });\n const entry = computed(() => findEntry(state.value, sourceId.value));\n\n function editCurrent(patch: PlDataTableEdit[\"patch\"]): void {\n if (sourceId.value !== null) edit({ sourceId: sourceId.value, patch });\n }\n\n const gridState = computed<PlDataTableGridStateCore>(() => entry.value?.gridState ?? {});\n const sorting = computed(() => entry.value?.sorting ?? null);\n const hiddenColIds = computed(() => entry.value?.hiddenColIds ?? null);\n\n const sheetsState = computed<PlDataTableSheetState[]>({\n get: () => entry.value?.sheetsState ?? [],\n set: (sheetsState) => editCurrent({ sheetsState }),\n });\n\n const filtersState = computed<PlDataTableFiltersWithMeta>({\n get: () => {\n const raw = entry.value?.filtersState;\n return isNil(raw) ? getEmptyGroupWithMeta() : normalizeFiltersState(raw);\n },\n set: (filtersState) => editCurrent({ filtersState }),\n });\n\n const defaultFiltersState = computed<null | PlDataTableFiltersWithMeta>({\n get: () => {\n const raw = entry.value?.defaultFiltersState;\n if (!isNil(raw)) return normalizeFiltersState(raw);\n if (!isNil(defaultFilters.value)) {\n return annotateFiltersWithIds(normalizeFiltersState(defaultFilters.value));\n }\n return null;\n },\n set: (defaultFiltersState) => editCurrent({ defaultFiltersState }),\n });\n\n function resetDefaultFilters(): void {\n defaultFiltersState.value = isNil(defaultFilters.value)\n ? null\n : annotateFiltersWithIds(normalizeFiltersState(defaultFilters.value));\n }\n\n const searchString = computed<string>({\n get: () => entry.value?.searchString ?? \"\",\n set: (searchString) => editCurrent({ searchString }),\n });\n\n return {\n sourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry: (id) => findEntry(state.value, id),\n updateGrid: (id, grid) => edit({ sourceId: id, patch: grid }),\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n };\n}\n\n// Internals\n\nconst CACHE_DEPTH = 5;\n\ntype FilterNode = FilterSpec<PlDataTableFilterSpecLeaf>;\ntype AnnotatedFilterSpec = FilterSpec<PlDataTableFilterSpecLeaf, PlDataTableFilterMeta>;\n\nfunction applyEdit(\n state: PlDataTableStateV2Normalized,\n { sourceId, patch }: PlDataTableEdit,\n): PlDataTableStateV2Normalized {\n const current = findEntry(state, sourceId);\n const entry = { ...(current ?? createEntry(sourceId)), ...patch };\n return {\n ...state,\n stateCache: isNil(current)\n ? [...state.stateCache, entry]\n : state.stateCache.map((e) => (e === current ? entry : e)),\n };\n}\n\nfunction alignWithTarget(\n state: PlDataTableStateV2Normalized,\n { sourceId, sheets }: PlDataTableTarget,\n): PlDataTableStateV2Normalized {\n const current = findEntry(state, sourceId) ?? createEntry(sourceId);\n const entry = { ...current, sheetsState: resolveSheetsState(sheets, current.sheetsState) };\n return {\n ...state,\n stateCache: [...state.stateCache.filter((e) => e.sourceId !== sourceId), entry],\n pTableParams: { ...createDefaultPTableParams(), sourceId },\n };\n}\n\nfunction findEntry(\n state: PlDataTableStateV2Normalized,\n sourceId: null | string,\n): undefined | PlDataTableStateV2CacheEntry {\n if (isNil(sourceId)) return undefined;\n return state.stateCache.find((e) => e.sourceId === sourceId);\n}\n\nfunction createEntry(sourceId: string): PlDataTableStateV2CacheEntry {\n return {\n sourceId,\n gridState: {},\n sorting: null,\n hiddenColIds: null,\n sheetsState: [],\n filtersState: null,\n defaultFiltersState: null,\n };\n}\n\nfunction isSheetOption(sheet: PlDataTableSheet, value: string | number): boolean {\n return sheet.options.some((option) => option.value === value);\n}\n\n/**\n * Normalizes raw filter state into a valid root filter structure.\n * Valid structure is Root(Group, Group, ...) — double nesting required:\n * root is and/or group, each child is also and/or group containing leaf filters.\n * - null/undefined/invalid → empty root\n * - Leaf node → Root(Group(leaf))\n * - Group with leaf children → Root(Group(leaves...))\n * - Group with group children → as-is\n */\nfunction normalizeFiltersState(raw: FilterNode) {\n // Leaf node → wrap in double nesting: Root(Group(leaf))\n if (raw.type !== \"and\" && raw.type !== \"or\" && raw.type !== \"not\") {\n if (\"type\" in raw && !isNil(raw.type)) {\n return {\n id: randomInt(),\n type: \"and\" as const,\n isExpanded: true,\n filters: [\n {\n id: randomInt(),\n type: \"and\" as const,\n isExpanded: true,\n filters: [raw as AnnotatedFilterSpec],\n } as AnnotatedFilterSpec,\n ],\n };\n }\n return getEmptyGroupWithMeta();\n }\n\n // Already a group — ensure children are also groups (double nesting)\n if ((raw.type === \"and\" || raw.type === \"or\") && \"filters\" in raw && Array.isArray(raw.filters)) {\n const allChildrenAreGroups = raw.filters.every(\n (f: FilterNode) => f.type === \"and\" || f.type === \"or\" || f.type === \"not\",\n );\n if (allChildrenAreGroups) {\n return raw as PlDataTableFiltersWithMeta;\n }\n // Children are leaves — wrap them in a single group\n return {\n id: randomInt(),\n type: raw.type as \"and\" | \"or\",\n isExpanded: true,\n filters: [\n {\n id: randomInt(),\n type: raw.type as \"and\" | \"or\",\n isExpanded: true,\n filters: raw.filters as AnnotatedFilterSpec[],\n } as AnnotatedFilterSpec,\n ],\n };\n }\n\n return getEmptyGroupWithMeta();\n}\n\nfunction getEmptyGroup(): PlDataTableFilters {\n return {\n type: \"and\" as const,\n filters: [],\n };\n}\nfunction getEmptyGroupWithMeta(): PlDataTableFiltersWithMeta {\n return {\n ...getEmptyGroup(),\n id: randomInt(),\n isExpanded: true,\n } as PlDataTableFiltersWithMeta;\n}\n\n/**\n * Recursively ensures every node in a filter tree has an `id` field.\n * Does not set `source` meta — defaults are now a separate list.\n */\nfunction annotateFiltersWithIds(\n filters: PlDataTableFilters | PlDataTableFiltersWithMeta,\n): PlDataTableFiltersWithMeta {\n return annotateNodeWithIds(filters) as PlDataTableFiltersWithMeta;\n}\n\nfunction annotateNodeWithIds(\n node: FilterNode | PlDataTableFilters | PlDataTableFiltersWithMeta,\n): AnnotatedFilterSpec {\n switch (node.type) {\n case \"and\":\n return {\n id: getField(node, \"id\") ?? randomInt(),\n isExpanded: getField(node, \"isExpanded\") ?? true,\n type: \"and\" as const,\n filters: node.filters.map((child) => annotateNodeWithIds(child)),\n };\n case \"or\":\n return {\n id: getField(node, \"id\") ?? randomInt(),\n isExpanded: getField(node, \"isExpanded\") ?? true,\n type: \"or\" as const,\n filters: node.filters.map((child) => annotateNodeWithIds(child)),\n };\n case \"not\":\n return {\n id: randomInt(),\n isExpanded: true,\n type: \"not\" as const,\n filter: annotateNodeWithIds(node.filter),\n };\n default:\n return { ...node, id: getField(node, \"id\") ?? randomInt() } as AnnotatedFilterSpec;\n }\n}\n"],"mappings":";;;;;;;AAsDA,SAAgBA,EACd,GACA,GACA,GAC8B;CAC9B,IAAMC,IAASC,EAAM,OAAOC,GAAWC,CAAM,GACvCC,IAAUC,EAAMC,CAAM,IAAIN,IAASO,EAAgBP,GAAQM,CAAM;CACvE,OAAOF,EAAQ,WAAW,SAASI,IAC/B;EAAE,GAAGJ;EAAS,YAAYA,EAAQ,WAAW,MAAM,CAACI,CAAW;CAAE,IACjEJ;AACN;AAOA,SAAgBK,EACd,GACA,GACyB;CACzB,OAAOC,EACJ,QAAQ,MAAUC,EAAM,QAAQ,SAAS,CAAC,CAAC,CAC3C,KAAK,MAAU;EACd,IAAMC,IAASC,EAAUF,EAAM,IAAI,GAC7BG,IAAaC,EAAM,MAAM,MAAMC,EAAYC,EAAE,QAAQL,CAAM,CAAC,CAAC,EAAE;EAOrE,OAAO;GAAE;GAAQ,OALf,CAACP,EAAMS,CAAU,KAAKI,EAAcP,GAAOG,CAAU,IACjDA,IACA,CAACT,EAAMM,EAAM,YAAY,KAAKO,EAAcP,GAAOA,EAAM,YAAY,IACnEA,EAAM,eACNA,EAAM,QAAQ,EAAE,CAAC;EACF;CACzB,CAAC;AACL;AAEA,SAAgBQ,EACd,GACA,GACA,GAiBA;CACA,IAAMhB,IAASiB,QAAeC,EAA0BC,EAAuB,KAAK,CAAC,GAC/EhB,IAASc,QACbG,EAAS,MAAM,aAAa,OACxB,OACA;EAAE,UAAUA,EAAS,MAAM;EAAU,QAAQA,EAAS,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,KAEnE,IACKf,IAGF;EACL,IAAIc,EAAU;EACd,MAAMd,EAAI;EACV,YAAY;EACZ,SAAS,CACP;GACE,IAAIc,EAAU;GACd,MAAMd,EAAI;GACV,YAAY;GACZ,SAASA,EAAI;EACf,CACF;CACF,IAGKC,EAAsB;AAC/B;AAEA,SAASe,IAAoC;CAC3C,OAAO;EACL,MAAM;EACN,SAAS,CAAC;CACZ;AACF;AACA,SAASf,IAAoD;CAC3D,OAAO;EACL,GAAGe,EAAc;EACjB,IAAIF,EAAU;EACd,YAAY;CACd;AACF;AAMA,SAAST,EACP,GAC4B;CAC5B,OAAOY,EAAoBC,CAAO;AACpC;AAEA,SAASD,EACP,GACqB;CACrB,QAAQE,EAAK,MAAb;EACE,KAAK,OACH,OAAO;GACL,IAAIC,EAASD,GAAM,IAAI,KAAKL,EAAU;GACtC,YAAYM,EAASD,GAAM,YAAY,KAAK;GAC5C,MAAM;GACN,SAASA,EAAK,QAAQ,KAAK,MAAUF,EAAoBI,CAAK,CAAC;EACjE;EACF,KAAK,MACH,OAAO;GACL,IAAID,EAASD,GAAM,IAAI,KAAKL,EAAU;GACtC,YAAYM,EAASD,GAAM,YAAY,KAAK;GAC5C,MAAM;GACN,SAASA,EAAK,QAAQ,KAAK,MAAUF,EAAoBI,CAAK,CAAC;EACjE;EACF,KAAK,OACH,OAAO;GACL,IAAIP,EAAU;GACd,YAAY;GACZ,MAAM;GACN,QAAQG,EAAoBE,EAAK,MAAM;EACzC;EACF,SACE,OAAO;GAAE,GAAGA;GAAM,IAAIC,EAASD,GAAM,IAAI,KAAKL,EAAU;EAAE;CAC9D;AACF"}
1
+ {"version":3,"file":"table-state-v2.js","names":["reduceTableState","edited","edits","applyEdit","stored","aligned","isNil","target","alignWithTarget","CACHE_DEPTH","resolveSheetsState","sheets","sheet","axisId","getAxisId","savedState","saved","isJsonEqual","s","offered","isSheetOption","value","defaultSheetValue","useTableState","computed","upgradePlDataTableStateV2","tableStateDenormalized","settings","pendingEdits","shallowRef","state","commit","base","unconfirmed","edit","next","change","sourceId","current","entry","findEntry","editCurrent","gridState","sorting","hiddenColIds","sheetsState","filtersState","raw","getEmptyGroupWithMeta","normalizeFiltersState","defaultFiltersState","defaultFilters","annotateFiltersWithIds","resetDefaultFilters","id","grid","createEntry","patch","createDefaultPTableParams","option","randomInt","f","getEmptyGroup","annotateNodeWithIds","filters","node","getField","child"],"sources":["../../../../src/components/PlAgDataTable/sources/table-state-v2.ts"],"sourcesContent":["import {\n createDefaultPTableParams,\n getAxisId,\n upgradePlDataTableStateV2,\n type FilterSpec,\n type PlDataTableGridStateCore,\n type PlDataTableSheet,\n type PlDataTableSheetState,\n type PlDataTableStateV2,\n type PlDataTableStateV2CacheEntry,\n type PlDataTableStateV2Normalized,\n type PlDataTableFilterSpecLeaf,\n type PlDataTableFilterMeta,\n type PlDataTableFilters,\n type PlDataTableFiltersWithMeta,\n type PTableColumnId,\n type PTableSorting,\n} from \"@platforma-sdk/model\";\nimport {\n computed,\n shallowRef,\n watch,\n type ComputedRef,\n type Ref,\n type WritableComputedRef,\n} from \"vue\";\nimport type { PlDataTableSettingsV2 } from \"../types\";\nimport type { PlDataTableGridFields } from \"./grid-state\";\nimport { isJsonEqual, randomInt, getField, type Nil } from \"@milaboratories/helpers\";\nimport { isNil } from \"es-toolkit\";\n\n/** The source the table shows, as the stored state has to describe it. */\nexport type PlDataTableTarget = {\n sourceId: string;\n sheets: PlDataTableSheet[];\n};\n\n/** A change the user made to the settings of one source. */\nexport type PlDataTableEdit = {\n sourceId: string;\n patch: Partial<Omit<PlDataTableStateV2CacheEntry, \"sourceId\">>;\n};\n\n/**\n * The stored state with the edits applied and, when a source is on screen,\n * brought in line with it: the stored state points at that source, the source\n * has an entry at the recent end of the cache, and its sheet selection names a\n * value each sheet offers.\n *\n * Every write of the table state is this function's result, whether the user\n * edited something or only the source on screen changed, so a table mounted\n * on a source the stored state does not point at writes the same way a sort\n * does.\n */\nexport function reduceTableState(\n stored: PlDataTableStateV2Normalized,\n target: null | PlDataTableTarget,\n edits: PlDataTableEdit[],\n): PlDataTableStateV2Normalized {\n const edited = edits.reduce(applyEdit, stored);\n const aligned = isNil(target) ? edited : alignWithTarget(edited, target);\n return aligned.stateCache.length > CACHE_DEPTH\n ? { ...aligned, stateCache: aligned.stateCache.slice(-CACHE_DEPTH) }\n : aligned;\n}\n\n/**\n * The values shown on each sheet. A sheet showing one value keeps the saved one\n * while the sheet still offers it; a sheet showing several keeps taking all its\n * values, or the saved values it still offers. When nothing saved is left, the sheet shows its\n * default, otherwise its first option. A saved state of the other kind, from\n * before the sheet changed how many values it shows, gives what it can: its\n * value, or its first value still offered. Sheets without options are not shown\n * and get no entry.\n */\nexport function resolveSheetsState(\n sheets: PlDataTableSheet[],\n saved: PlDataTableSheetState[],\n): PlDataTableSheetState[] {\n return sheets\n .filter((sheet) => sheet.options.length > 0)\n .map((sheet): PlDataTableSheetState => {\n const axisId = getAxisId(sheet.axis);\n const savedState = saved.find((s) => isJsonEqual(s.axisId, axisId));\n if (sheet.selection === \"multiple\" && !isNil(savedState) && \"allValues\" in savedState) {\n return { axisId, allValues: true };\n }\n const savedValues =\n isNil(savedState) || \"allValues\" in savedState\n ? []\n : \"value\" in savedState\n ? [savedState.value]\n : savedState.values;\n const offered = savedValues.filter((value) => isSheetOption(sheet, value));\n if (sheet.selection === \"multiple\") {\n return { axisId, values: offered.length > 0 ? offered : [defaultSheetValue(sheet)] };\n }\n return { axisId, value: offered[0] ?? defaultSheetValue(sheet) };\n });\n}\n\nexport function useTableState(\n tableStateDenormalized: Ref<PlDataTableStateV2>,\n settings: Ref<PlDataTableSettingsV2>,\n defaultFilters: Ref<Nil | PlDataTableFilters>,\n): {\n /** Source whose settings the controls show and edit; `null` while there is none. */\n sourceId: ComputedRef<null | string>;\n /** The grid's own state for the source on screen, to restore the grid from */\n gridState: ComputedRef<PlDataTableGridStateCore>;\n /** Sorting the user set on the source on screen; `null` while untouched */\n sorting: ComputedRef<null | PTableSorting[]>;\n /** Columns the user hid on the source on screen; `null` while untouched */\n hiddenColIds: ComputedRef<null | PTableColumnId[]>;\n getEntry: (sourceId: string) => undefined | PlDataTableStateV2CacheEntry;\n updateGrid: (sourceId: string, grid: PlDataTableGridFields) => void;\n sheetsState: WritableComputedRef<PlDataTableSheetState[]>;\n searchString: WritableComputedRef<string>;\n filtersState: WritableComputedRef<PlDataTableFiltersWithMeta>;\n defaultFiltersState: WritableComputedRef<null | PlDataTableFiltersWithMeta>;\n resetDefaultFilters: () => void;\n} {\n const stored = computed(() => upgradePlDataTableStateV2(tableStateDenormalized.value));\n const target = computed<null | PlDataTableTarget>(() =>\n settings.value.sourceId === null\n ? null\n : { sourceId: settings.value.sourceId, sheets: settings.value.sheets },\n );\n\n // Edits are kept until the stored state reports them back. Until then the\n // platform may hand back a state that predates them: a change by another\n // author, such as a running block, replaces the whole block state with the\n // project's copy, which lacks edits still waiting to be sent. Each such push\n // would otherwise undo what the user just did.\n const pendingEdits = shallowRef<PlDataTableEdit[]>([]);\n const state = computed(() => reduceTableState(stored.value, target.value, pendingEdits.value));\n\n function commit(): void {\n const base = stored.value;\n const unconfirmed = pendingEdits.value.filter(\n (edit) =>\n !isJsonEqual(\n reduceTableState(base, target.value, [edit]),\n reduceTableState(base, target.value, []),\n ),\n );\n if (unconfirmed.length !== pendingEdits.value.length) pendingEdits.value = unconfirmed;\n\n const next = reduceTableState(base, target.value, unconfirmed);\n if (!isJsonEqual(next, base)) tableStateDenormalized.value = next;\n }\n watch([stored, target, pendingEdits], commit, { immediate: true });\n\n function edit(change: PlDataTableEdit): void {\n pendingEdits.value = [...pendingEdits.value, change];\n commit();\n }\n\n // While the model reports an error there is no source on screen; the\n // controls keep showing the last one, so a filter that caused the error can\n // still be removed.\n const sourceId = computed<null | string>(() => {\n const current = settings.value;\n if (current.sourceId !== null) return current.sourceId;\n return current.error !== null ? stored.value.pTableParams.sourceId : null;\n });\n const entry = computed(() => findEntry(state.value, sourceId.value));\n\n function editCurrent(patch: PlDataTableEdit[\"patch\"]): void {\n if (sourceId.value !== null) edit({ sourceId: sourceId.value, patch });\n }\n\n const gridState = computed<PlDataTableGridStateCore>(() => entry.value?.gridState ?? {});\n const sorting = computed(() => entry.value?.sorting ?? null);\n const hiddenColIds = computed(() => entry.value?.hiddenColIds ?? null);\n\n const sheetsState = computed<PlDataTableSheetState[]>({\n get: () => entry.value?.sheetsState ?? [],\n set: (sheetsState) => editCurrent({ sheetsState }),\n });\n\n const filtersState = computed<PlDataTableFiltersWithMeta>({\n get: () => {\n const raw = entry.value?.filtersState;\n return isNil(raw) ? getEmptyGroupWithMeta() : normalizeFiltersState(raw);\n },\n set: (filtersState) => editCurrent({ filtersState }),\n });\n\n const defaultFiltersState = computed<null | PlDataTableFiltersWithMeta>({\n get: () => {\n const raw = entry.value?.defaultFiltersState;\n if (!isNil(raw)) return normalizeFiltersState(raw);\n if (!isNil(defaultFilters.value)) {\n return annotateFiltersWithIds(normalizeFiltersState(defaultFilters.value));\n }\n return null;\n },\n set: (defaultFiltersState) => editCurrent({ defaultFiltersState }),\n });\n\n function resetDefaultFilters(): void {\n defaultFiltersState.value = isNil(defaultFilters.value)\n ? null\n : annotateFiltersWithIds(normalizeFiltersState(defaultFilters.value));\n }\n\n const searchString = computed<string>({\n get: () => entry.value?.searchString ?? \"\",\n set: (searchString) => editCurrent({ searchString }),\n });\n\n return {\n sourceId,\n gridState,\n sorting,\n hiddenColIds,\n getEntry: (id) => findEntry(state.value, id),\n updateGrid: (id, grid) => edit({ sourceId: id, patch: grid }),\n sheetsState,\n searchString,\n filtersState,\n defaultFiltersState,\n resetDefaultFilters,\n };\n}\n\n// Internals\n\nconst CACHE_DEPTH = 5;\n\ntype FilterNode = FilterSpec<PlDataTableFilterSpecLeaf>;\ntype AnnotatedFilterSpec = FilterSpec<PlDataTableFilterSpecLeaf, PlDataTableFilterMeta>;\n\nfunction applyEdit(\n state: PlDataTableStateV2Normalized,\n { sourceId, patch }: PlDataTableEdit,\n): PlDataTableStateV2Normalized {\n const current = findEntry(state, sourceId);\n const entry = { ...(current ?? createEntry(sourceId)), ...patch };\n return {\n ...state,\n stateCache: isNil(current)\n ? [...state.stateCache, entry]\n : state.stateCache.map((e) => (e === current ? entry : e)),\n };\n}\n\nfunction alignWithTarget(\n state: PlDataTableStateV2Normalized,\n { sourceId, sheets }: PlDataTableTarget,\n): PlDataTableStateV2Normalized {\n const current = findEntry(state, sourceId) ?? createEntry(sourceId);\n const entry = { ...current, sheetsState: resolveSheetsState(sheets, current.sheetsState) };\n return {\n ...state,\n stateCache: [...state.stateCache.filter((e) => e.sourceId !== sourceId), entry],\n pTableParams: { ...createDefaultPTableParams(), sourceId },\n };\n}\n\nfunction findEntry(\n state: PlDataTableStateV2Normalized,\n sourceId: null | string,\n): undefined | PlDataTableStateV2CacheEntry {\n if (isNil(sourceId)) return undefined;\n return state.stateCache.find((e) => e.sourceId === sourceId);\n}\n\nfunction createEntry(sourceId: string): PlDataTableStateV2CacheEntry {\n return {\n sourceId,\n gridState: {},\n sorting: null,\n hiddenColIds: null,\n sheetsState: [],\n filtersState: null,\n defaultFiltersState: null,\n };\n}\n\nfunction isSheetOption(sheet: PlDataTableSheet, value: string | number): boolean {\n return sheet.options.some((option) => option.value === value);\n}\n\nfunction defaultSheetValue(sheet: PlDataTableSheet): string | number {\n return !isNil(sheet.defaultValue) && isSheetOption(sheet, sheet.defaultValue)\n ? sheet.defaultValue\n : sheet.options[0].value;\n}\n\n/**\n * Normalizes raw filter state into a valid root filter structure.\n * Valid structure is Root(Group, Group, ...) — double nesting required:\n * root is and/or group, each child is also and/or group containing leaf filters.\n * - null/undefined/invalid → empty root\n * - Leaf node → Root(Group(leaf))\n * - Group with leaf children → Root(Group(leaves...))\n * - Group with group children → as-is\n */\nfunction normalizeFiltersState(raw: FilterNode) {\n // Leaf node → wrap in double nesting: Root(Group(leaf))\n if (raw.type !== \"and\" && raw.type !== \"or\" && raw.type !== \"not\") {\n if (\"type\" in raw && !isNil(raw.type)) {\n return {\n id: randomInt(),\n type: \"and\" as const,\n isExpanded: true,\n filters: [\n {\n id: randomInt(),\n type: \"and\" as const,\n isExpanded: true,\n filters: [raw as AnnotatedFilterSpec],\n } as AnnotatedFilterSpec,\n ],\n };\n }\n return getEmptyGroupWithMeta();\n }\n\n // Already a group — ensure children are also groups (double nesting)\n if ((raw.type === \"and\" || raw.type === \"or\") && \"filters\" in raw && Array.isArray(raw.filters)) {\n const allChildrenAreGroups = raw.filters.every(\n (f: FilterNode) => f.type === \"and\" || f.type === \"or\" || f.type === \"not\",\n );\n if (allChildrenAreGroups) {\n return raw as PlDataTableFiltersWithMeta;\n }\n // Children are leaves — wrap them in a single group\n return {\n id: randomInt(),\n type: raw.type as \"and\" | \"or\",\n isExpanded: true,\n filters: [\n {\n id: randomInt(),\n type: raw.type as \"and\" | \"or\",\n isExpanded: true,\n filters: raw.filters as AnnotatedFilterSpec[],\n } as AnnotatedFilterSpec,\n ],\n };\n }\n\n return getEmptyGroupWithMeta();\n}\n\nfunction getEmptyGroup(): PlDataTableFilters {\n return {\n type: \"and\" as const,\n filters: [],\n };\n}\nfunction getEmptyGroupWithMeta(): PlDataTableFiltersWithMeta {\n return {\n ...getEmptyGroup(),\n id: randomInt(),\n isExpanded: true,\n } as PlDataTableFiltersWithMeta;\n}\n\n/**\n * Recursively ensures every node in a filter tree has an `id` field.\n * Does not set `source` meta — defaults are now a separate list.\n */\nfunction annotateFiltersWithIds(\n filters: PlDataTableFilters | PlDataTableFiltersWithMeta,\n): PlDataTableFiltersWithMeta {\n return annotateNodeWithIds(filters) as PlDataTableFiltersWithMeta;\n}\n\nfunction annotateNodeWithIds(\n node: FilterNode | PlDataTableFilters | PlDataTableFiltersWithMeta,\n): AnnotatedFilterSpec {\n switch (node.type) {\n case \"and\":\n return {\n id: getField(node, \"id\") ?? randomInt(),\n isExpanded: getField(node, \"isExpanded\") ?? true,\n type: \"and\" as const,\n filters: node.filters.map((child) => annotateNodeWithIds(child)),\n };\n case \"or\":\n return {\n id: getField(node, \"id\") ?? randomInt(),\n isExpanded: getField(node, \"isExpanded\") ?? true,\n type: \"or\" as const,\n filters: node.filters.map((child) => annotateNodeWithIds(child)),\n };\n case \"not\":\n return {\n id: randomInt(),\n isExpanded: true,\n type: \"not\" as const,\n filter: annotateNodeWithIds(node.filter),\n };\n default:\n return { ...node, id: getField(node, \"id\") ?? randomInt() } as AnnotatedFilterSpec;\n }\n}\n"],"mappings":";;;;;;;AAsDA,SAAgBA,EACd,GACA,GACA,GAC8B;CAC9B,IAAMC,IAASC,EAAM,OAAOC,GAAWC,CAAM,GACvCC,IAAUC,EAAMC,CAAM,IAAIN,IAASO,EAAgBP,GAAQM,CAAM;CACvE,OAAOF,EAAQ,WAAW,SAASI,IAC/B;EAAE,GAAGJ;EAAS,YAAYA,EAAQ,WAAW,MAAM,CAACI,CAAW;CAAE,IACjEJ;AACN;AAWA,SAAgBK,EACd,GACA,GACyB;CACzB,OAAOC,EACJ,QAAQ,MAAUC,EAAM,QAAQ,SAAS,CAAC,CAAC,CAC3C,KAAK,MAAiC;EACrC,IAAMC,IAASC,EAAUF,EAAM,IAAI,GAC7BG,IAAaC,EAAM,MAAM,MAAMC,EAAYC,EAAE,QAAQL,CAAM,CAAC;EAClE,IAAID,EAAM,cAAc,cAAc,CAACN,EAAMS,CAAU,KAAK,eAAeA,GACzE,OAAO;GAAE;GAAQ,WAAW;EAAK;EAQnC,IAAMI,KALJb,EAAMS,CAAU,KAAK,eAAeA,IAChC,CAAC,IACD,WAAWA,IACT,CAACA,EAAW,KAAK,IACjBA,EAAW,OAAA,CACS,QAAQ,MAAUK,EAAcR,GAAOS,CAAK,CAAC;EAIzE,OAHIT,EAAM,cAAc,aACf;GAAE;GAAQ,QAAQO,EAAQ,SAAS,IAAIA,IAAU,CAACG,EAAkBV,CAAK,CAAC;EAAE,IAE9E;GAAE;GAAQ,OAAOO,EAAQ,MAAMG,EAAkBV,CAAK;EAAE;CACjE,CAAC;AACL;AAEA,SAAgBW,EACd,GACA,GACA,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SACE,OAAO;GAAE,GAAGA;GAAM,IAAIC,EAASD,GAAM,IAAI,KAAKL,EAAU;EAAE;CAC9D;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"PlAnnotations.vue_vue_type_script_setup_true_lang.js","names":["$style","_openBlock","_createBlock","_unref","_withCtx","_createVNode","AnnotationsSidebar","_normalizeClass","FilterSidebar","_createCommentVNode","AnnotationsSidebar_default","FilterSidebar_default","PlAnnotations_vue_vue_type_script_setup_true_lang_default","props","__props","selectedStepId","shallowRef","selectedStep","computed","isNil","step","confirmResetSchema","useConfirm","handleDeleteSchema","updateSelectedStepId","id","updateSelectedStep","produce","idx","draft","s","openBlock","createBlock","unref","PlSidebarGroup","withCtx","createVNode","normalizeClass","_ctx","createCommentVNode"],"sources":["../../../../src/components/PlAnnotations/components/PlAnnotations.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Props as BaseProps } from \"./FilterSidebar.vue\";\nexport type Props = Omit<BaseProps, \"step\" | \"onUpdateStep\"> & {\n annotation: Annotation;\n onUpdateAnnotation: (annotation: Annotation) => void;\n onDeleteSchema?: () => void;\n};\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, effect, shallowRef } from \"vue\";\n\nimport { isNil } from \"@milaboratories/helpers\";\nimport { produce } from \"immer\";\nimport { PlSidebarGroup, useConfirm } from \"@milaboratories/uikit\";\n\nimport type { Annotation, Filter } from \"../types\";\nimport AnnotationsSidebar from \"./AnnotationsSidebar.vue\";\nimport FilterSidebar from \"./FilterSidebar.vue\";\n\nconst props = defineProps<Props>();\n\nconst selectedStepId = shallowRef<undefined | number>(undefined);\n\nconst selectedStep = computed(() => {\n return isNil(selectedStepId.value) || isNil(props.annotation)\n ? undefined\n : props.annotation.steps.find((step) => step.id === selectedStepId.value);\n});\n\neffect(function setDefaultStepId() {\n if (selectedStepId.value === undefined && props.annotation.steps.length > 0) {\n selectedStepId.value = props.annotation.steps[0].id;\n }\n});\n\nconst confirmResetSchema = useConfirm({\n title: \"Reset Schema\",\n message: \"Are you sure you want to reset the schema? This action cannot be undone.\",\n confirmLabel: \"Yes, reset\",\n cancelLabel: \"No, cancel\",\n});\n\nasync function handleDeleteSchema() {\n if (await confirmResetSchema()) {\n selectedStepId.value = undefined;\n props.onDeleteSchema?.();\n }\n}\n\nfunction updateSelectedStepId(id: undefined | number) {\n selectedStepId.value = id;\n}\n\nfunction updateSelectedStep(step: Filter) {\n props.onUpdateAnnotation(\n produce(props.annotation, (draft) => {\n const idx = draft.steps.findIndex((s) => s.id === step.id);\n if (idx !== -1) {\n draft.steps[idx] = step;\n }\n }),\n );\n}\n</script>\n\n<template>\n <PlSidebarGroup data-testid=\"pl-annotations\">\n <template #item-0>\n <AnnotationsSidebar\n :annotation=\"props.annotation\"\n :selected-step-id=\"selectedStepId\"\n :on-update-annotation=\"props.onUpdateAnnotation\"\n :on-update-selected-step-id=\"updateSelectedStepId\"\n :class=\"$style.sidebarItem\"\n @delete-schema=\"handleDeleteSchema\"\n />\n </template>\n <template #item-1>\n <FilterSidebar\n v-if=\"selectedStep\"\n :step=\"selectedStep\"\n :on-update-step=\"updateSelectedStep\"\n :class=\"$style.sidebarItem\"\n :columns=\"props.columns\"\n :get-suggest-options=\"props.getSuggestOptions\"\n :hasSelectedColumns=\"props.hasSelectedColumns\"\n :getValuesForSelectedColumns=\"props.getValuesForSelectedColumns\"\n />\n </template>\n </PlSidebarGroup>\n</template>\n\n<style module>\n.sidebarItem {\n width: 100%;\n height: 100%;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAoBA,IAAMa,IAAQC,GAERC,IAAiBC,EAA+B,KAAA,CAAS,GAEzDC,IAAeC,QACZC,EAAMJ,EAAe,KAAK,KAAKI,EAAMN,EAAM,UAAU,IACxD,KAAA,IACAA,EAAM,WAAW,MAAM,MAAM,MAASO,EAAK,OAAOL,EAAe,KAAK,CAC3E;EAED,EAAO,WAA4B;GACjC,AAAIA,EAAe,UAAU,KAAA,KAAaF,EAAM,WAAW,MAAM,SAAS,MACxE,EAAe,QAAQA,EAAM,WAAW,MAAM,EAAE,CAAC;EAErD,CAAC;EAED,IAAMQ,IAAqBC,EAAW;GACpC,OAAO;GACP,SAAS;GACT,cAAc;GACd,aAAa;EACf,CAAC;EAED,eAAeC,IAAqB;GAClC,AAAI,MAAMF,EAAmB,MAC3B,EAAe,QAAQ,KAAA,GACvBR,EAAM,iBAAiB;EAE3B;EAEA,SAASW,EAAqB,GAAwB;GACpD,EAAe,QAAQC;EACzB;EAEA,SAASC,EAAmB,GAAc;GACxC,EAAM,mBACJC,EAAQd,EAAM,aAAa,MAAU;IACnC,IAAMe,IAAMC,EAAM,MAAM,WAAW,MAAMC,EAAE,OAAOV,EAAK,EAAE;IACzD,AAAIQ,MAAQ,OACV,EAAM,MAAMA,KAAOR;GAEvB,CAAC,CACH;EACF;E,kBAIEnB,EAAA,GAAAC,EAuBiBC,EAAA+B,CAAA,GAAA,EAvBD,eAAY,iBAAgB,GAAA;GAC/B,UAAM9B,QAQb,CAPFC,EAOEC,GAAA;IANC,YAAYO,EAAM;IAClB,oBAAkBE,EAAA;IAClB,wBAAsBF,EAAM;IAC5B,8BAA4BW;IAC5B,OAAKjB,EAAEP,EAAAA,OAAO,WAAW;IACzB,gBAAeuB;;;;;;;GAGT,UAAMnB,QAiBD,CAfNa,EAAA,SADRhB,EAAA,GAAAC,EASEM,GAAA;;IAPC,MAAMS,EAAA;IACN,kBAAgBS;IAChB,OAAKnB,EAAEP,EAAAA,OAAO,WAAW;IACzB,SAASa,EAAM;IACf,uBAAqBA,EAAM;IAC3B,oBAAoBA,EAAM;IAC1B,6BAA6BA,EAAM"}
1
+ {"version":3,"file":"PlAnnotations.vue_vue_type_script_setup_true_lang.js","names":["$style","_openBlock","_createBlock","_unref","_withCtx","_createVNode","AnnotationsSidebar","_normalizeClass","FilterSidebar","_createCommentVNode","AnnotationsSidebar_default","FilterSidebar_default","PlAnnotations_vue_vue_type_script_setup_true_lang_default","props","__props","selectedStepId","shallowRef","selectedStep","computed","isNil","step","confirmResetSchema","useConfirm","handleDeleteSchema","updateSelectedStepId","id","updateSelectedStep","produce","idx","draft","s","openBlock","createBlock","unref","PlSidebarGroup","withCtx","createVNode","normalizeClass","_ctx","createCommentVNode"],"sources":["../../../../src/components/PlAnnotations/components/PlAnnotations.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Props as BaseProps } from \"./FilterSidebar.vue\";\nexport type Props = Omit<BaseProps, \"step\" | \"onUpdateStep\"> & {\n annotation: Annotation;\n onUpdateAnnotation: (annotation: Annotation) => void;\n onDeleteSchema?: () => void;\n};\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, effect, shallowRef } from \"vue\";\n\nimport { isNil } from \"@milaboratories/helpers\";\nimport { produce } from \"immer\";\nimport { PlSidebarGroup, useConfirm } from \"@milaboratories/uikit\";\n\nimport type { Annotation, Filter } from \"../types\";\nimport AnnotationsSidebar from \"./AnnotationsSidebar.vue\";\nimport FilterSidebar from \"./FilterSidebar.vue\";\n\nconst props = defineProps<Props>();\n\nconst selectedStepId = shallowRef<undefined | number>(undefined);\n\nconst selectedStep = computed(() => {\n return isNil(selectedStepId.value) || isNil(props.annotation)\n ? undefined\n : props.annotation.steps.find((step) => step.id === selectedStepId.value);\n});\n\neffect(function setDefaultStepId() {\n if (selectedStepId.value === undefined && props.annotation.steps.length > 0) {\n selectedStepId.value = props.annotation.steps[0].id;\n }\n});\n\nconst confirmResetSchema = useConfirm({\n title: \"Reset Schema\",\n message: \"Are you sure you want to reset the schema? This action cannot be undone.\",\n confirmLabel: \"Yes, reset\",\n cancelLabel: \"No, cancel\",\n});\n\nasync function handleDeleteSchema() {\n if (await confirmResetSchema()) {\n selectedStepId.value = undefined;\n props.onDeleteSchema?.();\n }\n}\n\nfunction updateSelectedStepId(id: undefined | number) {\n selectedStepId.value = id;\n}\n\nfunction updateSelectedStep(step: Filter) {\n props.onUpdateAnnotation(\n produce(props.annotation, (draft) => {\n const idx = draft.steps.findIndex((s) => s.id === step.id);\n if (idx !== -1) {\n draft.steps[idx] = step;\n }\n }),\n );\n}\n</script>\n\n<template>\n <PlSidebarGroup data-testid=\"pl-annotations\">\n <template #item-0>\n <AnnotationsSidebar\n :annotation=\"props.annotation\"\n :selected-step-id=\"selectedStepId\"\n :on-update-annotation=\"props.onUpdateAnnotation\"\n :on-update-selected-step-id=\"updateSelectedStepId\"\n :class=\"$style.sidebarItem\"\n @delete-schema=\"handleDeleteSchema\"\n />\n </template>\n <template #item-1>\n <FilterSidebar\n v-if=\"selectedStep\"\n :step=\"selectedStep\"\n :on-update-step=\"updateSelectedStep\"\n :class=\"$style.sidebarItem\"\n :columns=\"props.columns\"\n :get-suggest-options=\"props.getSuggestOptions\"\n :hasSelectedColumns=\"props.hasSelectedColumns\"\n :getValuesForSelectedColumns=\"props.getValuesForSelectedColumns\"\n />\n </template>\n </PlSidebarGroup>\n</template>\n\n<style module>\n.sidebarItem {\n width: 100%;\n height: 100%;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAoBA,IAAMa,IAAQC,GAERC,IAAiBC,EAA+B,KAAA,CAAS,GAEzDC,IAAeC,QACZC,EAAMJ,EAAe,KAAK,KAAKI,EAAMN,EAAM,UAAU,IACxD,KAAA,IACAA,EAAM,WAAW,MAAM,MAAM,MAASO,EAAK,OAAOL,EAAe,KAAK,CAC3E;EAED,EAAO,WAA4B;GACjC,AAAIA,EAAe,UAAU,KAAA,KAAaF,EAAM,WAAW,MAAM,SAAS,MACxE,EAAe,QAAQA,EAAM,WAAW,MAAM,EAAE,CAAC;EAErD,CAAC;EAED,IAAMQ,IAAqBC,EAAW;GACpC,OAAO;GACP,SAAS;GACT,cAAc;GACd,aAAa;EACf,CAAC;EAED,eAAeC,IAAqB;GAClC,AAAI,MAAMF,EAAmB,MAC3B,EAAe,QAAQ,KAAA,GACvBR,EAAM,iBAAiB;EAE3B;EAEA,SAASW,EAAqB,GAAwB;GACpD,EAAe,QAAQC;EACzB;EAEA,SAASC,EAAmB,GAAc;GACxC,EAAM,mBACJC,EAAQd,EAAM,aAAa,MAAU;IACnC,IAAMe,IAAMC,EAAM,MAAM,WAAW,MAAMC,EAAE,OAAOV,EAAK,EAAE;IACzD,AAAIQ,MAAQ,OACV,EAAM,MAAMA,KAAOR;GAEvB,CAAC,CACH;EACF;E,kBAIEnB,EAAA,GAAAC,EAuBiBC,EAAA+B,CAAA,GAAA,EAvBD,eAAY,iBAAgB,GAAA;GAC/B,UAAM9B,QAQb,CAPFC,EAOEC,GAAA;IANC,YAAYO,EAAM;IAClB,oBAAkBE,EAAA;IAClB,wBAAsBF,EAAM;IAC5B,8BAA4BW;IAC5B,OAAKjB,EAAEP,EAAAA,OAAO,WAAW;IACzB,gBAAeuB;;;;;;;GAGT,UAAMnB,QAUb,CARMa,EAAA,SADRhB,EAAA,GAAAC,EASEM,GAAA;;IAPC,MAAMS,EAAA;IACN,kBAAgBS;IAChB,OAAKnB,EAAEP,EAAAA,OAAO,WAAW;IACzB,SAASa,EAAM;IACf,uBAAqBA,EAAM;IAC3B,oBAAoBA,EAAM;IAC1B,6BAA6BA,EAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.90.20",
3
+ "version": "1.91.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -14,8 +14,8 @@
14
14
  "@milaboratories/columns-collection-driver": "0.3.0",
15
15
  "@milaboratories/pf-spec-driver": "1.6.2",
16
16
  "@milaboratories/pl-model-common": "1.56.0",
17
- "@milaboratories/uikit": "2.17.11",
18
- "@platforma-sdk/model": "1.90.20",
17
+ "@milaboratories/uikit": "2.17.13",
18
+ "@platforma-sdk/model": "1.91.0",
19
19
  "@types/d3-format": "^3.0.4",
20
20
  "@types/node": "~24.19.2",
21
21
  "@types/semver": "^7.7.0",
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
- import { PlDropdownLine } from "@milaboratories/uikit";
2
+ import { PlDropdownLine, PlDropdownMulti, type ListOption } from "@milaboratories/uikit";
3
3
  import type { PlDataTableSheet, PlDataTableSheetState } from "@platforma-sdk/model";
4
- import { getAxisId } from "@platforma-sdk/model";
4
+ import { Annotation, getAxisId, readAnnotation } from "@platforma-sdk/model";
5
5
  import { computed } from "vue";
6
6
  import { isJsonEqual } from "@milaboratories/helpers";
7
7
  import type { PlDataTableSheetNormalized } from "./types";
@@ -9,47 +9,119 @@ import type { PlDataTableSheetNormalized } from "./types";
9
9
  const props = defineProps<{
10
10
  /** Sheets of the source on screen */
11
11
  sheets: PlDataTableSheet[];
12
- /** Value picked on each sheet that has options, in the same order */
12
+ /** Values picked on each sheet that has options */
13
13
  state: PlDataTableSheetState[];
14
14
  onChange: (state: PlDataTableSheetState[]) => void;
15
15
  }>();
16
16
 
17
+ /** An entry of a sheet's multiple choice: every value of the sheet, or one of them. */
18
+ type SheetChoice = { type: "all" } | { type: "value"; value: string | number };
19
+
20
+ type SheetView = PlDataTableSheetNormalized &
21
+ (
22
+ | { selection: "single"; value: string | number }
23
+ | {
24
+ selection: "multiple";
25
+ label: string;
26
+ choices: SheetChoice[];
27
+ choiceOptions: ListOption<SheetChoice>[];
28
+ }
29
+ );
30
+
17
31
  // Sheets without options are not shown
18
- const sheets = computed<PlDataTableSheetNormalized[]>(() =>
32
+ const views = computed<SheetView[]>(() =>
19
33
  props.sheets
20
34
  .filter((sheet) => sheet.options.length > 0)
21
- .map((sheet, i) => ({
22
- axisId: getAxisId(sheet.axis),
23
- prefix: (sheet.axis.annotations?.["pl7.app/label"]?.trim() ?? `Unlabeled axis ${i}`) + ":",
24
- options: sheet.options,
25
- })),
35
+ .flatMap((sheet, i): SheetView[] => {
36
+ const axisId = getAxisId(sheet.axis);
37
+ const state = props.state.find((s) => isJsonEqual(s.axisId, axisId));
38
+ if (state === undefined) return [];
39
+ const label = readAnnotation(sheet.axis, Annotation.Label)?.trim() ?? `Unlabeled axis ${i}`;
40
+ const base: PlDataTableSheetNormalized = {
41
+ axisId,
42
+ prefix: label + ":",
43
+ options: sheet.options,
44
+ };
45
+ if (sheet.selection === "single") {
46
+ return "value" in state ? [{ ...base, selection: "single", value: state.value }] : [];
47
+ }
48
+ return [
49
+ {
50
+ ...base,
51
+ selection: "multiple",
52
+ label,
53
+ choices: toChoices(state),
54
+ choiceOptions: [
55
+ { value: { type: "all" }, label: "All" },
56
+ ...sheet.options.map((option): ListOption<SheetChoice> => ({
57
+ value: { type: "value", value: option.value },
58
+ label: option.label,
59
+ })),
60
+ ],
61
+ },
62
+ ];
63
+ }),
26
64
  );
27
65
 
28
- function onSheetChanged(i: number, value: string | number): void {
29
- if (props.state[i]?.value === value) return;
30
- const axisId = sheets.value[i].axisId;
31
- props.onChange([
32
- ...props.state.filter((sheet) => !isJsonEqual(sheet.axisId, axisId)),
33
- { axisId, value },
34
- ]);
66
+ function onValueChanged(axisId: PlDataTableSheetNormalized["axisId"], value: string | number) {
67
+ change({ axisId, value });
68
+ }
69
+
70
+ /**
71
+ * "All" excludes the single values: picking it drops them, and picking a value
72
+ * while "All" is on keeps only the values.
73
+ */
74
+ function onChoicesChanged(
75
+ axisId: PlDataTableSheetNormalized["axisId"],
76
+ current: SheetChoice[],
77
+ next: SheetChoice[],
78
+ ) {
79
+ const picksAll = next.some((c) => c.type === "all");
80
+ const hadAll = current.some((c) => c.type === "all");
81
+ const values = next.flatMap((c) => (c.type === "value" ? [c.value] : []));
82
+ change(
83
+ picksAll && (!hadAll || values.length === 0) ? { axisId, allValues: true } : { axisId, values },
84
+ );
85
+ }
86
+
87
+ function change(next: PlDataTableSheetState): void {
88
+ const current = props.state.find((s) => isJsonEqual(s.axisId, next.axisId));
89
+ if (isJsonEqual(current, next)) return;
90
+ props.onChange([...props.state.filter((s) => !isJsonEqual(s.axisId, next.axisId)), next]);
91
+ }
92
+
93
+ function toChoices(state: PlDataTableSheetState): SheetChoice[] {
94
+ if ("value" in state) return [{ type: "value", value: state.value }];
95
+ if ("allValues" in state) return [{ type: "all" }];
96
+ return state.values.map((value) => ({ type: "value", value }));
35
97
  }
36
98
  </script>
37
99
 
38
100
  <template>
39
101
  <div
40
- v-if="$slots['before'] || sheets.length > 0 || $slots['after']"
102
+ v-if="$slots['before'] || views.length > 0 || $slots['after']"
41
103
  data-testid="pl-ag-data-table-sheets"
42
104
  :class="$style.container"
43
105
  >
44
106
  <slot name="before" />
45
- <template v-for="(sheet, i) in sheets" :key="i">
107
+ <template v-for="(view, i) in views" :key="i">
108
+ <PlDropdownMulti
109
+ v-if="view.selection === 'multiple'"
110
+ data-testid="pl-ag-data-table-sheets-dropdown-multi"
111
+ :model-value="view.choices"
112
+ :options="view.choiceOptions"
113
+ :label="view.label"
114
+ @update:model-value="
115
+ (next: SheetChoice[]) => onChoicesChanged(view.axisId, view.choices, next)
116
+ "
117
+ />
46
118
  <PlDropdownLine
47
- v-if="state[i]"
119
+ v-else
48
120
  data-testid="pl-ag-data-table-sheets-dropdown"
49
- :model-value="state[i].value"
50
- :options="sheet.options"
51
- :prefix="sheet.prefix"
52
- @update:model-value="(value: string | number) => onSheetChanged(i, value)"
121
+ :model-value="view.value"
122
+ :options="view.options"
123
+ :prefix="view.prefix"
124
+ @update:model-value="(value: string | number) => onValueChanged(view.axisId, value)"
53
125
  />
54
126
  </template>
55
127
  <slot name="after" />
@@ -447,6 +447,7 @@ watch(
447
447
  visibleTableHandle: settings.model?.visibleTableHandle,
448
448
  columnsMeta: settings.model?.columnsMeta,
449
449
  sheets: settings.sheets ?? [],
450
+ sheetsState: sheetsState.value,
450
451
  dataRenderedTracker,
451
452
  hiddenColIds: hiddenColIds.value?.map((id) => canonicalizeJson<PTableColumnId>(id)),
452
453
  cellButtonAxisParams: {
@@ -14,6 +14,7 @@ import {
14
14
  pTableValue,
15
15
  type PFrameDriver,
16
16
  type PlDataTableSheet,
17
+ type PlDataTableSheetState,
17
18
  type PTableVector,
18
19
  type AxisId,
19
20
  type PTableColumnSpec,
@@ -23,6 +24,7 @@ import {
23
24
  isLinkerColumn as isLinkerColumnSpec,
24
25
  isColumnHidden,
25
26
  isColumnOptional,
27
+ isSheetFixedToOneValue,
26
28
  matchAxisId,
27
29
  readAnnotation,
28
30
  readAnnotationJson,
@@ -85,6 +87,7 @@ export async function calculateGridOptions({
85
87
  generation,
86
88
  pfDriver,
87
89
  sheets,
90
+ sheetsState,
88
91
  fullTableHandle,
89
92
  visibleTableHandle,
90
93
  columnsMeta,
@@ -93,6 +96,8 @@ export async function calculateGridOptions({
93
96
  cellButtonAxisParams,
94
97
  }: {
95
98
  sheets: PlDataTableSheet[];
99
+ /** Values picked on the sheets */
100
+ sheetsState: PlDataTableSheetState[];
96
101
  pfDriver: PFrameDriver;
97
102
  generation: Ref<number>;
98
103
  fullTableHandle: PTableHandle;
@@ -126,7 +131,7 @@ export async function calculateGridOptions({
126
131
  // index mapping from full specs to visible subset (hidden columns → -1)
127
132
  const specsToVisibleSpecsMapping = buildSpecsToVisibleSpecsMapping(tableSpecs, visibleTableSpecs);
128
133
 
129
- const isPartitionedAxis = createPartitionedAxisPredicate(sheets);
134
+ const isPartitionedAxis = createPartitionedAxisPredicate(sheets, sheetsState);
130
135
 
131
136
  // label columns indexed by labeled axis (used for displayability filter)
132
137
  const getLabelColumnIndex = collectLabelColumnsByAxis(tableSpecs, isPartitionedAxis);
@@ -442,10 +447,23 @@ function buildSpecsToVisibleSpecsMapping(
442
447
  );
443
448
  }
444
449
 
445
- /** Predicate that returns true when an axis is one of the sheet partition axes. */
446
- function createPartitionedAxisPredicate(sheets: PlDataTableSheet[]): (axisId: AxisId) => boolean {
447
- const sheetAxesIds = sheets.map((sheet) => getAxisId(sheet.axis));
448
- return (axisId) => sheetAxesIds.some((id) => matchAxisId(id, axisId));
450
+ /**
451
+ * Predicate that returns true when an axis is the axis of a sheet showing one
452
+ * value. Every row then holds that value, so neither the axis nor its label
453
+ * column is shown; a sheet showing several values leaves both in view, so rows
454
+ * of different values can be told apart.
455
+ */
456
+ function createPartitionedAxisPredicate(
457
+ sheets: PlDataTableSheet[],
458
+ sheetsState: PlDataTableSheetState[],
459
+ ): (axisId: AxisId) => boolean {
460
+ const fixedAxesIds = sheets
461
+ .map((sheet) => getAxisId(sheet.axis))
462
+ .filter((axisId) => {
463
+ const state = sheetsState.find((s) => matchAxisId(s.axisId, axisId));
464
+ return state === undefined || isSheetFixedToOneValue(state);
465
+ });
466
+ return (axisId) => fixedAxesIds.some((id) => matchAxisId(id, axisId));
449
467
  }
450
468
 
451
469
  /**
@@ -471,7 +489,11 @@ function collectLabelColumnsByAxis(
471
489
  labelColumns.find((info) => matchAxisId(info.axisId, axisId))?.labelColumnIdx ?? -1;
472
490
  }
473
491
 
474
- /** Indices of columns to display: drop partitioned axes, label/linker columns, hidden columns. */
492
+ /**
493
+ * Indices of columns to display: drop the axes of sheets showing one value and
494
+ * their label columns, axes shown through their label column, linker columns
495
+ * and hidden columns.
496
+ */
475
497
  function selectDisplayableIndices(
476
498
  tableSpecs: PTableColumnSpec[],
477
499
  isPartitionedAxis: (axisId: AxisId) => boolean,
@@ -489,7 +511,11 @@ function selectDisplayableIndices(
489
511
  : effectiveVisibility(spec, meta) === "hidden") && !isPartitionedAxis(spec.id)
490
512
  );
491
513
  case "column":
492
- return effectiveVisibility(spec, meta) !== "hidden" && !isLinkerColumnSpec(spec.spec);
514
+ return (
515
+ effectiveVisibility(spec, meta) !== "hidden" &&
516
+ !isLinkerColumnSpec(spec.spec) &&
517
+ !(isLabelColumnSpec(spec.spec) && isPartitionedAxis(getAxisId(spec.spec.axesSpec[0])))
518
+ );
493
519
  }
494
520
  })
495
521
  .map(([i]) => i)
@@ -73,7 +73,9 @@ describe("resolveSheetsState", () => {
73
73
  { label: "S2", value: "s2" },
74
74
  ],
75
75
  defaultValue: "s2",
76
+ selection: "single",
76
77
  };
78
+ const multiple: PlDataTableSheet = { ...sheet, selection: "multiple" };
77
79
  const axisId = getAxisId(axis("sample"));
78
80
 
79
81
  it("keeps a saved value the sheet still offers", () => {
@@ -94,6 +96,36 @@ describe("resolveSheetsState", () => {
94
96
  it("gives a sheet without options no entry", () => {
95
97
  expect(resolveSheetsState([{ ...sheet, options: [] }], [])).toEqual([]);
96
98
  });
99
+
100
+ it("keeps all values, or the saved values a sheet showing several still offers", () => {
101
+ expect(resolveSheetsState([multiple], [{ axisId, allValues: true }])).toEqual([
102
+ { axisId, allValues: true },
103
+ ]);
104
+ expect(resolveSheetsState([multiple], [{ axisId, values: ["s1", "gone", "s2"] }])).toEqual([
105
+ { axisId, values: ["s1", "s2"] },
106
+ ]);
107
+ });
108
+
109
+ it("shows the default on a sheet showing several once no saved value is left", () => {
110
+ expect(resolveSheetsState([multiple], [{ axisId, values: ["gone"] }])).toEqual([
111
+ { axisId, values: ["s2"] },
112
+ ]);
113
+ expect(resolveSheetsState([multiple], [{ axisId, values: [] }])).toEqual([
114
+ { axisId, values: ["s2"] },
115
+ ]);
116
+ });
117
+
118
+ it("carries a saved state over when the sheet changes how many values it shows", () => {
119
+ expect(resolveSheetsState([multiple], [{ axisId, value: "s1" }])).toEqual([
120
+ { axisId, values: ["s1"] },
121
+ ]);
122
+ expect(resolveSheetsState([sheet], [{ axisId, values: ["gone", "s1"] }])).toEqual([
123
+ { axisId, value: "s1" },
124
+ ]);
125
+ expect(resolveSheetsState([sheet], [{ axisId, allValues: true }])).toEqual([
126
+ { axisId, value: "s2" },
127
+ ]);
128
+ });
97
129
  });
98
130
 
99
131
  describe("useTableState", () => {
@@ -65,9 +65,13 @@ export function reduceTableState(
65
65
  }
66
66
 
67
67
  /**
68
- * The value shown on each sheet: the saved one while the sheet still offers it,
69
- * otherwise the sheet's default, otherwise its first option. Sheets without
70
- * options are not shown and get no entry.
68
+ * The values shown on each sheet. A sheet showing one value keeps the saved one
69
+ * while the sheet still offers it; a sheet showing several keeps taking all its
70
+ * values, or the saved values it still offers. When nothing saved is left, the sheet shows its
71
+ * default, otherwise its first option. A saved state of the other kind, from
72
+ * before the sheet changed how many values it shows, gives what it can: its
73
+ * value, or its first value still offered. Sheets without options are not shown
74
+ * and get no entry.
71
75
  */
72
76
  export function resolveSheetsState(
73
77
  sheets: PlDataTableSheet[],
@@ -75,16 +79,23 @@ export function resolveSheetsState(
75
79
  ): PlDataTableSheetState[] {
76
80
  return sheets
77
81
  .filter((sheet) => sheet.options.length > 0)
78
- .map((sheet) => {
82
+ .map((sheet): PlDataTableSheetState => {
79
83
  const axisId = getAxisId(sheet.axis);
80
- const savedValue = saved.find((s) => isJsonEqual(s.axisId, axisId))?.value;
81
- const value =
82
- !isNil(savedValue) && isSheetOption(sheet, savedValue)
83
- ? savedValue
84
- : !isNil(sheet.defaultValue) && isSheetOption(sheet, sheet.defaultValue)
85
- ? sheet.defaultValue
86
- : sheet.options[0].value;
87
- return { axisId, value };
84
+ const savedState = saved.find((s) => isJsonEqual(s.axisId, axisId));
85
+ if (sheet.selection === "multiple" && !isNil(savedState) && "allValues" in savedState) {
86
+ return { axisId, allValues: true };
87
+ }
88
+ const savedValues =
89
+ isNil(savedState) || "allValues" in savedState
90
+ ? []
91
+ : "value" in savedState
92
+ ? [savedState.value]
93
+ : savedState.values;
94
+ const offered = savedValues.filter((value) => isSheetOption(sheet, value));
95
+ if (sheet.selection === "multiple") {
96
+ return { axisId, values: offered.length > 0 ? offered : [defaultSheetValue(sheet)] };
97
+ }
98
+ return { axisId, value: offered[0] ?? defaultSheetValue(sheet) };
88
99
  });
89
100
  }
90
101
 
@@ -272,6 +283,12 @@ function isSheetOption(sheet: PlDataTableSheet, value: string | number): boolean
272
283
  return sheet.options.some((option) => option.value === value);
273
284
  }
274
285
 
286
+ function defaultSheetValue(sheet: PlDataTableSheet): string | number {
287
+ return !isNil(sheet.defaultValue) && isSheetOption(sheet, sheet.defaultValue)
288
+ ? sheet.defaultValue
289
+ : sheet.options[0].value;
290
+ }
291
+
275
292
  /**
276
293
  * Normalizes raw filter state into a valid root filter structure.
277
294
  * Valid structure is Root(Group, Group, ...) — double nesting required: