@form-engine-ts/react 4.7.0 → 5.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 +15 -2
- package/dist/index.cjs +560 -422
- package/dist/index.d.cts +62 -9
- package/dist/index.d.ts +62 -9
- package/dist/index.js +412 -275
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,8 @@ __export(index_exports, {
|
|
|
23
23
|
BUILDER_TRANSLATION_ALIASES: () => BUILDER_TRANSLATION_ALIASES,
|
|
24
24
|
BUILDER_TRANSLATION_KEYS: () => BUILDER_TRANSLATION_KEYS,
|
|
25
25
|
FormBuilder: () => FormBuilder,
|
|
26
|
+
FormEngineI18nContext: () => FormEngineI18nContext,
|
|
27
|
+
FormEngineI18nProvider: () => FormEngineI18nProvider,
|
|
26
28
|
FormProvider: () => FormProvider,
|
|
27
29
|
FormRenderer: () => FormRenderer,
|
|
28
30
|
FormSubmissionError: () => FormSubmissionError,
|
|
@@ -38,6 +40,7 @@ __export(index_exports, {
|
|
|
38
40
|
useField: () => useField,
|
|
39
41
|
useForm: () => useForm,
|
|
40
42
|
useFormBuilder: () => useFormBuilder,
|
|
43
|
+
useFormEngineI18n: () => useFormEngineI18n,
|
|
41
44
|
useSubmissionReceipts: () => useSubmissionReceipts,
|
|
42
45
|
useTranslationWorkspace: () => useTranslationWorkspace,
|
|
43
46
|
validateLocalePipeline: () => validateLocalePipeline
|
|
@@ -144,8 +147,8 @@ function createLocalStorageSubmissionAttemptStore(options = {}) {
|
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
// src/builder.tsx
|
|
147
|
-
var
|
|
148
|
-
var
|
|
150
|
+
var import_core3 = require("@form-engine-ts/core");
|
|
151
|
+
var import_react3 = require("react");
|
|
149
152
|
|
|
150
153
|
// src/hooks/useFormBuilder.ts
|
|
151
154
|
var import_core = require("@form-engine-ts/core");
|
|
@@ -960,8 +963,42 @@ function resolveTranslation(key, aliases, adapter, defaultCatalog, params = {},
|
|
|
960
963
|
return key;
|
|
961
964
|
}
|
|
962
965
|
|
|
963
|
-
// src/
|
|
966
|
+
// src/i18n/provider.tsx
|
|
967
|
+
var import_core2 = require("@form-engine-ts/core");
|
|
968
|
+
var import_react2 = require("react");
|
|
964
969
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
970
|
+
var defaultTranslator = (0, import_core2.createFormEngineTranslator)({ locale: "ja" });
|
|
971
|
+
var FormEngineI18nContext = (0, import_react2.createContext)({
|
|
972
|
+
uiLocale: "ja",
|
|
973
|
+
translator: defaultTranslator
|
|
974
|
+
});
|
|
975
|
+
var FormEngineI18nProviderScopeContext = (0, import_react2.createContext)(false);
|
|
976
|
+
function FormEngineI18nProvider({
|
|
977
|
+
locale = "ja",
|
|
978
|
+
fallbackLocale = "en",
|
|
979
|
+
messages,
|
|
980
|
+
customCatalogs,
|
|
981
|
+
translator: customTranslator,
|
|
982
|
+
children
|
|
983
|
+
}) {
|
|
984
|
+
const translator = (0, import_react2.useMemo)(() => {
|
|
985
|
+
if (customTranslator !== void 0) return customTranslator;
|
|
986
|
+
return (0, import_core2.createFormEngineTranslator)({
|
|
987
|
+
locale,
|
|
988
|
+
fallbackLocale,
|
|
989
|
+
...messages === void 0 ? {} : { messages },
|
|
990
|
+
...customCatalogs === void 0 ? {} : { customCatalogs }
|
|
991
|
+
});
|
|
992
|
+
}, [customCatalogs, customTranslator, fallbackLocale, locale, messages]);
|
|
993
|
+
const value = (0, import_react2.useMemo)(() => ({ uiLocale: locale, translator }), [locale, translator]);
|
|
994
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormEngineI18nProviderScopeContext.Provider, { value: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormEngineI18nContext.Provider, { value, children }) });
|
|
995
|
+
}
|
|
996
|
+
function useFormEngineI18n() {
|
|
997
|
+
return (0, import_react2.useContext)(FormEngineI18nContext);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// src/builder.tsx
|
|
1001
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
965
1002
|
function DefaultButton({
|
|
966
1003
|
id,
|
|
967
1004
|
className,
|
|
@@ -975,7 +1012,7 @@ function DefaultButton({
|
|
|
975
1012
|
action,
|
|
976
1013
|
targetId
|
|
977
1014
|
}) {
|
|
978
|
-
return /* @__PURE__ */ (0,
|
|
1015
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
979
1016
|
"button",
|
|
980
1017
|
{
|
|
981
1018
|
id,
|
|
@@ -994,7 +1031,7 @@ function DefaultButton({
|
|
|
994
1031
|
);
|
|
995
1032
|
}
|
|
996
1033
|
function DefaultIconButton(props) {
|
|
997
|
-
return /* @__PURE__ */ (0,
|
|
1034
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
998
1035
|
DefaultButton,
|
|
999
1036
|
{
|
|
1000
1037
|
...props.id === void 0 ? {} : { id: props.id },
|
|
@@ -1073,10 +1110,10 @@ function DefaultTextInput({
|
|
|
1073
1110
|
max,
|
|
1074
1111
|
step
|
|
1075
1112
|
}) {
|
|
1076
|
-
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0,
|
|
1077
|
-
return /* @__PURE__ */ (0,
|
|
1113
|
+
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: id, children: label });
|
|
1114
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1078
1115
|
labelElement,
|
|
1079
|
-
/* @__PURE__ */ (0,
|
|
1116
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1080
1117
|
"input",
|
|
1081
1118
|
{
|
|
1082
1119
|
id,
|
|
@@ -1100,7 +1137,7 @@ function DefaultTextInput({
|
|
|
1100
1137
|
onChange: (event) => onChange(event.currentTarget.value)
|
|
1101
1138
|
}
|
|
1102
1139
|
),
|
|
1103
|
-
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0,
|
|
1140
|
+
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { id: ariaDescribedBy, children: helperText })
|
|
1104
1141
|
] });
|
|
1105
1142
|
}
|
|
1106
1143
|
function DefaultTextArea({
|
|
@@ -1122,10 +1159,10 @@ function DefaultTextArea({
|
|
|
1122
1159
|
placeholder,
|
|
1123
1160
|
maxLength
|
|
1124
1161
|
}) {
|
|
1125
|
-
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0,
|
|
1126
|
-
return /* @__PURE__ */ (0,
|
|
1162
|
+
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: id, children: label });
|
|
1163
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1127
1164
|
labelElement,
|
|
1128
|
-
/* @__PURE__ */ (0,
|
|
1165
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1129
1166
|
"textarea",
|
|
1130
1167
|
{
|
|
1131
1168
|
id,
|
|
@@ -1145,7 +1182,7 @@ function DefaultTextArea({
|
|
|
1145
1182
|
onChange: (event) => onChange(event.currentTarget.value)
|
|
1146
1183
|
}
|
|
1147
1184
|
),
|
|
1148
|
-
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0,
|
|
1185
|
+
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { id: ariaDescribedBy, children: helperText })
|
|
1149
1186
|
] });
|
|
1150
1187
|
}
|
|
1151
1188
|
function DefaultSelect({
|
|
@@ -1171,10 +1208,10 @@ function DefaultSelect({
|
|
|
1171
1208
|
(option) => typeof option === "string" ? { value: option, label: option } : option
|
|
1172
1209
|
);
|
|
1173
1210
|
const selectedOption = normalizedOptions.find((option) => option.value === value);
|
|
1174
|
-
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0,
|
|
1175
|
-
return /* @__PURE__ */ (0,
|
|
1211
|
+
const labelElement = label === void 0 ? null : id === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: id, children: label });
|
|
1212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1176
1213
|
labelElement,
|
|
1177
|
-
/* @__PURE__ */ (0,
|
|
1214
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1178
1215
|
"select",
|
|
1179
1216
|
{
|
|
1180
1217
|
id,
|
|
@@ -1189,11 +1226,11 @@ function DefaultSelect({
|
|
|
1189
1226
|
value,
|
|
1190
1227
|
onChange: (event) => onChange(event.currentTarget.value),
|
|
1191
1228
|
onKeyDown,
|
|
1192
|
-
children: normalizedOptions.map((option) => /* @__PURE__ */ (0,
|
|
1229
|
+
children: normalizedOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: option.value, disabled: option.disabled, children: renderOption === void 0 ? option.label : renderOption(option) }, option.value))
|
|
1193
1230
|
}
|
|
1194
1231
|
),
|
|
1195
|
-
renderValue === void 0 ? null : /* @__PURE__ */ (0,
|
|
1196
|
-
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0,
|
|
1232
|
+
renderValue === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { children: renderValue(selectedOption) }),
|
|
1233
|
+
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { id: ariaDescribedBy, children: helperText })
|
|
1197
1234
|
] });
|
|
1198
1235
|
}
|
|
1199
1236
|
function DefaultCheckbox({
|
|
@@ -1212,9 +1249,9 @@ function DefaultCheckbox({
|
|
|
1212
1249
|
onChange,
|
|
1213
1250
|
label
|
|
1214
1251
|
}) {
|
|
1215
|
-
return /* @__PURE__ */ (0,
|
|
1216
|
-
/* @__PURE__ */ (0,
|
|
1217
|
-
/* @__PURE__ */ (0,
|
|
1252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1253
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className, children: [
|
|
1254
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1218
1255
|
"input",
|
|
1219
1256
|
{
|
|
1220
1257
|
id,
|
|
@@ -1232,7 +1269,7 @@ function DefaultCheckbox({
|
|
|
1232
1269
|
),
|
|
1233
1270
|
label
|
|
1234
1271
|
] }),
|
|
1235
|
-
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0,
|
|
1272
|
+
helperText === void 0 || helperText.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { id: ariaDescribedBy, children: helperText })
|
|
1236
1273
|
] });
|
|
1237
1274
|
}
|
|
1238
1275
|
function DefaultSection({
|
|
@@ -1245,7 +1282,7 @@ function DefaultSection({
|
|
|
1245
1282
|
onClickCapture,
|
|
1246
1283
|
children
|
|
1247
1284
|
}) {
|
|
1248
|
-
return /* @__PURE__ */ (0,
|
|
1285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1249
1286
|
"section",
|
|
1250
1287
|
{
|
|
1251
1288
|
id,
|
|
@@ -1254,21 +1291,21 @@ function DefaultSection({
|
|
|
1254
1291
|
"aria-labelledby": title === void 0 ? void 0 : headingId,
|
|
1255
1292
|
onClickCapture,
|
|
1256
1293
|
children: [
|
|
1257
|
-
title === void 0 ? null : /* @__PURE__ */ (0,
|
|
1258
|
-
description === void 0 ? null : /* @__PURE__ */ (0,
|
|
1294
|
+
title === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { id: headingId, children: title }),
|
|
1295
|
+
description === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: description }),
|
|
1259
1296
|
children
|
|
1260
1297
|
]
|
|
1261
1298
|
}
|
|
1262
1299
|
);
|
|
1263
1300
|
}
|
|
1264
1301
|
function DefaultFieldset({ className, legend, disabled, children }) {
|
|
1265
|
-
return /* @__PURE__ */ (0,
|
|
1266
|
-
legend === void 0 ? null : /* @__PURE__ */ (0,
|
|
1302
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("fieldset", { className, disabled, children: [
|
|
1303
|
+
legend === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("legend", { children: legend }),
|
|
1267
1304
|
children
|
|
1268
1305
|
] });
|
|
1269
1306
|
}
|
|
1270
1307
|
function DefaultErrorMessage({ className, message }) {
|
|
1271
|
-
return /* @__PURE__ */ (0,
|
|
1308
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className, children: message });
|
|
1272
1309
|
}
|
|
1273
1310
|
var DEFAULT_COMPONENTS = {
|
|
1274
1311
|
Button: DefaultButton,
|
|
@@ -1283,7 +1320,7 @@ var DEFAULT_COMPONENTS = {
|
|
|
1283
1320
|
renderIcon: defaultIconFor,
|
|
1284
1321
|
renderFieldTypeIcon: defaultFieldTypeIcon
|
|
1285
1322
|
};
|
|
1286
|
-
var BuilderPrimitiveContext = (0,
|
|
1323
|
+
var BuilderPrimitiveContext = (0, import_react3.createContext)({
|
|
1287
1324
|
components: DEFAULT_COMPONENTS,
|
|
1288
1325
|
readOnly: false,
|
|
1289
1326
|
unstyled: false
|
|
@@ -1297,9 +1334,9 @@ function primitiveClassName(className, defaultClassName, unstyled) {
|
|
|
1297
1334
|
return [unstyled ? void 0 : defaultClassName, userClassName].filter((value) => value !== void 0).join(" ") || void 0;
|
|
1298
1335
|
}
|
|
1299
1336
|
function BuilderButton(props) {
|
|
1300
|
-
const context = (0,
|
|
1337
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1301
1338
|
const Component = context.components.Button;
|
|
1302
|
-
return /* @__PURE__ */ (0,
|
|
1339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1303
1340
|
Component,
|
|
1304
1341
|
{
|
|
1305
1342
|
...props,
|
|
@@ -1310,10 +1347,10 @@ function BuilderButton(props) {
|
|
|
1310
1347
|
);
|
|
1311
1348
|
}
|
|
1312
1349
|
function BuilderIconButton(props) {
|
|
1313
|
-
const context = (0,
|
|
1350
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1314
1351
|
const Component = context.components.IconButton;
|
|
1315
1352
|
const icon = props.actionType === void 0 ? props.icon ?? void 0 : context.components.renderIcon(props.actionType) ?? props.icon ?? defaultIconFor(props.actionType);
|
|
1316
|
-
return /* @__PURE__ */ (0,
|
|
1353
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1317
1354
|
Component,
|
|
1318
1355
|
{
|
|
1319
1356
|
...props,
|
|
@@ -1325,9 +1362,9 @@ function BuilderIconButton(props) {
|
|
|
1325
1362
|
);
|
|
1326
1363
|
}
|
|
1327
1364
|
function BuilderTextInput(props) {
|
|
1328
|
-
const context = (0,
|
|
1365
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1329
1366
|
const Component = context.components.TextInput;
|
|
1330
|
-
return /* @__PURE__ */ (0,
|
|
1367
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1331
1368
|
Component,
|
|
1332
1369
|
{
|
|
1333
1370
|
...props,
|
|
@@ -1338,9 +1375,9 @@ function BuilderTextInput(props) {
|
|
|
1338
1375
|
);
|
|
1339
1376
|
}
|
|
1340
1377
|
function BuilderTextArea(props) {
|
|
1341
|
-
const context = (0,
|
|
1378
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1342
1379
|
const Component = context.components.TextArea;
|
|
1343
|
-
return /* @__PURE__ */ (0,
|
|
1380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1344
1381
|
Component,
|
|
1345
1382
|
{
|
|
1346
1383
|
...props,
|
|
@@ -1351,9 +1388,9 @@ function BuilderTextArea(props) {
|
|
|
1351
1388
|
);
|
|
1352
1389
|
}
|
|
1353
1390
|
function BuilderSelect(props) {
|
|
1354
|
-
const context = (0,
|
|
1391
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1355
1392
|
const Component = context.components.Select;
|
|
1356
|
-
return /* @__PURE__ */ (0,
|
|
1393
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1357
1394
|
Component,
|
|
1358
1395
|
{
|
|
1359
1396
|
...props,
|
|
@@ -1364,9 +1401,9 @@ function BuilderSelect(props) {
|
|
|
1364
1401
|
);
|
|
1365
1402
|
}
|
|
1366
1403
|
function BuilderCheckbox(props) {
|
|
1367
|
-
const context = (0,
|
|
1404
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1368
1405
|
const Component = context.components.Checkbox;
|
|
1369
|
-
return /* @__PURE__ */ (0,
|
|
1406
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1370
1407
|
Component,
|
|
1371
1408
|
{
|
|
1372
1409
|
...props,
|
|
@@ -1377,18 +1414,18 @@ function BuilderCheckbox(props) {
|
|
|
1377
1414
|
);
|
|
1378
1415
|
}
|
|
1379
1416
|
function BuilderSection(props) {
|
|
1380
|
-
const Component = (0,
|
|
1381
|
-
return /* @__PURE__ */ (0,
|
|
1417
|
+
const Component = (0, import_react3.useContext)(BuilderPrimitiveContext).components.Section;
|
|
1418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ...props });
|
|
1382
1419
|
}
|
|
1383
1420
|
function BuilderFieldset(props) {
|
|
1384
|
-
const context = (0,
|
|
1421
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1385
1422
|
const Component = context.components.Fieldset;
|
|
1386
|
-
return /* @__PURE__ */ (0,
|
|
1423
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ...props, disabled: context.readOnly || props.disabled === true });
|
|
1387
1424
|
}
|
|
1388
1425
|
function BuilderErrorMessage(props) {
|
|
1389
|
-
const context = (0,
|
|
1426
|
+
const context = (0, import_react3.useContext)(BuilderPrimitiveContext);
|
|
1390
1427
|
const Component = context.components.ErrorMessage;
|
|
1391
|
-
return /* @__PURE__ */ (0,
|
|
1428
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: primitiveClassName(props.className, "form-engine-builder__error", context.unstyled), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { message: props.message }) });
|
|
1392
1429
|
}
|
|
1393
1430
|
var GUARDED_COMPONENTS = {
|
|
1394
1431
|
Button: BuilderButton,
|
|
@@ -1556,7 +1593,7 @@ function BuilderSectionGroup({ children }) {
|
|
|
1556
1593
|
return children;
|
|
1557
1594
|
}
|
|
1558
1595
|
function sectionGroupName(node) {
|
|
1559
|
-
if (!(0,
|
|
1596
|
+
if (!(0, import_react3.isValidElement)(node) || node.type !== BuilderSectionGroup) return void 0;
|
|
1560
1597
|
return node.props.name;
|
|
1561
1598
|
}
|
|
1562
1599
|
function OrderedBuilderSections({
|
|
@@ -1565,11 +1602,11 @@ function OrderedBuilderSections({
|
|
|
1565
1602
|
}) {
|
|
1566
1603
|
if (order === void 0) return children;
|
|
1567
1604
|
const ranks = new Map(order.map((name, index) => [name, index]));
|
|
1568
|
-
const groups =
|
|
1605
|
+
const groups = import_react3.Children.toArray(children);
|
|
1569
1606
|
return groups.map((group, index) => ({ group, index, rank: ranks.get(sectionGroupName(group) ?? "questions") ?? order.length })).sort((left, right) => left.rank - right.rank || left.index - right.index).map(({ group }) => group);
|
|
1570
1607
|
}
|
|
1571
1608
|
function fieldTypeKey(type) {
|
|
1572
|
-
return
|
|
1609
|
+
return import_core3.DEFAULT_FIELD_TYPE_DEFINITIONS.find((definition) => definition.type === type)?.labelKey ?? `builder.fieldType.${type}`;
|
|
1573
1610
|
}
|
|
1574
1611
|
function operatorKey(operator) {
|
|
1575
1612
|
return `builder.operator.${operator}`;
|
|
@@ -1654,7 +1691,7 @@ function ConditionValueEditor({
|
|
|
1654
1691
|
if (condition.operator === "not_empty") return null;
|
|
1655
1692
|
const update = (value) => onChange({ ...condition, value });
|
|
1656
1693
|
if (source.type === "checkbox") {
|
|
1657
|
-
return /* @__PURE__ */ (0,
|
|
1694
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1658
1695
|
Select,
|
|
1659
1696
|
{
|
|
1660
1697
|
value: String(condition.value),
|
|
@@ -1667,7 +1704,7 @@ function ConditionValueEditor({
|
|
|
1667
1704
|
);
|
|
1668
1705
|
}
|
|
1669
1706
|
if (source.type === "number" || source.type === "rating") {
|
|
1670
|
-
return /* @__PURE__ */ (0,
|
|
1707
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1671
1708
|
TextInput,
|
|
1672
1709
|
{
|
|
1673
1710
|
"aria-label": translate("builder.conditionValue"),
|
|
@@ -1678,7 +1715,7 @@ function ConditionValueEditor({
|
|
|
1678
1715
|
);
|
|
1679
1716
|
}
|
|
1680
1717
|
if ("options" in source) {
|
|
1681
|
-
return /* @__PURE__ */ (0,
|
|
1718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1682
1719
|
Select,
|
|
1683
1720
|
{
|
|
1684
1721
|
value: String(condition.value ?? ""),
|
|
@@ -1687,7 +1724,7 @@ function ConditionValueEditor({
|
|
|
1687
1724
|
}
|
|
1688
1725
|
);
|
|
1689
1726
|
}
|
|
1690
|
-
return /* @__PURE__ */ (0,
|
|
1727
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1691
1728
|
TextInput,
|
|
1692
1729
|
{
|
|
1693
1730
|
"aria-label": translate("builder.conditionValue"),
|
|
@@ -1707,7 +1744,7 @@ function resolveInitialFieldType(defaultType, allowedTypes) {
|
|
|
1707
1744
|
function FormBuilder({
|
|
1708
1745
|
schema,
|
|
1709
1746
|
onChange,
|
|
1710
|
-
locale
|
|
1747
|
+
locale: explicitLocale,
|
|
1711
1748
|
translator,
|
|
1712
1749
|
translationAdapter,
|
|
1713
1750
|
translationOptions,
|
|
@@ -1734,6 +1771,12 @@ function FormBuilder({
|
|
|
1734
1771
|
onActiveFieldChange,
|
|
1735
1772
|
submissionSettingsOptions
|
|
1736
1773
|
}) {
|
|
1774
|
+
const i18n = useFormEngineI18n();
|
|
1775
|
+
const isProviderValue = (0, import_react3.useContext)(FormEngineI18nProviderScopeContext);
|
|
1776
|
+
const locale = explicitLocale ?? (isProviderValue ? i18n.uiLocale : "en");
|
|
1777
|
+
const resolvedTranslator = translator ?? (isProviderValue ? {
|
|
1778
|
+
translate: (key, _locale, params) => params === void 0 ? i18n.translator(key) : i18n.translator(key, { ...params })
|
|
1779
|
+
} : void 0);
|
|
1737
1780
|
const resolvedComponents = { ...DEFAULT_COMPONENTS, ...componentOverrides };
|
|
1738
1781
|
const components = {
|
|
1739
1782
|
...GUARDED_COMPONENTS,
|
|
@@ -1761,16 +1804,16 @@ function FormBuilder({
|
|
|
1761
1804
|
...defaultActiveFieldId === void 0 ? {} : { defaultActiveFieldId },
|
|
1762
1805
|
...onActiveFieldChange === void 0 ? {} : { onActiveFieldChange }
|
|
1763
1806
|
});
|
|
1764
|
-
const [newPageQuestionId, setNewPageQuestionId] = (0,
|
|
1765
|
-
const [newLocale, setNewLocale] = (0,
|
|
1766
|
-
const [editingLocale, setEditingLocale] = (0,
|
|
1767
|
-
const [isTranslating, setIsTranslating] = (0,
|
|
1768
|
-
const [translationError, setTranslationError] = (0,
|
|
1769
|
-
const [translationReport, setTranslationReport] = (0,
|
|
1807
|
+
const [newPageQuestionId, setNewPageQuestionId] = (0, import_react3.useState)("");
|
|
1808
|
+
const [newLocale, setNewLocale] = (0, import_react3.useState)("");
|
|
1809
|
+
const [editingLocale, setEditingLocale] = (0, import_react3.useState)("");
|
|
1810
|
+
const [isTranslating, setIsTranslating] = (0, import_react3.useState)(false);
|
|
1811
|
+
const [translationError, setTranslationError] = (0, import_react3.useState)(null);
|
|
1812
|
+
const [translationReport, setTranslationReport] = (0, import_react3.useState)();
|
|
1770
1813
|
const translate = (key, params = {}) => resolveTranslation(
|
|
1771
1814
|
key,
|
|
1772
1815
|
BUILDER_TRANSLATION_ALIASES[key] === void 0 ? [] : [BUILDER_TRANSLATION_ALIASES[key]],
|
|
1773
|
-
|
|
1816
|
+
resolvedTranslator,
|
|
1774
1817
|
BUILDER_DEFAULTS,
|
|
1775
1818
|
params,
|
|
1776
1819
|
locale
|
|
@@ -1882,7 +1925,7 @@ function FormBuilder({
|
|
|
1882
1925
|
setTranslationError(null);
|
|
1883
1926
|
try {
|
|
1884
1927
|
const translationPolicy = policy ?? translationOptions?.policy;
|
|
1885
|
-
const populated = await (0,
|
|
1928
|
+
const populated = await (0, import_core3.populateSchemaTranslations)(schema, [editingLocale], translationAdapter, {
|
|
1886
1929
|
overwrite: "missing-only",
|
|
1887
1930
|
...translationOptions,
|
|
1888
1931
|
...translationPolicy === void 0 ? {} : { policy: translationPolicy }
|
|
@@ -2039,11 +2082,11 @@ function FormBuilder({
|
|
|
2039
2082
|
params: { locale: targetLocale }
|
|
2040
2083
|
})
|
|
2041
2084
|
};
|
|
2042
|
-
return /* @__PURE__ */ (0,
|
|
2085
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2043
2086
|
BuilderPrimitiveContext.Provider,
|
|
2044
2087
|
{
|
|
2045
2088
|
value: { components: resolvedComponents, readOnly, unstyled: defaultStylesDisabled },
|
|
2046
|
-
children: /* @__PURE__ */ (0,
|
|
2089
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2047
2090
|
Section,
|
|
2048
2091
|
{
|
|
2049
2092
|
className: defaultStylesDisabled ? className || void 0 : `form-engine-builder ${className}`.trim(),
|
|
@@ -2063,15 +2106,15 @@ function FormBuilder({
|
|
|
2063
2106
|
addOption(fieldId);
|
|
2064
2107
|
}
|
|
2065
2108
|
},
|
|
2066
|
-
children: /* @__PURE__ */ (0,
|
|
2067
|
-
/* @__PURE__ */ (0,
|
|
2109
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Fieldset, { className: builderClass("form-engine-builder__controls"), disabled: readOnly, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(OrderedBuilderSections, { ...resolvedSectionOrder === void 0 ? {} : { order: resolvedSectionOrder }, children: [
|
|
2110
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "basicSettings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2068
2111
|
Section,
|
|
2069
2112
|
{
|
|
2070
2113
|
className: builderClass("form-engine-builder__basic-settings"),
|
|
2071
2114
|
headingId: "builder-basic-settings-heading",
|
|
2072
2115
|
title: translate("builder.basicSettings"),
|
|
2073
|
-
children: /* @__PURE__ */ (0,
|
|
2074
|
-
/* @__PURE__ */ (0,
|
|
2116
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2117
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2075
2118
|
TextInput,
|
|
2076
2119
|
{
|
|
2077
2120
|
id: "builder-form-title",
|
|
@@ -2085,7 +2128,7 @@ function FormBuilder({
|
|
|
2085
2128
|
onChange: (value) => setSourceText({ kind: "form" }, "title", value)
|
|
2086
2129
|
}
|
|
2087
2130
|
) }),
|
|
2088
|
-
/* @__PURE__ */ (0,
|
|
2131
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2089
2132
|
TextArea,
|
|
2090
2133
|
{
|
|
2091
2134
|
id: "builder-form-description",
|
|
@@ -2099,13 +2142,13 @@ function FormBuilder({
|
|
|
2099
2142
|
] })
|
|
2100
2143
|
}
|
|
2101
2144
|
) }),
|
|
2102
|
-
/* @__PURE__ */ (0,
|
|
2145
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "submissionSettings", children: submissionSettingsOptions?.enabled ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2103
2146
|
Section,
|
|
2104
2147
|
{
|
|
2105
2148
|
className: builderClass("form-engine-builder__submission-settings"),
|
|
2106
2149
|
title: translate("builder.submissionSettings"),
|
|
2107
2150
|
children: [
|
|
2108
|
-
/* @__PURE__ */ (0,
|
|
2151
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2109
2152
|
Checkbox,
|
|
2110
2153
|
{
|
|
2111
2154
|
id: "builder-show-confirmation",
|
|
@@ -2117,7 +2160,7 @@ function FormBuilder({
|
|
|
2117
2160
|
})
|
|
2118
2161
|
}
|
|
2119
2162
|
),
|
|
2120
|
-
/* @__PURE__ */ (0,
|
|
2163
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2121
2164
|
Select,
|
|
2122
2165
|
{
|
|
2123
2166
|
id: "builder-confirmation-render-mode",
|
|
@@ -2140,7 +2183,7 @@ function FormBuilder({
|
|
|
2140
2183
|
]
|
|
2141
2184
|
}
|
|
2142
2185
|
) : null }),
|
|
2143
|
-
resolvedSectionOrder === void 0 ? null : /* @__PURE__ */ (0,
|
|
2186
|
+
resolvedSectionOrder === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "completionMessage", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Section, { headingId: "builder-completion-message-heading", title: translate("builder.completionMessage"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2144
2187
|
TextInput,
|
|
2145
2188
|
{
|
|
2146
2189
|
id: "builder-completion-message",
|
|
@@ -2149,27 +2192,27 @@ function FormBuilder({
|
|
|
2149
2192
|
onChange: (value) => setSourceText({ kind: "form" }, "completionMessage", value)
|
|
2150
2193
|
}
|
|
2151
2194
|
) }) }),
|
|
2152
|
-
/* @__PURE__ */ (0,
|
|
2195
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "questions", children: pagesEnabled ? PagesSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2153
2196
|
Section,
|
|
2154
2197
|
{
|
|
2155
2198
|
className: builderClass("form-engine-builder__pages"),
|
|
2156
2199
|
headingId: "builder-pages-heading",
|
|
2157
2200
|
title: translate("builder.pages"),
|
|
2158
|
-
children: schema.pages === void 0 ? /* @__PURE__ */ (0,
|
|
2201
|
+
children: schema.pages === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { onClick: enablePages, children: translate("builder.enablePages") }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2159
2202
|
schema.pages.map((page, pageIndex) => {
|
|
2160
2203
|
const priorQuestionIds = new Set(
|
|
2161
2204
|
schema.pages?.slice(0, pageIndex).flatMap((item) => item.questionIds)
|
|
2162
2205
|
);
|
|
2163
2206
|
const availableSources = schema.fields.filter((field) => priorQuestionIds.has(field.id));
|
|
2164
2207
|
const source = schema.fields.find((field) => field.id === page.displayCondition?.questionId);
|
|
2165
|
-
return /* @__PURE__ */ (0,
|
|
2208
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2166
2209
|
Fieldset,
|
|
2167
2210
|
{
|
|
2168
2211
|
className: builderClass("form-engine-builder__page"),
|
|
2169
2212
|
legend: page.title ?? `${translate("builder.newPage")} ${pageIndex + 1}`,
|
|
2170
2213
|
children: [
|
|
2171
|
-
/* @__PURE__ */ (0,
|
|
2172
|
-
/* @__PURE__ */ (0,
|
|
2214
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__toolbar"), children: ToolbarSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2215
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2173
2216
|
IconButton,
|
|
2174
2217
|
{
|
|
2175
2218
|
actionType: "moveUp",
|
|
@@ -2178,7 +2221,7 @@ function FormBuilder({
|
|
|
2178
2221
|
onClick: () => movePage(pageIndex, -1)
|
|
2179
2222
|
}
|
|
2180
2223
|
),
|
|
2181
|
-
/* @__PURE__ */ (0,
|
|
2224
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2182
2225
|
IconButton,
|
|
2183
2226
|
{
|
|
2184
2227
|
actionType: "moveDown",
|
|
@@ -2187,7 +2230,7 @@ function FormBuilder({
|
|
|
2187
2230
|
onClick: () => movePage(pageIndex, 1)
|
|
2188
2231
|
}
|
|
2189
2232
|
),
|
|
2190
|
-
/* @__PURE__ */ (0,
|
|
2233
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2191
2234
|
IconButton,
|
|
2192
2235
|
{
|
|
2193
2236
|
actionType: "delete",
|
|
@@ -2195,7 +2238,7 @@ function FormBuilder({
|
|
|
2195
2238
|
onClick: () => removePage(pageIndex)
|
|
2196
2239
|
}
|
|
2197
2240
|
)
|
|
2198
|
-
] }) : /* @__PURE__ */ (0,
|
|
2241
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2199
2242
|
ToolbarSlot,
|
|
2200
2243
|
{
|
|
2201
2244
|
schema,
|
|
@@ -2213,8 +2256,8 @@ function FormBuilder({
|
|
|
2213
2256
|
components
|
|
2214
2257
|
}
|
|
2215
2258
|
) }),
|
|
2216
|
-
/* @__PURE__ */ (0,
|
|
2217
|
-
/* @__PURE__ */ (0,
|
|
2259
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2260
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2218
2261
|
TextInput,
|
|
2219
2262
|
{
|
|
2220
2263
|
id: `builder-page-${page.id}-title`,
|
|
@@ -2229,7 +2272,7 @@ function FormBuilder({
|
|
|
2229
2272
|
}
|
|
2230
2273
|
}
|
|
2231
2274
|
) }),
|
|
2232
|
-
/* @__PURE__ */ (0,
|
|
2275
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2233
2276
|
TextInput,
|
|
2234
2277
|
{
|
|
2235
2278
|
id: `builder-page-${page.id}-description`,
|
|
@@ -2245,10 +2288,10 @@ function FormBuilder({
|
|
|
2245
2288
|
}
|
|
2246
2289
|
) })
|
|
2247
2290
|
] }),
|
|
2248
|
-
!localizationEnabled || editingLocale.length === 0 ? null : /* @__PURE__ */ (0,
|
|
2249
|
-
/* @__PURE__ */ (0,
|
|
2250
|
-
/* @__PURE__ */ (0,
|
|
2251
|
-
/* @__PURE__ */ (0,
|
|
2291
|
+
!localizationEnabled || editingLocale.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__translation-editor"), children: [
|
|
2292
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: editingLocale }),
|
|
2293
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2294
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2252
2295
|
TextInput,
|
|
2253
2296
|
{
|
|
2254
2297
|
id: `builder-page-${page.id}-${editingLocale}-title`,
|
|
@@ -2267,7 +2310,7 @@ function FormBuilder({
|
|
|
2267
2310
|
})
|
|
2268
2311
|
}
|
|
2269
2312
|
) }),
|
|
2270
|
-
/* @__PURE__ */ (0,
|
|
2313
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2271
2314
|
TextInput,
|
|
2272
2315
|
{
|
|
2273
2316
|
id: `builder-page-${page.id}-${editingLocale}-description`,
|
|
@@ -2288,8 +2331,8 @@ function FormBuilder({
|
|
|
2288
2331
|
) })
|
|
2289
2332
|
] })
|
|
2290
2333
|
] }),
|
|
2291
|
-
conditionsEnabled ? /* @__PURE__ */ (0,
|
|
2292
|
-
/* @__PURE__ */ (0,
|
|
2334
|
+
conditionsEnabled ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__condition"), children: [
|
|
2335
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2293
2336
|
Select,
|
|
2294
2337
|
{
|
|
2295
2338
|
id: `builder-page-${page.id}-condition`,
|
|
@@ -2318,8 +2361,8 @@ function FormBuilder({
|
|
|
2318
2361
|
]
|
|
2319
2362
|
}
|
|
2320
2363
|
) }),
|
|
2321
|
-
page.displayCondition !== void 0 && source !== void 0 ? /* @__PURE__ */ (0,
|
|
2322
|
-
/* @__PURE__ */ (0,
|
|
2364
|
+
page.displayCondition !== void 0 && source !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2365
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2323
2366
|
Select,
|
|
2324
2367
|
{
|
|
2325
2368
|
"aria-label": translate("builder.conditionOperator"),
|
|
@@ -2341,7 +2384,7 @@ function FormBuilder({
|
|
|
2341
2384
|
}))
|
|
2342
2385
|
}
|
|
2343
2386
|
),
|
|
2344
|
-
/* @__PURE__ */ (0,
|
|
2387
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2345
2388
|
ConditionValueEditor,
|
|
2346
2389
|
{
|
|
2347
2390
|
source,
|
|
@@ -2361,8 +2404,8 @@ function FormBuilder({
|
|
|
2361
2404
|
page.id
|
|
2362
2405
|
);
|
|
2363
2406
|
}),
|
|
2364
|
-
/* @__PURE__ */ (0,
|
|
2365
|
-
/* @__PURE__ */ (0,
|
|
2407
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__page-add"), children: [
|
|
2408
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2366
2409
|
Select,
|
|
2367
2410
|
{
|
|
2368
2411
|
id: "builder-page-question",
|
|
@@ -2376,11 +2419,11 @@ function FormBuilder({
|
|
|
2376
2419
|
]
|
|
2377
2420
|
}
|
|
2378
2421
|
) }),
|
|
2379
|
-
/* @__PURE__ */ (0,
|
|
2422
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { disabled: movablePageQuestions.length === 0, onClick: addPage, children: translate("builder.addPage") })
|
|
2380
2423
|
] })
|
|
2381
2424
|
] })
|
|
2382
2425
|
}
|
|
2383
|
-
) : /* @__PURE__ */ (0,
|
|
2426
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2384
2427
|
PagesSlot,
|
|
2385
2428
|
{
|
|
2386
2429
|
schema,
|
|
@@ -2392,14 +2435,14 @@ function FormBuilder({
|
|
|
2392
2435
|
components
|
|
2393
2436
|
}
|
|
2394
2437
|
) : null }),
|
|
2395
|
-
/* @__PURE__ */ (0,
|
|
2438
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "localization", children: localizationEnabled ? LocalizationSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2396
2439
|
Section,
|
|
2397
2440
|
{
|
|
2398
2441
|
className: builderClass("form-engine-builder__localization"),
|
|
2399
2442
|
headingId: "builder-localization-heading",
|
|
2400
2443
|
title: translate("builder.localization"),
|
|
2401
2444
|
children: [
|
|
2402
|
-
resolvedSectionOrder === void 0 ? /* @__PURE__ */ (0,
|
|
2445
|
+
resolvedSectionOrder === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2403
2446
|
TextInput,
|
|
2404
2447
|
{
|
|
2405
2448
|
id: "builder-completion-message",
|
|
@@ -2408,8 +2451,8 @@ function FormBuilder({
|
|
|
2408
2451
|
onChange: (value) => setSourceText({ kind: "form" }, "completionMessage", value)
|
|
2409
2452
|
}
|
|
2410
2453
|
) }) : null,
|
|
2411
|
-
/* @__PURE__ */ (0,
|
|
2412
|
-
/* @__PURE__ */ (0,
|
|
2454
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2455
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2413
2456
|
TextInput,
|
|
2414
2457
|
{
|
|
2415
2458
|
id: "builder-default-locale",
|
|
@@ -2418,7 +2461,7 @@ function FormBuilder({
|
|
|
2418
2461
|
onChange: setDefaultLocale
|
|
2419
2462
|
}
|
|
2420
2463
|
) }),
|
|
2421
|
-
/* @__PURE__ */ (0,
|
|
2464
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: availableAllowedLocales === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2422
2465
|
TextInput,
|
|
2423
2466
|
{
|
|
2424
2467
|
id: "builder-new-locale",
|
|
@@ -2426,7 +2469,7 @@ function FormBuilder({
|
|
|
2426
2469
|
value: newLocale,
|
|
2427
2470
|
onChange: setNewLocale
|
|
2428
2471
|
}
|
|
2429
|
-
) : /* @__PURE__ */ (0,
|
|
2472
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2430
2473
|
Select,
|
|
2431
2474
|
{
|
|
2432
2475
|
id: "builder-new-locale",
|
|
@@ -2439,7 +2482,7 @@ function FormBuilder({
|
|
|
2439
2482
|
]
|
|
2440
2483
|
}
|
|
2441
2484
|
) }),
|
|
2442
|
-
/* @__PURE__ */ (0,
|
|
2485
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2443
2486
|
Button,
|
|
2444
2487
|
{
|
|
2445
2488
|
action: "addLocale",
|
|
@@ -2448,7 +2491,7 @@ function FormBuilder({
|
|
|
2448
2491
|
children: translate("builder.addLocale")
|
|
2449
2492
|
}
|
|
2450
2493
|
),
|
|
2451
|
-
/* @__PURE__ */ (0,
|
|
2494
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2452
2495
|
Select,
|
|
2453
2496
|
{
|
|
2454
2497
|
id: "builder-edit-locale",
|
|
@@ -2461,14 +2504,14 @@ function FormBuilder({
|
|
|
2461
2504
|
]
|
|
2462
2505
|
}
|
|
2463
2506
|
) }),
|
|
2464
|
-
TranslationActionsSlot === void 0 ? /* @__PURE__ */ (0,
|
|
2507
|
+
TranslationActionsSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2465
2508
|
Button,
|
|
2466
2509
|
{
|
|
2467
2510
|
disabled: translationAdapter === void 0 || editingLocale.length === 0 || isTranslating,
|
|
2468
2511
|
onClick: () => void translateAll(),
|
|
2469
2512
|
children: translate("builder.autoTranslate")
|
|
2470
2513
|
}
|
|
2471
|
-
) : /* @__PURE__ */ (0,
|
|
2514
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2472
2515
|
TranslationActionsSlot,
|
|
2473
2516
|
{
|
|
2474
2517
|
schema,
|
|
@@ -2486,10 +2529,10 @@ function FormBuilder({
|
|
|
2486
2529
|
}
|
|
2487
2530
|
)
|
|
2488
2531
|
] }),
|
|
2489
|
-
translationAdapter === void 0 ? /* @__PURE__ */ (0,
|
|
2490
|
-
translationError === null ? null : /* @__PURE__ */ (0,
|
|
2491
|
-
editingLocale.length === 0 ? null : /* @__PURE__ */ (0,
|
|
2492
|
-
/* @__PURE__ */ (0,
|
|
2532
|
+
translationAdapter === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: translate("builder.translationUnavailable") }) : null,
|
|
2533
|
+
translationError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorMessage, { message: translationError }),
|
|
2534
|
+
editingLocale.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2535
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2493
2536
|
TextInput,
|
|
2494
2537
|
{
|
|
2495
2538
|
id: `builder-${editingLocale}-form-title`,
|
|
@@ -2498,7 +2541,7 @@ function FormBuilder({
|
|
|
2498
2541
|
onChange: (value) => updateFormTranslation("title", value)
|
|
2499
2542
|
}
|
|
2500
2543
|
) }),
|
|
2501
|
-
/* @__PURE__ */ (0,
|
|
2544
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2502
2545
|
TextInput,
|
|
2503
2546
|
{
|
|
2504
2547
|
id: `builder-${editingLocale}-form-description`,
|
|
@@ -2507,7 +2550,7 @@ function FormBuilder({
|
|
|
2507
2550
|
onChange: (value) => updateFormTranslation("description", value)
|
|
2508
2551
|
}
|
|
2509
2552
|
) }),
|
|
2510
|
-
/* @__PURE__ */ (0,
|
|
2553
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2511
2554
|
TextInput,
|
|
2512
2555
|
{
|
|
2513
2556
|
id: `builder-${editingLocale}-completion-message`,
|
|
@@ -2519,7 +2562,7 @@ function FormBuilder({
|
|
|
2519
2562
|
] })
|
|
2520
2563
|
]
|
|
2521
2564
|
}
|
|
2522
|
-
) : /* @__PURE__ */ (0,
|
|
2565
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2523
2566
|
LocalizationSlot,
|
|
2524
2567
|
{
|
|
2525
2568
|
schema,
|
|
@@ -2536,7 +2579,7 @@ function FormBuilder({
|
|
|
2536
2579
|
components
|
|
2537
2580
|
}
|
|
2538
2581
|
) : null }),
|
|
2539
|
-
/* @__PURE__ */ (0,
|
|
2582
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "questions", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__list"), children: schema.fields.map((field, index) => {
|
|
2540
2583
|
const controls = resolveFieldEditorControls(fieldEditorControls);
|
|
2541
2584
|
const editorState = headless.getFieldEditorProps?.(field.id) ?? {
|
|
2542
2585
|
isActive: true,
|
|
@@ -2547,18 +2590,18 @@ function FormBuilder({
|
|
|
2547
2590
|
const source = condition === void 0 ? void 0 : schema.fields.find((item) => item.id === condition.questionId);
|
|
2548
2591
|
const availableSources = schema.fields.slice(0, index);
|
|
2549
2592
|
if (!editorState.isVisible) {
|
|
2550
|
-
return /* @__PURE__ */ (0,
|
|
2593
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2551
2594
|
"div",
|
|
2552
2595
|
{
|
|
2553
2596
|
className: builderClass("form-engine-builder__question-preview"),
|
|
2554
2597
|
"data-field-id": field.id,
|
|
2555
|
-
children: /* @__PURE__ */ (0,
|
|
2598
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: editorState.onSelect, children: field.title })
|
|
2556
2599
|
},
|
|
2557
2600
|
field.id
|
|
2558
2601
|
);
|
|
2559
2602
|
}
|
|
2560
2603
|
if (FieldEditorSlot !== void 0) {
|
|
2561
|
-
return /* @__PURE__ */ (0,
|
|
2604
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2562
2605
|
FieldEditorSlot,
|
|
2563
2606
|
{
|
|
2564
2607
|
schema,
|
|
@@ -2578,14 +2621,14 @@ function FormBuilder({
|
|
|
2578
2621
|
field.id
|
|
2579
2622
|
);
|
|
2580
2623
|
}
|
|
2581
|
-
return /* @__PURE__ */ (0,
|
|
2624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2582
2625
|
Fieldset,
|
|
2583
2626
|
{
|
|
2584
2627
|
className: builderClass("form-engine-builder__question"),
|
|
2585
2628
|
legend: field.title,
|
|
2586
2629
|
children: [
|
|
2587
|
-
/* @__PURE__ */ (0,
|
|
2588
|
-
/* @__PURE__ */ (0,
|
|
2630
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__toolbar"), children: ToolbarSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2631
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2589
2632
|
IconButton,
|
|
2590
2633
|
{
|
|
2591
2634
|
actionType: "moveUp",
|
|
@@ -2594,7 +2637,7 @@ function FormBuilder({
|
|
|
2594
2637
|
onClick: () => moveField(index, -1)
|
|
2595
2638
|
}
|
|
2596
2639
|
),
|
|
2597
|
-
/* @__PURE__ */ (0,
|
|
2640
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2598
2641
|
IconButton,
|
|
2599
2642
|
{
|
|
2600
2643
|
actionType: "moveDown",
|
|
@@ -2603,7 +2646,7 @@ function FormBuilder({
|
|
|
2603
2646
|
onClick: () => moveField(index, 1)
|
|
2604
2647
|
}
|
|
2605
2648
|
),
|
|
2606
|
-
/* @__PURE__ */ (0,
|
|
2649
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2607
2650
|
IconButton,
|
|
2608
2651
|
{
|
|
2609
2652
|
actionType: "delete",
|
|
@@ -2613,7 +2656,7 @@ function FormBuilder({
|
|
|
2613
2656
|
title: translate("builder.delete", { title: field.title })
|
|
2614
2657
|
}
|
|
2615
2658
|
)
|
|
2616
|
-
] }) : /* @__PURE__ */ (0,
|
|
2659
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2617
2660
|
ToolbarSlot,
|
|
2618
2661
|
{
|
|
2619
2662
|
schema,
|
|
@@ -2631,8 +2674,8 @@ function FormBuilder({
|
|
|
2631
2674
|
components
|
|
2632
2675
|
}
|
|
2633
2676
|
) }),
|
|
2634
|
-
/* @__PURE__ */ (0,
|
|
2635
|
-
controls.title === "hidden" ? null : /* @__PURE__ */ (0,
|
|
2677
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2678
|
+
controls.title === "hidden" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2636
2679
|
TextInput,
|
|
2637
2680
|
{
|
|
2638
2681
|
id: `builder-field-${field.id}-title`,
|
|
@@ -2651,7 +2694,7 @@ function FormBuilder({
|
|
|
2651
2694
|
}))
|
|
2652
2695
|
}
|
|
2653
2696
|
) }),
|
|
2654
|
-
controls.typeSelect === "hidden" ? null : /* @__PURE__ */ (0,
|
|
2697
|
+
controls.typeSelect === "hidden" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2655
2698
|
Select,
|
|
2656
2699
|
{
|
|
2657
2700
|
id: `builder-field-${field.id}-type`,
|
|
@@ -2668,7 +2711,7 @@ function FormBuilder({
|
|
|
2668
2711
|
)
|
|
2669
2712
|
}
|
|
2670
2713
|
) }),
|
|
2671
|
-
controls.required === "hidden" ? null : /* @__PURE__ */ (0,
|
|
2714
|
+
controls.required === "hidden" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2672
2715
|
Checkbox,
|
|
2673
2716
|
{
|
|
2674
2717
|
className: builderClass("form-engine-builder__check"),
|
|
@@ -2679,7 +2722,7 @@ function FormBuilder({
|
|
|
2679
2722
|
}
|
|
2680
2723
|
)
|
|
2681
2724
|
] }),
|
|
2682
|
-
controls.description === "hidden" ? null : /* @__PURE__ */ (0,
|
|
2725
|
+
controls.description === "hidden" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2683
2726
|
TextArea,
|
|
2684
2727
|
{
|
|
2685
2728
|
id: `builder-field-${field.id}-description`,
|
|
@@ -2694,7 +2737,7 @@ function FormBuilder({
|
|
|
2694
2737
|
})
|
|
2695
2738
|
}
|
|
2696
2739
|
) }),
|
|
2697
|
-
!pagesEnabled || schema.pages === void 0 ? null : /* @__PURE__ */ (0,
|
|
2740
|
+
!pagesEnabled || schema.pages === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2698
2741
|
Select,
|
|
2699
2742
|
{
|
|
2700
2743
|
id: `builder-field-${field.id}-page`,
|
|
@@ -2707,10 +2750,10 @@ function FormBuilder({
|
|
|
2707
2750
|
}))
|
|
2708
2751
|
}
|
|
2709
2752
|
) }),
|
|
2710
|
-
!localizationEnabled || editingLocale.length === 0 ? null : /* @__PURE__ */ (0,
|
|
2711
|
-
/* @__PURE__ */ (0,
|
|
2712
|
-
/* @__PURE__ */ (0,
|
|
2713
|
-
/* @__PURE__ */ (0,
|
|
2753
|
+
!localizationEnabled || editingLocale.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__translation-editor"), children: [
|
|
2754
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: editingLocale }),
|
|
2755
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2756
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2714
2757
|
TextInput,
|
|
2715
2758
|
{
|
|
2716
2759
|
id: `builder-field-${field.id}-${editingLocale}-title`,
|
|
@@ -2729,7 +2772,7 @@ function FormBuilder({
|
|
|
2729
2772
|
})
|
|
2730
2773
|
}
|
|
2731
2774
|
) }),
|
|
2732
|
-
controls.description === "hidden" ? null : /* @__PURE__ */ (0,
|
|
2775
|
+
controls.description === "hidden" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2733
2776
|
TextInput,
|
|
2734
2777
|
{
|
|
2735
2778
|
id: `builder-field-${field.id}-${editingLocale}-description`,
|
|
@@ -2750,7 +2793,7 @@ function FormBuilder({
|
|
|
2750
2793
|
}
|
|
2751
2794
|
) })
|
|
2752
2795
|
] }),
|
|
2753
|
-
"options" in field ? field.options.map((option, optionIndex) => /* @__PURE__ */ (0,
|
|
2796
|
+
"options" in field ? field.options.map((option, optionIndex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2754
2797
|
TextInput,
|
|
2755
2798
|
{
|
|
2756
2799
|
id: `builder-option-${option.id}-${editingLocale}`,
|
|
@@ -2770,8 +2813,8 @@ function FormBuilder({
|
|
|
2770
2813
|
}
|
|
2771
2814
|
) }, option.id)) : null
|
|
2772
2815
|
] }),
|
|
2773
|
-
field.type === "rating" && controls.ratingBounds !== "hidden" ? /* @__PURE__ */ (0,
|
|
2774
|
-
/* @__PURE__ */ (0,
|
|
2816
|
+
field.type === "rating" && controls.ratingBounds !== "hidden" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2817
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2775
2818
|
TextInput,
|
|
2776
2819
|
{
|
|
2777
2820
|
id: `builder-field-${field.id}-minimum`,
|
|
@@ -2789,7 +2832,7 @@ function FormBuilder({
|
|
|
2789
2832
|
}
|
|
2790
2833
|
}
|
|
2791
2834
|
) }),
|
|
2792
|
-
/* @__PURE__ */ (0,
|
|
2835
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2793
2836
|
TextInput,
|
|
2794
2837
|
{
|
|
2795
2838
|
id: `builder-field-${field.id}-maximum`,
|
|
@@ -2808,8 +2851,8 @@ function FormBuilder({
|
|
|
2808
2851
|
}
|
|
2809
2852
|
) })
|
|
2810
2853
|
] }) : null,
|
|
2811
|
-
(field.type === "text" || field.type === "textarea") && controls.textLimits !== "hidden" ? /* @__PURE__ */ (0,
|
|
2812
|
-
/* @__PURE__ */ (0,
|
|
2854
|
+
(field.type === "text" || field.type === "textarea") && controls.textLimits !== "hidden" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__grid"), children: [
|
|
2855
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2813
2856
|
TextInput,
|
|
2814
2857
|
{
|
|
2815
2858
|
id: `builder-field-${field.id}-min-length`,
|
|
@@ -2824,7 +2867,7 @@ function FormBuilder({
|
|
|
2824
2867
|
})
|
|
2825
2868
|
}
|
|
2826
2869
|
) }),
|
|
2827
|
-
/* @__PURE__ */ (0,
|
|
2870
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2828
2871
|
TextInput,
|
|
2829
2872
|
{
|
|
2830
2873
|
id: `builder-field-${field.id}-max-length`,
|
|
@@ -2839,7 +2882,7 @@ function FormBuilder({
|
|
|
2839
2882
|
})
|
|
2840
2883
|
}
|
|
2841
2884
|
) }),
|
|
2842
|
-
/* @__PURE__ */ (0,
|
|
2885
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2843
2886
|
TextInput,
|
|
2844
2887
|
{
|
|
2845
2888
|
id: `builder-field-${field.id}-pattern`,
|
|
@@ -2853,7 +2896,7 @@ function FormBuilder({
|
|
|
2853
2896
|
}
|
|
2854
2897
|
) })
|
|
2855
2898
|
] }) : null,
|
|
2856
|
-
field.type === "number" && controls.numberLimits !== "hidden" ? /* @__PURE__ */ (0,
|
|
2899
|
+
field.type === "number" && controls.numberLimits !== "hidden" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__grid"), children: ["min", "max", "step"].map((property) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2857
2900
|
TextInput,
|
|
2858
2901
|
{
|
|
2859
2902
|
id: `builder-field-${field.id}-${property}`,
|
|
@@ -2874,11 +2917,11 @@ function FormBuilder({
|
|
|
2874
2917
|
})
|
|
2875
2918
|
}
|
|
2876
2919
|
) }, property)) }) : null,
|
|
2877
|
-
"options" in field && controls.options !== "hidden" ? /* @__PURE__ */ (0,
|
|
2878
|
-
/* @__PURE__ */ (0,
|
|
2920
|
+
"options" in field && controls.options !== "hidden" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__options"), children: [
|
|
2921
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: translate("builder.options") }),
|
|
2879
2922
|
field.options.map(
|
|
2880
|
-
(option, optionIndex) => OptionEditorSlot === void 0 ? /* @__PURE__ */ (0,
|
|
2881
|
-
/* @__PURE__ */ (0,
|
|
2923
|
+
(option, optionIndex) => OptionEditorSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__option"), children: [
|
|
2924
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2882
2925
|
TextInput,
|
|
2883
2926
|
{
|
|
2884
2927
|
id: `builder-option-${option.id}`,
|
|
@@ -2889,8 +2932,8 @@ function FormBuilder({
|
|
|
2889
2932
|
onChange: (value) => value.trim().length === 0 ? void 0 : updateOption(field.id, option.id, value)
|
|
2890
2933
|
}
|
|
2891
2934
|
),
|
|
2892
|
-
ToolbarSlot === void 0 ? /* @__PURE__ */ (0,
|
|
2893
|
-
/* @__PURE__ */ (0,
|
|
2935
|
+
ToolbarSlot === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2936
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2894
2937
|
IconButton,
|
|
2895
2938
|
{
|
|
2896
2939
|
actionType: "moveUp",
|
|
@@ -2899,7 +2942,7 @@ function FormBuilder({
|
|
|
2899
2942
|
onClick: () => moveOption(field.id, option.id, optionIndex - 1)
|
|
2900
2943
|
}
|
|
2901
2944
|
),
|
|
2902
|
-
/* @__PURE__ */ (0,
|
|
2945
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2903
2946
|
IconButton,
|
|
2904
2947
|
{
|
|
2905
2948
|
actionType: "moveDown",
|
|
@@ -2908,7 +2951,7 @@ function FormBuilder({
|
|
|
2908
2951
|
onClick: () => moveOption(field.id, option.id, optionIndex + 1)
|
|
2909
2952
|
}
|
|
2910
2953
|
),
|
|
2911
|
-
/* @__PURE__ */ (0,
|
|
2954
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2912
2955
|
IconButton,
|
|
2913
2956
|
{
|
|
2914
2957
|
actionType: "delete",
|
|
@@ -2917,7 +2960,7 @@ function FormBuilder({
|
|
|
2917
2960
|
title: translate("builder.remove")
|
|
2918
2961
|
}
|
|
2919
2962
|
)
|
|
2920
|
-
] }) : /* @__PURE__ */ (0,
|
|
2963
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2921
2964
|
ToolbarSlot,
|
|
2922
2965
|
{
|
|
2923
2966
|
schema,
|
|
@@ -2935,7 +2978,7 @@ function FormBuilder({
|
|
|
2935
2978
|
components
|
|
2936
2979
|
}
|
|
2937
2980
|
)
|
|
2938
|
-
] }, option.id) : /* @__PURE__ */ (0,
|
|
2981
|
+
] }, option.id) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2939
2982
|
OptionEditorSlot,
|
|
2940
2983
|
{
|
|
2941
2984
|
schema,
|
|
@@ -2951,7 +2994,7 @@ function FormBuilder({
|
|
|
2951
2994
|
option.id
|
|
2952
2995
|
)
|
|
2953
2996
|
),
|
|
2954
|
-
/* @__PURE__ */ (0,
|
|
2997
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2955
2998
|
Button,
|
|
2956
2999
|
{
|
|
2957
3000
|
action: "addOption",
|
|
@@ -2962,8 +3005,8 @@ function FormBuilder({
|
|
|
2962
3005
|
}
|
|
2963
3006
|
)
|
|
2964
3007
|
] }) : null,
|
|
2965
|
-
conditionsEnabled && controls.displayConditions !== "hidden" ? /* @__PURE__ */ (0,
|
|
2966
|
-
/* @__PURE__ */ (0,
|
|
3008
|
+
conditionsEnabled && controls.displayConditions !== "hidden" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: builderClass("form-engine-builder__condition"), children: [
|
|
3009
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: builderClass("form-engine-builder__field"), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2967
3010
|
Select,
|
|
2968
3011
|
{
|
|
2969
3012
|
id: `builder-field-${field.id}-condition`,
|
|
@@ -2989,8 +3032,8 @@ function FormBuilder({
|
|
|
2989
3032
|
]
|
|
2990
3033
|
}
|
|
2991
3034
|
) }),
|
|
2992
|
-
condition !== void 0 && source !== void 0 ? /* @__PURE__ */ (0,
|
|
2993
|
-
/* @__PURE__ */ (0,
|
|
3035
|
+
condition !== void 0 && source !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
3036
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2994
3037
|
Select,
|
|
2995
3038
|
{
|
|
2996
3039
|
"aria-label": translate("builder.conditionOperator"),
|
|
@@ -3008,7 +3051,7 @@ function FormBuilder({
|
|
|
3008
3051
|
}))
|
|
3009
3052
|
}
|
|
3010
3053
|
),
|
|
3011
|
-
/* @__PURE__ */ (0,
|
|
3054
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3012
3055
|
ConditionValueEditor,
|
|
3013
3056
|
{
|
|
3014
3057
|
source,
|
|
@@ -3025,7 +3068,7 @@ function FormBuilder({
|
|
|
3025
3068
|
field.id
|
|
3026
3069
|
);
|
|
3027
3070
|
}) }) }),
|
|
3028
|
-
/* @__PURE__ */ (0,
|
|
3071
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BuilderSectionGroup, { name: "addQuestion", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3029
3072
|
Button,
|
|
3030
3073
|
{
|
|
3031
3074
|
className: builderClass("form-engine-builder__add"),
|
|
@@ -3043,8 +3086,8 @@ function FormBuilder({
|
|
|
3043
3086
|
}
|
|
3044
3087
|
|
|
3045
3088
|
// src/context.tsx
|
|
3046
|
-
var
|
|
3047
|
-
var
|
|
3089
|
+
var import_core4 = require("@form-engine-ts/core");
|
|
3090
|
+
var import_react4 = require("react");
|
|
3048
3091
|
|
|
3049
3092
|
// src/types.ts
|
|
3050
3093
|
var FormSubmissionError = class extends Error {
|
|
@@ -3057,8 +3100,8 @@ var FormSubmissionError = class extends Error {
|
|
|
3057
3100
|
};
|
|
3058
3101
|
|
|
3059
3102
|
// src/context.tsx
|
|
3060
|
-
var
|
|
3061
|
-
var FormContext = (0,
|
|
3103
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3104
|
+
var FormContext = (0, import_react4.createContext)(null);
|
|
3062
3105
|
function issuesByField(issues) {
|
|
3063
3106
|
const result = {};
|
|
3064
3107
|
for (const issue of issues) result[issue.fieldId] ??= issue;
|
|
@@ -3085,31 +3128,31 @@ function FormProvider({
|
|
|
3085
3128
|
onSubmit,
|
|
3086
3129
|
children
|
|
3087
3130
|
}) {
|
|
3088
|
-
const validSchema = (0,
|
|
3089
|
-
(0,
|
|
3090
|
-
const localized = (0,
|
|
3091
|
-
(0,
|
|
3131
|
+
const validSchema = (0, import_react4.useMemo)(() => {
|
|
3132
|
+
(0, import_core4.assertValidFormSchema)(schema);
|
|
3133
|
+
const localized = (0, import_core4.resolveLocalizedSchema)(schema, locale);
|
|
3134
|
+
(0, import_core4.assertValidFormSchema)(localized);
|
|
3092
3135
|
return localized;
|
|
3093
3136
|
}, [locale, schema]);
|
|
3094
|
-
const [values, setValues] = (0,
|
|
3095
|
-
const [errors, setErrors] = (0,
|
|
3096
|
-
const [submitStatus, setSubmitStatus] = (0,
|
|
3097
|
-
const [submitError, setSubmitError] = (0,
|
|
3098
|
-
const [validationPageIndex, setValidationPageIndex] = (0,
|
|
3099
|
-
const submissionInFlight = (0,
|
|
3100
|
-
const visibility = (0,
|
|
3101
|
-
const pageVisibility = (0,
|
|
3102
|
-
(0,
|
|
3137
|
+
const [values, setValues] = (0, import_react4.useState)(() => ({ ...initialValues }));
|
|
3138
|
+
const [errors, setErrors] = (0, import_react4.useState)({});
|
|
3139
|
+
const [submitStatus, setSubmitStatus] = (0, import_react4.useState)("idle");
|
|
3140
|
+
const [submitError, setSubmitError] = (0, import_react4.useState)(null);
|
|
3141
|
+
const [validationPageIndex, setValidationPageIndex] = (0, import_react4.useState)(null);
|
|
3142
|
+
const submissionInFlight = (0, import_react4.useRef)(false);
|
|
3143
|
+
const visibility = (0, import_react4.useMemo)(() => (0, import_core4.calculateFieldVisibility)(validSchema, values), [validSchema, values]);
|
|
3144
|
+
const pageVisibility = (0, import_react4.useMemo)(() => (0, import_core4.calculatePageVisibility)(validSchema, values), [validSchema, values]);
|
|
3145
|
+
(0, import_react4.useEffect)(() => {
|
|
3103
3146
|
const fieldIds = new Set(validSchema.fields.map((field) => field.id));
|
|
3104
3147
|
setValues((current) => Object.fromEntries(Object.entries(current).filter(([fieldId]) => fieldIds.has(fieldId))));
|
|
3105
3148
|
}, [validSchema]);
|
|
3106
|
-
const setValue = (0,
|
|
3149
|
+
const setValue = (0, import_react4.useCallback)(
|
|
3107
3150
|
(fieldId, value) => {
|
|
3108
3151
|
setValues((current) => {
|
|
3109
3152
|
const next = { ...current, [fieldId]: value };
|
|
3110
3153
|
setErrors((currentErrors) => {
|
|
3111
3154
|
if (Object.keys(currentErrors).length === 0) return currentErrors;
|
|
3112
|
-
const result = validationPageIndex === null ? (0,
|
|
3155
|
+
const result = validationPageIndex === null ? (0, import_core4.validateAnswers)(validSchema, next) : (0, import_core4.validatePageAnswers)(validSchema, validationPageIndex, next);
|
|
3113
3156
|
return issuesByField(result.issues);
|
|
3114
3157
|
});
|
|
3115
3158
|
return next;
|
|
@@ -3119,7 +3162,7 @@ function FormProvider({
|
|
|
3119
3162
|
},
|
|
3120
3163
|
[validSchema, validationPageIndex]
|
|
3121
3164
|
);
|
|
3122
|
-
const setServerErrors = (0,
|
|
3165
|
+
const setServerErrors = (0, import_react4.useCallback)((fieldErrors) => {
|
|
3123
3166
|
setErrors(
|
|
3124
3167
|
Object.fromEntries(
|
|
3125
3168
|
Object.entries(fieldErrors).map(([fieldId, message]) => [
|
|
@@ -3130,7 +3173,7 @@ function FormProvider({
|
|
|
3130
3173
|
);
|
|
3131
3174
|
setValidationPageIndex(null);
|
|
3132
3175
|
}, []);
|
|
3133
|
-
const restoreValues = (0,
|
|
3176
|
+
const restoreValues = (0, import_react4.useCallback)(
|
|
3134
3177
|
(restoredValues) => {
|
|
3135
3178
|
const fieldIds = new Set(validSchema.fields.map((field) => field.id));
|
|
3136
3179
|
setValues(Object.fromEntries(Object.entries(restoredValues).filter(([fieldId]) => fieldIds.has(fieldId))));
|
|
@@ -3141,9 +3184,9 @@ function FormProvider({
|
|
|
3141
3184
|
},
|
|
3142
3185
|
[validSchema]
|
|
3143
3186
|
);
|
|
3144
|
-
const validatePage = (0,
|
|
3187
|
+
const validatePage = (0, import_react4.useCallback)(
|
|
3145
3188
|
(pageIndex) => {
|
|
3146
|
-
const result = (0,
|
|
3189
|
+
const result = (0, import_core4.validatePageAnswers)(validSchema, pageIndex, values);
|
|
3147
3190
|
setErrors(issuesByField(result.issues));
|
|
3148
3191
|
setValidationPageIndex(result.valid ? null : pageIndex);
|
|
3149
3192
|
setSubmitStatus("idle");
|
|
@@ -3152,17 +3195,17 @@ function FormProvider({
|
|
|
3152
3195
|
},
|
|
3153
3196
|
[validSchema, values]
|
|
3154
3197
|
);
|
|
3155
|
-
const reset = (0,
|
|
3198
|
+
const reset = (0, import_react4.useCallback)(() => {
|
|
3156
3199
|
setValues({ ...initialValues });
|
|
3157
3200
|
setErrors({});
|
|
3158
3201
|
setValidationPageIndex(null);
|
|
3159
3202
|
setSubmitStatus("idle");
|
|
3160
3203
|
setSubmitError(null);
|
|
3161
3204
|
}, [initialValues]);
|
|
3162
|
-
const submit = (0,
|
|
3205
|
+
const submit = (0, import_react4.useCallback)(
|
|
3163
3206
|
async (beforeSubmit, submitContext) => {
|
|
3164
3207
|
if (submissionInFlight.current) return { status: "cancelled" };
|
|
3165
|
-
const validation = (0,
|
|
3208
|
+
const validation = (0, import_core4.validateAnswers)(validSchema, values);
|
|
3166
3209
|
if (!validation.valid) {
|
|
3167
3210
|
setErrors(issuesByField(validation.issues));
|
|
3168
3211
|
setValidationPageIndex(null);
|
|
@@ -3173,7 +3216,7 @@ function FormProvider({
|
|
|
3173
3216
|
setErrors({});
|
|
3174
3217
|
setValidationPageIndex(null);
|
|
3175
3218
|
setSubmitError(null);
|
|
3176
|
-
const visibleValues = (0,
|
|
3219
|
+
const visibleValues = (0, import_core4.selectVisibleAnswers)(validSchema, values);
|
|
3177
3220
|
submissionInFlight.current = true;
|
|
3178
3221
|
try {
|
|
3179
3222
|
setSubmitStatus("submitting");
|
|
@@ -3206,11 +3249,11 @@ function FormProvider({
|
|
|
3206
3249
|
},
|
|
3207
3250
|
[initialValues, locale, onSubmit, resetOnSuccess, validSchema, values]
|
|
3208
3251
|
);
|
|
3209
|
-
const translate = (0,
|
|
3252
|
+
const translate = (0, import_react4.useCallback)(
|
|
3210
3253
|
(key, params) => translator.translate(key, locale, params) ?? key,
|
|
3211
3254
|
[locale, translator]
|
|
3212
3255
|
);
|
|
3213
|
-
const contextValue = (0,
|
|
3256
|
+
const contextValue = (0, import_react4.useMemo)(
|
|
3214
3257
|
() => ({
|
|
3215
3258
|
schema: validSchema,
|
|
3216
3259
|
locale,
|
|
@@ -3249,10 +3292,10 @@ function FormProvider({
|
|
|
3249
3292
|
visibility
|
|
3250
3293
|
]
|
|
3251
3294
|
);
|
|
3252
|
-
return /* @__PURE__ */ (0,
|
|
3295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FormContext.Provider, { value: contextValue, children });
|
|
3253
3296
|
}
|
|
3254
3297
|
function useForm() {
|
|
3255
|
-
const context = (0,
|
|
3298
|
+
const context = (0, import_react4.useContext)(FormContext);
|
|
3256
3299
|
if (context === null) throw new Error("useForm must be called inside a FormProvider.");
|
|
3257
3300
|
return context;
|
|
3258
3301
|
}
|
|
@@ -3260,13 +3303,13 @@ function useField(fieldId) {
|
|
|
3260
3303
|
const form = useForm();
|
|
3261
3304
|
const field = form.schema.fields.find((item) => item.id === fieldId);
|
|
3262
3305
|
if (field === void 0) throw new Error(`Unknown form field: ${fieldId}`);
|
|
3263
|
-
const setValue = (0,
|
|
3306
|
+
const setValue = (0, import_react4.useCallback)((value) => form.setValue(fieldId, value), [fieldId, form]);
|
|
3264
3307
|
return { field, value: form.values[fieldId], error: form.errors[fieldId], setValue };
|
|
3265
3308
|
}
|
|
3266
3309
|
|
|
3267
3310
|
// src/hooks/useTranslationWorkspace.ts
|
|
3268
|
-
var
|
|
3269
|
-
var
|
|
3311
|
+
var import_core5 = require("@form-engine-ts/core");
|
|
3312
|
+
var import_react5 = require("react");
|
|
3270
3313
|
function updateTranslationMap(translations, locale, property, text) {
|
|
3271
3314
|
if (property === "label") return translations ?? {};
|
|
3272
3315
|
const current = translations?.[locale];
|
|
@@ -3282,20 +3325,9 @@ function asAsyncAdapter(adapter) {
|
|
|
3282
3325
|
)
|
|
3283
3326
|
};
|
|
3284
3327
|
}
|
|
3285
|
-
function isValidBcp47Locale(locale) {
|
|
3286
|
-
const language = locale.split("-")[0];
|
|
3287
|
-
if (language === void 0 || !/^[a-z]{2,3}$/iu.test(language)) return false;
|
|
3288
|
-
try {
|
|
3289
|
-
Intl.getCanonicalLocales(locale);
|
|
3290
|
-
return true;
|
|
3291
|
-
} catch {
|
|
3292
|
-
return false;
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
3328
|
var validateLocalePipeline = (locale, schema, policy, customValidator) => {
|
|
3296
|
-
const
|
|
3297
|
-
|
|
3298
|
-
if (!isValidBcp47Locale(locale)) {
|
|
3329
|
+
const canonicalLocale = (0, import_core5.normalizeLocale)(locale);
|
|
3330
|
+
if (canonicalLocale === null) {
|
|
3299
3331
|
return {
|
|
3300
3332
|
valid: false,
|
|
3301
3333
|
error: {
|
|
@@ -3304,21 +3336,23 @@ var validateLocalePipeline = (locale, schema, policy, customValidator) => {
|
|
|
3304
3336
|
}
|
|
3305
3337
|
};
|
|
3306
3338
|
}
|
|
3307
|
-
|
|
3339
|
+
const currentLocales = (schema.supportedLocales ?? []).map((candidate) => (0, import_core5.normalizeLocale)(candidate) ?? candidate);
|
|
3340
|
+
const defaultLocale = schema.defaultLocale === void 0 ? "" : (0, import_core5.normalizeLocale)(schema.defaultLocale) ?? schema.defaultLocale;
|
|
3341
|
+
if (canonicalLocale === defaultLocale || currentLocales.includes(canonicalLocale)) {
|
|
3308
3342
|
return {
|
|
3309
3343
|
valid: false,
|
|
3310
3344
|
error: {
|
|
3311
3345
|
type: "locale_already_exists",
|
|
3312
|
-
message: `Locale "${
|
|
3346
|
+
message: `Locale "${canonicalLocale}" is already registered.`
|
|
3313
3347
|
}
|
|
3314
3348
|
};
|
|
3315
3349
|
}
|
|
3316
|
-
if (policy?.allowedLocales !== void 0 && !policy.allowedLocales.
|
|
3350
|
+
if (policy?.allowedLocales !== void 0 && !policy.allowedLocales.some((candidate) => (0, import_core5.normalizeLocale)(candidate) === canonicalLocale)) {
|
|
3317
3351
|
return {
|
|
3318
3352
|
valid: false,
|
|
3319
3353
|
error: {
|
|
3320
3354
|
type: "locale_not_allowed",
|
|
3321
|
-
message: `Locale "${
|
|
3355
|
+
message: `Locale "${canonicalLocale}" is not allowed by policy.`
|
|
3322
3356
|
}
|
|
3323
3357
|
};
|
|
3324
3358
|
}
|
|
@@ -3333,8 +3367,13 @@ var validateLocalePipeline = (locale, schema, policy, customValidator) => {
|
|
|
3333
3367
|
};
|
|
3334
3368
|
}
|
|
3335
3369
|
if (customValidator !== void 0) {
|
|
3336
|
-
const
|
|
3337
|
-
|
|
3370
|
+
const context = {
|
|
3371
|
+
locale: canonicalLocale,
|
|
3372
|
+
defaultLocale,
|
|
3373
|
+
currentLocales: Object.freeze([...currentLocales]),
|
|
3374
|
+
...policy === void 0 ? {} : { policy }
|
|
3375
|
+
};
|
|
3376
|
+
const customResult = Reflect.apply(customValidator, void 0, [canonicalLocale, context]);
|
|
3338
3377
|
if (customResult === false) {
|
|
3339
3378
|
return {
|
|
3340
3379
|
valid: false,
|
|
@@ -3354,20 +3393,26 @@ var validateLocalePipeline = (locale, schema, policy, customValidator) => {
|
|
|
3354
3393
|
}
|
|
3355
3394
|
return { valid: true };
|
|
3356
3395
|
};
|
|
3357
|
-
function
|
|
3358
|
-
|
|
3359
|
-
|
|
3396
|
+
function workspaceLocaleValidationError(validation, currentLocales, requestedLocale) {
|
|
3397
|
+
const error = validation.error;
|
|
3398
|
+
if (error === void 0) return { type: "invalid_locale_format", locale: requestedLocale };
|
|
3399
|
+
if (error.type === "locale_not_allowed") return { type: "locale_not_allowed", locale: requestedLocale };
|
|
3400
|
+
if (error.type === "locale_already_exists") {
|
|
3401
|
+
return { type: "locale_already_exists", locale: requestedLocale };
|
|
3360
3402
|
}
|
|
3361
|
-
if (
|
|
3362
|
-
|
|
3363
|
-
return maximum === void 0 ? validation.error.message : `At most ${maximum} locales are allowed by the form policy.`;
|
|
3403
|
+
if (error.type === "invalid_locale_format") {
|
|
3404
|
+
return { type: "invalid_locale_format", locale: requestedLocale };
|
|
3364
3405
|
}
|
|
3365
|
-
|
|
3406
|
+
if (error.type === "max_locales_exceeded") {
|
|
3407
|
+
const max = Number(error.message.match(/\((\d+)\)/u)?.[1] ?? 0);
|
|
3408
|
+
return { type: "max_locales_exceeded", max, current: currentLocales };
|
|
3409
|
+
}
|
|
3410
|
+
return { type: "custom_validation_failed", message: error.message };
|
|
3366
3411
|
}
|
|
3367
3412
|
function manualMetadata(sourceText, sourceLocale) {
|
|
3368
3413
|
return {
|
|
3369
3414
|
sourceLocale,
|
|
3370
|
-
sourceTextHash: (0,
|
|
3415
|
+
sourceTextHash: (0, import_core5.computeSourceTextHash)(sourceText),
|
|
3371
3416
|
translationSource: "manual",
|
|
3372
3417
|
editedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3373
3418
|
};
|
|
@@ -3433,25 +3478,26 @@ function useTranslationWorkspace({
|
|
|
3433
3478
|
translationAdapter,
|
|
3434
3479
|
readOnly = false,
|
|
3435
3480
|
policy,
|
|
3481
|
+
beforeRemoveLocale,
|
|
3436
3482
|
validateLocale
|
|
3437
3483
|
}) {
|
|
3438
|
-
const [draftSchema, setDraftSchema] = (0,
|
|
3439
|
-
const [selectedLocale, setSelectedLocale] = (0,
|
|
3440
|
-
const [isTranslating, setIsTranslating] = (0,
|
|
3441
|
-
const [error, setError] = (0,
|
|
3484
|
+
const [draftSchema, setDraftSchema] = (0, import_react5.useState)(schema);
|
|
3485
|
+
const [selectedLocale, setSelectedLocale] = (0, import_react5.useState)(targetLocale ?? "");
|
|
3486
|
+
const [isTranslating, setIsTranslating] = (0, import_react5.useState)(false);
|
|
3487
|
+
const [error, setError] = (0, import_react5.useState)();
|
|
3442
3488
|
const currentSchema = onChange === void 0 ? draftSchema : schema;
|
|
3443
|
-
const targetLocales = (0,
|
|
3444
|
-
const locales = (0,
|
|
3489
|
+
const targetLocales = (0, import_react5.useMemo)(() => {
|
|
3490
|
+
const locales = (0, import_core5.collectSchemaLocales)(currentSchema).allUniqueLocales;
|
|
3445
3491
|
return [.../* @__PURE__ */ new Set([...currentSchema.supportedLocales ?? [], ...locales])].filter(
|
|
3446
3492
|
(locale) => locale !== sourceLocale
|
|
3447
3493
|
);
|
|
3448
3494
|
}, [currentSchema, sourceLocale]);
|
|
3449
3495
|
const activeLocale = selectedLocale.length > 0 ? selectedLocale : targetLocales[0] ?? "";
|
|
3450
|
-
const slots = (0,
|
|
3451
|
-
() => activeLocale.length === 0 ? [] : (0,
|
|
3496
|
+
const slots = (0, import_react5.useMemo)(
|
|
3497
|
+
() => activeLocale.length === 0 ? [] : (0, import_core5.collectTranslationSlots)(currentSchema, activeLocale),
|
|
3452
3498
|
[activeLocale, currentSchema]
|
|
3453
3499
|
);
|
|
3454
|
-
const summary = (0,
|
|
3500
|
+
const summary = (0, import_react5.useMemo)(() => {
|
|
3455
3501
|
const counts = {
|
|
3456
3502
|
missing: 0,
|
|
3457
3503
|
translated: 0,
|
|
@@ -3470,26 +3516,48 @@ function useTranslationWorkspace({
|
|
|
3470
3516
|
completionPercentage: slots.length === 0 ? 100 : Math.round(complete / slots.length * 100)
|
|
3471
3517
|
};
|
|
3472
3518
|
}, [slots]);
|
|
3473
|
-
const commit = (0,
|
|
3519
|
+
const commit = (0, import_react5.useCallback)(
|
|
3474
3520
|
(next) => {
|
|
3475
3521
|
setDraftSchema(next);
|
|
3476
3522
|
onChange?.(next);
|
|
3477
3523
|
},
|
|
3478
3524
|
[onChange]
|
|
3479
3525
|
);
|
|
3480
|
-
const setTranslation = (0,
|
|
3526
|
+
const setTranslation = (0, import_react5.useCallback)(
|
|
3481
3527
|
(slot, text) => {
|
|
3482
3528
|
if (readOnly) return;
|
|
3483
3529
|
commit(updateSchemaTranslation(currentSchema, slot, text, sourceLocale));
|
|
3484
3530
|
},
|
|
3485
3531
|
[commit, currentSchema, readOnly, sourceLocale]
|
|
3486
3532
|
);
|
|
3487
|
-
const addLocale = (0,
|
|
3533
|
+
const addLocale = (0, import_react5.useCallback)(
|
|
3488
3534
|
(locale) => {
|
|
3489
|
-
if (readOnly)
|
|
3490
|
-
|
|
3535
|
+
if (readOnly) {
|
|
3536
|
+
const workspaceError = { type: "read_only_mode" };
|
|
3537
|
+
setError(workspaceError);
|
|
3538
|
+
return { success: false, error: workspaceError };
|
|
3539
|
+
}
|
|
3540
|
+
const normalized = (0, import_core5.normalizeLocale)(locale);
|
|
3541
|
+
if (normalized === null) {
|
|
3542
|
+
const workspaceError = workspaceLocaleValidationError(
|
|
3543
|
+
validateLocalePipeline(locale, currentSchema, policy, validateLocale),
|
|
3544
|
+
(0, import_core5.collectSchemaLocales)(currentSchema).allUniqueLocales.size,
|
|
3545
|
+
locale
|
|
3546
|
+
);
|
|
3547
|
+
setError(workspaceError);
|
|
3548
|
+
return { success: false, error: workspaceError };
|
|
3549
|
+
}
|
|
3491
3550
|
const validation = validateLocalePipeline(normalized, currentSchema, policy, validateLocale);
|
|
3492
|
-
if (!validation.valid)
|
|
3551
|
+
if (!validation.valid) {
|
|
3552
|
+
const workspaceError = workspaceLocaleValidationError(
|
|
3553
|
+
validation,
|
|
3554
|
+
(0, import_core5.collectSchemaLocales)(currentSchema).allUniqueLocales.size,
|
|
3555
|
+
normalized
|
|
3556
|
+
);
|
|
3557
|
+
setError(workspaceError);
|
|
3558
|
+
return { success: false, error: workspaceError };
|
|
3559
|
+
}
|
|
3560
|
+
setError(void 0);
|
|
3493
3561
|
commit({
|
|
3494
3562
|
...currentSchema,
|
|
3495
3563
|
supportedLocales: [.../* @__PURE__ */ new Set([...currentSchema.supportedLocales ?? [], normalized])]
|
|
@@ -3499,30 +3567,72 @@ function useTranslationWorkspace({
|
|
|
3499
3567
|
},
|
|
3500
3568
|
[commit, currentSchema, policy, readOnly, validateLocale]
|
|
3501
3569
|
);
|
|
3502
|
-
const isAddLocaleAllowed = (0,
|
|
3570
|
+
const isAddLocaleAllowed = (0, import_react5.useCallback)(
|
|
3503
3571
|
(locale) => {
|
|
3504
3572
|
if (readOnly) return false;
|
|
3505
|
-
const normalized =
|
|
3573
|
+
const normalized = (0, import_core5.normalizeLocale)(locale);
|
|
3574
|
+
if (normalized === null) return false;
|
|
3506
3575
|
return validateLocalePipeline(normalized, currentSchema, policy, validateLocale).valid;
|
|
3507
3576
|
},
|
|
3508
3577
|
[currentSchema, policy, readOnly, validateLocale]
|
|
3509
3578
|
);
|
|
3510
|
-
const removeLocale = (0,
|
|
3579
|
+
const removeLocale = (0, import_react5.useCallback)(
|
|
3511
3580
|
(locale) => {
|
|
3512
|
-
if (readOnly || locale === sourceLocale || locale === currentSchema.defaultLocale) return;
|
|
3513
|
-
|
|
3514
|
-
|
|
3581
|
+
if (readOnly || locale === sourceLocale || locale === currentSchema.defaultLocale) return false;
|
|
3582
|
+
const remove = () => {
|
|
3583
|
+
commit((0, import_core5.removeLocaleFromSchema)(currentSchema, locale));
|
|
3584
|
+
if (activeLocale === locale) setSelectedLocale("");
|
|
3585
|
+
};
|
|
3586
|
+
const slotCount = (0, import_core5.collectTranslationSlots)(currentSchema, locale).length;
|
|
3587
|
+
if (beforeRemoveLocale === void 0) {
|
|
3588
|
+
remove();
|
|
3589
|
+
return true;
|
|
3590
|
+
}
|
|
3591
|
+
try {
|
|
3592
|
+
const decision = beforeRemoveLocale(locale, { slotCount });
|
|
3593
|
+
if (typeof decision === "boolean") {
|
|
3594
|
+
if (!decision) return false;
|
|
3595
|
+
remove();
|
|
3596
|
+
return true;
|
|
3597
|
+
}
|
|
3598
|
+
return decision.then((allowed) => {
|
|
3599
|
+
if (!allowed) return false;
|
|
3600
|
+
remove();
|
|
3601
|
+
return true;
|
|
3602
|
+
});
|
|
3603
|
+
} catch (cause) {
|
|
3604
|
+
const workspaceError = {
|
|
3605
|
+
type: "translation_failed",
|
|
3606
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
3607
|
+
cause
|
|
3608
|
+
};
|
|
3609
|
+
setError(workspaceError);
|
|
3610
|
+
return Promise.reject(cause);
|
|
3611
|
+
}
|
|
3515
3612
|
},
|
|
3516
|
-
[activeLocale, commit, currentSchema, readOnly, sourceLocale]
|
|
3613
|
+
[activeLocale, beforeRemoveLocale, commit, currentSchema, readOnly, sourceLocale]
|
|
3517
3614
|
);
|
|
3518
|
-
const translateAll = (0,
|
|
3615
|
+
const translateAll = (0, import_react5.useCallback)(
|
|
3519
3616
|
async (options = {}) => {
|
|
3520
|
-
if (
|
|
3521
|
-
|
|
3617
|
+
if (readOnly) {
|
|
3618
|
+
const workspaceError = { type: "read_only_mode" };
|
|
3619
|
+
setError(workspaceError);
|
|
3620
|
+
return { success: false, error: workspaceError };
|
|
3621
|
+
}
|
|
3622
|
+
if (translationAdapter === void 0) {
|
|
3623
|
+
const workspaceError = { type: "adapter_not_configured" };
|
|
3624
|
+
setError(workspaceError);
|
|
3625
|
+
return { success: false, error: workspaceError };
|
|
3626
|
+
}
|
|
3627
|
+
if (activeLocale.length === 0) {
|
|
3628
|
+
const workspaceError = { type: "target_locale_missing" };
|
|
3629
|
+
setError(workspaceError);
|
|
3630
|
+
return { success: false, error: workspaceError };
|
|
3631
|
+
}
|
|
3522
3632
|
setIsTranslating(true);
|
|
3523
3633
|
setError(void 0);
|
|
3524
3634
|
try {
|
|
3525
|
-
const populated = await (0,
|
|
3635
|
+
const populated = await (0, import_core5.populateSchemaTranslations)(
|
|
3526
3636
|
currentSchema,
|
|
3527
3637
|
[activeLocale],
|
|
3528
3638
|
asAsyncAdapter(translationAdapter),
|
|
@@ -3533,30 +3643,47 @@ function useTranslationWorkspace({
|
|
|
3533
3643
|
}
|
|
3534
3644
|
);
|
|
3535
3645
|
commit(populated.schema);
|
|
3536
|
-
return populated.report;
|
|
3646
|
+
return { success: true, report: populated.report };
|
|
3537
3647
|
} catch (cause) {
|
|
3538
|
-
const
|
|
3539
|
-
|
|
3540
|
-
|
|
3648
|
+
const workspaceError = {
|
|
3649
|
+
type: "translation_failed",
|
|
3650
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
3651
|
+
cause
|
|
3652
|
+
};
|
|
3653
|
+
setError(workspaceError);
|
|
3654
|
+
return { success: false, error: workspaceError };
|
|
3541
3655
|
} finally {
|
|
3542
3656
|
setIsTranslating(false);
|
|
3543
3657
|
}
|
|
3544
3658
|
},
|
|
3545
|
-
[activeLocale, commit, currentSchema, translationAdapter]
|
|
3659
|
+
[activeLocale, commit, currentSchema, readOnly, translationAdapter]
|
|
3546
3660
|
);
|
|
3547
|
-
const translateSlot = (0,
|
|
3661
|
+
const translateSlot = (0, import_react5.useCallback)(
|
|
3548
3662
|
async (slot) => {
|
|
3549
|
-
if (translationAdapter === void 0)
|
|
3550
|
-
|
|
3663
|
+
if (translationAdapter === void 0) {
|
|
3664
|
+
const workspaceError = { type: "adapter_not_configured" };
|
|
3665
|
+
setError(workspaceError);
|
|
3666
|
+
return { success: false, error: workspaceError };
|
|
3667
|
+
}
|
|
3668
|
+
if (readOnly) {
|
|
3669
|
+
const workspaceError = { type: "read_only_mode" };
|
|
3670
|
+
setError(workspaceError);
|
|
3671
|
+
return { success: false, error: workspaceError };
|
|
3672
|
+
}
|
|
3551
3673
|
setIsTranslating(true);
|
|
3552
3674
|
setError(void 0);
|
|
3553
3675
|
try {
|
|
3554
3676
|
const text = await asAsyncAdapter(translationAdapter).translateText(slot.sourceText, slot.locale, sourceLocale);
|
|
3555
3677
|
commit(updateSchemaTranslation(currentSchema, slot, text, sourceLocale));
|
|
3678
|
+
return { success: true };
|
|
3556
3679
|
} catch (cause) {
|
|
3557
|
-
const
|
|
3558
|
-
|
|
3559
|
-
|
|
3680
|
+
const workspaceError = {
|
|
3681
|
+
type: "translation_failed",
|
|
3682
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
3683
|
+
cause
|
|
3684
|
+
};
|
|
3685
|
+
setError(workspaceError);
|
|
3686
|
+
return { success: false, error: workspaceError };
|
|
3560
3687
|
} finally {
|
|
3561
3688
|
setIsTranslating(false);
|
|
3562
3689
|
}
|
|
@@ -3582,7 +3709,7 @@ function useTranslationWorkspace({
|
|
|
3582
3709
|
}
|
|
3583
3710
|
|
|
3584
3711
|
// src/receipt.ts
|
|
3585
|
-
var
|
|
3712
|
+
var import_react6 = require("react");
|
|
3586
3713
|
function submissionReceiptQueryKey(formId, formVersion) {
|
|
3587
3714
|
return `${formId}:v${formVersion}`;
|
|
3588
3715
|
}
|
|
@@ -3653,19 +3780,19 @@ function createLocalStorageSubmissionReceiptStore(options = {}) {
|
|
|
3653
3780
|
}
|
|
3654
3781
|
function useSubmissionReceipts(store, queries) {
|
|
3655
3782
|
const querySignature = JSON.stringify(queries.map(({ formId, formVersion }) => [formId, formVersion]));
|
|
3656
|
-
const stableQueries = (0,
|
|
3783
|
+
const stableQueries = (0, import_react6.useMemo)(() => {
|
|
3657
3784
|
const parsed = JSON.parse(querySignature);
|
|
3658
3785
|
if (!Array.isArray(parsed)) return [];
|
|
3659
3786
|
return parsed.flatMap(
|
|
3660
3787
|
(entry) => Array.isArray(entry) && typeof entry[0] === "string" && typeof entry[1] === "number" && Number.isSafeInteger(entry[1]) ? [{ formId: entry[0], formVersion: entry[1] }] : []
|
|
3661
3788
|
);
|
|
3662
3789
|
}, [querySignature]);
|
|
3663
|
-
const [state, setState] = (0,
|
|
3790
|
+
const [state, setState] = (0, import_react6.useState)({
|
|
3664
3791
|
receipts: /* @__PURE__ */ new Map(),
|
|
3665
3792
|
isLoading: stableQueries.length > 0,
|
|
3666
3793
|
error: null
|
|
3667
3794
|
});
|
|
3668
|
-
(0,
|
|
3795
|
+
(0, import_react6.useEffect)(() => {
|
|
3669
3796
|
let active = true;
|
|
3670
3797
|
if (stableQueries.length === 0) {
|
|
3671
3798
|
setState({ receipts: /* @__PURE__ */ new Map(), isLoading: false, error: null });
|
|
@@ -3699,9 +3826,9 @@ function useSubmissionReceipts(store, queries) {
|
|
|
3699
3826
|
}
|
|
3700
3827
|
|
|
3701
3828
|
// src/renderer.tsx
|
|
3702
|
-
var
|
|
3703
|
-
var
|
|
3704
|
-
var
|
|
3829
|
+
var import_core6 = require("@form-engine-ts/core");
|
|
3830
|
+
var import_react7 = require("react");
|
|
3831
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
3705
3832
|
var isChoiceFieldType = (type) => type === "radio" || type === "checkbox" || type === "multi-select" || type === "select";
|
|
3706
3833
|
function resolveChoiceFieldLayout(type, appearance, groupedChoiceFieldsLegacy = false) {
|
|
3707
3834
|
if (groupedChoiceFieldsLegacy) return "grouped";
|
|
@@ -3720,22 +3847,22 @@ function RequiredMark({
|
|
|
3720
3847
|
required,
|
|
3721
3848
|
className = "fe-required"
|
|
3722
3849
|
}) {
|
|
3723
|
-
return required ? /* @__PURE__ */ (0,
|
|
3850
|
+
return required ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className, "aria-hidden": "true", children: [
|
|
3724
3851
|
" ",
|
|
3725
3852
|
"*"
|
|
3726
3853
|
] }) : null;
|
|
3727
3854
|
}
|
|
3728
3855
|
function FieldMessage({ props }) {
|
|
3729
|
-
return /* @__PURE__ */ (0,
|
|
3730
|
-
props.field.description === void 0 ? null : /* @__PURE__ */ (0,
|
|
3731
|
-
props.error === void 0 ? null : /* @__PURE__ */ (0,
|
|
3856
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
3857
|
+
props.field.description === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: props.helpId, className: "fe-help", children: props.field.description }),
|
|
3858
|
+
props.error === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: props.errorId, className: "fe-error", children: props.translate(props.error.messageKey, props.error.params) })
|
|
3732
3859
|
] });
|
|
3733
3860
|
}
|
|
3734
3861
|
function GroupedChoiceDescription({ props }) {
|
|
3735
|
-
return props.field.description === void 0 ? null : /* @__PURE__ */ (0,
|
|
3862
|
+
return props.field.description === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: props.helpId, className: "fe-field-description", children: props.field.description });
|
|
3736
3863
|
}
|
|
3737
3864
|
function GroupedChoiceError({ props }) {
|
|
3738
|
-
return props.error === void 0 ? null : /* @__PURE__ */ (0,
|
|
3865
|
+
return props.error === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: props.errorId, className: "fe-field-error", role: "alert", children: props.translate(props.error.messageKey, props.error.params) });
|
|
3739
3866
|
}
|
|
3740
3867
|
function ChoiceGroupFrame({
|
|
3741
3868
|
props,
|
|
@@ -3759,10 +3886,10 @@ function ChoiceGroupFrame({
|
|
|
3759
3886
|
children,
|
|
3760
3887
|
className
|
|
3761
3888
|
};
|
|
3762
|
-
if (renderChoiceGroup !== void 0) return /* @__PURE__ */ (0,
|
|
3889
|
+
if (renderChoiceGroup !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: renderChoiceGroup(groupProps) });
|
|
3763
3890
|
return (
|
|
3764
3891
|
// biome-ignore lint/a11y/useAriaPropsSupportedByRole: The grouped fieldset exposes the required state for the complete choice question.
|
|
3765
|
-
/* @__PURE__ */ (0,
|
|
3892
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
3766
3893
|
"fieldset",
|
|
3767
3894
|
{
|
|
3768
3895
|
className,
|
|
@@ -3773,13 +3900,13 @@ function ChoiceGroupFrame({
|
|
|
3773
3900
|
"aria-required": field.required,
|
|
3774
3901
|
style: slotProps?.style,
|
|
3775
3902
|
children: [
|
|
3776
|
-
/* @__PURE__ */ (0,
|
|
3903
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("legend", { className: "fe-choice-legend", children: [
|
|
3777
3904
|
field.title,
|
|
3778
|
-
/* @__PURE__ */ (0,
|
|
3905
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required, className: "fe-required-badge" })
|
|
3779
3906
|
] }),
|
|
3780
|
-
/* @__PURE__ */ (0,
|
|
3907
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GroupedChoiceDescription, { props }),
|
|
3781
3908
|
children,
|
|
3782
|
-
/* @__PURE__ */ (0,
|
|
3909
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GroupedChoiceError, { props })
|
|
3783
3910
|
]
|
|
3784
3911
|
}
|
|
3785
3912
|
)
|
|
@@ -3803,7 +3930,7 @@ function DefaultField({
|
|
|
3803
3930
|
};
|
|
3804
3931
|
if (field.type === "checkbox") {
|
|
3805
3932
|
if (isGroupedChoiceField) {
|
|
3806
|
-
return /* @__PURE__ */ (0,
|
|
3933
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3807
3934
|
ChoiceGroupFrame,
|
|
3808
3935
|
{
|
|
3809
3936
|
props,
|
|
@@ -3812,8 +3939,8 @@ function DefaultField({
|
|
|
3812
3939
|
renderChoiceGroup,
|
|
3813
3940
|
disabled,
|
|
3814
3941
|
readOnly,
|
|
3815
|
-
children: /* @__PURE__ */ (0,
|
|
3816
|
-
/* @__PURE__ */ (0,
|
|
3942
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "fe-choice-options", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-choice-option", htmlFor: inputId, children: [
|
|
3943
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3817
3944
|
"input",
|
|
3818
3945
|
{
|
|
3819
3946
|
id: inputId,
|
|
@@ -3826,14 +3953,14 @@ function DefaultField({
|
|
|
3826
3953
|
onChange: (event) => setValue(event.currentTarget.checked)
|
|
3827
3954
|
}
|
|
3828
3955
|
),
|
|
3829
|
-
/* @__PURE__ */ (0,
|
|
3956
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: field.title })
|
|
3830
3957
|
] }) })
|
|
3831
3958
|
}
|
|
3832
3959
|
);
|
|
3833
3960
|
}
|
|
3834
|
-
return /* @__PURE__ */ (0,
|
|
3835
|
-
/* @__PURE__ */ (0,
|
|
3836
|
-
/* @__PURE__ */ (0,
|
|
3961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-field fe-field--checkbox", "data-field-id": field.id, children: [
|
|
3962
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-check-label", htmlFor: inputId, children: [
|
|
3963
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3837
3964
|
"input",
|
|
3838
3965
|
{
|
|
3839
3966
|
...ariaProps,
|
|
@@ -3844,19 +3971,19 @@ function DefaultField({
|
|
|
3844
3971
|
onChange: (event) => setValue(event.currentTarget.checked)
|
|
3845
3972
|
}
|
|
3846
3973
|
),
|
|
3847
|
-
/* @__PURE__ */ (0,
|
|
3974
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
3848
3975
|
field.title,
|
|
3849
|
-
/* @__PURE__ */ (0,
|
|
3976
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required })
|
|
3850
3977
|
] })
|
|
3851
3978
|
] }),
|
|
3852
|
-
/* @__PURE__ */ (0,
|
|
3979
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldMessage, { props })
|
|
3853
3980
|
] });
|
|
3854
3981
|
}
|
|
3855
3982
|
if (field.type === "radio" || field.type === "multi-select") {
|
|
3856
3983
|
const selected = Array.isArray(value) ? value : [];
|
|
3857
3984
|
if (isGroupedChoiceField) {
|
|
3858
3985
|
const isRadio = field.type === "radio";
|
|
3859
|
-
return /* @__PURE__ */ (0,
|
|
3986
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3860
3987
|
ChoiceGroupFrame,
|
|
3861
3988
|
{
|
|
3862
3989
|
props,
|
|
@@ -3865,11 +3992,11 @@ function DefaultField({
|
|
|
3865
3992
|
renderChoiceGroup,
|
|
3866
3993
|
disabled,
|
|
3867
3994
|
readOnly,
|
|
3868
|
-
children: /* @__PURE__ */ (0,
|
|
3995
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "fe-choice-options", children: field.options.map((option, index) => {
|
|
3869
3996
|
const optionId = `${inputId}-${index}`;
|
|
3870
3997
|
const checked = isRadio ? value === option.id : selected.includes(option.id);
|
|
3871
|
-
return /* @__PURE__ */ (0,
|
|
3872
|
-
/* @__PURE__ */ (0,
|
|
3998
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-choice-option", htmlFor: optionId, children: [
|
|
3999
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3873
4000
|
"input",
|
|
3874
4001
|
{
|
|
3875
4002
|
id: optionId,
|
|
@@ -3899,22 +4026,22 @@ function DefaultField({
|
|
|
3899
4026
|
}
|
|
3900
4027
|
}
|
|
3901
4028
|
),
|
|
3902
|
-
/* @__PURE__ */ (0,
|
|
4029
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: option.label })
|
|
3903
4030
|
] }, option.id);
|
|
3904
4031
|
}) })
|
|
3905
4032
|
}
|
|
3906
4033
|
);
|
|
3907
4034
|
}
|
|
3908
4035
|
if (field.type === "radio") {
|
|
3909
|
-
return /* @__PURE__ */ (0,
|
|
3910
|
-
/* @__PURE__ */ (0,
|
|
4036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-field fe-field--radio", "data-field-id": field.id, children: [
|
|
4037
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-label", children: [
|
|
3911
4038
|
field.title,
|
|
3912
|
-
/* @__PURE__ */ (0,
|
|
4039
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required })
|
|
3913
4040
|
] }),
|
|
3914
4041
|
field.options.map((option, index) => {
|
|
3915
4042
|
const optionId = `${inputId}-${index}`;
|
|
3916
|
-
return /* @__PURE__ */ (0,
|
|
3917
|
-
/* @__PURE__ */ (0,
|
|
4043
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-check-label", htmlFor: optionId, children: [
|
|
4044
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3918
4045
|
"input",
|
|
3919
4046
|
{
|
|
3920
4047
|
...ariaProps,
|
|
@@ -3926,22 +4053,22 @@ function DefaultField({
|
|
|
3926
4053
|
onChange: () => setValue(option.id)
|
|
3927
4054
|
}
|
|
3928
4055
|
),
|
|
3929
|
-
/* @__PURE__ */ (0,
|
|
4056
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: option.label })
|
|
3930
4057
|
] }, option.id);
|
|
3931
4058
|
}),
|
|
3932
|
-
/* @__PURE__ */ (0,
|
|
4059
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldMessage, { props })
|
|
3933
4060
|
] });
|
|
3934
4061
|
}
|
|
3935
|
-
return /* @__PURE__ */ (0,
|
|
3936
|
-
/* @__PURE__ */ (0,
|
|
4062
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { className: `fe-field fe-field--${field.type}`, "data-field-id": field.id, ...ariaProps, children: [
|
|
4063
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("legend", { className: "fe-label", children: [
|
|
3937
4064
|
field.title,
|
|
3938
|
-
/* @__PURE__ */ (0,
|
|
4065
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required })
|
|
3939
4066
|
] }),
|
|
3940
4067
|
field.options.map((option, index) => {
|
|
3941
4068
|
const optionId = `${inputId}-${index}`;
|
|
3942
4069
|
const checked = field.type === "radio" ? value === option.id : selected.includes(option.id);
|
|
3943
|
-
return /* @__PURE__ */ (0,
|
|
3944
|
-
/* @__PURE__ */ (0,
|
|
4070
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-check-label", htmlFor: optionId, children: [
|
|
4071
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3945
4072
|
"input",
|
|
3946
4073
|
{
|
|
3947
4074
|
id: optionId,
|
|
@@ -3958,24 +4085,24 @@ function DefaultField({
|
|
|
3958
4085
|
}
|
|
3959
4086
|
}
|
|
3960
4087
|
),
|
|
3961
|
-
/* @__PURE__ */ (0,
|
|
4088
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: option.label })
|
|
3962
4089
|
] }, option.id);
|
|
3963
4090
|
}),
|
|
3964
|
-
/* @__PURE__ */ (0,
|
|
4091
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldMessage, { props })
|
|
3965
4092
|
] });
|
|
3966
4093
|
}
|
|
3967
4094
|
if (field.type === "rating") {
|
|
3968
4095
|
const min = field.min ?? 1;
|
|
3969
4096
|
const max = field.max ?? 5;
|
|
3970
|
-
return /* @__PURE__ */ (0,
|
|
3971
|
-
/* @__PURE__ */ (0,
|
|
4097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { className: "fe-field fe-field--rating", "data-field-id": field.id, ...ariaProps, children: [
|
|
4098
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("legend", { className: "fe-label", children: [
|
|
3972
4099
|
field.title,
|
|
3973
|
-
/* @__PURE__ */ (0,
|
|
4100
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required })
|
|
3974
4101
|
] }),
|
|
3975
|
-
/* @__PURE__ */ (0,
|
|
4102
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "fe-rating-options", children: Array.from({ length: max - min + 1 }, (_, index) => min + index).map((rating) => {
|
|
3976
4103
|
const optionId = `${inputId}-${rating}`;
|
|
3977
|
-
return /* @__PURE__ */ (0,
|
|
3978
|
-
/* @__PURE__ */ (0,
|
|
4104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-rating-label", htmlFor: optionId, children: [
|
|
4105
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
3979
4106
|
"input",
|
|
3980
4107
|
{
|
|
3981
4108
|
id: optionId,
|
|
@@ -3986,15 +4113,15 @@ function DefaultField({
|
|
|
3986
4113
|
onChange: () => setValue(rating)
|
|
3987
4114
|
}
|
|
3988
4115
|
),
|
|
3989
|
-
/* @__PURE__ */ (0,
|
|
4116
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: rating })
|
|
3990
4117
|
] }, rating);
|
|
3991
4118
|
}) }),
|
|
3992
|
-
/* @__PURE__ */ (0,
|
|
4119
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldMessage, { props })
|
|
3993
4120
|
] });
|
|
3994
4121
|
}
|
|
3995
|
-
const label = /* @__PURE__ */ (0,
|
|
4122
|
+
const label = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: "fe-label", htmlFor: inputId, children: [
|
|
3996
4123
|
field.title,
|
|
3997
|
-
/* @__PURE__ */ (0,
|
|
4124
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RequiredMark, { required: field.required })
|
|
3998
4125
|
] });
|
|
3999
4126
|
let control;
|
|
4000
4127
|
const textConstraints = field.type === "text" || field.type === "textarea" ? {
|
|
@@ -4003,7 +4130,7 @@ function DefaultField({
|
|
|
4003
4130
|
...field.pattern === void 0 ? {} : { pattern: field.pattern }
|
|
4004
4131
|
} : {};
|
|
4005
4132
|
if (field.type === "textarea") {
|
|
4006
|
-
control = /* @__PURE__ */ (0,
|
|
4133
|
+
control = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4007
4134
|
"textarea",
|
|
4008
4135
|
{
|
|
4009
4136
|
...ariaProps,
|
|
@@ -4016,7 +4143,7 @@ function DefaultField({
|
|
|
4016
4143
|
}
|
|
4017
4144
|
);
|
|
4018
4145
|
} else if (field.type === "number") {
|
|
4019
|
-
control = /* @__PURE__ */ (0,
|
|
4146
|
+
control = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4020
4147
|
"input",
|
|
4021
4148
|
{
|
|
4022
4149
|
...ariaProps,
|
|
@@ -4033,7 +4160,7 @@ function DefaultField({
|
|
|
4033
4160
|
}
|
|
4034
4161
|
);
|
|
4035
4162
|
} else if (field.type === "select") {
|
|
4036
|
-
control = /* @__PURE__ */ (0,
|
|
4163
|
+
control = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4037
4164
|
"select",
|
|
4038
4165
|
{
|
|
4039
4166
|
...ariaProps,
|
|
@@ -4043,14 +4170,14 @@ function DefaultField({
|
|
|
4043
4170
|
value: typeof value === "string" ? value : "",
|
|
4044
4171
|
onChange: (event) => setValue(event.currentTarget.value || void 0),
|
|
4045
4172
|
children: [
|
|
4046
|
-
/* @__PURE__ */ (0,
|
|
4047
|
-
field.options.map((option) => /* @__PURE__ */ (0,
|
|
4173
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: "\u2014" }),
|
|
4174
|
+
field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: option.id, children: option.label }, option.id))
|
|
4048
4175
|
]
|
|
4049
4176
|
}
|
|
4050
4177
|
);
|
|
4051
4178
|
} else {
|
|
4052
4179
|
const placeholderKey = "placeholderKey" in field ? field.placeholderKey : void 0;
|
|
4053
|
-
control = /* @__PURE__ */ (0,
|
|
4180
|
+
control = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4054
4181
|
"input",
|
|
4055
4182
|
{
|
|
4056
4183
|
...ariaProps,
|
|
@@ -4064,7 +4191,7 @@ function DefaultField({
|
|
|
4064
4191
|
);
|
|
4065
4192
|
}
|
|
4066
4193
|
if (isGroupedChoiceField) {
|
|
4067
|
-
return /* @__PURE__ */ (0,
|
|
4194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4068
4195
|
ChoiceGroupFrame,
|
|
4069
4196
|
{
|
|
4070
4197
|
props,
|
|
@@ -4073,23 +4200,23 @@ function DefaultField({
|
|
|
4073
4200
|
renderChoiceGroup,
|
|
4074
4201
|
disabled,
|
|
4075
4202
|
readOnly,
|
|
4076
|
-
children: /* @__PURE__ */ (0,
|
|
4203
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "fe-choice-options", children: control })
|
|
4077
4204
|
}
|
|
4078
4205
|
);
|
|
4079
4206
|
}
|
|
4080
|
-
return /* @__PURE__ */ (0,
|
|
4207
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `fe-field fe-field--${field.type}`, "data-field-id": field.id, children: [
|
|
4081
4208
|
label,
|
|
4082
4209
|
control,
|
|
4083
4210
|
(field.type === "text" || field.type === "textarea") && field.maxLength !== void 0 ? props.renderCharacterCount?.({
|
|
4084
4211
|
fieldId: field.id,
|
|
4085
4212
|
current: typeof value === "string" ? value.length : 0,
|
|
4086
4213
|
max: field.maxLength
|
|
4087
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4214
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-character-count", "aria-live": "polite", children: [
|
|
4088
4215
|
typeof value === "string" ? value.length : 0,
|
|
4089
4216
|
" / ",
|
|
4090
4217
|
field.maxLength
|
|
4091
4218
|
] }) : null,
|
|
4092
|
-
/* @__PURE__ */ (0,
|
|
4219
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldMessage, { props })
|
|
4093
4220
|
] });
|
|
4094
4221
|
}
|
|
4095
4222
|
function isRecord(value) {
|
|
@@ -4211,32 +4338,34 @@ function ContextFormRenderer({
|
|
|
4211
4338
|
slots = {}
|
|
4212
4339
|
}) {
|
|
4213
4340
|
const form = useForm();
|
|
4214
|
-
const
|
|
4215
|
-
const
|
|
4216
|
-
const
|
|
4217
|
-
const
|
|
4218
|
-
const
|
|
4219
|
-
const [
|
|
4220
|
-
const [
|
|
4221
|
-
const [
|
|
4222
|
-
const [
|
|
4223
|
-
const [
|
|
4224
|
-
const [
|
|
4225
|
-
const [
|
|
4226
|
-
const
|
|
4227
|
-
const
|
|
4228
|
-
const
|
|
4229
|
-
const
|
|
4341
|
+
const i18n = useFormEngineI18n();
|
|
4342
|
+
const isProviderValue = (0, import_react7.useContext)(FormEngineI18nProviderScopeContext);
|
|
4343
|
+
const prefix = (0, import_react7.useId)().replace(/:/g, "");
|
|
4344
|
+
const formRef = (0, import_react7.useRef)(null);
|
|
4345
|
+
const loadedDraftKey = (0, import_react7.useRef)(null);
|
|
4346
|
+
const [draftRestored, setDraftRestored] = (0, import_react7.useState)(false);
|
|
4347
|
+
const [currentPageIndex, setCurrentPageIndex] = (0, import_react7.useState)(0);
|
|
4348
|
+
const [focusFieldId, setFocusFieldId] = (0, import_react7.useState)(null);
|
|
4349
|
+
const [confirmation, setConfirmation] = (0, import_react7.useState)(null);
|
|
4350
|
+
const [guardMessage, setGuardMessage] = (0, import_react7.useState)(null);
|
|
4351
|
+
const [guardsPending, setGuardsPending] = (0, import_react7.useState)(false);
|
|
4352
|
+
const [receipt, setReceipt] = (0, import_react7.useState)(null);
|
|
4353
|
+
const [completionData, setCompletionData] = (0, import_react7.useState)(null);
|
|
4354
|
+
const [receiptLoaded, setReceiptLoaded] = (0, import_react7.useState)(receiptStore === void 0);
|
|
4355
|
+
const rendererSubmissionInFlight = (0, import_react7.useRef)(false);
|
|
4356
|
+
const fallbackAttemptId = (0, import_react7.useRef)(null);
|
|
4357
|
+
const completionRef = (0, import_react7.useRef)(null);
|
|
4358
|
+
const confirmationRef = (0, import_react7.useRef)(null);
|
|
4230
4359
|
const pages = form.schema.pages;
|
|
4231
|
-
const visiblePageIndexes = (0,
|
|
4360
|
+
const visiblePageIndexes = (0, import_react7.useMemo)(
|
|
4232
4361
|
() => pages === void 0 ? [] : pages.flatMap((page, index) => form.pageVisibility[page.id] === true ? [index] : []),
|
|
4233
4362
|
[form.pageVisibility, pages]
|
|
4234
4363
|
);
|
|
4235
4364
|
const activePage = pages?.[currentPageIndex];
|
|
4236
4365
|
const activeVisibleIndex = visiblePageIndexes.indexOf(currentPageIndex);
|
|
4237
4366
|
const fieldIds = activePage === void 0 ? void 0 : new Set(activePage.questionIds);
|
|
4238
|
-
const visibleValues = (0,
|
|
4239
|
-
const visibleItems = (0,
|
|
4367
|
+
const visibleValues = (0, import_react7.useMemo)(() => (0, import_core6.selectVisibleAnswers)(form.schema, form.values), [form.schema, form.values]);
|
|
4368
|
+
const visibleItems = (0, import_react7.useMemo)(
|
|
4240
4369
|
() => buildSubmittedItems(form.schema, form.values, form.visibility, (key) => form.translate(key), false),
|
|
4241
4370
|
[form.schema, form.translate, form.values, form.visibility]
|
|
4242
4371
|
);
|
|
@@ -4245,23 +4374,24 @@ function ContextFormRenderer({
|
|
|
4245
4374
|
const submitState = confirmation === null && !guardsPending ? form.submitStatus : "confirming";
|
|
4246
4375
|
const interactionLocked = submitState === "confirming" || submitState === "submitting";
|
|
4247
4376
|
const isReplaceMode = successRenderMode === "replace" || hideFormOnSuccess;
|
|
4248
|
-
const resolveMessage = (0,
|
|
4377
|
+
const resolveMessage = (0, import_react7.useCallback)(
|
|
4249
4378
|
(key, fallback) => {
|
|
4250
|
-
const
|
|
4379
|
+
const providerDefault = isProviderValue ? i18n.translator(`renderer.${key}`) : void 0;
|
|
4380
|
+
const defaultText = fallback ?? (providerDefault === "" ? void 0 : providerDefault) ?? DEFAULT_RENDERER_MESSAGES[form.locale.toLowerCase().startsWith("ja") ? "ja" : "en"][key] ?? key;
|
|
4251
4381
|
const configured = messages[key];
|
|
4252
4382
|
return messageResolver?.(key, configured ?? defaultText) ?? configured ?? defaultText;
|
|
4253
4383
|
},
|
|
4254
|
-
[form.locale, messageResolver, messages]
|
|
4384
|
+
[form.locale, i18n, isProviderValue, messageResolver, messages]
|
|
4255
4385
|
);
|
|
4256
|
-
const fieldTranslate = (0,
|
|
4386
|
+
const fieldTranslate = (0, import_react7.useCallback)(
|
|
4257
4387
|
(key, params) => key === "validation.required" && (messages.requiredField !== void 0 || messageResolver !== void 0) ? resolveMessage("requiredField") : form.translate(key, params),
|
|
4258
4388
|
[form.translate, messageResolver, messages.requiredField, resolveMessage]
|
|
4259
4389
|
);
|
|
4260
|
-
const focusSubmitButton = (0,
|
|
4390
|
+
const focusSubmitButton = (0, import_react7.useCallback)(() => {
|
|
4261
4391
|
const button = formRef.current?.querySelector(".fe-submit, button[type='submit'], button");
|
|
4262
4392
|
button?.focus();
|
|
4263
4393
|
}, []);
|
|
4264
|
-
(0,
|
|
4394
|
+
(0, import_react7.useEffect)(() => {
|
|
4265
4395
|
let active = true;
|
|
4266
4396
|
if (receiptStore === void 0) {
|
|
4267
4397
|
setReceipt(null);
|
|
@@ -4282,14 +4412,14 @@ function ContextFormRenderer({
|
|
|
4282
4412
|
active = false;
|
|
4283
4413
|
};
|
|
4284
4414
|
}, [form.schema.id, form.schema.version, receiptStore]);
|
|
4285
|
-
(0,
|
|
4415
|
+
(0, import_react7.useEffect)(() => {
|
|
4286
4416
|
if (pages === void 0 || visiblePageIndexes.length === 0) {
|
|
4287
4417
|
setCurrentPageIndex(0);
|
|
4288
4418
|
return;
|
|
4289
4419
|
}
|
|
4290
4420
|
if (!visiblePageIndexes.includes(currentPageIndex)) setCurrentPageIndex(visiblePageIndexes[0] ?? 0);
|
|
4291
4421
|
}, [currentPageIndex, pages, visiblePageIndexes]);
|
|
4292
|
-
(0,
|
|
4422
|
+
(0, import_react7.useEffect)(() => {
|
|
4293
4423
|
if (focusFieldId === null) return;
|
|
4294
4424
|
const fieldContainer = [...formRef.current?.querySelectorAll("[data-field-id]") ?? []].find(
|
|
4295
4425
|
(element) => element.dataset.fieldId === focusFieldId
|
|
@@ -4301,11 +4431,11 @@ function ContextFormRenderer({
|
|
|
4301
4431
|
setFocusFieldId(null);
|
|
4302
4432
|
}
|
|
4303
4433
|
}, [focusFieldId]);
|
|
4304
|
-
(0,
|
|
4434
|
+
(0, import_react7.useEffect)(() => {
|
|
4305
4435
|
if (!isReplaceMode || form.submitStatus !== "success") return;
|
|
4306
4436
|
completionRef.current?.focus();
|
|
4307
4437
|
}, [form.submitStatus, isReplaceMode]);
|
|
4308
|
-
(0,
|
|
4438
|
+
(0, import_react7.useEffect)(() => {
|
|
4309
4439
|
if (confirmation === null) return;
|
|
4310
4440
|
const confirmButton = confirmationRef.current?.querySelector("[data-fe-confirm], button");
|
|
4311
4441
|
confirmButton?.focus();
|
|
@@ -4337,7 +4467,7 @@ function ContextFormRenderer({
|
|
|
4337
4467
|
globalThis.addEventListener("keydown", onKeyDown);
|
|
4338
4468
|
return () => globalThis.removeEventListener("keydown", onKeyDown);
|
|
4339
4469
|
}, [confirmation, confirmationRenderMode, focusSubmitButton]);
|
|
4340
|
-
(0,
|
|
4470
|
+
(0, import_react7.useEffect)(() => {
|
|
4341
4471
|
if (autoSaveKey === void 0 || typeof globalThis.localStorage === "undefined") return;
|
|
4342
4472
|
const loadIdentity = `${autoSaveKey}:${form.schema.id}:${form.schema.version}`;
|
|
4343
4473
|
if (loadedDraftKey.current === loadIdentity) return;
|
|
@@ -4349,7 +4479,7 @@ function ContextFormRenderer({
|
|
|
4349
4479
|
form.restoreValues(draft.values);
|
|
4350
4480
|
setDraftRestored(true);
|
|
4351
4481
|
}, [autoSaveKey, form.restoreValues, form.schema.id, form.schema.version]);
|
|
4352
|
-
(0,
|
|
4482
|
+
(0, import_react7.useEffect)(() => {
|
|
4353
4483
|
if (form.submitStatus === "success") return;
|
|
4354
4484
|
const timeout = globalThis.setTimeout(() => {
|
|
4355
4485
|
onDraftSave?.(form.values);
|
|
@@ -4405,7 +4535,7 @@ function ContextFormRenderer({
|
|
|
4405
4535
|
if (rendererSubmissionInFlight.current || submitState === "submitting" || submitState === "success" || confirmation !== null && !guardsConfirmed) {
|
|
4406
4536
|
return { status: "cancelled" };
|
|
4407
4537
|
}
|
|
4408
|
-
const validation = (0,
|
|
4538
|
+
const validation = (0, import_core6.validateAnswers)(form.schema, form.values);
|
|
4409
4539
|
const firstInvalidFieldId = validation.issues[0]?.fieldId;
|
|
4410
4540
|
if (validation.valid && !guardsConfirmed) {
|
|
4411
4541
|
rendererSubmissionInFlight.current = true;
|
|
@@ -4559,8 +4689,8 @@ function ContextFormRenderer({
|
|
|
4559
4689
|
disabled: interactionLocked || submitState === "success",
|
|
4560
4690
|
onSubmit: () => void submitValues()
|
|
4561
4691
|
};
|
|
4562
|
-
return slots.renderSubmitButton?.(submitButtonProps) ?? /* @__PURE__ */ (0,
|
|
4563
|
-
submitState === "submitting" ? /* @__PURE__ */ (0,
|
|
4692
|
+
return slots.renderSubmitButton?.(submitButtonProps) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: "fe-submit", type: "submit", disabled: submitButtonProps.disabled, children: [
|
|
4693
|
+
submitState === "submitting" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "fe-spinner", "aria-hidden": "true" }) : null,
|
|
4564
4694
|
submitState === "submitting" ? resolveMessage("submittingButton") : resolveMessage("submitButton", form.translate(form.schema.submitLabelKey ?? "form.submit"))
|
|
4565
4695
|
] });
|
|
4566
4696
|
};
|
|
@@ -4583,11 +4713,11 @@ function ContextFormRenderer({
|
|
|
4583
4713
|
...activeCompletionData.response === void 0 ? {} : { response: activeCompletionData.response },
|
|
4584
4714
|
onReset: form.reset
|
|
4585
4715
|
};
|
|
4586
|
-
const completionRegion = /* @__PURE__ */ (0,
|
|
4587
|
-
slots.renderCompletion?.(completionProps) ?? /* @__PURE__ */ (0,
|
|
4716
|
+
const completionRegion = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: completionRef, className: "fe-completion", role: "status", "aria-live": "polite", tabIndex: -1, children: [
|
|
4717
|
+
slots.renderCompletion?.(completionProps) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: completionMessage }),
|
|
4588
4718
|
slots.renderSubmittedValues?.({ items: activeCompletionData.submittedItems, schema: form.schema })
|
|
4589
4719
|
] });
|
|
4590
|
-
const confirmationContent = /* @__PURE__ */ (0,
|
|
4720
|
+
const confirmationContent = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4591
4721
|
"div",
|
|
4592
4722
|
{
|
|
4593
4723
|
ref: confirmationRef,
|
|
@@ -4601,53 +4731,53 @@ function ContextFormRenderer({
|
|
|
4601
4731
|
visibleItems,
|
|
4602
4732
|
onConfirm: confirmSubmission,
|
|
4603
4733
|
onCancel: cancelSubmission
|
|
4604
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4605
|
-
/* @__PURE__ */ (0,
|
|
4606
|
-
/* @__PURE__ */ (0,
|
|
4607
|
-
(confirmation?.findings ?? []).length === 0 ? null : /* @__PURE__ */ (0,
|
|
4734
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
4735
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { children: confirmation?.generic === true ? form.locale.toLowerCase().startsWith("ja") ? "\u56DE\u7B54\u5185\u5BB9\u306E\u78BA\u8A8D" : "Review your answers" : resolveMessage("confirmSensitiveDataTitle") }),
|
|
4736
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: confirmation?.message ?? (confirmation?.generic === true ? form.locale.toLowerCase().startsWith("ja") ? "\u56DE\u7B54\u5185\u5BB9\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001\u9001\u4FE1\u3057\u3066\u304F\u3060\u3055\u3044\u3002" : "Please review your answers before submitting." : resolveMessage("confirmSensitiveDataMessage", form.translate("form.confirmSensitiveData"))) }),
|
|
4737
|
+
(confirmation?.findings ?? []).length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { children: (confirmation?.findings ?? []).map((finding, index) => {
|
|
4608
4738
|
const field = form.schema.fields.find((candidate) => candidate.id === finding.fieldId);
|
|
4609
4739
|
const typeLabels = form.locale.toLowerCase().startsWith("ja") ? { email: "\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9", phone: "\u96FB\u8A71\u756A\u53F7", url: "URL", postal_code: "\u90F5\u4FBF\u756A\u53F7" } : { email: "Email address", phone: "Phone number", url: "URL", postal_code: "Postal code" };
|
|
4610
4740
|
const typeLabel = finding.typeLabel ?? typeLabels[finding.type] ?? finding.type;
|
|
4611
4741
|
const value = maskSensitiveValue(finding);
|
|
4612
|
-
return /* @__PURE__ */ (0,
|
|
4613
|
-
/* @__PURE__ */ (0,
|
|
4742
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
4743
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: finding.fieldTitle ?? field?.title ?? finding.fieldId }),
|
|
4614
4744
|
" ",
|
|
4615
|
-
/* @__PURE__ */ (0,
|
|
4616
|
-
value === void 0 ? null : /* @__PURE__ */ (0,
|
|
4745
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "fe-sensitive-type", children: typeLabel }),
|
|
4746
|
+
value === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "fe-sensitive-value", children: [
|
|
4617
4747
|
" ",
|
|
4618
4748
|
value
|
|
4619
4749
|
] })
|
|
4620
4750
|
] }, `${finding.fieldId}-${finding.type}-${finding.start ?? index}`);
|
|
4621
4751
|
}) }),
|
|
4622
|
-
confirmation?.generic === true ? /* @__PURE__ */ (0,
|
|
4623
|
-
/* @__PURE__ */ (0,
|
|
4752
|
+
confirmation?.generic === true ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "fe-submission-summary", children: visibleItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { children: [
|
|
4753
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: item.title }),
|
|
4624
4754
|
": ",
|
|
4625
|
-
/* @__PURE__ */ (0,
|
|
4755
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: item.displayValue })
|
|
4626
4756
|
] }, item.fieldId)) }) : null,
|
|
4627
|
-
/* @__PURE__ */ (0,
|
|
4628
|
-
/* @__PURE__ */ (0,
|
|
4757
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", "data-fe-confirm": "true", onClick: confirmSubmission, children: resolveMessage("confirmButton", form.translate("form.confirmSubmission")) }),
|
|
4758
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", onClick: cancelSubmission, children: resolveMessage("cancelButton", form.translate("form.cancelSubmission")) })
|
|
4629
4759
|
] })
|
|
4630
4760
|
}
|
|
4631
4761
|
);
|
|
4632
4762
|
if (!receiptLoaded) return null;
|
|
4633
4763
|
if (receipt !== null) {
|
|
4634
|
-
return /* @__PURE__ */ (0,
|
|
4764
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `fe-form fe-already-submitted ${className}`.trim(), children: slots.renderAlreadySubmitted?.({
|
|
4635
4765
|
receipt,
|
|
4636
4766
|
...receiptStore === void 0 ? {} : { onReset: () => void resetReceipt() }
|
|
4637
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4638
|
-
/* @__PURE__ */ (0,
|
|
4639
|
-
/* @__PURE__ */ (0,
|
|
4640
|
-
receiptStore === void 0 ? null : /* @__PURE__ */ (0,
|
|
4767
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { role: "status", children: [
|
|
4768
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { children: resolveMessage("alreadySubmittedTitle") }),
|
|
4769
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: resolveMessage("alreadySubmittedMessage", form.translate("form.alreadySubmitted")) }),
|
|
4770
|
+
receiptStore === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", onClick: () => void resetReceipt(), children: resolveMessage("submitButton", form.translate("form.submitAnother")) })
|
|
4641
4771
|
] }) });
|
|
4642
4772
|
}
|
|
4643
4773
|
if (form.submitStatus === "success" && isReplaceMode) {
|
|
4644
|
-
return /* @__PURE__ */ (0,
|
|
4774
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `fe-form ${className}`.trim(), children: completionRegion });
|
|
4645
4775
|
}
|
|
4646
4776
|
if (confirmation !== null && confirmationRenderMode === "replace") {
|
|
4647
|
-
return /* @__PURE__ */ (0,
|
|
4777
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `fe-form ${className}`.trim(), children: confirmationContent });
|
|
4648
4778
|
}
|
|
4649
|
-
return /* @__PURE__ */ (0,
|
|
4650
|
-
/* @__PURE__ */ (0,
|
|
4779
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
4780
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
4651
4781
|
"form",
|
|
4652
4782
|
{
|
|
4653
4783
|
ref: formRef,
|
|
@@ -4659,11 +4789,11 @@ function ContextFormRenderer({
|
|
|
4659
4789
|
slots.renderHeader?.({
|
|
4660
4790
|
title: form.schema.title,
|
|
4661
4791
|
...form.schema.description === void 0 ? {} : { description: form.schema.description }
|
|
4662
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4663
|
-
/* @__PURE__ */ (0,
|
|
4664
|
-
form.schema.description === void 0 ? null : /* @__PURE__ */ (0,
|
|
4665
|
-
pages === void 0 ? null : /* @__PURE__ */ (0,
|
|
4666
|
-
/* @__PURE__ */ (0,
|
|
4792
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "fe-header", children: [
|
|
4793
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { children: form.schema.title }),
|
|
4794
|
+
form.schema.description === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: form.schema.description }),
|
|
4795
|
+
pages === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-progress", children: [
|
|
4796
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4667
4797
|
"div",
|
|
4668
4798
|
{
|
|
4669
4799
|
className: "form-progress-bar",
|
|
@@ -4671,7 +4801,7 @@ function ContextFormRenderer({
|
|
|
4671
4801
|
"aria-valuemin": 1,
|
|
4672
4802
|
"aria-valuemax": visiblePageIndexes.length,
|
|
4673
4803
|
"aria-valuenow": activeVisibleIndex + 1,
|
|
4674
|
-
children: /* @__PURE__ */ (0,
|
|
4804
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4675
4805
|
"div",
|
|
4676
4806
|
{
|
|
4677
4807
|
className: "form-progress-fill",
|
|
@@ -4680,17 +4810,17 @@ function ContextFormRenderer({
|
|
|
4680
4810
|
)
|
|
4681
4811
|
}
|
|
4682
4812
|
),
|
|
4683
|
-
/* @__PURE__ */ (0,
|
|
4813
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: form.translate("form.step", { current: activeVisibleIndex + 1, total: visiblePageIndexes.length }) })
|
|
4684
4814
|
] }),
|
|
4685
|
-
draftRestored ? /* @__PURE__ */ (0,
|
|
4815
|
+
draftRestored ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "form-draft-badge", children: form.translate("form.draftRestored") }) : null
|
|
4686
4816
|
] }),
|
|
4687
4817
|
activePage === void 0 ? null : slots.renderPageHeader?.({
|
|
4688
4818
|
page: activePage,
|
|
4689
4819
|
pageIndex: activeVisibleIndex,
|
|
4690
4820
|
totalPages: visiblePageIndexes.length
|
|
4691
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4692
|
-
activePage.title === void 0 ? null : /* @__PURE__ */ (0,
|
|
4693
|
-
activePage.description === void 0 ? null : /* @__PURE__ */ (0,
|
|
4821
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-page-header", children: [
|
|
4822
|
+
activePage.title === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: "fe-page-title", children: activePage.title }),
|
|
4823
|
+
activePage.description === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "fe-page-description", children: activePage.description })
|
|
4694
4824
|
] }),
|
|
4695
4825
|
(() => {
|
|
4696
4826
|
const fieldChildren = form.schema.fields.filter((field) => form.visibility[field.id] === true && (fieldIds === void 0 || fieldIds.has(field.id))).map((field) => {
|
|
@@ -4707,7 +4837,7 @@ function ContextFormRenderer({
|
|
|
4707
4837
|
...slots.renderCharacterCount === void 0 ? {} : { renderCharacterCount: slots.renderCharacterCount }
|
|
4708
4838
|
};
|
|
4709
4839
|
if (slots.renderField !== void 0) {
|
|
4710
|
-
return /* @__PURE__ */ (0,
|
|
4840
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react7.Fragment, { children: slots.renderField({
|
|
4711
4841
|
question: field,
|
|
4712
4842
|
value: form.values[field.id],
|
|
4713
4843
|
onChange: (value) => {
|
|
@@ -4717,7 +4847,7 @@ function ContextFormRenderer({
|
|
|
4717
4847
|
}) }, field.id);
|
|
4718
4848
|
}
|
|
4719
4849
|
const Component = components[field.type];
|
|
4720
|
-
return Component === void 0 ? /* @__PURE__ */ (0,
|
|
4850
|
+
return Component === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4721
4851
|
DefaultField,
|
|
4722
4852
|
{
|
|
4723
4853
|
...props,
|
|
@@ -4728,20 +4858,20 @@ function ContextFormRenderer({
|
|
|
4728
4858
|
disabled: interactionLocked
|
|
4729
4859
|
},
|
|
4730
4860
|
field.id
|
|
4731
|
-
) : /* @__PURE__ */ (0,
|
|
4861
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component, { ...props }, field.id);
|
|
4732
4862
|
});
|
|
4733
4863
|
const fieldClassName = `fe-fields${fieldsClassName === void 0 ? "" : ` ${fieldsClassName}`}`;
|
|
4734
|
-
return slots.renderFields?.({ children: fieldChildren, className: fieldClassName }) ?? /* @__PURE__ */ (0,
|
|
4864
|
+
return slots.renderFields?.({ children: fieldChildren, className: fieldClassName }) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: fieldClassName, children: fieldChildren });
|
|
4735
4865
|
})(),
|
|
4736
|
-
guardMessage === null ? null : /* @__PURE__ */ (0,
|
|
4866
|
+
guardMessage === null ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { role: "alert", children: guardMessage }),
|
|
4737
4867
|
confirmation !== null && confirmationRenderMode === "inline" ? confirmationContent : null,
|
|
4738
|
-
validationIssues.length === 0 ? null : slots.renderValidationSummary?.({ issues: validationIssues }) ?? /* @__PURE__ */ (0,
|
|
4868
|
+
validationIssues.length === 0 ? null : slots.renderValidationSummary?.({ issues: validationIssues }) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-validation-summary", role: "alert", children: [
|
|
4739
4869
|
validationIssues.length,
|
|
4740
4870
|
" validation error",
|
|
4741
4871
|
validationIssues.length === 1 ? "" : "s",
|
|
4742
4872
|
"."
|
|
4743
4873
|
] }),
|
|
4744
|
-
pages === void 0 ? /* @__PURE__ */ (0,
|
|
4874
|
+
pages === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
4745
4875
|
slots.renderNavigation?.({
|
|
4746
4876
|
currentPage: 0,
|
|
4747
4877
|
totalPages: 1,
|
|
@@ -4751,7 +4881,7 @@ function ContextFormRenderer({
|
|
|
4751
4881
|
onNext: () => void 0
|
|
4752
4882
|
}),
|
|
4753
4883
|
renderSubmitButton()
|
|
4754
|
-
] }) : /* @__PURE__ */ (0,
|
|
4884
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "form-step-navigation", children: [
|
|
4755
4885
|
slots.renderNavigation?.({
|
|
4756
4886
|
currentPage: activeVisibleIndex,
|
|
4757
4887
|
totalPages: visiblePageIndexes.length,
|
|
@@ -4761,8 +4891,8 @@ function ContextFormRenderer({
|
|
|
4761
4891
|
if (!interactionLocked) setCurrentPageIndex(visiblePageIndexes[activeVisibleIndex - 1] ?? 0);
|
|
4762
4892
|
},
|
|
4763
4893
|
onNext: handleNext
|
|
4764
|
-
}) ?? /* @__PURE__ */ (0,
|
|
4765
|
-
canPrev ? /* @__PURE__ */ (0,
|
|
4894
|
+
}) ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
4895
|
+
canPrev ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4766
4896
|
"button",
|
|
4767
4897
|
{
|
|
4768
4898
|
className: "btn-prev",
|
|
@@ -4772,24 +4902,24 @@ function ContextFormRenderer({
|
|
|
4772
4902
|
children: form.translate("form.back")
|
|
4773
4903
|
}
|
|
4774
4904
|
) : null,
|
|
4775
|
-
canNext ? /* @__PURE__ */ (0,
|
|
4905
|
+
canNext ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "btn-next", type: "button", disabled: interactionLocked, onClick: handleNext, children: form.translate("form.next") }) : null
|
|
4776
4906
|
] }),
|
|
4777
4907
|
canNext ? null : renderSubmitButton()
|
|
4778
4908
|
] }),
|
|
4779
|
-
/* @__PURE__ */ (0,
|
|
4909
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "fe-status", "aria-live": "polite", children: [
|
|
4780
4910
|
form.submitStatus === "success" ? completionRegion : null,
|
|
4781
|
-
form.submitStatus === "error" && form.submitError !== null ? slots.renderSubmitError?.({ error: form.submitError, onRetry: () => void submitValues() }) ?? (form.submitError instanceof FormSubmissionError && form.submitError.payload.formError !== void 0 ? /* @__PURE__ */ (0,
|
|
4911
|
+
form.submitStatus === "error" && form.submitError !== null ? slots.renderSubmitError?.({ error: form.submitError, onRetry: () => void submitValues() }) ?? (form.submitError instanceof FormSubmissionError && form.submitError.payload.formError !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { role: "alert", children: [
|
|
4782
4912
|
form.submitError.payload.formError,
|
|
4783
|
-
/* @__PURE__ */ (0,
|
|
4784
|
-
] }) : /* @__PURE__ */ (0,
|
|
4913
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", onClick: () => void submitValues(), children: resolveMessage("retryButton") })
|
|
4914
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { role: "alert", children: [
|
|
4785
4915
|
errorMessageKey === void 0 ? resolveMessage("serverErrorSummary") : form.translate(errorMessageKey),
|
|
4786
|
-
/* @__PURE__ */ (0,
|
|
4916
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", onClick: () => void submitValues(), children: resolveMessage("retryButton") })
|
|
4787
4917
|
] })) : null
|
|
4788
4918
|
] })
|
|
4789
4919
|
]
|
|
4790
4920
|
}
|
|
4791
4921
|
),
|
|
4792
|
-
confirmation !== null && confirmationRenderMode === "dialog" ? /* @__PURE__ */ (0,
|
|
4922
|
+
confirmation !== null && confirmationRenderMode === "dialog" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "fe-confirmation-dialog-backdrop", role: "dialog", "aria-modal": "true", children: confirmationContent }) : null
|
|
4793
4923
|
] });
|
|
4794
4924
|
}
|
|
4795
4925
|
var RENDERER_MESSAGES = {
|
|
@@ -4834,17 +4964,22 @@ var defaultRendererTranslator = {
|
|
|
4834
4964
|
}
|
|
4835
4965
|
};
|
|
4836
4966
|
function FormRenderer(props) {
|
|
4837
|
-
|
|
4967
|
+
const i18n = useFormEngineI18n();
|
|
4968
|
+
const isProviderValue = (0, import_react7.useContext)(FormEngineI18nProviderScopeContext);
|
|
4969
|
+
if (!("schema" in props)) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ContextFormRenderer, { ...props });
|
|
4838
4970
|
const {
|
|
4839
4971
|
schema,
|
|
4840
4972
|
locale = schema.defaultLocale ?? "en",
|
|
4841
|
-
translator
|
|
4973
|
+
translator: explicitTranslator,
|
|
4842
4974
|
initialValues,
|
|
4843
4975
|
resetOnSuccess,
|
|
4844
4976
|
onSubmit,
|
|
4845
4977
|
...rendererProps
|
|
4846
4978
|
} = props;
|
|
4847
|
-
|
|
4979
|
+
const translator = explicitTranslator ?? (isProviderValue ? {
|
|
4980
|
+
translate: (key, _locale, params) => params === void 0 ? i18n.translator(key) : i18n.translator(key, { ...params })
|
|
4981
|
+
} : defaultRendererTranslator);
|
|
4982
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4848
4983
|
FormProvider,
|
|
4849
4984
|
{
|
|
4850
4985
|
schema,
|
|
@@ -4853,7 +4988,7 @@ function FormRenderer(props) {
|
|
|
4853
4988
|
onSubmit,
|
|
4854
4989
|
...initialValues === void 0 ? {} : { initialValues },
|
|
4855
4990
|
...resetOnSuccess === void 0 ? {} : { resetOnSuccess },
|
|
4856
|
-
children: /* @__PURE__ */ (0,
|
|
4991
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ContextFormRenderer, { ...rendererProps })
|
|
4857
4992
|
}
|
|
4858
4993
|
);
|
|
4859
4994
|
}
|
|
@@ -4862,6 +4997,8 @@ function FormRenderer(props) {
|
|
|
4862
4997
|
BUILDER_TRANSLATION_ALIASES,
|
|
4863
4998
|
BUILDER_TRANSLATION_KEYS,
|
|
4864
4999
|
FormBuilder,
|
|
5000
|
+
FormEngineI18nContext,
|
|
5001
|
+
FormEngineI18nProvider,
|
|
4865
5002
|
FormProvider,
|
|
4866
5003
|
FormRenderer,
|
|
4867
5004
|
FormSubmissionError,
|
|
@@ -4877,6 +5014,7 @@ function FormRenderer(props) {
|
|
|
4877
5014
|
useField,
|
|
4878
5015
|
useForm,
|
|
4879
5016
|
useFormBuilder,
|
|
5017
|
+
useFormEngineI18n,
|
|
4880
5018
|
useSubmissionReceipts,
|
|
4881
5019
|
useTranslationWorkspace,
|
|
4882
5020
|
validateLocalePipeline
|