@pixldocs/canvas-renderer 0.5.83 → 0.5.85
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 +285 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +285 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1677,7 +1677,7 @@ const useEditorStore = create((set, get) => ({
|
|
|
1677
1677
|
const themeConfig = state.canvas.themeConfig ?? createEmptyThemeConfig();
|
|
1678
1678
|
if (themeConfig.properties.some((p) => p.id === property.id)) return {};
|
|
1679
1679
|
const updatedProperties = [...themeConfig.properties, property];
|
|
1680
|
-
const updatedVariants = themeConfig.variants.map(
|
|
1680
|
+
const updatedVariants = property.linkedTo ? themeConfig.variants : themeConfig.variants.map(
|
|
1681
1681
|
(v) => v.isDefault ? { ...v, values: { ...v.values, [property.id]: currentValue } } : v
|
|
1682
1682
|
);
|
|
1683
1683
|
const nextCanvas = {
|
|
@@ -1703,9 +1703,17 @@ const useEditorStore = create((set, get) => ({
|
|
|
1703
1703
|
removeThemeProperty: (propertyId) => set((state) => {
|
|
1704
1704
|
const themeConfig = state.canvas.themeConfig;
|
|
1705
1705
|
if (!themeConfig) return {};
|
|
1706
|
-
const
|
|
1706
|
+
const linkedChildren = themeConfig.properties.filter((p) => p.linkedTo === propertyId);
|
|
1707
|
+
const updatedProperties = themeConfig.properties.filter((p) => p.id !== propertyId).map((p) => p.linkedTo === propertyId ? { ...p, linkedTo: void 0 } : p);
|
|
1707
1708
|
const updatedVariants = themeConfig.variants.map((v) => {
|
|
1708
|
-
const { [propertyId]:
|
|
1709
|
+
const { [propertyId]: removedValue, ...rest } = v.values;
|
|
1710
|
+
if (linkedChildren.length && removedValue !== void 0) {
|
|
1711
|
+
const seeded = { ...rest };
|
|
1712
|
+
for (const child of linkedChildren) {
|
|
1713
|
+
if (seeded[child.id] === void 0) seeded[child.id] = removedValue;
|
|
1714
|
+
}
|
|
1715
|
+
return { ...v, values: seeded };
|
|
1716
|
+
}
|
|
1709
1717
|
return { ...v, values: rest };
|
|
1710
1718
|
});
|
|
1711
1719
|
const nextCanvas = {
|
|
@@ -1779,7 +1787,7 @@ const useEditorStore = create((set, get) => ({
|
|
|
1779
1787
|
const PAGE_BG_ID = "__pageBackground__";
|
|
1780
1788
|
let updatedPages = [...state.canvas.pages];
|
|
1781
1789
|
for (const prop of themeConfig.properties) {
|
|
1782
|
-
const value = variant.values[prop.id];
|
|
1790
|
+
const value = variant.values[prop.linkedTo ?? prop.id];
|
|
1783
1791
|
if (value === void 0) continue;
|
|
1784
1792
|
if (prop.elementId === PAGE_BG_ID) {
|
|
1785
1793
|
if (prop.targetProperty === "backgroundColor") {
|
|
@@ -2002,19 +2010,7 @@ const useEditorStore = create((set, get) => ({
|
|
|
2002
2010
|
} else {
|
|
2003
2011
|
newCollapsedSet.add(groupId);
|
|
2004
2012
|
}
|
|
2005
|
-
|
|
2006
|
-
let nextCanvas = state.canvas;
|
|
2007
|
-
const group = findNodeById(currentPage.children, groupId);
|
|
2008
|
-
if (group && isGroup(group)) {
|
|
2009
|
-
nextCanvas = updateCurrentPageChildren(
|
|
2010
|
-
nextCanvas,
|
|
2011
|
-
(children) => updateNodeInTree(children, groupId, { collapsed: !isCollapsed })
|
|
2012
|
-
);
|
|
2013
|
-
}
|
|
2014
|
-
return {
|
|
2015
|
-
collapsedGroups: newCollapsedSet,
|
|
2016
|
-
canvas: nextCanvas
|
|
2017
|
-
};
|
|
2013
|
+
return { collapsedGroups: newCollapsedSet };
|
|
2018
2014
|
}),
|
|
2019
2015
|
// Convenience aliases
|
|
2020
2016
|
groupElements: (ids, name) => get().groupNodes(ids, name),
|
|
@@ -10281,7 +10277,8 @@ function formDefSectionsToInferred(schemaSections, repeatableNodeMap) {
|
|
|
10281
10277
|
})),
|
|
10282
10278
|
// Honor minEntries: 0 — start with no entries, user adds via "+ Add" button.
|
|
10283
10279
|
initialEntryCount: minEntries,
|
|
10284
|
-
parentId
|
|
10280
|
+
parentId,
|
|
10281
|
+
entryNameFieldKey: def.entryNameFieldKey
|
|
10285
10282
|
};
|
|
10286
10283
|
if (treeNodeId) section.treeNodeId = treeNodeId;
|
|
10287
10284
|
sections.push(section);
|
|
@@ -10726,6 +10723,26 @@ function baseId(id) {
|
|
|
10726
10723
|
const REPEATABLE_KEY_REGEX = /^field_(.+)_(\d+)_(.+)$/;
|
|
10727
10724
|
const NESTED_REPEATABLE_KEY_REGEX = /^field_(.+)_(\d+)_field_(.+)_(\d+)_(.+)$/;
|
|
10728
10725
|
const FORMDEF_CANONICAL_KEY_REGEX = /^field_.+_N_.+$/;
|
|
10726
|
+
function parseEntryRange(range, max) {
|
|
10727
|
+
if (!range || !range.trim()) return null;
|
|
10728
|
+
const out = /* @__PURE__ */ new Set();
|
|
10729
|
+
for (const partRaw of range.split(",")) {
|
|
10730
|
+
const part = partRaw.trim();
|
|
10731
|
+
if (!part) continue;
|
|
10732
|
+
if (/^\d+$/.test(part)) {
|
|
10733
|
+
const n = parseInt(part, 10);
|
|
10734
|
+
if (n >= 1 && n <= max) out.add(n);
|
|
10735
|
+
continue;
|
|
10736
|
+
}
|
|
10737
|
+
const m = /^(\d*)\s*-\s*(\d*)$/.exec(part);
|
|
10738
|
+
if (!m) continue;
|
|
10739
|
+
const start = m[1] === "" ? 1 : Math.max(1, parseInt(m[1], 10));
|
|
10740
|
+
const end = m[2] === "" ? max : Math.min(max, parseInt(m[2], 10));
|
|
10741
|
+
for (let i = start; i <= end; i++) out.add(i);
|
|
10742
|
+
}
|
|
10743
|
+
if (out.size === 0) return null;
|
|
10744
|
+
return Array.from(out).sort((a, b) => a - b);
|
|
10745
|
+
}
|
|
10729
10746
|
function applyTextCase(text, textCase) {
|
|
10730
10747
|
if (!textCase || textCase === "none") return text;
|
|
10731
10748
|
switch (textCase) {
|
|
@@ -10804,13 +10821,19 @@ function findElementBySourceIdInSubtree(nodes, sourceId) {
|
|
|
10804
10821
|
}
|
|
10805
10822
|
return void 0;
|
|
10806
10823
|
}
|
|
10807
|
-
function
|
|
10824
|
+
function findAllRepeatableElementsBySourceId(pages, baseNodeId, oneBasedIndex, sourceElementId, expectedEntriesPerOccurrence) {
|
|
10808
10825
|
var _a;
|
|
10809
10826
|
const groups = collectGroupsByBaseId(pages, baseNodeId);
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10827
|
+
if (!groups.length) return [];
|
|
10828
|
+
const N = Math.max(1, expectedEntriesPerOccurrence ?? groups.length);
|
|
10829
|
+
const out = [];
|
|
10830
|
+
for (let occStart = 0; occStart < groups.length; occStart += N) {
|
|
10831
|
+
const group = groups[occStart + (oneBasedIndex - 1)];
|
|
10832
|
+
if (!group || !isGroup(group) || !((_a = group.children) == null ? void 0 : _a.length)) continue;
|
|
10833
|
+
const found = findElementBySourceIdInSubtree(group.children, sourceElementId) ?? (group.__sourceId === sourceElementId ? group.id : void 0);
|
|
10834
|
+
if (found) out.push(found);
|
|
10835
|
+
}
|
|
10836
|
+
return out;
|
|
10814
10837
|
}
|
|
10815
10838
|
function findNestedRepeatableElementBySourceId(pages, parentBaseNodeId, parentPi, childBaseNodeId, childCi, sourceElementId) {
|
|
10816
10839
|
var _a, _b;
|
|
@@ -10831,6 +10854,24 @@ function findNestedRepeatableElementBySourceId(pages, parentBaseNodeId, parentPi
|
|
|
10831
10854
|
if (!childGroup || !isGroup(childGroup) || !((_b = childGroup.children) == null ? void 0 : _b.length)) return void 0;
|
|
10832
10855
|
return findElementBySourceIdInSubtree(childGroup.children, sourceElementId) ?? (childGroup.__sourceId === sourceElementId ? childGroup.id : void 0);
|
|
10833
10856
|
}
|
|
10857
|
+
function repeatableLabelKey(label) {
|
|
10858
|
+
return String(label ?? "").trim().toLowerCase();
|
|
10859
|
+
}
|
|
10860
|
+
function repeatableLabelSlug(label) {
|
|
10861
|
+
return repeatableLabelKey(label).replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
10862
|
+
}
|
|
10863
|
+
function addToSetMap(map, key, value) {
|
|
10864
|
+
if (!key || !value) return;
|
|
10865
|
+
const set = map.get(key);
|
|
10866
|
+
if (set) set.add(value);
|
|
10867
|
+
else map.set(key, /* @__PURE__ */ new Set([value]));
|
|
10868
|
+
}
|
|
10869
|
+
function getFieldKeyAliases(fieldId) {
|
|
10870
|
+
const aliases = /* @__PURE__ */ new Set([fieldId]);
|
|
10871
|
+
const canonicalParts = fieldId.split("_N_");
|
|
10872
|
+
if (canonicalParts.length > 1) aliases.add(canonicalParts[canonicalParts.length - 1]);
|
|
10873
|
+
return Array.from(aliases).filter(Boolean);
|
|
10874
|
+
}
|
|
10834
10875
|
function idPrefix(node) {
|
|
10835
10876
|
if (isGroup(node)) return "group";
|
|
10836
10877
|
const t = node.type;
|
|
@@ -10884,7 +10925,7 @@ function findRepeatableByNodeIds(pages, nodeIds) {
|
|
|
10884
10925
|
var _a2;
|
|
10885
10926
|
return !!((_a2 = n.repeatableSection) == null ? void 0 : _a2.label);
|
|
10886
10927
|
};
|
|
10887
|
-
function walk(children, parentRepeatableBaseId, parentInfo) {
|
|
10928
|
+
function walk(children, parentRepeatableBaseId, parentInfo, parentRepeatableEntryIndex) {
|
|
10888
10929
|
var _a2, _b;
|
|
10889
10930
|
if (!Array.isArray(children)) return;
|
|
10890
10931
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -10898,7 +10939,7 @@ function findRepeatableByNodeIds(pages, nodeIds) {
|
|
|
10898
10939
|
const childBaseFromMeta = child.__baseNodeId;
|
|
10899
10940
|
const isMatch = schemaBaseIds.has(child.id) || schemaBaseIds.has(childBase) || childBaseFromMeta != null && schemaBaseIds.has(childBaseFromMeta);
|
|
10900
10941
|
if (!isMatch) {
|
|
10901
|
-
if (isGroup(child) && Array.isArray(child.children)) walk(child.children, parentRepeatableBaseId);
|
|
10942
|
+
if (isGroup(child) && Array.isArray(child.children)) walk(child.children, parentRepeatableBaseId, void 0, parentRepeatableEntryIndex);
|
|
10902
10943
|
j++;
|
|
10903
10944
|
continue;
|
|
10904
10945
|
}
|
|
@@ -10921,17 +10962,22 @@ function findRepeatableByNodeIds(pages, nodeIds) {
|
|
|
10921
10962
|
count,
|
|
10922
10963
|
node: child,
|
|
10923
10964
|
baseNodeId: childBaseFromMeta ?? childBase,
|
|
10924
|
-
parentBaseNodeId: parentRepeatableBaseId
|
|
10965
|
+
parentBaseNodeId: parentRepeatableBaseId,
|
|
10966
|
+
parentEntryIndex: parentRepeatableEntryIndex
|
|
10925
10967
|
});
|
|
10926
|
-
|
|
10968
|
+
const childEntryIndex = child.__repeatableEntryIndex;
|
|
10969
|
+
if (isGroup(child) && Array.isArray(child.children)) walk(child.children, effectiveChildBase, void 0, childEntryIndex);
|
|
10927
10970
|
j += count;
|
|
10928
10971
|
}
|
|
10929
10972
|
} else if (isGroup(node) && ((_b = node.children) == null ? void 0 : _b.length)) {
|
|
10930
10973
|
const nodeBase = baseId(node.id);
|
|
10931
10974
|
const selfMatch = schemaBaseIds.has(node.id) || schemaBaseIds.has(nodeBase) || node.__baseNodeId != null && schemaBaseIds.has(node.__baseNodeId);
|
|
10932
|
-
|
|
10975
|
+
const isSelfRepeatable = selfMatch && hasRepeatableSection(node);
|
|
10976
|
+
let matchedSelfBase;
|
|
10977
|
+
if (selfMatch) matchedSelfBase = node.__baseNodeId ?? nodeBase;
|
|
10978
|
+
if (isSelfRepeatable) {
|
|
10933
10979
|
let count = 1;
|
|
10934
|
-
const effectiveBase =
|
|
10980
|
+
const effectiveBase = matchedSelfBase ?? nodeBase;
|
|
10935
10981
|
if (node.id !== nodeBase && node.id !== effectiveBase) {
|
|
10936
10982
|
while (i + count < children.length) {
|
|
10937
10983
|
const next = children[i + count];
|
|
@@ -10948,10 +10994,12 @@ function findRepeatableByNodeIds(pages, nodeIds) {
|
|
|
10948
10994
|
count,
|
|
10949
10995
|
node,
|
|
10950
10996
|
baseNodeId: effectiveBase,
|
|
10951
|
-
parentBaseNodeId: parentRepeatableBaseId
|
|
10997
|
+
parentBaseNodeId: parentRepeatableBaseId,
|
|
10998
|
+
parentEntryIndex: parentRepeatableEntryIndex
|
|
10952
10999
|
});
|
|
10953
11000
|
}
|
|
10954
|
-
|
|
11001
|
+
const nodeEntryIndex = node.__repeatableEntryIndex;
|
|
11002
|
+
walk(node.children, matchedSelfBase ?? parentRepeatableBaseId, void 0, nodeEntryIndex ?? parentRepeatableEntryIndex);
|
|
10955
11003
|
}
|
|
10956
11004
|
}
|
|
10957
11005
|
}
|
|
@@ -11010,7 +11058,7 @@ function getNestedRepeatableEntryCount(parentId, parentIndex, childId, formValue
|
|
|
11010
11058
|
return Math.max(1, maxIndex);
|
|
11011
11059
|
}
|
|
11012
11060
|
function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsFromSchema, repeatableEntryCounts, repeatableNestedEntryCounts, displayFormatMap, repeatablePagesFromSchema) {
|
|
11013
|
-
var _a, _b, _c
|
|
11061
|
+
var _a, _b, _c;
|
|
11014
11062
|
const cloned = JSON.parse(JSON.stringify(config));
|
|
11015
11063
|
if (!cloned.pages) return cloned;
|
|
11016
11064
|
const dynamicFields = cloned.dynamicFields;
|
|
@@ -11060,17 +11108,56 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11060
11108
|
}
|
|
11061
11109
|
const repeatableList = (repeatableSectionsFromSchema == null ? void 0 : repeatableSectionsFromSchema.length) ? repeatableSectionsFromSchema : getRepeatableFromConfig(pages);
|
|
11062
11110
|
const nodeIds = repeatableList.map((r) => r.nodeId);
|
|
11111
|
+
const repeatableBasesByLabel = /* @__PURE__ */ new Map();
|
|
11112
|
+
for (const r of repeatableList) {
|
|
11113
|
+
const base = baseId(r.nodeId);
|
|
11114
|
+
addToSetMap(repeatableBasesByLabel, repeatableLabelKey(r.label), base);
|
|
11115
|
+
addToSetMap(repeatableBasesByLabel, repeatableLabelSlug(r.label), base);
|
|
11116
|
+
}
|
|
11117
|
+
const repeatableTokenToBaseIds = /* @__PURE__ */ new Map();
|
|
11118
|
+
for (const r of repeatableList) {
|
|
11119
|
+
const base = baseId(r.nodeId);
|
|
11120
|
+
const labelBases = /* @__PURE__ */ new Set([
|
|
11121
|
+
base,
|
|
11122
|
+
...repeatableBasesByLabel.get(repeatableLabelKey(r.label)) ?? [],
|
|
11123
|
+
...repeatableBasesByLabel.get(repeatableLabelSlug(r.label)) ?? []
|
|
11124
|
+
]);
|
|
11125
|
+
for (const targetBase of labelBases) {
|
|
11126
|
+
addToSetMap(repeatableTokenToBaseIds, base, targetBase);
|
|
11127
|
+
addToSetMap(repeatableTokenToBaseIds, r.nodeId, targetBase);
|
|
11128
|
+
addToSetMap(repeatableTokenToBaseIds, repeatableLabelKey(r.label), targetBase);
|
|
11129
|
+
addToSetMap(repeatableTokenToBaseIds, repeatableLabelSlug(r.label), targetBase);
|
|
11130
|
+
}
|
|
11131
|
+
}
|
|
11132
|
+
const getRepeatableBaseIdsForToken = (token) => {
|
|
11133
|
+
const direct = repeatableTokenToBaseIds.get(token) ?? repeatableTokenToBaseIds.get(baseId(token));
|
|
11134
|
+
return direct ? Array.from(direct) : [baseId(token)];
|
|
11135
|
+
};
|
|
11063
11136
|
const entryCountFromList = (baseNodeId) => {
|
|
11064
11137
|
const item = repeatableList.find((r) => baseId(r.nodeId) === baseNodeId || r.nodeId === baseNodeId);
|
|
11065
11138
|
return item == null ? void 0 : item.entryCount;
|
|
11066
11139
|
};
|
|
11140
|
+
const entryFilterFromList = (baseNodeId) => {
|
|
11141
|
+
var _a2;
|
|
11142
|
+
const item = repeatableList.find((r) => baseId(r.nodeId) === baseNodeId || r.nodeId === baseNodeId);
|
|
11143
|
+
const filter = item == null ? void 0 : item.entryFilter;
|
|
11144
|
+
return (filter == null ? void 0 : filter.mode) === "range" && ((_a2 = filter.range) == null ? void 0 : _a2.trim()) ? filter : void 0;
|
|
11145
|
+
};
|
|
11067
11146
|
const resolvedIdMap = /* @__PURE__ */ new Map();
|
|
11147
|
+
const addResolved = (key, id) => {
|
|
11148
|
+
const arr = resolvedIdMap.get(key);
|
|
11149
|
+
if (arr) {
|
|
11150
|
+
if (!arr.includes(id)) arr.push(id);
|
|
11151
|
+
} else resolvedIdMap.set(key, [id]);
|
|
11152
|
+
};
|
|
11068
11153
|
const mappedNewIds = /* @__PURE__ */ new Set();
|
|
11069
11154
|
const elementIdToFieldId = /* @__PURE__ */ new Map();
|
|
11070
11155
|
if (dynamicFields == null ? void 0 : dynamicFields.length) {
|
|
11071
11156
|
for (const f of dynamicFields) {
|
|
11072
|
-
|
|
11073
|
-
|
|
11157
|
+
for (const m of f.mappings ?? []) {
|
|
11158
|
+
const elId = m == null ? void 0 : m.elementId;
|
|
11159
|
+
if (elId) elementIdToFieldId.set(elId, f.id);
|
|
11160
|
+
}
|
|
11074
11161
|
}
|
|
11075
11162
|
}
|
|
11076
11163
|
const repeatableInfosFirst = findRepeatableByNodeIds(pages, nodeIds);
|
|
@@ -11083,37 +11170,90 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11083
11170
|
for (const r of nestedFirst) {
|
|
11084
11171
|
if (r.parentBaseNodeId) nestedChildToParent.set(r.baseNodeId, r.parentBaseNodeId);
|
|
11085
11172
|
}
|
|
11173
|
+
const getNestedBasePairs = (parentToken, childToken) => {
|
|
11174
|
+
const pairs = [];
|
|
11175
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11176
|
+
for (const parentBaseId of getRepeatableBaseIdsForToken(parentToken)) {
|
|
11177
|
+
for (const childBaseId of getRepeatableBaseIdsForToken(childToken)) {
|
|
11178
|
+
const key = `${parentBaseId}::${childBaseId}`;
|
|
11179
|
+
if (seen.has(key)) continue;
|
|
11180
|
+
seen.add(key);
|
|
11181
|
+
pairs.push({ parentBaseId, childBaseId });
|
|
11182
|
+
}
|
|
11183
|
+
}
|
|
11184
|
+
return pairs.length ? pairs : [{ parentBaseId: baseId(parentToken), childBaseId: baseId(childToken) }];
|
|
11185
|
+
};
|
|
11186
|
+
const getNestedCountForBasePair = (parentBaseNodeId, parentIndex1Based, childBaseNodeId) => {
|
|
11187
|
+
let maxCount = 0;
|
|
11188
|
+
for (const { parentBaseId, childBaseId } of getNestedBasePairs(parentBaseNodeId, childBaseNodeId)) {
|
|
11189
|
+
const aliasKey = `${parentBaseId}_${parentIndex1Based}_${childBaseId}`;
|
|
11190
|
+
maxCount = Math.max(
|
|
11191
|
+
maxCount,
|
|
11192
|
+
(repeatableNestedEntryCounts == null ? void 0 : repeatableNestedEntryCounts[aliasKey]) ?? 0,
|
|
11193
|
+
getNestedRepeatableEntryCount(parentBaseId, parentIndex1Based, childBaseId, formValues)
|
|
11194
|
+
);
|
|
11195
|
+
}
|
|
11196
|
+
return Math.max(1, maxCount);
|
|
11197
|
+
};
|
|
11086
11198
|
const phase1NewToOriginal = /* @__PURE__ */ new Map();
|
|
11087
|
-
const
|
|
11199
|
+
const entryCountByBase = /* @__PURE__ */ new Map();
|
|
11200
|
+
[...topLevel].sort((a, b) => {
|
|
11201
|
+
if (a.parentChildren !== b.parentChildren) return 0;
|
|
11202
|
+
return b.startIndex - a.startIndex;
|
|
11203
|
+
});
|
|
11204
|
+
const occByParent = /* @__PURE__ */ new Map();
|
|
11088
11205
|
for (const r of topLevel) {
|
|
11089
|
-
if (!
|
|
11090
|
-
|
|
11091
|
-
}
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
const startIndex = Math.min(...blocks.map((b) => b.startIndex));
|
|
11095
|
-
const endIndex = Math.max(...blocks.map((b) => b.startIndex + b.count));
|
|
11096
|
-
const count = endIndex - startIndex;
|
|
11097
|
-
const { parentChildren, node, baseNodeId } = first;
|
|
11206
|
+
if (!occByParent.has(r.parentChildren)) occByParent.set(r.parentChildren, []);
|
|
11207
|
+
occByParent.get(r.parentChildren).push(r);
|
|
11208
|
+
}
|
|
11209
|
+
const computeN = (baseNodeId, sampleNodeId) => {
|
|
11210
|
+
if (entryCountByBase.has(baseNodeId)) return entryCountByBase.get(baseNodeId);
|
|
11098
11211
|
const countFromList = entryCountFromList(baseNodeId);
|
|
11099
|
-
const countFromState = countFromList ?? (repeatableEntryCounts == null ? void 0 : repeatableEntryCounts[baseNodeId]) ?? (repeatableEntryCounts == null ? void 0 : repeatableEntryCounts[
|
|
11212
|
+
const countFromState = countFromList ?? (repeatableEntryCounts == null ? void 0 : repeatableEntryCounts[baseNodeId]) ?? (repeatableEntryCounts == null ? void 0 : repeatableEntryCounts[sampleNodeId]) ?? repeatableEntryCounts;
|
|
11100
11213
|
const N = Math.max(1, countFromState ?? getRepeatableEntryCount(baseNodeId, formValues));
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11109
|
-
|
|
11110
|
-
|
|
11111
|
-
|
|
11112
|
-
|
|
11113
|
-
}
|
|
11114
|
-
|
|
11115
|
-
|
|
11116
|
-
|
|
11214
|
+
entryCountByBase.set(baseNodeId, N);
|
|
11215
|
+
return N;
|
|
11216
|
+
};
|
|
11217
|
+
const occurrenceIndexByBase = /* @__PURE__ */ new Map();
|
|
11218
|
+
for (const r of topLevel) {
|
|
11219
|
+
const idx = (occurrenceIndexByBase.get(r.baseNodeId) ?? 0) + 1;
|
|
11220
|
+
occurrenceIndexByBase.set(r.baseNodeId, idx);
|
|
11221
|
+
r.__occurrenceIndex = idx;
|
|
11222
|
+
}
|
|
11223
|
+
for (const [parentChildren, blocks] of occByParent) {
|
|
11224
|
+
const sorted = [...blocks].sort((a, b) => b.startIndex - a.startIndex);
|
|
11225
|
+
for (const block of sorted) {
|
|
11226
|
+
const { node, baseNodeId, startIndex, count } = block;
|
|
11227
|
+
const occIdx = block.__occurrenceIndex ?? 1;
|
|
11228
|
+
const N = computeN(baseNodeId, node.id);
|
|
11229
|
+
const entryFilter = ((_b = node.repeatableSection) == null ? void 0 : _b.entryFilter) ?? entryFilterFromList(baseNodeId);
|
|
11230
|
+
let entryIndices;
|
|
11231
|
+
if (entryFilter && entryFilter.mode === "range" && entryFilter.range) {
|
|
11232
|
+
const parsed = parseEntryRange(entryFilter.range, N);
|
|
11233
|
+
entryIndices = parsed && parsed.length ? parsed : Array.from({ length: N }, (_, k) => k + 1);
|
|
11234
|
+
} else {
|
|
11235
|
+
entryIndices = Array.from({ length: N }, (_, k) => k + 1);
|
|
11236
|
+
}
|
|
11237
|
+
const clones = [];
|
|
11238
|
+
for (const i of entryIndices) {
|
|
11239
|
+
const [clone, oldToNew] = cloneNodeWithNewIds$1(node, `${baseNodeId}_o${occIdx}_e${i}`);
|
|
11240
|
+
clone.__repeatableEntryIndex = i;
|
|
11241
|
+
delete clone.repeatableSection;
|
|
11242
|
+
clones.push(clone);
|
|
11243
|
+
const newToOriginal = /* @__PURE__ */ new Map();
|
|
11244
|
+
for (const [oldId, newId] of oldToNew) {
|
|
11245
|
+
addResolved(`${baseNodeId}_${i}_${oldId}`, newId);
|
|
11246
|
+
newToOriginal.set(newId, oldId);
|
|
11247
|
+
const fieldId = elementIdToFieldId.get(oldId);
|
|
11248
|
+
if (fieldId) {
|
|
11249
|
+
for (const alias of getFieldKeyAliases(fieldId)) addResolved(`${baseNodeId}_${i}_${alias}`, newId);
|
|
11250
|
+
}
|
|
11251
|
+
mappedNewIds.add(newId);
|
|
11252
|
+
}
|
|
11253
|
+
phase1NewToOriginal.set(`${baseNodeId}_${i}`, newToOriginal);
|
|
11254
|
+
}
|
|
11255
|
+
parentChildren.splice(startIndex, count, ...clones);
|
|
11256
|
+
}
|
|
11117
11257
|
}
|
|
11118
11258
|
if (nestedChildToParent.size > 0) {
|
|
11119
11259
|
const repeatableInfosSecond = findRepeatableByNodeIds(pages, nodeIds);
|
|
@@ -11126,25 +11266,41 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11126
11266
|
for (const [childBaseNodeId, blocks] of byChildBase) {
|
|
11127
11267
|
const parentBaseNodeId = nestedChildToParent.get(childBaseNodeId);
|
|
11128
11268
|
blocks.forEach((block, parentIndex0) => {
|
|
11129
|
-
|
|
11269
|
+
var _a2;
|
|
11270
|
+
const parentIndex1Based = block.parentEntryIndex ?? parentIndex0 + 1;
|
|
11130
11271
|
const { parentChildren, startIndex, count, node, baseNodeId } = block;
|
|
11131
|
-
const
|
|
11132
|
-
const N = Math.max(
|
|
11133
|
-
1,
|
|
11134
|
-
(repeatableNestedEntryCounts == null ? void 0 : repeatableNestedEntryCounts[nestedKey]) ?? getNestedRepeatableEntryCount(parentBaseNodeId, parentIndex1Based, baseNodeId, formValues)
|
|
11135
|
-
);
|
|
11272
|
+
const N = getNestedCountForBasePair(parentBaseNodeId, parentIndex1Based, baseNodeId);
|
|
11136
11273
|
const phase1Map = phase1NewToOriginal.get(`${parentBaseNodeId}_${parentIndex1Based}`);
|
|
11274
|
+
const nestedEntryFilter = ((_a2 = node.repeatableSection) == null ? void 0 : _a2.entryFilter) ?? entryFilterFromList(baseNodeId);
|
|
11275
|
+
let nestedEntryIndices;
|
|
11276
|
+
if (nestedEntryFilter && nestedEntryFilter.mode === "range" && nestedEntryFilter.range) {
|
|
11277
|
+
const parsed = parseEntryRange(nestedEntryFilter.range, N);
|
|
11278
|
+
nestedEntryIndices = parsed && parsed.length ? parsed : Array.from({ length: N }, (_, k) => k + 1);
|
|
11279
|
+
} else {
|
|
11280
|
+
nestedEntryIndices = Array.from({ length: N }, (_, k) => k + 1);
|
|
11281
|
+
}
|
|
11137
11282
|
const clones = [];
|
|
11138
|
-
for (
|
|
11283
|
+
for (const i of nestedEntryIndices) {
|
|
11139
11284
|
const [clone, oldToNew] = cloneNodeWithNewIds$1(node, `${parentBaseNodeId}_p${parentIndex1Based}_${baseNodeId}_e${i}`);
|
|
11140
11285
|
delete clone.repeatableSection;
|
|
11141
11286
|
clones.push(clone);
|
|
11142
11287
|
for (const [oldId, newId] of oldToNew) {
|
|
11143
11288
|
const originalId = (phase1Map == null ? void 0 : phase1Map.get(oldId)) ?? oldId;
|
|
11144
|
-
|
|
11145
|
-
|
|
11289
|
+
addResolved(`${parentBaseNodeId}_${parentIndex1Based}_${baseNodeId}_${i}_${originalId}`, newId);
|
|
11290
|
+
addResolved(`${parentBaseNodeId}_${parentIndex1Based}_${baseNodeId}_${i}_${oldId}`, newId);
|
|
11291
|
+
for (const { parentBaseId, childBaseId } of getNestedBasePairs(parentBaseNodeId, baseNodeId)) {
|
|
11292
|
+
addResolved(`${parentBaseId}_${parentIndex1Based}_${childBaseId}_${i}_${originalId}`, newId);
|
|
11293
|
+
addResolved(`${parentBaseId}_${parentIndex1Based}_${childBaseId}_${i}_${oldId}`, newId);
|
|
11294
|
+
}
|
|
11146
11295
|
const fieldId = elementIdToFieldId.get(originalId) ?? elementIdToFieldId.get(oldId);
|
|
11147
|
-
if (fieldId)
|
|
11296
|
+
if (fieldId) {
|
|
11297
|
+
for (const alias of getFieldKeyAliases(fieldId)) {
|
|
11298
|
+
addResolved(`${parentBaseNodeId}_${parentIndex1Based}_${baseNodeId}_${i}_${alias}`, newId);
|
|
11299
|
+
for (const { parentBaseId, childBaseId } of getNestedBasePairs(parentBaseNodeId, baseNodeId)) {
|
|
11300
|
+
addResolved(`${parentBaseId}_${parentIndex1Based}_${childBaseId}_${i}_${alias}`, newId);
|
|
11301
|
+
}
|
|
11302
|
+
}
|
|
11303
|
+
}
|
|
11148
11304
|
mappedNewIds.add(newId);
|
|
11149
11305
|
}
|
|
11150
11306
|
}
|
|
@@ -11152,7 +11308,9 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11152
11308
|
});
|
|
11153
11309
|
}
|
|
11154
11310
|
}
|
|
11155
|
-
cloned.__cloneIdMap = Object.fromEntries(
|
|
11311
|
+
cloned.__cloneIdMap = Object.fromEntries(
|
|
11312
|
+
Array.from(resolvedIdMap.entries()).map(([k, v]) => [k, v.length === 1 ? v[0] : v])
|
|
11313
|
+
);
|
|
11156
11314
|
cloned.__mappedElementIds = Array.from(mappedNewIds);
|
|
11157
11315
|
const fieldLabelByKey = /* @__PURE__ */ new Map();
|
|
11158
11316
|
const fieldTypeByKey = /* @__PURE__ */ new Map();
|
|
@@ -11295,10 +11453,7 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11295
11453
|
}
|
|
11296
11454
|
const byId = dynamicFields.find((f) => f.id === fieldId);
|
|
11297
11455
|
if (byId) return byId;
|
|
11298
|
-
const byElementId = dynamicFields.find((f) =>
|
|
11299
|
-
var _a2, _b2;
|
|
11300
|
-
return ((_b2 = (_a2 = f.mappings) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.elementId) === fieldId;
|
|
11301
|
-
});
|
|
11456
|
+
const byElementId = dynamicFields.find((f) => (f.mappings ?? []).some((m) => (m == null ? void 0 : m.elementId) === fieldId));
|
|
11302
11457
|
if (byElementId) return byElementId;
|
|
11303
11458
|
const suffixMatch = dynamicFields.find((f) => {
|
|
11304
11459
|
if (f.id.endsWith(`_N_${fieldId}`)) return true;
|
|
@@ -11314,39 +11469,36 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11314
11469
|
const [, parentId, parentIndexStr, childId, childIndexStr, fieldId] = nestedMatch;
|
|
11315
11470
|
const value = formValues[key];
|
|
11316
11471
|
const field = getFieldForRepeatableKey(fieldId, key);
|
|
11317
|
-
const mapping
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11322
|
-
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
);
|
|
11472
|
+
for (const mapping of (field == null ? void 0 : field.mappings) ?? []) {
|
|
11473
|
+
const oldElementId = mapping.elementId;
|
|
11474
|
+
const mapKeyByElement = `${baseId(parentId)}_${parentIndexStr}_${baseId(childId)}_${childIndexStr}_${oldElementId}`;
|
|
11475
|
+
let elementIds = resolvedIdMap.get(mapKeyByElement);
|
|
11476
|
+
if (!elementIds || elementIds.length === 0) {
|
|
11477
|
+
const mapKeyByElementBase = `${baseId(parentId)}_${parentIndexStr}_${baseId(childId)}_${childIndexStr}_${baseId(oldElementId)}`;
|
|
11478
|
+
elementIds = resolvedIdMap.get(mapKeyByElementBase);
|
|
11479
|
+
}
|
|
11480
|
+
if (!elementIds || elementIds.length === 0) {
|
|
11481
|
+
const fallback = findNestedRepeatableElementBySourceId(
|
|
11482
|
+
pages,
|
|
11483
|
+
baseId(parentId),
|
|
11484
|
+
parseInt(parentIndexStr, 10),
|
|
11485
|
+
baseId(childId),
|
|
11486
|
+
parseInt(childIndexStr, 10),
|
|
11487
|
+
oldElementId
|
|
11488
|
+
) ?? findNestedRepeatableElementBySourceId(
|
|
11489
|
+
pages,
|
|
11490
|
+
baseId(parentId),
|
|
11491
|
+
parseInt(parentIndexStr, 10),
|
|
11492
|
+
baseId(childId),
|
|
11493
|
+
parseInt(childIndexStr, 10),
|
|
11494
|
+
baseId(oldElementId)
|
|
11495
|
+
);
|
|
11496
|
+
if (fallback) elementIds = [fallback];
|
|
11497
|
+
}
|
|
11498
|
+
if (!elementIds || elementIds.length === 0) continue;
|
|
11499
|
+
const targetProperty = mapping.targetProperty || "text";
|
|
11500
|
+
for (const elementId of elementIds) applyValue(elementId, targetProperty, value, key);
|
|
11346
11501
|
}
|
|
11347
|
-
if (!elementId) continue;
|
|
11348
|
-
const targetProperty = mapping.targetProperty || "text";
|
|
11349
|
-
applyValue(elementId, targetProperty, value, key);
|
|
11350
11502
|
}
|
|
11351
11503
|
}
|
|
11352
11504
|
}
|
|
@@ -11369,18 +11521,29 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11369
11521
|
const [, nodeId, indexStr, fieldId] = match;
|
|
11370
11522
|
const value = formValues[key];
|
|
11371
11523
|
const field = getFieldForRepeatableKey(fieldId);
|
|
11372
|
-
const mapping
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11524
|
+
for (const mapping of (field == null ? void 0 : field.mappings) ?? []) {
|
|
11525
|
+
const oldElementId = mapping.elementId;
|
|
11526
|
+
const elementIds = /* @__PURE__ */ new Set();
|
|
11527
|
+
for (const candidateBaseId of getRepeatableBaseIdsForToken(nodeId)) {
|
|
11528
|
+
const mapKeyByElement = `${candidateBaseId}_${indexStr}_${oldElementId}`;
|
|
11529
|
+
const foundByMap = resolvedIdMap.get(mapKeyByElement);
|
|
11530
|
+
for (const id of foundByMap ?? []) elementIds.add(id);
|
|
11531
|
+
if (!(foundByMap == null ? void 0 : foundByMap.length)) {
|
|
11532
|
+
const N = entryCountByBase.get(candidateBaseId);
|
|
11533
|
+
const found = findAllRepeatableElementsBySourceId(
|
|
11534
|
+
pages,
|
|
11535
|
+
candidateBaseId,
|
|
11536
|
+
parseInt(indexStr, 10),
|
|
11537
|
+
oldElementId,
|
|
11538
|
+
N
|
|
11539
|
+
);
|
|
11540
|
+
for (const id of found) elementIds.add(id);
|
|
11541
|
+
}
|
|
11542
|
+
}
|
|
11543
|
+
if (elementIds.size === 0) continue;
|
|
11544
|
+
const targetProperty = mapping.targetProperty || "text";
|
|
11545
|
+
for (const elementId of elementIds) applyValue(elementId, targetProperty, value, key);
|
|
11380
11546
|
}
|
|
11381
|
-
if (!elementId) continue;
|
|
11382
|
-
const targetProperty = mapping.targetProperty || "text";
|
|
11383
|
-
applyValue(elementId, targetProperty, value, key);
|
|
11384
11547
|
}
|
|
11385
11548
|
}
|
|
11386
11549
|
const repeatableKeySet = new Set(
|
|
@@ -11433,7 +11596,7 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11433
11596
|
}
|
|
11434
11597
|
}
|
|
11435
11598
|
for (const page of pages) {
|
|
11436
|
-
if ((
|
|
11599
|
+
if ((_c = page.children) == null ? void 0 : _c.length) {
|
|
11437
11600
|
page.children = applyStackReflowToPageTree(page.children);
|
|
11438
11601
|
}
|
|
11439
11602
|
}
|
|
@@ -12391,7 +12554,8 @@ function applyThemeVariantToConfig(config, themeConfig, themeId) {
|
|
|
12391
12554
|
const cloneIdMap = config.__cloneIdMap || {};
|
|
12392
12555
|
const pageElements = result.pages.map((page) => flattenAll(page.children || []));
|
|
12393
12556
|
for (const prop of themeConfig.properties) {
|
|
12394
|
-
const
|
|
12557
|
+
const lookupId = prop.linkedTo || prop.id;
|
|
12558
|
+
const value = variant ? (_d = variant.values) == null ? void 0 : _d[lookupId] : prop.defaultValue;
|
|
12395
12559
|
if (value === void 0) continue;
|
|
12396
12560
|
if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
|
|
12397
12561
|
result.pages.forEach((p) => {
|