@overmap-ai/forms 1.0.12-links.1 → 1.0.12-links.10

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.
@@ -18,3 +18,7 @@ export declare const FieldTypeToClsMapping: {
18
18
  readonly "multi-string": typeof MultiStringField;
19
19
  readonly "multi-select": typeof MultiSelectField;
20
20
  };
21
+ export declare const linkOptions: {
22
+ target: string;
23
+ rel: string;
24
+ };
package/dist/forms.js CHANGED
@@ -5,13 +5,14 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
8
- import { Flex, Text, useSeverityColor, Checkbox, TextArea, Select, IconButton, Badge, MultiSelect, Button, ButtonList, divButtonProps, Tooltip, Separator, useDiscardAlertDialog, Dialog, DropdownItemMenu, useAlertDialog, useToast } from "@overmap-ai/blocks";
8
+ import { Flex, Text, useSeverityColor, Checkbox, Select, IconButton, Badge, MultiSelect, Button, TextArea, ButtonList, divButtonProps, Tooltip, Separator, useDiscardAlertDialog, Dialog, DropdownItemMenu, useAlertDialog, useToast } from "@overmap-ai/blocks";
9
9
  import { useField, useFormikContext, useFormik, FormikProvider } from "formik";
10
- import React, { useMemo, memo, useCallback, useState, useEffect, useRef, forwardRef, Fragment as Fragment$1, useReducer } from "react";
11
- import { CheckCircledIcon, FontFamilyIcon, CalendarIcon, InputIcon, RowsIcon, PlusIcon, Cross1Icon, ListBulletIcon, DropdownMenuIcon, CheckboxIcon, UploadIcon, StarFilledIcon, StarIcon, QuestionMarkCircledIcon, PersonIcon, Pencil1Icon, TrashIcon, CopyIcon, DragHandleDots2Icon, DotsVerticalIcon } from "@radix-ui/react-icons";
10
+ import React, { useMemo, memo, useCallback, useState, useRef, useEffect, forwardRef, Fragment as Fragment$1, useReducer } from "react";
11
+ import { CheckCircledIcon, FontFamilyIcon, CalendarIcon, PlusIcon, Cross1Icon, ListBulletIcon, DropdownMenuIcon, CheckboxIcon, UploadIcon, InputIcon, RowsIcon, StarFilledIcon, StarIcon, QuestionMarkCircledIcon, PersonIcon, Pencil1Icon, TrashIcon, CopyIcon, DragHandleDots2Icon, DotsVerticalIcon } from "@radix-ui/react-icons";
12
12
  import { TextField as TextField$1, Box, Card, Heading, Avatar, Em, Strong, Tabs } from "@radix-ui/themes";
13
+ import Linkify from "linkify-react";
13
14
  import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd";
14
- import { slugify, useAppSelector, selectFormRevision, useSDK, selectSubmissionAttachments, selectFilteredUserForms, selectUserFormMapping, selectOrganization, selectUser, selectNumberOfUserForms, selectCurrentUser, classNames, isToday, getLocalDateString, selectLatestFormRevision, useFileSrc, selectSubmissionsForForm } from "@overmap-ai/core";
15
+ import { slugify, classNames, useAppSelector, selectFormRevision, useSDK, selectSubmissionAttachments, selectFilteredUserForms, selectUserFormMapping, selectOrganization, selectUser, selectNumberOfUserForms, selectCurrentUser, isToday, getLocalDateString, selectLatestFormRevision, useFileSrc, selectSubmissionsForForm } from "@overmap-ai/core";
15
16
  import get from "lodash.get";
16
17
  import set from "lodash.set";
17
18
  import cloneDeep from "lodash.clonedeep";
@@ -106,7 +107,7 @@ class BaseField extends BaseFormElement {
106
107
  __publicField(BaseField, "fieldTypeName");
107
108
  __publicField(BaseField, "fieldTypeDescription");
108
109
  const description$1 = "_description_17zed_1";
109
- const styles$3 = {
110
+ const styles$4 = {
110
111
  description: description$1
111
112
  };
112
113
  const InputWithLabel = (props) => {
@@ -120,7 +121,7 @@ const InputWithLabelAndHelpText = (props) => {
120
121
  const { helpText, children, severity } = props;
121
122
  return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "1", children: [
122
123
  children,
123
- /* @__PURE__ */ jsx(Flex, { direction: "column", children: /* @__PURE__ */ jsx(Text, { size: "1", severity, className: styles$3.description, children: helpText }) })
124
+ /* @__PURE__ */ jsx(Flex, { direction: "column", children: /* @__PURE__ */ jsx(Text, { size: "1", severity, className: styles$4.description, children: helpText }) })
124
125
  ] });
125
126
  };
126
127
  const useFormikInput = (props) => {
@@ -472,65 +473,12 @@ __publicField(StringOrTextField, "_validateMax", (value, allValues) => {
472
473
  }
473
474
  return null;
474
475
  });
475
- const StringInput = memo(function StringInput2(props) {
476
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
477
- const color = useSeverityColor(severity);
478
- console.log(inputId, label, fieldProps, field, rest);
479
- return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsx(TextField$1.Input, { ...rest, ...fieldProps, type: field.inputType, id: inputId, color }) }) });
480
- });
481
- const _StringField = class _StringField extends StringOrTextField {
482
- constructor(options) {
483
- const { inputType = "text", ...rest } = options;
484
- const maxLength = options.maxLength ? Math.min(500, options.maxLength) : 500;
485
- const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
486
- super({ ...rest, maxLength, minLength, type: "string" });
487
- __publicField(this, "inputType");
488
- this.inputType = inputType;
489
- }
490
- serialize() {
491
- return { ...super._serialize(), input_type: this.inputType };
492
- }
493
- static deserialize(data) {
494
- if (data.type !== "string")
495
- throw new Error("Type mismatch.");
496
- const { maximum_length, minimum_length, input_type, ...rest } = data;
497
- return new _StringField({ ...rest, maxLength: maximum_length, minLength: minimum_length, inputType: input_type });
498
- }
499
- getInput(props) {
500
- return /* @__PURE__ */ jsx(StringInput, { field: this, ...props });
501
- }
502
- };
503
- __publicField(_StringField, "fieldTypeName", "Short Text");
504
- __publicField(_StringField, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line.");
505
- __publicField(_StringField, "Icon", InputIcon);
506
- let StringField = _StringField;
507
- const TextInput = memo(function TextInput2(props) {
508
- const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
509
- return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsx(TextArea, { ...rest, ...fieldProps, resize: "vertical", id: inputId, severity }) }) });
510
- });
511
- const _TextField = class _TextField extends StringOrTextField {
512
- constructor(options) {
513
- const maxLength = options.maxLength ? Math.min(5e3, options.maxLength) : 5e3;
514
- const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
515
- super({ ...options, maxLength, minLength, type: "text" });
516
- }
517
- serialize() {
518
- return super._serialize();
519
- }
520
- static deserialize(data) {
521
- if (data.type !== "text")
522
- throw new Error("Type mismatch.");
523
- const { maximum_length, minimum_length, ...rest } = data;
524
- return new _TextField({ ...rest, maxLength: maximum_length, minLength: minimum_length });
525
- }
526
- getInput(props) {
527
- return /* @__PURE__ */ jsx(TextInput, { field: this, ...props });
528
- }
476
+ const TextFieldRoot = "_TextFieldRoot_8ge74_1";
477
+ const TextFieldInputCopy = "_TextFieldInputCopy_8ge74_5";
478
+ const styles$3 = {
479
+ TextFieldRoot,
480
+ TextFieldInputCopy
529
481
  };
530
- __publicField(_TextField, "fieldTypeName", "Paragraph");
531
- __publicField(_TextField, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines.");
532
- __publicField(_TextField, "Icon", RowsIcon);
533
- let TextField = _TextField;
534
482
  const SelectInput = memo(function SelectInput2(props) {
535
483
  const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
536
484
  const { onChange, onBlur } = fieldProps;
@@ -955,16 +903,6 @@ __publicField(_MultiSelectField, "fieldTypeName", "Multi-select");
955
903
  __publicField(_MultiSelectField, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options.");
956
904
  __publicField(_MultiSelectField, "Icon", CheckboxIcon);
957
905
  let MultiSelectField = _MultiSelectField;
958
- const FieldInputCloner = memo(function FieldInputCloner2({ field, ...props }) {
959
- const [{ value: identifier }] = useField(field.options.clonedFieldIdentifier);
960
- const deserializedField = useMemo(() => {
961
- const options = field.options.getFieldToClone(identifier);
962
- if (!options)
963
- return null;
964
- return deserialize(options);
965
- }, [field.options, identifier]);
966
- return useFieldInput(deserializedField, props);
967
- });
968
906
  class CustomField extends BaseField {
969
907
  constructor(options, Component) {
970
908
  super({ ...options, type: "custom" });
@@ -984,164 +922,6 @@ class CustomField extends BaseField {
984
922
  }
985
923
  __publicField(CustomField, "fieldTypeName", "Custom");
986
924
  __publicField(CustomField, "fieldTypeDescription", "Allows re-rendering of field already in the form");
987
- class FieldInputClonerField extends CustomField {
988
- constructor(options) {
989
- super(options, FieldInputCloner);
990
- }
991
- }
992
- const FieldSectionLayout = memo(function FieldSectionLayout2(props) {
993
- const { field: section, ...rest } = props;
994
- const { label, description: description2, fields, condition } = section;
995
- const { values, setFieldValue } = useFormikContext();
996
- const conditionValue = (condition == null ? void 0 : condition.identifier) ? get(values, condition.identifier) : void 0;
997
- const conditionMet = useMemo(() => isConditionMet(condition, conditionValue), [condition, conditionValue]);
998
- useEffect(() => {
999
- if (!conditionMet) {
1000
- for (const childField of fields) {
1001
- setFieldValue(childField.getId(), "").then();
1002
- }
1003
- }
1004
- }, [conditionMet, fields, setFieldValue]);
1005
- const inputs = useFieldInputs(fields, rest);
1006
- if (!conditionMet) {
1007
- return null;
1008
- }
1009
- if (!label) {
1010
- return inputs;
1011
- }
1012
- return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "3", children: [
1013
- /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
1014
- /* @__PURE__ */ jsx(Heading, { as: "h3", size: "3", children: label }),
1015
- /* @__PURE__ */ jsx(Text, { className: styles$3.description, children: description2 })
1016
- ] }),
1017
- inputs
1018
- ] }) });
1019
- });
1020
- const _FieldSection = class _FieldSection extends BaseFormElement {
1021
- constructor(options) {
1022
- const { label = null, fields, condition = null, conditional, ...base } = options;
1023
- super({ ...base, type: "section" });
1024
- __publicField(this, "label");
1025
- __publicField(this, "fields");
1026
- __publicField(this, "condition");
1027
- this.fields = fields;
1028
- this.condition = condition;
1029
- this.label = label;
1030
- if (conditional === false) {
1031
- this.condition = null;
1032
- }
1033
- }
1034
- static getFieldCreationSchema(options) {
1035
- if (options.length === 0)
1036
- return [];
1037
- return [
1038
- new BooleanField({
1039
- label: "Conditional",
1040
- description: "Conditionally show or hide this section.",
1041
- identifier: "conditional",
1042
- required: false
1043
- }),
1044
- // Declare a section that will hold options for the condition (if any).
1045
- new _FieldSection({
1046
- label: "Conditional settings",
1047
- identifier: "conditional-settings",
1048
- // This section will only be rendered if the above "Conditional" field is checked.
1049
- condition: {
1050
- identifier: "conditional",
1051
- value: true
1052
- },
1053
- // These are the options of the condition.
1054
- fields: [
1055
- // Declare a select field that will be used to select the field against which we will check the
1056
- // condition. This must be selected before the next field is rendered.
1057
- new SelectField({
1058
- label: "Field",
1059
- description: "The field to use for the condition.",
1060
- // The options (for the field against which we will check the condition) are all the labels of
1061
- // the fields in the previous section(s) (or fields declared before with no section) that
1062
- // support conditions. We pass in both the label and the identifier of each supported field. The
1063
- // identifier becomes the value of the option.
1064
- options: options.map((option) => {
1065
- if (!option.label)
1066
- return null;
1067
- if (option.type === "upload")
1068
- return null;
1069
- return {
1070
- label: option.label,
1071
- value: option.identifier
1072
- };
1073
- }).filter((option) => !!option),
1074
- identifier: "condition.identifier",
1075
- required: true
1076
- }),
1077
- // Declare a custom field that will be used to input a value for the condition. The value of the
1078
- // conditional field selected in the previous step must be equal to the value the user inputs into
1079
- // this field for the section to be rendered.
1080
- new FieldInputClonerField({
1081
- label: "Value",
1082
- identifier: "condition.value",
1083
- required: true,
1084
- clonedFieldIdentifier: "condition.identifier",
1085
- getFieldToClone(identifier) {
1086
- if (!identifier) {
1087
- return null;
1088
- }
1089
- const option = options.find((option2) => option2.identifier === identifier);
1090
- if (!option) {
1091
- console.error("Could not find field with identifier", identifier);
1092
- return null;
1093
- }
1094
- return {
1095
- ...option,
1096
- // Override some options to make it make sense in the context and to make it work with the framework.
1097
- label: "Value",
1098
- identifier: "condition.value",
1099
- description: "The value to compare against.",
1100
- required: option.type !== "boolean"
1101
- };
1102
- }
1103
- })
1104
- ]
1105
- })
1106
- ];
1107
- }
1108
- static deserialize(data) {
1109
- var _a;
1110
- if (data.type !== "section")
1111
- throw new Error("Invalid type");
1112
- const fields = ((_a = data.fields) == null ? void 0 : _a.map(deserializeField)) ?? [];
1113
- return new _FieldSection({ ...data, fields });
1114
- }
1115
- conditional() {
1116
- return this.condition !== null;
1117
- }
1118
- serialize() {
1119
- return {
1120
- ...super._serialize(),
1121
- label: this.label,
1122
- condition: this.condition,
1123
- conditional: this.conditional(),
1124
- fields: this.fields.map((field) => field.serialize())
1125
- };
1126
- }
1127
- getErrors(allValues) {
1128
- const errors = {};
1129
- for (const field of this.fields) {
1130
- const id = field.getId();
1131
- const error = field.getError(get(allValues, id), allValues);
1132
- if (error) {
1133
- set(errors, field.getId(), error);
1134
- }
1135
- }
1136
- return errors;
1137
- }
1138
- getInput(props) {
1139
- return /* @__PURE__ */ jsx(FieldSectionLayout, { field: this, ...props });
1140
- }
1141
- };
1142
- __publicField(_FieldSection, "fieldTypeName", "Section");
1143
- __publicField(_FieldSection, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
1144
- let FieldSection = _FieldSection;
1145
925
  const previewImage = "_previewImage_1ig84_1";
1146
926
  const styles$2 = {
1147
927
  previewImage
@@ -1397,6 +1177,253 @@ const FieldTypeToClsMapping = {
1397
1177
  "multi-string": MultiStringField,
1398
1178
  "multi-select": MultiSelectField
1399
1179
  };
1180
+ const linkOptions = { target: "_blank", rel: "noopener" };
1181
+ const StringInput = memo(function StringInput2(props) {
1182
+ const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
1183
+ const color = useSeverityColor(severity);
1184
+ console.log(inputId, label, fieldProps, field, rest);
1185
+ return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxs(InputWithLabel, { severity, inputId, labelId, label, children: [
1186
+ /* @__PURE__ */ jsx(TextField$1.Input, { ...rest, ...fieldProps, type: field.inputType, id: inputId, color }),
1187
+ /* @__PURE__ */ jsxs(TextField$1.Root, { className: styles$3.TextFieldRoot, children: [
1188
+ /* @__PURE__ */ jsx(
1189
+ "div",
1190
+ {
1191
+ className: classNames(
1192
+ "rt-TextFieldInput rt-r-size-2 rt-variant-surface",
1193
+ styles$3.TextFieldInputCopy
1194
+ ),
1195
+ children: /* @__PURE__ */ jsx(Linkify, { options: linkOptions, children: fieldProps.value })
1196
+ }
1197
+ ),
1198
+ /* @__PURE__ */ jsx("div", { className: "rt-TextFieldChrome" })
1199
+ ] })
1200
+ ] }) });
1201
+ });
1202
+ const _StringField = class _StringField extends StringOrTextField {
1203
+ constructor(options) {
1204
+ const { inputType = "text", ...rest } = options;
1205
+ const maxLength = options.maxLength ? Math.min(500, options.maxLength) : 500;
1206
+ const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
1207
+ super({ ...rest, maxLength, minLength, type: "string" });
1208
+ __publicField(this, "inputType");
1209
+ this.inputType = inputType;
1210
+ }
1211
+ serialize() {
1212
+ return { ...super._serialize(), input_type: this.inputType };
1213
+ }
1214
+ static deserialize(data) {
1215
+ if (data.type !== "string")
1216
+ throw new Error("Type mismatch.");
1217
+ const { maximum_length, minimum_length, input_type, ...rest } = data;
1218
+ return new _StringField({ ...rest, maxLength: maximum_length, minLength: minimum_length, inputType: input_type });
1219
+ }
1220
+ getInput(props) {
1221
+ return /* @__PURE__ */ jsx(StringInput, { field: this, ...props });
1222
+ }
1223
+ };
1224
+ __publicField(_StringField, "fieldTypeName", "Short Text");
1225
+ __publicField(_StringField, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line.");
1226
+ __publicField(_StringField, "Icon", InputIcon);
1227
+ let StringField = _StringField;
1228
+ const TextInput = memo(function TextInput2(props) {
1229
+ const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
1230
+ return /* @__PURE__ */ jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxs(InputWithLabel, { severity, inputId, labelId, label, children: [
1231
+ /* @__PURE__ */ jsx(TextArea, { ...rest, ...fieldProps, resize: "vertical", id: inputId, severity }),
1232
+ /* @__PURE__ */ jsx("div", { className: "rt-TextAreaInput", children: /* @__PURE__ */ jsx(Linkify, { options: linkOptions, children: fieldProps.value }) }),
1233
+ /* @__PURE__ */ jsx("div", { className: "rt-TextAreaChrome" })
1234
+ ] }) });
1235
+ });
1236
+ const _TextField = class _TextField extends StringOrTextField {
1237
+ constructor(options) {
1238
+ const maxLength = options.maxLength ? Math.min(5e3, options.maxLength) : 5e3;
1239
+ const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
1240
+ super({ ...options, maxLength, minLength, type: "text" });
1241
+ }
1242
+ serialize() {
1243
+ return super._serialize();
1244
+ }
1245
+ static deserialize(data) {
1246
+ if (data.type !== "text")
1247
+ throw new Error("Type mismatch.");
1248
+ const { maximum_length, minimum_length, ...rest } = data;
1249
+ return new _TextField({ ...rest, maxLength: maximum_length, minLength: minimum_length });
1250
+ }
1251
+ getInput(props) {
1252
+ return /* @__PURE__ */ jsx(TextInput, { field: this, ...props });
1253
+ }
1254
+ };
1255
+ __publicField(_TextField, "fieldTypeName", "Paragraph");
1256
+ __publicField(_TextField, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines.");
1257
+ __publicField(_TextField, "Icon", RowsIcon);
1258
+ let TextField = _TextField;
1259
+ const FieldInputCloner = memo(function FieldInputCloner2({ field, ...props }) {
1260
+ const [{ value: identifier }] = useField(field.options.clonedFieldIdentifier);
1261
+ const deserializedField = useMemo(() => {
1262
+ const options = field.options.getFieldToClone(identifier);
1263
+ if (!options)
1264
+ return null;
1265
+ return deserialize(options);
1266
+ }, [field.options, identifier]);
1267
+ return useFieldInput(deserializedField, props);
1268
+ });
1269
+ class FieldInputClonerField extends CustomField {
1270
+ constructor(options) {
1271
+ super(options, FieldInputCloner);
1272
+ }
1273
+ }
1274
+ const FieldSectionLayout = memo(function FieldSectionLayout2(props) {
1275
+ const { field: section, ...rest } = props;
1276
+ const { label, description: description2, fields, condition } = section;
1277
+ const { values, setFieldValue } = useFormikContext();
1278
+ const conditionValue = (condition == null ? void 0 : condition.identifier) ? get(values, condition.identifier) : void 0;
1279
+ const conditionMet = useMemo(() => isConditionMet(condition, conditionValue), [condition, conditionValue]);
1280
+ useEffect(() => {
1281
+ if (!conditionMet) {
1282
+ for (const childField of fields) {
1283
+ setFieldValue(childField.getId(), "").then();
1284
+ }
1285
+ }
1286
+ }, [conditionMet, fields, setFieldValue]);
1287
+ const inputs = useFieldInputs(fields, rest);
1288
+ if (!conditionMet) {
1289
+ return null;
1290
+ }
1291
+ if (!label) {
1292
+ return inputs;
1293
+ }
1294
+ return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "3", children: [
1295
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
1296
+ /* @__PURE__ */ jsx(Heading, { as: "h3", size: "3", children: label }),
1297
+ /* @__PURE__ */ jsx(Text, { className: styles$4.description, children: description2 })
1298
+ ] }),
1299
+ inputs
1300
+ ] }) });
1301
+ });
1302
+ const _FieldSection = class _FieldSection extends BaseFormElement {
1303
+ constructor(options) {
1304
+ const { label = null, fields, condition = null, conditional, ...base } = options;
1305
+ super({ ...base, type: "section" });
1306
+ __publicField(this, "label");
1307
+ __publicField(this, "fields");
1308
+ __publicField(this, "condition");
1309
+ this.fields = fields;
1310
+ this.condition = condition;
1311
+ this.label = label;
1312
+ if (conditional === false) {
1313
+ this.condition = null;
1314
+ }
1315
+ }
1316
+ static getFieldCreationSchema(options) {
1317
+ if (options.length === 0)
1318
+ return [];
1319
+ return [
1320
+ new BooleanField({
1321
+ label: "Conditional",
1322
+ description: "Conditionally show or hide this section.",
1323
+ identifier: "conditional",
1324
+ required: false
1325
+ }),
1326
+ // Declare a section that will hold options for the condition (if any).
1327
+ new _FieldSection({
1328
+ label: "Conditional settings",
1329
+ identifier: "conditional-settings",
1330
+ // This section will only be rendered if the above "Conditional" field is checked.
1331
+ condition: {
1332
+ identifier: "conditional",
1333
+ value: true
1334
+ },
1335
+ // These are the options of the condition.
1336
+ fields: [
1337
+ // Declare a select field that will be used to select the field against which we will check the
1338
+ // condition. This must be selected before the next field is rendered.
1339
+ new SelectField({
1340
+ label: "Field",
1341
+ description: "The field to use for the condition.",
1342
+ // The options (for the field against which we will check the condition) are all the labels of
1343
+ // the fields in the previous section(s) (or fields declared before with no section) that
1344
+ // support conditions. We pass in both the label and the identifier of each supported field. The
1345
+ // identifier becomes the value of the option.
1346
+ options: options.map((option) => {
1347
+ if (!option.label)
1348
+ return null;
1349
+ if (option.type === "upload")
1350
+ return null;
1351
+ return {
1352
+ label: option.label,
1353
+ value: option.identifier
1354
+ };
1355
+ }).filter((option) => !!option),
1356
+ identifier: "condition.identifier",
1357
+ required: true
1358
+ }),
1359
+ // Declare a custom field that will be used to input a value for the condition. The value of the
1360
+ // conditional field selected in the previous step must be equal to the value the user inputs into
1361
+ // this field for the section to be rendered.
1362
+ new FieldInputClonerField({
1363
+ label: "Value",
1364
+ identifier: "condition.value",
1365
+ required: true,
1366
+ clonedFieldIdentifier: "condition.identifier",
1367
+ getFieldToClone(identifier) {
1368
+ if (!identifier) {
1369
+ return null;
1370
+ }
1371
+ const option = options.find((option2) => option2.identifier === identifier);
1372
+ if (!option) {
1373
+ console.error("Could not find field with identifier", identifier);
1374
+ return null;
1375
+ }
1376
+ return {
1377
+ ...option,
1378
+ // Override some options to make it make sense in the context and to make it work with the framework.
1379
+ label: "Value",
1380
+ identifier: "condition.value",
1381
+ description: "The value to compare against.",
1382
+ required: option.type !== "boolean"
1383
+ };
1384
+ }
1385
+ })
1386
+ ]
1387
+ })
1388
+ ];
1389
+ }
1390
+ static deserialize(data) {
1391
+ var _a;
1392
+ if (data.type !== "section")
1393
+ throw new Error("Invalid type");
1394
+ const fields = ((_a = data.fields) == null ? void 0 : _a.map(deserializeField)) ?? [];
1395
+ return new _FieldSection({ ...data, fields });
1396
+ }
1397
+ conditional() {
1398
+ return this.condition !== null;
1399
+ }
1400
+ serialize() {
1401
+ return {
1402
+ ...super._serialize(),
1403
+ label: this.label,
1404
+ condition: this.condition,
1405
+ conditional: this.conditional(),
1406
+ fields: this.fields.map((field) => field.serialize())
1407
+ };
1408
+ }
1409
+ getErrors(allValues) {
1410
+ const errors = {};
1411
+ for (const field of this.fields) {
1412
+ const id = field.getId();
1413
+ const error = field.getError(get(allValues, id), allValues);
1414
+ if (error) {
1415
+ set(errors, field.getId(), error);
1416
+ }
1417
+ }
1418
+ return errors;
1419
+ }
1420
+ getInput(props) {
1421
+ return /* @__PURE__ */ jsx(FieldSectionLayout, { field: this, ...props });
1422
+ }
1423
+ };
1424
+ __publicField(_FieldSection, "fieldTypeName", "Section");
1425
+ __publicField(_FieldSection, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
1426
+ let FieldSection = _FieldSection;
1400
1427
  const deserializeField = (serializedField) => {
1401
1428
  const fieldType = serializedField.type;
1402
1429
  const fieldCls = FieldTypeToClsMapping[fieldType];
@@ -1535,7 +1562,7 @@ const FormRenderer = memo(
1535
1562
  [schema.title]
1536
1563
  );
1537
1564
  const Description = useMemo(
1538
- () => typeof schema.description === "string" ? /* @__PURE__ */ jsx(Text, { className: styles$3.description, children: schema.description }) : schema.description,
1565
+ () => typeof schema.description === "string" ? /* @__PURE__ */ jsx(Text, { className: styles$4.description, children: schema.description }) : schema.description,
1539
1566
  [schema.description]
1540
1567
  );
1541
1568
  const inputs = useFieldInputs(schema.fields, { formId: formId2, disabled: readonly });
@@ -2399,7 +2426,7 @@ const FieldSectionWithActions = memo(function FieldSectionWithActions2(props) {
2399
2426
  /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "2", grow: "1", children: [
2400
2427
  /* @__PURE__ */ jsxs(Flex, { direction: "column", children: [
2401
2428
  /* @__PURE__ */ jsx(Heading, { as: "h3", size: "3", children: field.label }),
2402
- /* @__PURE__ */ jsx(Text, { className: styles$3.description, children: field.description })
2429
+ /* @__PURE__ */ jsx(Text, { className: styles$4.description, children: field.description })
2403
2430
  ] }),
2404
2431
  field.condition && /* @__PURE__ */ jsx(Text, { size: "1", children: /* @__PURE__ */ jsxs(Em, { children: [
2405
2432
  "Display only if ",