@pixldocs/canvas-renderer 0.5.1 → 0.5.2
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 +30 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10331,9 +10331,27 @@ async function fetchDefaultForm(supabaseUrl, anonKey, formSchemaId) {
|
|
|
10331
10331
|
const rows = await res.json();
|
|
10332
10332
|
return rows.length ? rows[0] : null;
|
|
10333
10333
|
}
|
|
10334
|
-
function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
|
|
10334
|
+
function deriveRepeatablePagesFromTemplate(config, inlineFormSchema, formData) {
|
|
10335
10335
|
if (!Array.isArray(config == null ? void 0 : config.pages) || config.pages.length === 0) return [];
|
|
10336
10336
|
const schemaPages = inlineFormSchema == null ? void 0 : inlineFormSchema.repeatablePages;
|
|
10337
|
+
const normalizeTemplateKeyPrefix = (prefix) => {
|
|
10338
|
+
if (!prefix || typeof prefix !== "string") return void 0;
|
|
10339
|
+
return prefix.replace(/^field_/, "");
|
|
10340
|
+
};
|
|
10341
|
+
const inferEntryCount = (prefix, minEntries) => {
|
|
10342
|
+
const normalizedPrefix = normalizeTemplateKeyPrefix(prefix);
|
|
10343
|
+
if (!normalizedPrefix) return minEntries === 0 ? 0 : void 0;
|
|
10344
|
+
let maxIndex = 0;
|
|
10345
|
+
const keyPrefix = `field_${normalizedPrefix}_`;
|
|
10346
|
+
for (const key of Object.keys(formData ?? {})) {
|
|
10347
|
+
if (!key.startsWith(keyPrefix)) continue;
|
|
10348
|
+
const rest = key.slice(keyPrefix.length);
|
|
10349
|
+
const match = /^(\d+)_/.exec(rest);
|
|
10350
|
+
if (match) maxIndex = Math.max(maxIndex, parseInt(match[1], 10));
|
|
10351
|
+
}
|
|
10352
|
+
if (maxIndex > 0) return maxIndex;
|
|
10353
|
+
return minEntries === 0 ? 0 : void 0;
|
|
10354
|
+
};
|
|
10337
10355
|
const collectIds = (nodes, out2) => {
|
|
10338
10356
|
for (const n of nodes ?? []) {
|
|
10339
10357
|
if (n == null ? void 0 : n.id) out2.add(n.id);
|
|
@@ -10346,9 +10364,11 @@ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
|
|
|
10346
10364
|
const boundId = page == null ? void 0 : page.boundRepeatablePageId;
|
|
10347
10365
|
if (!boundId) continue;
|
|
10348
10366
|
let templateKeyPrefix;
|
|
10367
|
+
let entryCount;
|
|
10349
10368
|
if (Array.isArray(schemaPages)) {
|
|
10350
|
-
const found = schemaPages.find((rp) => (rp == null ? void 0 : rp.id) === boundId);
|
|
10351
|
-
|
|
10369
|
+
const found = schemaPages.find((rp) => (rp == null ? void 0 : rp.id) === boundId || (rp == null ? void 0 : rp.id) === page.id);
|
|
10370
|
+
templateKeyPrefix = normalizeTemplateKeyPrefix(found == null ? void 0 : found.templateKeyPrefix);
|
|
10371
|
+
entryCount = inferEntryCount(templateKeyPrefix ?? (found == null ? void 0 : found.templateKeyPrefix) ?? "", found == null ? void 0 : found.minEntries);
|
|
10352
10372
|
}
|
|
10353
10373
|
if (!templateKeyPrefix && Array.isArray(dynamicFields) && dynamicFields.length > 0) {
|
|
10354
10374
|
const idsOnThisPage = /* @__PURE__ */ new Set();
|
|
@@ -10373,10 +10393,14 @@ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
|
|
|
10373
10393
|
bestCount = count;
|
|
10374
10394
|
}
|
|
10375
10395
|
}
|
|
10376
|
-
if (best) templateKeyPrefix = best;
|
|
10396
|
+
if (best) templateKeyPrefix = normalizeTemplateKeyPrefix(best);
|
|
10377
10397
|
}
|
|
10378
10398
|
if (templateKeyPrefix) {
|
|
10379
|
-
out.push({
|
|
10399
|
+
out.push({
|
|
10400
|
+
pageId: boundId,
|
|
10401
|
+
templateKeyPrefix,
|
|
10402
|
+
entryCount: entryCount ?? inferEntryCount(templateKeyPrefix)
|
|
10403
|
+
});
|
|
10380
10404
|
}
|
|
10381
10405
|
}
|
|
10382
10406
|
return out;
|
|
@@ -10430,7 +10454,7 @@ async function resolveTemplateData(options) {
|
|
|
10430
10454
|
});
|
|
10431
10455
|
}
|
|
10432
10456
|
}
|
|
10433
|
-
const repeatablePagesInput = deriveRepeatablePagesFromTemplate(config, inlineFormSchema);
|
|
10457
|
+
const repeatablePagesInput = deriveRepeatablePagesFromTemplate(config, inlineFormSchema, mergedFormData);
|
|
10434
10458
|
const resolvedConfig = applyFormDataToConfig(
|
|
10435
10459
|
config,
|
|
10436
10460
|
mappings,
|