@pixldocs/canvas-renderer 0.5.90 → 0.5.91
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 +76 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +76 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11646,6 +11646,8 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11646
11646
|
}
|
|
11647
11647
|
return cloned;
|
|
11648
11648
|
}
|
|
11649
|
+
const ENTRY_ID_KEY = "__entryId";
|
|
11650
|
+
const ENTRY_NAME_KEY = "__entryName";
|
|
11649
11651
|
function hasBaseNodeId(node) {
|
|
11650
11652
|
return node.__baseNodeId != null;
|
|
11651
11653
|
}
|
|
@@ -12225,6 +12227,76 @@ function getRenderableFormSections(schema) {
|
|
|
12225
12227
|
if (!pages.length) return base;
|
|
12226
12228
|
return [...base, ...pages.map(repeatablePageToSection)];
|
|
12227
12229
|
}
|
|
12230
|
+
function isRecord(value) {
|
|
12231
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
12232
|
+
}
|
|
12233
|
+
function getRepeatableEntryMeta(entry, section) {
|
|
12234
|
+
const entryNameKey = section.entryNameFieldKey;
|
|
12235
|
+
const nameCandidate = entry[ENTRY_NAME_KEY] ?? (entryNameKey ? entry[entryNameKey] : void 0) ?? entry.section_title ?? entry.label ?? entry.name;
|
|
12236
|
+
return {
|
|
12237
|
+
id: typeof entry[ENTRY_ID_KEY] === "string" ? entry[ENTRY_ID_KEY] : void 0,
|
|
12238
|
+
name: typeof nameCandidate === "string" ? nameCandidate : void 0
|
|
12239
|
+
};
|
|
12240
|
+
}
|
|
12241
|
+
function extractSectionStateCandidate(values, sections) {
|
|
12242
|
+
if (!isRecord(values)) return null;
|
|
12243
|
+
const raw = isDefaultDataV2(values) && isRecord(values.sectionState) ? values.sectionState : values;
|
|
12244
|
+
const sectionIds = new Set(sections.map((section) => section.id));
|
|
12245
|
+
const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
|
|
12246
|
+
return looksLikeSectionState ? raw : null;
|
|
12247
|
+
}
|
|
12248
|
+
function entryIdentityTokens(entry, section) {
|
|
12249
|
+
const entryNameKey = section == null ? void 0 : section.entryNameFieldKey;
|
|
12250
|
+
const candidates = [
|
|
12251
|
+
entry[ENTRY_NAME_KEY],
|
|
12252
|
+
entryNameKey ? entry[entryNameKey] : void 0,
|
|
12253
|
+
entry.section_title,
|
|
12254
|
+
entry.label,
|
|
12255
|
+
entry.name
|
|
12256
|
+
];
|
|
12257
|
+
return Array.from(new Set(
|
|
12258
|
+
candidates.filter((value) => typeof value === "string" && !!value.trim()).map((value) => value.trim().toLowerCase())
|
|
12259
|
+
));
|
|
12260
|
+
}
|
|
12261
|
+
function mergeRepeatableEntryMeta(target, metaSource, sections) {
|
|
12262
|
+
if (!metaSource) return target;
|
|
12263
|
+
let changed = false;
|
|
12264
|
+
const next = { ...target };
|
|
12265
|
+
const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
|
|
12266
|
+
const isRepeatableStateKey = (key) => repeatableIds.has(key) || Array.from(repeatableIds).some((id) => key.endsWith(`_${id}`));
|
|
12267
|
+
const sectionForStateKey = (key) => sections.find((section) => section.type === "repeatable" && (section.id === key || key.endsWith(`_${section.id}`)));
|
|
12268
|
+
for (const [key, targetEntries] of Object.entries(target)) {
|
|
12269
|
+
if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
|
|
12270
|
+
const sourceEntries = metaSource[key];
|
|
12271
|
+
if (!Array.isArray(sourceEntries)) continue;
|
|
12272
|
+
const section = sectionForStateKey(key);
|
|
12273
|
+
const sourceByToken = /* @__PURE__ */ new Map();
|
|
12274
|
+
const duplicateTokens = /* @__PURE__ */ new Set();
|
|
12275
|
+
for (const sourceEntry of sourceEntries) {
|
|
12276
|
+
if (!isRecord(sourceEntry)) continue;
|
|
12277
|
+
for (const token of entryIdentityTokens(sourceEntry, section)) {
|
|
12278
|
+
if (sourceByToken.has(token)) duplicateTokens.add(token);
|
|
12279
|
+
else sourceByToken.set(token, sourceEntry);
|
|
12280
|
+
}
|
|
12281
|
+
}
|
|
12282
|
+
for (const token of duplicateTokens) sourceByToken.delete(token);
|
|
12283
|
+
const mergedEntries = targetEntries.map((entry, index) => {
|
|
12284
|
+
if (!isRecord(entry)) return entry;
|
|
12285
|
+
const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
|
|
12286
|
+
if (!isRecord(sourceEntry)) return entry;
|
|
12287
|
+
const id = sourceEntry[ENTRY_ID_KEY];
|
|
12288
|
+
const name = sourceEntry[ENTRY_NAME_KEY];
|
|
12289
|
+
const additions = {};
|
|
12290
|
+
if (typeof id === "string" && id.trim() && typeof entry[ENTRY_ID_KEY] !== "string") additions[ENTRY_ID_KEY] = id;
|
|
12291
|
+
if (typeof name === "string" && name.trim() && typeof entry[ENTRY_NAME_KEY] !== "string") additions[ENTRY_NAME_KEY] = name;
|
|
12292
|
+
if (!Object.keys(additions).length) return entry;
|
|
12293
|
+
changed = true;
|
|
12294
|
+
return { ...entry, ...additions };
|
|
12295
|
+
});
|
|
12296
|
+
next[key] = mergedEntries;
|
|
12297
|
+
}
|
|
12298
|
+
return changed ? next : target;
|
|
12299
|
+
}
|
|
12228
12300
|
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
12229
12301
|
var _a;
|
|
12230
12302
|
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
@@ -12471,6 +12543,7 @@ async function resolveFromForm(options) {
|
|
|
12471
12543
|
} else {
|
|
12472
12544
|
inferredSections = [];
|
|
12473
12545
|
}
|
|
12546
|
+
const defaultFormMetaSectionState = extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.values, inferredSections) ?? extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.saved_data, inferredSections);
|
|
12474
12547
|
let mergedSectionState = { ...sectionState };
|
|
12475
12548
|
const templateDefaultData = templateRow.default_data;
|
|
12476
12549
|
if (templateDefaultData && isDefaultDataV2(templateDefaultData)) {
|
|
@@ -12481,6 +12554,7 @@ async function resolveFromForm(options) {
|
|
|
12481
12554
|
}
|
|
12482
12555
|
}
|
|
12483
12556
|
}
|
|
12557
|
+
mergedSectionState = mergeRepeatableEntryMeta(mergedSectionState, defaultFormMetaSectionState, inferredSections);
|
|
12484
12558
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
12485
12559
|
const dynamicFields = templateConfig.dynamicFields || [];
|
|
12486
12560
|
const mappings = [];
|
|
@@ -12502,10 +12576,7 @@ async function resolveFromForm(options) {
|
|
|
12502
12576
|
const entries = mergedSectionState[s.id] ?? [];
|
|
12503
12577
|
const nodeId = s.treeNodeId ?? s.id;
|
|
12504
12578
|
const schemaRepeatable = repeatableFromSchemaByBase.get(baseId(nodeId));
|
|
12505
|
-
const entryMeta = entries.map((e) => (
|
|
12506
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12507
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12508
|
-
}));
|
|
12579
|
+
const entryMeta = entries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12509
12580
|
return { nodeId, label: s.label, entryCount: Math.max(1, entries.length), entryFilter: schemaRepeatable == null ? void 0 : schemaRepeatable.entryFilter, entryMeta };
|
|
12510
12581
|
});
|
|
12511
12582
|
const nestedRepeatables = inferredSections.filter((s) => s.type === "repeatable" && s.parentId != null).map((s) => {
|
|
@@ -12519,10 +12590,7 @@ async function resolveFromForm(options) {
|
|
|
12519
12590
|
const merged = [];
|
|
12520
12591
|
for (let pi = 0; pi < parentEntries.length; pi++) {
|
|
12521
12592
|
const childEntries = mergedSectionState[`${parentId}_${pi}_${s.id}`] ?? [];
|
|
12522
|
-
const meta = childEntries.map((e) => (
|
|
12523
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12524
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12525
|
-
}));
|
|
12593
|
+
const meta = childEntries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12526
12594
|
nestedEntryMeta[`${baseId(parentNodeId)}_${pi + 1}_${baseId(nodeId)}`] = meta;
|
|
12527
12595
|
merged.push(...meta);
|
|
12528
12596
|
}
|