@pixldocs/canvas-renderer 0.3.7 → 0.3.9

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 CHANGED
@@ -9020,8 +9020,19 @@ function flattenSectionStateToFormData(sectionState, sections) {
9020
9020
  for (const child of children) {
9021
9021
  const childToken = child.templateKeyPrefix.startsWith("field_") ? child.templateKeyPrefix.slice(6) : child.templateKeyPrefix;
9022
9022
  const childStateKey = `${sectionStateKey}_${i}_${child.id}`;
9023
- const childPrefix = `${sectionPrefix}_${oneBased}_${childToken}`;
9024
- emitRepeatable(child, childStateKey, childPrefix);
9023
+ const compactPrefix = `${sectionPrefix}_${oneBased}_${childToken}`;
9024
+ emitRepeatable(child, childStateKey, compactPrefix);
9025
+ const aliasPrefix = `${sectionPrefix}_${oneBased}_field_${childToken}`;
9026
+ if (aliasPrefix !== compactPrefix) {
9027
+ emitRepeatable(child, childStateKey, aliasPrefix);
9028
+ }
9029
+ const childIdToken = child.id;
9030
+ if (childIdToken !== childToken) {
9031
+ const idPrefix2 = `${sectionPrefix}_${oneBased}_${childIdToken}`;
9032
+ emitRepeatable(child, childStateKey, idPrefix2);
9033
+ const idAliasPrefix = `${sectionPrefix}_${oneBased}_field_${childIdToken}`;
9034
+ emitRepeatable(child, childStateKey, idAliasPrefix);
9035
+ }
9025
9036
  }
9026
9037
  }
9027
9038
  };
@@ -10053,8 +10064,20 @@ async function resolveFromForm(options) {
10053
10064
  ]);
10054
10065
  const templateConfig = templateRow.config;
10055
10066
  const templateFormSchema = templateRow.form_schema;
10056
- const schemaSections = (_a = formSchemaRow.schema) == null ? void 0 : _a.sections;
10067
+ if (templateFormSchema) {
10068
+ if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
10069
+ templateConfig.dynamicFields = templateFormSchema.dynamicFields;
10070
+ }
10071
+ if (!Array.isArray(templateConfig.fieldGroups) && Array.isArray(templateFormSchema.fieldGroups)) {
10072
+ templateConfig.fieldGroups = templateFormSchema.fieldGroups;
10073
+ }
10074
+ }
10075
+ normalizeLayoutModes(templateConfig);
10057
10076
  const repeatableFromSchema = templateFormSchema == null ? void 0 : templateFormSchema.repeatableSections;
10077
+ if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
10078
+ paintRepeatableSections(templateConfig, repeatableFromSchema);
10079
+ }
10080
+ const schemaSections = (_a = formSchemaRow.schema) == null ? void 0 : _a.sections;
10058
10081
  const repeatableNodeMap = /* @__PURE__ */ new Map();
10059
10082
  if (repeatableFromSchema) {
10060
10083
  for (const r of repeatableFromSchema) {
@@ -10086,9 +10109,7 @@ async function resolveFromForm(options) {
10086
10109
  }
10087
10110
  }
10088
10111
  const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
10089
- const configDynamicFields = templateConfig.dynamicFields;
10090
- const formSchemaDynamicFields = templateFormSchema == null ? void 0 : templateFormSchema.dynamicFields;
10091
- const dynamicFields = ((configDynamicFields == null ? void 0 : configDynamicFields.length) ? configDynamicFields : formSchemaDynamicFields) || [];
10112
+ const dynamicFields = templateConfig.dynamicFields || [];
10092
10113
  const mappings = [];
10093
10114
  for (const field of dynamicFields) {
10094
10115
  if (field.mappings) {
@@ -10204,6 +10225,54 @@ function flattenAll(nodes) {
10204
10225
  }
10205
10226
  return result;
10206
10227
  }
10228
+ function normalizeLayoutModes(config) {
10229
+ function walk(node) {
10230
+ if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
10231
+ node.layoutMode = "vertical-stack";
10232
+ }
10233
+ if (Array.isArray(node.children)) {
10234
+ for (const child of node.children) walk(child);
10235
+ }
10236
+ }
10237
+ for (const page of config.pages ?? []) {
10238
+ if (page.children) {
10239
+ for (const child of page.children) walk(child);
10240
+ }
10241
+ }
10242
+ }
10243
+ function paintRepeatableSections(config, repeatableSections) {
10244
+ const pages = config.pages ?? [];
10245
+ function stripFlags(nodes) {
10246
+ for (const node of nodes) {
10247
+ delete node.repeatableSection;
10248
+ if (Array.isArray(node.children)) stripFlags(node.children);
10249
+ }
10250
+ }
10251
+ for (const page of pages) {
10252
+ if (page.children) stripFlags(page.children);
10253
+ }
10254
+ function setRepeatable(nodes, nodeId, payload) {
10255
+ for (const node of nodes) {
10256
+ const id = node.id;
10257
+ if (id && (id === nodeId || baseId(id) === baseId(nodeId))) {
10258
+ node.repeatableSection = payload;
10259
+ return true;
10260
+ }
10261
+ if (Array.isArray(node.children) && setRepeatable(node.children, nodeId, payload)) {
10262
+ return true;
10263
+ }
10264
+ }
10265
+ return false;
10266
+ }
10267
+ for (const section of repeatableSections) {
10268
+ const payload = { label: section.label };
10269
+ if (section.minEntries !== void 0) payload.minEntries = section.minEntries;
10270
+ if (section.maxEntries !== void 0) payload.maxEntries = section.maxEntries;
10271
+ for (const page of pages) {
10272
+ if (setRepeatable(page.children ?? [], section.nodeId, payload)) break;
10273
+ }
10274
+ }
10275
+ }
10207
10276
  function PixldocsPreview(props) {
10208
10277
  const {
10209
10278
  pageIndex = 0,