@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.
- package/dist/form/builder/flow/index.d.ts +1 -1
- package/dist/form/builder/flow/layout.d.ts +1 -1
- package/dist/form/builder/flow/typings.d.ts +1 -0
- package/dist/form/fields/FieldSection/FieldSection.d.ts +1 -1
- package/dist/form/fields/typings.d.ts +17 -7
- package/dist/form/schema/FieldSchema.d.ts +10 -9
- package/dist/forms.js +67 -54
- package/dist/forms.umd.cjs +66 -53
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './FlowBuilder';
|
|
2
|
-
export {
|
|
2
|
+
export { getLayoutedNodesAndEdges } from './layout';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { FieldSectionConditionEdge, FieldSectionNode, LayoutDirection } from './typings';
|
|
2
|
-
export declare const
|
|
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
|
|
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
|
|
30
|
-
readonly fields:
|
|
31
|
-
getFields():
|
|
32
|
-
addField(field:
|
|
33
|
-
addFields(fields:
|
|
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:
|
|
36
|
-
removeFields(fields:
|
|
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,
|
|
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
|
|
5
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,
|
|
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, "
|
|
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.
|
|
34950
|
+
this.fieldSections = this.initFields(fields);
|
|
34951
34951
|
}
|
|
34952
34952
|
serialize() {
|
|
34953
|
-
return this.
|
|
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
|
-
|
|
34959
|
-
this.
|
|
34960
|
-
this.notify(this);
|
|
34958
|
+
getFields() {
|
|
34959
|
+
return this.fieldSections.flatMap((fieldSection) => fieldSection.getFields());
|
|
34961
34960
|
}
|
|
34962
|
-
|
|
34963
|
-
|
|
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
|
-
|
|
34967
|
-
|
|
34968
|
+
addFieldSections(fields) {
|
|
34969
|
+
this.fieldSections = this.initFields([...this.fieldSections, ...fields]);
|
|
34970
|
+
this.notify(this);
|
|
34968
34971
|
}
|
|
34969
|
-
|
|
34970
|
-
const newFields = this.
|
|
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.
|
|
34977
|
+
this.fieldSections = this.initFields(newFields);
|
|
34975
34978
|
this.notify(this);
|
|
34976
34979
|
}
|
|
34977
|
-
|
|
34980
|
+
removeFieldSections(fields) {
|
|
34978
34981
|
const fieldsIds = new Set(fields.map((f) => f.identifier));
|
|
34979
|
-
this.
|
|
34982
|
+
this.fieldSections = this.initFields(this.fieldSections.filter((f) => !fieldsIds.has(f.identifier)));
|
|
34980
34983
|
this.notify(this);
|
|
34981
34984
|
}
|
|
34982
|
-
|
|
34983
|
-
const newFields = [...this.
|
|
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.
|
|
34989
|
+
this.fieldSections = this.initFields(newFields);
|
|
34987
34990
|
this.notify(this);
|
|
34988
34991
|
}
|
|
34989
34992
|
deserializeValues(values) {
|
|
34990
|
-
return deserializeFieldValues(
|
|
34993
|
+
return deserializeFieldValues(this.getFields(), values);
|
|
34991
34994
|
}
|
|
34992
34995
|
serializeValues(values) {
|
|
34993
|
-
return serializeFieldValues(
|
|
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
|
-
) }
|
|
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.
|
|
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.
|
|
35552
|
+
fieldSchema.addFieldSection(section);
|
|
35548
35553
|
fieldSection.addConditional(section.identifier);
|
|
35549
35554
|
}, [fieldSchema, fieldSection]);
|
|
35550
35555
|
const handleDuplicate = useCallback(() => {
|
|
35551
|
-
fieldSchema.
|
|
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
|
|
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(
|
|
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.
|
|
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.
|
|
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.
|
|
35736
|
+
for (const section of fieldSchema.fieldSections) {
|
|
35725
35737
|
sectionsMapping[section.identifier] = section;
|
|
35726
35738
|
}
|
|
35727
|
-
for (const section of fieldSchema.
|
|
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.
|
|
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
|
|
35769
|
+
return getLayoutedNodesAndEdges(nodes, edges, layoutDirection);
|
|
35757
35770
|
}, [edges, layoutDirection, nodes]);
|
|
35758
35771
|
const handleAddSection = useCallback(() => {
|
|
35759
|
-
fieldSchema.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
35922
|
-
}, [fieldSchema.
|
|
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.
|
|
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.
|
|
35949
|
+
return fieldSchema.fieldSections.filter(
|
|
35937
35950
|
(sourceSection) => !willCreateCycle(graph, sourceSection.identifier, fieldSection.identifier)
|
|
35938
35951
|
);
|
|
35939
|
-
}, [fieldSchema.
|
|
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.
|
|
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.
|
|
36021
|
+
fieldSchema.moveFieldSection(sectionIndex, targetIndex);
|
|
36009
36022
|
},
|
|
36010
36023
|
[fieldSchema, sectionIndex]
|
|
36011
36024
|
);
|
|
36012
36025
|
const duplicateSection = useCallback(() => {
|
|
36013
|
-
fieldSchema.
|
|
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.
|
|
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.
|
|
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.
|
|
36373
|
+
fields: fieldSchema.fieldSections,
|
|
36361
36374
|
meta: {
|
|
36362
36375
|
readonly: false
|
|
36363
36376
|
}
|
|
36364
36377
|
};
|
|
36365
|
-
}, [fieldSchema.
|
|
36378
|
+
}, [fieldSchema.fieldSections, values.description, values.title]);
|
|
36366
36379
|
return /* @__PURE__ */ jsx(FormRenderer, { schema: previewSchema, hideTitle: !showFormTitle });
|
|
36367
36380
|
});
|
|
36368
36381
|
FormBuilderPreview.displayName = "FormBuilderPreview";
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -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, "
|
|
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.
|
|
34952
|
+
this.fieldSections = this.initFields(fields);
|
|
34953
34953
|
}
|
|
34954
34954
|
serialize() {
|
|
34955
|
-
return this.
|
|
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
|
-
|
|
34961
|
-
this.
|
|
34962
|
-
this.notify(this);
|
|
34960
|
+
getFields() {
|
|
34961
|
+
return this.fieldSections.flatMap((fieldSection) => fieldSection.getFields());
|
|
34963
34962
|
}
|
|
34964
|
-
|
|
34965
|
-
|
|
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
|
-
|
|
34969
|
-
|
|
34970
|
+
addFieldSections(fields) {
|
|
34971
|
+
this.fieldSections = this.initFields([...this.fieldSections, ...fields]);
|
|
34972
|
+
this.notify(this);
|
|
34970
34973
|
}
|
|
34971
|
-
|
|
34972
|
-
const newFields = this.
|
|
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.
|
|
34979
|
+
this.fieldSections = this.initFields(newFields);
|
|
34977
34980
|
this.notify(this);
|
|
34978
34981
|
}
|
|
34979
|
-
|
|
34982
|
+
removeFieldSections(fields) {
|
|
34980
34983
|
const fieldsIds = new Set(fields.map((f) => f.identifier));
|
|
34981
|
-
this.
|
|
34984
|
+
this.fieldSections = this.initFields(this.fieldSections.filter((f) => !fieldsIds.has(f.identifier)));
|
|
34982
34985
|
this.notify(this);
|
|
34983
34986
|
}
|
|
34984
|
-
|
|
34985
|
-
const newFields = [...this.
|
|
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.
|
|
34991
|
+
this.fieldSections = this.initFields(newFields);
|
|
34989
34992
|
this.notify(this);
|
|
34990
34993
|
}
|
|
34991
34994
|
deserializeValues(values) {
|
|
34992
|
-
return deserializeFieldValues(
|
|
34995
|
+
return deserializeFieldValues(this.getFields(), values);
|
|
34993
34996
|
}
|
|
34994
34997
|
serializeValues(values) {
|
|
34995
|
-
return serializeFieldValues(
|
|
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
|
-
) }
|
|
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.
|
|
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.
|
|
35554
|
+
fieldSchema.addFieldSection(section);
|
|
35550
35555
|
fieldSection.addConditional(section.identifier);
|
|
35551
35556
|
}, [fieldSchema, fieldSection]);
|
|
35552
35557
|
const handleDuplicate = React.useCallback(() => {
|
|
35553
|
-
fieldSchema.
|
|
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
|
|
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(
|
|
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.
|
|
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.
|
|
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.
|
|
35738
|
+
for (const section of fieldSchema.fieldSections) {
|
|
35727
35739
|
sectionsMapping[section.identifier] = section;
|
|
35728
35740
|
}
|
|
35729
|
-
for (const section of fieldSchema.
|
|
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.
|
|
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
|
|
35771
|
+
return getLayoutedNodesAndEdges(nodes, edges, layoutDirection);
|
|
35759
35772
|
}, [edges, layoutDirection, nodes]);
|
|
35760
35773
|
const handleAddSection = React.useCallback(() => {
|
|
35761
|
-
fieldSchema.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
35924
|
-
}, [fieldSchema.
|
|
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.
|
|
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.
|
|
35951
|
+
return fieldSchema.fieldSections.filter(
|
|
35939
35952
|
(sourceSection) => !graphologyDag.willCreateCycle(graph, sourceSection.identifier, fieldSection.identifier)
|
|
35940
35953
|
);
|
|
35941
|
-
}, [fieldSchema.
|
|
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.
|
|
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.
|
|
36023
|
+
fieldSchema.moveFieldSection(sectionIndex, targetIndex);
|
|
36011
36024
|
},
|
|
36012
36025
|
[fieldSchema, sectionIndex]
|
|
36013
36026
|
);
|
|
36014
36027
|
const duplicateSection = React.useCallback(() => {
|
|
36015
|
-
fieldSchema.
|
|
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.
|
|
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.
|
|
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.
|
|
36375
|
+
fields: fieldSchema.fieldSections,
|
|
36363
36376
|
meta: {
|
|
36364
36377
|
readonly: false
|
|
36365
36378
|
}
|
|
36366
36379
|
};
|
|
36367
|
-
}, [fieldSchema.
|
|
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";
|