@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.
@@ -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) => {
@@ -2042,13 +2042,15 @@ var __publicField = (obj, key, value) => {
2042
2042
  newFields = insert(parent, index, field);
2043
2043
  }
2044
2044
  setFieldValue(parentPath, newFields).then();
2045
- closeDialog({ force: true });
2045
+ setIsOpen(false);
2046
+ console.log(closeDialog);
2046
2047
  },
2047
- [editing, type, values, parentPath, setFieldValue, index]
2048
+ [type, values, parentPath, editing, setFieldValue, setIsOpen, index]
2048
2049
  );
2049
2050
  const handleDirtyChange = React.useCallback((dirty) => setFormIsDirty(dirty), []);
2050
2051
  const dialogContent = React.useCallback(
2051
2052
  (closeDialog) => {
2053
+ console.log(showChooseField, type, editing, initial);
2052
2054
  if (showChooseField) {
2053
2055
  return /* @__PURE__ */ jsxRuntime.jsx(ChooseFieldToAdd, { setFieldType });
2054
2056
  }
@@ -2066,22 +2068,32 @@ var __publicField = (obj, key, value) => {
2066
2068
  },
2067
2069
  [conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]
2068
2070
  );
2069
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Dialog, { onCloseInterrupt: handleCloseInterrupt, title: title2, description: description2, content: dialogContent, children });
2071
+ return /* @__PURE__ */ jsxRuntime.jsx(
2072
+ blocks.Dialog,
2073
+ {
2074
+ title: title2,
2075
+ description: description2,
2076
+ content: dialogContent,
2077
+ open: isOpen,
2078
+ onOpenChange: handleCloseDialog
2079
+ }
2080
+ );
2070
2081
  });
2071
- const DefaultWrapper = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2072
2082
  const forMobile = (mobile, display) => ({
2073
2083
  initial: mobile ? display : "none",
2074
2084
  sm: mobile ? "none" : display
2075
2085
  });
2076
2086
  const FieldActions = React.memo(function FieldActions2(props) {
2077
2087
  const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
2088
+ const [isDialogOpen, setIsDialogOpen] = React.useState(false);
2078
2089
  const actions = React.useMemo(
2079
2090
  () => [
2080
2091
  {
2081
- Wrapper: FieldBuilder,
2082
- wrapperProps: editProps,
2092
+ SelectedContent: FieldBuilder,
2093
+ selectedContentProps: { ...editProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2083
2094
  Icon: reactIcons.Pencil1Icon,
2084
- text: "Edit"
2095
+ text: "Edit",
2096
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2085
2097
  },
2086
2098
  {
2087
2099
  Icon: reactIcons.TrashIcon,
@@ -2091,16 +2103,18 @@ var __publicField = (obj, key, value) => {
2091
2103
  text: "Delete"
2092
2104
  },
2093
2105
  {
2094
- Wrapper: FieldBuilder,
2095
- wrapperProps: duplicateProps,
2106
+ SelectedContent: FieldBuilder,
2107
+ selectedContentProps: { ...duplicateProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2096
2108
  Icon: reactIcons.CopyIcon,
2097
- text: "Duplicate"
2109
+ text: "Duplicate",
2110
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2098
2111
  },
2099
2112
  {
2100
- Wrapper: FieldBuilder,
2101
- wrapperProps: insertAfterProps,
2113
+ SelectedContent: FieldBuilder,
2114
+ selectedContentProps: { ...insertAfterProps, isOpen: isDialogOpen, setIsOpen: setIsDialogOpen },
2102
2115
  Icon: reactIcons.PlusIcon,
2103
- text: "Add after"
2116
+ text: "Add after",
2117
+ buttonProps: { onClick: () => setIsDialogOpen(true) }
2104
2118
  },
2105
2119
  {
2106
2120
  // Wrapping icon in a div so that the asChild turns the button into a div
@@ -2112,12 +2126,14 @@ var __publicField = (obj, key, value) => {
2112
2126
  buttonProps: { ...dragHandleProps, asChild: true }
2113
2127
  }
2114
2128
  ],
2115
- [dragHandleProps, duplicateProps, editProps, insertAfterProps, remove2]
2129
+ [dragHandleProps, duplicateProps, editProps, insertAfterProps, isDialogOpen, remove2]
2116
2130
  );
2117
2131
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2118
2132
  /* @__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);
2133
+ return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2134
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}) }),
2135
+ Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(Action.SelectedContent, { ...Action.selectedContentProps })
2136
+ ] }, Action.text);
2121
2137
  }) }),
2122
2138
  /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsxRuntime.jsx(
2123
2139
  blocks.DropdownItemMenu,
@@ -2128,14 +2144,16 @@ var __publicField = (obj, key, value) => {
2128
2144
  var _a;
2129
2145
  if (Action.disableOnMobile)
2130
2146
  return null;
2131
- const Wrapper = Action.Wrapper ?? DefaultWrapper;
2132
2147
  return {
2133
2148
  ...Action.buttonProps,
2134
2149
  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
- ] }) })
2150
+ content: /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2151
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2152
+ /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2153
+ Action.text
2154
+ ] }),
2155
+ Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(Action.SelectedContent, { ...Action.selectedContentProps })
2156
+ ] }, Action.text)
2139
2157
  };
2140
2158
  }).filter((x) => x !== null)
2141
2159
  }
@@ -2206,6 +2224,7 @@ var __publicField = (obj, key, value) => {
2206
2224
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2207
2225
  const { field, index: sectionIndex, dropState } = props;
2208
2226
  const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
2227
+ const [isAddFieldDialogOpen, setIsAddFieldDialogOpen] = React.useState(false);
2209
2228
  const { setFieldValue, values } = formik.useFormikContext();
2210
2229
  const alertDialog = blocks.useAlertDialog();
2211
2230
  const takenFieldLabels = getTakenFieldLabels(values.fields);
@@ -2396,10 +2415,26 @@ var __publicField = (obj, key, value) => {
2396
2415
  child.identifier
2397
2416
  )),
2398
2417
  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
- ] }) })
2418
+ /* @__PURE__ */ jsxRuntime.jsxs(
2419
+ blocks.Button,
2420
+ {
2421
+ type: "button",
2422
+ variant: "outline",
2423
+ onClick: () => setIsAddFieldDialogOpen(true),
2424
+ children: [
2425
+ /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2426
+ " Add a field"
2427
+ ]
2428
+ }
2429
+ ),
2430
+ /* @__PURE__ */ jsxRuntime.jsx(
2431
+ FieldBuilder,
2432
+ {
2433
+ ...insertFieldAtEndOfSection,
2434
+ isOpen: isAddFieldDialogOpen,
2435
+ setIsOpen: setIsAddFieldDialogOpen
2436
+ }
2437
+ )
2403
2438
  ]
2404
2439
  }
2405
2440
  ) })
@@ -2482,6 +2517,7 @@ var __publicField = (obj, key, value) => {
2482
2517
  const FieldsEditor = React.memo(function FieldsEditor2() {
2483
2518
  const { values, setFieldValue } = formik.useFormikContext();
2484
2519
  const [dropState, dispatch] = React.useReducer(reducer, values.fields, initializer);
2520
+ const [isAddSectionDialogOpen, setIsAddSectionDialogOpen] = React.useState(false);
2485
2521
  const { showInfo } = blocks.useToast();
2486
2522
  React.useEffect(() => {
2487
2523
  dispatch({ type: "update", state: initializer(values.fields) });
@@ -2569,10 +2605,18 @@ var __publicField = (obj, key, value) => {
2569
2605
  field.label
2570
2606
  )),
2571
2607
  droppableProvided.placeholder,
2572
- /* @__PURE__ */ jsxRuntime.jsx(FieldBuilder, { ...makeFieldSectionProps, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", children: [
2608
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", onClick: () => setIsAddSectionDialogOpen(true), children: [
2573
2609
  /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2574
2610
  " Add a section"
2575
- ] }) })
2611
+ ] }),
2612
+ /* @__PURE__ */ jsxRuntime.jsx(
2613
+ FieldBuilder,
2614
+ {
2615
+ ...makeFieldSectionProps,
2616
+ isOpen: isAddSectionDialogOpen,
2617
+ setIsOpen: setIsAddSectionDialogOpen
2618
+ }
2619
+ )
2576
2620
  ]
2577
2621
  }
2578
2622
  ) }) });