@platforma-sdk/model 1.68.8 → 1.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs +26 -44
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js +26 -44
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs +1 -5
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js +1 -5
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs +2 -14
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.js +3 -15
- package/dist/components/PlDataTable/createPlDataTable/utils.js.map +1 -1
- package/dist/components/PlDataTable/labels.cjs +0 -25
- package/dist/components/PlDataTable/labels.cjs.map +1 -1
- package/dist/components/PlDataTable/labels.js +2 -26
- package/dist/components/PlDataTable/labels.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +7 -7
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.ts +3 -42
- package/src/components/PlDataTable/createPlDataTable/discoverColumns.ts +0 -9
- package/src/components/PlDataTable/createPlDataTable/utils.test.ts +5 -131
- package/src/components/PlDataTable/createPlDataTable/utils.ts +2 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discoverColumns.cjs","names":["ColumnCollectionBuilder","toColumnSnapshotProvider","collectCtxColumnSnapshotProviders"],"sources":["../../../../src/components/PlDataTable/createPlDataTable/discoverColumns.ts"],"sourcesContent":["import type { PColumnSpec, PlRef, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { createDiscoveredPColumnId, isPlRef } from \"@milaboratories/pl-model-common\";\nimport type { RenderCtxBase } from \"../../../render\";\nimport type {\n ColumnSource,\n ColumnVariant,\n RelaxedColumnSelector,\n ColumnSnapshotProvider,\n ColumnSnapshot,\n} from \"../../../columns\";\nimport { ColumnCollectionBuilder } from \"../../../columns\";\nimport { toColumnSnapshotProvider } from \"../../../columns/column_snapshot_provider\";\nimport { collectCtxColumnSnapshotProviders } from \"../../../columns/ctx_column_sources\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport type { ColumnsSelectorConfig, TableColumnVariant } from \"./createPlDataTableV3\";\
|
|
1
|
+
{"version":3,"file":"discoverColumns.cjs","names":["ColumnCollectionBuilder","toColumnSnapshotProvider","collectCtxColumnSnapshotProviders"],"sources":["../../../../src/components/PlDataTable/createPlDataTable/discoverColumns.ts"],"sourcesContent":["import type { PColumnSpec, PlRef, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { createDiscoveredPColumnId, isPlRef } from \"@milaboratories/pl-model-common\";\nimport type { RenderCtxBase } from \"../../../render\";\nimport type {\n ColumnSource,\n ColumnVariant,\n RelaxedColumnSelector,\n ColumnSnapshotProvider,\n ColumnSnapshot,\n} from \"../../../columns\";\nimport { ColumnCollectionBuilder } from \"../../../columns\";\nimport { toColumnSnapshotProvider } from \"../../../columns/column_snapshot_provider\";\nimport { collectCtxColumnSnapshotProviders } from \"../../../columns/ctx_column_sources\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport type { ColumnsSelectorConfig, TableColumnVariant } from \"./createPlDataTableV3\";\n\nexport type DiscoverTableColumnOptions = {\n sources?: ColumnSource[];\n anchors: Record<string, PlRef | PObjectId | PColumnSpec | RelaxedColumnSelector>;\n selector: ColumnsSelectorConfig;\n};\n\n/** Discover columns from sources/anchors and normalize into a flat TableColumnVariant list. */\nexport function discoverTableColumnSnaphots(\n ctx: RenderCtxBase,\n options: DiscoverTableColumnOptions,\n): TableColumnVariant[] | undefined {\n // Resolve PlRef anchors to PColumnSpec\n const resolvedOptions = {\n ...options,\n anchors: resolveAnchors(ctx, options.anchors),\n };\n\n // Resolve providers\n const providers = resolveProviders(ctx, resolvedOptions.sources);\n if (providers.length === 0) return undefined;\n\n // Build collection (anchored or plain)\n const collection = new ColumnCollectionBuilder(ctx.getService(\"pframeSpec\"))\n .addSources(providers)\n .build(resolvedOptions);\n if (collection === undefined) return undefined;\n\n try {\n const variants = collection.findColumnVariants({\n ...(resolvedOptions.selector ?? {}),\n });\n const anchors = collection.getAnchors();\n return mapToTableColumnVariants(variants, anchors);\n } finally {\n collection.dispose();\n }\n}\n\n// --- Pure helper functions ---\n\n/** Resolve PlRef values in anchors to PColumnSpec via the result pool. */\nfunction resolveAnchors(\n ctx: RenderCtxBase,\n anchors: Record<string, PlRef | PObjectId | PColumnSpec | RelaxedColumnSelector>,\n): Record<string, PObjectId | PColumnSpec | RelaxedColumnSelector> {\n const result: Record<string, PObjectId | PColumnSpec | RelaxedColumnSelector> = {};\n for (const [key, value] of Object.entries(anchors)) {\n if (isPlRef(value)) {\n result[key] =\n ctx.resultPool.getPColumnSpecByRef(value) ??\n throwError(\n `Anchor ${key} with ref ${JSON.stringify(value)} could not be resolved to a PColumnSpec`,\n );\n } else {\n result[key] = value;\n }\n }\n return result;\n}\n\n/** Resolve column snapshot providers from explicit sources or context. */\nfunction resolveProviders(\n ctx: RenderCtxBase,\n sources: undefined | ColumnSource[],\n): ColumnSnapshotProvider[] {\n return sources !== undefined\n ? sources.map(toColumnSnapshotProvider)\n : collectCtxColumnSnapshotProviders(ctx);\n}\n\n/** Map column variants into TableColumnVariant list with anchor-derived isPrimary flag. */\nfunction mapToTableColumnVariants(\n variants: readonly ColumnVariant[],\n anchors: Map<string, ColumnSnapshot<PObjectId>>,\n): TableColumnVariant[] {\n const columnIdToAnchorName = new Map<PObjectId, string>(\n Array.from(anchors.entries(), ([key, { id }]) => [id, key] as const),\n );\n\n return variants.map((variant): TableColumnVariant => {\n const snap = variant.column;\n const isPrimary = columnIdToAnchorName.get(snap.id) !== undefined;\n\n const discoveredId = createDiscoveredPColumnId({\n column: snap.id,\n path: variant.path.map((p) => ({\n type: \"linker\",\n column: p.linker.id,\n qualifications: p.qualifications,\n })),\n columnQualifications: variant.qualifications.forHit,\n queriesQualifications: variant.qualifications.forQueries,\n });\n return {\n column: {\n id: discoveredId,\n spec: snap.spec,\n data: snap.data,\n dataStatus: snap.dataStatus,\n },\n path: variant.path,\n qualifications: variant.qualifications,\n originalId: snap.id,\n isPrimary,\n };\n });\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,4BACd,KACA,SACkC;CAElC,MAAM,kBAAkB;EACtB,GAAG;EACH,SAAS,eAAe,KAAK,QAAQ,QAAQ;EAC9C;CAGD,MAAM,YAAY,iBAAiB,KAAK,gBAAgB,QAAQ;AAChE,KAAI,UAAU,WAAW,EAAG,QAAO,KAAA;CAGnC,MAAM,aAAa,IAAIA,kCAAAA,wBAAwB,IAAI,WAAW,aAAa,CAAC,CACzE,WAAW,UAAU,CACrB,MAAM,gBAAgB;AACzB,KAAI,eAAe,KAAA,EAAW,QAAO,KAAA;AAErC,KAAI;AAKF,SAAO,yBAJU,WAAW,mBAAmB,EAC7C,GAAI,gBAAgB,YAAY,EAAE,EACnC,CAAC,EACc,WAAW,YAAY,CACW;WAC1C;AACR,aAAW,SAAS;;;;AAOxB,SAAS,eACP,KACA,SACiE;CACjE,MAAM,SAA0E,EAAE;AAClF,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAChD,MAAA,GAAA,gCAAA,SAAY,MAAM,CAChB,QAAO,OACL,IAAI,WAAW,oBAAoB,MAAM,KAAA,GAAA,wBAAA,YAEvC,UAAU,IAAI,YAAY,KAAK,UAAU,MAAM,CAAC,yCACjD;KAEH,QAAO,OAAO;AAGlB,QAAO;;;AAIT,SAAS,iBACP,KACA,SAC0B;AAC1B,QAAO,YAAY,KAAA,IACf,QAAQ,IAAIC,iCAAAA,yBAAyB,GACrCC,2BAAAA,kCAAkC,IAAI;;;AAI5C,SAAS,yBACP,UACA,SACsB;CACtB,MAAM,uBAAuB,IAAI,IAC/B,MAAM,KAAK,QAAQ,SAAS,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,IAAI,CAAU,CACrE;AAED,QAAO,SAAS,KAAK,YAAgC;EACnD,MAAM,OAAO,QAAQ;EACrB,MAAM,YAAY,qBAAqB,IAAI,KAAK,GAAG,KAAK,KAAA;AAYxD,SAAO;GACL,QAAQ;IACN,KAAA,GAAA,gCAAA,2BAZ2C;KAC7C,QAAQ,KAAK;KACb,MAAM,QAAQ,KAAK,KAAK,OAAO;MAC7B,MAAM;MACN,QAAQ,EAAE,OAAO;MACjB,gBAAgB,EAAE;MACnB,EAAE;KACH,sBAAsB,QAAQ,eAAe;KAC7C,uBAAuB,QAAQ,eAAe;KAC/C,CAAC;IAIE,MAAM,KAAK;IACX,MAAM,KAAK;IACX,YAAY,KAAK;IAClB;GACD,MAAM,QAAQ;GACd,gBAAgB,QAAQ;GACxB,YAAY,KAAK;GACjB;GACD;GACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discoverColumns.d.ts","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/discoverColumns.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"discoverColumns.d.ts","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/discoverColumns.ts"],"mappings":";;;;;;;KAgBY,0BAAA;EACV,OAAA,GAAU,YAAA;EACV,OAAA,EAAS,MAAA,SAAe,KAAA,GAAQ,SAAA,GAAY,WAAA,GAAc,qBAAA;EAC1D,QAAA,EAAU,qBAAA;AAAA;AAHZ;AAAA,iBAOgB,2BAAA,CACd,GAAA,EAAK,aAAA,EACL,OAAA,EAAS,0BAAA,GACR,kBAAA"}
|
|
@@ -4,7 +4,6 @@ import { collectCtxColumnSnapshotProviders } from "../../../columns/ctx_column_s
|
|
|
4
4
|
import "../../../columns/index.js";
|
|
5
5
|
import { createDiscoveredPColumnId, isPlRef } from "@milaboratories/pl-model-common";
|
|
6
6
|
import { throwError } from "@milaboratories/helpers";
|
|
7
|
-
import { isNil as isNil$1 } from "es-toolkit";
|
|
8
7
|
//#region src/components/PlDataTable/createPlDataTable/discoverColumns.ts
|
|
9
8
|
/** Discover columns from sources/anchors and normalize into a flat TableColumnVariant list. */
|
|
10
9
|
function discoverTableColumnSnaphots(ctx, options) {
|
|
@@ -17,10 +16,7 @@ function discoverTableColumnSnaphots(ctx, options) {
|
|
|
17
16
|
const collection = new ColumnCollectionBuilder(ctx.getService("pframeSpec")).addSources(providers).build(resolvedOptions);
|
|
18
17
|
if (collection === void 0) return void 0;
|
|
19
18
|
try {
|
|
20
|
-
return mapToTableColumnVariants(collection.findColumnVariants({
|
|
21
|
-
...resolvedOptions.selector ?? {},
|
|
22
|
-
exclude: [...Array.isArray(resolvedOptions.selector?.exclude) ? resolvedOptions.selector.exclude : !isNil$1(resolvedOptions.selector.exclude) ? [resolvedOptions.selector.exclude] : [], { name: "pl7.app/label" }]
|
|
23
|
-
}), collection.getAnchors());
|
|
19
|
+
return mapToTableColumnVariants(collection.findColumnVariants({ ...resolvedOptions.selector ?? {} }), collection.getAnchors());
|
|
24
20
|
} finally {
|
|
25
21
|
collection.dispose();
|
|
26
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discoverColumns.js","names":["resolveAnchors"
|
|
1
|
+
{"version":3,"file":"discoverColumns.js","names":["resolveAnchors"],"sources":["../../../../src/components/PlDataTable/createPlDataTable/discoverColumns.ts"],"sourcesContent":["import type { PColumnSpec, PlRef, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { createDiscoveredPColumnId, isPlRef } from \"@milaboratories/pl-model-common\";\nimport type { RenderCtxBase } from \"../../../render\";\nimport type {\n ColumnSource,\n ColumnVariant,\n RelaxedColumnSelector,\n ColumnSnapshotProvider,\n ColumnSnapshot,\n} from \"../../../columns\";\nimport { ColumnCollectionBuilder } from \"../../../columns\";\nimport { toColumnSnapshotProvider } from \"../../../columns/column_snapshot_provider\";\nimport { collectCtxColumnSnapshotProviders } from \"../../../columns/ctx_column_sources\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport type { ColumnsSelectorConfig, TableColumnVariant } from \"./createPlDataTableV3\";\n\nexport type DiscoverTableColumnOptions = {\n sources?: ColumnSource[];\n anchors: Record<string, PlRef | PObjectId | PColumnSpec | RelaxedColumnSelector>;\n selector: ColumnsSelectorConfig;\n};\n\n/** Discover columns from sources/anchors and normalize into a flat TableColumnVariant list. */\nexport function discoverTableColumnSnaphots(\n ctx: RenderCtxBase,\n options: DiscoverTableColumnOptions,\n): TableColumnVariant[] | undefined {\n // Resolve PlRef anchors to PColumnSpec\n const resolvedOptions = {\n ...options,\n anchors: resolveAnchors(ctx, options.anchors),\n };\n\n // Resolve providers\n const providers = resolveProviders(ctx, resolvedOptions.sources);\n if (providers.length === 0) return undefined;\n\n // Build collection (anchored or plain)\n const collection = new ColumnCollectionBuilder(ctx.getService(\"pframeSpec\"))\n .addSources(providers)\n .build(resolvedOptions);\n if (collection === undefined) return undefined;\n\n try {\n const variants = collection.findColumnVariants({\n ...(resolvedOptions.selector ?? {}),\n });\n const anchors = collection.getAnchors();\n return mapToTableColumnVariants(variants, anchors);\n } finally {\n collection.dispose();\n }\n}\n\n// --- Pure helper functions ---\n\n/** Resolve PlRef values in anchors to PColumnSpec via the result pool. */\nfunction resolveAnchors(\n ctx: RenderCtxBase,\n anchors: Record<string, PlRef | PObjectId | PColumnSpec | RelaxedColumnSelector>,\n): Record<string, PObjectId | PColumnSpec | RelaxedColumnSelector> {\n const result: Record<string, PObjectId | PColumnSpec | RelaxedColumnSelector> = {};\n for (const [key, value] of Object.entries(anchors)) {\n if (isPlRef(value)) {\n result[key] =\n ctx.resultPool.getPColumnSpecByRef(value) ??\n throwError(\n `Anchor ${key} with ref ${JSON.stringify(value)} could not be resolved to a PColumnSpec`,\n );\n } else {\n result[key] = value;\n }\n }\n return result;\n}\n\n/** Resolve column snapshot providers from explicit sources or context. */\nfunction resolveProviders(\n ctx: RenderCtxBase,\n sources: undefined | ColumnSource[],\n): ColumnSnapshotProvider[] {\n return sources !== undefined\n ? sources.map(toColumnSnapshotProvider)\n : collectCtxColumnSnapshotProviders(ctx);\n}\n\n/** Map column variants into TableColumnVariant list with anchor-derived isPrimary flag. */\nfunction mapToTableColumnVariants(\n variants: readonly ColumnVariant[],\n anchors: Map<string, ColumnSnapshot<PObjectId>>,\n): TableColumnVariant[] {\n const columnIdToAnchorName = new Map<PObjectId, string>(\n Array.from(anchors.entries(), ([key, { id }]) => [id, key] as const),\n );\n\n return variants.map((variant): TableColumnVariant => {\n const snap = variant.column;\n const isPrimary = columnIdToAnchorName.get(snap.id) !== undefined;\n\n const discoveredId = createDiscoveredPColumnId({\n column: snap.id,\n path: variant.path.map((p) => ({\n type: \"linker\",\n column: p.linker.id,\n qualifications: p.qualifications,\n })),\n columnQualifications: variant.qualifications.forHit,\n queriesQualifications: variant.qualifications.forQueries,\n });\n return {\n column: {\n id: discoveredId,\n spec: snap.spec,\n data: snap.data,\n dataStatus: snap.dataStatus,\n },\n path: variant.path,\n qualifications: variant.qualifications,\n originalId: snap.id,\n isPrimary,\n };\n });\n}\n"],"mappings":";;;;;;;;AAuBA,SAAgB,4BACd,KACA,SACkC;CAElC,MAAM,kBAAkB;EACtB,GAAG;EACH,SAASA,iBAAe,KAAK,QAAQ,QAAQ;EAC9C;CAGD,MAAM,YAAY,iBAAiB,KAAK,gBAAgB,QAAQ;AAChE,KAAI,UAAU,WAAW,EAAG,QAAO,KAAA;CAGnC,MAAM,aAAa,IAAI,wBAAwB,IAAI,WAAW,aAAa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D;GACD"}
|
|
@@ -167,9 +167,8 @@ function withHidenAxesAnnotations(columns) {
|
|
|
167
167
|
}
|
|
168
168
|
/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */
|
|
169
169
|
function deriveAllLabels(options) {
|
|
170
|
-
const { columns,
|
|
171
|
-
|
|
172
|
-
const columnLabels = require_derive_distinct_labels.deriveDistinctLabels(columns.map((c) => ({
|
|
170
|
+
const { columns, deriveLabelsOptions } = options;
|
|
171
|
+
return require_derive_distinct_labels.deriveDistinctLabels(columns.map((c) => ({
|
|
173
172
|
spec: c.spec,
|
|
174
173
|
linkerPath: c.linkerPath?.map((step) => ({
|
|
175
174
|
spec: step.linker.spec,
|
|
@@ -177,17 +176,6 @@ function deriveAllLabels(options) {
|
|
|
177
176
|
})),
|
|
178
177
|
qualifications: c.qualifications
|
|
179
178
|
})), deriveLabelsOptions).reduce((acc, label, index) => (acc[columns[index].id] = label, acc), {});
|
|
180
|
-
return {
|
|
181
|
-
...axisLabels,
|
|
182
|
-
...columnLabels
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
/** Derive axis labels from matching label columns, falling back to axis spec annotations. */
|
|
186
|
-
function deriveAxisLabels(columns, labelColumns) {
|
|
187
|
-
const axisSpecMap = new Map(columns.flatMap((c) => c.spec.axesSpec).map((a) => [(0, _milaboratories_pl_model_common.canonicalizeJson)((0, _milaboratories_pl_model_common.getAxisId)(a)), a]));
|
|
188
|
-
const result = {};
|
|
189
|
-
for (const axisKey of axisSpecMap.keys()) result[axisKey] = (0, _milaboratories_pl_model_common.readAnnotation)(labelColumns.find((lc) => (0, _milaboratories_pl_model_common.canonicalizeJson)((0, _milaboratories_pl_model_common.getAxisId)(lc.spec.axesSpec[0])) === axisKey)?.spec ?? axisSpecMap.get(axisKey) ?? {}, _milaboratories_pl_model_common.Annotation.Label)?.trim() ?? "Unlabeled";
|
|
190
|
-
return result;
|
|
191
179
|
}
|
|
192
180
|
/** Derive origin tooltips for columns whose qualifications or linker path carry info. */
|
|
193
181
|
function deriveAllTooltips(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["Annotation","ColumnCollectionBuilder","ArrayColumnProvider","deriveDistinctLabels","deriveDistinctTooltips"],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"sourcesContent":["import {\n type PColumn,\n type PColumnSpec,\n type PFrameSpecDriver,\n type PObjectId,\n Annotation,\n canonicalizeAxisId,\n canonicalizeJson,\n DiscoveredPColumnId,\n getAxisId,\n readAnnotation,\n readAnnotationJson,\n} from \"@milaboratories/pl-model-common\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../../labels/derive_distinct_labels\";\nimport {\n deriveDistinctTooltips,\n type TooltipEntry,\n} from \"../../../labels/derive_distinct_tooltips\";\nimport type { MatchQualifications, MatchVariant } from \"../../../columns\";\nimport type { ColumnMatcher, ColumnOrderRule, ColumnVisibilityRule } from \"./createPlDataTableV3\";\nimport type { ColumnSelector } from \"../../../columns\";\nimport { ArrayColumnProvider, ColumnCollectionBuilder } from \"../../../columns\";\nimport { isNil } from \"es-toolkit\";\n\n/** Check if column should be omitted from the table */\nexport function isColumnHidden(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"hidden\";\n}\n\n/** Check if column is hidden by default */\nexport function isColumnOptional(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"optional\";\n}\n\n/** Column shape consumed by rule evaluation. */\nexport type RuleColumn = Pick<PColumn<PObjectId>, \"id\" | \"spec\">;\n\n/** Get effective visibility for a column. Rule map lookup first, then annotation fallback. */\nexport function getEffectiveVisibility(\n col: RuleColumn,\n visibilityByColId?: Map<PObjectId, ColumnVisibilityRule>,\n): undefined | \"default\" | \"optional\" | \"hidden\" {\n const rule = visibilityByColId?.get(col.id);\n if (rule !== undefined) return rule.visibility;\n if (isColumnHidden(col.spec)) return \"hidden\";\n if (isColumnOptional(col.spec)) return \"optional\";\n return undefined;\n}\n\n/** Get ordering priority for a column. Rule map lookup first, then annotation fallback. */\nexport function getOrderPriority(\n col: RuleColumn,\n orderByColId?: Map<PObjectId, ColumnOrderRule>,\n): undefined | number {\n const rule = orderByColId?.get(col.id);\n if (rule !== undefined) return rule.priority;\n return readAnnotationJson(col.spec, Annotation.Table.OrderPriority);\n}\n\n/**\n * Evaluate display rules against a set of columns and return a map of `colId → winning rule`\n * (first-match-wins, preserving original rule order).\n *\n * Predicate-based rules (`ColumnMatcher`) are evaluated directly on the spec.\n * Selector-based rules (`ColumnSelector`) are matched via `PFrameSpecDriver.discoverColumns`\n * using the same engine as `ColumnCollection.findColumns` — no client-side matcher.\n */\nexport function evaluateRules<R extends { match: ColumnMatcher | ColumnSelector }>(\n rules: R[],\n columns: RuleColumn[],\n pframeSpec: PFrameSpecDriver,\n): Map<PObjectId, R> {\n const result = new Map<PObjectId, R>();\n if (rules.length === 0 || columns.length === 0) return result;\n\n const hasSelectorRules = rules.some((rule) => typeof rule.match !== \"function\");\n const selectorHitsByRule = new Map<R, Set<PObjectId>>();\n\n if (hasSelectorRules) {\n const dedupedColumns = dedupeById(columns);\n const pColumns = dedupedColumns.map((c) => ({ id: c.id, spec: c.spec, data: undefined }));\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSource(new ArrayColumnProvider(pColumns))\n .build();\n if (collection === undefined) return result;\n\n try {\n for (const rule of rules) {\n if (typeof rule.match === \"function\") continue;\n const hits = collection.findColumns({ include: rule.match });\n selectorHitsByRule.set(rule, new Set(hits.map((h) => h.id)));\n }\n } finally {\n collection.dispose();\n }\n }\n\n for (const col of columns) {\n for (const rule of rules) {\n const matches =\n typeof rule.match === \"function\"\n ? rule.match(col.spec)\n : (selectorHitsByRule.get(rule)?.has(col.id) ?? false);\n if (matches) {\n result.set(col.id, rule);\n break;\n }\n }\n }\n return result;\n}\n\nfunction dedupeById(columns: RuleColumn[]): RuleColumn[] {\n const seen = new Set<PObjectId>();\n const result: RuleColumn[] = [];\n for (const col of columns) {\n if (seen.has(col.id)) continue;\n seen.add(col.id);\n result.push(col);\n }\n return result;\n}\n\n/**\n * Writes derived labels into column and axis annotations.\n * Returns new column objects with modified specs — original columns are not mutated.\n *\n * For each column: writes derived label into Annotation.Label (if present in derivedLabels).\n * For each axis in column specs: writes derived axis label into AxisSpec annotations.\n */\nexport function withLabelAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(derivedLabels: undefined | Record<string, string>, columns: T[]): T[] {\n if (derivedLabels === undefined) return columns;\n return columns.map((col) => {\n const colLabel = derivedLabels[col.id];\n return {\n ...col,\n spec: {\n ...col.spec,\n ...(isNil(colLabel)\n ? {}\n : { annotations: { ...col.spec.annotations, [Annotation.Label]: colLabel } }),\n axesSpec: col.spec.axesSpec.map((axis) => {\n const label = derivedLabels[canonicalizeAxisId(axis)];\n return isNil(label)\n ? axis\n : { ...axis, annotations: { ...axis.annotations, [Annotation.Label]: label } };\n }),\n },\n } as T;\n });\n}\n\n/**\n * Writes effective display properties (OrderPriority, Visibility) from precomputed rule maps\n * into column annotations. Returns new column objects — originals are not mutated.\n */\nexport function withTableVisualAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(\n visibilityByColId: undefined | Map<PObjectId, ColumnVisibilityRule>,\n orderByColId: undefined | Map<PObjectId, ColumnOrderRule>,\n columns: T[],\n): T[] {\n if (visibilityByColId === undefined && orderByColId === undefined) return columns;\n return columns.map((col) => {\n const annotations = { ...col.spec.annotations };\n\n const visibility = getEffectiveVisibility(col, visibilityByColId);\n if (!isNil(visibility)) annotations[Annotation.Table.Visibility] = visibility;\n\n const orderPriority = getOrderPriority(col, orderByColId);\n if (!isNil(orderPriority)) annotations[Annotation.Table.OrderPriority] = String(orderPriority);\n\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: annotations,\n },\n } as T;\n });\n}\n\n/**\n * Writes derived info annotations into column annotations.\n * Columns without an info entry are passed through unchanged.\n */\nexport function withInfoAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(infoById: undefined | Record<string, string>, columns: T[]): T[] {\n if (isNil(infoById)) return columns;\n return columns.map((col) => {\n const info = infoById[col.id];\n if (isNil(info)) return col;\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: { ...col.spec.annotations, [Annotation.Table.Info]: info },\n },\n } as T;\n });\n}\n\nexport function withHidenAxesAnnotations<T extends { readonly spec: PColumnSpec }>(\n columns: T[],\n): T[] {\n return columns.map(\n (col) =>\n ({\n ...col,\n spec: {\n ...col.spec,\n axesSpec: col.spec.axesSpec.map((axis) => ({\n ...axis,\n annotations: { ...axis.annotations, [Annotation.Table.Visibility]: \"hidden\" },\n })),\n },\n }) as T,\n );\n}\n\n/** Column shape required by label derivation. */\nexport type LabelableColumn = {\n readonly id: PObjectId;\n readonly spec: PColumnSpec;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */\nexport function deriveAllLabels(options: {\n columns: LabelableColumn[];\n labelColumns: { readonly spec: PColumnSpec }[];\n deriveLabelsOptions?: DeriveLabelsOptions;\n}): Record<string, string> {\n const { columns, labelColumns, deriveLabelsOptions } = options;\n const axisLabels = deriveAxisLabels(columns, labelColumns);\n const entries = columns.map((c) => ({\n spec: c.spec,\n linkerPath: c.linkerPath?.map((step) => ({\n spec: step.linker.spec,\n qualifications: step.qualifications,\n })),\n qualifications: c.qualifications,\n }));\n const columnLabels = deriveDistinctLabels(entries, deriveLabelsOptions).reduce(\n (acc, label, index) => ((acc[columns[index].id] = label), acc),\n {} as Record<string, string>,\n );\n return { ...axisLabels, ...columnLabels };\n}\n\n/** Derive axis labels from matching label columns, falling back to axis spec annotations. */\nfunction deriveAxisLabels(\n columns: { readonly spec: PColumnSpec }[],\n labelColumns: { readonly spec: PColumnSpec }[],\n): Record<string, string> {\n const axisSpecMap = new Map(\n columns.flatMap((c) => c.spec.axesSpec).map((a) => [canonicalizeJson(getAxisId(a)), a]),\n );\n const result: Record<string, string> = {};\n for (const axisKey of axisSpecMap.keys()) {\n const labelCol = labelColumns.find(\n (lc) => canonicalizeJson(getAxisId(lc.spec.axesSpec[0])) === axisKey,\n );\n const source = labelCol?.spec ?? axisSpecMap.get(axisKey);\n result[axisKey] = readAnnotation(source ?? {}, Annotation.Label)?.trim() ?? \"Unlabeled\";\n }\n return result;\n}\n\n/** Column shape required by tooltip derivation. */\nexport type TooltipableColumn = {\n readonly id: DiscoveredPColumnId;\n readonly spec: PColumnSpec;\n readonly originalId: PObjectId;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive origin tooltips for columns whose qualifications or linker path carry info. */\nexport function deriveAllTooltips(options: {\n columns: TooltipableColumn[];\n}): Record<DiscoveredPColumnId, string> {\n const { columns } = options;\n\n const variantCountByOriginal = columns.reduce<Map<PObjectId, number>>((acc, c) => {\n return acc.set(c.originalId, (acc.get(c.originalId) ?? 0) + 1);\n }, new Map());\n\n const { entries } = columns.reduce(\n ({ entries, variantSeen }, c) => {\n const variantCount = variantCountByOriginal.get(c.originalId);\n const variantIndex =\n (variantSeen.set(c.originalId, (variantSeen.get(c.originalId) ?? 0) + 1),\n variantSeen.get(c.originalId));\n\n entries.push({\n spec: c.spec,\n linkerPath: c.linkerPath,\n qualifications: c.qualifications,\n variantIndex,\n variantCount,\n });\n\n return { entries, variantSeen };\n },\n { entries: [] as TooltipEntry[], variantSeen: new Map<PObjectId, number>() },\n );\n\n const tooltips = deriveDistinctTooltips(entries);\n\n return Object.fromEntries(\n tooltips.flatMap((t, i) => (isNil(t) ? [] : [[columns[i].id, t] as const])),\n );\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,eAAe,MAA6C;AAC1E,SAAA,GAAA,gCAAA,gBAAsB,MAAMA,gCAAAA,WAAW,MAAM,WAAW,KAAK;;;AAI/D,SAAgB,iBA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AAI,KAAwB;EAAE,CAC7E;CAED,MAAM,WAAWI,iCAAAA,uBAAuB,QAAQ;AAEhD,QAAO,OAAO,YACZ,SAAS,SAAS,GAAG,OAAA,GAAA,WAAA,OAAa,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAU,CAAE,CAC5E"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["Annotation","ColumnCollectionBuilder","ArrayColumnProvider","deriveDistinctLabels","deriveDistinctTooltips"],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"sourcesContent":["import {\n type PColumn,\n type PColumnSpec,\n type PFrameSpecDriver,\n type PObjectId,\n Annotation,\n canonicalizeAxisId,\n DiscoveredPColumnId,\n readAnnotation,\n readAnnotationJson,\n} from \"@milaboratories/pl-model-common\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../../labels/derive_distinct_labels\";\nimport {\n deriveDistinctTooltips,\n type TooltipEntry,\n} from \"../../../labels/derive_distinct_tooltips\";\nimport type { MatchQualifications, MatchVariant } from \"../../../columns\";\nimport type { ColumnMatcher, ColumnOrderRule, ColumnVisibilityRule } from \"./createPlDataTableV3\";\nimport type { ColumnSelector } from \"../../../columns\";\nimport { ArrayColumnProvider, ColumnCollectionBuilder } from \"../../../columns\";\nimport { isNil } from \"es-toolkit\";\n\n/** Check if column should be omitted from the table */\nexport function isColumnHidden(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"hidden\";\n}\n\n/** Check if column is hidden by default */\nexport function isColumnOptional(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"optional\";\n}\n\n/** Column shape consumed by rule evaluation. */\nexport type RuleColumn = Pick<PColumn<PObjectId>, \"id\" | \"spec\">;\n\n/** Get effective visibility for a column. Rule map lookup first, then annotation fallback. */\nexport function getEffectiveVisibility(\n col: RuleColumn,\n visibilityByColId?: Map<PObjectId, ColumnVisibilityRule>,\n): undefined | \"default\" | \"optional\" | \"hidden\" {\n const rule = visibilityByColId?.get(col.id);\n if (rule !== undefined) return rule.visibility;\n if (isColumnHidden(col.spec)) return \"hidden\";\n if (isColumnOptional(col.spec)) return \"optional\";\n return undefined;\n}\n\n/** Get ordering priority for a column. Rule map lookup first, then annotation fallback. */\nexport function getOrderPriority(\n col: RuleColumn,\n orderByColId?: Map<PObjectId, ColumnOrderRule>,\n): undefined | number {\n const rule = orderByColId?.get(col.id);\n if (rule !== undefined) return rule.priority;\n return readAnnotationJson(col.spec, Annotation.Table.OrderPriority);\n}\n\n/**\n * Evaluate display rules against a set of columns and return a map of `colId → winning rule`\n * (first-match-wins, preserving original rule order).\n *\n * Predicate-based rules (`ColumnMatcher`) are evaluated directly on the spec.\n * Selector-based rules (`ColumnSelector`) are matched via `PFrameSpecDriver.discoverColumns`\n * using the same engine as `ColumnCollection.findColumns` — no client-side matcher.\n */\nexport function evaluateRules<R extends { match: ColumnMatcher | ColumnSelector }>(\n rules: R[],\n columns: RuleColumn[],\n pframeSpec: PFrameSpecDriver,\n): Map<PObjectId, R> {\n const result = new Map<PObjectId, R>();\n if (rules.length === 0 || columns.length === 0) return result;\n\n const hasSelectorRules = rules.some((rule) => typeof rule.match !== \"function\");\n const selectorHitsByRule = new Map<R, Set<PObjectId>>();\n\n if (hasSelectorRules) {\n const dedupedColumns = dedupeById(columns);\n const pColumns = dedupedColumns.map((c) => ({ id: c.id, spec: c.spec, data: undefined }));\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSource(new ArrayColumnProvider(pColumns))\n .build();\n if (collection === undefined) return result;\n\n try {\n for (const rule of rules) {\n if (typeof rule.match === \"function\") continue;\n const hits = collection.findColumns({ include: rule.match });\n selectorHitsByRule.set(rule, new Set(hits.map((h) => h.id)));\n }\n } finally {\n collection.dispose();\n }\n }\n\n for (const col of columns) {\n for (const rule of rules) {\n const matches =\n typeof rule.match === \"function\"\n ? rule.match(col.spec)\n : (selectorHitsByRule.get(rule)?.has(col.id) ?? false);\n if (matches) {\n result.set(col.id, rule);\n break;\n }\n }\n }\n return result;\n}\n\nfunction dedupeById(columns: RuleColumn[]): RuleColumn[] {\n const seen = new Set<PObjectId>();\n const result: RuleColumn[] = [];\n for (const col of columns) {\n if (seen.has(col.id)) continue;\n seen.add(col.id);\n result.push(col);\n }\n return result;\n}\n\n/**\n * Writes derived labels into column and axis annotations.\n * Returns new column objects with modified specs — original columns are not mutated.\n *\n * For each column: writes derived label into Annotation.Label (if present in derivedLabels).\n * For each axis in column specs: writes derived axis label into AxisSpec annotations.\n */\nexport function withLabelAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(derivedLabels: undefined | Record<string, string>, columns: T[]): T[] {\n if (derivedLabels === undefined) return columns;\n return columns.map((col) => {\n const colLabel = derivedLabels[col.id];\n return {\n ...col,\n spec: {\n ...col.spec,\n ...(isNil(colLabel)\n ? {}\n : { annotations: { ...col.spec.annotations, [Annotation.Label]: colLabel } }),\n axesSpec: col.spec.axesSpec.map((axis) => {\n const label = derivedLabels[canonicalizeAxisId(axis)];\n return isNil(label)\n ? axis\n : { ...axis, annotations: { ...axis.annotations, [Annotation.Label]: label } };\n }),\n },\n } as T;\n });\n}\n\n/**\n * Writes effective display properties (OrderPriority, Visibility) from precomputed rule maps\n * into column annotations. Returns new column objects — originals are not mutated.\n */\nexport function withTableVisualAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(\n visibilityByColId: undefined | Map<PObjectId, ColumnVisibilityRule>,\n orderByColId: undefined | Map<PObjectId, ColumnOrderRule>,\n columns: T[],\n): T[] {\n if (visibilityByColId === undefined && orderByColId === undefined) return columns;\n return columns.map((col) => {\n const annotations = { ...col.spec.annotations };\n\n const visibility = getEffectiveVisibility(col, visibilityByColId);\n if (!isNil(visibility)) annotations[Annotation.Table.Visibility] = visibility;\n\n const orderPriority = getOrderPriority(col, orderByColId);\n if (!isNil(orderPriority)) annotations[Annotation.Table.OrderPriority] = String(orderPriority);\n\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: annotations,\n },\n } as T;\n });\n}\n\n/**\n * Writes derived info annotations into column annotations.\n * Columns without an info entry are passed through unchanged.\n */\nexport function withInfoAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(infoById: undefined | Record<string, string>, columns: T[]): T[] {\n if (isNil(infoById)) return columns;\n return columns.map((col) => {\n const info = infoById[col.id];\n if (isNil(info)) return col;\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: { ...col.spec.annotations, [Annotation.Table.Info]: info },\n },\n } as T;\n });\n}\n\nexport function withHidenAxesAnnotations<T extends { readonly spec: PColumnSpec }>(\n columns: T[],\n): T[] {\n return columns.map(\n (col) =>\n ({\n ...col,\n spec: {\n ...col.spec,\n axesSpec: col.spec.axesSpec.map((axis) => ({\n ...axis,\n annotations: { ...axis.annotations, [Annotation.Table.Visibility]: \"hidden\" },\n })),\n },\n }) as T,\n );\n}\n\n/** Column shape required by label derivation. */\nexport type LabelableColumn = {\n readonly id: PObjectId;\n readonly spec: PColumnSpec;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */\nexport function deriveAllLabels(options: {\n columns: LabelableColumn[];\n deriveLabelsOptions?: DeriveLabelsOptions;\n}): Record<string, string> {\n const { columns, deriveLabelsOptions } = options;\n const entries = columns.map((c) => ({\n spec: c.spec,\n linkerPath: c.linkerPath?.map((step) => ({\n spec: step.linker.spec,\n qualifications: step.qualifications,\n })),\n qualifications: c.qualifications,\n }));\n const columnLabels = deriveDistinctLabels(entries, deriveLabelsOptions).reduce(\n (acc, label, index) => ((acc[columns[index].id] = label), acc),\n {} as Record<string, string>,\n );\n return columnLabels;\n}\n\n/** Column shape required by tooltip derivation. */\nexport type TooltipableColumn = {\n readonly id: DiscoveredPColumnId;\n readonly spec: PColumnSpec;\n readonly originalId: PObjectId;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive origin tooltips for columns whose qualifications or linker path carry info. */\nexport function deriveAllTooltips(options: {\n columns: TooltipableColumn[];\n}): Record<DiscoveredPColumnId, string> {\n const { columns } = options;\n\n const variantCountByOriginal = columns.reduce<Map<PObjectId, number>>((acc, c) => {\n return acc.set(c.originalId, (acc.get(c.originalId) ?? 0) + 1);\n }, new Map());\n\n const { entries } = columns.reduce(\n ({ entries, variantSeen }, c) => {\n const variantCount = variantCountByOriginal.get(c.originalId);\n const variantIndex =\n (variantSeen.set(c.originalId, (variantSeen.get(c.originalId) ?? 0) + 1),\n variantSeen.get(c.originalId));\n\n entries.push({\n spec: c.spec,\n linkerPath: c.linkerPath,\n qualifications: c.qualifications,\n variantIndex,\n variantCount,\n });\n\n return { entries, variantSeen };\n },\n { entries: [] as TooltipEntry[], variantSeen: new Map<PObjectId, number>() },\n );\n\n const tooltips = deriveDistinctTooltips(entries);\n\n return Object.fromEntries(\n tooltips.flatMap((t, i) => (isNil(t) ? [] : [[columns[i].id, t] as const])),\n );\n}\n"],"mappings":";;;;;;;;;;AA0BA,SAAgB,eAAe,MAA6C;AAC1E,SAAA,GAAA,gCAAA,gBAAsB,MAAMA,gCAAAA,WAAW,MAAM,WAAW,KAAK;;;AAI/D,SAAgB,iBAAiB,MAA6C;AAC5E,SAAA,GAAA,gCAAA,gBAAsB,MAAMA,gCAAAA,WAAW,MAAM,WAAW,KAAK;;;AAO/D,SAAgB,uBACd,KACA,mBAC+C;CAC/C,MAAM,OAAO,mBAAmB,IAAI,IAAI,GAAG;AAC3C,KAAI,SAAS,KAAA,EAAW,QAAO,KAAK;AACpC,KAAI,eAAe,IAAI,KAAK,CAAE,QAAO;AACrC,KAAI,iBAAiB,IAAI,KAAK,CAAE,QAAO;;;AAKzC,SAAgB,iBACd,KACA,cACoB;CACpB,MAAM,OAAO,cAAc,IAAI,IAAI,GAAG;AACtC,KAAI,SAA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aAAa,YAAY,IAAI,EAAE,WAAW,IAAI,KAAK,EAAE,EACxE,YAAY,IAAI,EAAE,WAAW;AAE/B,UAAQ,KAAK;GACX,MAAM,EAAE;GACR,YAAY,EAAE;GACd,gBAAgB,EAAE;GAClB;GACA;GACD,CAAC;AAEF,SAAO;GAAE;GAAS;GAAa;IAEjC;EAAE,SAAS,EAAE;EAAoB,6BAAa,IAAI,KAAwB;EAAE,CAC7E;CAED,MAAM,WAAWC,iCAAAA,uBAAuB,QAAQ;AAEhD,QAAO,OAAO,YACZ,SAAS,SAAS,GAAG,OAAA,GAAA,WAAA,OAAa,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAU,CAAE,CAC5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"mappings":";;;;;iBA0BgB,cAAA,CAAe,IAAA;EAAQ,WAAA,GAAc,UAAA;AAAA;;iBAKrC,gBAAA,CAAiB,IAAA;EAAQ,WAAA,GAAc,UAAA;AAAA;;KAK3C,UAAA,GAAa,IAAA,CAAK,OAAA,CAAQ,SAAA;AALtC;AAAA,iBAQgB,sBAAA,CACd,GAAA,EAAK,UAAA,EACL,iBAAA,GAAoB,GAAA,CAAI,SAAA,EAAW,oBAAA;;iBAUrB,gBAAA,CACd,GAAA,EAAK,UAAA,EACL,YAAA,GAAe,GAAA,CAAI,SAAA,EAAW,eAAA"}
|
|
@@ -3,7 +3,7 @@ import { ArrayColumnProvider } from "../../../columns/column_snapshot_provider.j
|
|
|
3
3
|
import { ColumnCollectionBuilder } from "../../../columns/column_collection_builder.js";
|
|
4
4
|
import "../../../columns/index.js";
|
|
5
5
|
import { deriveDistinctTooltips } from "../../../labels/derive_distinct_tooltips.js";
|
|
6
|
-
import { Annotation, canonicalizeAxisId,
|
|
6
|
+
import { Annotation, canonicalizeAxisId, readAnnotation, readAnnotationJson } from "@milaboratories/pl-model-common";
|
|
7
7
|
import { isNil } from "es-toolkit";
|
|
8
8
|
//#region src/components/PlDataTable/createPlDataTable/utils.ts
|
|
9
9
|
/** Check if column should be omitted from the table */
|
|
@@ -166,9 +166,8 @@ function withHidenAxesAnnotations(columns) {
|
|
|
166
166
|
}
|
|
167
167
|
/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */
|
|
168
168
|
function deriveAllLabels(options) {
|
|
169
|
-
const { columns,
|
|
170
|
-
|
|
171
|
-
const columnLabels = deriveDistinctLabels(columns.map((c) => ({
|
|
169
|
+
const { columns, deriveLabelsOptions } = options;
|
|
170
|
+
return deriveDistinctLabels(columns.map((c) => ({
|
|
172
171
|
spec: c.spec,
|
|
173
172
|
linkerPath: c.linkerPath?.map((step) => ({
|
|
174
173
|
spec: step.linker.spec,
|
|
@@ -176,17 +175,6 @@ function deriveAllLabels(options) {
|
|
|
176
175
|
})),
|
|
177
176
|
qualifications: c.qualifications
|
|
178
177
|
})), deriveLabelsOptions).reduce((acc, label, index) => (acc[columns[index].id] = label, acc), {});
|
|
179
|
-
return {
|
|
180
|
-
...axisLabels,
|
|
181
|
-
...columnLabels
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
/** Derive axis labels from matching label columns, falling back to axis spec annotations. */
|
|
185
|
-
function deriveAxisLabels(columns, labelColumns) {
|
|
186
|
-
const axisSpecMap = new Map(columns.flatMap((c) => c.spec.axesSpec).map((a) => [canonicalizeJson(getAxisId(a)), a]));
|
|
187
|
-
const result = {};
|
|
188
|
-
for (const axisKey of axisSpecMap.keys()) result[axisKey] = readAnnotation(labelColumns.find((lc) => canonicalizeJson(getAxisId(lc.spec.axesSpec[0])) === axisKey)?.spec ?? axisSpecMap.get(axisKey) ?? {}, Annotation.Label)?.trim() ?? "Unlabeled";
|
|
189
|
-
return result;
|
|
190
178
|
}
|
|
191
179
|
/** Derive origin tooltips for columns whose qualifications or linker path carry info. */
|
|
192
180
|
function deriveAllTooltips(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"sourcesContent":["import {\n type PColumn,\n type PColumnSpec,\n type PFrameSpecDriver,\n type PObjectId,\n Annotation,\n canonicalizeAxisId,\n canonicalizeJson,\n DiscoveredPColumnId,\n getAxisId,\n readAnnotation,\n readAnnotationJson,\n} from \"@milaboratories/pl-model-common\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../../labels/derive_distinct_labels\";\nimport {\n deriveDistinctTooltips,\n type TooltipEntry,\n} from \"../../../labels/derive_distinct_tooltips\";\nimport type { MatchQualifications, MatchVariant } from \"../../../columns\";\nimport type { ColumnMatcher, ColumnOrderRule, ColumnVisibilityRule } from \"./createPlDataTableV3\";\nimport type { ColumnSelector } from \"../../../columns\";\nimport { ArrayColumnProvider, ColumnCollectionBuilder } from \"../../../columns\";\nimport { isNil } from \"es-toolkit\";\n\n/** Check if column should be omitted from the table */\nexport function isColumnHidden(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"hidden\";\n}\n\n/** Check if column is hidden by default */\nexport function isColumnOptional(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"optional\";\n}\n\n/** Column shape consumed by rule evaluation. */\nexport type RuleColumn = Pick<PColumn<PObjectId>, \"id\" | \"spec\">;\n\n/** Get effective visibility for a column. Rule map lookup first, then annotation fallback. */\nexport function getEffectiveVisibility(\n col: RuleColumn,\n visibilityByColId?: Map<PObjectId, ColumnVisibilityRule>,\n): undefined | \"default\" | \"optional\" | \"hidden\" {\n const rule = visibilityByColId?.get(col.id);\n if (rule !== undefined) return rule.visibility;\n if (isColumnHidden(col.spec)) return \"hidden\";\n if (isColumnOptional(col.spec)) return \"optional\";\n return undefined;\n}\n\n/** Get ordering priority for a column. Rule map lookup first, then annotation fallback. */\nexport function getOrderPriority(\n col: RuleColumn,\n orderByColId?: Map<PObjectId, ColumnOrderRule>,\n): undefined | number {\n const rule = orderByColId?.get(col.id);\n if (rule !== undefined) return rule.priority;\n return readAnnotationJson(col.spec, Annotation.Table.OrderPriority);\n}\n\n/**\n * Evaluate display rules against a set of columns and return a map of `colId → winning rule`\n * (first-match-wins, preserving original rule order).\n *\n * Predicate-based rules (`ColumnMatcher`) are evaluated directly on the spec.\n * Selector-based rules (`ColumnSelector`) are matched via `PFrameSpecDriver.discoverColumns`\n * using the same engine as `ColumnCollection.findColumns` — no client-side matcher.\n */\nexport function evaluateRules<R extends { match: ColumnMatcher | ColumnSelector }>(\n rules: R[],\n columns: RuleColumn[],\n pframeSpec: PFrameSpecDriver,\n): Map<PObjectId, R> {\n const result = new Map<PObjectId, R>();\n if (rules.length === 0 || columns.length === 0) return result;\n\n const hasSelectorRules = rules.some((rule) => typeof rule.match !== \"function\");\n const selectorHitsByRule = new Map<R, Set<PObjectId>>();\n\n if (hasSelectorRules) {\n const dedupedColumns = dedupeById(columns);\n const pColumns = dedupedColumns.map((c) => ({ id: c.id, spec: c.spec, data: undefined }));\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSource(new ArrayColumnProvider(pColumns))\n .build();\n if (collection === undefined) return result;\n\n try {\n for (const rule of rules) {\n if (typeof rule.match === \"function\") continue;\n const hits = collection.findColumns({ include: rule.match });\n selectorHitsByRule.set(rule, new Set(hits.map((h) => h.id)));\n }\n } finally {\n collection.dispose();\n }\n }\n\n for (const col of columns) {\n for (const rule of rules) {\n const matches =\n typeof rule.match === \"function\"\n ? rule.match(col.spec)\n : (selectorHitsByRule.get(rule)?.has(col.id) ?? false);\n if (matches) {\n result.set(col.id, rule);\n break;\n }\n }\n }\n return result;\n}\n\nfunction dedupeById(columns: RuleColumn[]): RuleColumn[] {\n const seen = new Set<PObjectId>();\n const result: RuleColumn[] = [];\n for (const col of columns) {\n if (seen.has(col.id)) continue;\n seen.add(col.id);\n result.push(col);\n }\n return result;\n}\n\n/**\n * Writes derived labels into column and axis annotations.\n * Returns new column objects with modified specs — original columns are not mutated.\n *\n * For each column: writes derived label into Annotation.Label (if present in derivedLabels).\n * For each axis in column specs: writes derived axis label into AxisSpec annotations.\n */\nexport function withLabelAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(derivedLabels: undefined | Record<string, string>, columns: T[]): T[] {\n if (derivedLabels === undefined) return columns;\n return columns.map((col) => {\n const colLabel = derivedLabels[col.id];\n return {\n ...col,\n spec: {\n ...col.spec,\n ...(isNil(colLabel)\n ? {}\n : { annotations: { ...col.spec.annotations, [Annotation.Label]: colLabel } }),\n axesSpec: col.spec.axesSpec.map((axis) => {\n const label = derivedLabels[canonicalizeAxisId(axis)];\n return isNil(label)\n ? axis\n : { ...axis, annotations: { ...axis.annotations, [Annotation.Label]: label } };\n }),\n },\n } as T;\n });\n}\n\n/**\n * Writes effective display properties (OrderPriority, Visibility) from precomputed rule maps\n * into column annotations. Returns new column objects — originals are not mutated.\n */\nexport function withTableVisualAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(\n visibilityByColId: undefined | Map<PObjectId, ColumnVisibilityRule>,\n orderByColId: undefined | Map<PObjectId, ColumnOrderRule>,\n columns: T[],\n): T[] {\n if (visibilityByColId === undefined && orderByColId === undefined) return columns;\n return columns.map((col) => {\n const annotations = { ...col.spec.annotations };\n\n const visibility = getEffectiveVisibility(col, visibilityByColId);\n if (!isNil(visibility)) annotations[Annotation.Table.Visibility] = visibility;\n\n const orderPriority = getOrderPriority(col, orderByColId);\n if (!isNil(orderPriority)) annotations[Annotation.Table.OrderPriority] = String(orderPriority);\n\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: annotations,\n },\n } as T;\n });\n}\n\n/**\n * Writes derived info annotations into column annotations.\n * Columns without an info entry are passed through unchanged.\n */\nexport function withInfoAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(infoById: undefined | Record<string, string>, columns: T[]): T[] {\n if (isNil(infoById)) return columns;\n return columns.map((col) => {\n const info = infoById[col.id];\n if (isNil(info)) return col;\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: { ...col.spec.annotations, [Annotation.Table.Info]: info },\n },\n } as T;\n });\n}\n\nexport function withHidenAxesAnnotations<T extends { readonly spec: PColumnSpec }>(\n columns: T[],\n): T[] {\n return columns.map(\n (col) =>\n ({\n ...col,\n spec: {\n ...col.spec,\n axesSpec: col.spec.axesSpec.map((axis) => ({\n ...axis,\n annotations: { ...axis.annotations, [Annotation.Table.Visibility]: \"hidden\" },\n })),\n },\n }) as T,\n );\n}\n\n/** Column shape required by label derivation. */\nexport type LabelableColumn = {\n readonly id: PObjectId;\n readonly spec: PColumnSpec;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */\nexport function deriveAllLabels(options: {\n columns: LabelableColumn[];\n labelColumns: { readonly spec: PColumnSpec }[];\n deriveLabelsOptions?: DeriveLabelsOptions;\n}): Record<string, string> {\n const { columns, labelColumns, deriveLabelsOptions } = options;\n const axisLabels = deriveAxisLabels(columns, labelColumns);\n const entries = columns.map((c) => ({\n spec: c.spec,\n linkerPath: c.linkerPath?.map((step) => ({\n spec: step.linker.spec,\n qualifications: step.qualifications,\n })),\n qualifications: c.qualifications,\n }));\n const columnLabels = deriveDistinctLabels(entries, deriveLabelsOptions).reduce(\n (acc, label, index) => ((acc[columns[index].id] = label), acc),\n {} as Record<string, string>,\n );\n return { ...axisLabels, ...columnLabels };\n}\n\n/** Derive axis labels from matching label columns, falling back to axis spec annotations. */\nfunction deriveAxisLabels(\n columns: { readonly spec: PColumnSpec }[],\n labelColumns: { readonly spec: PColumnSpec }[],\n): Record<string, string> {\n const axisSpecMap = new Map(\n columns.flatMap((c) => c.spec.axesSpec).map((a) => [canonicalizeJson(getAxisId(a)), a]),\n );\n const result: Record<string, string> = {};\n for (const axisKey of axisSpecMap.keys()) {\n const labelCol = labelColumns.find(\n (lc) => canonicalizeJson(getAxisId(lc.spec.axesSpec[0])) === axisKey,\n );\n const source = labelCol?.spec ?? axisSpecMap.get(axisKey);\n result[axisKey] = readAnnotation(source ?? {}, Annotation.Label)?.trim() ?? \"Unlabeled\";\n }\n return result;\n}\n\n/** Column shape required by tooltip derivation. */\nexport type TooltipableColumn = {\n readonly id: DiscoveredPColumnId;\n readonly spec: PColumnSpec;\n readonly originalId: PObjectId;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive origin tooltips for columns whose qualifications or linker path carry info. */\nexport function deriveAllTooltips(options: {\n columns: TooltipableColumn[];\n}): Record<DiscoveredPColumnId, string> {\n const { columns } = options;\n\n const variantCountByOriginal = columns.reduce<Map<PObjectId, number>>((acc, c) => {\n return acc.set(c.originalId, (acc.get(c.originalId) ?? 0) + 1);\n }, new Map());\n\n const { entries } = columns.reduce(\n ({ entries, variantSeen }, c) => {\n const variantCount = variantCountByOriginal.get(c.originalId);\n const variantIndex =\n (variantSeen.set(c.originalId, (variantSeen.get(c.originalId) ?? 0) + 1),\n variantSeen.get(c.originalId));\n\n entries.push({\n spec: c.spec,\n linkerPath: c.linkerPath,\n qualifications: c.qualifications,\n variantIndex,\n variantCount,\n });\n\n return { entries, variantSeen };\n },\n { entries: [] as TooltipEntry[], variantSeen: new Map<PObjectId, number>() },\n );\n\n const tooltips = deriveDistinctTooltips(entries);\n\n return Object.fromEntries(\n tooltips.flatMap((t, i) => (isNil(t) ? [] : [[columns[i].id, t] as const])),\n );\n}\n"],"mappings":";;;;;;;;;AA4BA,SAAgB,eAAe,MAA6C;AAC1E,QAAO,eAAe,MAAM,WAAW,MAAM,WAAW,KAAK;;;AAI/D,SAAgB,iBAAiB,MAA6C;AAC5E,QAAO,eAAe,M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,iBAAiB,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,CACxF;CACD,MAAM,SAAiC,EAAE;AACzC,MAAK,MAAM,WAAW,YAAY,MAAM,CAKtC,QAAO,WAAW,eAJD,aAAa,MAC3B,OAAO,iBAAiB,UAAU,GAAG,KAAK,SAAS,GAAG,CAAC,KAAK,QAC9D,EACwB,QAAQ,YAAY,IAAI,QAAQ,IACd,EAAE,EAAE,WAAW,MAAM,EAAE,MAAM,IAAI;AAE9E,QAAO;;;AAaT,SAAgB,kBAAkB,SAEM;CACtC,MAAM,EAAE,YAAY;CAEpB,MAAM,yBAAyB,QAAQ,QAAgC,KAAK,MAAM;AAChF,SAAO,IAAI,IAAI,EAAE,aAAa,IAAI,IAAI,EAAE,WAAW,IAAI,KAAK,EAAE;oBAC7D,IAAI,KAAK,CAAC;CAEb,MAAM,EAAE,YAAY,QAAQ,QACzB,EAAE,SAAS,eAAe,MAAM;EAC/B,MAAM,eAAe,uBAAuB,IAAI,EAAE,WAAW;EAC7D,MAAM,gBACH,YAAY,IAAI,EAAE,aAAa,YAAY,IAAI,EAAE,WAAW,IAAI,KAAK,EAAE,EACxE,YAAY,IAAI,EAAE,WAAW;AAE/B,UAAQ,KAAK;GACX,MAAM,EAAE;GACR,YAAY,EAAE;GACd,gBAAgB,EAAE;GAClB;GACA;GACD,CAAC;AAEF,SAAO;GAAE;GAAS;GAAa;IAEjC;EAAE,SAAS,EAAE;EAAoB,6BAAa,IAAI,KAAwB;EAAE,CAC7E;CAED,MAAM,WAAW,uBAAuB,QAAQ;AAEhD,QAAO,OAAO,YACZ,SAAS,SAAS,GAAG,MAAO,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAU,CAAE,CAC5E"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/components/PlDataTable/createPlDataTable/utils.ts"],"sourcesContent":["import {\n type PColumn,\n type PColumnSpec,\n type PFrameSpecDriver,\n type PObjectId,\n Annotation,\n canonicalizeAxisId,\n DiscoveredPColumnId,\n readAnnotation,\n readAnnotationJson,\n} from \"@milaboratories/pl-model-common\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../../labels/derive_distinct_labels\";\nimport {\n deriveDistinctTooltips,\n type TooltipEntry,\n} from \"../../../labels/derive_distinct_tooltips\";\nimport type { MatchQualifications, MatchVariant } from \"../../../columns\";\nimport type { ColumnMatcher, ColumnOrderRule, ColumnVisibilityRule } from \"./createPlDataTableV3\";\nimport type { ColumnSelector } from \"../../../columns\";\nimport { ArrayColumnProvider, ColumnCollectionBuilder } from \"../../../columns\";\nimport { isNil } from \"es-toolkit\";\n\n/** Check if column should be omitted from the table */\nexport function isColumnHidden(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"hidden\";\n}\n\n/** Check if column is hidden by default */\nexport function isColumnOptional(spec: { annotations?: Annotation }): boolean {\n return readAnnotation(spec, Annotation.Table.Visibility) === \"optional\";\n}\n\n/** Column shape consumed by rule evaluation. */\nexport type RuleColumn = Pick<PColumn<PObjectId>, \"id\" | \"spec\">;\n\n/** Get effective visibility for a column. Rule map lookup first, then annotation fallback. */\nexport function getEffectiveVisibility(\n col: RuleColumn,\n visibilityByColId?: Map<PObjectId, ColumnVisibilityRule>,\n): undefined | \"default\" | \"optional\" | \"hidden\" {\n const rule = visibilityByColId?.get(col.id);\n if (rule !== undefined) return rule.visibility;\n if (isColumnHidden(col.spec)) return \"hidden\";\n if (isColumnOptional(col.spec)) return \"optional\";\n return undefined;\n}\n\n/** Get ordering priority for a column. Rule map lookup first, then annotation fallback. */\nexport function getOrderPriority(\n col: RuleColumn,\n orderByColId?: Map<PObjectId, ColumnOrderRule>,\n): undefined | number {\n const rule = orderByColId?.get(col.id);\n if (rule !== undefined) return rule.priority;\n return readAnnotationJson(col.spec, Annotation.Table.OrderPriority);\n}\n\n/**\n * Evaluate display rules against a set of columns and return a map of `colId → winning rule`\n * (first-match-wins, preserving original rule order).\n *\n * Predicate-based rules (`ColumnMatcher`) are evaluated directly on the spec.\n * Selector-based rules (`ColumnSelector`) are matched via `PFrameSpecDriver.discoverColumns`\n * using the same engine as `ColumnCollection.findColumns` — no client-side matcher.\n */\nexport function evaluateRules<R extends { match: ColumnMatcher | ColumnSelector }>(\n rules: R[],\n columns: RuleColumn[],\n pframeSpec: PFrameSpecDriver,\n): Map<PObjectId, R> {\n const result = new Map<PObjectId, R>();\n if (rules.length === 0 || columns.length === 0) return result;\n\n const hasSelectorRules = rules.some((rule) => typeof rule.match !== \"function\");\n const selectorHitsByRule = new Map<R, Set<PObjectId>>();\n\n if (hasSelectorRules) {\n const dedupedColumns = dedupeById(columns);\n const pColumns = dedupedColumns.map((c) => ({ id: c.id, spec: c.spec, data: undefined }));\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSource(new ArrayColumnProvider(pColumns))\n .build();\n if (collection === undefined) return result;\n\n try {\n for (const rule of rules) {\n if (typeof rule.match === \"function\") continue;\n const hits = collection.findColumns({ include: rule.match });\n selectorHitsByRule.set(rule, new Set(hits.map((h) => h.id)));\n }\n } finally {\n collection.dispose();\n }\n }\n\n for (const col of columns) {\n for (const rule of rules) {\n const matches =\n typeof rule.match === \"function\"\n ? rule.match(col.spec)\n : (selectorHitsByRule.get(rule)?.has(col.id) ?? false);\n if (matches) {\n result.set(col.id, rule);\n break;\n }\n }\n }\n return result;\n}\n\nfunction dedupeById(columns: RuleColumn[]): RuleColumn[] {\n const seen = new Set<PObjectId>();\n const result: RuleColumn[] = [];\n for (const col of columns) {\n if (seen.has(col.id)) continue;\n seen.add(col.id);\n result.push(col);\n }\n return result;\n}\n\n/**\n * Writes derived labels into column and axis annotations.\n * Returns new column objects with modified specs — original columns are not mutated.\n *\n * For each column: writes derived label into Annotation.Label (if present in derivedLabels).\n * For each axis in column specs: writes derived axis label into AxisSpec annotations.\n */\nexport function withLabelAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(derivedLabels: undefined | Record<string, string>, columns: T[]): T[] {\n if (derivedLabels === undefined) return columns;\n return columns.map((col) => {\n const colLabel = derivedLabels[col.id];\n return {\n ...col,\n spec: {\n ...col.spec,\n ...(isNil(colLabel)\n ? {}\n : { annotations: { ...col.spec.annotations, [Annotation.Label]: colLabel } }),\n axesSpec: col.spec.axesSpec.map((axis) => {\n const label = derivedLabels[canonicalizeAxisId(axis)];\n return isNil(label)\n ? axis\n : { ...axis, annotations: { ...axis.annotations, [Annotation.Label]: label } };\n }),\n },\n } as T;\n });\n}\n\n/**\n * Writes effective display properties (OrderPriority, Visibility) from precomputed rule maps\n * into column annotations. Returns new column objects — originals are not mutated.\n */\nexport function withTableVisualAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(\n visibilityByColId: undefined | Map<PObjectId, ColumnVisibilityRule>,\n orderByColId: undefined | Map<PObjectId, ColumnOrderRule>,\n columns: T[],\n): T[] {\n if (visibilityByColId === undefined && orderByColId === undefined) return columns;\n return columns.map((col) => {\n const annotations = { ...col.spec.annotations };\n\n const visibility = getEffectiveVisibility(col, visibilityByColId);\n if (!isNil(visibility)) annotations[Annotation.Table.Visibility] = visibility;\n\n const orderPriority = getOrderPriority(col, orderByColId);\n if (!isNil(orderPriority)) annotations[Annotation.Table.OrderPriority] = String(orderPriority);\n\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: annotations,\n },\n } as T;\n });\n}\n\n/**\n * Writes derived info annotations into column annotations.\n * Columns without an info entry are passed through unchanged.\n */\nexport function withInfoAnnotations<\n T extends { readonly id: PObjectId; readonly spec: PColumnSpec },\n>(infoById: undefined | Record<string, string>, columns: T[]): T[] {\n if (isNil(infoById)) return columns;\n return columns.map((col) => {\n const info = infoById[col.id];\n if (isNil(info)) return col;\n return {\n ...col,\n spec: {\n ...col.spec,\n annotations: { ...col.spec.annotations, [Annotation.Table.Info]: info },\n },\n } as T;\n });\n}\n\nexport function withHidenAxesAnnotations<T extends { readonly spec: PColumnSpec }>(\n columns: T[],\n): T[] {\n return columns.map(\n (col) =>\n ({\n ...col,\n spec: {\n ...col.spec,\n axesSpec: col.spec.axesSpec.map((axis) => ({\n ...axis,\n annotations: { ...axis.annotations, [Annotation.Table.Visibility]: \"hidden\" },\n })),\n },\n }) as T,\n );\n}\n\n/** Column shape required by label derivation. */\nexport type LabelableColumn = {\n readonly id: PObjectId;\n readonly spec: PColumnSpec;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive labels for all table elements: columns via deriveDistinctLabels, axes from label columns. */\nexport function deriveAllLabels(options: {\n columns: LabelableColumn[];\n deriveLabelsOptions?: DeriveLabelsOptions;\n}): Record<string, string> {\n const { columns, deriveLabelsOptions } = options;\n const entries = columns.map((c) => ({\n spec: c.spec,\n linkerPath: c.linkerPath?.map((step) => ({\n spec: step.linker.spec,\n qualifications: step.qualifications,\n })),\n qualifications: c.qualifications,\n }));\n const columnLabels = deriveDistinctLabels(entries, deriveLabelsOptions).reduce(\n (acc, label, index) => ((acc[columns[index].id] = label), acc),\n {} as Record<string, string>,\n );\n return columnLabels;\n}\n\n/** Column shape required by tooltip derivation. */\nexport type TooltipableColumn = {\n readonly id: DiscoveredPColumnId;\n readonly spec: PColumnSpec;\n readonly originalId: PObjectId;\n readonly linkerPath?: MatchVariant[\"path\"];\n readonly qualifications?: MatchQualifications;\n};\n\n/** Derive origin tooltips for columns whose qualifications or linker path carry info. */\nexport function deriveAllTooltips(options: {\n columns: TooltipableColumn[];\n}): Record<DiscoveredPColumnId, string> {\n const { columns } = options;\n\n const variantCountByOriginal = columns.reduce<Map<PObjectId, number>>((acc, c) => {\n return acc.set(c.originalId, (acc.get(c.originalId) ?? 0) + 1);\n }, new Map());\n\n const { entries } = columns.reduce(\n ({ entries, variantSeen }, c) => {\n const variantCount = variantCountByOriginal.get(c.originalId);\n const variantIndex =\n (variantSeen.set(c.originalId, (variantSeen.get(c.originalId) ?? 0) + 1),\n variantSeen.get(c.originalId));\n\n entries.push({\n spec: c.spec,\n linkerPath: c.linkerPath,\n qualifications: c.qualifications,\n variantIndex,\n variantCount,\n });\n\n return { entries, variantSeen };\n },\n { entries: [] as TooltipEntry[], variantSeen: new Map<PObjectId, number>() },\n );\n\n const tooltips = deriveDistinctTooltips(entries);\n\n return Object.fromEntries(\n tooltips.flatMap((t, i) => (isNil(t) ? [] : [[columns[i].id, t] as const])),\n );\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,eAAe,MAA6C;AAC1E,QAAO,eAAe,MAAM,WAAW,MAAM,WAAW,KAAK;;;AAI/D,SAAgB,iBAAiB,MAA6C;AAC5E,QAAO,eAAe,MAAM,WAAW,MAAM,WAAW,KAAK;;;AAO/D,SAAgB,uBACd,KACA,mBAC+C;CAC/C,MAAM,OAAO,mBAAmB,IAAI,IAAI,GAAG;AAC3C,KAAI,SAAS,KAAA,EAAW,QAAO,KAAK;AACpC,KAAI,eAAe,IAAI,KAAK,CAAE,QAAO;AACrC,KAAI,iBAAiB,IAAI,KAAK,CAAE,QAAO;;;AAKzC,SAAgB,iBACd,KACA,cACoB;CACpB,MAAM,OAAO,cAAc,IAAI,IAAI,GAAG;AACtC,KAAI,SAAS,KAAA,EAAW,QAAO,KAAK;AACpC,QAAO,mBAAmB,IAAI,MAAM,WAAW,MAAM,cAAc;;;;;;;;;;AAWrE,SAAgB,cACd,OACA,SACA,YACmB;CACnB,MAAM,yBAAS,IAAI,KAAmB;AACtC,KAAI,MAAM,WAAW,KAAK,QAAQ,WAAW,EAAG,QAAO;CAEvD,MAAM,mBAAmB,MAAM,MAAM,SAAS,OAAO,KAAK,UAAU,WAAW;CAC/E,MAAM,qCAAqB,IAAI,KAAwB;AAEvD,KAAI,kBAAkB;EAEpB,MAAM,WADiB,WAAW,QAAQ,CACV,KAAK,OAAO;GAAE,IAAI,EAAE;GAAI,MAAM,EAAE;GAAM,MAAM,KAAA;GAAW,EAAE;EACzF,MAAM,aAAa,IAA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EACR,YAAY,EAAE,YAAY,KAAK,UAAU;GACvC,MAAM,KAAK,OAAO;GAClB,gBAAgB,KAAK;GACtB,EAAE;EACH,gBAAgB,EAAE;EACnB,EAAE,EACgD,oBAAoB,CAAC,QACrE,KAAK,OAAO,WAAY,IAAI,QAAQ,OAAO,MAAM,OAAQ,MAC1D,EAAE,CACH;;;AAcH,SAAgB,kBAAkB,SAEM;CACtC,MAAM,EAAE,YAAY;CAEpB,MAAM,yBAAyB,QAAQ,QAAgC,KAAK,MAAM;AAChF,SAAO,IAAI,IAAI,EAAE,aAAa,IAAI,IAAI,EAAE,WAAW,IAAI,KAAK,EAAE;oBAC7D,IAAI,KAAK,CAAC;CAEb,MAAM,EAAE,YAAY,QAAQ,QACzB,EAAE,SAAS,eAAe,MAAM;EAC/B,MAAM,eAAe,uBAAuB,IAAI,EAAE,WAAW;EAC7D,MAAM,gBACH,YAAY,IAAI,EAAE,aAAa,YAAY,IAAI,EAAE,WAAW,IAAI,KAAK,EAAE,EACxE,YAAY,IAAI,EAAE,WAAW;AAE/B,UAAQ,KAAK;GACX,MAAM,EAAE;GACR,YAAY,EAAE;GACd,gBAAgB,EAAE;GAClB;GACA;GACD,CAAC;AAEF,SAAO;GAAE;GAAS;GAAa;IAEjC;EAAE,SAAS,EAAE;EAAoB,6BAAa,IAAI,KAAwB;EAAE,CAC7E;CAED,MAAM,WAAW,uBAAuB,QAAQ;AAEhD,QAAO,OAAO,YACZ,SAAS,SAAS,GAAG,MAAO,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAU,CAAE,CAC5E"}
|
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_column_collection_builder = require("../../columns/column_collection_builder.cjs");
|
|
3
|
-
const require_ctx_column_sources = require("../../columns/ctx_column_sources.cjs");
|
|
4
2
|
require("../../columns/index.cjs");
|
|
5
3
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
6
4
|
//#region src/components/PlDataTable/labels.ts
|
|
7
|
-
/**
|
|
8
|
-
* Get all label columns visible in the current render context
|
|
9
|
-
* (result pool + block outputs + prerun).
|
|
10
|
-
*/
|
|
11
|
-
function getAllLabelColumns(ctx) {
|
|
12
|
-
const collection = new require_column_collection_builder.ColumnCollectionBuilder(ctx.getService("pframeSpec")).addSources(require_ctx_column_sources.collectCtxColumnSnapshotProviders(ctx)).build({ allowPartialColumnList: true });
|
|
13
|
-
try {
|
|
14
|
-
return collection.findColumns({ include: {
|
|
15
|
-
name: _milaboratories_pl_model_common.PColumnName.Label,
|
|
16
|
-
axes: []
|
|
17
|
-
} }).reduce((acc, hit) => {
|
|
18
|
-
const data = hit.data?.get();
|
|
19
|
-
return data === void 0 ? acc : [...acc, {
|
|
20
|
-
id: hit.id,
|
|
21
|
-
spec: hit.spec,
|
|
22
|
-
data
|
|
23
|
-
}];
|
|
24
|
-
}, []);
|
|
25
|
-
} finally {
|
|
26
|
-
collection.dispose();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
5
|
/** Get label columns matching the provided columns from the result pool */
|
|
30
6
|
function getMatchingLabelColumns(columns, allLabelColumns) {
|
|
31
7
|
const inputLabelColumns = [];
|
|
@@ -79,7 +55,6 @@ function getMatchingLabelColumns(columns, allLabelColumns) {
|
|
|
79
55
|
return labelColumns;
|
|
80
56
|
}
|
|
81
57
|
//#endregion
|
|
82
|
-
exports.getAllLabelColumns = getAllLabelColumns;
|
|
83
58
|
exports.getMatchingLabelColumns = getMatchingLabelColumns;
|
|
84
59
|
|
|
85
60
|
//# sourceMappingURL=labels.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labels.cjs","names":[
|
|
1
|
+
{"version":3,"file":"labels.cjs","names":[],"sources":["../../../src/components/PlDataTable/labels.ts"],"sourcesContent":["import type { AxisId, PColumn, PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport {\n getAxisId,\n isLabelColumn,\n matchAxisId,\n PColumnName,\n} from \"@milaboratories/pl-model-common\";\nimport type { PColumnDataUniversal, RenderCtxBase } from \"../../render\";\nimport { ColumnCollectionBuilder, collectCtxColumnSnapshotProviders } from \"../../columns\";\n\n/**\n * Get all label columns visible in the current render context\n * (result pool + block outputs + prerun).\n */\nexport function getAllLabelColumns<A, U>(\n ctx: RenderCtxBase<A, U>,\n): PColumn<PColumnDataUniversal>[] {\n const pframeSpec = ctx.getService(\"pframeSpec\");\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSources(collectCtxColumnSnapshotProviders(ctx))\n .build({ allowPartialColumnList: true });\n try {\n return collection\n .findColumns({ include: { name: PColumnName.Label, axes: [] } })\n .reduce<PColumn<PColumnDataUniversal>[]>((acc, hit) => {\n const data = hit.data?.get();\n return data === undefined ? acc : [...acc, { id: hit.id, spec: hit.spec, data }];\n }, []);\n } finally {\n collection.dispose();\n }\n}\n\n/** Get label columns matching the provided columns from the result pool */\nexport function getMatchingLabelColumns(\n columns: { spec: PColumnSpec }[],\n allLabelColumns: PColumn<PColumnDataUniversal>[],\n): PColumn<PColumnDataUniversal>[] {\n // split input columns into label and value columns\n const inputLabelColumns: typeof columns = [];\n const inputValueColumns: typeof columns = [];\n for (const column of columns) {\n if (isLabelColumn(column.spec)) {\n inputLabelColumns.push(column);\n } else {\n inputValueColumns.push(column);\n }\n }\n\n // collect distinct axes of value columns\n const unlabeledAxes: AxisId[] = [];\n for (const column of inputValueColumns) {\n for (const axis of column.spec.axesSpec) {\n const axisId = getAxisId(axis);\n if (!unlabeledAxes.some((id) => matchAxisId(id, axisId))) {\n unlabeledAxes.push(axisId);\n }\n }\n }\n\n // remove axes matched by input label columns\n for (const labelColumn of inputLabelColumns) {\n const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n\n // warning: changing this id will break backward compatibility\n const colId = (\n id: PObjectId,\n domain?: Record<string, string>,\n contextDomain?: Record<string, string>,\n ): PObjectId => {\n let wid = id.toString();\n if (domain) {\n for (const k in domain) {\n wid += k;\n wid += domain[k];\n }\n }\n if (contextDomain) {\n for (const k in contextDomain) {\n wid += k;\n wid += contextDomain[k];\n }\n }\n return wid as PObjectId;\n };\n\n // search label columns for unmatched axes\n const labelColumns: typeof allLabelColumns = [];\n for (const labelColumn of allLabelColumns) {\n const labelAxis = labelColumn.spec.axesSpec[0];\n const labelAxisId = getAxisId(labelAxis);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n const axisId = unlabeledAxes[labelMatch];\n const dataDomainLen =\n Object.keys(axisId.domain ?? {}).length + Object.keys(axisId.contextDomain ?? {}).length;\n const labelDomainLen =\n Object.keys(labelAxis.domain ?? {}).length +\n Object.keys(labelAxis.contextDomain ?? {}).length;\n if (dataDomainLen > labelDomainLen) {\n labelColumns.push({\n id: colId(labelColumn.id, axisId.domain, axisId.contextDomain),\n spec: {\n ...labelColumn.spec,\n axesSpec: [{ ...axisId, annotations: labelAxis.annotations }],\n },\n data: labelColumn.data,\n });\n } else {\n labelColumns.push(labelColumn);\n }\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n return labelColumns;\n}\n"],"mappings":";;;;;AAkCA,SAAgB,wBACd,SACA,iBACiC;CAEjC,MAAM,oBAAoC,EAAE;CAC5C,MAAM,oBAAoC,EAAE;AAC5C,MAAK,MAAM,UAAU,QACnB,MAAA,GAAA,gCAAA,eAAkB,OAAO,KAAK,CAC5B,mBAAkB,KAAK,OAAO;KAE9B,mBAAkB,KAAK,OAAO;CAKlC,MAAM,gBAA0B,EAAE;AAClC,MAAK,MAAM,UAAU,kBACnB,MAAK,MAAM,QAAQ,OAAO,KAAK,UAAU;EACvC,MAAM,UAAA,GAAA,gCAAA,WAAmB,KAAK;AAC9B,MA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Y;AAEhC,iBAAc,OAAO,YAAY,EAAE;;;AAGvC,QAAO"}
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import { ColumnCollectionBuilder } from "../../columns/column_collection_builder.js";
|
|
2
|
-
import { collectCtxColumnSnapshotProviders } from "../../columns/ctx_column_sources.js";
|
|
3
1
|
import "../../columns/index.js";
|
|
4
|
-
import {
|
|
2
|
+
import { getAxisId, isLabelColumn, matchAxisId } from "@milaboratories/pl-model-common";
|
|
5
3
|
//#region src/components/PlDataTable/labels.ts
|
|
6
|
-
/**
|
|
7
|
-
* Get all label columns visible in the current render context
|
|
8
|
-
* (result pool + block outputs + prerun).
|
|
9
|
-
*/
|
|
10
|
-
function getAllLabelColumns(ctx) {
|
|
11
|
-
const collection = new ColumnCollectionBuilder(ctx.getService("pframeSpec")).addSources(collectCtxColumnSnapshotProviders(ctx)).build({ allowPartialColumnList: true });
|
|
12
|
-
try {
|
|
13
|
-
return collection.findColumns({ include: {
|
|
14
|
-
name: PColumnName.Label,
|
|
15
|
-
axes: []
|
|
16
|
-
} }).reduce((acc, hit) => {
|
|
17
|
-
const data = hit.data?.get();
|
|
18
|
-
return data === void 0 ? acc : [...acc, {
|
|
19
|
-
id: hit.id,
|
|
20
|
-
spec: hit.spec,
|
|
21
|
-
data
|
|
22
|
-
}];
|
|
23
|
-
}, []);
|
|
24
|
-
} finally {
|
|
25
|
-
collection.dispose();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
4
|
/** Get label columns matching the provided columns from the result pool */
|
|
29
5
|
function getMatchingLabelColumns(columns, allLabelColumns) {
|
|
30
6
|
const inputLabelColumns = [];
|
|
@@ -78,6 +54,6 @@ function getMatchingLabelColumns(columns, allLabelColumns) {
|
|
|
78
54
|
return labelColumns;
|
|
79
55
|
}
|
|
80
56
|
//#endregion
|
|
81
|
-
export {
|
|
57
|
+
export { getMatchingLabelColumns };
|
|
82
58
|
|
|
83
59
|
//# sourceMappingURL=labels.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labels.js","names":[],"sources":["../../../src/components/PlDataTable/labels.ts"],"sourcesContent":["import type { AxisId, PColumn, PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport {\n getAxisId,\n isLabelColumn,\n matchAxisId,\n PColumnName,\n} from \"@milaboratories/pl-model-common\";\nimport type { PColumnDataUniversal, RenderCtxBase } from \"../../render\";\nimport { ColumnCollectionBuilder, collectCtxColumnSnapshotProviders } from \"../../columns\";\n\n/**\n * Get all label columns visible in the current render context\n * (result pool + block outputs + prerun).\n */\nexport function getAllLabelColumns<A, U>(\n ctx: RenderCtxBase<A, U>,\n): PColumn<PColumnDataUniversal>[] {\n const pframeSpec = ctx.getService(\"pframeSpec\");\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSources(collectCtxColumnSnapshotProviders(ctx))\n .build({ allowPartialColumnList: true });\n try {\n return collection\n .findColumns({ include: { name: PColumnName.Label, axes: [] } })\n .reduce<PColumn<PColumnDataUniversal>[]>((acc, hit) => {\n const data = hit.data?.get();\n return data === undefined ? acc : [...acc, { id: hit.id, spec: hit.spec, data }];\n }, []);\n } finally {\n collection.dispose();\n }\n}\n\n/** Get label columns matching the provided columns from the result pool */\nexport function getMatchingLabelColumns(\n columns: { spec: PColumnSpec }[],\n allLabelColumns: PColumn<PColumnDataUniversal>[],\n): PColumn<PColumnDataUniversal>[] {\n // split input columns into label and value columns\n const inputLabelColumns: typeof columns = [];\n const inputValueColumns: typeof columns = [];\n for (const column of columns) {\n if (isLabelColumn(column.spec)) {\n inputLabelColumns.push(column);\n } else {\n inputValueColumns.push(column);\n }\n }\n\n // collect distinct axes of value columns\n const unlabeledAxes: AxisId[] = [];\n for (const column of inputValueColumns) {\n for (const axis of column.spec.axesSpec) {\n const axisId = getAxisId(axis);\n if (!unlabeledAxes.some((id) => matchAxisId(id, axisId))) {\n unlabeledAxes.push(axisId);\n }\n }\n }\n\n // remove axes matched by input label columns\n for (const labelColumn of inputLabelColumns) {\n const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n\n // warning: changing this id will break backward compatibility\n const colId = (\n id: PObjectId,\n domain?: Record<string, string>,\n contextDomain?: Record<string, string>,\n ): PObjectId => {\n let wid = id.toString();\n if (domain) {\n for (const k in domain) {\n wid += k;\n wid += domain[k];\n }\n }\n if (contextDomain) {\n for (const k in contextDomain) {\n wid += k;\n wid += contextDomain[k];\n }\n }\n return wid as PObjectId;\n };\n\n // search label columns for unmatched axes\n const labelColumns: typeof allLabelColumns = [];\n for (const labelColumn of allLabelColumns) {\n const labelAxis = labelColumn.spec.axesSpec[0];\n const labelAxisId = getAxisId(labelAxis);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n const axisId = unlabeledAxes[labelMatch];\n const dataDomainLen =\n Object.keys(axisId.domain ?? {}).length + Object.keys(axisId.contextDomain ?? {}).length;\n const labelDomainLen =\n Object.keys(labelAxis.domain ?? {}).length +\n Object.keys(labelAxis.contextDomain ?? {}).length;\n if (dataDomainLen > labelDomainLen) {\n labelColumns.push({\n id: colId(labelColumn.id, axisId.domain, axisId.contextDomain),\n spec: {\n ...labelColumn.spec,\n axesSpec: [{ ...axisId, annotations: labelAxis.annotations }],\n },\n data: labelColumn.data,\n });\n } else {\n labelColumns.push(labelColumn);\n }\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n return labelColumns;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"labels.js","names":[],"sources":["../../../src/components/PlDataTable/labels.ts"],"sourcesContent":["import type { AxisId, PColumn, PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport {\n getAxisId,\n isLabelColumn,\n matchAxisId,\n PColumnName,\n} from \"@milaboratories/pl-model-common\";\nimport type { PColumnDataUniversal, RenderCtxBase } from \"../../render\";\nimport { ColumnCollectionBuilder, collectCtxColumnSnapshotProviders } from \"../../columns\";\n\n/**\n * Get all label columns visible in the current render context\n * (result pool + block outputs + prerun).\n */\nexport function getAllLabelColumns<A, U>(\n ctx: RenderCtxBase<A, U>,\n): PColumn<PColumnDataUniversal>[] {\n const pframeSpec = ctx.getService(\"pframeSpec\");\n const collection = new ColumnCollectionBuilder(pframeSpec)\n .addSources(collectCtxColumnSnapshotProviders(ctx))\n .build({ allowPartialColumnList: true });\n try {\n return collection\n .findColumns({ include: { name: PColumnName.Label, axes: [] } })\n .reduce<PColumn<PColumnDataUniversal>[]>((acc, hit) => {\n const data = hit.data?.get();\n return data === undefined ? acc : [...acc, { id: hit.id, spec: hit.spec, data }];\n }, []);\n } finally {\n collection.dispose();\n }\n}\n\n/** Get label columns matching the provided columns from the result pool */\nexport function getMatchingLabelColumns(\n columns: { spec: PColumnSpec }[],\n allLabelColumns: PColumn<PColumnDataUniversal>[],\n): PColumn<PColumnDataUniversal>[] {\n // split input columns into label and value columns\n const inputLabelColumns: typeof columns = [];\n const inputValueColumns: typeof columns = [];\n for (const column of columns) {\n if (isLabelColumn(column.spec)) {\n inputLabelColumns.push(column);\n } else {\n inputValueColumns.push(column);\n }\n }\n\n // collect distinct axes of value columns\n const unlabeledAxes: AxisId[] = [];\n for (const column of inputValueColumns) {\n for (const axis of column.spec.axesSpec) {\n const axisId = getAxisId(axis);\n if (!unlabeledAxes.some((id) => matchAxisId(id, axisId))) {\n unlabeledAxes.push(axisId);\n }\n }\n }\n\n // remove axes matched by input label columns\n for (const labelColumn of inputLabelColumns) {\n const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n\n // warning: changing this id will break backward compatibility\n const colId = (\n id: PObjectId,\n domain?: Record<string, string>,\n contextDomain?: Record<string, string>,\n ): PObjectId => {\n let wid = id.toString();\n if (domain) {\n for (const k in domain) {\n wid += k;\n wid += domain[k];\n }\n }\n if (contextDomain) {\n for (const k in contextDomain) {\n wid += k;\n wid += contextDomain[k];\n }\n }\n return wid as PObjectId;\n };\n\n // search label columns for unmatched axes\n const labelColumns: typeof allLabelColumns = [];\n for (const labelColumn of allLabelColumns) {\n const labelAxis = labelColumn.spec.axesSpec[0];\n const labelAxisId = getAxisId(labelAxis);\n const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));\n if (labelMatch !== -1) {\n const axisId = unlabeledAxes[labelMatch];\n const dataDomainLen =\n Object.keys(axisId.domain ?? {}).length + Object.keys(axisId.contextDomain ?? {}).length;\n const labelDomainLen =\n Object.keys(labelAxis.domain ?? {}).length +\n Object.keys(labelAxis.contextDomain ?? {}).length;\n if (dataDomainLen > labelDomainLen) {\n labelColumns.push({\n id: colId(labelColumn.id, axisId.domain, axisId.contextDomain),\n spec: {\n ...labelColumn.spec,\n axesSpec: [{ ...axisId, annotations: labelAxis.annotations }],\n },\n data: labelColumn.data,\n });\n } else {\n labelColumns.push(labelColumn);\n }\n unlabeledAxes.splice(labelMatch, 1);\n }\n }\n return labelColumns;\n}\n"],"mappings":";;;;AAkCA,SAAgB,wBACd,SACA,iBACiC;CAEjC,MAAM,oBAAoC,EAAE;CAC5C,MAAM,oBAAoC,EAAE;AAC5C,MAAK,MAAM,UAAU,QACnB,KAAI,cAAc,OAAO,KAAK,CAC5B,mBAAkB,KAAK,OAAO;KAE9B,mBAAkB,KAAK,OAAO;CAKlC,MAAM,gBAA0B,EAAE;AAClC,MAAK,MAAM,UAAU,kBACnB,MAAK,MAAM,QAAQ,OAAO,KAAK,UAAU;EACvC,MAAM,SAAS,UAAU,KAAK;AAC9B,MAAI,CAAC,cAAc,MAAM,OAAO,YAAY,IAAI,OAAO,CAAC,CACtD,eAAc,KAAK,OAAO;;AAMhC,MAAK,MAAM,eAAe,mBAAmB;EAC3C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
"version": "1.
|
|
3
|
+
"version": "1.69.0",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"files": [
|
|
6
6
|
"./dist/**/*",
|
|
@@ -30,22 +30,22 @@
|
|
|
30
30
|
"fast-json-patch": "^3.1.1",
|
|
31
31
|
"utility-types": "^3.11.0",
|
|
32
32
|
"zod": "~3.25.76",
|
|
33
|
-
"@milaboratories/helpers": "1.14.1",
|
|
34
|
-
"@milaboratories/pl-model-middle-layer": "1.18.7",
|
|
35
33
|
"@milaboratories/pl-error-like": "1.12.10",
|
|
36
34
|
"@milaboratories/ptabler-expression-js": "1.2.17",
|
|
37
|
-
"@milaboratories/
|
|
35
|
+
"@milaboratories/helpers": "1.14.1",
|
|
36
|
+
"@milaboratories/pl-model-common": "1.36.2",
|
|
37
|
+
"@milaboratories/pl-model-middle-layer": "1.18.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@vitest/coverage-istanbul": "^4.1.3",
|
|
41
41
|
"fast-json-patch": "^3.1.1",
|
|
42
42
|
"typescript": "~5.9.3",
|
|
43
43
|
"vitest": "^4.1.3",
|
|
44
|
-
"@milaboratories/build-configs": "2.0.0",
|
|
45
|
-
"@milaboratories/pf-driver": "1.4.2",
|
|
46
44
|
"@milaboratories/pf-spec-driver": "1.3.6",
|
|
45
|
+
"@milaboratories/pf-driver": "1.4.2",
|
|
46
|
+
"@milaboratories/ts-builder": "1.3.2",
|
|
47
47
|
"@milaboratories/ts-configs": "1.2.3",
|
|
48
|
-
"@milaboratories/
|
|
48
|
+
"@milaboratories/build-configs": "2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "ts-builder build --target node",
|