@pixldocs/canvas-renderer 0.5.220 → 0.5.222

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.
@@ -17390,7 +17390,13 @@ function sanitizeSectionStateAgainstSchema(state, schema) {
17390
17390
  if (!state) return {};
17391
17391
  if (!schema) return { ...state };
17392
17392
  const known = /* @__PURE__ */ new Set();
17393
- for (const s of schema.sections ?? []) known.add(s.id);
17393
+ const collectSectionIds = (sections) => {
17394
+ for (const s of sections ?? []) {
17395
+ known.add(s.id);
17396
+ collectSectionIds(s.children);
17397
+ }
17398
+ };
17399
+ collectSectionIds(schema.sections);
17394
17400
  for (const p of schema.repeatablePages ?? []) known.add(p.id);
17395
17401
  const out = {};
17396
17402
  for (const [key, value] of Object.entries(state)) {
@@ -17537,7 +17543,7 @@ async function resolveTemplateData(options) {
17537
17543
  }
17538
17544
  }
17539
17545
  if (repeatableSectionsInput.length > 0) {
17540
- paintRepeatableSections(config, repeatableSectionsInput);
17546
+ paintRepeatableSections(config, repeatableSectionsInput, inlineFormSchema);
17541
17547
  }
17542
17548
  }
17543
17549
  const mergedFormData = {
@@ -17580,10 +17586,11 @@ async function resolveTemplateData(options) {
17580
17586
  async function resolveFromForm(options) {
17581
17587
  var _a, _b, _c;
17582
17588
  const { templateId, formSchemaId, sectionState, flatFormData: directFlatFormData, themeId, supabaseUrl, supabaseAnonKey, prefetched } = options;
17583
- if (!formSchemaId) {
17589
+ const hasSectionStateInput = !!sectionState && Object.keys(sectionState).length > 0;
17590
+ if (!formSchemaId && !hasSectionStateInput) {
17584
17591
  return resolveTemplateData({
17585
17592
  templateId,
17586
- formData: directFlatFormData ?? sectionState ?? {},
17593
+ formData: directFlatFormData ?? {},
17587
17594
  supabaseUrl,
17588
17595
  supabaseAnonKey,
17589
17596
  prefetched: (prefetched == null ? void 0 : prefetched.templateRow) ? { templateRow: prefetched.templateRow } : void 0
@@ -17591,12 +17598,12 @@ async function resolveFromForm(options) {
17591
17598
  }
17592
17599
  const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
17593
17600
  (prefetched == null ? void 0 : prefetched.templateRow) ? Promise.resolve(prefetched.templateRow) : fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
17594
- (prefetched == null ? void 0 : prefetched.formSchemaRow) !== void 0 ? Promise.resolve(prefetched.formSchemaRow) : fetchRow(supabaseUrl, supabaseAnonKey, "form_schemas", formSchemaId),
17595
- (prefetched == null ? void 0 : prefetched.defaultForm) !== void 0 ? Promise.resolve(prefetched.defaultForm) : fetchDefaultForm(supabaseUrl, supabaseAnonKey, formSchemaId)
17601
+ (prefetched == null ? void 0 : prefetched.formSchemaRow) !== void 0 ? Promise.resolve(prefetched.formSchemaRow) : formSchemaId ? fetchRow(supabaseUrl, supabaseAnonKey, "form_schemas", formSchemaId).catch(() => null) : Promise.resolve(null),
17602
+ (prefetched == null ? void 0 : prefetched.defaultForm) !== void 0 ? Promise.resolve(prefetched.defaultForm) : formSchemaId ? fetchDefaultForm(supabaseUrl, supabaseAnonKey, formSchemaId) : Promise.resolve(null)
17596
17603
  ]);
17597
17604
  const templateConfig = templateRow.config;
17598
17605
  const templateFormSchema = templateRow.form_schema;
17599
- const formSchema = formSchemaRow.schema;
17606
+ const formSchema = (formSchemaRow == null ? void 0 : formSchemaRow.schema) ?? void 0;
17600
17607
  if (templateFormSchema) {
17601
17608
  if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
17602
17609
  templateConfig.dynamicFields = templateFormSchema.dynamicFields;
@@ -17608,7 +17615,7 @@ async function resolveFromForm(options) {
17608
17615
  normalizeLayoutModes(templateConfig);
17609
17616
  const repeatableFromSchema = templateFormSchema == null ? void 0 : templateFormSchema.repeatableSections;
17610
17617
  if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
17611
- paintRepeatableSections(templateConfig, repeatableFromSchema);
17618
+ paintRepeatableSections(templateConfig, repeatableFromSchema, templateFormSchema);
17612
17619
  }
17613
17620
  const schemaSections = getRenderableFormSections(formSchema);
17614
17621
  const repeatableNodeMap = /* @__PURE__ */ new Map();
@@ -17911,8 +17918,11 @@ function normalizeLayoutModes(config) {
17911
17918
  }
17912
17919
  }
17913
17920
  }
17914
- function paintRepeatableSections(config, repeatableSections) {
17921
+ function paintRepeatableSections(config, repeatableSections, formSchema) {
17922
+ var _a, _b;
17915
17923
  const pages = config.pages ?? [];
17924
+ const entryFilters = (formSchema == null ? void 0 : formSchema.entryFilters) ?? [];
17925
+ const entryFilterBases = new Set(entryFilters.map((f) => baseId(f.nodeId)));
17916
17926
  function stripFlags(nodes) {
17917
17927
  for (const node of nodes) {
17918
17928
  delete node.repeatableSection;
@@ -17922,32 +17932,53 @@ function paintRepeatableSections(config, repeatableSections) {
17922
17932
  for (const page of pages) {
17923
17933
  if (page.children) stripFlags(page.children);
17924
17934
  }
17925
- function setRepeatable(nodes, nodeId, payload) {
17935
+ function setRepeatableAll(nodes, nodeId, payload) {
17936
+ let painted = 0;
17926
17937
  for (const node of nodes) {
17927
17938
  const id = node.id;
17928
- if (node.repeatableSection) {
17929
- if (Array.isArray(node.children) && setRepeatable(node.children, nodeId, payload)) {
17930
- return true;
17931
- }
17932
- continue;
17933
- }
17934
17939
  if (id && (id === nodeId || baseId(id) === baseId(nodeId))) {
17935
17940
  node.repeatableSection = payload;
17936
- return true;
17941
+ painted++;
17937
17942
  }
17938
- if (Array.isArray(node.children) && setRepeatable(node.children, nodeId, payload)) {
17939
- return true;
17943
+ if (Array.isArray(node.children)) {
17944
+ painted += setRepeatableAll(node.children, nodeId, payload);
17940
17945
  }
17941
17946
  }
17942
- return false;
17947
+ return painted;
17943
17948
  }
17944
17949
  for (const section of repeatableSections) {
17950
+ const inlineRange = ((_a = section.entryFilter) == null ? void 0 : _a.mode) === "range" ? (_b = section.entryFilter.range) == null ? void 0 : _b.trim() : void 0;
17951
+ const shouldUseInlineFilter = !!inlineRange && !entryFilterBases.has(baseId(section.nodeId));
17945
17952
  const payload = { label: section.label };
17946
17953
  if (section.minEntries !== void 0) payload.minEntries = section.minEntries;
17947
17954
  if (section.maxEntries !== void 0) payload.maxEntries = section.maxEntries;
17948
- if (section.entryFilter !== void 0) payload.entryFilter = section.entryFilter;
17955
+ if (shouldUseInlineFilter) payload.entryFilter = { mode: "range", range: inlineRange };
17949
17956
  for (const page of pages) {
17950
- if (setRepeatable(page.children ?? [], section.nodeId, payload)) break;
17957
+ setRepeatableAll(page.children ?? [], section.nodeId, payload);
17958
+ }
17959
+ }
17960
+ if (entryFilters.length) {
17961
+ const occurrencesByBase = /* @__PURE__ */ new Map();
17962
+ const collect = (nodes) => {
17963
+ var _a2;
17964
+ for (const node of nodes ?? []) {
17965
+ if ((_a2 = node.repeatableSection) == null ? void 0 : _a2.label) {
17966
+ const base = baseId(node.id);
17967
+ if (!occurrencesByBase.has(base)) occurrencesByBase.set(base, []);
17968
+ occurrencesByBase.get(base).push(node);
17969
+ }
17970
+ if (Array.isArray(node.children)) collect(node.children);
17971
+ }
17972
+ };
17973
+ for (const page of pages) collect(page.children ?? []);
17974
+ for (const filter of entryFilters) {
17975
+ const base = baseId(filter.nodeId);
17976
+ const occurrences = occurrencesByBase.get(base);
17977
+ if (!(occurrences == null ? void 0 : occurrences.length)) continue;
17978
+ const target = filter.occurrenceIndex && filter.occurrenceIndex >= 1 ? occurrences[filter.occurrenceIndex - 1] : occurrences.find((node) => node.id === filter.nodeId) ?? occurrences[0];
17979
+ if (target == null ? void 0 : target.repeatableSection) {
17980
+ target.repeatableSection.entryFilter = { mode: filter.mode, ...filter.range ? { range: filter.range } : {} };
17981
+ }
17951
17982
  }
17952
17983
  }
17953
17984
  }
@@ -19092,9 +19123,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
19092
19123
  }
19093
19124
  return svgString;
19094
19125
  }
19095
- const resolvedPackageVersion = "0.5.220";
19126
+ const resolvedPackageVersion = "0.5.222";
19096
19127
  const PACKAGE_VERSION = resolvedPackageVersion;
19097
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.220";
19128
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.222";
19098
19129
  const roundParityValue = (value) => {
19099
19130
  if (typeof value !== "number") return value;
19100
19131
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -19838,7 +19869,7 @@ class PixldocsRenderer {
19838
19869
  await this.waitForCanvasScene(container, cloned, i);
19839
19870
  }
19840
19871
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
19841
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-UBFTDrVt.cjs"));
19872
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-CDMnc_eW.cjs"));
19842
19873
  const prepared = preparePagesForExport(
19843
19874
  cloned.pages,
19844
19875
  canvasWidth,
@@ -22028,7 +22059,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
22028
22059
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
22029
22060
  sanitizeSvgTreeForPdf(svgToDraw);
22030
22061
  try {
22031
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-UBFTDrVt.cjs"));
22062
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-CDMnc_eW.cjs"));
22032
22063
  try {
22033
22064
  await logTextMeasurementDiagnostic(svgToDraw);
22034
22065
  } catch {
@@ -22425,4 +22456,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
22425
22456
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
22426
22457
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
22427
22458
  exports.warmTemplateFromForm = warmTemplateFromForm;
22428
- //# sourceMappingURL=index-DRHaeOxK.cjs.map
22459
+ //# sourceMappingURL=index-BKJxI43i.cjs.map