@pixldocs/canvas-renderer 0.5.89 → 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 +79 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -10
- 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 [];
|
|
@@ -12453,8 +12525,9 @@ async function resolveFromForm(options) {
|
|
|
12453
12525
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
12454
12526
|
if (repeatableFromSchema) {
|
|
12455
12527
|
for (const r of repeatableFromSchema) {
|
|
12456
|
-
repeatableNodeMap.set(r.label, r.nodeId);
|
|
12457
|
-
|
|
12528
|
+
if (!repeatableNodeMap.has(r.label)) repeatableNodeMap.set(r.label, r.nodeId);
|
|
12529
|
+
const labelKey = r.label.trim().toLowerCase();
|
|
12530
|
+
if (!repeatableNodeMap.has(labelKey)) repeatableNodeMap.set(labelKey, r.nodeId);
|
|
12458
12531
|
}
|
|
12459
12532
|
}
|
|
12460
12533
|
let inferredSections;
|
|
@@ -12470,6 +12543,7 @@ async function resolveFromForm(options) {
|
|
|
12470
12543
|
} else {
|
|
12471
12544
|
inferredSections = [];
|
|
12472
12545
|
}
|
|
12546
|
+
const defaultFormMetaSectionState = extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.values, inferredSections) ?? extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.saved_data, inferredSections);
|
|
12473
12547
|
let mergedSectionState = { ...sectionState };
|
|
12474
12548
|
const templateDefaultData = templateRow.default_data;
|
|
12475
12549
|
if (templateDefaultData && isDefaultDataV2(templateDefaultData)) {
|
|
@@ -12480,6 +12554,7 @@ async function resolveFromForm(options) {
|
|
|
12480
12554
|
}
|
|
12481
12555
|
}
|
|
12482
12556
|
}
|
|
12557
|
+
mergedSectionState = mergeRepeatableEntryMeta(mergedSectionState, defaultFormMetaSectionState, inferredSections);
|
|
12483
12558
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
12484
12559
|
const dynamicFields = templateConfig.dynamicFields || [];
|
|
12485
12560
|
const mappings = [];
|
|
@@ -12501,10 +12576,7 @@ async function resolveFromForm(options) {
|
|
|
12501
12576
|
const entries = mergedSectionState[s.id] ?? [];
|
|
12502
12577
|
const nodeId = s.treeNodeId ?? s.id;
|
|
12503
12578
|
const schemaRepeatable = repeatableFromSchemaByBase.get(baseId(nodeId));
|
|
12504
|
-
const entryMeta = entries.map((e) => (
|
|
12505
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12506
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12507
|
-
}));
|
|
12579
|
+
const entryMeta = entries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12508
12580
|
return { nodeId, label: s.label, entryCount: Math.max(1, entries.length), entryFilter: schemaRepeatable == null ? void 0 : schemaRepeatable.entryFilter, entryMeta };
|
|
12509
12581
|
});
|
|
12510
12582
|
const nestedRepeatables = inferredSections.filter((s) => s.type === "repeatable" && s.parentId != null).map((s) => {
|
|
@@ -12518,10 +12590,7 @@ async function resolveFromForm(options) {
|
|
|
12518
12590
|
const merged = [];
|
|
12519
12591
|
for (let pi = 0; pi < parentEntries.length; pi++) {
|
|
12520
12592
|
const childEntries = mergedSectionState[`${parentId}_${pi}_${s.id}`] ?? [];
|
|
12521
|
-
const meta = childEntries.map((e) => (
|
|
12522
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12523
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12524
|
-
}));
|
|
12593
|
+
const meta = childEntries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12525
12594
|
nestedEntryMeta[`${baseId(parentNodeId)}_${pi + 1}_${baseId(nodeId)}`] = meta;
|
|
12526
12595
|
merged.push(...meta);
|
|
12527
12596
|
}
|