Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829import { stringify } from 'yaml'import type { TypedNodeCatalogType } from '../types-records/typed-node-catalog'
/** Creates the editable YAML seed used when a type is launched from the browser. */export function generateBasesYamlForType(type: TypedNodeCatalogType): string { const formulas: Record<string, string> = { 'file.name': 'file.name', 'file.title': 'file.title', 'file.fullname': 'file.fullname', 'file.path': 'file.path', 'file.folder': 'file.folder', 'file.ext': 'file.ext', } const fieldColumns: string[] = [] const formulaIds = new Set(Object.keys(formulas)) for (const [index, field] of type.fields.entries()) { const preferred = /^[A-Za-z_$][\w$]*$/.test(field.key) ? field.key : '' let formulaId = preferred && !formulaIds.has(preferred) ? preferred : `field_${index}` while (formulaIds.has(formulaId)) formulaId = `${formulaId}_${index}` formulaIds.add(formulaId) formulas[formulaId] = `node.records[${JSON.stringify(type.typeName)}][${JSON.stringify(field.key)}]` fieldColumns.push(`formula.${formulaId}`) } return stringify({ formulas, views: [{ name: type.typeName, filters: `node.records[${JSON.stringify(type.typeName)}] != null`, order: ['file.title', 'file.name', ...fieldColumns] }], })}