@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.
@@ -1985,7 +1985,7 @@ var __publicField = (obj, key, value) => {
1985
1985
  );
1986
1986
  });
1987
1987
  const FieldBuilder = React.memo(function FieldBuilder2(props) {
1988
- const { parentPath, index, children, initial, editing, conditionalSourceFields } = props;
1988
+ const { parentPath, index, isOpen, setIsOpen, initial, editing, conditionalSourceFields } = props;
1989
1989
  const [fieldType, setFieldType] = React.useState();
1990
1990
  const [formIsDirty, setFormIsDirty] = React.useState(false);
1991
1991
  const type = (initial == null ? void 0 : initial.type) ?? fieldType;
@@ -2001,21 +2001,21 @@ var __publicField = (obj, key, value) => {
2001
2001
  setFieldType(void 0);
2002
2002
  setFormIsDirty(false);
2003
2003
  }, []);
2004
- const handleCloseInterrupt = React.useCallback(
2005
- (confirmClose) => {
2006
- if (formIsDirty) {
2004
+ const handleCloseDialog = React.useCallback(
2005
+ (force) => {
2006
+ if (force || !formIsDirty) {
2007
+ setFieldType(void 0);
2008
+ setIsOpen(false);
2009
+ } else {
2007
2010
  openConfirmDiscardChangesDialog({
2008
2011
  onDiscard: () => {
2009
2012
  setFieldType(void 0);
2010
- confirmClose();
2013
+ setIsOpen(false);
2011
2014
  }
2012
2015
  });
2013
- } else {
2014
- setFieldType(void 0);
2015
- confirmClose();
2016
2016
  }
2017
2017
  },
2018
- [formIsDirty, openConfirmDiscardChangesDialog]
2018
+ [formIsDirty, openConfirmDiscardChangesDialog, setIsOpen]
2019
2019
  );
2020
2020
  const handleCreateField = React.useCallback(
2021
2021
  (form, closeDialog) => {
@@ -2066,22 +2066,32 @@ var __publicField = (obj, key, value) => {
2066
2066
  },
2067
2067
  [conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]
2068
2068
  );
2069
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Dialog, { onCloseInterrupt: handleCloseInterrupt, title: title2, description: description2, content: dialogContent, children });
2069
+ return /* @__PURE__ */ jsxRuntime.jsx(
2070
+ blocks.Dialog,
2071
+ {
2072
+ title: title2,
2073
+ description: description2,
2074
+ content: dialogContent,
2075
+ open: isOpen,
2076
+ onOpenChange: handleCloseDialog
2077
+ }
2078
+ );
2070
2079
  });
2071
- const DefaultWrapper = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2072
2080
  const forMobile = (mobile, display) => ({
2073
2081
  initial: mobile ? display : "none",
2074
2082
  sm: mobile ? "none" : display
2075
2083
  });
2076
2084
  const FieldActions = React.memo(function FieldActions2(props) {
2077
2085
  const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
2086
+ const [isDialogOpen, setIsDialogOpen] = React.useState(false);
2078
2087
  const actions = React.useMemo(
2079
2088
  () => [
2080
2089
  {
2081
- Wrapper: FieldBuilder,
2082
- wrapperProps: editProps,
2090
+ SelectedContent: FieldBuilder,
2091
+ selectedContentProps: { ...editProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2083
2092
  Icon: reactIcons.Pencil1Icon,
2084
- text: "Edit"
2093
+ text: "Edit",
2094
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2085
2095
  },
2086
2096
  {
2087
2097
  Icon: reactIcons.TrashIcon,
@@ -2091,16 +2101,18 @@ var __publicField = (obj, key, value) => {
2091
2101
  text: "Delete"
2092
2102
  },
2093
2103
  {
2094
- Wrapper: FieldBuilder,
2095
- wrapperProps: duplicateProps,
2104
+ SelectedContent: FieldBuilder,
2105
+ selectedContentProps: { ...duplicateProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2096
2106
  Icon: reactIcons.CopyIcon,
2097
- text: "Duplicate"
2107
+ text: "Duplicate",
2108
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2098
2109
  },
2099
2110
  {
2100
- Wrapper: FieldBuilder,
2101
- wrapperProps: insertAfterProps,
2111
+ SelectedContent: FieldBuilder,
2112
+ selectedContentProps: { ...insertAfterProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2102
2113
  Icon: reactIcons.PlusIcon,
2103
- text: "Add after"
2114
+ text: "Add after",
2115
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2104
2116
  },
2105
2117
  {
2106
2118
  // Wrapping icon in a div so that the asChild turns the button into a div
@@ -2112,12 +2124,14 @@ var __publicField = (obj, key, value) => {
2112
2124
  buttonProps: { ...dragHandleProps, asChild: true }
2113
2125
  }
2114
2126
  ],
2115
- [dragHandleProps, duplicateProps, editProps, insertAfterProps, remove2]
2127
+ [dragHandleProps, duplicateProps, editProps, insertAfterProps, isDialogOpen, remove2]
2116
2128
  );
2117
2129
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2118
2130
  /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { gap: "4", display: forMobile(false, "flex"), children: actions.map((Action) => {
2119
- const Wrapper = Action.Wrapper ?? DefaultWrapper;
2120
- return /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...Action.wrapperProps, children: /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}) }) }, Action.text);
2131
+ return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2132
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}) }),
2133
+ Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(Action.SelectedContent, { ...Action.selectedContentProps })
2134
+ ] }, Action.text);
2121
2135
  }) }),
2122
2136
  /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsxRuntime.jsx(
2123
2137
  blocks.DropdownItemMenu,
@@ -2128,14 +2142,21 @@ var __publicField = (obj, key, value) => {
2128
2142
  var _a;
2129
2143
  if (Action.disableOnMobile)
2130
2144
  return null;
2131
- const Wrapper = Action.Wrapper ?? DefaultWrapper;
2132
2145
  return {
2133
2146
  ...Action.buttonProps,
2134
2147
  onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
2135
- content: /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...Action.wrapperProps, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2136
- /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2137
- Action.text
2138
- ] }) })
2148
+ content: /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2149
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2150
+ /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2151
+ Action.text
2152
+ ] }),
2153
+ Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(
2154
+ Action.SelectedContent,
2155
+ {
2156
+ ...Action.selectedContentProps
2157
+ }
2158
+ )
2159
+ ] }, Action.text)
2139
2160
  };
2140
2161
  }).filter((x) => x !== null)
2141
2162
  }
@@ -2206,6 +2227,7 @@ var __publicField = (obj, key, value) => {
2206
2227
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2207
2228
  const { field, index: sectionIndex, dropState } = props;
2208
2229
  const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
2230
+ const [isAddFieldDialogOpen, setIsAddFieldDialogOpen] = React.useState(false);
2209
2231
  const { setFieldValue, values } = formik.useFormikContext();
2210
2232
  const alertDialog = blocks.useAlertDialog();
2211
2233
  const takenFieldLabels = getTakenFieldLabels(values.fields);
@@ -2396,10 +2418,26 @@ var __publicField = (obj, key, value) => {
2396
2418
  child.identifier
2397
2419
  )),
2398
2420
  droppableProvided.placeholder,
2399
- /* @__PURE__ */ jsxRuntime.jsx(FieldBuilder, { ...insertFieldAtEndOfSection, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", children: [
2400
- /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2401
- " Add a field"
2402
- ] }) })
2421
+ /* @__PURE__ */ jsxRuntime.jsxs(
2422
+ blocks.Button,
2423
+ {
2424
+ type: "button",
2425
+ variant: "outline",
2426
+ onClick: () => setIsAddFieldDialogOpen(true),
2427
+ children: [
2428
+ /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2429
+ " Add a field"
2430
+ ]
2431
+ }
2432
+ ),
2433
+ /* @__PURE__ */ jsxRuntime.jsx(
2434
+ FieldBuilder,
2435
+ {
2436
+ ...insertFieldAtEndOfSection,
2437
+ isOpen: isAddFieldDialogOpen,
2438
+ setIsOpen: setIsAddFieldDialogOpen
2439
+ }
2440
+ )
2403
2441
  ]
2404
2442
  }
2405
2443
  ) })
@@ -2482,6 +2520,7 @@ var __publicField = (obj, key, value) => {
2482
2520
  const FieldsEditor = React.memo(function FieldsEditor2() {
2483
2521
  const { values, setFieldValue } = formik.useFormikContext();
2484
2522
  const [dropState, dispatch] = React.useReducer(reducer, values.fields, initializer);
2523
+ const [isAddSectionDialogOpen, setIsAddSectionDialogOpen] = React.useState(false);
2485
2524
  const { showInfo } = blocks.useToast();
2486
2525
  React.useEffect(() => {
2487
2526
  dispatch({ type: "update", state: initializer(values.fields) });
@@ -2569,10 +2608,18 @@ var __publicField = (obj, key, value) => {
2569
2608
  field.label
2570
2609
  )),
2571
2610
  droppableProvided.placeholder,
2572
- /* @__PURE__ */ jsxRuntime.jsx(FieldBuilder, { ...makeFieldSectionProps, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", children: [
2611
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", onClick: () => setIsAddSectionDialogOpen(true), children: [
2573
2612
  /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2574
2613
  " Add a section"
2575
- ] }) })
2614
+ ] }),
2615
+ /* @__PURE__ */ jsxRuntime.jsx(
2616
+ FieldBuilder,
2617
+ {
2618
+ ...makeFieldSectionProps,
2619
+ isOpen: isAddSectionDialogOpen,
2620
+ setIsOpen: setIsAddSectionDialogOpen
2621
+ }
2622
+ )
2576
2623
  ]
2577
2624
  }
2578
2625
  ) }) });