@overmap-ai/forms 1.0.32-react-flow-david-fixes.27 → 1.0.32-react-flow-david-fixes.30

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,2 +1,2 @@
1
1
  export * from './FlowBuilder';
2
- export { getLayoutedElements } from './layout';
2
+ export { getLayoutedNodesAndEdges } from './layout';
@@ -1,2 +1,2 @@
1
1
  import { FieldSectionConditionEdge, FieldSectionNode, LayoutDirection } from './typings';
2
- export declare const getLayoutedElements: (nodes: FieldSectionNode[], edges: FieldSectionConditionEdge[], direction: LayoutDirection) => [FieldSectionNode[], FieldSectionConditionEdge[]];
2
+ export declare const getLayoutedNodesAndEdges: (nodes: FieldSectionNode[], edges: FieldSectionConditionEdge[], direction: LayoutDirection) => [FieldSectionNode[], FieldSectionConditionEdge[]];
@@ -10,5 +10,6 @@ export type FieldSectionNode = Node<FieldSectionNodeData, "fieldSection">;
10
10
  export type FieldSectionConditionEdgeData = {
11
11
  targetSection: FieldSection;
12
12
  sourceSection: FieldSection;
13
+ layoutDirection: LayoutDirection;
13
14
  };
14
15
  export type FieldSectionConditionEdge = Edge<FieldSectionConditionEdgeData, "fieldSectionCondition">;
@@ -10,7 +10,7 @@ export interface FieldSectionOptions extends FormElementOptions {
10
10
  conditions?: FieldSectionConditions;
11
11
  fields: Field[];
12
12
  }
13
- export declare class FieldSection extends BaseFormElement<"section", FieldSection> implements ConditionManager<Condition>, FieldsManager<Field> {
13
+ export declare class FieldSection extends BaseFormElement<"section", FieldSection> implements ConditionManager<Condition>, FieldsManager {
14
14
  static readonly fieldTypeName = "Section";
15
15
  static readonly fieldTypeDescription = "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.";
16
16
  readonly type = "section";
@@ -26,12 +26,22 @@ export type Field = BooleanField | CheckboxListField | DateField | MultiSelectFi
26
26
  export type FieldClass = typeof BooleanField | typeof CheckboxListField | typeof DateField | typeof MultiSelectField | typeof MultiStringField | typeof NumberField | typeof RadioField | typeof ScanField | typeof SelectField | typeof StringField | typeof TextField | typeof UploadField | typeof OTPField;
27
27
  export type SerializedField = SerializedTextField | SerializedBooleanField | SerializedNumberField | SerializedDateField | SerializedStringField | SerializedSelectField | SerializedFieldSection | SerializedMultiStringField | SerializedMultiSelectField | SerializedUploadField | SerializedScanField | SerializedRadioField | SerializedCheckboxListField | SerializedOTPField;
28
28
  export type SerializedOnlyField = Exclude<SerializedField, SerializedFieldSection>;
29
- export interface FieldsManager<TField extends AnyFormElement> {
30
- readonly fields: TField[];
31
- getFields(): TField[];
32
- addField(field: TField): void;
33
- addFields(fields: TField[]): void;
29
+ export interface FieldsManager {
30
+ readonly fields: Field[];
31
+ getFields(): Field[];
32
+ addField(field: Field): void;
33
+ addFields(fields: Field[]): void;
34
34
  moveField(sourceIndex: number, targetIndex: number): void;
35
- removeField(field: TField): void;
36
- removeFields(fields: TField[]): void;
35
+ removeField(field: Field): void;
36
+ removeFields(fields: Field[]): void;
37
+ }
38
+ export interface FieldSectionManager {
39
+ readonly fieldSections: FieldSection[];
40
+ getFields(): Field[];
41
+ getFieldSections(): FieldSection[];
42
+ addFieldSection(field: FieldSection): void;
43
+ addFieldSections(fields: FieldSection[]): void;
44
+ moveFieldSection(sourceIndex: number, targetIndex: number): void;
45
+ removeFieldSection(field: FieldSection): void;
46
+ removeFieldSections(fields: FieldSection[]): void;
37
47
  }
@@ -1,19 +1,20 @@
1
- import { FieldSection, FieldsManager, SerializedFieldSection } from '../fields';
1
+ import { Field, FieldSection, FieldSectionManager, SerializedFieldSection } from '../fields';
2
2
  import { Observable } from '../observable/Observable';
3
3
  import { FieldValues, SerializedFieldValues } from '../typings';
4
- export declare class FieldSchema extends Observable<FieldSchema> implements FieldsManager<FieldSection> {
5
- fields: FieldSection[];
4
+ export declare class FieldSchema extends Observable<FieldSchema> implements FieldSectionManager {
5
+ fieldSections: FieldSection[];
6
6
  constructor(fields: FieldSection[]);
7
7
  serialize(): SerializedFieldSection[];
8
8
  static deserialize(serializedSections: SerializedFieldSection[]): FieldSchema;
9
9
  private fieldObserver;
10
10
  private initFields;
11
- addField(field: FieldSection): void;
12
- addFields(fields: FieldSection[]): void;
13
- getFields(): FieldSection[];
14
- removeField(field: FieldSection): void;
15
- removeFields(fields: FieldSection[]): void;
16
- moveField(sourceIndex: number, targetIndex: number): void;
11
+ getFields(): Field[];
12
+ getFieldSections(): FieldSection[];
13
+ addFieldSection(field: FieldSection): void;
14
+ addFieldSections(fields: FieldSection[]): void;
15
+ removeFieldSection(field: FieldSection): void;
16
+ removeFieldSections(fields: FieldSection[]): void;
17
+ moveFieldSection(sourceIndex: number, targetIndex: number): void;
17
18
  deserializeValues(values: SerializedFieldValues): FieldValues;
18
19
  serializeValues(values: FieldValues): SerializedFieldValues;
19
20
  }
package/dist/forms.js CHANGED
@@ -7,7 +7,7 @@ import { cx } from "class-variance-authority";
7
7
  import * as React from "react";
8
8
  import { memo, forwardRef, createContext, useContext, useState, useRef, useCallback, useMemo, useEffect, Fragment as Fragment$1, use, useLayoutEffect, useId as useId$1 } from "react";
9
9
  import "@xyflow/react/dist/style.css";
10
- import { getBezierPath, BaseEdge, EdgeLabelRenderer, NodeToolbar, Position, Handle, MarkerType, useNodesState, useEdgesState, ReactFlow, Panel } from "@xyflow/react";
10
+ import { getBezierPath, Position, BaseEdge, EdgeLabelRenderer, NodeToolbar, Handle, MarkerType, useNodesState, useEdgesState, ReactFlow, Panel } from "@xyflow/react";
11
11
  import { useField, useFormikContext, useFormik, FormikProvider } from "formik";
12
12
  import { DirectedGraph } from "graphology";
13
13
  import { willCreateCycle } from "graphology-dag";
@@ -34938,7 +34938,7 @@ let FieldSection = _FieldSection;
34938
34938
  class FieldSchema extends Observable {
34939
34939
  constructor(fields) {
34940
34940
  super();
34941
- __publicField(this, "fields");
34941
+ __publicField(this, "fieldSections");
34942
34942
  // Fields
34943
34943
  __publicField(this, "fieldObserver", () => {
34944
34944
  this.notify(this);
@@ -34947,50 +34947,53 @@ class FieldSchema extends Observable {
34947
34947
  for (const field of fields) field.observe(this.fieldObserver);
34948
34948
  return fields;
34949
34949
  });
34950
- this.fields = this.initFields(fields);
34950
+ this.fieldSections = this.initFields(fields);
34951
34951
  }
34952
34952
  serialize() {
34953
- return this.fields.map((field) => field.serialize());
34953
+ return this.fieldSections.map((field) => field.serialize());
34954
34954
  }
34955
34955
  static deserialize(serializedSections) {
34956
34956
  return new FieldSchema(serializedSections.map(FieldSection.deserialize));
34957
34957
  }
34958
- addField(field) {
34959
- this.fields = this.initFields([...this.fields, field]);
34960
- this.notify(this);
34958
+ getFields() {
34959
+ return this.fieldSections.flatMap((fieldSection) => fieldSection.getFields());
34961
34960
  }
34962
- addFields(fields) {
34963
- this.fields = this.initFields([...this.fields, ...fields]);
34961
+ getFieldSections() {
34962
+ return this.fieldSections;
34963
+ }
34964
+ addFieldSection(field) {
34965
+ this.fieldSections = this.initFields([...this.fieldSections, field]);
34964
34966
  this.notify(this);
34965
34967
  }
34966
- getFields() {
34967
- return this.fields;
34968
+ addFieldSections(fields) {
34969
+ this.fieldSections = this.initFields([...this.fieldSections, ...fields]);
34970
+ this.notify(this);
34968
34971
  }
34969
- removeField(field) {
34970
- const newFields = this.fields.filter((f) => f.identifier !== field.identifier);
34972
+ removeFieldSection(field) {
34973
+ const newFields = this.fieldSections.filter((f) => f.identifier !== field.identifier);
34971
34974
  for (const field2 of newFields) {
34972
34975
  field2.removeConditional(field2.identifier);
34973
34976
  }
34974
- this.fields = this.initFields(newFields);
34977
+ this.fieldSections = this.initFields(newFields);
34975
34978
  this.notify(this);
34976
34979
  }
34977
- removeFields(fields) {
34980
+ removeFieldSections(fields) {
34978
34981
  const fieldsIds = new Set(fields.map((f) => f.identifier));
34979
- this.fields = this.initFields(this.fields.filter((f) => !fieldsIds.has(f.identifier)));
34982
+ this.fieldSections = this.initFields(this.fieldSections.filter((f) => !fieldsIds.has(f.identifier)));
34980
34983
  this.notify(this);
34981
34984
  }
34982
- moveField(sourceIndex, targetIndex) {
34983
- const newFields = [...this.fields];
34985
+ moveFieldSection(sourceIndex, targetIndex) {
34986
+ const newFields = [...this.fieldSections];
34984
34987
  const [removedElement] = newFields.splice(sourceIndex, 1);
34985
34988
  newFields.splice(targetIndex, 0, removedElement);
34986
- this.fields = this.initFields(newFields);
34989
+ this.fieldSections = this.initFields(newFields);
34987
34990
  this.notify(this);
34988
34991
  }
34989
34992
  deserializeValues(values) {
34990
- return deserializeFieldValues(flattenFields(this.fields), values);
34993
+ return deserializeFieldValues(this.getFields(), values);
34991
34994
  }
34992
34995
  serializeValues(values) {
34993
- return serializeFieldValues(flattenFields(this.fields), values);
34996
+ return serializeFieldValues(this.getFields(), values);
34994
34997
  }
34995
34998
  }
34996
34999
  const FieldSchemaContext = createContext(new FieldSchema([]));
@@ -35437,7 +35440,7 @@ const FieldWithActions = memo((props) => {
35437
35440
  FieldWithActions.displayName = "FieldWithActions";
35438
35441
  const FieldSectionConditionEdgeComponent = memo((props) => {
35439
35442
  const { id, sourceX, sourceY, targetX, targetY, style, markerEnd, data } = props;
35440
- const { targetSection, sourceSection } = data;
35443
+ const { targetSection, sourceSection, layoutDirection } = data;
35441
35444
  const conditions = useMemo(() => {
35442
35445
  return sourceSection.getConditions(targetSection.identifier);
35443
35446
  }, [sourceSection, targetSection.identifier]);
@@ -35459,11 +35462,13 @@ const FieldSectionConditionEdgeComponent = memo((props) => {
35459
35462
  const [edgePath, labelX, labelY] = getBezierPath({
35460
35463
  sourceX,
35461
35464
  sourceY,
35465
+ sourcePosition: layoutDirection === "LR" ? Position.Right : Position.Bottom,
35462
35466
  targetX,
35463
- targetY
35467
+ targetY,
35468
+ targetPosition: layoutDirection === "LR" ? Position.Left : Position.Top
35464
35469
  });
35465
35470
  return /* @__PURE__ */ jsxs(Fragment, { children: [
35466
- /* @__PURE__ */ jsx(BaseEdge, { id, path: edgePath, style, markerEnd }),
35471
+ /* @__PURE__ */ jsx(BaseEdge, { id, path: edgePath, style, markerEnd, labelX, labelY }),
35467
35472
  /* @__PURE__ */ jsx(EdgeLabelRenderer, { children: /* @__PURE__ */ jsxs(
35468
35473
  Card,
35469
35474
  {
@@ -35512,7 +35517,7 @@ const FieldSectionConditionEdgeComponent = memo((props) => {
35512
35517
  }) }, condition.id)) })
35513
35518
  ]
35514
35519
  }
35515
- ) }, id)
35520
+ ) })
35516
35521
  ] });
35517
35522
  });
35518
35523
  FieldSectionConditionEdgeComponent.displayName = "FieldSectionConditionEdgeComponent";
@@ -35534,7 +35539,7 @@ const FieldSectionNodeComponent = memo((props) => {
35534
35539
  const { fieldSection, index: sectionIndex, layoutDirection } = data;
35535
35540
  const fieldSchema = use(FieldSchemaContext);
35536
35541
  const removeSection = useCallback(() => {
35537
- fieldSchema.removeField(fieldSection);
35542
+ fieldSchema.removeFieldSection(fieldSection);
35538
35543
  }, [fieldSchema, fieldSection]);
35539
35544
  const addField = useCallback(
35540
35545
  (type) => {
@@ -35544,11 +35549,11 @@ const FieldSectionNodeComponent = memo((props) => {
35544
35549
  );
35545
35550
  const handleAddBranch = useCallback(() => {
35546
35551
  const section = new FieldSection({ identifier: v4(), fields: [] });
35547
- fieldSchema.addField(section);
35552
+ fieldSchema.addFieldSection(section);
35548
35553
  fieldSection.addConditional(section.identifier);
35549
35554
  }, [fieldSchema, fieldSection]);
35550
35555
  const handleDuplicate = useCallback(() => {
35551
- fieldSchema.addField(fieldSection.duplicate(v4()));
35556
+ fieldSchema.addFieldSection(fieldSection.duplicate(v4()));
35552
35557
  }, [fieldSchema, fieldSection]);
35553
35558
  const fieldTypeItems = useFieldTypeItems(addField);
35554
35559
  const removeField = useCallback(
@@ -35664,10 +35669,17 @@ const nodeTypes = {
35664
35669
  const edgeTypes = {
35665
35670
  fieldSectionCondition: FieldSectionConditionEdgeComponent
35666
35671
  };
35667
- const getLayoutedElements = (nodes, edges, direction) => {
35672
+ const getLayoutedNodesAndEdges = (nodes, edges, direction) => {
35668
35673
  const g = new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({}));
35669
35674
  g.setGraph({ rankdir: direction, nodesep: 200, edgesep: 500, ranksep: 500 });
35670
- edges.forEach((edge) => g.setEdge(edge.source, edge.target));
35675
+ edges.forEach(
35676
+ (edge) => g.setEdge(edge.source, edge.target, {
35677
+ // TODO: Measure edges
35678
+ width: 500,
35679
+ height: 200,
35680
+ labelpos: "c"
35681
+ })
35682
+ );
35671
35683
  nodes.forEach(
35672
35684
  (node) => {
35673
35685
  var _a2, _b;
@@ -35705,7 +35717,7 @@ const FormBuilderFlowBuilder = memo(() => {
35705
35717
  ref.current.classList.remove("light");
35706
35718
  }, []);
35707
35719
  const initialNodes = useMemo(
35708
- () => fieldSchema.fields.map((fieldSection, index) => ({
35720
+ () => fieldSchema.fieldSections.map((fieldSection, index) => ({
35709
35721
  id: fieldSection.identifier,
35710
35722
  position: { x: 0, y: 0 },
35711
35723
  data: {
@@ -35716,15 +35728,15 @@ const FormBuilderFlowBuilder = memo(() => {
35716
35728
  draggable: true,
35717
35729
  type: "fieldSection"
35718
35730
  })),
35719
- [fieldSchema.fields, layoutDirection]
35731
+ [fieldSchema.fieldSections, layoutDirection]
35720
35732
  );
35721
35733
  const initialEdges = useMemo(() => {
35722
35734
  const es = [];
35723
35735
  const sectionsMapping = {};
35724
- for (const section of fieldSchema.fields) {
35736
+ for (const section of fieldSchema.fieldSections) {
35725
35737
  sectionsMapping[section.identifier] = section;
35726
35738
  }
35727
- for (const section of fieldSchema.fields) {
35739
+ for (const section of fieldSchema.fieldSections) {
35728
35740
  const sectionConditions = section.conditions;
35729
35741
  for (const [conditionSectionId, conditions] of Object.entries(sectionConditions)) {
35730
35742
  es.push({
@@ -35733,7 +35745,8 @@ const FormBuilderFlowBuilder = memo(() => {
35733
35745
  target: conditionSectionId,
35734
35746
  data: {
35735
35747
  targetSection: sectionsMapping[conditionSectionId],
35736
- sourceSection: section
35748
+ sourceSection: section,
35749
+ layoutDirection
35737
35750
  },
35738
35751
  animated: conditions.length > 0,
35739
35752
  markerEnd: MarkerType.Arrow,
@@ -35743,7 +35756,7 @@ const FormBuilderFlowBuilder = memo(() => {
35743
35756
  }
35744
35757
  }
35745
35758
  return es;
35746
- }, [fieldSchema.fields]);
35759
+ }, [fieldSchema.fieldSections, layoutDirection]);
35747
35760
  const [nodes, setNodes, handleNodesChange] = useNodesState(initialNodes);
35748
35761
  const [edges, setEdges, handleEdgesChange] = useEdgesState(initialEdges);
35749
35762
  useEffect(() => {
@@ -35753,15 +35766,15 @@ const FormBuilderFlowBuilder = memo(() => {
35753
35766
  setEdges(initialEdges);
35754
35767
  }, [initialEdges, setEdges]);
35755
35768
  const [layoutedNodes, layoutedEdges] = useMemo(() => {
35756
- return getLayoutedElements(nodes, edges, layoutDirection);
35769
+ return getLayoutedNodesAndEdges(nodes, edges, layoutDirection);
35757
35770
  }, [edges, layoutDirection, nodes]);
35758
35771
  const handleAddSection = useCallback(() => {
35759
- fieldSchema.addField(new FieldSection({ identifier: v4(), fields: [] }));
35772
+ fieldSchema.addFieldSection(new FieldSection({ identifier: v4(), fields: [] }));
35760
35773
  }, [fieldSchema]);
35761
35774
  const handleConnect = useCallback(
35762
35775
  (params) => {
35763
35776
  const { source: sourceId, target: targetId } = params;
35764
- const sourceSection = fieldSchema.fields.find(({ identifier }) => identifier === sourceId);
35777
+ const sourceSection = fieldSchema.fieldSections.find(({ identifier }) => identifier === sourceId);
35765
35778
  sourceSection.setOptions({
35766
35779
  conditions: {
35767
35780
  ...sourceSection.conditions,
@@ -35769,19 +35782,19 @@ const FormBuilderFlowBuilder = memo(() => {
35769
35782
  }
35770
35783
  });
35771
35784
  },
35772
- [fieldSchema.fields]
35785
+ [fieldSchema.fieldSections]
35773
35786
  );
35774
35787
  const handleValidConnection = useCallback(
35775
35788
  (edge) => {
35776
35789
  const graph = new DirectedGraph({});
35777
- for (const sourceSection of fieldSchema.fields) {
35790
+ for (const sourceSection of fieldSchema.fieldSections) {
35778
35791
  for (const targetSectionId of Object.keys(sourceSection.conditions)) {
35779
35792
  graph.mergeEdge(sourceSection.identifier, targetSectionId);
35780
35793
  }
35781
35794
  }
35782
35795
  return !willCreateCycle(graph, edge.source, edge.target);
35783
35796
  },
35784
- [fieldSchema.fields]
35797
+ [fieldSchema.fieldSections]
35785
35798
  );
35786
35799
  const [titleFieldProps, titleMeta, titleHelpers] = useField("title");
35787
35800
  const [descriptionFieldProps, _descriptionMeta, descriptionHelpers] = useField("description");
@@ -35918,8 +35931,8 @@ const FieldSectionBuilder = memo((props) => {
35918
35931
  const { fieldSection } = props;
35919
35932
  const fieldSchema = use(FieldSchemaContext);
35920
35933
  const conditionalSections = useMemo(() => {
35921
- return fieldSchema.fields.filter((section) => fieldSection.identifier in section.conditions);
35922
- }, [fieldSchema.fields, fieldSection.identifier]);
35934
+ return fieldSchema.fieldSections.filter((section) => fieldSection.identifier in section.conditions);
35935
+ }, [fieldSchema.fieldSections, fieldSection.identifier]);
35923
35936
  const handleAddConditional = useCallback(
35924
35937
  (conditionalSection) => {
35925
35938
  conditionalSection.addConditional(fieldSection.identifier);
@@ -35928,15 +35941,15 @@ const FieldSectionBuilder = memo((props) => {
35928
35941
  );
35929
35942
  const validFieldSections = useMemo(() => {
35930
35943
  const graph = new DirectedGraph({});
35931
- for (const sourceSection of fieldSchema.fields) {
35944
+ for (const sourceSection of fieldSchema.fieldSections) {
35932
35945
  for (const targetSectionId of Object.keys(sourceSection.conditions)) {
35933
35946
  graph.mergeEdge(sourceSection.identifier, targetSectionId);
35934
35947
  }
35935
35948
  }
35936
- return fieldSchema.fields.filter(
35949
+ return fieldSchema.fieldSections.filter(
35937
35950
  (sourceSection) => !willCreateCycle(graph, sourceSection.identifier, fieldSection.identifier)
35938
35951
  );
35939
- }, [fieldSchema.fields, fieldSection.identifier]);
35952
+ }, [fieldSchema.fieldSections, fieldSection.identifier]);
35940
35953
  return /* @__PURE__ */ jsxs("div", { className: "flex grow w-full flex-col gap-4", children: [
35941
35954
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 w-full overflow-hidden", children: [
35942
35955
  /* @__PURE__ */ jsx(Input.Root, { variant: "outline", size: "md", children: /* @__PURE__ */ jsx(
@@ -36000,17 +36013,17 @@ const FieldSectionWithActions = memo((props) => {
36000
36013
  [fieldSection]
36001
36014
  );
36002
36015
  const removeSection = useCallback(() => {
36003
- fieldSchema.removeField(fieldSection);
36016
+ fieldSchema.removeFieldSection(fieldSection);
36004
36017
  }, [fieldSchema, fieldSection]);
36005
36018
  const moveSection = useCallback(
36006
36019
  (direction) => {
36007
36020
  const targetIndex = direction === "up" ? sectionIndex - 1 : sectionIndex + 1;
36008
- fieldSchema.moveField(sectionIndex, targetIndex);
36021
+ fieldSchema.moveFieldSection(sectionIndex, targetIndex);
36009
36022
  },
36010
36023
  [fieldSchema, sectionIndex]
36011
36024
  );
36012
36025
  const duplicateSection = useCallback(() => {
36013
- fieldSchema.addField(fieldSection.duplicate(v4()));
36026
+ fieldSchema.addFieldSection(fieldSection.duplicate(v4()));
36014
36027
  }, [fieldSchema, fieldSection]);
36015
36028
  const handleCreateField = useCallback(
36016
36029
  (type) => {
@@ -36069,7 +36082,7 @@ const FormBuilderListBuilder = memo(() => {
36069
36082
  const { hideTitle, hideDescription, onCancel } = use(FormBuilderContext);
36070
36083
  const fieldSchema = use(FieldSchemaContext);
36071
36084
  const handleCreateEmptySection = useCallback(() => {
36072
- fieldSchema.addField(new FieldSection({ identifier: v4(), fields: [] }));
36085
+ fieldSchema.addFieldSection(new FieldSection({ identifier: v4(), fields: [] }));
36073
36086
  }, [fieldSchema]);
36074
36087
  const [titleFieldProps, titleMeta, titleHelpers] = useField("title");
36075
36088
  const [descriptionFieldProps, _descriptionMeta, descriptionHelpers] = useField("description");
@@ -36108,7 +36121,7 @@ const FormBuilderListBuilder = memo(() => {
36108
36121
  }
36109
36122
  ),
36110
36123
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
36111
- fieldSchema.fields.map((fieldSection, index) => /* @__PURE__ */ jsx(FieldSectionWithActions, { fieldSection, index }, fieldSection.identifier)),
36124
+ fieldSchema.fieldSections.map((fieldSection, index) => /* @__PURE__ */ jsx(FieldSectionWithActions, { fieldSection, index }, fieldSection.identifier)),
36112
36125
  /* @__PURE__ */ jsxs(
36113
36126
  Button,
36114
36127
  {
@@ -36357,12 +36370,12 @@ const FormBuilderPreview = memo((props) => {
36357
36370
  return {
36358
36371
  title: values.title,
36359
36372
  description: values.description,
36360
- fields: fieldSchema.fields,
36373
+ fields: fieldSchema.fieldSections,
36361
36374
  meta: {
36362
36375
  readonly: false
36363
36376
  }
36364
36377
  };
36365
- }, [fieldSchema.fields, values.description, values.title]);
36378
+ }, [fieldSchema.fieldSections, values.description, values.title]);
36366
36379
  return /* @__PURE__ */ jsx(FormRenderer, { schema: previewSchema, hideTitle: !showFormTitle });
36367
36380
  });
36368
36381
  FormBuilderPreview.displayName = "FormBuilderPreview";
@@ -34940,7 +34940,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
34940
34940
  class FieldSchema extends Observable {
34941
34941
  constructor(fields) {
34942
34942
  super();
34943
- __publicField(this, "fields");
34943
+ __publicField(this, "fieldSections");
34944
34944
  // Fields
34945
34945
  __publicField(this, "fieldObserver", () => {
34946
34946
  this.notify(this);
@@ -34949,50 +34949,53 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
34949
34949
  for (const field of fields) field.observe(this.fieldObserver);
34950
34950
  return fields;
34951
34951
  });
34952
- this.fields = this.initFields(fields);
34952
+ this.fieldSections = this.initFields(fields);
34953
34953
  }
34954
34954
  serialize() {
34955
- return this.fields.map((field) => field.serialize());
34955
+ return this.fieldSections.map((field) => field.serialize());
34956
34956
  }
34957
34957
  static deserialize(serializedSections) {
34958
34958
  return new FieldSchema(serializedSections.map(FieldSection.deserialize));
34959
34959
  }
34960
- addField(field) {
34961
- this.fields = this.initFields([...this.fields, field]);
34962
- this.notify(this);
34960
+ getFields() {
34961
+ return this.fieldSections.flatMap((fieldSection) => fieldSection.getFields());
34963
34962
  }
34964
- addFields(fields) {
34965
- this.fields = this.initFields([...this.fields, ...fields]);
34963
+ getFieldSections() {
34964
+ return this.fieldSections;
34965
+ }
34966
+ addFieldSection(field) {
34967
+ this.fieldSections = this.initFields([...this.fieldSections, field]);
34966
34968
  this.notify(this);
34967
34969
  }
34968
- getFields() {
34969
- return this.fields;
34970
+ addFieldSections(fields) {
34971
+ this.fieldSections = this.initFields([...this.fieldSections, ...fields]);
34972
+ this.notify(this);
34970
34973
  }
34971
- removeField(field) {
34972
- const newFields = this.fields.filter((f) => f.identifier !== field.identifier);
34974
+ removeFieldSection(field) {
34975
+ const newFields = this.fieldSections.filter((f) => f.identifier !== field.identifier);
34973
34976
  for (const field2 of newFields) {
34974
34977
  field2.removeConditional(field2.identifier);
34975
34978
  }
34976
- this.fields = this.initFields(newFields);
34979
+ this.fieldSections = this.initFields(newFields);
34977
34980
  this.notify(this);
34978
34981
  }
34979
- removeFields(fields) {
34982
+ removeFieldSections(fields) {
34980
34983
  const fieldsIds = new Set(fields.map((f) => f.identifier));
34981
- this.fields = this.initFields(this.fields.filter((f) => !fieldsIds.has(f.identifier)));
34984
+ this.fieldSections = this.initFields(this.fieldSections.filter((f) => !fieldsIds.has(f.identifier)));
34982
34985
  this.notify(this);
34983
34986
  }
34984
- moveField(sourceIndex, targetIndex) {
34985
- const newFields = [...this.fields];
34987
+ moveFieldSection(sourceIndex, targetIndex) {
34988
+ const newFields = [...this.fieldSections];
34986
34989
  const [removedElement] = newFields.splice(sourceIndex, 1);
34987
34990
  newFields.splice(targetIndex, 0, removedElement);
34988
- this.fields = this.initFields(newFields);
34991
+ this.fieldSections = this.initFields(newFields);
34989
34992
  this.notify(this);
34990
34993
  }
34991
34994
  deserializeValues(values) {
34992
- return deserializeFieldValues(flattenFields(this.fields), values);
34995
+ return deserializeFieldValues(this.getFields(), values);
34993
34996
  }
34994
34997
  serializeValues(values) {
34995
- return serializeFieldValues(flattenFields(this.fields), values);
34998
+ return serializeFieldValues(this.getFields(), values);
34996
34999
  }
34997
35000
  }
34998
35001
  const FieldSchemaContext = React.createContext(new FieldSchema([]));
@@ -35439,7 +35442,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35439
35442
  FieldWithActions.displayName = "FieldWithActions";
35440
35443
  const FieldSectionConditionEdgeComponent = React.memo((props) => {
35441
35444
  const { id, sourceX, sourceY, targetX, targetY, style, markerEnd, data } = props;
35442
- const { targetSection, sourceSection } = data;
35445
+ const { targetSection, sourceSection, layoutDirection } = data;
35443
35446
  const conditions = React.useMemo(() => {
35444
35447
  return sourceSection.getConditions(targetSection.identifier);
35445
35448
  }, [sourceSection, targetSection.identifier]);
@@ -35461,11 +35464,13 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35461
35464
  const [edgePath, labelX, labelY] = react.getBezierPath({
35462
35465
  sourceX,
35463
35466
  sourceY,
35467
+ sourcePosition: layoutDirection === "LR" ? react.Position.Right : react.Position.Bottom,
35464
35468
  targetX,
35465
- targetY
35469
+ targetY,
35470
+ targetPosition: layoutDirection === "LR" ? react.Position.Left : react.Position.Top
35466
35471
  });
35467
35472
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
35468
- /* @__PURE__ */ jsxRuntime.jsx(react.BaseEdge, { id, path: edgePath, style, markerEnd }),
35473
+ /* @__PURE__ */ jsxRuntime.jsx(react.BaseEdge, { id, path: edgePath, style, markerEnd, labelX, labelY }),
35469
35474
  /* @__PURE__ */ jsxRuntime.jsx(react.EdgeLabelRenderer, { children: /* @__PURE__ */ jsxRuntime.jsxs(
35470
35475
  blocks.Card,
35471
35476
  {
@@ -35514,7 +35519,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35514
35519
  }) }, condition.id)) })
35515
35520
  ]
35516
35521
  }
35517
- ) }, id)
35522
+ ) })
35518
35523
  ] });
35519
35524
  });
35520
35525
  FieldSectionConditionEdgeComponent.displayName = "FieldSectionConditionEdgeComponent";
@@ -35536,7 +35541,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35536
35541
  const { fieldSection, index: sectionIndex, layoutDirection } = data;
35537
35542
  const fieldSchema = React.use(FieldSchemaContext);
35538
35543
  const removeSection = React.useCallback(() => {
35539
- fieldSchema.removeField(fieldSection);
35544
+ fieldSchema.removeFieldSection(fieldSection);
35540
35545
  }, [fieldSchema, fieldSection]);
35541
35546
  const addField = React.useCallback(
35542
35547
  (type) => {
@@ -35546,11 +35551,11 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35546
35551
  );
35547
35552
  const handleAddBranch = React.useCallback(() => {
35548
35553
  const section = new FieldSection({ identifier: uuid.v4(), fields: [] });
35549
- fieldSchema.addField(section);
35554
+ fieldSchema.addFieldSection(section);
35550
35555
  fieldSection.addConditional(section.identifier);
35551
35556
  }, [fieldSchema, fieldSection]);
35552
35557
  const handleDuplicate = React.useCallback(() => {
35553
- fieldSchema.addField(fieldSection.duplicate(uuid.v4()));
35558
+ fieldSchema.addFieldSection(fieldSection.duplicate(uuid.v4()));
35554
35559
  }, [fieldSchema, fieldSection]);
35555
35560
  const fieldTypeItems = useFieldTypeItems(addField);
35556
35561
  const removeField = React.useCallback(
@@ -35666,10 +35671,17 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35666
35671
  const edgeTypes = {
35667
35672
  fieldSectionCondition: FieldSectionConditionEdgeComponent
35668
35673
  };
35669
- const getLayoutedElements = (nodes, edges, direction) => {
35674
+ const getLayoutedNodesAndEdges = (nodes, edges, direction) => {
35670
35675
  const g = new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({}));
35671
35676
  g.setGraph({ rankdir: direction, nodesep: 200, edgesep: 500, ranksep: 500 });
35672
- edges.forEach((edge) => g.setEdge(edge.source, edge.target));
35677
+ edges.forEach(
35678
+ (edge) => g.setEdge(edge.source, edge.target, {
35679
+ // TODO: Measure edges
35680
+ width: 500,
35681
+ height: 200,
35682
+ labelpos: "c"
35683
+ })
35684
+ );
35673
35685
  nodes.forEach(
35674
35686
  (node) => {
35675
35687
  var _a2, _b;
@@ -35707,7 +35719,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35707
35719
  ref.current.classList.remove("light");
35708
35720
  }, []);
35709
35721
  const initialNodes = React.useMemo(
35710
- () => fieldSchema.fields.map((fieldSection, index) => ({
35722
+ () => fieldSchema.fieldSections.map((fieldSection, index) => ({
35711
35723
  id: fieldSection.identifier,
35712
35724
  position: { x: 0, y: 0 },
35713
35725
  data: {
@@ -35718,15 +35730,15 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35718
35730
  draggable: true,
35719
35731
  type: "fieldSection"
35720
35732
  })),
35721
- [fieldSchema.fields, layoutDirection]
35733
+ [fieldSchema.fieldSections, layoutDirection]
35722
35734
  );
35723
35735
  const initialEdges = React.useMemo(() => {
35724
35736
  const es = [];
35725
35737
  const sectionsMapping = {};
35726
- for (const section of fieldSchema.fields) {
35738
+ for (const section of fieldSchema.fieldSections) {
35727
35739
  sectionsMapping[section.identifier] = section;
35728
35740
  }
35729
- for (const section of fieldSchema.fields) {
35741
+ for (const section of fieldSchema.fieldSections) {
35730
35742
  const sectionConditions = section.conditions;
35731
35743
  for (const [conditionSectionId, conditions] of Object.entries(sectionConditions)) {
35732
35744
  es.push({
@@ -35735,7 +35747,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35735
35747
  target: conditionSectionId,
35736
35748
  data: {
35737
35749
  targetSection: sectionsMapping[conditionSectionId],
35738
- sourceSection: section
35750
+ sourceSection: section,
35751
+ layoutDirection
35739
35752
  },
35740
35753
  animated: conditions.length > 0,
35741
35754
  markerEnd: react.MarkerType.Arrow,
@@ -35745,7 +35758,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35745
35758
  }
35746
35759
  }
35747
35760
  return es;
35748
- }, [fieldSchema.fields]);
35761
+ }, [fieldSchema.fieldSections, layoutDirection]);
35749
35762
  const [nodes, setNodes, handleNodesChange] = react.useNodesState(initialNodes);
35750
35763
  const [edges, setEdges, handleEdgesChange] = react.useEdgesState(initialEdges);
35751
35764
  React.useEffect(() => {
@@ -35755,15 +35768,15 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35755
35768
  setEdges(initialEdges);
35756
35769
  }, [initialEdges, setEdges]);
35757
35770
  const [layoutedNodes, layoutedEdges] = React.useMemo(() => {
35758
- return getLayoutedElements(nodes, edges, layoutDirection);
35771
+ return getLayoutedNodesAndEdges(nodes, edges, layoutDirection);
35759
35772
  }, [edges, layoutDirection, nodes]);
35760
35773
  const handleAddSection = React.useCallback(() => {
35761
- fieldSchema.addField(new FieldSection({ identifier: uuid.v4(), fields: [] }));
35774
+ fieldSchema.addFieldSection(new FieldSection({ identifier: uuid.v4(), fields: [] }));
35762
35775
  }, [fieldSchema]);
35763
35776
  const handleConnect = React.useCallback(
35764
35777
  (params) => {
35765
35778
  const { source: sourceId, target: targetId } = params;
35766
- const sourceSection = fieldSchema.fields.find(({ identifier }) => identifier === sourceId);
35779
+ const sourceSection = fieldSchema.fieldSections.find(({ identifier }) => identifier === sourceId);
35767
35780
  sourceSection.setOptions({
35768
35781
  conditions: {
35769
35782
  ...sourceSection.conditions,
@@ -35771,19 +35784,19 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35771
35784
  }
35772
35785
  });
35773
35786
  },
35774
- [fieldSchema.fields]
35787
+ [fieldSchema.fieldSections]
35775
35788
  );
35776
35789
  const handleValidConnection = React.useCallback(
35777
35790
  (edge) => {
35778
35791
  const graph = new graphology.DirectedGraph({});
35779
- for (const sourceSection of fieldSchema.fields) {
35792
+ for (const sourceSection of fieldSchema.fieldSections) {
35780
35793
  for (const targetSectionId of Object.keys(sourceSection.conditions)) {
35781
35794
  graph.mergeEdge(sourceSection.identifier, targetSectionId);
35782
35795
  }
35783
35796
  }
35784
35797
  return !graphologyDag.willCreateCycle(graph, edge.source, edge.target);
35785
35798
  },
35786
- [fieldSchema.fields]
35799
+ [fieldSchema.fieldSections]
35787
35800
  );
35788
35801
  const [titleFieldProps, titleMeta, titleHelpers] = formik.useField("title");
35789
35802
  const [descriptionFieldProps, _descriptionMeta, descriptionHelpers] = formik.useField("description");
@@ -35920,8 +35933,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35920
35933
  const { fieldSection } = props;
35921
35934
  const fieldSchema = React.use(FieldSchemaContext);
35922
35935
  const conditionalSections = React.useMemo(() => {
35923
- return fieldSchema.fields.filter((section) => fieldSection.identifier in section.conditions);
35924
- }, [fieldSchema.fields, fieldSection.identifier]);
35936
+ return fieldSchema.fieldSections.filter((section) => fieldSection.identifier in section.conditions);
35937
+ }, [fieldSchema.fieldSections, fieldSection.identifier]);
35925
35938
  const handleAddConditional = React.useCallback(
35926
35939
  (conditionalSection) => {
35927
35940
  conditionalSection.addConditional(fieldSection.identifier);
@@ -35930,15 +35943,15 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
35930
35943
  );
35931
35944
  const validFieldSections = React.useMemo(() => {
35932
35945
  const graph = new graphology.DirectedGraph({});
35933
- for (const sourceSection of fieldSchema.fields) {
35946
+ for (const sourceSection of fieldSchema.fieldSections) {
35934
35947
  for (const targetSectionId of Object.keys(sourceSection.conditions)) {
35935
35948
  graph.mergeEdge(sourceSection.identifier, targetSectionId);
35936
35949
  }
35937
35950
  }
35938
- return fieldSchema.fields.filter(
35951
+ return fieldSchema.fieldSections.filter(
35939
35952
  (sourceSection) => !graphologyDag.willCreateCycle(graph, sourceSection.identifier, fieldSection.identifier)
35940
35953
  );
35941
- }, [fieldSchema.fields, fieldSection.identifier]);
35954
+ }, [fieldSchema.fieldSections, fieldSection.identifier]);
35942
35955
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex grow w-full flex-col gap-4", children: [
35943
35956
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 w-full overflow-hidden", children: [
35944
35957
  /* @__PURE__ */ jsxRuntime.jsx(blocks.Input.Root, { variant: "outline", size: "md", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -36002,17 +36015,17 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36002
36015
  [fieldSection]
36003
36016
  );
36004
36017
  const removeSection = React.useCallback(() => {
36005
- fieldSchema.removeField(fieldSection);
36018
+ fieldSchema.removeFieldSection(fieldSection);
36006
36019
  }, [fieldSchema, fieldSection]);
36007
36020
  const moveSection = React.useCallback(
36008
36021
  (direction) => {
36009
36022
  const targetIndex = direction === "up" ? sectionIndex - 1 : sectionIndex + 1;
36010
- fieldSchema.moveField(sectionIndex, targetIndex);
36023
+ fieldSchema.moveFieldSection(sectionIndex, targetIndex);
36011
36024
  },
36012
36025
  [fieldSchema, sectionIndex]
36013
36026
  );
36014
36027
  const duplicateSection = React.useCallback(() => {
36015
- fieldSchema.addField(fieldSection.duplicate(uuid.v4()));
36028
+ fieldSchema.addFieldSection(fieldSection.duplicate(uuid.v4()));
36016
36029
  }, [fieldSchema, fieldSection]);
36017
36030
  const handleCreateField = React.useCallback(
36018
36031
  (type) => {
@@ -36071,7 +36084,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36071
36084
  const { hideTitle, hideDescription, onCancel } = React.use(FormBuilderContext);
36072
36085
  const fieldSchema = React.use(FieldSchemaContext);
36073
36086
  const handleCreateEmptySection = React.useCallback(() => {
36074
- fieldSchema.addField(new FieldSection({ identifier: uuid.v4(), fields: [] }));
36087
+ fieldSchema.addFieldSection(new FieldSection({ identifier: uuid.v4(), fields: [] }));
36075
36088
  }, [fieldSchema]);
36076
36089
  const [titleFieldProps, titleMeta, titleHelpers] = formik.useField("title");
36077
36090
  const [descriptionFieldProps, _descriptionMeta, descriptionHelpers] = formik.useField("description");
@@ -36110,7 +36123,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36110
36123
  }
36111
36124
  ),
36112
36125
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
36113
- fieldSchema.fields.map((fieldSection, index) => /* @__PURE__ */ jsxRuntime.jsx(FieldSectionWithActions, { fieldSection, index }, fieldSection.identifier)),
36126
+ fieldSchema.fieldSections.map((fieldSection, index) => /* @__PURE__ */ jsxRuntime.jsx(FieldSectionWithActions, { fieldSection, index }, fieldSection.identifier)),
36114
36127
  /* @__PURE__ */ jsxRuntime.jsxs(
36115
36128
  blocks.Button,
36116
36129
  {
@@ -36359,12 +36372,12 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36359
36372
  return {
36360
36373
  title: values.title,
36361
36374
  description: values.description,
36362
- fields: fieldSchema.fields,
36375
+ fields: fieldSchema.fieldSections,
36363
36376
  meta: {
36364
36377
  readonly: false
36365
36378
  }
36366
36379
  };
36367
- }, [fieldSchema.fields, values.description, values.title]);
36380
+ }, [fieldSchema.fieldSections, values.description, values.title]);
36368
36381
  return /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { schema: previewSchema, hideTitle: !showFormTitle });
36369
36382
  });
36370
36383
  FormBuilderPreview.displayName = "FormBuilderPreview";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmap-ai/forms",
3
- "version": "1.0.32-react-flow-david-fixes.27",
3
+ "version": "1.0.32-react-flow-david-fixes.30",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/forms.umd.cjs",
6
6
  "module": "dist/forms.js",