@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.cjs
CHANGED
|
@@ -11665,6 +11665,8 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11665
11665
|
}
|
|
11666
11666
|
return cloned;
|
|
11667
11667
|
}
|
|
11668
|
+
const ENTRY_ID_KEY = "__entryId";
|
|
11669
|
+
const ENTRY_NAME_KEY = "__entryName";
|
|
11668
11670
|
function hasBaseNodeId(node) {
|
|
11669
11671
|
return node.__baseNodeId != null;
|
|
11670
11672
|
}
|
|
@@ -12244,6 +12246,76 @@ function getRenderableFormSections(schema) {
|
|
|
12244
12246
|
if (!pages.length) return base;
|
|
12245
12247
|
return [...base, ...pages.map(repeatablePageToSection)];
|
|
12246
12248
|
}
|
|
12249
|
+
function isRecord(value) {
|
|
12250
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
12251
|
+
}
|
|
12252
|
+
function getRepeatableEntryMeta(entry, section) {
|
|
12253
|
+
const entryNameKey = section.entryNameFieldKey;
|
|
12254
|
+
const nameCandidate = entry[ENTRY_NAME_KEY] ?? (entryNameKey ? entry[entryNameKey] : void 0) ?? entry.section_title ?? entry.label ?? entry.name;
|
|
12255
|
+
return {
|
|
12256
|
+
id: typeof entry[ENTRY_ID_KEY] === "string" ? entry[ENTRY_ID_KEY] : void 0,
|
|
12257
|
+
name: typeof nameCandidate === "string" ? nameCandidate : void 0
|
|
12258
|
+
};
|
|
12259
|
+
}
|
|
12260
|
+
function extractSectionStateCandidate(values, sections) {
|
|
12261
|
+
if (!isRecord(values)) return null;
|
|
12262
|
+
const raw = isDefaultDataV2(values) && isRecord(values.sectionState) ? values.sectionState : values;
|
|
12263
|
+
const sectionIds = new Set(sections.map((section) => section.id));
|
|
12264
|
+
const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
|
|
12265
|
+
return looksLikeSectionState ? raw : null;
|
|
12266
|
+
}
|
|
12267
|
+
function entryIdentityTokens(entry, section) {
|
|
12268
|
+
const entryNameKey = section == null ? void 0 : section.entryNameFieldKey;
|
|
12269
|
+
const candidates = [
|
|
12270
|
+
entry[ENTRY_NAME_KEY],
|
|
12271
|
+
entryNameKey ? entry[entryNameKey] : void 0,
|
|
12272
|
+
entry.section_title,
|
|
12273
|
+
entry.label,
|
|
12274
|
+
entry.name
|
|
12275
|
+
];
|
|
12276
|
+
return Array.from(new Set(
|
|
12277
|
+
candidates.filter((value) => typeof value === "string" && !!value.trim()).map((value) => value.trim().toLowerCase())
|
|
12278
|
+
));
|
|
12279
|
+
}
|
|
12280
|
+
function mergeRepeatableEntryMeta(target, metaSource, sections) {
|
|
12281
|
+
if (!metaSource) return target;
|
|
12282
|
+
let changed = false;
|
|
12283
|
+
const next = { ...target };
|
|
12284
|
+
const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
|
|
12285
|
+
const isRepeatableStateKey = (key) => repeatableIds.has(key) || Array.from(repeatableIds).some((id) => key.endsWith(`_${id}`));
|
|
12286
|
+
const sectionForStateKey = (key) => sections.find((section) => section.type === "repeatable" && (section.id === key || key.endsWith(`_${section.id}`)));
|
|
12287
|
+
for (const [key, targetEntries] of Object.entries(target)) {
|
|
12288
|
+
if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
|
|
12289
|
+
const sourceEntries = metaSource[key];
|
|
12290
|
+
if (!Array.isArray(sourceEntries)) continue;
|
|
12291
|
+
const section = sectionForStateKey(key);
|
|
12292
|
+
const sourceByToken = /* @__PURE__ */ new Map();
|
|
12293
|
+
const duplicateTokens = /* @__PURE__ */ new Set();
|
|
12294
|
+
for (const sourceEntry of sourceEntries) {
|
|
12295
|
+
if (!isRecord(sourceEntry)) continue;
|
|
12296
|
+
for (const token of entryIdentityTokens(sourceEntry, section)) {
|
|
12297
|
+
if (sourceByToken.has(token)) duplicateTokens.add(token);
|
|
12298
|
+
else sourceByToken.set(token, sourceEntry);
|
|
12299
|
+
}
|
|
12300
|
+
}
|
|
12301
|
+
for (const token of duplicateTokens) sourceByToken.delete(token);
|
|
12302
|
+
const mergedEntries = targetEntries.map((entry, index) => {
|
|
12303
|
+
if (!isRecord(entry)) return entry;
|
|
12304
|
+
const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
|
|
12305
|
+
if (!isRecord(sourceEntry)) return entry;
|
|
12306
|
+
const id = sourceEntry[ENTRY_ID_KEY];
|
|
12307
|
+
const name = sourceEntry[ENTRY_NAME_KEY];
|
|
12308
|
+
const additions = {};
|
|
12309
|
+
if (typeof id === "string" && id.trim() && typeof entry[ENTRY_ID_KEY] !== "string") additions[ENTRY_ID_KEY] = id;
|
|
12310
|
+
if (typeof name === "string" && name.trim() && typeof entry[ENTRY_NAME_KEY] !== "string") additions[ENTRY_NAME_KEY] = name;
|
|
12311
|
+
if (!Object.keys(additions).length) return entry;
|
|
12312
|
+
changed = true;
|
|
12313
|
+
return { ...entry, ...additions };
|
|
12314
|
+
});
|
|
12315
|
+
next[key] = mergedEntries;
|
|
12316
|
+
}
|
|
12317
|
+
return changed ? next : target;
|
|
12318
|
+
}
|
|
12247
12319
|
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
12248
12320
|
var _a;
|
|
12249
12321
|
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
@@ -12472,8 +12544,9 @@ async function resolveFromForm(options) {
|
|
|
12472
12544
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
12473
12545
|
if (repeatableFromSchema) {
|
|
12474
12546
|
for (const r of repeatableFromSchema) {
|
|
12475
|
-
repeatableNodeMap.set(r.label, r.nodeId);
|
|
12476
|
-
|
|
12547
|
+
if (!repeatableNodeMap.has(r.label)) repeatableNodeMap.set(r.label, r.nodeId);
|
|
12548
|
+
const labelKey = r.label.trim().toLowerCase();
|
|
12549
|
+
if (!repeatableNodeMap.has(labelKey)) repeatableNodeMap.set(labelKey, r.nodeId);
|
|
12477
12550
|
}
|
|
12478
12551
|
}
|
|
12479
12552
|
let inferredSections;
|
|
@@ -12489,6 +12562,7 @@ async function resolveFromForm(options) {
|
|
|
12489
12562
|
} else {
|
|
12490
12563
|
inferredSections = [];
|
|
12491
12564
|
}
|
|
12565
|
+
const defaultFormMetaSectionState = extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.values, inferredSections) ?? extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.saved_data, inferredSections);
|
|
12492
12566
|
let mergedSectionState = { ...sectionState };
|
|
12493
12567
|
const templateDefaultData = templateRow.default_data;
|
|
12494
12568
|
if (templateDefaultData && isDefaultDataV2(templateDefaultData)) {
|
|
@@ -12499,6 +12573,7 @@ async function resolveFromForm(options) {
|
|
|
12499
12573
|
}
|
|
12500
12574
|
}
|
|
12501
12575
|
}
|
|
12576
|
+
mergedSectionState = mergeRepeatableEntryMeta(mergedSectionState, defaultFormMetaSectionState, inferredSections);
|
|
12502
12577
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
12503
12578
|
const dynamicFields = templateConfig.dynamicFields || [];
|
|
12504
12579
|
const mappings = [];
|
|
@@ -12520,10 +12595,7 @@ async function resolveFromForm(options) {
|
|
|
12520
12595
|
const entries = mergedSectionState[s.id] ?? [];
|
|
12521
12596
|
const nodeId = s.treeNodeId ?? s.id;
|
|
12522
12597
|
const schemaRepeatable = repeatableFromSchemaByBase.get(baseId(nodeId));
|
|
12523
|
-
const entryMeta = entries.map((e) => (
|
|
12524
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12525
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12526
|
-
}));
|
|
12598
|
+
const entryMeta = entries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12527
12599
|
return { nodeId, label: s.label, entryCount: Math.max(1, entries.length), entryFilter: schemaRepeatable == null ? void 0 : schemaRepeatable.entryFilter, entryMeta };
|
|
12528
12600
|
});
|
|
12529
12601
|
const nestedRepeatables = inferredSections.filter((s) => s.type === "repeatable" && s.parentId != null).map((s) => {
|
|
@@ -12537,10 +12609,7 @@ async function resolveFromForm(options) {
|
|
|
12537
12609
|
const merged = [];
|
|
12538
12610
|
for (let pi = 0; pi < parentEntries.length; pi++) {
|
|
12539
12611
|
const childEntries = mergedSectionState[`${parentId}_${pi}_${s.id}`] ?? [];
|
|
12540
|
-
const meta = childEntries.map((e) => (
|
|
12541
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12542
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12543
|
-
}));
|
|
12612
|
+
const meta = childEntries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12544
12613
|
nestedEntryMeta[`${baseId(parentNodeId)}_${pi + 1}_${baseId(nodeId)}`] = meta;
|
|
12545
12614
|
merged.push(...meta);
|
|
12546
12615
|
}
|