mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(shared): add Section concept and toolSection() partition
This commit is contained in:
@@ -7,4 +7,5 @@ export * from "./features.js";
|
|||||||
export * from "./i18n/index.js";
|
export * from "./i18n/index.js";
|
||||||
export * from "./modality.js";
|
export * from "./modality.js";
|
||||||
export * from "./permissions.js";
|
export * from "./permissions.js";
|
||||||
|
export * from "./section.js";
|
||||||
export * from "./types.js";
|
export * from "./types.js";
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { MODALITIES, type Modality } from "./modality.js";
|
||||||
|
import type { Tool } from "./types.js";
|
||||||
|
|
||||||
|
export type Section = "image" | "video" | "audio" | "pdf" | "files";
|
||||||
|
|
||||||
|
export interface SectionInfo {
|
||||||
|
id: Section;
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
color: string;
|
||||||
|
order: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reuse the existing modality visuals so icon/color have one source of truth.
|
||||||
|
function visualOf(modality: Modality): { icon: string; color: string } {
|
||||||
|
const m = MODALITIES.find((x) => x.id === modality);
|
||||||
|
return { icon: m?.icon ?? "File", color: m?.color ?? "#6B7280" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SECTIONS: SectionInfo[] = [
|
||||||
|
{ id: "image", name: "Image", order: 0, ...visualOf("image") },
|
||||||
|
{ id: "video", name: "Video", order: 1, ...visualOf("video") },
|
||||||
|
{ id: "audio", name: "Audio", order: 2, ...visualOf("audio") },
|
||||||
|
{ id: "pdf", name: "PDF", order: 3, ...visualOf("document") },
|
||||||
|
{ id: "files", name: "Files", order: 4, ...visualOf("file") },
|
||||||
|
];
|
||||||
|
|
||||||
|
// A tool's presentation section. The backend Modality enum is unchanged;
|
||||||
|
// the "document" modality splits by whether the tool ingests PDFs.
|
||||||
|
export function toolSection(tool: Pick<Tool, "modality" | "acceptedInputs">): Section {
|
||||||
|
switch (tool.modality) {
|
||||||
|
case "image":
|
||||||
|
return "image";
|
||||||
|
case "video":
|
||||||
|
return "video";
|
||||||
|
case "audio":
|
||||||
|
return "audio";
|
||||||
|
case "file":
|
||||||
|
return "files";
|
||||||
|
case "document":
|
||||||
|
return tool.acceptedInputs.includes(".pdf") ? "pdf" : "files";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { SECTIONS, type Section, TOOLS, toolSection } from "@snapotter/shared";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("toolSection", () => {
|
||||||
|
it("maps non-document modalities directly", () => {
|
||||||
|
expect(toolSection({ modality: "image", acceptedInputs: [".png"] })).toBe("image");
|
||||||
|
expect(toolSection({ modality: "video", acceptedInputs: [".mp4"] })).toBe("video");
|
||||||
|
expect(toolSection({ modality: "audio", acceptedInputs: [".mp3"] })).toBe("audio");
|
||||||
|
expect(toolSection({ modality: "file", acceptedInputs: [".csv"] })).toBe("files");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("splits document modality by .pdf input", () => {
|
||||||
|
expect(toolSection({ modality: "document", acceptedInputs: [".pdf"] })).toBe("pdf");
|
||||||
|
expect(toolSection({ modality: "document", acceptedInputs: [".docx", ".odt"] })).toBe("files");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("partitions the catalog into exactly 25 PDF and 22 Files tools", () => {
|
||||||
|
const bySection = (s: Section) =>
|
||||||
|
TOOLS.filter((t) => toolSection(t) === s)
|
||||||
|
.map((t) => t.id)
|
||||||
|
.sort();
|
||||||
|
expect(TOOLS.filter((t) => toolSection(t) === "image")).toHaveLength(64);
|
||||||
|
expect(TOOLS.filter((t) => toolSection(t) === "video")).toHaveLength(29);
|
||||||
|
expect(TOOLS.filter((t) => toolSection(t) === "audio")).toHaveLength(17);
|
||||||
|
expect(bySection("pdf")).toHaveLength(25);
|
||||||
|
expect(bySection("files")).toHaveLength(22);
|
||||||
|
expect(bySection("pdf")).toContain("merge-pdf");
|
||||||
|
expect(bySection("pdf")).toContain("ocr-pdf");
|
||||||
|
expect(bySection("files")).toContain("word-to-pdf");
|
||||||
|
expect(bySection("files")).toContain("convert-spreadsheet");
|
||||||
|
expect(bySection("files")).toContain("csv-json");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes 5 ordered sections", () => {
|
||||||
|
expect(SECTIONS.map((s) => s.id)).toEqual(["image", "video", "audio", "pdf", "files"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user