@fuf-stack/uniform 0.4.0 → 0.6.0
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/FieldArray/index.cjs +13 -0
- package/dist/FieldArray/index.cjs.map +1 -0
- package/dist/FieldArray/index.d.cts +8 -0
- package/dist/FieldArray/index.d.ts +8 -0
- package/dist/FieldArray/index.js +13 -0
- package/dist/FieldArray/index.js.map +1 -0
- package/dist/FieldArray-DUvn98Fe.d.cts +27 -0
- package/dist/FieldArray-DUvn98Fe.d.ts +27 -0
- package/dist/Form/index.cjs +2 -2
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.d.cts +2 -2
- package/dist/Form/index.d.ts +2 -2
- package/dist/Form/index.js +1 -1
- package/dist/{Form-Bv0R3QNk.d.cts → Form-nJbG1hNH.d.cts} +1 -1
- package/dist/{Form-Bv0R3QNk.d.ts → Form-nJbG1hNH.d.ts} +1 -1
- package/dist/Grid/index.cjs.map +1 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.cjs.map +1 -1
- package/dist/Input/index.js +2 -2
- package/dist/RadioGroup/index.cjs +13 -0
- package/dist/RadioGroup/index.cjs.map +1 -0
- package/dist/RadioGroup/index.d.cts +7 -0
- package/dist/RadioGroup/index.d.ts +7 -0
- package/dist/RadioGroup/index.js +13 -0
- package/dist/RadioGroup/index.js.map +1 -0
- package/dist/RadioGroup-BU4K9cnS.d.cts +40 -0
- package/dist/RadioGroup-BU4K9cnS.d.ts +40 -0
- package/dist/Select/index.cjs +13 -0
- package/dist/Select/index.cjs.map +1 -0
- package/dist/Select/index.d.cts +8 -0
- package/dist/Select/index.d.ts +8 -0
- package/dist/Select/index.js +13 -0
- package/dist/Select/index.js.map +1 -0
- package/dist/Select-Mp6Y00dT.d.cts +40 -0
- package/dist/Select-Mp6Y00dT.d.ts +40 -0
- package/dist/SubmitButton/index.cjs +2 -2
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.js +1 -1
- package/dist/Switch/index.cjs +13 -0
- package/dist/Switch/index.cjs.map +1 -0
- package/dist/Switch/index.d.cts +7 -0
- package/dist/Switch/index.d.ts +7 -0
- package/dist/Switch/index.js +13 -0
- package/dist/Switch/index.js.map +1 -0
- package/dist/Switch-DmjDKgKs.d.cts +20 -0
- package/dist/Switch-DmjDKgKs.d.ts +20 -0
- package/dist/TextArea/index.cjs +13 -0
- package/dist/TextArea/index.cjs.map +1 -0
- package/dist/TextArea/index.d.cts +8 -0
- package/dist/TextArea/index.d.ts +8 -0
- package/dist/TextArea/index.js +13 -0
- package/dist/TextArea/index.js.map +1 -0
- package/dist/TextArea-B-sKvTkd.d.cts +25 -0
- package/dist/TextArea-B-sKvTkd.d.ts +25 -0
- package/dist/chunk-3K4JQTPQ.js +205 -0
- package/dist/chunk-3K4JQTPQ.js.map +1 -0
- package/dist/chunk-3SSUEUB5.js +81 -0
- package/dist/chunk-3SSUEUB5.js.map +1 -0
- package/dist/chunk-53AGVLUG.cjs +287 -0
- package/dist/chunk-53AGVLUG.cjs.map +1 -0
- package/dist/chunk-57OFVPRD.js +287 -0
- package/dist/chunk-57OFVPRD.js.map +1 -0
- package/dist/chunk-6GN255GP.cjs.map +1 -1
- package/dist/chunk-BBB4FEY6.cjs.map +1 -1
- package/dist/{chunk-OYXZQOGU.js → chunk-BGSQU5EH.js} +4 -4
- package/dist/{chunk-2CKPLOCK.cjs → chunk-FASB7HG3.cjs} +5 -5
- package/dist/chunk-FASB7HG3.cjs.map +1 -0
- package/dist/{chunk-BNTEIMNY.cjs → chunk-JFCOC5TW.cjs} +32 -25
- package/dist/chunk-JFCOC5TW.cjs.map +1 -0
- package/dist/chunk-JR7MAHBR.cjs +81 -0
- package/dist/chunk-JR7MAHBR.cjs.map +1 -0
- package/dist/chunk-KC3PZFGE.js +76 -0
- package/dist/chunk-KC3PZFGE.js.map +1 -0
- package/dist/{chunk-HT3LKDHX.cjs → chunk-KMMS4G7A.cjs} +4 -2
- package/dist/chunk-KMMS4G7A.cjs.map +1 -0
- package/dist/chunk-OSEU4ZUE.cjs +205 -0
- package/dist/chunk-OSEU4ZUE.cjs.map +1 -0
- package/dist/{chunk-5FMJUJ7H.js → chunk-QD6IQL6U.js} +3 -3
- package/dist/{chunk-5FMJUJ7H.js.map → chunk-QD6IQL6U.js.map} +1 -1
- package/dist/chunk-QTL5FREE.cjs.map +1 -1
- package/dist/{chunk-OV5RMSYD.js → chunk-T3CCNJHK.js} +4 -2
- package/dist/chunk-T3CCNJHK.js.map +1 -0
- package/dist/chunk-WNESYY6E.cjs +239 -0
- package/dist/chunk-WNESYY6E.cjs.map +1 -0
- package/dist/chunk-WQRM7G4C.cjs.map +1 -1
- package/dist/chunk-WRYE2CF5.cjs +76 -0
- package/dist/chunk-WRYE2CF5.cjs.map +1 -0
- package/dist/{chunk-AGAYQTFD.cjs → chunk-XJ3JTLXZ.cjs} +3 -3
- package/dist/chunk-XJ3JTLXZ.cjs.map +1 -0
- package/dist/{chunk-KFRKKWZT.js → chunk-Y4CFVCUN.js} +32 -25
- package/dist/chunk-Y4CFVCUN.js.map +1 -0
- package/dist/chunk-YAVU7ZYD.js +239 -0
- package/dist/chunk-YAVU7ZYD.js.map +1 -0
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/index.cjs +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +26 -6
- package/dist/partials/FieldCopyTestIdButton/index.cjs +2 -2
- package/dist/partials/FieldCopyTestIdButton/index.cjs.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.js +1 -1
- package/dist/partials/FieldValidationError/index.cjs.map +1 -1
- package/package.json +44 -19
- package/dist/chunk-2CKPLOCK.cjs.map +0 -1
- package/dist/chunk-AGAYQTFD.cjs.map +0 -1
- package/dist/chunk-BNTEIMNY.cjs.map +0 -1
- package/dist/chunk-HT3LKDHX.cjs.map +0 -1
- package/dist/chunk-KFRKKWZT.js.map +0 -1
- package/dist/chunk-OV5RMSYD.js.map +0 -1
- /package/dist/{chunk-OYXZQOGU.js.map → chunk-BGSQU5EH.js.map} +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkQTL5FREEcjs = require('./chunk-QTL5FREE.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWQRM7G4Ccjs = require('./chunk-WQRM7G4C.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
13
|
+
|
|
14
|
+
// src/FieldArray/FieldArray.tsx
|
|
15
|
+
var _react = require('react');
|
|
16
|
+
var _reacthookform = require('react-hook-form');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _core = require('@dnd-kit/core');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _modifiers = require('@dnd-kit/modifiers');
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _sortable = require('@dnd-kit/sortable');
|
|
33
|
+
var _input = require('@nextui-org/input');
|
|
34
|
+
var _pixels = require('@fuf-stack/pixels');
|
|
35
|
+
|
|
36
|
+
// src/FieldArray/FieldArrayField.tsx
|
|
37
|
+
|
|
38
|
+
var _fa = require('react-icons/fa');
|
|
39
|
+
|
|
40
|
+
var _utilities = require('@dnd-kit/utilities');
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
44
|
+
var FieldArrayField = ({
|
|
45
|
+
children,
|
|
46
|
+
className = void 0,
|
|
47
|
+
field,
|
|
48
|
+
fields,
|
|
49
|
+
hideButtons = [],
|
|
50
|
+
id,
|
|
51
|
+
index,
|
|
52
|
+
insert,
|
|
53
|
+
lastNotDeletable = true,
|
|
54
|
+
move,
|
|
55
|
+
moveField,
|
|
56
|
+
name,
|
|
57
|
+
remove,
|
|
58
|
+
testId = void 0
|
|
59
|
+
}) => {
|
|
60
|
+
const { attributes, listeners, setNodeRef, transform, transition } = _sortable.useSortable.call(void 0, { id });
|
|
61
|
+
const style = {
|
|
62
|
+
transform: _utilities.CSS.Translate.toString(transform),
|
|
63
|
+
transition
|
|
64
|
+
};
|
|
65
|
+
const { getFieldState, register, watch, trigger } = _chunkWQRM7G4Ccjs.useFormContext.call(void 0, );
|
|
66
|
+
const { error, invalid } = getFieldState(`${name}`, void 0);
|
|
67
|
+
const { getHelperWrapperProps, getErrorMessageProps } = _input.useInput.call(void 0, {
|
|
68
|
+
isInvalid: invalid,
|
|
69
|
+
errorMessage: JSON.stringify(error),
|
|
70
|
+
labelPlacement: "inside",
|
|
71
|
+
placeholder: " ",
|
|
72
|
+
classNames: { helperWrapper: "block" }
|
|
73
|
+
});
|
|
74
|
+
register(`${name}.${index}._errors`);
|
|
75
|
+
const formValues = watch();
|
|
76
|
+
_react.useEffect.call(void 0, () => {
|
|
77
|
+
trigger(`${name}.${index}._errors`);
|
|
78
|
+
}, [JSON.stringify(formValues)]);
|
|
79
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "li", { ref: setNodeRef, style, className, children: [
|
|
81
|
+
!hideButtons.includes("move") && !hideButtons.includes("all") && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "mr-6 flex flex-row items-center", children: [
|
|
82
|
+
moveField.includes("drag-drop") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: "mr-2 text-base text-xl",
|
|
86
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0, `${name}_${index}_movebutton`),
|
|
87
|
+
...attributes,
|
|
88
|
+
...listeners,
|
|
89
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaGripLines, {})
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
moveField.includes("button") && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
|
|
93
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
94
|
+
_pixels.Button,
|
|
95
|
+
{
|
|
96
|
+
testId: `${name}.${index}.up`,
|
|
97
|
+
disabled: index === 0,
|
|
98
|
+
onClick: () => move(index, index - 1),
|
|
99
|
+
className: "flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm",
|
|
100
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaAngleUp, {})
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
104
|
+
_pixels.Button,
|
|
105
|
+
{
|
|
106
|
+
testId: `${name}.${index}.down`,
|
|
107
|
+
disabled: index === fields.length - 1,
|
|
108
|
+
onClick: () => move(index, index + 1),
|
|
109
|
+
className: "flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm",
|
|
110
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaAngleDown, {})
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] })
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "w-full", children: [
|
|
116
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "mb-2 flex items-center", children: [
|
|
117
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-grow", "data-testid": testId, children }),
|
|
118
|
+
!hideButtons.includes("remove") && !hideButtons.includes("all") && (lastNotDeletable && fields.length === 1 ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pixels.Button, { onClick: () => remove(index), className: "ml-1", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
119
|
+
"svg",
|
|
120
|
+
{
|
|
121
|
+
className: "h-4 w-4",
|
|
122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
123
|
+
viewBox: "0 0 20 20",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
"aria-hidden": "true",
|
|
126
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
fillRule: "evenodd",
|
|
130
|
+
d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
|
|
131
|
+
clipRule: "evenodd"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
) }))
|
|
136
|
+
] }),
|
|
137
|
+
!hideButtons.includes("insert") && !hideButtons.includes("all") && index !== fields.length - 1 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
138
|
+
_pixels.Button,
|
|
139
|
+
{
|
|
140
|
+
className: "text-xs font-medium",
|
|
141
|
+
testId: `add-harbor-button-${index}`,
|
|
142
|
+
onClick: () => {
|
|
143
|
+
insert(index + 1, {});
|
|
144
|
+
},
|
|
145
|
+
children: "insert"
|
|
146
|
+
}
|
|
147
|
+
) : null
|
|
148
|
+
] }, `rest-${field.id}`)
|
|
149
|
+
] }),
|
|
150
|
+
error && typeof error[index] !== "undefined" && // @ts-expect-error rhf incompatibility
|
|
151
|
+
_optionalChain([error, 'access', _ => _[Number(index)], 'optionalAccess', _2 => _2._errors]) && // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)
|
|
152
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
153
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQTL5FREEcjs.FieldValidationError_default, { error: _optionalChain([error, 'access', _3 => _3[Number(index)], 'optionalAccess', _4 => _4._errors]) }) }) })
|
|
154
|
+
] });
|
|
155
|
+
};
|
|
156
|
+
var FieldArrayField_default = FieldArrayField;
|
|
157
|
+
|
|
158
|
+
// src/FieldArray/FieldArray.tsx
|
|
159
|
+
|
|
160
|
+
var FieldArray = ({
|
|
161
|
+
children,
|
|
162
|
+
hideButtons = [],
|
|
163
|
+
label: _label = void 0,
|
|
164
|
+
lastNotDeletable = true,
|
|
165
|
+
name,
|
|
166
|
+
testId: _testId = void 0,
|
|
167
|
+
moveField = ["button"]
|
|
168
|
+
}) => {
|
|
169
|
+
const { control, getValues, getFieldState, register, trigger, watch } = _chunkWQRM7G4Ccjs.useFormContext.call(void 0, );
|
|
170
|
+
const { fields, append, remove, insert, move } = _reacthookform.useFieldArray.call(void 0, {
|
|
171
|
+
control,
|
|
172
|
+
name
|
|
173
|
+
});
|
|
174
|
+
const { error, testId, invalid, required } = getFieldState(name, _testId);
|
|
175
|
+
register(`${name}._errors`);
|
|
176
|
+
const formValues = watch();
|
|
177
|
+
_react.useEffect.call(void 0, () => {
|
|
178
|
+
trigger(`${name}._errors`);
|
|
179
|
+
}, [JSON.stringify(formValues)]);
|
|
180
|
+
const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } = _input.useInput.call(void 0, {
|
|
181
|
+
isInvalid: invalid,
|
|
182
|
+
isRequired: required,
|
|
183
|
+
errorMessage: JSON.stringify(error),
|
|
184
|
+
label: _label,
|
|
185
|
+
labelPlacement: "inside",
|
|
186
|
+
placeholder: " ",
|
|
187
|
+
classNames: { helperWrapper: "block" }
|
|
188
|
+
});
|
|
189
|
+
if (lastNotDeletable && fields.length === 0) {
|
|
190
|
+
append({});
|
|
191
|
+
}
|
|
192
|
+
const sensors = _core.useSensors.call(void 0,
|
|
193
|
+
_core.useSensor.call(void 0, _core.PointerSensor),
|
|
194
|
+
_core.useSensor.call(void 0, _core.KeyboardSensor)
|
|
195
|
+
);
|
|
196
|
+
const handleDragEnd = (event) => {
|
|
197
|
+
const { active, over } = event;
|
|
198
|
+
if (active.id !== _optionalChain([over, 'optionalAccess', _5 => _5.id])) {
|
|
199
|
+
const oldIndex = fields.findIndex((field) => field.id === active.id);
|
|
200
|
+
const newIndex = fields.findIndex((field) => field.id === _optionalChain([over, 'optionalAccess', _6 => _6.id]));
|
|
201
|
+
move(oldIndex, newIndex);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
205
|
+
_core.DndContext,
|
|
206
|
+
{
|
|
207
|
+
sensors,
|
|
208
|
+
collisionDetection: _core.closestCenter,
|
|
209
|
+
onDragEnd: handleDragEnd,
|
|
210
|
+
modifiers: [_modifiers.restrictToVerticalAxis, _modifiers.restrictToWindowEdges],
|
|
211
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
212
|
+
_sortable.SortableContext,
|
|
213
|
+
{
|
|
214
|
+
items: fields.map((field) => field.id),
|
|
215
|
+
strategy: _sortable.verticalListSortingStrategy,
|
|
216
|
+
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "ul", { "data-testid": testId, children: [
|
|
217
|
+
label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
218
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
219
|
+
"label",
|
|
220
|
+
{
|
|
221
|
+
...getLabelProps(),
|
|
222
|
+
className: `${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`,
|
|
223
|
+
children: label
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKMMS4G7Acjs.FieldCopyTestIdButton_default, { testId }),
|
|
227
|
+
fields.map((field, index) => {
|
|
228
|
+
const duplicate = (i) => {
|
|
229
|
+
const values = getValues(name);
|
|
230
|
+
insert(i + 1, { ...values[i], id: null });
|
|
231
|
+
};
|
|
232
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
233
|
+
FieldArrayField_default,
|
|
234
|
+
{
|
|
235
|
+
id: field.id,
|
|
236
|
+
testId: `${testId}_${index}`,
|
|
237
|
+
className: "mb-3 mt-5 flex flex-row items-center",
|
|
238
|
+
field,
|
|
239
|
+
fields,
|
|
240
|
+
hideButtons,
|
|
241
|
+
index,
|
|
242
|
+
insert,
|
|
243
|
+
lastNotDeletable,
|
|
244
|
+
move,
|
|
245
|
+
moveField,
|
|
246
|
+
name,
|
|
247
|
+
remove,
|
|
248
|
+
children: children(
|
|
249
|
+
`${name}[${index}]`,
|
|
250
|
+
index,
|
|
251
|
+
fields.length,
|
|
252
|
+
move,
|
|
253
|
+
insert,
|
|
254
|
+
remove,
|
|
255
|
+
duplicate
|
|
256
|
+
)
|
|
257
|
+
},
|
|
258
|
+
field.id
|
|
259
|
+
);
|
|
260
|
+
}),
|
|
261
|
+
!hideButtons.includes("add") && !hideButtons.includes("all") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
262
|
+
_pixels.Button,
|
|
263
|
+
{
|
|
264
|
+
testId: `${testId}_append`,
|
|
265
|
+
size: "sm",
|
|
266
|
+
onClick: () => append({}),
|
|
267
|
+
children: "Add"
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
_optionalChain([error, 'optionalAccess', _7 => _7._errors]) && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
271
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQTL5FREEcjs.FieldValidationError_default, { error: _optionalChain([error, 'optionalAccess', _8 => _8._errors]) }) }) })
|
|
272
|
+
] })
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
var FieldArray_default = FieldArray;
|
|
279
|
+
|
|
280
|
+
// src/FieldArray/index.ts
|
|
281
|
+
var FieldArray_default2 = FieldArray_default;
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
exports.FieldArray_default = FieldArray_default; exports.FieldArray_default2 = FieldArray_default2;
|
|
287
|
+
//# sourceMappingURL=chunk-53AGVLUG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-53AGVLUG.cjs","../src/FieldArray/FieldArray.tsx","../src/FieldArray/FieldArrayField.tsx","../src/FieldArray/index.ts"],"names":["jsx","Button"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACLA,8BAA0B;AAC1B,gDAA8B;AAE9B;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,qCACK;AACP;AACE;AACA;AAAA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S,MAAA;AACA,MAAA;AACZ,MAAA;AACzB,IAAA;AACF,EAAA;AAEEA,EAAAA;AAAC,IAAA;AAAA,IAAA;AACC,MAAA;AACoB,MAAA;AACT,MAAA;AACyB,MAAA;AAEpCA,MAAAA;AAAC,QAAA;AAAA,QAAA;AAC8B,UAAA;AACnB,UAAA;AAET,UAAA;AACE,YAAA;AAECA,4BAAAA;AAAC,cAAA;AAAA,cAAA;AAEmB,gBAAA;AACU,gBAAA;AAE3B,gBAAA;AAAA,cAAA;AACH,YAAA;AAED,4BAAA;AAE6B,YAAA;AACK,cAAA;AACN,gBAAA;AACE,gBAAA;AAC7B,cAAA;AAGEA,cAAAA;AAAC,gBAAA;AAAA,gBAAA;AACW,kBAAA;AAEgB,kBAAA;AAChB,kBAAA;AACV,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AACA,kBAAA;AAEC,kBAAA;AACiB,oBAAA;AAChB,oBAAA;AACO,oBAAA;AACP,oBAAA;AACA,oBAAA;AACA,oBAAA;AACA,oBAAA;AACF,kBAAA;AAAA,gBAAA;AAtBW,gBAAA;AAuBb,cAAA;AAEH,YAAA;AAEgC,YAAA;AAC9BC,cAAAA;AAAA,cAAA;AACkB,gBAAA;AACZ,gBAAA;AACmB,gBAAA;AACzB,gBAAA;AAAA,cAAA;AAED,YAAA;AAGM,4BAAA;AAEA,4BAAA;AAQV,UAAA;AAAA,QAAA;AACF,MAAA;AAAA,IAAA;AACF,EAAA;AAEJ;AAEe;ADiE6B;AACA;AG7Q7B;AH+Q6B;AACA;AACA;AACA;AACA","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-53AGVLUG.cjs","sourcesContent":[null,"import type { DragEndEvent } from '@dnd-kit/core';\nimport type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useFieldArray } from 'react-hook-form';\n\nimport {\n closestCenter,\n DndContext,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport {\n restrictToVerticalAxis,\n restrictToWindowEdges,\n} from '@dnd-kit/modifiers';\nimport {\n SortableContext,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\nimport FieldArrayField from './FieldArrayField';\n\nexport type FieldArrayHideOption = 'add' | 'remove' | 'move' | 'insert' | 'all';\nexport type FieldArrayFieldChildren = (\n name: string,\n index: number,\n length: number,\n move: UseFieldArrayMove,\n insert: UseFieldArrayInsert<FieldValues, string>,\n remove: UseFieldArrayRemove,\n duplicate: (i: number) => void,\n) => JSX.Element;\n\nexport type MoveField = 'drag-drop' | 'button';\n\nexport interface FieldArrayProps {\n /** function that renders the children with provided Properties. */\n children: FieldArrayFieldChildren;\n /** Hide a set of buttons. */\n hideButtons?: FieldArrayHideOption[];\n /** label of the FieldArray. */\n label?: React.ReactNode;\n /** stops user from deleting all items. */\n lastNotDeletable?: boolean;\n /** name the FieldArray is registered in RHF */\n name: string;\n /** ID for test purposes. */\n testId?: string;\n /* how the fields can be moved */\n moveField: MoveField[];\n}\n\n/**\n * FieldArray component using react-hook-form\n */\nconst FieldArray = ({\n children,\n hideButtons = [],\n label: _label = undefined,\n lastNotDeletable = true,\n name,\n testId: _testId = undefined,\n moveField = ['button'],\n}: FieldArrayProps) => {\n const { control, getValues, getFieldState, register, trigger, watch } =\n useFormContext();\n\n const { fields, append, remove, insert, move } = useFieldArray({\n control,\n name,\n });\n\n const { error, testId, invalid, required } = getFieldState(name, _testId);\n\n register(`${name}._errors`);\n\n const formValues = watch();\n\n useEffect(() => {\n trigger(`${name}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n // TODO: what about input props?\n const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } =\n useInput({\n isInvalid: invalid,\n isRequired: required,\n errorMessage: JSON.stringify(error),\n label: _label,\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n if (lastNotDeletable && fields.length === 0) {\n append({});\n }\n\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor),\n );\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (active.id !== over?.id) {\n const oldIndex = fields.findIndex((field) => field.id === active.id);\n const newIndex = fields.findIndex((field) => field.id === over?.id);\n move(oldIndex, newIndex);\n }\n };\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragEnd={handleDragEnd}\n modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}\n >\n <SortableContext\n items={fields.map((field) => field.id)}\n strategy={verticalListSortingStrategy}\n >\n <ul data-testid={testId}>\n {label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getLabelProps()}\n className={`${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`}\n >\n {label}\n </label>\n )}\n <FieldCopyTestIdButton testId={testId} />\n\n {fields.map((field, index) => {\n const duplicate = (i: number) => {\n const values = getValues(name);\n insert(i + 1, { ...values[i], id: null });\n };\n\n return (\n <FieldArrayField\n id={field.id}\n key={field.id}\n testId={`${testId}_${index}`}\n className=\"mb-3 mt-5 flex flex-row items-center\"\n field={field}\n fields={fields}\n hideButtons={hideButtons}\n index={index}\n insert={insert}\n lastNotDeletable={lastNotDeletable}\n move={move}\n moveField={moveField}\n name={name}\n remove={remove}\n >\n {children(\n `${name}[${index}]`,\n index,\n fields.length,\n move,\n insert,\n remove,\n duplicate,\n )}\n </FieldArrayField>\n );\n })}\n\n {!hideButtons.includes('add') && !hideButtons.includes('all') && (\n <Button\n testId={`${testId}_append`}\n size=\"sm\"\n onClick={() => append({})}\n >\n Add\n </Button>\n )}\n {/* @ts-expect-error rhf incompatibility */}\n {error?._errors && (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error?._errors} />\n </div>\n </div>\n )}\n </ul>\n </SortableContext>\n </DndContext>\n );\n};\n\nexport default FieldArray;\n","import type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\nimport type { FieldArrayHideOption, MoveField } from './FieldArray';\n\nimport { useEffect } from 'react';\nimport { FaAngleDown, FaAngleUp, FaGripLines } from 'react-icons/fa';\n\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\ninterface FieldArrayFieldProps {\n children: React.ReactNode;\n className?: string;\n field: Record<'id', string>;\n fields: Record<'id', string>[];\n hideButtons?: FieldArrayHideOption[];\n id: string | number;\n index: number;\n insert: UseFieldArrayInsert<FieldValues, string>;\n lastNotDeletable?: boolean;\n move: UseFieldArrayMove;\n moveField: MoveField[];\n testId?: string;\n name: string;\n remove: UseFieldArrayRemove;\n}\n\n/**\n * FieldArrayField component using react-hook-form\n */\nconst FieldArrayField = ({\n children,\n className = undefined,\n field,\n fields,\n hideButtons = [],\n id,\n index,\n insert,\n lastNotDeletable = true,\n move,\n moveField,\n name,\n remove,\n testId = undefined,\n}: FieldArrayFieldProps) => {\n const { attributes, listeners, setNodeRef, transform, transition } =\n useSortable({ id });\n\n const style = {\n transform: CSS.Translate.toString(transform),\n transition,\n };\n\n const { getFieldState, register, watch, trigger } = useFormContext();\n const { error, invalid } = getFieldState(`${name}`, undefined);\n\n // TODO: what about input props? and label props? Do we need a label?\n const { getHelperWrapperProps, getErrorMessageProps } = useInput({\n isInvalid: invalid,\n errorMessage: JSON.stringify(error),\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n // TODO: Check if this is a current issue: _error gets kicked out of the formValidation if no other errors exist. validationError exists, but the structure changes.\n register(`${name}.${index}._errors`);\n\n const formValues = watch();\n useEffect(() => {\n trigger(`${name}.${index}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n return (\n <>\n <li ref={setNodeRef} style={style} className={className}>\n {/** Start Button up/down */}\n {!hideButtons.includes('move') && !hideButtons.includes('all') && (\n <div className=\"mr-6 flex flex-row items-center\">\n {moveField.includes('drag-drop') && (\n <div\n className=\"mr-2 text-base text-xl\"\n data-testid={slugify(`${name}_${index}_movebutton`)}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...attributes}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...listeners}\n >\n <FaGripLines />\n </div>\n )}\n {moveField.includes('button') && (\n <div className=\"flex flex-col\">\n <Button\n testId={`${name}.${index}.up`}\n disabled={index === 0}\n onClick={() => move(index, index - 1)}\n className=\"flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleUp />\n </Button>\n <Button\n testId={`${name}.${index}.down`}\n disabled={index === fields.length - 1}\n onClick={() => move(index, index + 1)}\n className=\"flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleDown />\n </Button>\n </div>\n )}\n </div>\n )}\n {/** End Button up/down */}\n <div key={`rest-${field.id}`} className=\"w-full\">\n <div className=\"mb-2 flex items-center\">\n {/** RENDER CHILDREN */}\n <div className=\"flex-grow\" data-testid={testId}>\n {children}\n </div>\n {!hideButtons.includes('remove') &&\n !hideButtons.includes('all') &&\n (lastNotDeletable && fields.length === 1 ? null : (\n <Button onClick={() => remove(index)} className=\"ml-1\">\n <svg\n className=\"h-4 w-4\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n aria-hidden=\"true\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z\"\n clipRule=\"evenodd\"\n />\n </svg>\n </Button>\n ))}\n </div>\n\n {!hideButtons.includes('insert') &&\n !hideButtons.includes('all') &&\n index !== fields.length - 1 ? (\n <Button\n className=\"text-xs font-medium\"\n testId={`add-harbor-button-${index}`}\n onClick={() => {\n insert(index + 1, {});\n }}\n >\n insert\n </Button>\n ) : null}\n </div>\n </li>\n {error &&\n typeof error[index] !== 'undefined' &&\n // @ts-expect-error rhf incompatibility\n error[Number(index)]?._errors && ( // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error[Number(index)]?._errors} />\n </div>\n </div>\n )}\n </>\n );\n};\nexport default FieldArrayField;\n","import FieldArray from './FieldArray';\n\nexport type {\n FieldArrayProps,\n FieldArrayHideOption,\n FieldArrayFieldChildren,\n} from './FieldArray';\n\nexport { FieldArray };\n\nexport default FieldArray;\n"]}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-T3CCNJHK.js";
|
|
4
|
+
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-DBLODROX.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-BCMPSLSG.js";
|
|
10
|
+
import {
|
|
11
|
+
slugify
|
|
12
|
+
} from "./chunk-V46BHM2U.js";
|
|
13
|
+
|
|
14
|
+
// src/FieldArray/FieldArray.tsx
|
|
15
|
+
import { useEffect as useEffect2 } from "react";
|
|
16
|
+
import { useFieldArray } from "react-hook-form";
|
|
17
|
+
import {
|
|
18
|
+
closestCenter,
|
|
19
|
+
DndContext,
|
|
20
|
+
KeyboardSensor,
|
|
21
|
+
PointerSensor,
|
|
22
|
+
useSensor,
|
|
23
|
+
useSensors
|
|
24
|
+
} from "@dnd-kit/core";
|
|
25
|
+
import {
|
|
26
|
+
restrictToVerticalAxis,
|
|
27
|
+
restrictToWindowEdges
|
|
28
|
+
} from "@dnd-kit/modifiers";
|
|
29
|
+
import {
|
|
30
|
+
SortableContext,
|
|
31
|
+
verticalListSortingStrategy
|
|
32
|
+
} from "@dnd-kit/sortable";
|
|
33
|
+
import { useInput as useInput2 } from "@nextui-org/input";
|
|
34
|
+
import { Button as Button2 } from "@fuf-stack/pixels";
|
|
35
|
+
|
|
36
|
+
// src/FieldArray/FieldArrayField.tsx
|
|
37
|
+
import { useEffect } from "react";
|
|
38
|
+
import { FaAngleDown, FaAngleUp, FaGripLines } from "react-icons/fa";
|
|
39
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
40
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
41
|
+
import { useInput } from "@nextui-org/input";
|
|
42
|
+
import { Button } from "@fuf-stack/pixels";
|
|
43
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
44
|
+
var FieldArrayField = ({
|
|
45
|
+
children,
|
|
46
|
+
className = void 0,
|
|
47
|
+
field,
|
|
48
|
+
fields,
|
|
49
|
+
hideButtons = [],
|
|
50
|
+
id,
|
|
51
|
+
index,
|
|
52
|
+
insert,
|
|
53
|
+
lastNotDeletable = true,
|
|
54
|
+
move,
|
|
55
|
+
moveField,
|
|
56
|
+
name,
|
|
57
|
+
remove,
|
|
58
|
+
testId = void 0
|
|
59
|
+
}) => {
|
|
60
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
|
|
61
|
+
const style = {
|
|
62
|
+
transform: CSS.Translate.toString(transform),
|
|
63
|
+
transition
|
|
64
|
+
};
|
|
65
|
+
const { getFieldState, register, watch, trigger } = useFormContext();
|
|
66
|
+
const { error, invalid } = getFieldState(`${name}`, void 0);
|
|
67
|
+
const { getHelperWrapperProps, getErrorMessageProps } = useInput({
|
|
68
|
+
isInvalid: invalid,
|
|
69
|
+
errorMessage: JSON.stringify(error),
|
|
70
|
+
labelPlacement: "inside",
|
|
71
|
+
placeholder: " ",
|
|
72
|
+
classNames: { helperWrapper: "block" }
|
|
73
|
+
});
|
|
74
|
+
register(`${name}.${index}._errors`);
|
|
75
|
+
const formValues = watch();
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
trigger(`${name}.${index}._errors`);
|
|
78
|
+
}, [JSON.stringify(formValues)]);
|
|
79
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsxs("li", { ref: setNodeRef, style, className, children: [
|
|
81
|
+
!hideButtons.includes("move") && !hideButtons.includes("all") && /* @__PURE__ */ jsxs("div", { className: "mr-6 flex flex-row items-center", children: [
|
|
82
|
+
moveField.includes("drag-drop") && /* @__PURE__ */ jsx(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: "mr-2 text-base text-xl",
|
|
86
|
+
"data-testid": slugify(`${name}_${index}_movebutton`),
|
|
87
|
+
...attributes,
|
|
88
|
+
...listeners,
|
|
89
|
+
children: /* @__PURE__ */ jsx(FaGripLines, {})
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
moveField.includes("button") && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Button,
|
|
95
|
+
{
|
|
96
|
+
testId: `${name}.${index}.up`,
|
|
97
|
+
disabled: index === 0,
|
|
98
|
+
onClick: () => move(index, index - 1),
|
|
99
|
+
className: "flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm",
|
|
100
|
+
children: /* @__PURE__ */ jsx(FaAngleUp, {})
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
Button,
|
|
105
|
+
{
|
|
106
|
+
testId: `${name}.${index}.down`,
|
|
107
|
+
disabled: index === fields.length - 1,
|
|
108
|
+
onClick: () => move(index, index + 1),
|
|
109
|
+
className: "flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm",
|
|
110
|
+
children: /* @__PURE__ */ jsx(FaAngleDown, {})
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] })
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
116
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center", children: [
|
|
117
|
+
/* @__PURE__ */ jsx("div", { className: "flex-grow", "data-testid": testId, children }),
|
|
118
|
+
!hideButtons.includes("remove") && !hideButtons.includes("all") && (lastNotDeletable && fields.length === 1 ? null : /* @__PURE__ */ jsx(Button, { onClick: () => remove(index), className: "ml-1", children: /* @__PURE__ */ jsx(
|
|
119
|
+
"svg",
|
|
120
|
+
{
|
|
121
|
+
className: "h-4 w-4",
|
|
122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
123
|
+
viewBox: "0 0 20 20",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
"aria-hidden": "true",
|
|
126
|
+
children: /* @__PURE__ */ jsx(
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
fillRule: "evenodd",
|
|
130
|
+
d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
|
|
131
|
+
clipRule: "evenodd"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
) }))
|
|
136
|
+
] }),
|
|
137
|
+
!hideButtons.includes("insert") && !hideButtons.includes("all") && index !== fields.length - 1 ? /* @__PURE__ */ jsx(
|
|
138
|
+
Button,
|
|
139
|
+
{
|
|
140
|
+
className: "text-xs font-medium",
|
|
141
|
+
testId: `add-harbor-button-${index}`,
|
|
142
|
+
onClick: () => {
|
|
143
|
+
insert(index + 1, {});
|
|
144
|
+
},
|
|
145
|
+
children: "insert"
|
|
146
|
+
}
|
|
147
|
+
) : null
|
|
148
|
+
] }, `rest-${field.id}`)
|
|
149
|
+
] }),
|
|
150
|
+
error && typeof error[index] !== "undefined" && // @ts-expect-error rhf incompatibility
|
|
151
|
+
error[Number(index)]?._errors && // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)
|
|
152
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
153
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error: error[Number(index)]?._errors }) }) })
|
|
154
|
+
] });
|
|
155
|
+
};
|
|
156
|
+
var FieldArrayField_default = FieldArrayField;
|
|
157
|
+
|
|
158
|
+
// src/FieldArray/FieldArray.tsx
|
|
159
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
160
|
+
var FieldArray = ({
|
|
161
|
+
children,
|
|
162
|
+
hideButtons = [],
|
|
163
|
+
label: _label = void 0,
|
|
164
|
+
lastNotDeletable = true,
|
|
165
|
+
name,
|
|
166
|
+
testId: _testId = void 0,
|
|
167
|
+
moveField = ["button"]
|
|
168
|
+
}) => {
|
|
169
|
+
const { control, getValues, getFieldState, register, trigger, watch } = useFormContext();
|
|
170
|
+
const { fields, append, remove, insert, move } = useFieldArray({
|
|
171
|
+
control,
|
|
172
|
+
name
|
|
173
|
+
});
|
|
174
|
+
const { error, testId, invalid, required } = getFieldState(name, _testId);
|
|
175
|
+
register(`${name}._errors`);
|
|
176
|
+
const formValues = watch();
|
|
177
|
+
useEffect2(() => {
|
|
178
|
+
trigger(`${name}._errors`);
|
|
179
|
+
}, [JSON.stringify(formValues)]);
|
|
180
|
+
const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } = useInput2({
|
|
181
|
+
isInvalid: invalid,
|
|
182
|
+
isRequired: required,
|
|
183
|
+
errorMessage: JSON.stringify(error),
|
|
184
|
+
label: _label,
|
|
185
|
+
labelPlacement: "inside",
|
|
186
|
+
placeholder: " ",
|
|
187
|
+
classNames: { helperWrapper: "block" }
|
|
188
|
+
});
|
|
189
|
+
if (lastNotDeletable && fields.length === 0) {
|
|
190
|
+
append({});
|
|
191
|
+
}
|
|
192
|
+
const sensors = useSensors(
|
|
193
|
+
useSensor(PointerSensor),
|
|
194
|
+
useSensor(KeyboardSensor)
|
|
195
|
+
);
|
|
196
|
+
const handleDragEnd = (event) => {
|
|
197
|
+
const { active, over } = event;
|
|
198
|
+
if (active.id !== over?.id) {
|
|
199
|
+
const oldIndex = fields.findIndex((field) => field.id === active.id);
|
|
200
|
+
const newIndex = fields.findIndex((field) => field.id === over?.id);
|
|
201
|
+
move(oldIndex, newIndex);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ jsx2(
|
|
205
|
+
DndContext,
|
|
206
|
+
{
|
|
207
|
+
sensors,
|
|
208
|
+
collisionDetection: closestCenter,
|
|
209
|
+
onDragEnd: handleDragEnd,
|
|
210
|
+
modifiers: [restrictToVerticalAxis, restrictToWindowEdges],
|
|
211
|
+
children: /* @__PURE__ */ jsx2(
|
|
212
|
+
SortableContext,
|
|
213
|
+
{
|
|
214
|
+
items: fields.map((field) => field.id),
|
|
215
|
+
strategy: verticalListSortingStrategy,
|
|
216
|
+
children: /* @__PURE__ */ jsxs2("ul", { "data-testid": testId, children: [
|
|
217
|
+
label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
218
|
+
/* @__PURE__ */ jsx2(
|
|
219
|
+
"label",
|
|
220
|
+
{
|
|
221
|
+
...getLabelProps(),
|
|
222
|
+
className: `${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`,
|
|
223
|
+
children: label
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsx2(FieldCopyTestIdButton_default, { testId }),
|
|
227
|
+
fields.map((field, index) => {
|
|
228
|
+
const duplicate = (i) => {
|
|
229
|
+
const values = getValues(name);
|
|
230
|
+
insert(i + 1, { ...values[i], id: null });
|
|
231
|
+
};
|
|
232
|
+
return /* @__PURE__ */ jsx2(
|
|
233
|
+
FieldArrayField_default,
|
|
234
|
+
{
|
|
235
|
+
id: field.id,
|
|
236
|
+
testId: `${testId}_${index}`,
|
|
237
|
+
className: "mb-3 mt-5 flex flex-row items-center",
|
|
238
|
+
field,
|
|
239
|
+
fields,
|
|
240
|
+
hideButtons,
|
|
241
|
+
index,
|
|
242
|
+
insert,
|
|
243
|
+
lastNotDeletable,
|
|
244
|
+
move,
|
|
245
|
+
moveField,
|
|
246
|
+
name,
|
|
247
|
+
remove,
|
|
248
|
+
children: children(
|
|
249
|
+
`${name}[${index}]`,
|
|
250
|
+
index,
|
|
251
|
+
fields.length,
|
|
252
|
+
move,
|
|
253
|
+
insert,
|
|
254
|
+
remove,
|
|
255
|
+
duplicate
|
|
256
|
+
)
|
|
257
|
+
},
|
|
258
|
+
field.id
|
|
259
|
+
);
|
|
260
|
+
}),
|
|
261
|
+
!hideButtons.includes("add") && !hideButtons.includes("all") && /* @__PURE__ */ jsx2(
|
|
262
|
+
Button2,
|
|
263
|
+
{
|
|
264
|
+
testId: `${testId}_append`,
|
|
265
|
+
size: "sm",
|
|
266
|
+
onClick: () => append({}),
|
|
267
|
+
children: "Add"
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
error?._errors && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
271
|
+
/* @__PURE__ */ jsx2("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx2("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx2(FieldValidationError_default, { error: error?._errors }) }) })
|
|
272
|
+
] })
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
var FieldArray_default = FieldArray;
|
|
279
|
+
|
|
280
|
+
// src/FieldArray/index.ts
|
|
281
|
+
var FieldArray_default2 = FieldArray_default;
|
|
282
|
+
|
|
283
|
+
export {
|
|
284
|
+
FieldArray_default,
|
|
285
|
+
FieldArray_default2
|
|
286
|
+
};
|
|
287
|
+
//# sourceMappingURL=chunk-57OFVPRD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/FieldArray/FieldArray.tsx","../src/FieldArray/FieldArrayField.tsx","../src/FieldArray/index.ts"],"sourcesContent":["import type { DragEndEvent } from '@dnd-kit/core';\nimport type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useFieldArray } from 'react-hook-form';\n\nimport {\n closestCenter,\n DndContext,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport {\n restrictToVerticalAxis,\n restrictToWindowEdges,\n} from '@dnd-kit/modifiers';\nimport {\n SortableContext,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\nimport FieldArrayField from './FieldArrayField';\n\nexport type FieldArrayHideOption = 'add' | 'remove' | 'move' | 'insert' | 'all';\nexport type FieldArrayFieldChildren = (\n name: string,\n index: number,\n length: number,\n move: UseFieldArrayMove,\n insert: UseFieldArrayInsert<FieldValues, string>,\n remove: UseFieldArrayRemove,\n duplicate: (i: number) => void,\n) => JSX.Element;\n\nexport type MoveField = 'drag-drop' | 'button';\n\nexport interface FieldArrayProps {\n /** function that renders the children with provided Properties. */\n children: FieldArrayFieldChildren;\n /** Hide a set of buttons. */\n hideButtons?: FieldArrayHideOption[];\n /** label of the FieldArray. */\n label?: React.ReactNode;\n /** stops user from deleting all items. */\n lastNotDeletable?: boolean;\n /** name the FieldArray is registered in RHF */\n name: string;\n /** ID for test purposes. */\n testId?: string;\n /* how the fields can be moved */\n moveField: MoveField[];\n}\n\n/**\n * FieldArray component using react-hook-form\n */\nconst FieldArray = ({\n children,\n hideButtons = [],\n label: _label = undefined,\n lastNotDeletable = true,\n name,\n testId: _testId = undefined,\n moveField = ['button'],\n}: FieldArrayProps) => {\n const { control, getValues, getFieldState, register, trigger, watch } =\n useFormContext();\n\n const { fields, append, remove, insert, move } = useFieldArray({\n control,\n name,\n });\n\n const { error, testId, invalid, required } = getFieldState(name, _testId);\n\n register(`${name}._errors`);\n\n const formValues = watch();\n\n useEffect(() => {\n trigger(`${name}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n // TODO: what about input props?\n const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } =\n useInput({\n isInvalid: invalid,\n isRequired: required,\n errorMessage: JSON.stringify(error),\n label: _label,\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n if (lastNotDeletable && fields.length === 0) {\n append({});\n }\n\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor),\n );\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (active.id !== over?.id) {\n const oldIndex = fields.findIndex((field) => field.id === active.id);\n const newIndex = fields.findIndex((field) => field.id === over?.id);\n move(oldIndex, newIndex);\n }\n };\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragEnd={handleDragEnd}\n modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}\n >\n <SortableContext\n items={fields.map((field) => field.id)}\n strategy={verticalListSortingStrategy}\n >\n <ul data-testid={testId}>\n {label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getLabelProps()}\n className={`${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`}\n >\n {label}\n </label>\n )}\n <FieldCopyTestIdButton testId={testId} />\n\n {fields.map((field, index) => {\n const duplicate = (i: number) => {\n const values = getValues(name);\n insert(i + 1, { ...values[i], id: null });\n };\n\n return (\n <FieldArrayField\n id={field.id}\n key={field.id}\n testId={`${testId}_${index}`}\n className=\"mb-3 mt-5 flex flex-row items-center\"\n field={field}\n fields={fields}\n hideButtons={hideButtons}\n index={index}\n insert={insert}\n lastNotDeletable={lastNotDeletable}\n move={move}\n moveField={moveField}\n name={name}\n remove={remove}\n >\n {children(\n `${name}[${index}]`,\n index,\n fields.length,\n move,\n insert,\n remove,\n duplicate,\n )}\n </FieldArrayField>\n );\n })}\n\n {!hideButtons.includes('add') && !hideButtons.includes('all') && (\n <Button\n testId={`${testId}_append`}\n size=\"sm\"\n onClick={() => append({})}\n >\n Add\n </Button>\n )}\n {/* @ts-expect-error rhf incompatibility */}\n {error?._errors && (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error?._errors} />\n </div>\n </div>\n )}\n </ul>\n </SortableContext>\n </DndContext>\n );\n};\n\nexport default FieldArray;\n","import type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\nimport type { FieldArrayHideOption, MoveField } from './FieldArray';\n\nimport { useEffect } from 'react';\nimport { FaAngleDown, FaAngleUp, FaGripLines } from 'react-icons/fa';\n\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\ninterface FieldArrayFieldProps {\n children: React.ReactNode;\n className?: string;\n field: Record<'id', string>;\n fields: Record<'id', string>[];\n hideButtons?: FieldArrayHideOption[];\n id: string | number;\n index: number;\n insert: UseFieldArrayInsert<FieldValues, string>;\n lastNotDeletable?: boolean;\n move: UseFieldArrayMove;\n moveField: MoveField[];\n testId?: string;\n name: string;\n remove: UseFieldArrayRemove;\n}\n\n/**\n * FieldArrayField component using react-hook-form\n */\nconst FieldArrayField = ({\n children,\n className = undefined,\n field,\n fields,\n hideButtons = [],\n id,\n index,\n insert,\n lastNotDeletable = true,\n move,\n moveField,\n name,\n remove,\n testId = undefined,\n}: FieldArrayFieldProps) => {\n const { attributes, listeners, setNodeRef, transform, transition } =\n useSortable({ id });\n\n const style = {\n transform: CSS.Translate.toString(transform),\n transition,\n };\n\n const { getFieldState, register, watch, trigger } = useFormContext();\n const { error, invalid } = getFieldState(`${name}`, undefined);\n\n // TODO: what about input props? and label props? Do we need a label?\n const { getHelperWrapperProps, getErrorMessageProps } = useInput({\n isInvalid: invalid,\n errorMessage: JSON.stringify(error),\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n // TODO: Check if this is a current issue: _error gets kicked out of the formValidation if no other errors exist. validationError exists, but the structure changes.\n register(`${name}.${index}._errors`);\n\n const formValues = watch();\n useEffect(() => {\n trigger(`${name}.${index}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n return (\n <>\n <li ref={setNodeRef} style={style} className={className}>\n {/** Start Button up/down */}\n {!hideButtons.includes('move') && !hideButtons.includes('all') && (\n <div className=\"mr-6 flex flex-row items-center\">\n {moveField.includes('drag-drop') && (\n <div\n className=\"mr-2 text-base text-xl\"\n data-testid={slugify(`${name}_${index}_movebutton`)}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...attributes}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...listeners}\n >\n <FaGripLines />\n </div>\n )}\n {moveField.includes('button') && (\n <div className=\"flex flex-col\">\n <Button\n testId={`${name}.${index}.up`}\n disabled={index === 0}\n onClick={() => move(index, index - 1)}\n className=\"flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleUp />\n </Button>\n <Button\n testId={`${name}.${index}.down`}\n disabled={index === fields.length - 1}\n onClick={() => move(index, index + 1)}\n className=\"flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleDown />\n </Button>\n </div>\n )}\n </div>\n )}\n {/** End Button up/down */}\n <div key={`rest-${field.id}`} className=\"w-full\">\n <div className=\"mb-2 flex items-center\">\n {/** RENDER CHILDREN */}\n <div className=\"flex-grow\" data-testid={testId}>\n {children}\n </div>\n {!hideButtons.includes('remove') &&\n !hideButtons.includes('all') &&\n (lastNotDeletable && fields.length === 1 ? null : (\n <Button onClick={() => remove(index)} className=\"ml-1\">\n <svg\n className=\"h-4 w-4\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n aria-hidden=\"true\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z\"\n clipRule=\"evenodd\"\n />\n </svg>\n </Button>\n ))}\n </div>\n\n {!hideButtons.includes('insert') &&\n !hideButtons.includes('all') &&\n index !== fields.length - 1 ? (\n <Button\n className=\"text-xs font-medium\"\n testId={`add-harbor-button-${index}`}\n onClick={() => {\n insert(index + 1, {});\n }}\n >\n insert\n </Button>\n ) : null}\n </div>\n </li>\n {error &&\n typeof error[index] !== 'undefined' &&\n // @ts-expect-error rhf incompatibility\n error[Number(index)]?._errors && ( // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error[Number(index)]?._errors} />\n </div>\n </div>\n )}\n </>\n );\n};\nexport default FieldArrayField;\n","import FieldArray from './FieldArray';\n\nexport type {\n FieldArrayProps,\n FieldArrayHideOption,\n FieldArrayFieldChildren,\n} from './FieldArray';\n\nexport { FieldArray };\n\nexport default FieldArray;\n"],"mappings":";;;;;;;;;;;;;;AAQA,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAAC,iBAAgB;AAEzB,SAAS,UAAAC,eAAc;;;ACrBvB,SAAS,iBAAiB;AAC1B,SAAS,aAAa,WAAW,mBAAmB;AAEpD,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAAS,gBAAgB;AAEzB,SAAS,cAAc;AAwEnB,mBAcY,KAIF,YAlBV;AA9CJ,IAAM,kBAAkB,CAAC;AAAA,EACvB;AAAA,EACA,YAAY;AAAA,E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