@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.js CHANGED
@@ -10312,9 +10312,27 @@ async function fetchDefaultForm(supabaseUrl, anonKey, formSchemaId) {
10312
10312
  const rows = await res.json();
10313
10313
  return rows.length ? rows[0] : null;
10314
10314
  }
10315
- function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
10315
+ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema, formData) {
10316
10316
  if (!Array.isArray(config == null ? void 0 : config.pages) || config.pages.length === 0) return [];
10317
10317
  const schemaPages = inlineFormSchema == null ? void 0 : inlineFormSchema.repeatablePages;
10318
+ const normalizeTemplateKeyPrefix = (prefix) => {
10319
+ if (!prefix || typeof prefix !== "string") return void 0;
10320
+ return prefix.replace(/^field_/, "");
10321
+ };
10322
+ const inferEntryCount = (prefix, minEntries) => {
10323
+ const normalizedPrefix = normalizeTemplateKeyPrefix(prefix);
10324
+ if (!normalizedPrefix) return minEntries === 0 ? 0 : void 0;
10325
+ let maxIndex = 0;
10326
+ const keyPrefix = `field_${normalizedPrefix}_`;
10327
+ for (const key of Object.keys(formData ?? {})) {
10328
+ if (!key.startsWith(keyPrefix)) continue;
10329
+ const rest = key.slice(keyPrefix.length);
10330
+ const match = /^(\d+)_/.exec(rest);
10331
+ if (match) maxIndex = Math.max(maxIndex, parseInt(match[1], 10));
10332
+ }
10333
+ if (maxIndex > 0) return maxIndex;
10334
+ return minEntries === 0 ? 0 : void 0;
10335
+ };
10318
10336
  const collectIds = (nodes, out2) => {
10319
10337
  for (const n of nodes ?? []) {
10320
10338
  if (n == null ? void 0 : n.id) out2.add(n.id);
@@ -10327,9 +10345,11 @@ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
10327
10345
  const boundId = page == null ? void 0 : page.boundRepeatablePageId;
10328
10346
  if (!boundId) continue;
10329
10347
  let templateKeyPrefix;
10348
+ let entryCount;
10330
10349
  if (Array.isArray(schemaPages)) {
10331
- const found = schemaPages.find((rp) => (rp == null ? void 0 : rp.id) === boundId);
10332
- if (found == null ? void 0 : found.templateKeyPrefix) templateKeyPrefix = found.templateKeyPrefix;
10350
+ const found = schemaPages.find((rp) => (rp == null ? void 0 : rp.id) === boundId || (rp == null ? void 0 : rp.id) === page.id);
10351
+ templateKeyPrefix = normalizeTemplateKeyPrefix(found == null ? void 0 : found.templateKeyPrefix);
10352
+ entryCount = inferEntryCount(templateKeyPrefix ?? (found == null ? void 0 : found.templateKeyPrefix) ?? "", found == null ? void 0 : found.minEntries);
10333
10353
  }
10334
10354
  if (!templateKeyPrefix && Array.isArray(dynamicFields) && dynamicFields.length > 0) {
10335
10355
  const idsOnThisPage = /* @__PURE__ */ new Set();
@@ -10354,10 +10374,14 @@ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema) {
10354
10374
  bestCount = count;
10355
10375
  }
10356
10376
  }
10357
- if (best) templateKeyPrefix = best;
10377
+ if (best) templateKeyPrefix = normalizeTemplateKeyPrefix(best);
10358
10378
  }
10359
10379
  if (templateKeyPrefix) {
10360
- out.push({ pageId: boundId, templateKeyPrefix });
10380
+ out.push({
10381
+ pageId: boundId,
10382
+ templateKeyPrefix,
10383
+ entryCount: entryCount ?? inferEntryCount(templateKeyPrefix)
10384
+ });
10361
10385
  }
10362
10386
  }
10363
10387
  return out;
@@ -10411,7 +10435,7 @@ async function resolveTemplateData(options) {
10411
10435
  });
10412
10436
  }
10413
10437
  }
10414
- const repeatablePagesInput = deriveRepeatablePagesFromTemplate(config, inlineFormSchema);
10438
+ const repeatablePagesInput = deriveRepeatablePagesFromTemplate(config, inlineFormSchema, mergedFormData);
10415
10439
  const resolvedConfig = applyFormDataToConfig(
10416
10440
  config,
10417
10441
  mappings,