@form-eng/mui 1.0.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/README.md +138 -0
- package/dist/index.d.mts +141 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +1036 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +995 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,995 @@
|
|
|
1
|
+
// src/fields/Textbox.tsx
|
|
2
|
+
import { TextField } from "@mui/material";
|
|
3
|
+
|
|
4
|
+
// src/components/ReadOnlyText.tsx
|
|
5
|
+
import { Typography } from "@mui/material";
|
|
6
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
7
|
+
var ReadOnlyText = (props) => {
|
|
8
|
+
const { value, fieldName, valueClassName, showControlOnSide, containerClassName, ellipsifyTextCharacters } = props;
|
|
9
|
+
const classNameValue = valueClassName === void 0 ? "read-only-field" : valueClassName;
|
|
10
|
+
const cutoff = (ellipsifyTextCharacters || 0) - 3;
|
|
11
|
+
return /* @__PURE__ */ jsx("div", { className: `${showControlOnSide ? "flexBox" : ""} ${containerClassName ?? ""}`, children: /* @__PURE__ */ jsx(
|
|
12
|
+
Typography,
|
|
13
|
+
{
|
|
14
|
+
variant: "body2",
|
|
15
|
+
id: `${fieldName}-read-only`,
|
|
16
|
+
className: classNameValue,
|
|
17
|
+
title: value,
|
|
18
|
+
component: "span",
|
|
19
|
+
children: value ? /* @__PURE__ */ jsx(Fragment, { children: ellipsifyTextCharacters && value.length > ellipsifyTextCharacters ? `${value.substring(0, cutoff)}...` : value }) : /* @__PURE__ */ jsx(Fragment, { children: "-" })
|
|
20
|
+
}
|
|
21
|
+
) });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/helpers.ts
|
|
25
|
+
var FieldClassName = (className, error) => {
|
|
26
|
+
return error ? `${className} error` : className;
|
|
27
|
+
};
|
|
28
|
+
var GetFieldDataTestId = (fieldName, programName, entityType, entityId) => {
|
|
29
|
+
return `${programName}-${entityType}-${entityId}-${fieldName}`;
|
|
30
|
+
};
|
|
31
|
+
function formatDateTime(dateStr, options) {
|
|
32
|
+
if (!dateStr) return "";
|
|
33
|
+
const date = new Date(dateStr);
|
|
34
|
+
if (isNaN(date.getTime())) return dateStr;
|
|
35
|
+
if (options?.hideTimestamp) {
|
|
36
|
+
return date.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
|
|
37
|
+
}
|
|
38
|
+
return date.toLocaleString(void 0, { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
|
|
39
|
+
}
|
|
40
|
+
var DocumentLinksStrings = {
|
|
41
|
+
link: "Link",
|
|
42
|
+
addLink: "Add Link",
|
|
43
|
+
addAnotherLink: "Add Another Link",
|
|
44
|
+
deleteLink: "Delete Link",
|
|
45
|
+
confirmDeleteLink: "Are you sure you want to delete",
|
|
46
|
+
delete: "Delete",
|
|
47
|
+
cancel: "Cancel",
|
|
48
|
+
saveChanges: "Save Changes",
|
|
49
|
+
save: "Save"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/fields/Textbox.tsx
|
|
53
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
54
|
+
var Textbox = (props) => {
|
|
55
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, placeholder, setFieldValue } = props;
|
|
56
|
+
const onChange = (event) => {
|
|
57
|
+
setFieldValue(fieldName, event.target.value, false, 3e3);
|
|
58
|
+
};
|
|
59
|
+
return readOnly ? /* @__PURE__ */ jsx2(
|
|
60
|
+
ReadOnlyText,
|
|
61
|
+
{
|
|
62
|
+
fieldName,
|
|
63
|
+
value,
|
|
64
|
+
ellipsifyTextCharacters: config?.ellipsifyTextCharacters
|
|
65
|
+
}
|
|
66
|
+
) : /* @__PURE__ */ jsx2(
|
|
67
|
+
TextField,
|
|
68
|
+
{
|
|
69
|
+
className: FieldClassName("hook-textbox", error),
|
|
70
|
+
autoComplete: "off",
|
|
71
|
+
value: value ?? "",
|
|
72
|
+
onChange,
|
|
73
|
+
size: "small",
|
|
74
|
+
fullWidth: true,
|
|
75
|
+
error: !!error,
|
|
76
|
+
required,
|
|
77
|
+
placeholder: placeholder ?? config?.placeHolder,
|
|
78
|
+
helperText: error?.message,
|
|
79
|
+
inputProps: {
|
|
80
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
var Textbox_default = Textbox;
|
|
86
|
+
|
|
87
|
+
// src/fields/Number.tsx
|
|
88
|
+
import { isNull } from "@form-eng/core";
|
|
89
|
+
import { TextField as TextField2 } from "@mui/material";
|
|
90
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
91
|
+
var NumberField = (props) => {
|
|
92
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, setFieldValue } = props;
|
|
93
|
+
const onChange = (event) => {
|
|
94
|
+
const number = Number(event.target.value);
|
|
95
|
+
if (!isNaN(number)) {
|
|
96
|
+
setFieldValue(fieldName, number, false, 1500);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return readOnly ? /* @__PURE__ */ jsx3(ReadOnlyText, { fieldName, value: String(value) }) : /* @__PURE__ */ jsx3(
|
|
100
|
+
TextField2,
|
|
101
|
+
{
|
|
102
|
+
className: FieldClassName("hook-number", error),
|
|
103
|
+
autoComplete: "off",
|
|
104
|
+
type: "number",
|
|
105
|
+
value: !isNull(value) ? String(value) : "",
|
|
106
|
+
onChange,
|
|
107
|
+
size: "small",
|
|
108
|
+
fullWidth: true,
|
|
109
|
+
error: !!error,
|
|
110
|
+
required,
|
|
111
|
+
helperText: error?.message,
|
|
112
|
+
inputProps: {
|
|
113
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
var Number_default = NumberField;
|
|
119
|
+
|
|
120
|
+
// src/fields/Toggle.tsx
|
|
121
|
+
import { convertBooleanToYesOrNoText } from "@form-eng/core";
|
|
122
|
+
import { Switch, FormControlLabel } from "@mui/material";
|
|
123
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
124
|
+
var Toggle = (props) => {
|
|
125
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
126
|
+
const onChange = (_, checked) => {
|
|
127
|
+
setFieldValue(fieldName, checked);
|
|
128
|
+
};
|
|
129
|
+
return readOnly ? /* @__PURE__ */ jsx4(ReadOnlyText, { fieldName, value: convertBooleanToYesOrNoText(value) }) : /* @__PURE__ */ jsx4(
|
|
130
|
+
FormControlLabel,
|
|
131
|
+
{
|
|
132
|
+
className: "hook-toggle",
|
|
133
|
+
control: /* @__PURE__ */ jsx4(
|
|
134
|
+
Switch,
|
|
135
|
+
{
|
|
136
|
+
checked: value,
|
|
137
|
+
onChange,
|
|
138
|
+
"aria-invalid": !!error,
|
|
139
|
+
"aria-required": required,
|
|
140
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
label: ""
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
var Toggle_default = Toggle;
|
|
148
|
+
|
|
149
|
+
// src/fields/Dropdown.tsx
|
|
150
|
+
import { FormControl, Select, MenuItem } from "@mui/material";
|
|
151
|
+
import React from "react";
|
|
152
|
+
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
153
|
+
var Dropdown = (props) => {
|
|
154
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, placeholder, options, setFieldValue } = props;
|
|
155
|
+
const onChange = (event) => {
|
|
156
|
+
setFieldValue(fieldName, event.target.value);
|
|
157
|
+
};
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
if (!value && !readOnly && config?.setDefaultKeyIfOnlyOneOption && options?.length === 1) {
|
|
160
|
+
setFieldValue(fieldName, String(options[0].value));
|
|
161
|
+
}
|
|
162
|
+
}, [options]);
|
|
163
|
+
return readOnly ? /* @__PURE__ */ jsx5(ReadOnlyText, { fieldName, value }) : /* @__PURE__ */ jsx5(FormControl, { fullWidth: true, size: "small", error: !!error, required, children: /* @__PURE__ */ jsxs(
|
|
164
|
+
Select,
|
|
165
|
+
{
|
|
166
|
+
className: FieldClassName("hook-dropdown", error),
|
|
167
|
+
value: value ? String(value) : "",
|
|
168
|
+
onChange,
|
|
169
|
+
displayEmpty: true,
|
|
170
|
+
"aria-required": required,
|
|
171
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
172
|
+
children: [
|
|
173
|
+
!value && (placeholder ?? config?.placeHolder) && /* @__PURE__ */ jsx5(MenuItem, { value: "", disabled: true, children: placeholder ?? config?.placeHolder }),
|
|
174
|
+
options?.map((option) => /* @__PURE__ */ jsx5(MenuItem, { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
) });
|
|
178
|
+
};
|
|
179
|
+
var Dropdown_default = Dropdown;
|
|
180
|
+
|
|
181
|
+
// src/fields/MultiSelect.tsx
|
|
182
|
+
import { FormControl as FormControl2, Select as Select2, MenuItem as MenuItem2, Chip, Box } from "@mui/material";
|
|
183
|
+
import { useFormContext } from "react-hook-form";
|
|
184
|
+
import { Fragment as Fragment2, jsx as jsx6 } from "react/jsx-runtime";
|
|
185
|
+
var MultiSelect = (props) => {
|
|
186
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options, setFieldValue } = props;
|
|
187
|
+
const { watch } = useFormContext();
|
|
188
|
+
const selectedOptions = watch(`${fieldName}`) ?? [];
|
|
189
|
+
const onChange = (event) => {
|
|
190
|
+
const newValue = event.target.value;
|
|
191
|
+
setFieldValue(fieldName, typeof newValue === "string" ? newValue.split(",") : newValue, false, 1500);
|
|
192
|
+
};
|
|
193
|
+
return readOnly ? /* @__PURE__ */ jsx6(Fragment2, { children: value && value.length > 0 ? /* @__PURE__ */ jsx6(Box, { className: "hook-multi-select-read-only", sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: value.map((v) => /* @__PURE__ */ jsx6(Chip, { label: v, size: "small" }, v)) }) : null }) : /* @__PURE__ */ jsx6(FormControl2, { fullWidth: true, size: "small", error: !!error, required, children: /* @__PURE__ */ jsx6(
|
|
194
|
+
Select2,
|
|
195
|
+
{
|
|
196
|
+
className: FieldClassName("hook-multi-select", error),
|
|
197
|
+
multiple: true,
|
|
198
|
+
value: selectedOptions,
|
|
199
|
+
onChange,
|
|
200
|
+
"aria-invalid": !!error,
|
|
201
|
+
"aria-required": required,
|
|
202
|
+
renderValue: (selected) => /* @__PURE__ */ jsx6(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: selected.map((val) => /* @__PURE__ */ jsx6(Chip, { label: val, size: "small" }, val)) }),
|
|
203
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
204
|
+
children: options?.map((option) => /* @__PURE__ */ jsx6(MenuItem2, { value: String(option.value), disabled: option.disabled, children: option.label }, String(option.value)))
|
|
205
|
+
}
|
|
206
|
+
) });
|
|
207
|
+
};
|
|
208
|
+
var MultiSelect_default = MultiSelect;
|
|
209
|
+
|
|
210
|
+
// src/fields/DateControl.tsx
|
|
211
|
+
import { FormStrings } from "@form-eng/core";
|
|
212
|
+
import { TextField as TextField3, IconButton } from "@mui/material";
|
|
213
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
214
|
+
var DateControl = (props) => {
|
|
215
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, setFieldValue } = props;
|
|
216
|
+
const onChange = (event) => {
|
|
217
|
+
const date = new Date(event.target.value);
|
|
218
|
+
if (!isNaN(date.getTime())) {
|
|
219
|
+
setFieldValue(fieldName, date.toISOString());
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const onClearDate = () => {
|
|
223
|
+
setFieldValue(fieldName, null);
|
|
224
|
+
};
|
|
225
|
+
const dateInputValue = value ? new Date(value).toISOString().split("T")[0] : "";
|
|
226
|
+
return readOnly ? /* @__PURE__ */ jsx7(Fragment3, { children: value ? /* @__PURE__ */ jsx7("span", { className: "hook-read-only-date", children: formatDateTime(value, { hideTimestamp: true }) }) : /* @__PURE__ */ jsx7(Fragment3, { children: "-" }) }) : /* @__PURE__ */ jsxs2("div", { className: "hook-date-control-container", style: { display: "flex", alignItems: "center", gap: "4px" }, children: [
|
|
227
|
+
/* @__PURE__ */ jsx7(
|
|
228
|
+
TextField3,
|
|
229
|
+
{
|
|
230
|
+
className: FieldClassName("hook-date-control", error),
|
|
231
|
+
type: "date",
|
|
232
|
+
value: dateInputValue,
|
|
233
|
+
onChange,
|
|
234
|
+
size: "small",
|
|
235
|
+
fullWidth: true,
|
|
236
|
+
error: !!error,
|
|
237
|
+
required,
|
|
238
|
+
helperText: error?.message,
|
|
239
|
+
InputLabelProps: { shrink: true },
|
|
240
|
+
inputProps: {
|
|
241
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
/* @__PURE__ */ jsx7(
|
|
246
|
+
IconButton,
|
|
247
|
+
{
|
|
248
|
+
size: "small",
|
|
249
|
+
onClick: onClearDate,
|
|
250
|
+
title: FormStrings.clickToClear,
|
|
251
|
+
"aria-label": `${fieldName} ${FormStrings.clear}`,
|
|
252
|
+
children: "\u2715"
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
] });
|
|
256
|
+
};
|
|
257
|
+
var DateControl_default = DateControl;
|
|
258
|
+
|
|
259
|
+
// src/fields/Slider.tsx
|
|
260
|
+
import { Slider as MuiSlider } from "@mui/material";
|
|
261
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
262
|
+
var Slider = (props) => {
|
|
263
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, setFieldValue } = props;
|
|
264
|
+
const onChange = (_, newValue) => {
|
|
265
|
+
setFieldValue(fieldName, newValue);
|
|
266
|
+
};
|
|
267
|
+
return readOnly ? /* @__PURE__ */ jsx8(ReadOnlyText, { fieldName, value: String(value) }) : /* @__PURE__ */ jsx8(
|
|
268
|
+
MuiSlider,
|
|
269
|
+
{
|
|
270
|
+
className: FieldClassName("hook-slider", error),
|
|
271
|
+
value: value ?? 0,
|
|
272
|
+
onChange,
|
|
273
|
+
max: config?.max,
|
|
274
|
+
min: config?.min,
|
|
275
|
+
step: config?.step,
|
|
276
|
+
valueLabelDisplay: "auto",
|
|
277
|
+
"aria-invalid": !!error,
|
|
278
|
+
"aria-required": required,
|
|
279
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
var Slider_default = Slider;
|
|
284
|
+
|
|
285
|
+
// src/fields/DynamicFragment.tsx
|
|
286
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
287
|
+
var DynamicFragment = (props) => {
|
|
288
|
+
const { value } = props;
|
|
289
|
+
return /* @__PURE__ */ jsx9("input", { type: "hidden", value });
|
|
290
|
+
};
|
|
291
|
+
var DynamicFragment_default = DynamicFragment;
|
|
292
|
+
|
|
293
|
+
// src/fields/SimpleDropdown.tsx
|
|
294
|
+
import { FormControl as FormControl3, Select as Select3, MenuItem as MenuItem3 } from "@mui/material";
|
|
295
|
+
import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
296
|
+
var SimpleDropdown = (props) => {
|
|
297
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, config, error, required, placeholder, setFieldValue } = props;
|
|
298
|
+
const simpleOptions = config?.dropdownOptions ?? [];
|
|
299
|
+
const onChange = (event) => {
|
|
300
|
+
setFieldValue(fieldName, event.target.value);
|
|
301
|
+
};
|
|
302
|
+
return readOnly ? /* @__PURE__ */ jsx10(ReadOnlyText, { fieldName, value }) : /* @__PURE__ */ jsx10(FormControl3, { fullWidth: true, size: "small", error: !!error, required, children: /* @__PURE__ */ jsxs3(
|
|
303
|
+
Select3,
|
|
304
|
+
{
|
|
305
|
+
className: FieldClassName("hook-dropdown", error),
|
|
306
|
+
value: value ?? "",
|
|
307
|
+
onChange,
|
|
308
|
+
displayEmpty: true,
|
|
309
|
+
"aria-required": required,
|
|
310
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
311
|
+
children: [
|
|
312
|
+
!value && (placeholder ?? config?.placeHolder) && /* @__PURE__ */ jsx10(MenuItem3, { value: "", disabled: true, children: placeholder ?? config?.placeHolder }),
|
|
313
|
+
simpleOptions.map((option) => /* @__PURE__ */ jsx10(MenuItem3, { value: option, children: option }, option))
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
) });
|
|
317
|
+
};
|
|
318
|
+
var SimpleDropdown_default = SimpleDropdown;
|
|
319
|
+
|
|
320
|
+
// src/fields/MultiSelectSearch.tsx
|
|
321
|
+
import { Autocomplete, TextField as TextField4, Chip as Chip2, Box as Box2 } from "@mui/material";
|
|
322
|
+
import { Fragment as Fragment4, jsx as jsx11 } from "react/jsx-runtime";
|
|
323
|
+
import { createElement } from "react";
|
|
324
|
+
var MultiSelectSearch = (props) => {
|
|
325
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, required, options: dropdownOptions, setFieldValue } = props;
|
|
326
|
+
const selectedValues = value ?? [];
|
|
327
|
+
const mappedOptions = dropdownOptions?.map((o) => ({
|
|
328
|
+
value: String(o.value),
|
|
329
|
+
label: o.label,
|
|
330
|
+
disabled: !!o.disabled
|
|
331
|
+
})) ?? [];
|
|
332
|
+
const onChange = (_, newValue) => {
|
|
333
|
+
setFieldValue(fieldName, newValue.map((v) => v.value), false, 3e3);
|
|
334
|
+
};
|
|
335
|
+
return readOnly ? /* @__PURE__ */ jsx11(Fragment4, { children: value && value.length > 0 ? /* @__PURE__ */ jsx11(Box2, { className: "hook-multi-select-search-read-only", sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: value.map((v) => /* @__PURE__ */ jsx11(Chip2, { label: v, size: "small" }, v)) }) : null }) : /* @__PURE__ */ jsx11(
|
|
336
|
+
Autocomplete,
|
|
337
|
+
{
|
|
338
|
+
className: FieldClassName("hook-multi-select-search", error),
|
|
339
|
+
multiple: true,
|
|
340
|
+
freeSolo: true,
|
|
341
|
+
"aria-required": required,
|
|
342
|
+
options: mappedOptions,
|
|
343
|
+
getOptionLabel: (option) => typeof option === "string" ? option : option.label,
|
|
344
|
+
getOptionDisabled: (option) => typeof option === "string" ? false : !!option.disabled,
|
|
345
|
+
value: mappedOptions.filter((o) => selectedValues.includes(o.value)),
|
|
346
|
+
onChange,
|
|
347
|
+
renderTags: (tagValue, getTagProps) => tagValue.map((option, index) => /* @__PURE__ */ createElement(
|
|
348
|
+
Chip2,
|
|
349
|
+
{
|
|
350
|
+
size: "small",
|
|
351
|
+
label: typeof option === "string" ? option : option.label,
|
|
352
|
+
...getTagProps({ index }),
|
|
353
|
+
key: typeof option === "string" ? option : option.value
|
|
354
|
+
}
|
|
355
|
+
)),
|
|
356
|
+
renderInput: (params) => /* @__PURE__ */ jsx11(
|
|
357
|
+
TextField4,
|
|
358
|
+
{
|
|
359
|
+
...params,
|
|
360
|
+
size: "small",
|
|
361
|
+
error: !!error,
|
|
362
|
+
required,
|
|
363
|
+
helperText: error?.message,
|
|
364
|
+
inputProps: {
|
|
365
|
+
...params.inputProps,
|
|
366
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
var MultiSelectSearch_default = MultiSelectSearch;
|
|
374
|
+
|
|
375
|
+
// src/fields/PopOutEditor.tsx
|
|
376
|
+
import { FormStrings as FormStrings3 } from "@form-eng/core";
|
|
377
|
+
import {
|
|
378
|
+
TextField as TextField5,
|
|
379
|
+
Button,
|
|
380
|
+
Dialog,
|
|
381
|
+
DialogTitle,
|
|
382
|
+
DialogContent,
|
|
383
|
+
DialogActions,
|
|
384
|
+
IconButton as IconButton2
|
|
385
|
+
} from "@mui/material";
|
|
386
|
+
import { useState } from "react";
|
|
387
|
+
|
|
388
|
+
// src/components/StatusMessage.tsx
|
|
389
|
+
import { FormStrings as FormStrings2 } from "@form-eng/core";
|
|
390
|
+
import { CircularProgress } from "@mui/material";
|
|
391
|
+
import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
392
|
+
var StatusMessage = (props) => {
|
|
393
|
+
const { id, error, errorCount, savePending, saving } = props;
|
|
394
|
+
return /* @__PURE__ */ jsx12("div", { className: "message", children: error ? /* @__PURE__ */ jsxs4(Fragment5, { children: [
|
|
395
|
+
/* @__PURE__ */ jsx12("span", { className: "error-icon", style: { color: "#d32f2f", fontSize: "16px" }, children: "\u26A0" }),
|
|
396
|
+
/* @__PURE__ */ jsx12("span", { className: "error-message", id, role: "alert", children: error.message || "Error" })
|
|
397
|
+
] }) : savePending ? /* @__PURE__ */ jsxs4(Fragment5, { children: [
|
|
398
|
+
/* @__PURE__ */ jsx12("span", { className: "warning-icon", style: { color: "#ed6c02", fontSize: "16px" }, children: "\u26A0" }),
|
|
399
|
+
/* @__PURE__ */ jsxs4("span", { className: "warning-message", id, role: "alert", children: [
|
|
400
|
+
FormStrings2.autoSavePending,
|
|
401
|
+
" (",
|
|
402
|
+
errorCount,
|
|
403
|
+
" ",
|
|
404
|
+
FormStrings2.remaining,
|
|
405
|
+
")"
|
|
406
|
+
] })
|
|
407
|
+
] }) : saving ? /* @__PURE__ */ jsxs4(Fragment5, { children: [
|
|
408
|
+
/* @__PURE__ */ jsx12(CircularProgress, { size: 16 }),
|
|
409
|
+
/* @__PURE__ */ jsx12("span", { className: "save-message", id, role: "alert", children: FormStrings2.saving })
|
|
410
|
+
] }) : null });
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/fields/PopOutEditor.tsx
|
|
414
|
+
import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
415
|
+
var PopOutEditor = (props) => {
|
|
416
|
+
const {
|
|
417
|
+
error,
|
|
418
|
+
fieldName,
|
|
419
|
+
programName,
|
|
420
|
+
entityType,
|
|
421
|
+
entityId,
|
|
422
|
+
config,
|
|
423
|
+
readOnly,
|
|
424
|
+
required,
|
|
425
|
+
savePending,
|
|
426
|
+
saving,
|
|
427
|
+
value,
|
|
428
|
+
label,
|
|
429
|
+
setFieldValue
|
|
430
|
+
} = props;
|
|
431
|
+
const [modalValue, setModalValue] = useState();
|
|
432
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
433
|
+
const [dialogVisible, setDialogVisible] = useState(false);
|
|
434
|
+
const onChange = (event) => {
|
|
435
|
+
const newValue = event.target.value;
|
|
436
|
+
modalVisible ? setModalValue(newValue) : setFieldValue(fieldName, newValue, false, 3e3);
|
|
437
|
+
};
|
|
438
|
+
const onExpandButtonClick = () => {
|
|
439
|
+
setModalVisible(true);
|
|
440
|
+
setModalValue(value ? `${value}` : "");
|
|
441
|
+
};
|
|
442
|
+
const onSaveButtonClick = () => {
|
|
443
|
+
setFieldValue(fieldName, modalValue, false);
|
|
444
|
+
setDialogVisible(false);
|
|
445
|
+
setModalVisible(false);
|
|
446
|
+
config?.saveCallback?.();
|
|
447
|
+
};
|
|
448
|
+
const onCancelButtonClick = () => {
|
|
449
|
+
if (dialogVisible) {
|
|
450
|
+
setDialogVisible(false);
|
|
451
|
+
setModalVisible(false);
|
|
452
|
+
} else if (modalValue !== value) {
|
|
453
|
+
setDialogVisible(true);
|
|
454
|
+
} else {
|
|
455
|
+
setModalVisible(false);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
if (readOnly) {
|
|
459
|
+
return /* @__PURE__ */ jsx13(
|
|
460
|
+
ReadOnlyText,
|
|
461
|
+
{
|
|
462
|
+
fieldName,
|
|
463
|
+
value: value ? `${value}` : "",
|
|
464
|
+
ellipsifyTextCharacters: config?.ellipsifyTextCharacters
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
return /* @__PURE__ */ jsxs5(Fragment6, { children: [
|
|
469
|
+
/* @__PURE__ */ jsxs5("div", { className: "hook-textarea", children: [
|
|
470
|
+
/* @__PURE__ */ jsx13(
|
|
471
|
+
TextField5,
|
|
472
|
+
{
|
|
473
|
+
className: FieldClassName("hook-text-area", error),
|
|
474
|
+
autoComplete: "off",
|
|
475
|
+
multiline: true,
|
|
476
|
+
rows: config?.numberOfRows ?? 4,
|
|
477
|
+
value: modalVisible ? `${modalValue}` : value ? `${value}` : "",
|
|
478
|
+
onChange,
|
|
479
|
+
size: "small",
|
|
480
|
+
fullWidth: true,
|
|
481
|
+
error: !!error,
|
|
482
|
+
helperText: error?.message,
|
|
483
|
+
inputProps: {
|
|
484
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId)
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
),
|
|
488
|
+
/* @__PURE__ */ jsx13(
|
|
489
|
+
Button,
|
|
490
|
+
{
|
|
491
|
+
className: "expand-button",
|
|
492
|
+
variant: "outlined",
|
|
493
|
+
size: "small",
|
|
494
|
+
onClick: onExpandButtonClick,
|
|
495
|
+
"aria-label": FormStrings3.openExpandedTextEditor,
|
|
496
|
+
sx: { mt: 1 },
|
|
497
|
+
children: FormStrings3.expand
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] }),
|
|
501
|
+
/* @__PURE__ */ jsxs5(
|
|
502
|
+
Dialog,
|
|
503
|
+
{
|
|
504
|
+
open: modalVisible,
|
|
505
|
+
onClose: onCancelButtonClick,
|
|
506
|
+
maxWidth: "md",
|
|
507
|
+
fullWidth: true,
|
|
508
|
+
children: [
|
|
509
|
+
/* @__PURE__ */ jsxs5(DialogTitle, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
510
|
+
/* @__PURE__ */ jsxs5("span", { children: [
|
|
511
|
+
label,
|
|
512
|
+
required && /* @__PURE__ */ jsx13("span", { className: "required-indicator", children: " *" })
|
|
513
|
+
] }),
|
|
514
|
+
/* @__PURE__ */ jsx13(
|
|
515
|
+
IconButton2,
|
|
516
|
+
{
|
|
517
|
+
size: "small",
|
|
518
|
+
onClick: onCancelButtonClick,
|
|
519
|
+
"aria-label": FormStrings3.closeExpandedTextEditor,
|
|
520
|
+
children: "\u2715"
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
] }),
|
|
524
|
+
/* @__PURE__ */ jsx13(DialogContent, { children: /* @__PURE__ */ jsx13(
|
|
525
|
+
TextField5,
|
|
526
|
+
{
|
|
527
|
+
className: FieldClassName("hook-text-area", error),
|
|
528
|
+
autoComplete: "off",
|
|
529
|
+
multiline: true,
|
|
530
|
+
rows: 12,
|
|
531
|
+
value: modalVisible ? `${modalValue}` : value ? `${value}` : "",
|
|
532
|
+
onChange,
|
|
533
|
+
fullWidth: true,
|
|
534
|
+
error: !!error,
|
|
535
|
+
sx: { mt: 1 }
|
|
536
|
+
}
|
|
537
|
+
) }),
|
|
538
|
+
/* @__PURE__ */ jsxs5(DialogActions, { children: [
|
|
539
|
+
config?.renderExtraModalFooter && /* @__PURE__ */ jsx13("div", { className: "custom-footer", children: config.renderExtraModalFooter() }),
|
|
540
|
+
/* @__PURE__ */ jsx13("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: (savePending || saving) && /* @__PURE__ */ jsx13(StatusMessage, { savePending: !error ? savePending : void 0, saving, error }) }),
|
|
541
|
+
/* @__PURE__ */ jsx13(Button, { variant: "outlined", onClick: onCancelButtonClick, children: FormStrings3.cancel }),
|
|
542
|
+
/* @__PURE__ */ jsx13(
|
|
543
|
+
Button,
|
|
544
|
+
{
|
|
545
|
+
variant: "contained",
|
|
546
|
+
onClick: onSaveButtonClick,
|
|
547
|
+
disabled: !config?.saveCallback && modalValue === value,
|
|
548
|
+
"data-testid": `${programName}-${entityType}-${entityId}-save-note`,
|
|
549
|
+
children: FormStrings3.save
|
|
550
|
+
}
|
|
551
|
+
)
|
|
552
|
+
] })
|
|
553
|
+
]
|
|
554
|
+
}
|
|
555
|
+
),
|
|
556
|
+
/* @__PURE__ */ jsxs5(Dialog, { open: dialogVisible, onClose: () => setDialogVisible(false), children: [
|
|
557
|
+
/* @__PURE__ */ jsx13(DialogTitle, { children: FormStrings3.unsavedChanges }),
|
|
558
|
+
/* @__PURE__ */ jsx13(DialogContent, { children: FormStrings3.saveChangesTo(label) }),
|
|
559
|
+
/* @__PURE__ */ jsxs5(DialogActions, { children: [
|
|
560
|
+
/* @__PURE__ */ jsx13(Button, { variant: "outlined", onClick: onCancelButtonClick, children: FormStrings3.dontSave }),
|
|
561
|
+
/* @__PURE__ */ jsx13(Button, { variant: "contained", onClick: onSaveButtonClick, children: FormStrings3.save })
|
|
562
|
+
] })
|
|
563
|
+
] })
|
|
564
|
+
] });
|
|
565
|
+
};
|
|
566
|
+
var PopOutEditor_default = PopOutEditor;
|
|
567
|
+
|
|
568
|
+
// src/fields/DocumentLinks.tsx
|
|
569
|
+
import { FormStrings as FormStrings4, FormConstants } from "@form-eng/core";
|
|
570
|
+
import {
|
|
571
|
+
Button as Button2,
|
|
572
|
+
IconButton as IconButton3,
|
|
573
|
+
TextField as TextField6,
|
|
574
|
+
Dialog as Dialog2,
|
|
575
|
+
DialogTitle as DialogTitle2,
|
|
576
|
+
DialogContent as DialogContent2,
|
|
577
|
+
DialogActions as DialogActions2,
|
|
578
|
+
List,
|
|
579
|
+
ListItem,
|
|
580
|
+
ListItemText,
|
|
581
|
+
Tooltip,
|
|
582
|
+
Typography as Typography2
|
|
583
|
+
} from "@mui/material";
|
|
584
|
+
import React3 from "react";
|
|
585
|
+
import { Controller, useForm, useFormContext as useFormContext2 } from "react-hook-form";
|
|
586
|
+
import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
587
|
+
var DocumentLinkItem = (props) => {
|
|
588
|
+
const {
|
|
589
|
+
fieldName,
|
|
590
|
+
programName,
|
|
591
|
+
entityType,
|
|
592
|
+
entityId,
|
|
593
|
+
readOnly,
|
|
594
|
+
index,
|
|
595
|
+
title,
|
|
596
|
+
url,
|
|
597
|
+
addNewLink,
|
|
598
|
+
saveLinks,
|
|
599
|
+
onCancelAddLink,
|
|
600
|
+
onConfirmDeleteLink
|
|
601
|
+
} = props;
|
|
602
|
+
const { confirm, cancel, linkTitleLabel, linkUrlLabel, add, edit, deleteLabel } = FormStrings4;
|
|
603
|
+
const [editingLink, setEditingLink] = React3.useState(false);
|
|
604
|
+
const { control, handleSubmit, setValue, reset, trigger } = useForm({
|
|
605
|
+
mode: "onChange",
|
|
606
|
+
defaultValues: { title: addNewLink ? "" : title, url: addNewLink ? "" : url }
|
|
607
|
+
});
|
|
608
|
+
const onSubmit = (data) => {
|
|
609
|
+
saveLinks({ title: data.title, url: data.url }, addNewLink, index);
|
|
610
|
+
setEditingLink(false);
|
|
611
|
+
};
|
|
612
|
+
React3.useEffect(() => {
|
|
613
|
+
setEditingLink(addNewLink);
|
|
614
|
+
}, [title, url, addNewLink]);
|
|
615
|
+
const onLinkTitleChange = (e) => {
|
|
616
|
+
setValue("title", e.target.value);
|
|
617
|
+
trigger("title");
|
|
618
|
+
};
|
|
619
|
+
const onLinkUrlChange = (e) => {
|
|
620
|
+
setValue("url", e.target.value);
|
|
621
|
+
trigger("url");
|
|
622
|
+
};
|
|
623
|
+
const onEditDocumentLink = () => setEditingLink(true);
|
|
624
|
+
const onCancelFormChanges = () => {
|
|
625
|
+
reset();
|
|
626
|
+
setEditingLink(false);
|
|
627
|
+
onCancelAddLink?.();
|
|
628
|
+
};
|
|
629
|
+
const onDelete = () => onConfirmDeleteLink(index);
|
|
630
|
+
return editingLink ? /* @__PURE__ */ jsx14("div", { className: "editing-link", children: /* @__PURE__ */ jsxs6("form", { onSubmit: handleSubmit(onSubmit), children: [
|
|
631
|
+
/* @__PURE__ */ jsxs6("div", { className: "header", style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "8px" }, children: [
|
|
632
|
+
/* @__PURE__ */ jsxs6(Typography2, { variant: "subtitle2", children: [
|
|
633
|
+
addNewLink ? add : edit,
|
|
634
|
+
" ",
|
|
635
|
+
DocumentLinksStrings.link
|
|
636
|
+
] }),
|
|
637
|
+
/* @__PURE__ */ jsxs6("div", { style: { display: "flex", gap: "4px" }, children: [
|
|
638
|
+
/* @__PURE__ */ jsx14(IconButton3, { size: "small", "aria-label": confirm, onClick: handleSubmit(onSubmit), children: "\u2713" }),
|
|
639
|
+
/* @__PURE__ */ jsx14(IconButton3, { size: "small", "aria-label": cancel, onClick: onCancelFormChanges, children: "\u2715" })
|
|
640
|
+
] })
|
|
641
|
+
] }),
|
|
642
|
+
/* @__PURE__ */ jsx14(
|
|
643
|
+
Controller,
|
|
644
|
+
{
|
|
645
|
+
name: "title",
|
|
646
|
+
control,
|
|
647
|
+
rules: { required: { value: true, message: FormStrings4.required } },
|
|
648
|
+
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx14("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsx14(
|
|
649
|
+
TextField6,
|
|
650
|
+
{
|
|
651
|
+
label: linkTitleLabel,
|
|
652
|
+
value: field.value,
|
|
653
|
+
onChange: onLinkTitleChange,
|
|
654
|
+
required: true,
|
|
655
|
+
size: "small",
|
|
656
|
+
fullWidth: true,
|
|
657
|
+
error: !!error,
|
|
658
|
+
helperText: error?.message,
|
|
659
|
+
inputProps: {
|
|
660
|
+
"data-testid": `${GetFieldDataTestId(fieldName, programName, entityType, entityId)}-link-title`
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
) })
|
|
664
|
+
}
|
|
665
|
+
),
|
|
666
|
+
/* @__PURE__ */ jsx14(
|
|
667
|
+
Controller,
|
|
668
|
+
{
|
|
669
|
+
name: "url",
|
|
670
|
+
control,
|
|
671
|
+
rules: {
|
|
672
|
+
required: { value: true, message: FormStrings4.required },
|
|
673
|
+
pattern: { value: FormConstants.urlRegex, message: FormStrings4.urlRequired }
|
|
674
|
+
},
|
|
675
|
+
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx14("div", { style: { marginBottom: "8px" }, children: /* @__PURE__ */ jsx14(
|
|
676
|
+
TextField6,
|
|
677
|
+
{
|
|
678
|
+
label: linkUrlLabel,
|
|
679
|
+
value: field.value,
|
|
680
|
+
onChange: onLinkUrlChange,
|
|
681
|
+
required: true,
|
|
682
|
+
size: "small",
|
|
683
|
+
fullWidth: true,
|
|
684
|
+
error: !!error,
|
|
685
|
+
helperText: error?.message,
|
|
686
|
+
inputProps: {
|
|
687
|
+
"data-testid": `${GetFieldDataTestId(fieldName, programName, entityType, entityId)}-link-url`
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
) })
|
|
691
|
+
}
|
|
692
|
+
)
|
|
693
|
+
] }) }) : addNewLink ? null : /* @__PURE__ */ jsx14(
|
|
694
|
+
ListItem,
|
|
695
|
+
{
|
|
696
|
+
className: "document-link-item",
|
|
697
|
+
disableGutters: true,
|
|
698
|
+
secondaryAction: !readOnly ? /* @__PURE__ */ jsxs6("div", { style: { display: "flex", gap: "2px" }, children: [
|
|
699
|
+
/* @__PURE__ */ jsx14(Tooltip, { title: edit, children: /* @__PURE__ */ jsx14(IconButton3, { size: "small", "aria-label": edit, onClick: onEditDocumentLink, children: "\u270E" }) }),
|
|
700
|
+
/* @__PURE__ */ jsx14(Tooltip, { title: deleteLabel, children: /* @__PURE__ */ jsx14(IconButton3, { size: "small", "aria-label": deleteLabel, onClick: onDelete, children: "\u{1F5D1}" }) })
|
|
701
|
+
] }) : void 0,
|
|
702
|
+
children: /* @__PURE__ */ jsx14(
|
|
703
|
+
ListItemText,
|
|
704
|
+
{
|
|
705
|
+
primary: /* @__PURE__ */ jsx14("a", { className: "link", href: url, target: "_blank", rel: "noopener noreferrer", children: title })
|
|
706
|
+
}
|
|
707
|
+
)
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
};
|
|
711
|
+
var DocumentLinks = (props) => {
|
|
712
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, setFieldValue } = props;
|
|
713
|
+
const { watch } = useFormContext2();
|
|
714
|
+
const documentLinks = watch(`${fieldName}`);
|
|
715
|
+
const [addNewLink, setAddNewLink] = React3.useState(false);
|
|
716
|
+
const [deleteLinkIndex, setDeleteLinkIndex] = React3.useState(void 0);
|
|
717
|
+
const onUpdateLinks = (newLink, addNew, index) => {
|
|
718
|
+
let newDocumentLinks = [];
|
|
719
|
+
if (addNew && !documentLinks) {
|
|
720
|
+
newDocumentLinks = [newLink];
|
|
721
|
+
} else if (addNew) {
|
|
722
|
+
newDocumentLinks = [...documentLinks, newLink];
|
|
723
|
+
} else {
|
|
724
|
+
newDocumentLinks = [...documentLinks];
|
|
725
|
+
newDocumentLinks[index] = newLink;
|
|
726
|
+
}
|
|
727
|
+
setFieldValue(fieldName, newDocumentLinks);
|
|
728
|
+
};
|
|
729
|
+
const onDeleteLink = (index) => {
|
|
730
|
+
const newDocumentLinks = [...documentLinks];
|
|
731
|
+
newDocumentLinks.splice(index, 1);
|
|
732
|
+
setFieldValue(fieldName, newDocumentLinks);
|
|
733
|
+
};
|
|
734
|
+
const onAddNewLink = () => setAddNewLink(true);
|
|
735
|
+
const onCancelAddLink = () => setAddNewLink(false);
|
|
736
|
+
const onConfirmDeleteLink = (index) => setDeleteLinkIndex(index);
|
|
737
|
+
const onCloseDeleteDialog = () => setDeleteLinkIndex(void 0);
|
|
738
|
+
const commitDeleteLink = () => {
|
|
739
|
+
onDeleteLink(deleteLinkIndex);
|
|
740
|
+
setDeleteLinkIndex(void 0);
|
|
741
|
+
};
|
|
742
|
+
const saveLinks = (newLink, addNew, index) => {
|
|
743
|
+
onUpdateLinks(newLink, addNew, index);
|
|
744
|
+
setAddNewLink(false);
|
|
745
|
+
};
|
|
746
|
+
const links = value;
|
|
747
|
+
return /* @__PURE__ */ jsxs6("div", { className: FieldClassName("hook-document-links", readOnly ? void 0 : error), children: [
|
|
748
|
+
/* @__PURE__ */ jsx14(List, { disablePadding: true, children: links?.length > 0 ? links.map((link, index) => /* @__PURE__ */ jsx14(
|
|
749
|
+
DocumentLinkItem,
|
|
750
|
+
{
|
|
751
|
+
fieldName,
|
|
752
|
+
programName,
|
|
753
|
+
entityType,
|
|
754
|
+
entityId,
|
|
755
|
+
index,
|
|
756
|
+
title: link.title,
|
|
757
|
+
url: link.url,
|
|
758
|
+
saveLinks,
|
|
759
|
+
onConfirmDeleteLink,
|
|
760
|
+
readOnly
|
|
761
|
+
},
|
|
762
|
+
`${link.url}-${index}`
|
|
763
|
+
)) : null }),
|
|
764
|
+
addNewLink ? /* @__PURE__ */ jsx14(
|
|
765
|
+
DocumentLinkItem,
|
|
766
|
+
{
|
|
767
|
+
fieldName,
|
|
768
|
+
programName,
|
|
769
|
+
entityType,
|
|
770
|
+
entityId,
|
|
771
|
+
addNewLink: true,
|
|
772
|
+
saveLinks,
|
|
773
|
+
onCancelAddLink
|
|
774
|
+
}
|
|
775
|
+
) : !readOnly ? /* @__PURE__ */ jsx14("div", { className: "add-link", style: { marginTop: "8px" }, children: /* @__PURE__ */ jsx14(Tooltip, { title: DocumentLinksStrings.addAnotherLink, children: /* @__PURE__ */ jsx14(
|
|
776
|
+
Button2,
|
|
777
|
+
{
|
|
778
|
+
variant: "outlined",
|
|
779
|
+
size: "small",
|
|
780
|
+
onClick: onAddNewLink,
|
|
781
|
+
"data-testid": `${GetFieldDataTestId(fieldName, programName, entityType, entityId)}-add-link`,
|
|
782
|
+
children: links?.length > 0 ? DocumentLinksStrings.addAnotherLink : DocumentLinksStrings.addLink
|
|
783
|
+
}
|
|
784
|
+
) }) }) : null,
|
|
785
|
+
/* @__PURE__ */ jsxs6(Dialog2, { open: deleteLinkIndex !== void 0, onClose: onCloseDeleteDialog, children: [
|
|
786
|
+
/* @__PURE__ */ jsx14(DialogTitle2, { children: DocumentLinksStrings.deleteLink }),
|
|
787
|
+
/* @__PURE__ */ jsx14(DialogContent2, { children: `${DocumentLinksStrings.confirmDeleteLink} ${links?.[deleteLinkIndex]?.title || ""}?` }),
|
|
788
|
+
/* @__PURE__ */ jsxs6(DialogActions2, { children: [
|
|
789
|
+
/* @__PURE__ */ jsx14(Button2, { variant: "outlined", onClick: onCloseDeleteDialog, children: DocumentLinksStrings.cancel }),
|
|
790
|
+
/* @__PURE__ */ jsx14(Button2, { variant: "contained", onClick: commitDeleteLink, children: DocumentLinksStrings.delete })
|
|
791
|
+
] })
|
|
792
|
+
] })
|
|
793
|
+
] });
|
|
794
|
+
};
|
|
795
|
+
var DocumentLinks_default = DocumentLinks;
|
|
796
|
+
|
|
797
|
+
// src/fields/StatusDropdown.tsx
|
|
798
|
+
import { FormControl as FormControl4, Select as Select4, MenuItem as MenuItem4 } from "@mui/material";
|
|
799
|
+
import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
800
|
+
var StatusDot = ({ color }) => /* @__PURE__ */ jsx15(
|
|
801
|
+
"span",
|
|
802
|
+
{
|
|
803
|
+
className: "status-color",
|
|
804
|
+
style: {
|
|
805
|
+
display: "inline-block",
|
|
806
|
+
backgroundColor: color || "transparent",
|
|
807
|
+
width: "12px",
|
|
808
|
+
height: "12px",
|
|
809
|
+
borderRadius: "50%",
|
|
810
|
+
flexShrink: 0,
|
|
811
|
+
marginRight: "8px"
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
);
|
|
815
|
+
var StatusDropdown = (props) => {
|
|
816
|
+
const { fieldName, programName, entityType, entityId, value, readOnly, error, config, options, setFieldValue } = props;
|
|
817
|
+
const statusColors = config?.statusColors ?? {};
|
|
818
|
+
const onChange = (event) => {
|
|
819
|
+
setFieldValue(fieldName, event.target.value);
|
|
820
|
+
};
|
|
821
|
+
return readOnly ? /* @__PURE__ */ jsxs7("div", { className: "hook-read-only-status-dropdown", style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
|
|
822
|
+
/* @__PURE__ */ jsx15(StatusDot, { color: statusColors && value ? statusColors[value] : void 0 }),
|
|
823
|
+
/* @__PURE__ */ jsx15(ReadOnlyText, { fieldName, value })
|
|
824
|
+
] }) : /* @__PURE__ */ jsxs7("div", { className: FieldClassName("hook-status-dropdown", error), style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
|
|
825
|
+
/* @__PURE__ */ jsx15(StatusDot, { color: statusColors && value ? statusColors[value] : void 0 }),
|
|
826
|
+
/* @__PURE__ */ jsx15(FormControl4, { fullWidth: true, size: "small", error: !!error, children: /* @__PURE__ */ jsx15(
|
|
827
|
+
Select4,
|
|
828
|
+
{
|
|
829
|
+
value: value ? String(value) : "",
|
|
830
|
+
onChange,
|
|
831
|
+
displayEmpty: true,
|
|
832
|
+
"data-testid": GetFieldDataTestId(fieldName, programName, entityType, entityId),
|
|
833
|
+
renderValue: (selected) => {
|
|
834
|
+
const option = options?.find((o) => String(o.value) === selected);
|
|
835
|
+
return option?.label ?? "";
|
|
836
|
+
},
|
|
837
|
+
children: options?.map((option) => /* @__PURE__ */ jsxs7(MenuItem4, { value: String(option.value), disabled: option.disabled, children: [
|
|
838
|
+
/* @__PURE__ */ jsx15(StatusDot, { color: statusColors[String(option.value)] }),
|
|
839
|
+
option.label
|
|
840
|
+
] }, String(option.value)))
|
|
841
|
+
}
|
|
842
|
+
) })
|
|
843
|
+
] });
|
|
844
|
+
};
|
|
845
|
+
var StatusDropdown_default = StatusDropdown;
|
|
846
|
+
|
|
847
|
+
// src/fields/readonly/ReadOnly.tsx
|
|
848
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
849
|
+
var ReadOnly = (props) => {
|
|
850
|
+
const { fieldName, value, config } = props;
|
|
851
|
+
return /* @__PURE__ */ jsx16(ReadOnlyText, { fieldName, value, ...config });
|
|
852
|
+
};
|
|
853
|
+
var ReadOnly_default = ReadOnly;
|
|
854
|
+
|
|
855
|
+
// src/fields/readonly/ReadOnlyArray.tsx
|
|
856
|
+
import { Fragment as Fragment7, jsx as jsx17 } from "react/jsx-runtime";
|
|
857
|
+
var ReadOnlyArray = (props) => {
|
|
858
|
+
const { fieldName, value, config } = props;
|
|
859
|
+
return /* @__PURE__ */ jsx17(Fragment7, { children: value?.map((v, i) => /* @__PURE__ */ jsx17(ReadOnlyText, { fieldName, value: v, ...config }, i)) });
|
|
860
|
+
};
|
|
861
|
+
var ReadOnlyArray_default = ReadOnlyArray;
|
|
862
|
+
|
|
863
|
+
// src/fields/readonly/ReadOnlyDateTime.tsx
|
|
864
|
+
import { Typography as Typography3 } from "@mui/material";
|
|
865
|
+
import { Fragment as Fragment8, jsx as jsx18 } from "react/jsx-runtime";
|
|
866
|
+
var ReadOnlyDateTime = (props) => {
|
|
867
|
+
const { config, value } = props;
|
|
868
|
+
return /* @__PURE__ */ jsx18(Fragment8, { children: value ? /* @__PURE__ */ jsx18(Typography3, { variant: "body2", className: "hook-read-only-date-time", component: "span", children: formatDateTime(value, { hideTimestamp: config?.hidetimeStamp }) }) : /* @__PURE__ */ jsx18(Fragment8, { children: "-" }) });
|
|
869
|
+
};
|
|
870
|
+
var ReadOnlyDateTime_default = ReadOnlyDateTime;
|
|
871
|
+
|
|
872
|
+
// src/fields/readonly/ReadOnlyCumulativeNumber.tsx
|
|
873
|
+
import { isEmpty } from "@form-eng/core";
|
|
874
|
+
import React4 from "react";
|
|
875
|
+
import { useFormContext as useFormContext3 } from "react-hook-form";
|
|
876
|
+
import { Fragment as Fragment9, jsx as jsx19 } from "react/jsx-runtime";
|
|
877
|
+
var ReadOnlyCumulativeNumber = (props) => {
|
|
878
|
+
const { fieldName, config } = props;
|
|
879
|
+
const { formState, getValues } = useFormContext3();
|
|
880
|
+
const [value, setValue] = React4.useState();
|
|
881
|
+
const { dependencyFields } = config || {};
|
|
882
|
+
React4.useEffect(() => {
|
|
883
|
+
const formValues = getValues();
|
|
884
|
+
if (!isEmpty(dependencyFields)) {
|
|
885
|
+
let totalCount = 0;
|
|
886
|
+
dependencyFields.map((fn) => {
|
|
887
|
+
totalCount += Number(formValues[fn]) || 0;
|
|
888
|
+
});
|
|
889
|
+
setValue(totalCount);
|
|
890
|
+
}
|
|
891
|
+
}, [formState]);
|
|
892
|
+
return fieldName ? /* @__PURE__ */ jsx19(ReadOnlyText, { fieldName, value: String(value), ...config }) : /* @__PURE__ */ jsx19(Fragment9, {});
|
|
893
|
+
};
|
|
894
|
+
var ReadOnlyCumulativeNumber_default = ReadOnlyCumulativeNumber;
|
|
895
|
+
|
|
896
|
+
// src/fields/readonly/ReadOnlyRichText.tsx
|
|
897
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
898
|
+
var ReadOnlyRichText = (props) => {
|
|
899
|
+
const { value } = props;
|
|
900
|
+
return /* @__PURE__ */ jsx20(
|
|
901
|
+
"div",
|
|
902
|
+
{
|
|
903
|
+
className: "hook-read-only-rich-text-editor",
|
|
904
|
+
dangerouslySetInnerHTML: { __html: value || "" }
|
|
905
|
+
}
|
|
906
|
+
);
|
|
907
|
+
};
|
|
908
|
+
var ReadOnlyRichText_default = ReadOnlyRichText;
|
|
909
|
+
|
|
910
|
+
// src/fields/readonly/ReadOnlyWithButton.tsx
|
|
911
|
+
import { Button as Button3 } from "@mui/material";
|
|
912
|
+
import { jsx as jsx21, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
913
|
+
var ReadOnlyWithButton = (props) => {
|
|
914
|
+
const { fieldName, value, config } = props;
|
|
915
|
+
return /* @__PURE__ */ jsxs8("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, className: config?.containerClassName, children: [
|
|
916
|
+
/* @__PURE__ */ jsx21(ReadOnlyText, { fieldName, value: `${value}` }),
|
|
917
|
+
config?.buttonText && /* @__PURE__ */ jsx21(Button3, { variant: "outlined", size: "small", onClick: config.onButtonClick, children: config.buttonText })
|
|
918
|
+
] });
|
|
919
|
+
};
|
|
920
|
+
var ReadOnlyWithButton_default = ReadOnlyWithButton;
|
|
921
|
+
|
|
922
|
+
// src/components/FormLoading.tsx
|
|
923
|
+
import { FormConstants as FormConstants2 } from "@form-eng/core";
|
|
924
|
+
import { Skeleton } from "@mui/material";
|
|
925
|
+
import { jsx as jsx22, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
926
|
+
var FormLoading = (props) => {
|
|
927
|
+
const { loadingShimmerCount, loadingFieldShimmerHeight, inPanel, hideTitleShimmer } = props;
|
|
928
|
+
return /* @__PURE__ */ jsx22("div", { className: `fe-loading ${inPanel ? "in-panel" : ""}`, children: [...Array(loadingShimmerCount || FormConstants2.loadingShimmerCount)].map((_, i) => /* @__PURE__ */ jsxs9("div", { className: "form-field-loading", style: { marginBottom: "16px" }, children: [
|
|
929
|
+
!hideTitleShimmer && /* @__PURE__ */ jsx22(Skeleton, { variant: "text", width: "33%" }),
|
|
930
|
+
/* @__PURE__ */ jsx22(
|
|
931
|
+
Skeleton,
|
|
932
|
+
{
|
|
933
|
+
variant: "rectangular",
|
|
934
|
+
height: loadingFieldShimmerHeight || FormConstants2.loadingFieldShimmerHeight
|
|
935
|
+
}
|
|
936
|
+
)
|
|
937
|
+
] }, `fe-loading-${i}`)) });
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
// src/registry.ts
|
|
941
|
+
import { ComponentTypes } from "@form-eng/core";
|
|
942
|
+
import React5 from "react";
|
|
943
|
+
function createMuiFieldRegistry() {
|
|
944
|
+
return {
|
|
945
|
+
[ComponentTypes.Textbox]: React5.createElement(Textbox_default),
|
|
946
|
+
[ComponentTypes.Number]: React5.createElement(Number_default),
|
|
947
|
+
[ComponentTypes.Toggle]: React5.createElement(Toggle_default),
|
|
948
|
+
[ComponentTypes.Dropdown]: React5.createElement(Dropdown_default),
|
|
949
|
+
[ComponentTypes.MultiSelect]: React5.createElement(MultiSelect_default),
|
|
950
|
+
[ComponentTypes.DateControl]: React5.createElement(DateControl_default),
|
|
951
|
+
[ComponentTypes.Slider]: React5.createElement(Slider_default),
|
|
952
|
+
[ComponentTypes.Fragment]: React5.createElement(DynamicFragment_default),
|
|
953
|
+
[ComponentTypes.SimpleDropdown]: React5.createElement(SimpleDropdown_default),
|
|
954
|
+
[ComponentTypes.MultiSelectSearch]: React5.createElement(MultiSelectSearch_default),
|
|
955
|
+
[ComponentTypes.Textarea]: React5.createElement(PopOutEditor_default),
|
|
956
|
+
[ComponentTypes.DocumentLinks]: React5.createElement(DocumentLinks_default),
|
|
957
|
+
[ComponentTypes.StatusDropdown]: React5.createElement(StatusDropdown_default),
|
|
958
|
+
[ComponentTypes.ReadOnly]: React5.createElement(ReadOnly_default),
|
|
959
|
+
[ComponentTypes.ReadOnlyArray]: React5.createElement(ReadOnlyArray_default),
|
|
960
|
+
[ComponentTypes.ReadOnlyDateTime]: React5.createElement(ReadOnlyDateTime_default),
|
|
961
|
+
[ComponentTypes.ReadOnlyCumulativeNumber]: React5.createElement(ReadOnlyCumulativeNumber_default),
|
|
962
|
+
[ComponentTypes.ReadOnlyRichText]: React5.createElement(ReadOnlyRichText_default),
|
|
963
|
+
[ComponentTypes.ReadOnlyWithButton]: React5.createElement(ReadOnlyWithButton_default)
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
export {
|
|
967
|
+
DateControl_default as DateControl,
|
|
968
|
+
DocumentLinks_default as DocumentLinks,
|
|
969
|
+
DocumentLinksStrings,
|
|
970
|
+
Dropdown_default as Dropdown,
|
|
971
|
+
DynamicFragment_default as DynamicFragment,
|
|
972
|
+
FieldClassName,
|
|
973
|
+
FormLoading,
|
|
974
|
+
GetFieldDataTestId,
|
|
975
|
+
MultiSelect_default as MultiSelect,
|
|
976
|
+
MultiSelectSearch_default as MultiSelectSearch,
|
|
977
|
+
Number_default as Number,
|
|
978
|
+
PopOutEditor_default as PopOutEditor,
|
|
979
|
+
ReadOnly_default as ReadOnly,
|
|
980
|
+
ReadOnlyArray_default as ReadOnlyArray,
|
|
981
|
+
ReadOnlyCumulativeNumber_default as ReadOnlyCumulativeNumber,
|
|
982
|
+
ReadOnlyDateTime_default as ReadOnlyDateTime,
|
|
983
|
+
ReadOnlyRichText_default as ReadOnlyRichText,
|
|
984
|
+
ReadOnlyText,
|
|
985
|
+
ReadOnlyWithButton_default as ReadOnlyWithButton,
|
|
986
|
+
SimpleDropdown_default as SimpleDropdown,
|
|
987
|
+
Slider_default as Slider,
|
|
988
|
+
StatusDropdown_default as StatusDropdown,
|
|
989
|
+
StatusMessage,
|
|
990
|
+
Textbox_default as Textbox,
|
|
991
|
+
Toggle_default as Toggle,
|
|
992
|
+
createMuiFieldRegistry,
|
|
993
|
+
formatDateTime
|
|
994
|
+
};
|
|
995
|
+
//# sourceMappingURL=index.mjs.map
|