pcm-shared-components 2.1.392 → 2.1.393
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { TextField, Icon, IconButton, Button, Paper, Typography, InputAdornment, MenuItem, ToggleButton, ToggleButtonGroup, Checkbox, ListItemText, Chip, Alert, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions } from '@mui/material';
|
|
4
4
|
import { ThemeProvider } from '@mui/system';
|
|
@@ -195,6 +195,42 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
195
195
|
setPendingFocusIndex(idx);
|
|
196
196
|
};
|
|
197
197
|
const selectedItem = items[selectedIndex];
|
|
198
|
+
|
|
199
|
+
// Ref registry for each field's label element, keyed by field.key -- rebuilt every render (a
|
|
200
|
+
// field can be removed/reordered), read by the layout effect below to measure whether a label
|
|
201
|
+
// actually wrapped onto a second line at its current column width.
|
|
202
|
+
const labelRefs = useRef(new Map());
|
|
203
|
+
const [wrappedKeys, setWrappedKeys] = useState(() => new Set());
|
|
204
|
+
|
|
205
|
+
// A label long enough to wrap onto a second line at half-column width throws that field's
|
|
206
|
+
// control out of vertical alignment with whatever ends up paired next to it -- a one-line label
|
|
207
|
+
// and a two-line label start their inputs at different heights even though both cells are the
|
|
208
|
+
// same width. Admin-typed labels are free text up to 100 characters of wildly different letter
|
|
209
|
+
// widths, so a character-count cutoff would either wrongly wrap a short-but-wide label or miss a
|
|
210
|
+
// long-but-narrow one; this measures the ACTUAL rendered height of every label after each paint
|
|
211
|
+
// instead and promotes any field whose label wrapped to full width too, same treatment as a
|
|
212
|
+
// type-forced or orphaned field.
|
|
213
|
+
//
|
|
214
|
+
// Re-runs whenever the wrapped set itself changes (not just when `fieldConfig` changes), because
|
|
215
|
+
// promoting one field to full width re-pairs its neighbors, which can occasionally make a
|
|
216
|
+
// DIFFERENT field's label newly wrap (or stop wrapping) at its new column width. Safe from an
|
|
217
|
+
// infinite loop: promotions only ever add width, never remove it, so this converges in at most a
|
|
218
|
+
// few passes, and the state setter bails out (no re-render) the moment a pass finds no change.
|
|
219
|
+
useLayoutEffect(() => {
|
|
220
|
+
const nextWrapped = new Set();
|
|
221
|
+
labelRefs.current.forEach((el, fieldKey) => {
|
|
222
|
+
if (!el) return;
|
|
223
|
+
const lineHeight = parseFloat(getComputedStyle(el).lineHeight) || 0;
|
|
224
|
+
if (lineHeight > 0 && el.offsetHeight > lineHeight * 1.4) {
|
|
225
|
+
nextWrapped.add(fieldKey);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
setWrappedKeys(prev => {
|
|
229
|
+
if (prev.size === nextWrapped.size && [...prev].every(k => nextWrapped.has(k))) return prev;
|
|
230
|
+
return nextWrapped;
|
|
231
|
+
});
|
|
232
|
+
}, [fieldConfig, wrappedKeys]);
|
|
233
|
+
const isFullWidthField = f => ['select', 'textarea', 'select_multiple'].includes(f.type) || wrappedKeys.has(f.key);
|
|
198
234
|
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
199
235
|
theme: defaultTheme
|
|
200
236
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -302,7 +338,7 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
302
338
|
}, /*#__PURE__*/React.createElement(DeleteOutlineIcon, {
|
|
303
339
|
fontSize: "small"
|
|
304
340
|
}))), (() => {
|
|
305
|
-
const pairableFields = fieldConfig.filter(f => !
|
|
341
|
+
const pairableFields = fieldConfig.filter(f => !isFullWidthField(f));
|
|
306
342
|
const orphanField = pairableFields.length % 2 === 1 ? pairableFields[pairableFields.length - 1] : null;
|
|
307
343
|
return /*#__PURE__*/React.createElement("div", {
|
|
308
344
|
ref: fieldsContainerRef,
|
|
@@ -327,7 +363,7 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
327
363
|
// extra length was long enough to wrap onto a second line in a narrow column,
|
|
328
364
|
// throwing that field's input out of vertical alignment with its paired neighbor.
|
|
329
365
|
const labelText = field.required ? `${field.label} *` : field.label;
|
|
330
|
-
const wrapperClassName =
|
|
366
|
+
const wrapperClassName = isFullWidthField(field) || field === orphanField ? 'col-span-full' : undefined;
|
|
331
367
|
let control;
|
|
332
368
|
if (showAsDrifted) {
|
|
333
369
|
// Generic stringify -- this renders whatever type the field used to be, which
|
|
@@ -523,6 +559,9 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
523
559
|
key: revealKey,
|
|
524
560
|
"data-field-invalid": showError ? 'true' : undefined
|
|
525
561
|
}, /*#__PURE__*/React.createElement(Typography, {
|
|
562
|
+
ref: el => {
|
|
563
|
+
if (el) labelRefs.current.set(field.key, el);else labelRefs.current.delete(field.key);
|
|
564
|
+
},
|
|
526
565
|
variant: "body2",
|
|
527
566
|
sx: {
|
|
528
567
|
fontWeight: 500,
|
|
@@ -2524,7 +2524,8 @@
|
|
|
2524
2524
|
"width": "Ancho",
|
|
2525
2525
|
"max_adult": "Máximo de adultos",
|
|
2526
2526
|
"max_children": "Máximo de niños",
|
|
2527
|
-
"max_animal": "Máximo de animales"
|
|
2527
|
+
"max_animal": "Máximo de animales",
|
|
2528
|
+
"animal_fields": "Campos para animales"
|
|
2528
2529
|
}
|
|
2529
2530
|
},
|
|
2530
2531
|
"lot_selection": {
|
|
@@ -2524,7 +2524,8 @@
|
|
|
2524
2524
|
"width": "Largeur",
|
|
2525
2525
|
"max_adult": "Adultes max",
|
|
2526
2526
|
"max_children": "Enfants max",
|
|
2527
|
-
"max_animal": "Animaux max"
|
|
2527
|
+
"max_animal": "Animaux max",
|
|
2528
|
+
"animal_fields": "Champs pour les animaux"
|
|
2528
2529
|
}
|
|
2529
2530
|
},
|
|
2530
2531
|
"lot_selection": {
|