domain/converters/structure.converter.ts
domain/converters/structure.converter.ts is a file in Bane's Lab Site. 86 lines of code and 8 definitions.
import {
CELL_INTRO,
CELL_JOIN,
CELL_TITLE,
EDGE_INTRO,
EDGE_LABEL,
EDGE_TITLE,
FOUNDATION_LAYERS_TITLE,
FOUNDATION_SEQUENCE_TITLE,
INVARIANT_GROUPS_TITLE,
MAP_INTRO,
MAP_TITLE,
MEMBERS_LABEL,
PATTERN_OPERATIONS_TITLE,
TARGET_LABEL,
} from "#configuration/strings/reason.strings";
import { EDGE_SECTION_ID, MAP_SECTION_ID, UNCOVERED_SECTION_ID } from "#core/ids/ontology.ids";
import type { Section, Subsection } from "#types/document.types";
import { glossary, labeled, linkList, linkOf, linked, row } from "#domain/converters/ontology.converter";
import { FLOW_ARROW } from "#configuration/strings/ontology.strings";
import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons";
import type { ReasonView } from "#types/reason.types";
const overview = function overview(
id: string,
title: string,
intro: string,
subsections: readonly Subsection[],
): Section {
return { icon: REASON_SECTION_ICON, id, intro, subsections, title };
};
const cellSection = function cellSection(reason: ReasonView): Section {
return overview(UNCOVERED_SECTION_ID, CELL_TITLE, CELL_INTRO, [
{
blocks: [
glossary(
reason.uncoveredCells.map((cell) =>
row(
cell.dimension.label + CELL_JOIN + cell.lens.label,
linkOf(cell.dimension) + CELL_JOIN + linkOf(cell.lens),
),
),
),
],
title: CELL_TITLE,
},
]);
};
const mapSection = function mapSection(reason: ReasonView): Section {
const { maps } = reason;
const sequence = row(FOUNDATION_SEQUENCE_TITLE, maps.foundationSequence.map(linkOf).join(FLOW_ARROW));
const operations = row(MEMBERS_LABEL, linkList(maps.patternOperations));
return overview(MAP_SECTION_ID, MAP_TITLE, MAP_INTRO, [
{ blocks: [glossary([sequence])], title: FOUNDATION_SEQUENCE_TITLE },
{
blocks: [glossary(maps.foundationLayers.map((layer) => row(layer.layer, linkList(layer.mathTypes))))],
title: FOUNDATION_LAYERS_TITLE,
},
{
blocks: [glossary(maps.invariantGroups.map((group) => row(group.group, linkList(group.members))))],
title: INVARIANT_GROUPS_TITLE,
},
{ blocks: [glossary([operations])], title: PATTERN_OPERATIONS_TITLE },
]);
};
const edgeSection = function edgeSection(reason: ReasonView): Section {
return overview(EDGE_SECTION_ID, EDGE_TITLE, EDGE_INTRO, [
{
blocks: [
glossary(
reason.edges.map((edge) =>
row(
edge.from.label,
[linkOf(edge.from), linked(TARGET_LABEL, edge.to), labeled(EDGE_LABEL, edge.label)]
.filter((part): part is string => part !== null)
.join(FLOW_ARROW),
),
),
),
],
title: EDGE_TITLE,
},
]);
};
export const structureSections = function structureSections(reason: ReasonView): readonly Section[] {
return [cellSection(reason), mapSection(reason), edgeSection(reason)];
};