@overmap-ai/forms 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/forms.umd.cjs
CHANGED
|
@@ -1498,6 +1498,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1498
1498
|
cancelText,
|
|
1499
1499
|
onCancel,
|
|
1500
1500
|
onDirty,
|
|
1501
|
+
onDirtyChange,
|
|
1501
1502
|
// if the title isn't provided, hide it by default
|
|
1502
1503
|
hideTitle = !schema.title,
|
|
1503
1504
|
hideDescription,
|
|
@@ -1526,7 +1527,9 @@ var __publicField = (obj, key, value) => {
|
|
|
1526
1527
|
React.useEffect(() => {
|
|
1527
1528
|
if (dirty && onDirty)
|
|
1528
1529
|
onDirty();
|
|
1529
|
-
|
|
1530
|
+
if (onDirtyChange)
|
|
1531
|
+
onDirtyChange(dirty);
|
|
1532
|
+
}, [dirty, onDirty, onDirtyChange]);
|
|
1530
1533
|
return /* @__PURE__ */ jsxRuntime.jsx(formik.FormikProvider, { value: formik$1, children: /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { ref, direction: "column", gap: "2", className, asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { id: formId2, onSubmit: formik$1.handleSubmit, children: [
|
|
1531
1534
|
!hideTitle && /* @__PURE__ */ jsxRuntime.jsx(blocks.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "1", children: [
|
|
1532
1535
|
Title,
|
|
@@ -1938,7 +1941,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1938
1941
|
];
|
|
1939
1942
|
};
|
|
1940
1943
|
const FieldOptionsForm = React.memo(function FieldOptionsForm2(props) {
|
|
1941
|
-
const { fieldType, handleCancel, handleCreateField, defaultField, conditionalSourceFields } = props;
|
|
1944
|
+
const { fieldType, handleCancel, handleCreateField, handleDirtyChange, defaultField, conditionalSourceFields } = props;
|
|
1942
1945
|
const fieldCls = CompleteFieldTypeToClsMapping[fieldType];
|
|
1943
1946
|
const formik$1 = formik.useFormikContext();
|
|
1944
1947
|
const schema = React.useMemo(() => {
|
|
@@ -1969,26 +1972,44 @@ var __publicField = (obj, key, value) => {
|
|
|
1969
1972
|
values: defaultField,
|
|
1970
1973
|
onSubmit: handleCreateField,
|
|
1971
1974
|
cancelText: defaultField ? void 0 : "Back",
|
|
1972
|
-
onCancel: handleCancel
|
|
1975
|
+
onCancel: handleCancel,
|
|
1976
|
+
onDirtyChange: handleDirtyChange
|
|
1973
1977
|
}
|
|
1974
1978
|
);
|
|
1975
1979
|
});
|
|
1976
1980
|
const FieldBuilder = React.memo(function FieldBuilder2(props) {
|
|
1977
1981
|
const { parentPath, index, children, initial, editing, conditionalSourceFields } = props;
|
|
1978
1982
|
const [fieldType, setFieldType] = React.useState();
|
|
1983
|
+
const [formIsDirty, setFormIsDirty] = React.useState(false);
|
|
1979
1984
|
const type = (initial == null ? void 0 : initial.type) ?? fieldType;
|
|
1980
1985
|
const typeName = type ? CompleteFieldTypeToClsMapping[type].fieldTypeName : void 0;
|
|
1981
1986
|
const { setFieldValue, values } = formik.useFormikContext();
|
|
1982
1987
|
if (editing && !initial)
|
|
1983
1988
|
throw new Error("Initial field must be provided if editing is true.");
|
|
1989
|
+
const openConfirmDiscardChangesDialog = blocks.useDiscardAlertDialog();
|
|
1984
1990
|
const showChooseField = !type && !editing && !initial;
|
|
1985
1991
|
const title2 = showChooseField ? "Choose a field type" : `${typeName} settings`;
|
|
1986
1992
|
const description2 = showChooseField ? "Select a field type to add to this section." : (typeName == null ? void 0 : typeName.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${typeName == null ? void 0 : typeName.toLowerCase()} field.`;
|
|
1987
|
-
const handleCancel = React.useCallback(() =>
|
|
1988
|
-
const handleCloseInterrupt = React.useCallback((confirmClose) => {
|
|
1993
|
+
const handleCancel = React.useCallback(() => {
|
|
1989
1994
|
setFieldType(void 0);
|
|
1990
|
-
|
|
1995
|
+
setFormIsDirty(false);
|
|
1991
1996
|
}, []);
|
|
1997
|
+
const handleCloseInterrupt = React.useCallback(
|
|
1998
|
+
(confirmClose) => {
|
|
1999
|
+
if (formIsDirty) {
|
|
2000
|
+
openConfirmDiscardChangesDialog({
|
|
2001
|
+
onDiscard: () => {
|
|
2002
|
+
setFieldType(void 0);
|
|
2003
|
+
confirmClose();
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
} else {
|
|
2007
|
+
setFieldType(void 0);
|
|
2008
|
+
confirmClose();
|
|
2009
|
+
}
|
|
2010
|
+
},
|
|
2011
|
+
[formIsDirty, openConfirmDiscardChangesDialog]
|
|
2012
|
+
);
|
|
1992
2013
|
const handleCreateField = React.useCallback(
|
|
1993
2014
|
(form, closeDialog) => {
|
|
1994
2015
|
const { label } = form;
|
|
@@ -2014,10 +2035,11 @@ var __publicField = (obj, key, value) => {
|
|
|
2014
2035
|
newFields = insert(parent, index, field);
|
|
2015
2036
|
}
|
|
2016
2037
|
setFieldValue(parentPath, newFields).then();
|
|
2017
|
-
closeDialog();
|
|
2038
|
+
closeDialog({ force: true });
|
|
2018
2039
|
},
|
|
2019
2040
|
[editing, type, values, parentPath, setFieldValue, index]
|
|
2020
2041
|
);
|
|
2042
|
+
const handleDirtyChange = React.useCallback((dirty) => setFormIsDirty(dirty), []);
|
|
2021
2043
|
const dialogContent = React.useCallback(
|
|
2022
2044
|
(closeDialog) => {
|
|
2023
2045
|
if (showChooseField) {
|
|
@@ -2030,11 +2052,12 @@ var __publicField = (obj, key, value) => {
|
|
|
2030
2052
|
handleCancel,
|
|
2031
2053
|
handleCreateField: (form) => handleCreateField(form, closeDialog),
|
|
2032
2054
|
fieldType: type,
|
|
2033
|
-
defaultField: initial
|
|
2055
|
+
defaultField: initial,
|
|
2056
|
+
handleDirtyChange
|
|
2034
2057
|
}
|
|
2035
2058
|
);
|
|
2036
2059
|
},
|
|
2037
|
-
[conditionalSourceFields, handleCancel, handleCreateField, initial, showChooseField, type]
|
|
2060
|
+
[conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]
|
|
2038
2061
|
);
|
|
2039
2062
|
return /* @__PURE__ */ jsxRuntime.jsx(blocks.Dialog, { onCloseInterrupt: handleCloseInterrupt, title: title2, description: description2, content: dialogContent, children });
|
|
2040
2063
|
});
|
|
@@ -2175,7 +2198,7 @@ var __publicField = (obj, key, value) => {
|
|
|
2175
2198
|
) });
|
|
2176
2199
|
});
|
|
2177
2200
|
const FieldSectionWithActions = React.memo(function FieldSectionWithActions2(props) {
|
|
2178
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2201
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2179
2202
|
const { field, index: sectionIndex, dropState } = props;
|
|
2180
2203
|
const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
|
|
2181
2204
|
const { setFieldValue, values } = formik.useFormikContext();
|
|
@@ -2328,7 +2351,7 @@ var __publicField = (obj, key, value) => {
|
|
|
2328
2351
|
const conditionComparison = Array.isArray((_c = field.condition) == null ? void 0 : _c.value) ? "contains all of" : "equals";
|
|
2329
2352
|
if (valueIsFile((_d = field.condition) == null ? void 0 : _d.value))
|
|
2330
2353
|
throw new Error("File values are not supported for conditions.");
|
|
2331
|
-
const conditionValue = Array.isArray((_e = field.condition) == null ? void 0 : _e.value) ? (_f = field.condition) == null ? void 0 : _f.value.map((v) => typeof v === "string" ? v : v.label).join(", ") : (
|
|
2354
|
+
const conditionValue = Array.isArray((_e = field.condition) == null ? void 0 : _e.value) ? (_g = (_f = field.condition) == null ? void 0 : _f.value) == null ? void 0 : _g.map((v) => typeof v === "string" ? v : v.label).join(", ") : (_i = (_h = field.condition) == null ? void 0 : _h.value) == null ? void 0 : _i.toString();
|
|
2332
2355
|
return /* @__PURE__ */ jsxRuntime.jsx(dnd.Draggable, { draggableId: field.identifier, index: sectionIndex, children: (draggableProvided) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2333
2356
|
blocks.Card,
|
|
2334
2357
|
{
|