@pixldocs/canvas-renderer 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +42 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10285,6 +10285,40 @@ function applyContentBoundsPagination(config) {
|
|
|
10285
10285
|
if (!mutated) return config;
|
|
10286
10286
|
return { ...config, pages: resultPages };
|
|
10287
10287
|
}
|
|
10288
|
+
function repeatablePageToSection(page) {
|
|
10289
|
+
return {
|
|
10290
|
+
id: page.id,
|
|
10291
|
+
label: page.label,
|
|
10292
|
+
description: page.description,
|
|
10293
|
+
order: typeof page.order === "number" ? page.order + 1e4 : 1e4,
|
|
10294
|
+
fields: page.fields,
|
|
10295
|
+
repeatable: true,
|
|
10296
|
+
minEntries: page.minEntries,
|
|
10297
|
+
maxEntries: page.maxEntries,
|
|
10298
|
+
templateKeyPrefix: page.templateKeyPrefix,
|
|
10299
|
+
children: page.children
|
|
10300
|
+
};
|
|
10301
|
+
}
|
|
10302
|
+
function getRenderableFormSections(schema) {
|
|
10303
|
+
if (!schema) return [];
|
|
10304
|
+
const base = schema.sections ?? [];
|
|
10305
|
+
const pages = schema.repeatablePages ?? [];
|
|
10306
|
+
if (!pages.length) return base;
|
|
10307
|
+
return [...base, ...pages.map(repeatablePageToSection)];
|
|
10308
|
+
}
|
|
10309
|
+
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
10310
|
+
var _a;
|
|
10311
|
+
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
10312
|
+
return schema.repeatablePages.map((page) => {
|
|
10313
|
+
const entries = sectionState == null ? void 0 : sectionState[page.id];
|
|
10314
|
+
const minEntries = page.minEntries != null ? Math.max(0, page.minEntries) : 1;
|
|
10315
|
+
let entryCount;
|
|
10316
|
+
if (Array.isArray(entries)) {
|
|
10317
|
+
entryCount = minEntries === 0 ? entries.length : Math.max(1, entries.length);
|
|
10318
|
+
}
|
|
10319
|
+
return { pageId: page.id, templateKeyPrefix: page.templateKeyPrefix, entryCount };
|
|
10320
|
+
});
|
|
10321
|
+
}
|
|
10288
10322
|
async function fetchRow(supabaseUrl, anonKey, table, id) {
|
|
10289
10323
|
const url = `${supabaseUrl}/rest/v1/${table}?id=eq.${id}&select=*`;
|
|
10290
10324
|
const res = await fetch(url, {
|
|
@@ -10454,7 +10488,7 @@ async function resolveTemplateData(options) {
|
|
|
10454
10488
|
};
|
|
10455
10489
|
}
|
|
10456
10490
|
async function resolveFromForm(options) {
|
|
10457
|
-
var _a, _b, _c
|
|
10491
|
+
var _a, _b, _c;
|
|
10458
10492
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10459
10493
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10460
10494
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10463,6 +10497,7 @@ async function resolveFromForm(options) {
|
|
|
10463
10497
|
]);
|
|
10464
10498
|
const templateConfig = templateRow.config;
|
|
10465
10499
|
const templateFormSchema = templateRow.form_schema;
|
|
10500
|
+
const formSchema = formSchemaRow.schema;
|
|
10466
10501
|
if (templateFormSchema) {
|
|
10467
10502
|
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10468
10503
|
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
@@ -10476,7 +10511,7 @@ async function resolveFromForm(options) {
|
|
|
10476
10511
|
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10477
10512
|
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10478
10513
|
}
|
|
10479
|
-
const schemaSections = (
|
|
10514
|
+
const schemaSections = getRenderableFormSections(formSchema);
|
|
10480
10515
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10481
10516
|
if (repeatableFromSchema) {
|
|
10482
10517
|
for (const r of repeatableFromSchema) {
|
|
@@ -10487,12 +10522,12 @@ async function resolveFromForm(options) {
|
|
|
10487
10522
|
let inferredSections;
|
|
10488
10523
|
if (schemaSections == null ? void 0 : schemaSections.length) {
|
|
10489
10524
|
inferredSections = formDefSectionsToInferred(schemaSections, repeatableNodeMap);
|
|
10490
|
-
} else if ((
|
|
10525
|
+
} else if ((_a = templateConfig.dynamicFields) == null ? void 0 : _a.length) {
|
|
10491
10526
|
const groups = templateConfig.fieldGroups || [];
|
|
10492
10527
|
inferredSections = inferFormSchemaFromTemplate(
|
|
10493
10528
|
templateConfig.dynamicFields,
|
|
10494
10529
|
groups,
|
|
10495
|
-
((
|
|
10530
|
+
((_b = templateConfig.pages) == null ? void 0 : _b.length) ? { pages: templateConfig.pages } : void 0
|
|
10496
10531
|
);
|
|
10497
10532
|
} else {
|
|
10498
10533
|
inferredSections = [];
|
|
@@ -10577,9 +10612,10 @@ async function resolveFromForm(options) {
|
|
|
10577
10612
|
repeatableList.length > 0 ? repeatableList : repeatableFromSchema ?? [],
|
|
10578
10613
|
void 0,
|
|
10579
10614
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10580
|
-
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10615
|
+
displayFormatMap.size > 0 ? displayFormatMap : void 0,
|
|
10616
|
+
buildRepeatablePagesInputForApply(formSchema, mergedSectionState)
|
|
10581
10617
|
);
|
|
10582
|
-
if ((
|
|
10618
|
+
if ((_c = resolvedConfig.themeConfig) == null ? void 0 : _c.variables) {
|
|
10583
10619
|
const baseOverrides = {};
|
|
10584
10620
|
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10585
10621
|
baseOverrides[key] = def.value;
|