alinea
Version:
Headless git-based CMS
61 lines (59 loc) • 1.73 kB
JavaScript
import "../chunks/chunk-NZLE2WMY.js";
// src/core/Section.ts
import { Field } from "./Field.js";
import { assign, create, defineProperty, entries } from "./util/Objects.js";
import { rowId } from "./util/RowId.js";
var Section;
((Section2) => {
Section2.Data = Symbol.for("@alinea/Section.Data");
function view(section2) {
return section2[Section2.Data].view;
}
Section2.view = view;
function referencedViews(section2) {
const { view: view2, sections } = section2[Section2.Data];
return [view2, ...sections.flatMap(referencedViews)].filter(
(v) => typeof v === "string"
);
}
Section2.referencedViews = referencedViews;
function definition(section2) {
return section2[Section2.Data].definition;
}
Section2.definition = definition;
function fields(section2) {
return section2[Section2.Data].fields;
}
Section2.fields = fields;
function isSection(value) {
return Boolean(value?.[Section2.Data]);
}
Section2.isSection = isSection;
})(Section || (Section = {}));
function section(data) {
const section2 = create(null);
const sections = [];
const fields = create(null);
for (const [key, value] of entries(data.definition)) {
if (Field.isField(value)) {
defineProperty(section2, key, { value, enumerable: false });
fields[key] = value;
} else if (Section.isSection(value)) {
sections.push(value);
assign(fields, Section.fields(value));
}
}
const id = rowId();
section2[id] = section2;
if (!data.fields) assign(data, { fields });
if (!data.sections) assign(data, { sections });
defineProperty(section2, Section.Data, {
value: data,
enumerable: false
});
return section2;
}
export {
Section,
section
};