UNPKG

alinea

Version:
79 lines (77 loc) 2.26 kB
import "../chunks/chunk-NZLE2WMY.js"; // src/core/Workspace.ts import { getWorkspace, hasWorkspace, internalWorkspace } from "./Internal.js"; import { Root } from "./Root.js"; import { getRandomColor } from "./util/GetRandomColor.js"; import { isValidIdentifier } from "./util/Identifiers.js"; import { entries, values } from "./util/Objects.js"; var Workspace; ((Workspace2) => { function data(workspace2) { return getWorkspace(workspace2); } Workspace2.data = data; function roots(workspace2) { return getWorkspace(workspace2).roots; } Workspace2.roots = roots; function label(workspace2) { return getWorkspace(workspace2).label; } Workspace2.label = label; function preview(workspace2) { return getWorkspace(workspace2).preview; } Workspace2.preview = preview; function isWorkspace(value) { return Boolean(value && hasWorkspace(value)); } Workspace2.isWorkspace = isWorkspace; function defaultMediaRoot(workspace2) { const { roots: roots2 } = getWorkspace(workspace2); for (const [name, root] of entries(roots2)) if (Root.isMediaRoot(root)) return name; throw new Error("Workspace has no media root"); } Workspace2.defaultMediaRoot = defaultMediaRoot; function defaultRoot(workspace2) { return Object.keys(getWorkspace(workspace2).roots)[0]; } Workspace2.defaultRoot = defaultRoot; function validate(workspace2, schema) { for (const [key, root] of entries(workspace2)) { if (!isValidIdentifier(key)) throw new Error( `Invalid Root name "${key}" in workspace "${label( workspace2 )}", use only a-z, A-Z, 0-9, and _` ); Root.validate(root, label(workspace2), schema); } } Workspace2.validate = validate; function referencedViews(workspace2) { return values(roots(workspace2)).flatMap(Root.referencedViews); } Workspace2.referencedViews = referencedViews; })(Workspace || (Workspace = {})); function workspace(label, config) { const roots = config.roots; const instance = { ...roots, [internalWorkspace]: { ...config, label, color: config.color ?? getRandomColor(JSON.stringify(label)) } }; return instance; } export { Workspace, workspace };