@openzeppelin/ui-components 1.0.0 → 1.0.2
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/ErrorMessage-D4BAP8iw.cjs +281 -0
- package/dist/ErrorMessage-D4BAP8iw.cjs.map +1 -0
- package/dist/ErrorMessage-DyO9ZWWz.js +170 -0
- package/dist/ErrorMessage-DyO9ZWWz.js.map +1 -0
- package/dist/code-editor-BKEEXGxt.d.cts +122 -0
- package/dist/code-editor-BKEEXGxt.d.cts.map +1 -0
- package/dist/code-editor-CxxSe1o8.d.ts +122 -0
- package/dist/code-editor-CxxSe1o8.d.ts.map +1 -0
- package/dist/code-editor.cjs +132 -0
- package/dist/code-editor.cjs.map +1 -0
- package/dist/code-editor.d.cts +122 -0
- package/dist/code-editor.d.ts +122 -0
- package/dist/code-editor.js +129 -0
- package/dist/code-editor.js.map +1 -0
- package/dist/{index-CrEkH28U.d.cts → index-DDdy06qO.d.ts} +8 -124
- package/dist/index-DDdy06qO.d.ts.map +1 -0
- package/dist/{index-CYn57Ffl.d.ts → index-DfQJGBqH.d.cts} +13 -129
- package/dist/index-DfQJGBqH.d.cts.map +1 -0
- package/dist/index.cjs +268 -584
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -121
- package/dist/index.d.ts +11 -127
- package/dist/index.js +196 -482
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
- package/dist/index-CYn57Ffl.d.ts.map +0 -1
- package/dist/index-CrEkH28U.d.cts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { a as getValidationStateClasses, c as isDuplicateMapKey, d as INTEGER_HTML_PATTERN, f as INTEGER_INPUT_PATTERN, i as getErrorMessage, l as validateField, n as createValidationResult, o as handleValidationError, p as INTEGER_PATTERN, r as formatValidationError, s as hasFieldError, t as ErrorMessage, u as validateMapEntries } from "./ErrorMessage-DyO9ZWWz.js";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { Controller, FormProvider, useFieldArray, useFormContext, useWatch } from "react-hook-form";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
1
6
|
import * as AccordionPrimitive from "@radix-ui/react-accordion";
|
|
2
7
|
import { cva } from "class-variance-authority";
|
|
3
8
|
import { AlertCircle, Calendar as Calendar$1, Check, CheckCircle, CheckCircle2, CheckIcon, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Circle, Copy, DollarSign, ExternalLink as ExternalLink$1, ExternalLinkIcon, Eye, EyeOff, File, FileText, GripVertical, Hash, Info, Loader2, Menu, Network, Plus, Search, Timer, Upload, X } from "lucide-react";
|
|
4
|
-
import * as React$1 from "react";
|
|
5
|
-
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
9
|
import { cn, getDefaultValueForType, getInvalidUrlMessage, isValidUrl, truncateMiddle, validateBytesSimple } from "@openzeppelin/ui-utils";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
10
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
9
11
|
import { DayPicker } from "react-day-picker";
|
|
10
12
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
@@ -12,19 +14,205 @@ import { format } from "date-fns";
|
|
|
12
14
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
13
15
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
14
16
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
15
|
-
import { Controller, FormProvider, useFieldArray, useFormContext, useWatch } from "react-hook-form";
|
|
16
17
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
17
18
|
import * as ProgressPrimitive from "@radix-ui/react-progress";
|
|
18
19
|
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
|
|
19
20
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
|
20
21
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
21
22
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
22
|
-
import CodeEditor from "@uiw/react-textarea-code-editor";
|
|
23
|
-
import CodeEditorNoHighlight from "@uiw/react-textarea-code-editor/nohighlight";
|
|
24
23
|
import { isMapEntryArray } from "@openzeppelin/ui-types";
|
|
25
24
|
import { Toaster as Toaster$1, toast } from "sonner";
|
|
26
25
|
import { useTheme } from "next-themes";
|
|
27
26
|
|
|
27
|
+
//#region src/components/fields/utils/accessibility.ts
|
|
28
|
+
/**
|
|
29
|
+
* Accessibility utilities for form field components
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Default aria-describedby ID generator based on field ID
|
|
33
|
+
*/
|
|
34
|
+
function getDescribedById(id, type = "error") {
|
|
35
|
+
return `${id}-${type}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generates accessibility attributes for form fields
|
|
39
|
+
*/
|
|
40
|
+
function getAccessibilityProps({ id, hasError = false, isRequired = false, isDisabled = false, isReadOnly = false, hasHelperText = false, hasCharacterCounter = false }) {
|
|
41
|
+
const describedByIds = [];
|
|
42
|
+
if (hasError) describedByIds.push(getDescribedById(id, "error"));
|
|
43
|
+
if (hasHelperText) describedByIds.push(getDescribedById(id, "description"));
|
|
44
|
+
if (hasCharacterCounter) describedByIds.push(getDescribedById(id, "counter"));
|
|
45
|
+
return {
|
|
46
|
+
"aria-invalid": hasError,
|
|
47
|
+
"aria-required": isRequired,
|
|
48
|
+
"aria-describedby": describedByIds.length > 0 ? describedByIds.join(" ") : void 0,
|
|
49
|
+
"aria-errormessage": hasError ? getDescribedById(id, "error") : void 0,
|
|
50
|
+
required: isRequired,
|
|
51
|
+
disabled: isDisabled,
|
|
52
|
+
readOnly: isReadOnly,
|
|
53
|
+
tabIndex: isDisabled ? -1 : 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Utility function to handle keyboard events for interactive elements
|
|
58
|
+
* Helps ensure keyboard users can interact with form controls
|
|
59
|
+
*/
|
|
60
|
+
function handleKeyboardEvent(event, handlers) {
|
|
61
|
+
switch (event.key) {
|
|
62
|
+
case "Enter":
|
|
63
|
+
if (handlers.onEnter) {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
handlers.onEnter();
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case " ":
|
|
69
|
+
if (handlers.onSpace) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
handlers.onSpace();
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case "Escape":
|
|
75
|
+
if (handlers.onEscape) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
handlers.onEscape();
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case "ArrowUp":
|
|
81
|
+
if (handlers.onArrowUp) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
handlers.onArrowUp();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "ArrowDown":
|
|
87
|
+
if (handlers.onArrowDown) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
handlers.onArrowDown();
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case "ArrowLeft":
|
|
93
|
+
if (handlers.onArrowLeft) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
handlers.onArrowLeft();
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
case "ArrowRight":
|
|
99
|
+
if (handlers.onArrowRight) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
handlers.onArrowRight();
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "Tab":
|
|
105
|
+
if (handlers.onTab) {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
handlers.onTab();
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
default: break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Field focus management utility
|
|
115
|
+
* For managing focus within a field group or complex form component
|
|
116
|
+
*/
|
|
117
|
+
function createFocusManager() {
|
|
118
|
+
return {
|
|
119
|
+
focusFirstElement(container) {
|
|
120
|
+
if (!container) return;
|
|
121
|
+
const focusable = container.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])");
|
|
122
|
+
if (focusable.length > 0) focusable[0].focus();
|
|
123
|
+
},
|
|
124
|
+
focusElementById(id) {
|
|
125
|
+
const element = document.getElementById(id);
|
|
126
|
+
if (element) element.focus();
|
|
127
|
+
},
|
|
128
|
+
trapFocus(event, container) {
|
|
129
|
+
if (!container || event.key !== "Tab") return;
|
|
130
|
+
const focusable = Array.from(container.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])"));
|
|
131
|
+
if (focusable.length === 0) return;
|
|
132
|
+
const firstElement = focusable[0];
|
|
133
|
+
const lastElement = focusable[focusable.length - 1];
|
|
134
|
+
if (event.shiftKey && document.activeElement === firstElement) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
lastElement.focus();
|
|
137
|
+
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
firstElement.focus();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Provides a handler for Escape key to clear input fields
|
|
146
|
+
*
|
|
147
|
+
* @param onChange - Function to call when value changes
|
|
148
|
+
* @param value - Current value of the input
|
|
149
|
+
* @returns A function to handle the Escape key press
|
|
150
|
+
*/
|
|
151
|
+
function handleEscapeKey(onChange, value) {
|
|
152
|
+
return (e) => {
|
|
153
|
+
if (e.key === "Escape") {
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
if (value) onChange("");
|
|
156
|
+
else e.target.blur();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provides a handler for Space/Enter keys for toggle components (checkboxes, switches)
|
|
162
|
+
*
|
|
163
|
+
* @param onChange - Function to call when value changes
|
|
164
|
+
* @param value - Current value of the input
|
|
165
|
+
* @returns A function to handle the Space/Enter key press
|
|
166
|
+
*/
|
|
167
|
+
function handleToggleKeys(onChange, value) {
|
|
168
|
+
return (e) => {
|
|
169
|
+
if (e.key === " " || e.key === "Enter") {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
onChange(!value);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Provides a handler for arrow keys for numeric inputs
|
|
177
|
+
*
|
|
178
|
+
* @param onChange - Function to call when value changes
|
|
179
|
+
* @param value - Current numeric value
|
|
180
|
+
* @param step - Step amount for increments/decrements
|
|
181
|
+
* @param min - Minimum allowed value (optional)
|
|
182
|
+
* @param max - Maximum allowed value (optional)
|
|
183
|
+
* @returns A function to handle arrow key presses
|
|
184
|
+
*/
|
|
185
|
+
function handleNumericKeys(onChange, value, step = 1, min, max) {
|
|
186
|
+
return (e) => {
|
|
187
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
const direction = e.key === "ArrowUp" ? 1 : -1;
|
|
190
|
+
let newValue = typeof value === "number" ? value + step * direction : 0;
|
|
191
|
+
if (typeof min === "number") newValue = Math.max(min, newValue);
|
|
192
|
+
if (typeof max === "number") newValue = Math.min(max, newValue);
|
|
193
|
+
onChange(newValue);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/components/fields/utils/layout.ts
|
|
200
|
+
/**
|
|
201
|
+
* Layout utility functions for form components
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* Helper function to get width classes based on the field width
|
|
205
|
+
*/
|
|
206
|
+
function getWidthClasses(width) {
|
|
207
|
+
switch (width) {
|
|
208
|
+
case "half": return "form-field-half";
|
|
209
|
+
case "third": return "form-field-third";
|
|
210
|
+
case "full":
|
|
211
|
+
default: return "form-field-full";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
28
216
|
//#region src/components/ui/accordion.tsx
|
|
29
217
|
const accordionItemVariants = cva("", {
|
|
30
218
|
variants: { variant: {
|
|
@@ -302,7 +490,7 @@ Button.displayName = "Button";
|
|
|
302
490
|
function Calendar({ className, classNames, showOutsideDays = true, ...props }) {
|
|
303
491
|
return /* @__PURE__ */ jsx(DayPicker, {
|
|
304
492
|
showOutsideDays,
|
|
305
|
-
className: cn("p-3", className),
|
|
493
|
+
className: cn("relative p-3", className),
|
|
306
494
|
classNames: {
|
|
307
495
|
months: "flex flex-col sm:flex-row gap-2 px-5",
|
|
308
496
|
month: "flex flex-col gap-4",
|
|
@@ -1464,360 +1652,6 @@ function ViewContractStateButton({ contractAddress, onToggle }) {
|
|
|
1464
1652
|
});
|
|
1465
1653
|
}
|
|
1466
1654
|
|
|
1467
|
-
//#endregion
|
|
1468
|
-
//#region src/components/fields/utils/accessibility.ts
|
|
1469
|
-
/**
|
|
1470
|
-
* Accessibility utilities for form field components
|
|
1471
|
-
*/
|
|
1472
|
-
/**
|
|
1473
|
-
* Default aria-describedby ID generator based on field ID
|
|
1474
|
-
*/
|
|
1475
|
-
function getDescribedById(id, type = "error") {
|
|
1476
|
-
return `${id}-${type}`;
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Generates accessibility attributes for form fields
|
|
1480
|
-
*/
|
|
1481
|
-
function getAccessibilityProps({ id, hasError = false, isRequired = false, isDisabled = false, isReadOnly = false, hasHelperText = false, hasCharacterCounter = false }) {
|
|
1482
|
-
const describedByIds = [];
|
|
1483
|
-
if (hasError) describedByIds.push(getDescribedById(id, "error"));
|
|
1484
|
-
if (hasHelperText) describedByIds.push(getDescribedById(id, "description"));
|
|
1485
|
-
if (hasCharacterCounter) describedByIds.push(getDescribedById(id, "counter"));
|
|
1486
|
-
return {
|
|
1487
|
-
"aria-invalid": hasError,
|
|
1488
|
-
"aria-required": isRequired,
|
|
1489
|
-
"aria-describedby": describedByIds.length > 0 ? describedByIds.join(" ") : void 0,
|
|
1490
|
-
"aria-errormessage": hasError ? getDescribedById(id, "error") : void 0,
|
|
1491
|
-
required: isRequired,
|
|
1492
|
-
disabled: isDisabled,
|
|
1493
|
-
readOnly: isReadOnly,
|
|
1494
|
-
tabIndex: isDisabled ? -1 : 0
|
|
1495
|
-
};
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Utility function to handle keyboard events for interactive elements
|
|
1499
|
-
* Helps ensure keyboard users can interact with form controls
|
|
1500
|
-
*/
|
|
1501
|
-
function handleKeyboardEvent(event, handlers) {
|
|
1502
|
-
switch (event.key) {
|
|
1503
|
-
case "Enter":
|
|
1504
|
-
if (handlers.onEnter) {
|
|
1505
|
-
event.preventDefault();
|
|
1506
|
-
handlers.onEnter();
|
|
1507
|
-
}
|
|
1508
|
-
break;
|
|
1509
|
-
case " ":
|
|
1510
|
-
if (handlers.onSpace) {
|
|
1511
|
-
event.preventDefault();
|
|
1512
|
-
handlers.onSpace();
|
|
1513
|
-
}
|
|
1514
|
-
break;
|
|
1515
|
-
case "Escape":
|
|
1516
|
-
if (handlers.onEscape) {
|
|
1517
|
-
event.preventDefault();
|
|
1518
|
-
handlers.onEscape();
|
|
1519
|
-
}
|
|
1520
|
-
break;
|
|
1521
|
-
case "ArrowUp":
|
|
1522
|
-
if (handlers.onArrowUp) {
|
|
1523
|
-
event.preventDefault();
|
|
1524
|
-
handlers.onArrowUp();
|
|
1525
|
-
}
|
|
1526
|
-
break;
|
|
1527
|
-
case "ArrowDown":
|
|
1528
|
-
if (handlers.onArrowDown) {
|
|
1529
|
-
event.preventDefault();
|
|
1530
|
-
handlers.onArrowDown();
|
|
1531
|
-
}
|
|
1532
|
-
break;
|
|
1533
|
-
case "ArrowLeft":
|
|
1534
|
-
if (handlers.onArrowLeft) {
|
|
1535
|
-
event.preventDefault();
|
|
1536
|
-
handlers.onArrowLeft();
|
|
1537
|
-
}
|
|
1538
|
-
break;
|
|
1539
|
-
case "ArrowRight":
|
|
1540
|
-
if (handlers.onArrowRight) {
|
|
1541
|
-
event.preventDefault();
|
|
1542
|
-
handlers.onArrowRight();
|
|
1543
|
-
}
|
|
1544
|
-
break;
|
|
1545
|
-
case "Tab":
|
|
1546
|
-
if (handlers.onTab) {
|
|
1547
|
-
event.preventDefault();
|
|
1548
|
-
handlers.onTab();
|
|
1549
|
-
}
|
|
1550
|
-
break;
|
|
1551
|
-
default: break;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
/**
|
|
1555
|
-
* Field focus management utility
|
|
1556
|
-
* For managing focus within a field group or complex form component
|
|
1557
|
-
*/
|
|
1558
|
-
function createFocusManager() {
|
|
1559
|
-
return {
|
|
1560
|
-
focusFirstElement(container) {
|
|
1561
|
-
if (!container) return;
|
|
1562
|
-
const focusable = container.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])");
|
|
1563
|
-
if (focusable.length > 0) focusable[0].focus();
|
|
1564
|
-
},
|
|
1565
|
-
focusElementById(id) {
|
|
1566
|
-
const element = document.getElementById(id);
|
|
1567
|
-
if (element) element.focus();
|
|
1568
|
-
},
|
|
1569
|
-
trapFocus(event, container) {
|
|
1570
|
-
if (!container || event.key !== "Tab") return;
|
|
1571
|
-
const focusable = Array.from(container.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])"));
|
|
1572
|
-
if (focusable.length === 0) return;
|
|
1573
|
-
const firstElement = focusable[0];
|
|
1574
|
-
const lastElement = focusable[focusable.length - 1];
|
|
1575
|
-
if (event.shiftKey && document.activeElement === firstElement) {
|
|
1576
|
-
event.preventDefault();
|
|
1577
|
-
lastElement.focus();
|
|
1578
|
-
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
1579
|
-
event.preventDefault();
|
|
1580
|
-
firstElement.focus();
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
};
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Provides a handler for Escape key to clear input fields
|
|
1587
|
-
*
|
|
1588
|
-
* @param onChange - Function to call when value changes
|
|
1589
|
-
* @param value - Current value of the input
|
|
1590
|
-
* @returns A function to handle the Escape key press
|
|
1591
|
-
*/
|
|
1592
|
-
function handleEscapeKey(onChange, value) {
|
|
1593
|
-
return (e) => {
|
|
1594
|
-
if (e.key === "Escape") {
|
|
1595
|
-
e.preventDefault();
|
|
1596
|
-
if (value) onChange("");
|
|
1597
|
-
else e.target.blur();
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
}
|
|
1601
|
-
/**
|
|
1602
|
-
* Provides a handler for Space/Enter keys for toggle components (checkboxes, switches)
|
|
1603
|
-
*
|
|
1604
|
-
* @param onChange - Function to call when value changes
|
|
1605
|
-
* @param value - Current value of the input
|
|
1606
|
-
* @returns A function to handle the Space/Enter key press
|
|
1607
|
-
*/
|
|
1608
|
-
function handleToggleKeys(onChange, value) {
|
|
1609
|
-
return (e) => {
|
|
1610
|
-
if (e.key === " " || e.key === "Enter") {
|
|
1611
|
-
e.preventDefault();
|
|
1612
|
-
onChange(!value);
|
|
1613
|
-
}
|
|
1614
|
-
};
|
|
1615
|
-
}
|
|
1616
|
-
/**
|
|
1617
|
-
* Provides a handler for arrow keys for numeric inputs
|
|
1618
|
-
*
|
|
1619
|
-
* @param onChange - Function to call when value changes
|
|
1620
|
-
* @param value - Current numeric value
|
|
1621
|
-
* @param step - Step amount for increments/decrements
|
|
1622
|
-
* @param min - Minimum allowed value (optional)
|
|
1623
|
-
* @param max - Maximum allowed value (optional)
|
|
1624
|
-
* @returns A function to handle arrow key presses
|
|
1625
|
-
*/
|
|
1626
|
-
function handleNumericKeys(onChange, value, step = 1, min, max) {
|
|
1627
|
-
return (e) => {
|
|
1628
|
-
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
1629
|
-
e.preventDefault();
|
|
1630
|
-
const direction = e.key === "ArrowUp" ? 1 : -1;
|
|
1631
|
-
let newValue = typeof value === "number" ? value + step * direction : 0;
|
|
1632
|
-
if (typeof min === "number") newValue = Math.max(min, newValue);
|
|
1633
|
-
if (typeof max === "number") newValue = Math.min(max, newValue);
|
|
1634
|
-
onChange(newValue);
|
|
1635
|
-
}
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
//#endregion
|
|
1640
|
-
//#region src/components/fields/utils/integerValidation.ts
|
|
1641
|
-
/**
|
|
1642
|
-
* Shared integer validation patterns for BigInt fields and validation utilities.
|
|
1643
|
-
*
|
|
1644
|
-
* These patterns ensure consistent validation across the application.
|
|
1645
|
-
*/
|
|
1646
|
-
/**
|
|
1647
|
-
* Integer validation pattern - requires at least one digit
|
|
1648
|
-
* Used for validation to ensure complete integers are entered
|
|
1649
|
-
* Matches: -123, 0, 456
|
|
1650
|
-
* Does not match: -, abc, 12.3
|
|
1651
|
-
*/
|
|
1652
|
-
const INTEGER_PATTERN = /^-?\d+$/;
|
|
1653
|
-
/**
|
|
1654
|
-
* Integer input pattern - allows partial input during typing
|
|
1655
|
-
* Used during input to allow users to type minus sign first
|
|
1656
|
-
* Matches: -, -1, 123, (empty string)
|
|
1657
|
-
* Does not match: abc, 12.3
|
|
1658
|
-
*/
|
|
1659
|
-
const INTEGER_INPUT_PATTERN = /^-?\d*$/;
|
|
1660
|
-
/**
|
|
1661
|
-
* HTML pattern attribute for integer inputs
|
|
1662
|
-
* Must use [0-9] instead of \d for HTML5 pattern attribute
|
|
1663
|
-
*/
|
|
1664
|
-
const INTEGER_HTML_PATTERN = "-?[0-9]*";
|
|
1665
|
-
|
|
1666
|
-
//#endregion
|
|
1667
|
-
//#region src/components/fields/utils/validation.ts
|
|
1668
|
-
/**
|
|
1669
|
-
* Determines if a field has an error
|
|
1670
|
-
*/
|
|
1671
|
-
function hasFieldError(error) {
|
|
1672
|
-
return !!error;
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Gets appropriate error message from field error
|
|
1676
|
-
*/
|
|
1677
|
-
function getErrorMessage(error) {
|
|
1678
|
-
if (!error) return void 0;
|
|
1679
|
-
return error.message || "This field is invalid";
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* Formats validation error messages for display
|
|
1683
|
-
*/
|
|
1684
|
-
function formatValidationError(error, fieldName) {
|
|
1685
|
-
if (!error) return void 0;
|
|
1686
|
-
const defaultMessage = fieldName ? `${fieldName} is invalid` : "This field is invalid";
|
|
1687
|
-
return error.message || defaultMessage;
|
|
1688
|
-
}
|
|
1689
|
-
/**
|
|
1690
|
-
* Generates common CSS classes for field validation states
|
|
1691
|
-
*/
|
|
1692
|
-
function getValidationStateClasses(error, touched) {
|
|
1693
|
-
if (error) return "border-destructive focus:border-destructive focus:ring-destructive/30";
|
|
1694
|
-
if (touched) return "border-success focus:border-success focus:ring-success/30";
|
|
1695
|
-
return "";
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* Helper for handling form validation errors with React Hook Form
|
|
1699
|
-
*/
|
|
1700
|
-
function handleValidationError(error, id) {
|
|
1701
|
-
const hasError = hasFieldError(error);
|
|
1702
|
-
const errorMessage = getErrorMessage(error);
|
|
1703
|
-
return {
|
|
1704
|
-
errorId: `${id}-error`,
|
|
1705
|
-
errorMessage,
|
|
1706
|
-
hasError,
|
|
1707
|
-
validationClasses: getValidationStateClasses(error)
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Creates a validation result object for field components
|
|
1712
|
-
*/
|
|
1713
|
-
function createValidationResult(id, error, touched) {
|
|
1714
|
-
const hasError = hasFieldError(error);
|
|
1715
|
-
const errorMessage = getErrorMessage(error);
|
|
1716
|
-
const errorId = `${id}-error`;
|
|
1717
|
-
return {
|
|
1718
|
-
hasError,
|
|
1719
|
-
errorMessage,
|
|
1720
|
-
errorId,
|
|
1721
|
-
validationClasses: getValidationStateClasses(error, touched),
|
|
1722
|
-
"aria-invalid": hasError,
|
|
1723
|
-
"aria-errormessage": hasError ? errorId : void 0
|
|
1724
|
-
};
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* Generic field validation function that can be used to validate any field type
|
|
1728
|
-
* based on common validation criteria
|
|
1729
|
-
*/
|
|
1730
|
-
function validateField(value, validation) {
|
|
1731
|
-
if (!validation) return true;
|
|
1732
|
-
if (validation.required && (value === void 0 || value === null || value === "")) return typeof validation.required === "boolean" ? "This field is required" : "This field is required";
|
|
1733
|
-
if (value === void 0 || value === null || value === "") return true;
|
|
1734
|
-
if (typeof value === "string") {
|
|
1735
|
-
if (validation.minLength && value.length < validation.minLength) return `Minimum length is ${validation.minLength} characters`;
|
|
1736
|
-
if (validation.maxLength && value.length > validation.maxLength) return `Maximum length is ${validation.maxLength} characters`;
|
|
1737
|
-
if (validation.pattern) {
|
|
1738
|
-
if (!(typeof validation.pattern === "string" ? new RegExp(validation.pattern) : validation.pattern).test(value)) {
|
|
1739
|
-
if (!INTEGER_PATTERN.test(value) && /\d/.test(value)) return "Value must be a valid integer (no decimals)";
|
|
1740
|
-
return "Value does not match the required pattern";
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
if (typeof value === "number" || typeof value === "string" && !isNaN(Number(value))) {
|
|
1745
|
-
const numValue = typeof value === "number" ? value : Number(value);
|
|
1746
|
-
if (validation.min !== void 0 && numValue < validation.min) return `Minimum value is ${validation.min}`;
|
|
1747
|
-
if (validation.max !== void 0 && numValue > validation.max) return `Maximum value is ${validation.max}`;
|
|
1748
|
-
}
|
|
1749
|
-
if (validation.conditions && validation.conditions.length > 0) {}
|
|
1750
|
-
return true;
|
|
1751
|
-
}
|
|
1752
|
-
/**
|
|
1753
|
-
* Map validation utilities
|
|
1754
|
-
*/
|
|
1755
|
-
/**
|
|
1756
|
-
* Checks if a map entry at the given index has a duplicate key
|
|
1757
|
-
* @param entries - Array of map entries
|
|
1758
|
-
* @param currentIndex - Index of the entry to check
|
|
1759
|
-
* @returns true if the key at currentIndex is duplicated elsewhere in the array
|
|
1760
|
-
*/
|
|
1761
|
-
function isDuplicateMapKey(entries, currentIndex) {
|
|
1762
|
-
if (!Array.isArray(entries) || entries.length <= 1) return false;
|
|
1763
|
-
const currentKeyValue = entries[currentIndex]?.key;
|
|
1764
|
-
if (!currentKeyValue || currentKeyValue === "") return false;
|
|
1765
|
-
return entries.some((entry, i) => {
|
|
1766
|
-
if (i === currentIndex) return false;
|
|
1767
|
-
const key = entry?.key;
|
|
1768
|
-
if (key === "") return false;
|
|
1769
|
-
if (typeof key === "string" && typeof currentKeyValue === "string") return key === currentKeyValue;
|
|
1770
|
-
if (typeof key === "number" && typeof currentKeyValue === "number") return Number.isNaN(key) ? Number.isNaN(currentKeyValue) : key === currentKeyValue;
|
|
1771
|
-
if (typeof key === "boolean" && typeof currentKeyValue === "boolean") return key === currentKeyValue;
|
|
1772
|
-
if (typeof key === "object" && key !== null && typeof currentKeyValue === "object" && currentKeyValue !== null) return key === currentKeyValue;
|
|
1773
|
-
return false;
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
/**
|
|
1777
|
-
* Validates an array of map entries for duplicate keys
|
|
1778
|
-
* @param entries - Array of map entries to validate
|
|
1779
|
-
* @returns Validation error message if duplicates found, otherwise undefined
|
|
1780
|
-
*/
|
|
1781
|
-
function validateMapEntries(entries) {
|
|
1782
|
-
if (!Array.isArray(entries) || entries.length <= 1) return;
|
|
1783
|
-
const keyStrings = entries.map((entry) => entry?.key).filter((key) => key !== void 0 && key !== null && key !== "").map((key) => String(key));
|
|
1784
|
-
const uniqueKeyStrings = new Set(keyStrings);
|
|
1785
|
-
if (keyStrings.length !== uniqueKeyStrings.size) return "Duplicate keys are not allowed";
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
//#endregion
|
|
1789
|
-
//#region src/components/fields/utils/ErrorMessage.tsx
|
|
1790
|
-
/**
|
|
1791
|
-
* Displays validation error messages for form fields
|
|
1792
|
-
*/
|
|
1793
|
-
function ErrorMessage({ error, id, message, className = "" }) {
|
|
1794
|
-
const errorMessage = message || getErrorMessage(error);
|
|
1795
|
-
if (!errorMessage) return null;
|
|
1796
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1797
|
-
id,
|
|
1798
|
-
className: `text-destructive mt-1 text-sm ${className}`,
|
|
1799
|
-
role: "alert",
|
|
1800
|
-
children: errorMessage
|
|
1801
|
-
});
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
//#endregion
|
|
1805
|
-
//#region src/components/fields/utils/layout.ts
|
|
1806
|
-
/**
|
|
1807
|
-
* Layout utility functions for form components
|
|
1808
|
-
*/
|
|
1809
|
-
/**
|
|
1810
|
-
* Helper function to get width classes based on the field width
|
|
1811
|
-
*/
|
|
1812
|
-
function getWidthClasses(width) {
|
|
1813
|
-
switch (width) {
|
|
1814
|
-
case "half": return "form-field-half";
|
|
1815
|
-
case "third": return "form-field-third";
|
|
1816
|
-
case "full":
|
|
1817
|
-
default: return "form-field-full";
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
1655
|
//#endregion
|
|
1822
1656
|
//#region src/components/fields/AddressField.tsx
|
|
1823
1657
|
/**
|
|
@@ -2927,126 +2761,6 @@ function BytesField({ id, label, helperText, control, name, width = "full", vali
|
|
|
2927
2761
|
}
|
|
2928
2762
|
BytesField.displayName = "BytesField";
|
|
2929
2763
|
|
|
2930
|
-
//#endregion
|
|
2931
|
-
//#region src/components/fields/CodeEditorField.tsx
|
|
2932
|
-
/**
|
|
2933
|
-
* CodeEditorField provides syntax-highlighted code editing with form integration.
|
|
2934
|
-
*
|
|
2935
|
-
* Features:
|
|
2936
|
-
* - Syntax highlighting via @uiw/react-textarea-code-editor
|
|
2937
|
-
* - React Hook Form integration with Controller
|
|
2938
|
-
* - Configurable language support (JSON, TypeScript, etc.)
|
|
2939
|
-
* - Performance optimizations with smart highlighting
|
|
2940
|
-
* - Constrained height with automatic scrolling
|
|
2941
|
-
* - Design system styling integration
|
|
2942
|
-
*
|
|
2943
|
-
* @example
|
|
2944
|
-
* ```tsx
|
|
2945
|
-
* <CodeEditorField
|
|
2946
|
-
* id="contractAbi"
|
|
2947
|
-
* name="contractSchema"
|
|
2948
|
-
* control={control}
|
|
2949
|
-
* label="Contract ABI"
|
|
2950
|
-
* language="json"
|
|
2951
|
-
* placeholder="Paste your ABI JSON here..."
|
|
2952
|
-
* />
|
|
2953
|
-
* ```
|
|
2954
|
-
*/
|
|
2955
|
-
function CodeEditorField({ id, name, control, label, helperText, placeholder = "", language = "json", theme = "light", height = "200px", maxHeight = "400px", performanceThreshold = 5e3, required = false, disabled = false, readOnly = false, validateCode, className }) {
|
|
2956
|
-
function extractPixelValue(val, fallback) {
|
|
2957
|
-
if (typeof val === "number") return val;
|
|
2958
|
-
const match = typeof val === "string" ? val.match(/^(\d+)\s*px$/) : null;
|
|
2959
|
-
if (match) return parseInt(match[1], 10);
|
|
2960
|
-
return fallback;
|
|
2961
|
-
}
|
|
2962
|
-
const minHeightNum = extractPixelValue(height, 200);
|
|
2963
|
-
const maxHeightNum = extractPixelValue(maxHeight, 400);
|
|
2964
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
2965
|
-
className,
|
|
2966
|
-
children: [label && /* @__PURE__ */ jsxs("label", {
|
|
2967
|
-
htmlFor: id,
|
|
2968
|
-
className: "block text-sm font-medium text-foreground mb-2",
|
|
2969
|
-
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
2970
|
-
className: "text-destructive ml-1",
|
|
2971
|
-
children: "*"
|
|
2972
|
-
})]
|
|
2973
|
-
}), /* @__PURE__ */ jsx(Controller, {
|
|
2974
|
-
name,
|
|
2975
|
-
control,
|
|
2976
|
-
rules: {
|
|
2977
|
-
required: required ? "This field is required" : false,
|
|
2978
|
-
validate: { validCode: (value) => {
|
|
2979
|
-
if (!validateCode || !value) return true;
|
|
2980
|
-
const validation = validateCode(value);
|
|
2981
|
-
if (typeof validation === "string") return validation;
|
|
2982
|
-
if (validation === false) return "Invalid code format";
|
|
2983
|
-
return true;
|
|
2984
|
-
} }
|
|
2985
|
-
},
|
|
2986
|
-
render: ({ field: { onChange, onBlur, value }, fieldState: { error } }) => {
|
|
2987
|
-
const shouldDisableHighlighting = (value || "").length > performanceThreshold;
|
|
2988
|
-
const EditorComponent = shouldDisableHighlighting ? CodeEditorNoHighlight : CodeEditor;
|
|
2989
|
-
const handleChange = (event) => {
|
|
2990
|
-
onChange(event.target.value);
|
|
2991
|
-
};
|
|
2992
|
-
const handleBlur = () => {
|
|
2993
|
-
onBlur();
|
|
2994
|
-
};
|
|
2995
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
2996
|
-
className: "space-y-2",
|
|
2997
|
-
children: [
|
|
2998
|
-
/* @__PURE__ */ jsx("div", {
|
|
2999
|
-
className: "w-full rounded-md border border-input bg-background ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 disabled:cursor-not-allowed resize-y",
|
|
3000
|
-
style: {
|
|
3001
|
-
maxHeight: `${maxHeightNum}px`,
|
|
3002
|
-
overflow: "auto",
|
|
3003
|
-
overflowX: "hidden",
|
|
3004
|
-
minHeight: `${minHeightNum}px`,
|
|
3005
|
-
resize: "vertical"
|
|
3006
|
-
},
|
|
3007
|
-
children: /* @__PURE__ */ jsx(EditorComponent, {
|
|
3008
|
-
id,
|
|
3009
|
-
value: value || "",
|
|
3010
|
-
language,
|
|
3011
|
-
placeholder,
|
|
3012
|
-
onChange: handleChange,
|
|
3013
|
-
onBlur: handleBlur,
|
|
3014
|
-
padding: 12,
|
|
3015
|
-
minHeight: minHeightNum,
|
|
3016
|
-
"data-color-mode": theme,
|
|
3017
|
-
disabled,
|
|
3018
|
-
readOnly,
|
|
3019
|
-
"data-testid": `${id}-code-editor${shouldDisableHighlighting ? "-no-highlight" : ""}`,
|
|
3020
|
-
className: "text-sm placeholder:text-muted-foreground",
|
|
3021
|
-
style: {
|
|
3022
|
-
fontFamily: "ui-monospace, SFMono-Regular, \"SF Mono\", Consolas, \"Liberation Mono\", Menlo, monospace",
|
|
3023
|
-
fontSize: "14px",
|
|
3024
|
-
border: "none",
|
|
3025
|
-
backgroundColor: "transparent",
|
|
3026
|
-
width: "100%",
|
|
3027
|
-
wordWrap: "break-word",
|
|
3028
|
-
whiteSpace: "pre-wrap",
|
|
3029
|
-
overflowWrap: "break-word"
|
|
3030
|
-
}
|
|
3031
|
-
})
|
|
3032
|
-
}),
|
|
3033
|
-
/* @__PURE__ */ jsx(ErrorMessage, {
|
|
3034
|
-
error,
|
|
3035
|
-
id: `${id}-error`
|
|
3036
|
-
}),
|
|
3037
|
-
helperText && !error && /* @__PURE__ */ jsx("p", {
|
|
3038
|
-
className: "text-sm text-muted-foreground",
|
|
3039
|
-
id: `${id}-helper`,
|
|
3040
|
-
children: helperText
|
|
3041
|
-
})
|
|
3042
|
-
]
|
|
3043
|
-
});
|
|
3044
|
-
}
|
|
3045
|
-
})]
|
|
3046
|
-
});
|
|
3047
|
-
}
|
|
3048
|
-
CodeEditorField.displayName = "CodeEditorField";
|
|
3049
|
-
|
|
3050
2764
|
//#endregion
|
|
3051
2765
|
//#region src/components/fields/DateTimeField.tsx
|
|
3052
2766
|
/**
|
|
@@ -5344,5 +5058,5 @@ const Toaster = ({ ...props }) => {
|
|
|
5344
5058
|
};
|
|
5345
5059
|
|
|
5346
5060
|
//#endregion
|
|
5347
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AddressDisplay, AddressField, Alert, AlertDescription, AlertTitle, AmountField, ArrayField, ArrayObjectField, Banner, BaseField, BigIntField, BooleanField, Button, BytesField, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox,
|
|
5061
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AddressDisplay, AddressField, Alert, AlertDescription, AlertTitle, AmountField, ArrayField, ArrayObjectField, Banner, BaseField, BigIntField, BooleanField, Button, BytesField, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, DateRangePicker, DateTimeField, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, EnumField, ErrorMessage, ExternalLink, FileUploadField, Footer, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Header, INTEGER_HTML_PATTERN, INTEGER_INPUT_PATTERN, INTEGER_PATTERN, Input, Label, LoadingButton, MapEntryRow, MapField, MidnightIcon, NetworkErrorNotificationProvider, NetworkIcon, NetworkSelector, NetworkStatusBadge, NumberField, ObjectField, PasswordField, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RadioField, RadioGroup, RadioGroupItem, RelayerDetailsCard, Select, SelectContent, SelectField, SelectGroup, SelectGroupedField, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, SidebarButton, SidebarLayout, SidebarSection, Tabs, TabsContent, TabsList, TabsTrigger, TextAreaField, TextField, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UrlField, ViewContractStateButton, buttonVariants, computeChildTouched, createFocusManager, createValidationResult, formatValidationError, getAccessibilityProps, getDescribedById, getErrorMessage, getValidationStateClasses, getWidthClasses, handleEscapeKey, handleKeyboardEvent, handleNumericKeys, handleToggleKeys, handleValidationError, hasFieldError, isDuplicateMapKey, useDuplicateKeyIndexes, useMapFieldSync, useNetworkErrorAwareAdapter, useNetworkErrorReporter, useNetworkErrors, validateField, validateMapEntries, validateMapStructure };
|
|
5348
5062
|
//# sourceMappingURL=index.js.map
|