@invana/forms 0.0.11 → 0.0.12
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/index.cjs +70 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +70 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -66,6 +66,20 @@ type FieldConfig = {
|
|
|
66
66
|
defaultValue?: string;
|
|
67
67
|
/** Number of visible rows for `textarea` fields. */
|
|
68
68
|
rows?: number;
|
|
69
|
+
/**
|
|
70
|
+
* How many grid columns the field spans on `md+` screens. Defaults to `1`.
|
|
71
|
+
* The grid is two columns by default (see `ObjectField`'s `columns`), so
|
|
72
|
+
* `colSpan: 2` makes a full-width field (textarea, long URI, …). A span
|
|
73
|
+
* larger than the column count simply fills the row. Ignored below `md`,
|
|
74
|
+
* where every field stacks full width.
|
|
75
|
+
*/
|
|
76
|
+
colSpan?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Extra classes merged onto the field's grid cell. Escape hatch for
|
|
79
|
+
* per-field layout/spacing tweaks (custom width, ordering, margins, …)
|
|
80
|
+
* without adding a dedicated prop for every case.
|
|
81
|
+
*/
|
|
82
|
+
className?: string;
|
|
69
83
|
};
|
|
70
84
|
type RowConfig = {
|
|
71
85
|
id: string;
|
|
@@ -79,6 +93,12 @@ interface ObjectFieldProps {
|
|
|
79
93
|
labelPosition?: LabelPosition;
|
|
80
94
|
/** Field density. Defaults to `sm` (compact) for backward compatibility. */
|
|
81
95
|
size?: FieldSize;
|
|
96
|
+
/**
|
|
97
|
+
* Number of columns in the field grid on `md+` screens. Defaults to `2`.
|
|
98
|
+
* Increase it to build wider layouts that fields can span via `colSpan`.
|
|
99
|
+
* Below `md` the grid always collapses to a single column.
|
|
100
|
+
*/
|
|
101
|
+
columns?: number;
|
|
82
102
|
}
|
|
83
103
|
|
|
84
104
|
type AnyValue = any;
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,20 @@ type FieldConfig = {
|
|
|
66
66
|
defaultValue?: string;
|
|
67
67
|
/** Number of visible rows for `textarea` fields. */
|
|
68
68
|
rows?: number;
|
|
69
|
+
/**
|
|
70
|
+
* How many grid columns the field spans on `md+` screens. Defaults to `1`.
|
|
71
|
+
* The grid is two columns by default (see `ObjectField`'s `columns`), so
|
|
72
|
+
* `colSpan: 2` makes a full-width field (textarea, long URI, …). A span
|
|
73
|
+
* larger than the column count simply fills the row. Ignored below `md`,
|
|
74
|
+
* where every field stacks full width.
|
|
75
|
+
*/
|
|
76
|
+
colSpan?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Extra classes merged onto the field's grid cell. Escape hatch for
|
|
79
|
+
* per-field layout/spacing tweaks (custom width, ordering, margins, …)
|
|
80
|
+
* without adding a dedicated prop for every case.
|
|
81
|
+
*/
|
|
82
|
+
className?: string;
|
|
69
83
|
};
|
|
70
84
|
type RowConfig = {
|
|
71
85
|
id: string;
|
|
@@ -79,6 +93,12 @@ interface ObjectFieldProps {
|
|
|
79
93
|
labelPosition?: LabelPosition;
|
|
80
94
|
/** Field density. Defaults to `sm` (compact) for backward compatibility. */
|
|
81
95
|
size?: FieldSize;
|
|
96
|
+
/**
|
|
97
|
+
* Number of columns in the field grid on `md+` screens. Defaults to `2`.
|
|
98
|
+
* Increase it to build wider layouts that fields can span via `colSpan`.
|
|
99
|
+
* Below `md` the grid always collapses to a single column.
|
|
100
|
+
*/
|
|
101
|
+
columns?: number;
|
|
82
102
|
}
|
|
83
103
|
|
|
84
104
|
type AnyValue = any;
|
package/dist/index.js
CHANGED
|
@@ -681,11 +681,6 @@ var Field = {
|
|
|
681
681
|
function humanize(name) {
|
|
682
682
|
return name.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase()).trim();
|
|
683
683
|
}
|
|
684
|
-
function chunk(arr, size) {
|
|
685
|
-
const out = [];
|
|
686
|
-
for (let i = 0; i < arr.length; i += size) out.push(arr.slice(i, i + size));
|
|
687
|
-
return out;
|
|
688
|
-
}
|
|
689
684
|
function renderField(field, parentName, control, labelPosition, size) {
|
|
690
685
|
return /* @__PURE__ */ jsx(
|
|
691
686
|
FormField,
|
|
@@ -751,9 +746,38 @@ function renderField(field, parentName, control, labelPosition, size) {
|
|
|
751
746
|
field.name
|
|
752
747
|
);
|
|
753
748
|
}
|
|
754
|
-
function
|
|
749
|
+
function renderGrid(fields, parentName, control, labelPosition, size, columns, key) {
|
|
750
|
+
const customCols = columns !== 2;
|
|
751
|
+
return /* @__PURE__ */ jsx(
|
|
752
|
+
"div",
|
|
753
|
+
{
|
|
754
|
+
className: cn(
|
|
755
|
+
"grid grid-cols-1 gap-4",
|
|
756
|
+
customCols ? "md:[grid-template-columns:repeat(var(--ff-cols),minmax(0,1fr))]" : "md:grid-cols-2"
|
|
757
|
+
),
|
|
758
|
+
style: customCols ? { "--ff-cols": columns } : void 0,
|
|
759
|
+
children: fields.map((f) => {
|
|
760
|
+
const span = f.colSpan && f.colSpan > 1 ? f.colSpan : void 0;
|
|
761
|
+
return /* @__PURE__ */ jsx(
|
|
762
|
+
"div",
|
|
763
|
+
{
|
|
764
|
+
className: cn(
|
|
765
|
+
span && "md:[grid-column:span_var(--ff-span)/span_var(--ff-span)]",
|
|
766
|
+
f.className
|
|
767
|
+
),
|
|
768
|
+
style: span ? { "--ff-span": span } : void 0,
|
|
769
|
+
children: renderField(f, parentName, control, labelPosition, size)
|
|
770
|
+
},
|
|
771
|
+
f.name
|
|
772
|
+
);
|
|
773
|
+
})
|
|
774
|
+
},
|
|
775
|
+
key
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
function renderRows(fields, rowConfig, parentName, control, labelPosition, size, columns) {
|
|
755
779
|
if (!rowConfig || rowConfig.length === 0) {
|
|
756
|
-
return
|
|
780
|
+
return renderGrid(fields, parentName, control, labelPosition, size, columns);
|
|
757
781
|
}
|
|
758
782
|
const used = new Set(rowConfig.flatMap((r) => r.fields));
|
|
759
783
|
const unassigned = fields.filter((f) => !used.has(f.name));
|
|
@@ -761,16 +785,26 @@ function renderRows(fields, rowConfig, parentName, control, labelPosition, size)
|
|
|
761
785
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
762
786
|
rowConfig.map((row) => {
|
|
763
787
|
const rowFields = row.fields.map((n) => byName.get(n)).filter((f) => !!f);
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
788
|
+
if (rowFields.length === 0) return null;
|
|
789
|
+
return renderGrid(
|
|
790
|
+
rowFields,
|
|
791
|
+
parentName,
|
|
792
|
+
control,
|
|
793
|
+
labelPosition,
|
|
794
|
+
size,
|
|
795
|
+
columns,
|
|
796
|
+
row.id
|
|
797
|
+
);
|
|
772
798
|
}),
|
|
773
|
-
unassigned.length > 0 &&
|
|
799
|
+
unassigned.length > 0 && renderGrid(
|
|
800
|
+
unassigned,
|
|
801
|
+
parentName,
|
|
802
|
+
control,
|
|
803
|
+
labelPosition,
|
|
804
|
+
size,
|
|
805
|
+
columns,
|
|
806
|
+
"_unassigned"
|
|
807
|
+
)
|
|
774
808
|
] });
|
|
775
809
|
}
|
|
776
810
|
var ObjectField = ({
|
|
@@ -779,7 +813,8 @@ var ObjectField = ({
|
|
|
779
813
|
fields,
|
|
780
814
|
rowConfig,
|
|
781
815
|
labelPosition = "side",
|
|
782
|
-
size = "sm"
|
|
816
|
+
size = "sm",
|
|
817
|
+
columns = 2
|
|
783
818
|
}) => {
|
|
784
819
|
const grouped = fields.reduce((acc, f) => {
|
|
785
820
|
const key = f.group ?? "_ungrouped";
|
|
@@ -790,7 +825,15 @@ var ObjectField = ({
|
|
|
790
825
|
delete grouped["_ungrouped"];
|
|
791
826
|
const groupedEntries = Object.entries(grouped);
|
|
792
827
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
793
|
-
ungrouped.length > 0 && /* @__PURE__ */ jsx("div", { className: "space-y-4", children: renderRows(
|
|
828
|
+
ungrouped.length > 0 && /* @__PURE__ */ jsx("div", { className: "space-y-4", children: renderRows(
|
|
829
|
+
ungrouped,
|
|
830
|
+
rowConfig,
|
|
831
|
+
name,
|
|
832
|
+
control,
|
|
833
|
+
labelPosition,
|
|
834
|
+
size,
|
|
835
|
+
columns
|
|
836
|
+
) }),
|
|
794
837
|
groupedEntries.length > 0 && /* @__PURE__ */ jsx(
|
|
795
838
|
Accordion,
|
|
796
839
|
{
|
|
@@ -802,7 +845,15 @@ var ObjectField = ({
|
|
|
802
845
|
humanize(group),
|
|
803
846
|
" Settings"
|
|
804
847
|
] }),
|
|
805
|
-
/* @__PURE__ */ jsx(AccordionContent, { className: "px-3 pb-3", children: /* @__PURE__ */ jsx("div", { className: "space-y-4", children: renderRows(
|
|
848
|
+
/* @__PURE__ */ jsx(AccordionContent, { className: "px-3 pb-3", children: /* @__PURE__ */ jsx("div", { className: "space-y-4", children: renderRows(
|
|
849
|
+
gFields,
|
|
850
|
+
rowConfig,
|
|
851
|
+
name,
|
|
852
|
+
control,
|
|
853
|
+
labelPosition,
|
|
854
|
+
size,
|
|
855
|
+
columns
|
|
856
|
+
) }) })
|
|
806
857
|
] }, group))
|
|
807
858
|
}
|
|
808
859
|
)
|