@open-mercato/ui 0.6.2-develop.3381.1.8461b312a9 → 0.6.2-develop.3400.2.d948268f50

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.
@@ -102,6 +102,10 @@ const CRUDFORM_EXTENDED_EVENTS_ENABLED = parseBooleanWithDefault(
102
102
  process.env.NEXT_PUBLIC_OM_CRUDFORM_EXTENDED_EVENTS_ENABLED,
103
103
  true
104
104
  );
105
+ function evaluateFieldVisibility(visibleWhen, values) {
106
+ if (!visibleWhen) return true;
107
+ return values[visibleWhen.field] === visibleWhen.equals;
108
+ }
105
109
  function isFormControlTarget(target) {
106
110
  if (!target || typeof target.tagName !== "string") return false;
107
111
  const el = target;
@@ -750,7 +754,7 @@ function CrudForm({
750
754
  setIsInDialog(Boolean(root.closest("[data-dialog-content]")));
751
755
  }, []);
752
756
  const dialogFooterClass = isInDialog ? "sticky bottom-0 left-0 right-0 z-20 -mx-6 px-6 bg-card border-t border-border/70 py-2 sm:-mx-6 sm:px-6" : "";
753
- const dialogFormPadding = isInDialog ? "pb-4" : "";
757
+ const dialogFormPadding = isInDialog ? "pb-20" : "";
754
758
  const buildCustomFieldsManageHref = React.useCallback(
755
759
  (targetEntityId) => {
756
760
  if (!targetEntityId) return null;
@@ -1168,6 +1172,16 @@ function CrudForm({
1168
1172
  record: recordValues
1169
1173
  };
1170
1174
  }, [values]);
1175
+ const hiddenBaseFieldIds = React.useMemo(() => {
1176
+ const hidden = /* @__PURE__ */ new Set();
1177
+ const recordValues = values;
1178
+ for (const field of fields) {
1179
+ if (!evaluateFieldVisibility(field.visibleWhen, recordValues)) {
1180
+ hidden.add(field.id);
1181
+ }
1182
+ }
1183
+ return hidden;
1184
+ }, [fields, values]);
1171
1185
  const hiddenInjectedFieldIds = React.useMemo(() => {
1172
1186
  const hidden = /* @__PURE__ */ new Set();
1173
1187
  for (const definition of injectedFieldDefinitions) {
@@ -1226,7 +1240,7 @@ function CrudForm({
1226
1240
  if (formReadOnly) return;
1227
1241
  const field = fieldById.get(fieldId);
1228
1242
  if (!field || field.disabled) return;
1229
- if (hiddenInjectedFieldIds.has(fieldId)) return;
1243
+ if (hiddenBaseFieldIds.has(fieldId) || hiddenInjectedFieldIds.has(fieldId)) return;
1230
1244
  const nextValues = sourceValues ?? valuesRef.current;
1231
1245
  const nextFieldErrors = {};
1232
1246
  const requiredMessage = t("ui.forms.errors.required");
@@ -1303,6 +1317,7 @@ function CrudForm({
1303
1317
  customEntity,
1304
1318
  fieldById,
1305
1319
  formReadOnly,
1320
+ hiddenBaseFieldIds,
1306
1321
  hiddenInjectedFieldIds,
1307
1322
  injectedFieldIdSet,
1308
1323
  mapDefsForValidation,
@@ -1781,7 +1796,7 @@ function CrudForm({
1781
1796
  for (const field of allFields) {
1782
1797
  if (!field.required) continue;
1783
1798
  if (field.disabled) continue;
1784
- if (hiddenInjectedFieldIds.has(field.id)) continue;
1799
+ if (hiddenBaseFieldIds.has(field.id) || hiddenInjectedFieldIds.has(field.id)) continue;
1785
1800
  const v = values[field.id];
1786
1801
  const isArray = Array.isArray(v);
1787
1802
  const isString = typeof v === "string";
@@ -2610,6 +2625,7 @@ function CrudForm({
2610
2625
  }
2611
2626
  ) : null,
2612
2627
  /* @__PURE__ */ jsx("div", { className: grid, children: allFields.map((f) => {
2628
+ if (hiddenBaseFieldIds.has(f.id) || hiddenInjectedFieldIds.has(f.id)) return null;
2613
2629
  const layout = f.layout ?? "full";
2614
2630
  const wrapperClassName = usesResponsiveLayout ? resolveLayoutClass(layout) : void 0;
2615
2631
  return /* @__PURE__ */ jsx(