@open-mercato/ui 0.5.1-develop.2935.357c9db339 → 0.5.1-develop.2949.009dcdd2d5

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.
@@ -154,6 +154,16 @@ function readByDotPath(source, path) {
154
154
  }
155
155
  return current;
156
156
  }
157
+ function readInitialCustomFieldValue(source, key) {
158
+ if (!source || !key) return void 0;
159
+ const candidates = [`cf_${key}`, `cf:${key}`, key];
160
+ for (const candidate of candidates) {
161
+ if (Object.prototype.hasOwnProperty.call(source, candidate)) {
162
+ return source[candidate];
163
+ }
164
+ }
165
+ return void 0;
166
+ }
157
167
  function serializeIssuePath(path) {
158
168
  if (!Array.isArray(path) || path.length === 0) return null;
159
169
  const segments = path.map((segment) => {
@@ -1577,20 +1587,34 @@ function CrudForm({
1577
1587
  const dirtyBaselineSnapshotRef = React.useRef(void 0);
1578
1588
  React.useLayoutEffect(() => {
1579
1589
  if (!initialValues) return;
1580
- const snapshot = JSON.stringify(initialValues);
1590
+ const snapshot = JSON.stringify({
1591
+ initialValues,
1592
+ injectedFieldIds: injectedFieldDefinitions.map((definition) => definition.id),
1593
+ customFieldMappings: cfDefinitions.map((definition) => definition.key)
1594
+ });
1581
1595
  if (appliedInitialValuesSnapshotRef.current === snapshot) return;
1582
1596
  appliedInitialValuesSnapshotRef.current = snapshot;
1597
+ const initialRecord = initialValues;
1583
1598
  let mergedValues = null;
1584
1599
  setValues((prev) => {
1585
1600
  const merged = { ...prev, ...initialValues };
1586
1601
  for (const definition of injectedFieldDefinitions) {
1587
1602
  if (merged[definition.id] !== void 0) continue;
1588
- const extracted = readByDotPath(initialValues, definition.id);
1603
+ const extracted = readByDotPath(initialRecord, definition.id);
1589
1604
  if (extracted !== void 0) {
1590
1605
  ;
1591
1606
  merged[definition.id] = extracted;
1592
1607
  }
1593
1608
  }
1609
+ for (const definition of cfDefinitions) {
1610
+ const targetId = customEntity ? definition.key : `cf_${definition.key}`;
1611
+ if (!targetId || merged[targetId] !== void 0) continue;
1612
+ const extracted = readInitialCustomFieldValue(initialRecord, definition.key);
1613
+ if (extracted !== void 0) {
1614
+ ;
1615
+ merged[targetId] = extracted;
1616
+ }
1617
+ }
1594
1618
  mergedValues = merged;
1595
1619
  return mergedValues;
1596
1620
  });
@@ -1618,7 +1642,14 @@ function CrudForm({
1618
1642
  return () => {
1619
1643
  cancelled = true;
1620
1644
  };
1621
- }, [extendedInjectionEventsEnabled, initialValues, injectedFieldDefinitions, triggerInjectionEvent]);
1645
+ }, [
1646
+ cfDefinitions,
1647
+ customEntity,
1648
+ extendedInjectionEventsEnabled,
1649
+ initialValues,
1650
+ injectedFieldDefinitions,
1651
+ triggerInjectionEvent
1652
+ ]);
1622
1653
  const cfDefaultsAppliedRef = React.useRef(false);
1623
1654
  const initialValuesHasId = React.useMemo(() => {
1624
1655
  if (!initialValues) return false;