@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.cjs
CHANGED
|
@@ -10304,6 +10304,40 @@ function applyContentBoundsPagination(config) {
|
|
|
10304
10304
|
if (!mutated) return config;
|
|
10305
10305
|
return { ...config, pages: resultPages };
|
|
10306
10306
|
}
|
|
10307
|
+
function repeatablePageToSection(page) {
|
|
10308
|
+
return {
|
|
10309
|
+
id: page.id,
|
|
10310
|
+
label: page.label,
|
|
10311
|
+
description: page.description,
|
|
10312
|
+
order: typeof page.order === "number" ? page.order + 1e4 : 1e4,
|
|
10313
|
+
fields: page.fields,
|
|
10314
|
+
repeatable: true,
|
|
10315
|
+
minEntries: page.minEntries,
|
|
10316
|
+
maxEntries: page.maxEntries,
|
|
10317
|
+
templateKeyPrefix: page.templateKeyPrefix,
|
|
10318
|
+
children: page.children
|
|
10319
|
+
};
|
|
10320
|
+
}
|
|
10321
|
+
function getRenderableFormSections(schema) {
|
|
10322
|
+
if (!schema) return [];
|
|
10323
|
+
const base = schema.sections ?? [];
|
|
10324
|
+
const pages = schema.repeatablePages ?? [];
|
|
10325
|
+
if (!pages.length) return base;
|
|
10326
|
+
return [...base, ...pages.map(repeatablePageToSection)];
|
|
10327
|
+
}
|
|
10328
|
+
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
10329
|
+
var _a;
|
|
10330
|
+
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
10331
|
+
return schema.repeatablePages.map((page) => {
|
|
10332
|
+
const entries = sectionState == null ? void 0 : sectionState[page.id];
|
|
10333
|
+
const minEntries = page.minEntries != null ? Math.max(0, page.minEntries) : 1;
|
|
10334
|
+
let entryCount;
|
|
10335
|
+
if (Array.isArray(entries)) {
|
|
10336
|
+
entryCount = minEntries === 0 ? entries.length : Math.max(1, entries.length);
|
|
10337
|
+
}
|
|
10338
|
+
return { pageId: page.id, templateKeyPrefix: page.templateKeyPrefix, entryCount };
|
|
10339
|
+
});
|
|
10340
|
+
}
|
|
10307
10341
|
async function fetchRow(supabaseUrl, anonKey, table, id) {
|
|
10308
10342
|
const url = `${supabaseUrl}/rest/v1/${table}?id=eq.${id}&select=*`;
|
|
10309
10343
|
const res = await fetch(url, {
|
|
@@ -10473,7 +10507,7 @@ async function resolveTemplateData(options) {
|
|
|
10473
10507
|
};
|
|
10474
10508
|
}
|
|
10475
10509
|
async function resolveFromForm(options) {
|
|
10476
|
-
var _a, _b, _c
|
|
10510
|
+
var _a, _b, _c;
|
|
10477
10511
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10478
10512
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10479
10513
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10482,6 +10516,7 @@ async function resolveFromForm(options) {
|
|
|
10482
10516
|
]);
|
|
10483
10517
|
const templateConfig = templateRow.config;
|
|
10484
10518
|
const templateFormSchema = templateRow.form_schema;
|
|
10519
|
+
const formSchema = formSchemaRow.schema;
|
|
10485
10520
|
if (templateFormSchema) {
|
|
10486
10521
|
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10487
10522
|
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
@@ -10495,7 +10530,7 @@ async function resolveFromForm(options) {
|
|
|
10495
10530
|
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10496
10531
|
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10497
10532
|
}
|
|
10498
|
-
const schemaSections = (
|
|
10533
|
+
const schemaSections = getRenderableFormSections(formSchema);
|
|
10499
10534
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10500
10535
|
if (repeatableFromSchema) {
|
|
10501
10536
|
for (const r of repeatableFromSchema) {
|
|
@@ -10506,12 +10541,12 @@ async function resolveFromForm(options) {
|
|
|
10506
10541
|
let inferredSections;
|
|
10507
10542
|
if (schemaSections == null ? void 0 : schemaSections.length) {
|
|
10508
10543
|
inferredSections = formDefSectionsToInferred(schemaSections, repeatableNodeMap);
|
|
10509
|
-
} else if ((
|
|
10544
|
+
} else if ((_a = templateConfig.dynamicFields) == null ? void 0 : _a.length) {
|
|
10510
10545
|
const groups = templateConfig.fieldGroups || [];
|
|
10511
10546
|
inferredSections = inferFormSchemaFromTemplate(
|
|
10512
10547
|
templateConfig.dynamicFields,
|
|
10513
10548
|
groups,
|
|
10514
|
-
((
|
|
10549
|
+
((_b = templateConfig.pages) == null ? void 0 : _b.length) ? { pages: templateConfig.pages } : void 0
|
|
10515
10550
|
);
|
|
10516
10551
|
} else {
|
|
10517
10552
|
inferredSections = [];
|
|
@@ -10596,9 +10631,10 @@ async function resolveFromForm(options) {
|
|
|
10596
10631
|
repeatableList.length > 0 ? repeatableList : repeatableFromSchema ?? [],
|
|
10597
10632
|
void 0,
|
|
10598
10633
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10599
|
-
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10634
|
+
displayFormatMap.size > 0 ? displayFormatMap : void 0,
|
|
10635
|
+
buildRepeatablePagesInputForApply(formSchema, mergedSectionState)
|
|
10600
10636
|
);
|
|
10601
|
-
if ((
|
|
10637
|
+
if ((_c = resolvedConfig.themeConfig) == null ? void 0 : _c.variables) {
|
|
10602
10638
|
const baseOverrides = {};
|
|
10603
10639
|
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10604
10640
|
baseOverrides[key] = def.value;
|