@overmap-ai/forms 1.0.9 → 1.0.10-conditional-arrows-2.1

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.
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("@overmap-ai/blocks"), require("formik"), require("react"), require("@hello-pangea/dnd"), require("@overmap-ai/core"), require("lodash.get"), require("lodash.set"), require("lodash.clonedeep")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "@overmap-ai/blocks", "formik", "react", "@hello-pangea/dnd", "@overmap-ai/core", "lodash.get", "lodash.set", "lodash.clonedeep"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.forms = {}, global.jsxRuntime, global.blocks, global.formik, global.React, global.dnd, global.core, global.get, global.set, global.cloneDeep));
3
- })(this, function(exports2, jsxRuntime, blocks, formik, React, dnd, core, get, set, cloneDeep) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("@overmap-ai/blocks"), require("formik"), require("react"), require("@hello-pangea/dnd"), require("@overmap-ai/core"), require("lodash.get"), require("lodash.set"), require("lodash.clonedeep"), require("react-xarrows")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "@overmap-ai/blocks", "formik", "react", "@hello-pangea/dnd", "@overmap-ai/core", "lodash.get", "lodash.set", "lodash.clonedeep", "react-xarrows"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.forms = {}, global.jsxRuntime, global.blocks, global.formik, global.React, global.dnd, global.core, global.get, global.set, global.cloneDeep, global.Xarrow));
3
+ })(this, function(exports2, jsxRuntime, blocks, formik, React, dnd, core, get, set, cloneDeep, Xarrow) {
4
4
  "use strict";var __defProp = Object.defineProperty;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
6
  var __publicField = (obj, key, value) => {
@@ -98,9 +98,11 @@ var __publicField = (obj, key, value) => {
98
98
  }
99
99
  __publicField(BaseField, "fieldTypeName");
100
100
  __publicField(BaseField, "fieldTypeDescription");
101
- const description$1 = "_description_17zed_1";
101
+ const description$1 = "_description_1se5r_1";
102
+ const sectionContainer = "_sectionContainer_1se5r_5";
102
103
  const styles$3 = {
103
- description: description$1
104
+ description: description$1,
105
+ sectionContainer
104
106
  };
105
107
  const InputWithLabel = (props) => {
106
108
  const { label, children, severity, inputId, labelId, flexProps } = props;
@@ -2062,12 +2064,8 @@ var __publicField = (obj, key, value) => {
2062
2064
  return /* @__PURE__ */ jsxRuntime.jsx(blocks.Dialog, { onCloseInterrupt: handleCloseInterrupt, title: title2, description: description2, content: dialogContent, children });
2063
2065
  });
2064
2066
  const DefaultWrapper = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2065
- const forMobile = (mobile, display) => ({
2066
- initial: mobile ? display : "none",
2067
- sm: mobile ? "none" : display
2068
- });
2069
2067
  const FieldActions = React.memo(function FieldActions2(props) {
2070
- const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
2068
+ const { remove: remove2, editProps, insertAfterProps, duplicateProps, type } = props;
2071
2069
  const actions = React.useMemo(
2072
2070
  () => [
2073
2071
  {
@@ -2093,53 +2091,39 @@ var __publicField = (obj, key, value) => {
2093
2091
  Wrapper: FieldBuilder,
2094
2092
  wrapperProps: insertAfterProps,
2095
2093
  Icon: blocks.PlusIcon,
2096
- text: "Add after"
2097
- },
2098
- {
2099
- // Wrapping icon in a div so that the asChild turns the button into a div
2100
- // so that the drag handle props are not applied to the icon
2101
- // Note: b/c the <button> does not handle the space-press event correctly
2102
- Icon: (props2) => /* @__PURE__ */ jsxRuntime.jsx("div", { ...props2, children: /* @__PURE__ */ jsxRuntime.jsx(blocks.DragHandleDots2Icon, {}) }),
2103
- text: "Reorder",
2104
- disableOnMobile: true,
2105
- buttonProps: { ...dragHandleProps, asChild: true }
2094
+ text: `Add ${type === "section" ? "section" : "field"}`
2106
2095
  }
2107
2096
  ],
2108
- [dragHandleProps, duplicateProps, editProps, insertAfterProps, remove2]
2097
+ [duplicateProps, editProps, insertAfterProps, remove2, type]
2109
2098
  );
2110
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2111
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { gap: "4", display: forMobile(false, "flex"), children: actions.map((Action) => {
2112
- const Wrapper = Action.Wrapper ?? DefaultWrapper;
2113
- 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);
2114
- }) }),
2115
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsxRuntime.jsx(
2116
- blocks.DropdownMenu,
2117
- {
2118
- trigger: /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ jsxRuntime.jsx(blocks.DotsVerticalIcon, {}) }),
2119
- closeOnSelect: false,
2120
- items: actions.map((Action) => {
2121
- var _a;
2122
- if (Action.disableOnMobile)
2123
- return null;
2124
- const Wrapper = Action.Wrapper ?? DefaultWrapper;
2125
- return {
2126
- ...Action.buttonProps,
2127
- onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
2128
- content: /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...Action.wrapperProps, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2129
- /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2130
- Action.text
2131
- ] }) })
2132
- };
2133
- }).filter((x) => x !== null)
2134
- }
2135
- ) })
2136
- ] });
2099
+ const actionItems = actions.map((Action) => {
2100
+ var _a;
2101
+ const Wrapper = Action.Wrapper ?? DefaultWrapper;
2102
+ return {
2103
+ ...Action.buttonProps,
2104
+ onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
2105
+ content: /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...Action.wrapperProps, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2106
+ /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2107
+ Action.text
2108
+ ] }) })
2109
+ };
2110
+ });
2111
+ console.log(actionItems);
2112
+ return /* @__PURE__ */ jsxRuntime.jsx(blocks.Box, { display: "block", children: /* @__PURE__ */ jsxRuntime.jsx(
2113
+ blocks.DropdownMenu,
2114
+ {
2115
+ trigger: /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ jsxRuntime.jsx(blocks.DotsVerticalIcon, {}) }),
2116
+ closeOnSelect: false,
2117
+ items: actionItems
2118
+ }
2119
+ ) });
2137
2120
  });
2138
2121
  const formId = "form-builder";
2139
2122
  const FieldWithActions = React.memo(function FieldWithActions2(props) {
2140
2123
  const { field, index, sectionIndex, takenLabels, remove: remove2 } = props;
2141
2124
  const deserializedField = React.useMemo(() => deserialize(field), [field]);
2142
2125
  const input = useFieldInput(deserializedField, { formId, disabled: true });
2126
+ const updateXarrow = Xarrow.useXarrow();
2143
2127
  const duplicateField = React.useCallback(
2144
2128
  (field2) => {
2145
2129
  if (field2.label === null) {
@@ -2180,6 +2164,8 @@ var __publicField = (obj, key, value) => {
2180
2164
  ref: draggableProvided.innerRef,
2181
2165
  ...draggableProvided.draggableProps,
2182
2166
  ...draggableProvided.dragHandleProps,
2167
+ onDragStart: updateXarrow,
2168
+ id: `${field.identifier}-card`,
2183
2169
  mb: "4",
2184
2170
  children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "4", justify: "between", align: "center", children: [
2185
2171
  input,
@@ -2189,20 +2175,91 @@ var __publicField = (obj, key, value) => {
2189
2175
  remove: remove2,
2190
2176
  editProps: editFieldProps,
2191
2177
  duplicateProps: duplicateFieldProps,
2192
- insertAfterProps,
2193
- dragHandleProps: draggableProvided.dragHandleProps
2178
+ insertAfterProps
2194
2179
  }
2195
2180
  )
2196
2181
  ] })
2197
2182
  }
2198
2183
  ) });
2199
2184
  });
2185
+ const ArrowSpacingDiv = React.memo(function ArrowSpacingDiv2(props) {
2186
+ const { identifier, index, conditionalFieldCounts } = props;
2187
+ const HORIZONTAL_SPACE = 3;
2188
+ const totalConditionals = conditionalFieldCounts.filter((count) => count !== null).length;
2189
+ const conditionalNum = conditionalFieldCounts[index] ?? 0;
2190
+ const marginLeft = HORIZONTAL_SPACE / totalConditionals * conditionalNum;
2191
+ return /* @__PURE__ */ jsxRuntime.jsx(
2192
+ "div",
2193
+ {
2194
+ id: `${identifier}-floating-point`,
2195
+ style: {
2196
+ width: `${HORIZONTAL_SPACE - marginLeft}%`,
2197
+ marginLeft: `${marginLeft}%`
2198
+ }
2199
+ }
2200
+ );
2201
+ });
2202
+ const ConditionalArrow = (props) => {
2203
+ const { identifier, condition } = props;
2204
+ const primaryColor = "var(--gray-a4)";
2205
+ const hoverColor = "var(--primary-color)";
2206
+ const [color, setColor] = React.useState(primaryColor);
2207
+ const [zIndex, setZIndex] = React.useState(0);
2208
+ const handleMouseEnter = React.useCallback(() => {
2209
+ setColor(hoverColor);
2210
+ setZIndex(1);
2211
+ }, [hoverColor]);
2212
+ const handleMouseLeave = React.useCallback(() => {
2213
+ setColor(primaryColor);
2214
+ setZIndex(0);
2215
+ }, [primaryColor]);
2216
+ const settings = React.useMemo(() => {
2217
+ return {
2218
+ strokeWidth: 1,
2219
+ showHead: false,
2220
+ color,
2221
+ zIndex,
2222
+ arrowBodyProps: {
2223
+ onMouseEnter: handleMouseEnter,
2224
+ onMouseLeave: handleMouseLeave
2225
+ }
2226
+ };
2227
+ }, [color, handleMouseEnter, handleMouseLeave, zIndex]);
2228
+ if (!condition)
2229
+ return null;
2230
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2231
+ /* @__PURE__ */ jsxRuntime.jsx(
2232
+ Xarrow,
2233
+ {
2234
+ start: `${identifier}-card`,
2235
+ end: `${identifier}-floating-point`,
2236
+ startAnchor: "right",
2237
+ endAnchor: "left",
2238
+ path: "straight",
2239
+ ...settings
2240
+ }
2241
+ ),
2242
+ /* @__PURE__ */ jsxRuntime.jsx(
2243
+ Xarrow,
2244
+ {
2245
+ start: `${identifier}-floating-point`,
2246
+ end: `${condition.identifier}-card`,
2247
+ startAnchor: "left",
2248
+ endAnchor: "right",
2249
+ path: "grid",
2250
+ gridBreak: "0",
2251
+ ...settings
2252
+ }
2253
+ )
2254
+ ] });
2255
+ };
2200
2256
  const FieldSectionWithActions = React.memo(function FieldSectionWithActions2(props) {
2201
2257
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2202
- const { field, index: sectionIndex, dropState } = props;
2258
+ const { field, index: sectionIndex, dropState, conditionalFieldCounts } = props;
2203
2259
  const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
2204
2260
  const { setFieldValue, values } = formik.useFormikContext();
2205
2261
  const alertDialog = blocks.useAlertDialog();
2262
+ const updateXarrow = Xarrow.useXarrow();
2206
2263
  const takenFieldLabels = getTakenFieldLabels(values.fields);
2207
2264
  const removeSectionConditions = React.useCallback(
2208
2265
  (sectionsToUpdate, allSections) => {
@@ -2353,64 +2410,95 @@ var __publicField = (obj, key, value) => {
2353
2410
  throw new Error("File values are not supported for conditions.");
2354
2411
  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();
2355
2412
  return /* @__PURE__ */ jsxRuntime.jsx(dnd.Draggable, { draggableId: field.identifier, index: sectionIndex, children: (draggableProvided) => /* @__PURE__ */ jsxRuntime.jsx(
2356
- blocks.Card,
2413
+ blocks.Flex,
2357
2414
  {
2415
+ className: styles$3.sectionContainer,
2358
2416
  ref: draggableProvided.innerRef,
2359
2417
  ...draggableProvided.draggableProps,
2360
- ...draggableProvided.dragHandleProps,
2418
+ direction: "row",
2419
+ justify: "center",
2420
+ align: "center",
2361
2421
  mb: "4",
2362
- children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "3", justify: "between", align: "center", children: [
2363
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", grow: "1", children: [
2364
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", children: [
2365
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Heading, { as: "h3", size: "3", children: field.label }),
2366
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { className: styles$3.description, children: field.description })
2367
- ] }),
2368
- field.condition && /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Em, { children: [
2369
- "Display only if ",
2370
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Strong, { children: conditionLabel }),
2371
- " ",
2372
- conditionComparison,
2373
- " ",
2374
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Strong, { children: conditionValue })
2375
- ] }) }),
2376
- /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId: field.identifier, type: "SECTION", isDropDisabled, children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(
2377
- blocks.Flex,
2378
- {
2379
- ref: droppableProvided.innerRef,
2380
- ...droppableProvided.droppableProps,
2381
- direction: "column",
2382
- gap: "0",
2383
- children: [
2384
- field.fields.map((child, i) => /* @__PURE__ */ jsxRuntime.jsx(
2385
- FieldWithActions,
2386
- {
2387
- field: child,
2388
- index: i,
2389
- sectionIndex,
2390
- remove: () => removeField(i),
2391
- takenLabels: takenFieldLabels
2392
- },
2393
- child.identifier
2394
- )),
2395
- droppableProvided.placeholder,
2396
- /* @__PURE__ */ jsxRuntime.jsx(FieldBuilder, { ...insertFieldAtEndOfSection, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", children: [
2397
- /* @__PURE__ */ jsxRuntime.jsx(blocks.PlusIcon, {}),
2398
- " Add a field"
2399
- ] }) })
2400
- ]
2401
- }
2402
- ) })
2403
- ] }),
2422
+ children: /* @__PURE__ */ jsxRuntime.jsxs(Xarrow.Xwrapper, { children: [
2404
2423
  /* @__PURE__ */ jsxRuntime.jsx(
2405
- FieldActions,
2424
+ blocks.Card,
2406
2425
  {
2407
- remove: removeSection,
2408
- insertAfterProps: insertSectionProps,
2409
- dragHandleProps: draggableProvided.dragHandleProps,
2410
- editProps: editSectionProps,
2411
- duplicateProps: duplicateSectionProps
2426
+ ...draggableProvided.dragHandleProps,
2427
+ onDragStart: updateXarrow,
2428
+ id: `${field.identifier}-card`,
2429
+ style: { flexGrow: "1" },
2430
+ children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "3", justify: "between", align: "center", children: [
2431
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", grow: "1", children: [
2432
+ /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", children: [
2433
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.Heading, { as: "h3", size: "3", children: field.label }),
2434
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { className: styles$3.description, children: field.description })
2435
+ ] }),
2436
+ field.condition && /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Em, { children: [
2437
+ "Display only if ",
2438
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.Strong, { children: conditionLabel }),
2439
+ " ",
2440
+ conditionComparison,
2441
+ " ",
2442
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.Strong, { children: conditionValue })
2443
+ ] }) }),
2444
+ /* @__PURE__ */ jsxRuntime.jsx(
2445
+ dnd.Droppable,
2446
+ {
2447
+ droppableId: field.identifier,
2448
+ type: "SECTION",
2449
+ isDropDisabled,
2450
+ children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(
2451
+ blocks.Flex,
2452
+ {
2453
+ ref: droppableProvided.innerRef,
2454
+ ...droppableProvided.droppableProps,
2455
+ direction: "column",
2456
+ gap: "0",
2457
+ children: [
2458
+ field.fields.map((child, i) => /* @__PURE__ */ jsxRuntime.jsx(
2459
+ FieldWithActions,
2460
+ {
2461
+ field: child,
2462
+ index: i,
2463
+ sectionIndex,
2464
+ remove: () => removeField(i),
2465
+ takenLabels: takenFieldLabels
2466
+ },
2467
+ child.identifier
2468
+ )),
2469
+ droppableProvided.placeholder,
2470
+ /* @__PURE__ */ jsxRuntime.jsx(FieldBuilder, { ...insertFieldAtEndOfSection, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", children: [
2471
+ /* @__PURE__ */ jsxRuntime.jsx(blocks.PlusIcon, {}),
2472
+ " Add a field"
2473
+ ] }) })
2474
+ ]
2475
+ }
2476
+ )
2477
+ }
2478
+ )
2479
+ ] }),
2480
+ /* @__PURE__ */ jsxRuntime.jsx(
2481
+ FieldActions,
2482
+ {
2483
+ remove: removeSection,
2484
+ insertAfterProps: insertSectionProps,
2485
+ editProps: editSectionProps,
2486
+ duplicateProps: duplicateSectionProps,
2487
+ type: "section"
2488
+ }
2489
+ )
2490
+ ] })
2412
2491
  }
2413
- )
2492
+ ),
2493
+ conditionalFieldCounts.some((count) => count !== null) && /* @__PURE__ */ jsxRuntime.jsx(
2494
+ ArrowSpacingDiv,
2495
+ {
2496
+ identifier: field.identifier,
2497
+ index: sectionIndex,
2498
+ conditionalFieldCounts
2499
+ }
2500
+ ),
2501
+ field.condition && /* @__PURE__ */ jsxRuntime.jsx(ConditionalArrow, { identifier: field.identifier, condition: field.condition })
2414
2502
  ] })
2415
2503
  }
2416
2504
  ) });
@@ -2548,6 +2636,12 @@ var __publicField = (obj, key, value) => {
2548
2636
  }),
2549
2637
  [values.fields]
2550
2638
  );
2639
+ const conditionalFieldCounts = () => {
2640
+ let conditionalCount = 1;
2641
+ return values.fields.map((field) => {
2642
+ return field.conditional ? conditionalCount++ : null;
2643
+ });
2644
+ };
2551
2645
  return /* @__PURE__ */ jsxRuntime.jsx(dnd.DragDropContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId: "droppable", type: "ROOT", children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(
2552
2646
  blocks.Flex,
2553
2647
  {
@@ -2561,7 +2655,8 @@ var __publicField = (obj, key, value) => {
2561
2655
  {
2562
2656
  field,
2563
2657
  index,
2564
- dropState
2658
+ dropState,
2659
+ conditionalFieldCounts: conditionalFieldCounts()
2565
2660
  },
2566
2661
  field.label
2567
2662
  )),