@pixldocs/canvas-renderer 0.3.8 → 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
@@ -10064,8 +10064,20 @@ async function resolveFromForm(options) {
10064
10064
  ]);
10065
10065
  const templateConfig = templateRow.config;
10066
10066
  const templateFormSchema = templateRow.form_schema;
10067
- 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);
10068
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;
10069
10081
  const repeatableNodeMap = /* @__PURE__ */ new Map();
10070
10082
  if (repeatableFromSchema) {
10071
10083
  for (const r of repeatableFromSchema) {
@@ -10097,9 +10109,7 @@ async function resolveFromForm(options) {
10097
10109
  }
10098
10110
  }
10099
10111
  const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
10100
- const configDynamicFields = templateConfig.dynamicFields;
10101
- const formSchemaDynamicFields = templateFormSchema == null ? void 0 : templateFormSchema.dynamicFields;
10102
- const dynamicFields = ((configDynamicFields == null ? void 0 : configDynamicFields.length) ? configDynamicFields : formSchemaDynamicFields) || [];
10112
+ const dynamicFields = templateConfig.dynamicFields || [];
10103
10113
  const mappings = [];
10104
10114
  for (const field of dynamicFields) {
10105
10115
  if (field.mappings) {
@@ -10215,6 +10225,54 @@ function flattenAll(nodes) {
10215
10225
  }
10216
10226
  return result;
10217
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
+ }
10218
10276
  function PixldocsPreview(props) {
10219
10277
  const {
10220
10278
  pageIndex = 0,