@overmap-ai/forms 1.0.11 → 1.0.12-fix-dropdown-error.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder/FieldBuilder.d.ts +5 -4
- package/dist/forms.js +82 -35
- package/dist/forms.js.map +1 -1
- package/dist/forms.umd.cjs +81 -34
- package/dist/forms.umd.cjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NestedFieldPath } from "./typings";
|
|
2
|
-
import { FC,
|
|
2
|
+
import { FC, Dispatch, SetStateAction } from "react";
|
|
3
3
|
import { FieldTypeIdentifier, ISerializedField } from "@overmap-ai/core";
|
|
4
4
|
import { Form } from '../typings';
|
|
5
5
|
interface FieldOptionsFormProps {
|
|
@@ -11,13 +11,14 @@ interface FieldOptionsFormProps {
|
|
|
11
11
|
handleDirtyChange: (dirty: boolean) => void;
|
|
12
12
|
handleCreateField: (form: Form) => void;
|
|
13
13
|
}
|
|
14
|
-
interface FieldBuilderProps extends Pick<FieldOptionsFormProps, "conditionalSourceFields"> {
|
|
14
|
+
export interface FieldBuilderProps extends Pick<FieldOptionsFormProps, "conditionalSourceFields"> {
|
|
15
15
|
index: number;
|
|
16
16
|
parentPath: NestedFieldPath;
|
|
17
|
+
isOpen: boolean;
|
|
18
|
+
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
17
19
|
initial?: ISerializedField;
|
|
18
20
|
editing?: boolean;
|
|
19
|
-
children: ReactNode;
|
|
20
21
|
}
|
|
21
|
-
export type FieldBuilderArgs = Omit<FieldBuilderProps, "children">;
|
|
22
|
+
export type FieldBuilderArgs = Omit<FieldBuilderProps, "children" | "isOpen" | "setIsOpen">;
|
|
22
23
|
export declare const FieldBuilder: FC<FieldBuilderProps>;
|
|
23
24
|
export {};
|
package/dist/forms.js
CHANGED
|
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
8
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";
|
|
9
9
|
import { useField, useFormikContext, useFormik, FormikProvider } from "formik";
|
|
10
|
-
import React, { useMemo, memo, useCallback, useState, useEffect, useRef, forwardRef, useReducer } from "react";
|
|
10
|
+
import React, { useMemo, memo, useCallback, useState, useEffect, useRef, forwardRef, Fragment as Fragment$1, useReducer } from "react";
|
|
11
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";
|
|
12
12
|
import { TextField as TextField$1, Box, Card, Heading, Avatar, Em, Strong, Tabs } from "@radix-ui/themes";
|
|
13
13
|
import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd";
|
|
@@ -1992,7 +1992,7 @@ const FieldOptionsForm = memo(function FieldOptionsForm2(props) {
|
|
|
1992
1992
|
);
|
|
1993
1993
|
});
|
|
1994
1994
|
const FieldBuilder = memo(function FieldBuilder2(props) {
|
|
1995
|
-
const { parentPath, index,
|
|
1995
|
+
const { parentPath, index, isOpen, setIsOpen, initial, editing, conditionalSourceFields } = props;
|
|
1996
1996
|
const [fieldType, setFieldType] = useState();
|
|
1997
1997
|
const [formIsDirty, setFormIsDirty] = useState(false);
|
|
1998
1998
|
const type = (initial == null ? void 0 : initial.type) ?? fieldType;
|
|
@@ -2008,21 +2008,21 @@ const FieldBuilder = memo(function FieldBuilder2(props) {
|
|
|
2008
2008
|
setFieldType(void 0);
|
|
2009
2009
|
setFormIsDirty(false);
|
|
2010
2010
|
}, []);
|
|
2011
|
-
const
|
|
2012
|
-
(
|
|
2013
|
-
if (formIsDirty) {
|
|
2011
|
+
const handleCloseDialog = useCallback(
|
|
2012
|
+
(force) => {
|
|
2013
|
+
if (force || !formIsDirty) {
|
|
2014
|
+
setFieldType(void 0);
|
|
2015
|
+
setIsOpen(false);
|
|
2016
|
+
} else {
|
|
2014
2017
|
openConfirmDiscardChangesDialog({
|
|
2015
2018
|
onDiscard: () => {
|
|
2016
2019
|
setFieldType(void 0);
|
|
2017
|
-
|
|
2020
|
+
setIsOpen(false);
|
|
2018
2021
|
}
|
|
2019
2022
|
});
|
|
2020
|
-
} else {
|
|
2021
|
-
setFieldType(void 0);
|
|
2022
|
-
confirmClose();
|
|
2023
2023
|
}
|
|
2024
2024
|
},
|
|
2025
|
-
[formIsDirty, openConfirmDiscardChangesDialog]
|
|
2025
|
+
[formIsDirty, openConfirmDiscardChangesDialog, setIsOpen]
|
|
2026
2026
|
);
|
|
2027
2027
|
const handleCreateField = useCallback(
|
|
2028
2028
|
(form, closeDialog) => {
|
|
@@ -2073,22 +2073,32 @@ const FieldBuilder = memo(function FieldBuilder2(props) {
|
|
|
2073
2073
|
},
|
|
2074
2074
|
[conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]
|
|
2075
2075
|
);
|
|
2076
|
-
return /* @__PURE__ */ jsx(
|
|
2076
|
+
return /* @__PURE__ */ jsx(
|
|
2077
|
+
Dialog,
|
|
2078
|
+
{
|
|
2079
|
+
title: title2,
|
|
2080
|
+
description: description2,
|
|
2081
|
+
content: dialogContent,
|
|
2082
|
+
open: isOpen,
|
|
2083
|
+
onOpenChange: handleCloseDialog
|
|
2084
|
+
}
|
|
2085
|
+
);
|
|
2077
2086
|
});
|
|
2078
|
-
const DefaultWrapper = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
2079
2087
|
const forMobile = (mobile, display) => ({
|
|
2080
2088
|
initial: mobile ? display : "none",
|
|
2081
2089
|
sm: mobile ? "none" : display
|
|
2082
2090
|
});
|
|
2083
2091
|
const FieldActions = memo(function FieldActions2(props) {
|
|
2084
2092
|
const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
|
|
2093
|
+
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
2085
2094
|
const actions = useMemo(
|
|
2086
2095
|
() => [
|
|
2087
2096
|
{
|
|
2088
|
-
|
|
2089
|
-
|
|
2097
|
+
SelectedContent: FieldBuilder,
|
|
2098
|
+
selectedContentProps: { ...editProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2090
2099
|
Icon: Pencil1Icon,
|
|
2091
|
-
text: "Edit"
|
|
2100
|
+
text: "Edit",
|
|
2101
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2092
2102
|
},
|
|
2093
2103
|
{
|
|
2094
2104
|
Icon: TrashIcon,
|
|
@@ -2098,16 +2108,18 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2098
2108
|
text: "Delete"
|
|
2099
2109
|
},
|
|
2100
2110
|
{
|
|
2101
|
-
|
|
2102
|
-
|
|
2111
|
+
SelectedContent: FieldBuilder,
|
|
2112
|
+
selectedContentProps: { ...duplicateProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2103
2113
|
Icon: CopyIcon,
|
|
2104
|
-
text: "Duplicate"
|
|
2114
|
+
text: "Duplicate",
|
|
2115
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2105
2116
|
},
|
|
2106
2117
|
{
|
|
2107
|
-
|
|
2108
|
-
|
|
2118
|
+
SelectedContent: FieldBuilder,
|
|
2119
|
+
selectedContentProps: { ...insertAfterProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2109
2120
|
Icon: PlusIcon,
|
|
2110
|
-
text: "Add after"
|
|
2121
|
+
text: "Add after",
|
|
2122
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2111
2123
|
},
|
|
2112
2124
|
{
|
|
2113
2125
|
// Wrapping icon in a div so that the asChild turns the button into a div
|
|
@@ -2119,12 +2131,14 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2119
2131
|
buttonProps: { ...dragHandleProps, asChild: true }
|
|
2120
2132
|
}
|
|
2121
2133
|
],
|
|
2122
|
-
[dragHandleProps, duplicateProps, editProps, insertAfterProps, remove2]
|
|
2134
|
+
[dragHandleProps, duplicateProps, editProps, insertAfterProps, isDialogOpen, remove2]
|
|
2123
2135
|
);
|
|
2124
2136
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2125
2137
|
/* @__PURE__ */ jsx(Flex, { gap: "4", display: forMobile(false, "flex"), children: actions.map((Action) => {
|
|
2126
|
-
|
|
2127
|
-
|
|
2138
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2139
|
+
/* @__PURE__ */ jsx(IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsx(Action.Icon, {}) }),
|
|
2140
|
+
Action.SelectedContent && /* @__PURE__ */ jsx(Action.SelectedContent, { ...Action.selectedContentProps })
|
|
2141
|
+
] }, Action.text);
|
|
2128
2142
|
}) }),
|
|
2129
2143
|
/* @__PURE__ */ jsx(Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsx(
|
|
2130
2144
|
DropdownItemMenu,
|
|
@@ -2135,14 +2149,21 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2135
2149
|
var _a;
|
|
2136
2150
|
if (Action.disableOnMobile)
|
|
2137
2151
|
return null;
|
|
2138
|
-
const Wrapper = Action.Wrapper ?? DefaultWrapper;
|
|
2139
2152
|
return {
|
|
2140
2153
|
...Action.buttonProps,
|
|
2141
2154
|
onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
|
|
2142
|
-
content: /* @__PURE__ */
|
|
2143
|
-
/* @__PURE__ */
|
|
2144
|
-
|
|
2145
|
-
|
|
2155
|
+
content: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2156
|
+
/* @__PURE__ */ jsxs(Flex, { gap: "2", align: "center", children: [
|
|
2157
|
+
/* @__PURE__ */ jsx(Action.Icon, {}),
|
|
2158
|
+
Action.text
|
|
2159
|
+
] }),
|
|
2160
|
+
Action.SelectedContent && /* @__PURE__ */ jsx(
|
|
2161
|
+
Action.SelectedContent,
|
|
2162
|
+
{
|
|
2163
|
+
...Action.selectedContentProps
|
|
2164
|
+
}
|
|
2165
|
+
)
|
|
2166
|
+
] }, Action.text)
|
|
2146
2167
|
};
|
|
2147
2168
|
}).filter((x) => x !== null)
|
|
2148
2169
|
}
|
|
@@ -2213,6 +2234,7 @@ const FieldSectionWithActions = memo(function FieldSectionWithActions2(props) {
|
|
|
2213
2234
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2214
2235
|
const { field, index: sectionIndex, dropState } = props;
|
|
2215
2236
|
const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
|
|
2237
|
+
const [isAddFieldDialogOpen, setIsAddFieldDialogOpen] = useState(false);
|
|
2216
2238
|
const { setFieldValue, values } = useFormikContext();
|
|
2217
2239
|
const alertDialog = useAlertDialog();
|
|
2218
2240
|
const takenFieldLabels = getTakenFieldLabels(values.fields);
|
|
@@ -2403,10 +2425,26 @@ const FieldSectionWithActions = memo(function FieldSectionWithActions2(props) {
|
|
|
2403
2425
|
child.identifier
|
|
2404
2426
|
)),
|
|
2405
2427
|
droppableProvided.placeholder,
|
|
2406
|
-
/* @__PURE__ */
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2428
|
+
/* @__PURE__ */ jsxs(
|
|
2429
|
+
Button,
|
|
2430
|
+
{
|
|
2431
|
+
type: "button",
|
|
2432
|
+
variant: "outline",
|
|
2433
|
+
onClick: () => setIsAddFieldDialogOpen(true),
|
|
2434
|
+
children: [
|
|
2435
|
+
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
2436
|
+
" Add a field"
|
|
2437
|
+
]
|
|
2438
|
+
}
|
|
2439
|
+
),
|
|
2440
|
+
/* @__PURE__ */ jsx(
|
|
2441
|
+
FieldBuilder,
|
|
2442
|
+
{
|
|
2443
|
+
...insertFieldAtEndOfSection,
|
|
2444
|
+
isOpen: isAddFieldDialogOpen,
|
|
2445
|
+
setIsOpen: setIsAddFieldDialogOpen
|
|
2446
|
+
}
|
|
2447
|
+
)
|
|
2410
2448
|
]
|
|
2411
2449
|
}
|
|
2412
2450
|
) })
|
|
@@ -2489,6 +2527,7 @@ const findSection = (fields, sectionId) => {
|
|
|
2489
2527
|
const FieldsEditor = memo(function FieldsEditor2() {
|
|
2490
2528
|
const { values, setFieldValue } = useFormikContext();
|
|
2491
2529
|
const [dropState, dispatch] = useReducer(reducer, values.fields, initializer);
|
|
2530
|
+
const [isAddSectionDialogOpen, setIsAddSectionDialogOpen] = useState(false);
|
|
2492
2531
|
const { showInfo } = useToast();
|
|
2493
2532
|
useEffect(() => {
|
|
2494
2533
|
dispatch({ type: "update", state: initializer(values.fields) });
|
|
@@ -2576,10 +2615,18 @@ const FieldsEditor = memo(function FieldsEditor2() {
|
|
|
2576
2615
|
field.label
|
|
2577
2616
|
)),
|
|
2578
2617
|
droppableProvided.placeholder,
|
|
2579
|
-
/* @__PURE__ */
|
|
2618
|
+
/* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", onClick: () => setIsAddSectionDialogOpen(true), children: [
|
|
2580
2619
|
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
2581
2620
|
" Add a section"
|
|
2582
|
-
] })
|
|
2621
|
+
] }),
|
|
2622
|
+
/* @__PURE__ */ jsx(
|
|
2623
|
+
FieldBuilder,
|
|
2624
|
+
{
|
|
2625
|
+
...makeFieldSectionProps,
|
|
2626
|
+
isOpen: isAddSectionDialogOpen,
|
|
2627
|
+
setIsOpen: setIsAddSectionDialogOpen
|
|
2628
|
+
}
|
|
2629
|
+
)
|
|
2583
2630
|
]
|
|
2584
2631
|
}
|
|
2585
2632
|
) }) });
|