@overmap-ai/forms 1.0.11 → 1.0.12-fix-dropdown-error.2
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 +81 -37
- package/dist/forms.js.map +1 -1
- package/dist/forms.umd.cjs +80 -36
- 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) => {
|
|
@@ -2049,13 +2049,15 @@ const FieldBuilder = memo(function FieldBuilder2(props) {
|
|
|
2049
2049
|
newFields = insert(parent, index, field);
|
|
2050
2050
|
}
|
|
2051
2051
|
setFieldValue(parentPath, newFields).then();
|
|
2052
|
-
|
|
2052
|
+
setIsOpen(false);
|
|
2053
|
+
console.log(closeDialog);
|
|
2053
2054
|
},
|
|
2054
|
-
[
|
|
2055
|
+
[type, values, parentPath, editing, setFieldValue, setIsOpen, index]
|
|
2055
2056
|
);
|
|
2056
2057
|
const handleDirtyChange = useCallback((dirty) => setFormIsDirty(dirty), []);
|
|
2057
2058
|
const dialogContent = useCallback(
|
|
2058
2059
|
(closeDialog) => {
|
|
2060
|
+
console.log(showChooseField, type, editing, initial);
|
|
2059
2061
|
if (showChooseField) {
|
|
2060
2062
|
return /* @__PURE__ */ jsx(ChooseFieldToAdd, { setFieldType });
|
|
2061
2063
|
}
|
|
@@ -2073,22 +2075,32 @@ const FieldBuilder = memo(function FieldBuilder2(props) {
|
|
|
2073
2075
|
},
|
|
2074
2076
|
[conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]
|
|
2075
2077
|
);
|
|
2076
|
-
return /* @__PURE__ */ jsx(
|
|
2078
|
+
return /* @__PURE__ */ jsx(
|
|
2079
|
+
Dialog,
|
|
2080
|
+
{
|
|
2081
|
+
title: title2,
|
|
2082
|
+
description: description2,
|
|
2083
|
+
content: dialogContent,
|
|
2084
|
+
open: isOpen,
|
|
2085
|
+
onOpenChange: handleCloseDialog
|
|
2086
|
+
}
|
|
2087
|
+
);
|
|
2077
2088
|
});
|
|
2078
|
-
const DefaultWrapper = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
2079
2089
|
const forMobile = (mobile, display) => ({
|
|
2080
2090
|
initial: mobile ? display : "none",
|
|
2081
2091
|
sm: mobile ? "none" : display
|
|
2082
2092
|
});
|
|
2083
2093
|
const FieldActions = memo(function FieldActions2(props) {
|
|
2084
2094
|
const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
|
|
2095
|
+
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
2085
2096
|
const actions = useMemo(
|
|
2086
2097
|
() => [
|
|
2087
2098
|
{
|
|
2088
|
-
|
|
2089
|
-
|
|
2099
|
+
SelectedContent: FieldBuilder,
|
|
2100
|
+
selectedContentProps: { ...editProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2090
2101
|
Icon: Pencil1Icon,
|
|
2091
|
-
text: "Edit"
|
|
2102
|
+
text: "Edit",
|
|
2103
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2092
2104
|
},
|
|
2093
2105
|
{
|
|
2094
2106
|
Icon: TrashIcon,
|
|
@@ -2098,16 +2110,18 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2098
2110
|
text: "Delete"
|
|
2099
2111
|
},
|
|
2100
2112
|
{
|
|
2101
|
-
|
|
2102
|
-
|
|
2113
|
+
SelectedContent: FieldBuilder,
|
|
2114
|
+
selectedContentProps: { ...duplicateProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2103
2115
|
Icon: CopyIcon,
|
|
2104
|
-
text: "Duplicate"
|
|
2116
|
+
text: "Duplicate",
|
|
2117
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2105
2118
|
},
|
|
2106
2119
|
{
|
|
2107
|
-
|
|
2108
|
-
|
|
2120
|
+
SelectedContent: FieldBuilder,
|
|
2121
|
+
selectedContentProps: { ...insertAfterProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
|
|
2109
2122
|
Icon: PlusIcon,
|
|
2110
|
-
text: "Add after"
|
|
2123
|
+
text: "Add after",
|
|
2124
|
+
buttonProps: { onClick: () => setIsDialogOpen(true) }
|
|
2111
2125
|
},
|
|
2112
2126
|
{
|
|
2113
2127
|
// Wrapping icon in a div so that the asChild turns the button into a div
|
|
@@ -2119,12 +2133,14 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2119
2133
|
buttonProps: { ...dragHandleProps, asChild: true }
|
|
2120
2134
|
}
|
|
2121
2135
|
],
|
|
2122
|
-
[dragHandleProps, duplicateProps, editProps, insertAfterProps, remove2]
|
|
2136
|
+
[dragHandleProps, duplicateProps, editProps, insertAfterProps, isDialogOpen, remove2]
|
|
2123
2137
|
);
|
|
2124
2138
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2125
2139
|
/* @__PURE__ */ jsx(Flex, { gap: "4", display: forMobile(false, "flex"), children: actions.map((Action) => {
|
|
2126
|
-
|
|
2127
|
-
|
|
2140
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2141
|
+
/* @__PURE__ */ jsx(IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsx(Action.Icon, {}) }),
|
|
2142
|
+
Action.SelectedContent && /* @__PURE__ */ jsx(Action.SelectedContent, { ...Action.selectedContentProps })
|
|
2143
|
+
] }, Action.text);
|
|
2128
2144
|
}) }),
|
|
2129
2145
|
/* @__PURE__ */ jsx(Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsx(
|
|
2130
2146
|
DropdownItemMenu,
|
|
@@ -2135,14 +2151,16 @@ const FieldActions = memo(function FieldActions2(props) {
|
|
|
2135
2151
|
var _a;
|
|
2136
2152
|
if (Action.disableOnMobile)
|
|
2137
2153
|
return null;
|
|
2138
|
-
const Wrapper = Action.Wrapper ?? DefaultWrapper;
|
|
2139
2154
|
return {
|
|
2140
2155
|
...Action.buttonProps,
|
|
2141
2156
|
onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
|
|
2142
|
-
content: /* @__PURE__ */
|
|
2143
|
-
/* @__PURE__ */
|
|
2144
|
-
|
|
2145
|
-
|
|
2157
|
+
content: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2158
|
+
/* @__PURE__ */ jsxs(Flex, { gap: "2", align: "center", children: [
|
|
2159
|
+
/* @__PURE__ */ jsx(Action.Icon, {}),
|
|
2160
|
+
Action.text
|
|
2161
|
+
] }),
|
|
2162
|
+
Action.SelectedContent && /* @__PURE__ */ jsx(Action.SelectedContent, { ...Action.selectedContentProps })
|
|
2163
|
+
] }, Action.text)
|
|
2146
2164
|
};
|
|
2147
2165
|
}).filter((x) => x !== null)
|
|
2148
2166
|
}
|
|
@@ -2213,6 +2231,7 @@ const FieldSectionWithActions = memo(function FieldSectionWithActions2(props) {
|
|
|
2213
2231
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2214
2232
|
const { field, index: sectionIndex, dropState } = props;
|
|
2215
2233
|
const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
|
|
2234
|
+
const [isAddFieldDialogOpen, setIsAddFieldDialogOpen] = useState(false);
|
|
2216
2235
|
const { setFieldValue, values } = useFormikContext();
|
|
2217
2236
|
const alertDialog = useAlertDialog();
|
|
2218
2237
|
const takenFieldLabels = getTakenFieldLabels(values.fields);
|
|
@@ -2403,10 +2422,26 @@ const FieldSectionWithActions = memo(function FieldSectionWithActions2(props) {
|
|
|
2403
2422
|
child.identifier
|
|
2404
2423
|
)),
|
|
2405
2424
|
droppableProvided.placeholder,
|
|
2406
|
-
/* @__PURE__ */
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2425
|
+
/* @__PURE__ */ jsxs(
|
|
2426
|
+
Button,
|
|
2427
|
+
{
|
|
2428
|
+
type: "button",
|
|
2429
|
+
variant: "outline",
|
|
2430
|
+
onClick: () => setIsAddFieldDialogOpen(true),
|
|
2431
|
+
children: [
|
|
2432
|
+
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
2433
|
+
" Add a field"
|
|
2434
|
+
]
|
|
2435
|
+
}
|
|
2436
|
+
),
|
|
2437
|
+
/* @__PURE__ */ jsx(
|
|
2438
|
+
FieldBuilder,
|
|
2439
|
+
{
|
|
2440
|
+
...insertFieldAtEndOfSection,
|
|
2441
|
+
isOpen: isAddFieldDialogOpen,
|
|
2442
|
+
setIsOpen: setIsAddFieldDialogOpen
|
|
2443
|
+
}
|
|
2444
|
+
)
|
|
2410
2445
|
]
|
|
2411
2446
|
}
|
|
2412
2447
|
) })
|
|
@@ -2489,6 +2524,7 @@ const findSection = (fields, sectionId) => {
|
|
|
2489
2524
|
const FieldsEditor = memo(function FieldsEditor2() {
|
|
2490
2525
|
const { values, setFieldValue } = useFormikContext();
|
|
2491
2526
|
const [dropState, dispatch] = useReducer(reducer, values.fields, initializer);
|
|
2527
|
+
const [isAddSectionDialogOpen, setIsAddSectionDialogOpen] = useState(false);
|
|
2492
2528
|
const { showInfo } = useToast();
|
|
2493
2529
|
useEffect(() => {
|
|
2494
2530
|
dispatch({ type: "update", state: initializer(values.fields) });
|
|
@@ -2576,10 +2612,18 @@ const FieldsEditor = memo(function FieldsEditor2() {
|
|
|
2576
2612
|
field.label
|
|
2577
2613
|
)),
|
|
2578
2614
|
droppableProvided.placeholder,
|
|
2579
|
-
/* @__PURE__ */
|
|
2615
|
+
/* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", onClick: () => setIsAddSectionDialogOpen(true), children: [
|
|
2580
2616
|
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
2581
2617
|
" Add a section"
|
|
2582
|
-
] })
|
|
2618
|
+
] }),
|
|
2619
|
+
/* @__PURE__ */ jsx(
|
|
2620
|
+
FieldBuilder,
|
|
2621
|
+
{
|
|
2622
|
+
...makeFieldSectionProps,
|
|
2623
|
+
isOpen: isAddSectionDialogOpen,
|
|
2624
|
+
setIsOpen: setIsAddSectionDialogOpen
|
|
2625
|
+
}
|
|
2626
|
+
)
|
|
2583
2627
|
]
|
|
2584
2628
|
}
|
|
2585
2629
|
) }) });
|