@aatulwork/customform-renderer 1.11.0 → 1.13.0
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/fields.js +16 -3
- package/dist/fields.js.map +1 -1
- package/dist/fields.mjs +17 -4
- package/dist/fields.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +127 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -30,8 +30,9 @@ interface FieldViewProps {
|
|
|
30
30
|
field: FormField;
|
|
31
31
|
value: any;
|
|
32
32
|
services?: FormServices;
|
|
33
|
+
colors?: FormColors;
|
|
33
34
|
}
|
|
34
|
-
declare const FieldView: ({ field, value, services }: FieldViewProps) => react_jsx_runtime.JSX.Element;
|
|
35
|
+
declare const FieldView: ({ field, value, services, colors }: FieldViewProps) => react_jsx_runtime.JSX.Element;
|
|
35
36
|
|
|
36
37
|
interface SimpleSelectOption {
|
|
37
38
|
value: string | number;
|
package/dist/index.js
CHANGED
|
@@ -293,6 +293,7 @@ var SimpleSelect = ({
|
|
|
293
293
|
onRefresh
|
|
294
294
|
}) => {
|
|
295
295
|
const [filterText, setFilterText] = react.useState("");
|
|
296
|
+
const selectId = react.useId();
|
|
296
297
|
const handleChange = (event) => {
|
|
297
298
|
const val = event.target.value;
|
|
298
299
|
onChange(val);
|
|
@@ -307,10 +308,21 @@ var SimpleSelect = ({
|
|
|
307
308
|
setFilterText("");
|
|
308
309
|
};
|
|
309
310
|
return /* @__PURE__ */ jsxRuntime.jsxs(material.FormControl, { fullWidth, size, required, error, disabled, children: [
|
|
310
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
311
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
312
|
+
material.FormLabel,
|
|
313
|
+
{
|
|
314
|
+
component: "label",
|
|
315
|
+
htmlFor: selectId,
|
|
316
|
+
required,
|
|
317
|
+
error,
|
|
318
|
+
sx: { mb: 0.5, display: "block" },
|
|
319
|
+
children: label
|
|
320
|
+
}
|
|
321
|
+
),
|
|
311
322
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
312
323
|
material.Select,
|
|
313
324
|
{
|
|
325
|
+
id: selectId,
|
|
314
326
|
value: value ?? (multiple ? [] : ""),
|
|
315
327
|
onChange: handleChange,
|
|
316
328
|
onClose: handleClose,
|
|
@@ -542,11 +554,12 @@ var ColorField = ({ field, control, defaultValue, rules, errors }) => {
|
|
|
542
554
|
onChange: formField.onChange,
|
|
543
555
|
onBlur: formField.onBlur,
|
|
544
556
|
sx: {
|
|
545
|
-
width:
|
|
546
|
-
height:
|
|
557
|
+
width: 30,
|
|
558
|
+
height: 30,
|
|
547
559
|
padding: 0,
|
|
548
560
|
cursor: "pointer",
|
|
549
561
|
backgroundColor: "transparent",
|
|
562
|
+
border: "none",
|
|
550
563
|
"&::-webkit-color-swatch-wrapper": { padding: 0 },
|
|
551
564
|
"&::-webkit-color-swatch": { border: "none", borderRadius: "4px" },
|
|
552
565
|
"&::-moz-color-swatch": { border: "none", borderRadius: "4px" }
|
|
@@ -1377,7 +1390,22 @@ var FieldRenderer = (props) => {
|
|
|
1377
1390
|
return null;
|
|
1378
1391
|
}
|
|
1379
1392
|
};
|
|
1380
|
-
var
|
|
1393
|
+
var REFERENCE_OPTIONS_CACHE_TTL = 5 * 60 * 1e3;
|
|
1394
|
+
var referenceOptionsCache = /* @__PURE__ */ new Map();
|
|
1395
|
+
var getCachedOptions = (key) => {
|
|
1396
|
+
const cached = referenceOptionsCache.get(key);
|
|
1397
|
+
if (!cached) return null;
|
|
1398
|
+
if (Date.now() - cached.timestamp > REFERENCE_OPTIONS_CACHE_TTL) {
|
|
1399
|
+
referenceOptionsCache.delete(key);
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
return cached.options;
|
|
1403
|
+
};
|
|
1404
|
+
var setCachedOptions = (key, options) => {
|
|
1405
|
+
referenceOptionsCache.set(key, { options, timestamp: Date.now() });
|
|
1406
|
+
};
|
|
1407
|
+
var FieldView = ({ field, value, services, colors }) => {
|
|
1408
|
+
const formColors = useFormColors(colors);
|
|
1381
1409
|
const dateFormatter = services?.dateFormatter || defaultDateFormatterService;
|
|
1382
1410
|
const FileDisplayComponent = services?.FileDisplayComponent;
|
|
1383
1411
|
const CKEditorDisplayComponent = services?.CKEditorDisplayComponent;
|
|
@@ -1415,13 +1443,16 @@ var FieldView = ({ field, value, services }) => {
|
|
|
1415
1443
|
borderColor: "divider"
|
|
1416
1444
|
},
|
|
1417
1445
|
children: [
|
|
1418
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: field.label }),
|
|
1446
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body2", sx: { fontWeight: 500, color: formColors.primary }, children: field.label }),
|
|
1419
1447
|
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body1", sx: { color: "text.secondary" }, children: value ? Array.isArray(value) ? `${value.length} file(s)` : "1 file" : "\u2014" })
|
|
1420
1448
|
]
|
|
1421
1449
|
},
|
|
1422
1450
|
field.name
|
|
1423
1451
|
);
|
|
1424
1452
|
}
|
|
1453
|
+
if (field.type === "formReference" || field.type === "apiReference") {
|
|
1454
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ReferenceFieldView, { field, value, services });
|
|
1455
|
+
}
|
|
1425
1456
|
if (field.type === "ckeditor") {
|
|
1426
1457
|
if (CKEditorDisplayComponent) {
|
|
1427
1458
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1511,6 +1542,93 @@ var FieldView = ({ field, value, services }) => {
|
|
|
1511
1542
|
field.name
|
|
1512
1543
|
);
|
|
1513
1544
|
};
|
|
1545
|
+
var ReferenceFieldView = ({
|
|
1546
|
+
field,
|
|
1547
|
+
value,
|
|
1548
|
+
services
|
|
1549
|
+
}) => {
|
|
1550
|
+
const [displayLabels, setDisplayLabels] = react.useState(null);
|
|
1551
|
+
react.useEffect(() => {
|
|
1552
|
+
if (value === null || value === void 0 || value === "") {
|
|
1553
|
+
setDisplayLabels([]);
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
let values;
|
|
1557
|
+
if (field.allowMultiple) {
|
|
1558
|
+
values = Array.isArray(value) ? value : value ? [value] : [];
|
|
1559
|
+
} else {
|
|
1560
|
+
values = Array.isArray(value) && value.length > 0 ? [value[0]] : value ? [value] : [];
|
|
1561
|
+
}
|
|
1562
|
+
if (values.length === 0) {
|
|
1563
|
+
setDisplayLabels([]);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
const fetchLabels = async () => {
|
|
1567
|
+
try {
|
|
1568
|
+
let cacheKey = null;
|
|
1569
|
+
let options = null;
|
|
1570
|
+
if (field.type === "formReference" && field.referenceFormName && field.referenceFieldName) {
|
|
1571
|
+
cacheKey = `formRef:${field.referenceFormName}:${field.referenceFieldName}`;
|
|
1572
|
+
options = getCachedOptions(cacheKey);
|
|
1573
|
+
if (!options) {
|
|
1574
|
+
const formRefService = services?.formReference || defaultFormReferenceService;
|
|
1575
|
+
options = await formRefService.fetchOptions(field.referenceFormName, field.referenceFieldName);
|
|
1576
|
+
setCachedOptions(cacheKey, options);
|
|
1577
|
+
}
|
|
1578
|
+
} else if (field.type === "apiReference" && field.apiEndpoint && field.apiLabelField) {
|
|
1579
|
+
const valueField = field.apiValueField || "_id";
|
|
1580
|
+
cacheKey = `apiRef:${field.apiEndpoint}:${field.apiLabelField}:${valueField}`;
|
|
1581
|
+
options = getCachedOptions(cacheKey);
|
|
1582
|
+
if (!options) {
|
|
1583
|
+
const apiRefService = services?.apiReference || defaultApiReferenceService;
|
|
1584
|
+
options = await apiRefService.fetchOptions(field.apiEndpoint, field.apiLabelField, valueField);
|
|
1585
|
+
setCachedOptions(cacheKey, options);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
const labels = values.map((val) => {
|
|
1589
|
+
const option = (options || []).find((opt) => opt.value === val || String(opt.value) === String(val));
|
|
1590
|
+
return option ? option.label : String(val);
|
|
1591
|
+
});
|
|
1592
|
+
setDisplayLabels(labels);
|
|
1593
|
+
} catch {
|
|
1594
|
+
setDisplayLabels(values.map((v) => String(v)));
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
fetchLabels();
|
|
1598
|
+
}, [field, value, services]);
|
|
1599
|
+
const displayText = displayLabels === null ? "..." : displayLabels.length === 0 ? "\u2014" : displayLabels.join(", ");
|
|
1600
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1601
|
+
material.Box,
|
|
1602
|
+
{
|
|
1603
|
+
sx: {
|
|
1604
|
+
display: "flex",
|
|
1605
|
+
flexDirection: "column",
|
|
1606
|
+
gap: 0.5,
|
|
1607
|
+
py: 1.5,
|
|
1608
|
+
px: 1,
|
|
1609
|
+
borderColor: "divider"
|
|
1610
|
+
},
|
|
1611
|
+
children: [
|
|
1612
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: field.label }),
|
|
1613
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1614
|
+
material.Typography,
|
|
1615
|
+
{
|
|
1616
|
+
variant: "body1",
|
|
1617
|
+
sx: {
|
|
1618
|
+
color: displayText === "\u2014" ? "text.disabled" : "text.primary",
|
|
1619
|
+
fontStyle: displayText === "\u2014" ? "italic" : "normal",
|
|
1620
|
+
fontWeight: 400,
|
|
1621
|
+
fontSize: "0.875rem",
|
|
1622
|
+
lineHeight: 1.5
|
|
1623
|
+
},
|
|
1624
|
+
children: displayText
|
|
1625
|
+
}
|
|
1626
|
+
)
|
|
1627
|
+
]
|
|
1628
|
+
},
|
|
1629
|
+
field.name
|
|
1630
|
+
);
|
|
1631
|
+
};
|
|
1514
1632
|
var formatFieldValue = (field, value, dateFormatter, services) => {
|
|
1515
1633
|
if (value === null || value === void 0 || value === "") {
|
|
1516
1634
|
return "\u2014";
|
|
@@ -1522,8 +1640,6 @@ var formatFieldValue = (field, value, dateFormatter, services) => {
|
|
|
1522
1640
|
case "datepicker":
|
|
1523
1641
|
return dateFormatter?.format(value, { datePickerMode: field.datePickerMode }) || String(value);
|
|
1524
1642
|
case "select":
|
|
1525
|
-
case "formReference":
|
|
1526
|
-
case "apiReference":
|
|
1527
1643
|
let values;
|
|
1528
1644
|
if (field.allowMultiple) {
|
|
1529
1645
|
values = Array.isArray(value) ? value : value ? [value] : [];
|
|
@@ -1585,7 +1701,7 @@ var FormViewMode = ({ formSchema, initialValues, hideTitle = false, services, co
|
|
|
1585
1701
|
id: `panel-${section.id}-header`,
|
|
1586
1702
|
children: /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
1587
1703
|
/* @__PURE__ */ jsxRuntime.jsx(DoubleArrowOutlinedIcon__default.default, { fontSize: "small", sx: { color: formColors.primary } }),
|
|
1588
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1", sx: {
|
|
1704
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1", sx: { color: formColors.primary }, children: section.title })
|
|
1589
1705
|
] })
|
|
1590
1706
|
}
|
|
1591
1707
|
),
|
|
@@ -1599,7 +1715,7 @@ var FormViewMode = ({ formSchema, initialValues, hideTitle = false, services, co
|
|
|
1599
1715
|
gridTemplateColumns: isMobile ? "repeat(1, 1fr)" : "repeat(2, 1fr)",
|
|
1600
1716
|
gap: 1
|
|
1601
1717
|
},
|
|
1602
|
-
children: section.fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(FieldView, { field, value: initialValues?.[field.name], services }, field.name))
|
|
1718
|
+
children: section.fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(FieldView, { field, value: initialValues?.[field.name], services, colors }, field.name))
|
|
1603
1719
|
}
|
|
1604
1720
|
)
|
|
1605
1721
|
] })
|
|
@@ -1774,7 +1890,7 @@ var FormRenderer = ({
|
|
|
1774
1890
|
);
|
|
1775
1891
|
if (sectionDisplayMode === "stepper") {
|
|
1776
1892
|
return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { border: "1px solid", borderColor: formColors.divider, p: 5, backgroundColor: formColors.backgroundPaper }, children: [
|
|
1777
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Stepper, { activeStep, orientation: "horizontal", children: formSchema.sections.map((section) => /* @__PURE__ */ jsxRuntime.jsx(material.Step, { children: /* @__PURE__ */ jsxRuntime.jsx(material.StepLabel, { children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1",
|
|
1893
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Stepper, { activeStep, orientation: "horizontal", children: formSchema.sections.map((section) => /* @__PURE__ */ jsxRuntime.jsx(material.Step, { children: /* @__PURE__ */ jsxRuntime.jsx(material.StepLabel, { children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1", children: section.title }) }) }, section.id)) }),
|
|
1778
1894
|
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { mt: 5 }, children: formSchema.sections.map((section, sectionIndex) => {
|
|
1779
1895
|
const sectionsLength = formSchema.sections?.length || 0;
|
|
1780
1896
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1830,7 +1946,7 @@ var FormRenderer = ({
|
|
|
1830
1946
|
id: `panel-${section.id}-header`,
|
|
1831
1947
|
children: /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
1832
1948
|
/* @__PURE__ */ jsxRuntime.jsx(DoubleArrowOutlinedIcon__default.default, { fontSize: "small", sx: { color: formColors.primary } }),
|
|
1833
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1", sx: {
|
|
1949
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "subtitle1", sx: { color: formColors.primary }, children: section.title })
|
|
1834
1950
|
] })
|
|
1835
1951
|
}
|
|
1836
1952
|
),
|