@openzeppelin/ui-components 1.0.0 → 1.0.1

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.
@@ -0,0 +1,281 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let react = require("react");
29
+ react = __toESM(react);
30
+ let react_jsx_runtime = require("react/jsx-runtime");
31
+
32
+ //#region src/components/fields/utils/integerValidation.ts
33
+ /**
34
+ * Shared integer validation patterns for BigInt fields and validation utilities.
35
+ *
36
+ * These patterns ensure consistent validation across the application.
37
+ */
38
+ /**
39
+ * Integer validation pattern - requires at least one digit
40
+ * Used for validation to ensure complete integers are entered
41
+ * Matches: -123, 0, 456
42
+ * Does not match: -, abc, 12.3
43
+ */
44
+ const INTEGER_PATTERN = /^-?\d+$/;
45
+ /**
46
+ * Integer input pattern - allows partial input during typing
47
+ * Used during input to allow users to type minus sign first
48
+ * Matches: -, -1, 123, (empty string)
49
+ * Does not match: abc, 12.3
50
+ */
51
+ const INTEGER_INPUT_PATTERN = /^-?\d*$/;
52
+ /**
53
+ * HTML pattern attribute for integer inputs
54
+ * Must use [0-9] instead of \d for HTML5 pattern attribute
55
+ */
56
+ const INTEGER_HTML_PATTERN = "-?[0-9]*";
57
+
58
+ //#endregion
59
+ //#region src/components/fields/utils/validation.ts
60
+ /**
61
+ * Determines if a field has an error
62
+ */
63
+ function hasFieldError(error) {
64
+ return !!error;
65
+ }
66
+ /**
67
+ * Gets appropriate error message from field error
68
+ */
69
+ function getErrorMessage(error) {
70
+ if (!error) return void 0;
71
+ return error.message || "This field is invalid";
72
+ }
73
+ /**
74
+ * Formats validation error messages for display
75
+ */
76
+ function formatValidationError(error, fieldName) {
77
+ if (!error) return void 0;
78
+ const defaultMessage = fieldName ? `${fieldName} is invalid` : "This field is invalid";
79
+ return error.message || defaultMessage;
80
+ }
81
+ /**
82
+ * Generates common CSS classes for field validation states
83
+ */
84
+ function getValidationStateClasses(error, touched) {
85
+ if (error) return "border-destructive focus:border-destructive focus:ring-destructive/30";
86
+ if (touched) return "border-success focus:border-success focus:ring-success/30";
87
+ return "";
88
+ }
89
+ /**
90
+ * Helper for handling form validation errors with React Hook Form
91
+ */
92
+ function handleValidationError(error, id) {
93
+ const hasError = hasFieldError(error);
94
+ const errorMessage = getErrorMessage(error);
95
+ return {
96
+ errorId: `${id}-error`,
97
+ errorMessage,
98
+ hasError,
99
+ validationClasses: getValidationStateClasses(error)
100
+ };
101
+ }
102
+ /**
103
+ * Creates a validation result object for field components
104
+ */
105
+ function createValidationResult(id, error, touched) {
106
+ const hasError = hasFieldError(error);
107
+ const errorMessage = getErrorMessage(error);
108
+ const errorId = `${id}-error`;
109
+ return {
110
+ hasError,
111
+ errorMessage,
112
+ errorId,
113
+ validationClasses: getValidationStateClasses(error, touched),
114
+ "aria-invalid": hasError,
115
+ "aria-errormessage": hasError ? errorId : void 0
116
+ };
117
+ }
118
+ /**
119
+ * Generic field validation function that can be used to validate any field type
120
+ * based on common validation criteria
121
+ */
122
+ function validateField(value, validation) {
123
+ if (!validation) return true;
124
+ if (validation.required && (value === void 0 || value === null || value === "")) return typeof validation.required === "boolean" ? "This field is required" : "This field is required";
125
+ if (value === void 0 || value === null || value === "") return true;
126
+ if (typeof value === "string") {
127
+ if (validation.minLength && value.length < validation.minLength) return `Minimum length is ${validation.minLength} characters`;
128
+ if (validation.maxLength && value.length > validation.maxLength) return `Maximum length is ${validation.maxLength} characters`;
129
+ if (validation.pattern) {
130
+ if (!(typeof validation.pattern === "string" ? new RegExp(validation.pattern) : validation.pattern).test(value)) {
131
+ if (!INTEGER_PATTERN.test(value) && /\d/.test(value)) return "Value must be a valid integer (no decimals)";
132
+ return "Value does not match the required pattern";
133
+ }
134
+ }
135
+ }
136
+ if (typeof value === "number" || typeof value === "string" && !isNaN(Number(value))) {
137
+ const numValue = typeof value === "number" ? value : Number(value);
138
+ if (validation.min !== void 0 && numValue < validation.min) return `Minimum value is ${validation.min}`;
139
+ if (validation.max !== void 0 && numValue > validation.max) return `Maximum value is ${validation.max}`;
140
+ }
141
+ if (validation.conditions && validation.conditions.length > 0) {}
142
+ return true;
143
+ }
144
+ /**
145
+ * Map validation utilities
146
+ */
147
+ /**
148
+ * Checks if a map entry at the given index has a duplicate key
149
+ * @param entries - Array of map entries
150
+ * @param currentIndex - Index of the entry to check
151
+ * @returns true if the key at currentIndex is duplicated elsewhere in the array
152
+ */
153
+ function isDuplicateMapKey(entries, currentIndex) {
154
+ if (!Array.isArray(entries) || entries.length <= 1) return false;
155
+ const currentKeyValue = entries[currentIndex]?.key;
156
+ if (!currentKeyValue || currentKeyValue === "") return false;
157
+ return entries.some((entry, i) => {
158
+ if (i === currentIndex) return false;
159
+ const key = entry?.key;
160
+ if (key === "") return false;
161
+ if (typeof key === "string" && typeof currentKeyValue === "string") return key === currentKeyValue;
162
+ if (typeof key === "number" && typeof currentKeyValue === "number") return Number.isNaN(key) ? Number.isNaN(currentKeyValue) : key === currentKeyValue;
163
+ if (typeof key === "boolean" && typeof currentKeyValue === "boolean") return key === currentKeyValue;
164
+ if (typeof key === "object" && key !== null && typeof currentKeyValue === "object" && currentKeyValue !== null) return key === currentKeyValue;
165
+ return false;
166
+ });
167
+ }
168
+ /**
169
+ * Validates an array of map entries for duplicate keys
170
+ * @param entries - Array of map entries to validate
171
+ * @returns Validation error message if duplicates found, otherwise undefined
172
+ */
173
+ function validateMapEntries(entries) {
174
+ if (!Array.isArray(entries) || entries.length <= 1) return;
175
+ const keyStrings = entries.map((entry) => entry?.key).filter((key) => key !== void 0 && key !== null && key !== "").map((key) => String(key));
176
+ const uniqueKeyStrings = new Set(keyStrings);
177
+ if (keyStrings.length !== uniqueKeyStrings.size) return "Duplicate keys are not allowed";
178
+ }
179
+
180
+ //#endregion
181
+ //#region src/components/fields/utils/ErrorMessage.tsx
182
+ /**
183
+ * Displays validation error messages for form fields
184
+ */
185
+ function ErrorMessage({ error, id, message, className = "" }) {
186
+ const errorMessage = message || getErrorMessage(error);
187
+ if (!errorMessage) return null;
188
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
189
+ id,
190
+ className: `text-destructive mt-1 text-sm ${className}`,
191
+ role: "alert",
192
+ children: errorMessage
193
+ });
194
+ }
195
+
196
+ //#endregion
197
+ Object.defineProperty(exports, 'ErrorMessage', {
198
+ enumerable: true,
199
+ get: function () {
200
+ return ErrorMessage;
201
+ }
202
+ });
203
+ Object.defineProperty(exports, 'INTEGER_HTML_PATTERN', {
204
+ enumerable: true,
205
+ get: function () {
206
+ return INTEGER_HTML_PATTERN;
207
+ }
208
+ });
209
+ Object.defineProperty(exports, 'INTEGER_INPUT_PATTERN', {
210
+ enumerable: true,
211
+ get: function () {
212
+ return INTEGER_INPUT_PATTERN;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, 'INTEGER_PATTERN', {
216
+ enumerable: true,
217
+ get: function () {
218
+ return INTEGER_PATTERN;
219
+ }
220
+ });
221
+ Object.defineProperty(exports, '__toESM', {
222
+ enumerable: true,
223
+ get: function () {
224
+ return __toESM;
225
+ }
226
+ });
227
+ Object.defineProperty(exports, 'createValidationResult', {
228
+ enumerable: true,
229
+ get: function () {
230
+ return createValidationResult;
231
+ }
232
+ });
233
+ Object.defineProperty(exports, 'formatValidationError', {
234
+ enumerable: true,
235
+ get: function () {
236
+ return formatValidationError;
237
+ }
238
+ });
239
+ Object.defineProperty(exports, 'getErrorMessage', {
240
+ enumerable: true,
241
+ get: function () {
242
+ return getErrorMessage;
243
+ }
244
+ });
245
+ Object.defineProperty(exports, 'getValidationStateClasses', {
246
+ enumerable: true,
247
+ get: function () {
248
+ return getValidationStateClasses;
249
+ }
250
+ });
251
+ Object.defineProperty(exports, 'handleValidationError', {
252
+ enumerable: true,
253
+ get: function () {
254
+ return handleValidationError;
255
+ }
256
+ });
257
+ Object.defineProperty(exports, 'hasFieldError', {
258
+ enumerable: true,
259
+ get: function () {
260
+ return hasFieldError;
261
+ }
262
+ });
263
+ Object.defineProperty(exports, 'isDuplicateMapKey', {
264
+ enumerable: true,
265
+ get: function () {
266
+ return isDuplicateMapKey;
267
+ }
268
+ });
269
+ Object.defineProperty(exports, 'validateField', {
270
+ enumerable: true,
271
+ get: function () {
272
+ return validateField;
273
+ }
274
+ });
275
+ Object.defineProperty(exports, 'validateMapEntries', {
276
+ enumerable: true,
277
+ get: function () {
278
+ return validateMapEntries;
279
+ }
280
+ });
281
+ //# sourceMappingURL=ErrorMessage-D4BAP8iw.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorMessage-D4BAP8iw.cjs","names":[],"sources":["../src/components/fields/utils/integerValidation.ts","../src/components/fields/utils/validation.ts","../src/components/fields/utils/ErrorMessage.tsx"],"sourcesContent":["/**\n * Shared integer validation patterns for BigInt fields and validation utilities.\n *\n * These patterns ensure consistent validation across the application.\n */\n\n/**\n * Integer validation pattern - requires at least one digit\n * Used for validation to ensure complete integers are entered\n * Matches: -123, 0, 456\n * Does not match: -, abc, 12.3\n */\nexport const INTEGER_PATTERN = /^-?\\d+$/;\n\n/**\n * Integer input pattern - allows partial input during typing\n * Used during input to allow users to type minus sign first\n * Matches: -, -1, 123, (empty string)\n * Does not match: abc, 12.3\n */\nexport const INTEGER_INPUT_PATTERN = /^-?\\d*$/;\n\n/**\n * HTML pattern attribute for integer inputs\n * Must use [0-9] instead of \\d for HTML5 pattern attribute\n */\nexport const INTEGER_HTML_PATTERN = '-?[0-9]*';\n","/**\n * Validation and error handling utilities for form field components\n */\nimport { FieldError } from 'react-hook-form';\n\nimport { FieldValidation, MapEntry } from '@openzeppelin/ui-types';\n\nimport { INTEGER_PATTERN } from './integerValidation';\n\n/**\n * Determines if a field has an error\n */\nexport function hasFieldError(error: FieldError | undefined): boolean {\n return !!error;\n}\n\n/**\n * Gets appropriate error message from field error\n */\nexport function getErrorMessage(error: FieldError | undefined): string | undefined {\n if (!error) return undefined;\n\n return error.message || 'This field is invalid';\n}\n\n/**\n * Formats validation error messages for display\n */\nexport function formatValidationError(\n error: FieldError | undefined,\n fieldName?: string\n): string | undefined {\n if (!error) return undefined;\n\n const defaultMessage = fieldName ? `${fieldName} is invalid` : 'This field is invalid';\n\n return error.message || defaultMessage;\n}\n\n/**\n * Generates common CSS classes for field validation states\n */\nexport function getValidationStateClasses(\n error: FieldError | undefined,\n touched?: boolean\n): string {\n if (error) {\n return 'border-destructive focus:border-destructive focus:ring-destructive/30';\n }\n\n if (touched) {\n return 'border-success focus:border-success focus:ring-success/30';\n }\n\n return '';\n}\n\n/**\n * Helper for handling form validation errors with React Hook Form\n */\nexport function handleValidationError(\n error: FieldError | undefined,\n id: string\n): {\n errorId: string;\n errorMessage: string | undefined;\n hasError: boolean;\n validationClasses: string;\n} {\n const hasError = hasFieldError(error);\n const errorMessage = getErrorMessage(error);\n const errorId = `${id}-error`;\n const validationClasses = getValidationStateClasses(error);\n\n return {\n errorId,\n errorMessage,\n hasError,\n validationClasses,\n };\n}\n\n/**\n * Creates a validation result object for field components\n */\nexport function createValidationResult(\n id: string,\n error: FieldError | undefined,\n touched?: boolean\n): {\n hasError: boolean;\n errorMessage: string | undefined;\n errorId: string;\n validationClasses: string;\n 'aria-invalid': boolean;\n 'aria-errormessage'?: string;\n} {\n const hasError = hasFieldError(error);\n const errorMessage = getErrorMessage(error);\n const errorId = `${id}-error`;\n const validationClasses = getValidationStateClasses(error, touched);\n\n return {\n hasError,\n errorMessage,\n errorId,\n validationClasses,\n 'aria-invalid': hasError,\n 'aria-errormessage': hasError ? errorId : undefined,\n };\n}\n\n/**\n * Generic field validation function that can be used to validate any field type\n * based on common validation criteria\n */\nexport function validateField(value: unknown, validation?: FieldValidation): string | boolean {\n // Return true if no validation rules are provided\n if (!validation) return true;\n\n // Check if required but empty\n if (validation.required && (value === undefined || value === null || value === '')) {\n return typeof validation.required === 'boolean'\n ? 'This field is required'\n : 'This field is required'; // Always return the standard message for required fields\n }\n\n // Skip other validations if value is empty and not required\n if (value === undefined || value === null || value === '') {\n return true;\n }\n\n // Validate string length\n if (typeof value === 'string') {\n if (validation.minLength && value.length < validation.minLength) {\n return `Minimum length is ${validation.minLength} characters`;\n }\n\n if (validation.maxLength && value.length > validation.maxLength) {\n return `Maximum length is ${validation.maxLength} characters`;\n }\n\n // Validate pattern\n if (validation.pattern) {\n const pattern =\n typeof validation.pattern === 'string'\n ? new RegExp(validation.pattern)\n : validation.pattern;\n\n if (!pattern.test(value)) {\n // Provide more specific error message for integer validation\n if (!INTEGER_PATTERN.test(value) && /\\d/.test(value)) {\n return 'Value must be a valid integer (no decimals)';\n }\n return 'Value does not match the required pattern';\n }\n }\n }\n\n // Validate number range\n if (typeof value === 'number' || (typeof value === 'string' && !isNaN(Number(value)))) {\n const numValue = typeof value === 'number' ? value : Number(value);\n\n if (validation.min !== undefined && numValue < validation.min) {\n return `Minimum value is ${validation.min}`;\n }\n\n if (validation.max !== undefined && numValue > validation.max) {\n return `Maximum value is ${validation.max}`;\n }\n }\n\n // Check field conditions if defined\n if (validation.conditions && validation.conditions.length > 0) {\n // Note: This would need the current form values to evaluate conditions\n // This is intended to be used with React Hook Form's validation context\n // Implementation would depend on how conditions are evaluated in the form context\n }\n\n // If all validations pass\n return true;\n}\n\n/**\n * Map validation utilities\n */\n\n/**\n * Checks if a map entry at the given index has a duplicate key\n * @param entries - Array of map entries\n * @param currentIndex - Index of the entry to check\n * @returns true if the key at currentIndex is duplicated elsewhere in the array\n */\nexport function isDuplicateMapKey(entries: MapEntry[], currentIndex: number): boolean {\n if (!Array.isArray(entries) || entries.length <= 1) {\n return false;\n }\n\n const currentKeyValue = entries[currentIndex]?.key;\n\n // Don't consider empty keys as duplicates\n if (!currentKeyValue || currentKeyValue === '') {\n return false;\n }\n\n // Prefer strict equality to avoid cross-type false positives (e.g., 123 vs \"123\")\n // Treat empty string as non-duplicate as above.\n return entries.some((entry: MapEntry, i: number) => {\n if (i === currentIndex) return false;\n const key = entry?.key;\n if (key === '') return false;\n // If both are strings, compare strings\n if (typeof key === 'string' && typeof currentKeyValue === 'string') {\n return key === currentKeyValue;\n }\n // If both are numbers, compare numbers\n if (typeof key === 'number' && typeof currentKeyValue === 'number') {\n return Number.isNaN(key) ? Number.isNaN(currentKeyValue) : key === currentKeyValue;\n }\n // If both are booleans\n if (typeof key === 'boolean' && typeof currentKeyValue === 'boolean') {\n return key === currentKeyValue;\n }\n // For objects (including dates) fall back to reference equality\n if (\n typeof key === 'object' &&\n key !== null &&\n typeof currentKeyValue === 'object' &&\n currentKeyValue !== null\n ) {\n return key === currentKeyValue;\n }\n // Otherwise, consider different types as different keys\n return false;\n });\n}\n\n/**\n * Validates an array of map entries for duplicate keys\n * @param entries - Array of map entries to validate\n * @returns Validation error message if duplicates found, otherwise undefined\n */\nexport function validateMapEntries(entries: MapEntry[]): string | undefined {\n if (!Array.isArray(entries) || entries.length <= 1) {\n return undefined;\n }\n\n const keys = entries\n .map((entry) => entry?.key)\n .filter((key) => key !== undefined && key !== null && key !== '');\n\n const keyStrings = keys.map((key) => String(key));\n const uniqueKeyStrings = new Set(keyStrings);\n\n if (keyStrings.length !== uniqueKeyStrings.size) {\n return 'Duplicate keys are not allowed';\n }\n\n return undefined;\n}\n","import React from 'react';\nimport { FieldError } from 'react-hook-form';\n\nimport { getErrorMessage } from './validation';\n\ninterface ErrorMessageProps {\n /**\n * The error object from React Hook Form\n */\n error?: FieldError;\n\n /**\n * The ID of the error message for aria-errormessage references\n */\n id: string;\n\n /**\n * Optional custom error message to display instead of the error from React Hook Form\n */\n message?: string;\n\n /**\n * Optional additional CSS classes\n */\n className?: string;\n}\n\n/**\n * Displays validation error messages for form fields\n */\nexport function ErrorMessage({\n error,\n id,\n message,\n className = '',\n}: ErrorMessageProps): React.ReactElement | null {\n const errorMessage = message || getErrorMessage(error);\n\n if (!errorMessage) return null;\n\n return (\n <div id={id} className={`text-destructive mt-1 text-sm ${className}`} role=\"alert\">\n {errorMessage}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAa,kBAAkB;;;;;;;AAQ/B,MAAa,wBAAwB;;;;;AAMrC,MAAa,uBAAuB;;;;;;;ACdpC,SAAgB,cAAc,OAAwC;AACpE,QAAO,CAAC,CAAC;;;;;AAMX,SAAgB,gBAAgB,OAAmD;AACjF,KAAI,CAAC,MAAO,QAAO;AAEnB,QAAO,MAAM,WAAW;;;;;AAM1B,SAAgB,sBACd,OACA,WACoB;AACpB,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,iBAAiB,YAAY,GAAG,UAAU,eAAe;AAE/D,QAAO,MAAM,WAAW;;;;;AAM1B,SAAgB,0BACd,OACA,SACQ;AACR,KAAI,MACF,QAAO;AAGT,KAAI,QACF,QAAO;AAGT,QAAO;;;;;AAMT,SAAgB,sBACd,OACA,IAMA;CACA,MAAM,WAAW,cAAc,MAAM;CACrC,MAAM,eAAe,gBAAgB,MAAM;AAI3C,QAAO;EACL,SAJc,GAAG,GAAG;EAKpB;EACA;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GACG"}
@@ -0,0 +1,170 @@
1
+ import React from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ //#region src/components/fields/utils/integerValidation.ts
5
+ /**
6
+ * Shared integer validation patterns for BigInt fields and validation utilities.
7
+ *
8
+ * These patterns ensure consistent validation across the application.
9
+ */
10
+ /**
11
+ * Integer validation pattern - requires at least one digit
12
+ * Used for validation to ensure complete integers are entered
13
+ * Matches: -123, 0, 456
14
+ * Does not match: -, abc, 12.3
15
+ */
16
+ const INTEGER_PATTERN = /^-?\d+$/;
17
+ /**
18
+ * Integer input pattern - allows partial input during typing
19
+ * Used during input to allow users to type minus sign first
20
+ * Matches: -, -1, 123, (empty string)
21
+ * Does not match: abc, 12.3
22
+ */
23
+ const INTEGER_INPUT_PATTERN = /^-?\d*$/;
24
+ /**
25
+ * HTML pattern attribute for integer inputs
26
+ * Must use [0-9] instead of \d for HTML5 pattern attribute
27
+ */
28
+ const INTEGER_HTML_PATTERN = "-?[0-9]*";
29
+
30
+ //#endregion
31
+ //#region src/components/fields/utils/validation.ts
32
+ /**
33
+ * Determines if a field has an error
34
+ */
35
+ function hasFieldError(error) {
36
+ return !!error;
37
+ }
38
+ /**
39
+ * Gets appropriate error message from field error
40
+ */
41
+ function getErrorMessage(error) {
42
+ if (!error) return void 0;
43
+ return error.message || "This field is invalid";
44
+ }
45
+ /**
46
+ * Formats validation error messages for display
47
+ */
48
+ function formatValidationError(error, fieldName) {
49
+ if (!error) return void 0;
50
+ const defaultMessage = fieldName ? `${fieldName} is invalid` : "This field is invalid";
51
+ return error.message || defaultMessage;
52
+ }
53
+ /**
54
+ * Generates common CSS classes for field validation states
55
+ */
56
+ function getValidationStateClasses(error, touched) {
57
+ if (error) return "border-destructive focus:border-destructive focus:ring-destructive/30";
58
+ if (touched) return "border-success focus:border-success focus:ring-success/30";
59
+ return "";
60
+ }
61
+ /**
62
+ * Helper for handling form validation errors with React Hook Form
63
+ */
64
+ function handleValidationError(error, id) {
65
+ const hasError = hasFieldError(error);
66
+ const errorMessage = getErrorMessage(error);
67
+ return {
68
+ errorId: `${id}-error`,
69
+ errorMessage,
70
+ hasError,
71
+ validationClasses: getValidationStateClasses(error)
72
+ };
73
+ }
74
+ /**
75
+ * Creates a validation result object for field components
76
+ */
77
+ function createValidationResult(id, error, touched) {
78
+ const hasError = hasFieldError(error);
79
+ const errorMessage = getErrorMessage(error);
80
+ const errorId = `${id}-error`;
81
+ return {
82
+ hasError,
83
+ errorMessage,
84
+ errorId,
85
+ validationClasses: getValidationStateClasses(error, touched),
86
+ "aria-invalid": hasError,
87
+ "aria-errormessage": hasError ? errorId : void 0
88
+ };
89
+ }
90
+ /**
91
+ * Generic field validation function that can be used to validate any field type
92
+ * based on common validation criteria
93
+ */
94
+ function validateField(value, validation) {
95
+ if (!validation) return true;
96
+ if (validation.required && (value === void 0 || value === null || value === "")) return typeof validation.required === "boolean" ? "This field is required" : "This field is required";
97
+ if (value === void 0 || value === null || value === "") return true;
98
+ if (typeof value === "string") {
99
+ if (validation.minLength && value.length < validation.minLength) return `Minimum length is ${validation.minLength} characters`;
100
+ if (validation.maxLength && value.length > validation.maxLength) return `Maximum length is ${validation.maxLength} characters`;
101
+ if (validation.pattern) {
102
+ if (!(typeof validation.pattern === "string" ? new RegExp(validation.pattern) : validation.pattern).test(value)) {
103
+ if (!INTEGER_PATTERN.test(value) && /\d/.test(value)) return "Value must be a valid integer (no decimals)";
104
+ return "Value does not match the required pattern";
105
+ }
106
+ }
107
+ }
108
+ if (typeof value === "number" || typeof value === "string" && !isNaN(Number(value))) {
109
+ const numValue = typeof value === "number" ? value : Number(value);
110
+ if (validation.min !== void 0 && numValue < validation.min) return `Minimum value is ${validation.min}`;
111
+ if (validation.max !== void 0 && numValue > validation.max) return `Maximum value is ${validation.max}`;
112
+ }
113
+ if (validation.conditions && validation.conditions.length > 0) {}
114
+ return true;
115
+ }
116
+ /**
117
+ * Map validation utilities
118
+ */
119
+ /**
120
+ * Checks if a map entry at the given index has a duplicate key
121
+ * @param entries - Array of map entries
122
+ * @param currentIndex - Index of the entry to check
123
+ * @returns true if the key at currentIndex is duplicated elsewhere in the array
124
+ */
125
+ function isDuplicateMapKey(entries, currentIndex) {
126
+ if (!Array.isArray(entries) || entries.length <= 1) return false;
127
+ const currentKeyValue = entries[currentIndex]?.key;
128
+ if (!currentKeyValue || currentKeyValue === "") return false;
129
+ return entries.some((entry, i) => {
130
+ if (i === currentIndex) return false;
131
+ const key = entry?.key;
132
+ if (key === "") return false;
133
+ if (typeof key === "string" && typeof currentKeyValue === "string") return key === currentKeyValue;
134
+ if (typeof key === "number" && typeof currentKeyValue === "number") return Number.isNaN(key) ? Number.isNaN(currentKeyValue) : key === currentKeyValue;
135
+ if (typeof key === "boolean" && typeof currentKeyValue === "boolean") return key === currentKeyValue;
136
+ if (typeof key === "object" && key !== null && typeof currentKeyValue === "object" && currentKeyValue !== null) return key === currentKeyValue;
137
+ return false;
138
+ });
139
+ }
140
+ /**
141
+ * Validates an array of map entries for duplicate keys
142
+ * @param entries - Array of map entries to validate
143
+ * @returns Validation error message if duplicates found, otherwise undefined
144
+ */
145
+ function validateMapEntries(entries) {
146
+ if (!Array.isArray(entries) || entries.length <= 1) return;
147
+ const keyStrings = entries.map((entry) => entry?.key).filter((key) => key !== void 0 && key !== null && key !== "").map((key) => String(key));
148
+ const uniqueKeyStrings = new Set(keyStrings);
149
+ if (keyStrings.length !== uniqueKeyStrings.size) return "Duplicate keys are not allowed";
150
+ }
151
+
152
+ //#endregion
153
+ //#region src/components/fields/utils/ErrorMessage.tsx
154
+ /**
155
+ * Displays validation error messages for form fields
156
+ */
157
+ function ErrorMessage({ error, id, message, className = "" }) {
158
+ const errorMessage = message || getErrorMessage(error);
159
+ if (!errorMessage) return null;
160
+ return /* @__PURE__ */ jsx("div", {
161
+ id,
162
+ className: `text-destructive mt-1 text-sm ${className}`,
163
+ role: "alert",
164
+ children: errorMessage
165
+ });
166
+ }
167
+
168
+ //#endregion
169
+ export { getValidationStateClasses as a, isDuplicateMapKey as c, INTEGER_HTML_PATTERN as d, INTEGER_INPUT_PATTERN as f, getErrorMessage as i, validateField as l, createValidationResult as n, handleValidationError as o, INTEGER_PATTERN as p, formatValidationError as r, hasFieldError as s, ErrorMessage as t, validateMapEntries as u };
170
+ //# sourceMappingURL=ErrorMessage-DyO9ZWWz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorMessage-DyO9ZWWz.js","names":[],"sources":["../src/components/fields/utils/integerValidation.ts","../src/components/fields/utils/validation.ts","../src/components/fields/utils/ErrorMessage.tsx"],"sourcesContent":["/**\n * Shared integer validation patterns for BigInt fields and validation utilities.\n *\n * These patterns ensure consistent validation across the application.\n */\n\n/**\n * Integer validation pattern - requires at least one digit\n * Used for validation to ensure complete integers are entered\n * Matches: -123, 0, 456\n * Does not match: -, abc, 12.3\n */\nexport const INTEGER_PATTERN = /^-?\\d+$/;\n\n/**\n * Integer input pattern - allows partial input during typing\n * Used during input to allow users to type minus sign first\n * Matches: -, -1, 123, (empty string)\n * Does not match: abc, 12.3\n */\nexport const INTEGER_INPUT_PATTERN = /^-?\\d*$/;\n\n/**\n * HTML pattern attribute for integer inputs\n * Must use [0-9] instead of \\d for HTML5 pattern attribute\n */\nexport const INTEGER_HTML_PATTERN = '-?[0-9]*';\n","/**\n * Validation and error handling utilities for form field components\n */\nimport { FieldError } from 'react-hook-form';\n\nimport { FieldValidation, MapEntry } from '@openzeppelin/ui-types';\n\nimport { INTEGER_PATTERN } from './integerValidation';\n\n/**\n * Determines if a field has an error\n */\nexport function hasFieldError(error: FieldError | undefined): boolean {\n return !!error;\n}\n\n/**\n * Gets appropriate error message from field error\n */\nexport function getErrorMessage(error: FieldError | undefined): string | undefined {\n if (!error) return undefined;\n\n return error.message || 'This field is invalid';\n}\n\n/**\n * Formats validation error messages for display\n */\nexport function formatValidationError(\n error: FieldError | undefined,\n fieldName?: string\n): string | undefined {\n if (!error) return undefined;\n\n const defaultMessage = fieldName ? `${fieldName} is invalid` : 'This field is invalid';\n\n return error.message || defaultMessage;\n}\n\n/**\n * Generates common CSS classes for field validation states\n */\nexport function getValidationStateClasses(\n error: FieldError | undefined,\n touched?: boolean\n): string {\n if (error) {\n return 'border-destructive focus:border-destructive focus:ring-destructive/30';\n }\n\n if (touched) {\n return 'border-success focus:border-success focus:ring-success/30';\n }\n\n return '';\n}\n\n/**\n * Helper for handling form validation errors with React Hook Form\n */\nexport function handleValidationError(\n error: FieldError | undefined,\n id: string\n): {\n errorId: string;\n errorMessage: string | undefined;\n hasError: boolean;\n validationClasses: string;\n} {\n const hasError = hasFieldError(error);\n const errorMessage = getErrorMessage(error);\n const errorId = `${id}-error`;\n const validationClasses = getValidationStateClasses(error);\n\n return {\n errorId,\n errorMessage,\n hasError,\n validationClasses,\n };\n}\n\n/**\n * Creates a validation result object for field components\n */\nexport function createValidationResult(\n id: string,\n error: FieldError | undefined,\n touched?: boolean\n): {\n hasError: boolean;\n errorMessage: string | undefined;\n errorId: string;\n validationClasses: string;\n 'aria-invalid': boolean;\n 'aria-errormessage'?: string;\n} {\n const hasError = hasFieldError(error);\n const errorMessage = getErrorMessage(error);\n const errorId = `${id}-error`;\n const validationClasses = getValidationStateClasses(error, touched);\n\n return {\n hasError,\n errorMessage,\n errorId,\n validationClasses,\n 'aria-invalid': hasError,\n 'aria-errormessage': hasError ? errorId : undefined,\n };\n}\n\n/**\n * Generic field validation function that can be used to validate any field type\n * based on common validation criteria\n */\nexport function validateField(value: unknown, validation?: FieldValidation): string | boolean {\n // Return true if no validation rules are provided\n if (!validation) return true;\n\n // Check if required but empty\n if (validation.required && (value === undefined || value === null || value === '')) {\n return typeof validation.required === 'boolean'\n ? 'This field is required'\n : 'This field is required'; // Always return the standard message for required fields\n }\n\n // Skip other validations if value is empty and not required\n if (value === undefined || value === null || value === '') {\n return true;\n }\n\n // Validate string length\n if (typeof value === 'string') {\n if (validation.minLength && value.length < validation.minLength) {\n return `Minimum length is ${validation.minLength} characters`;\n }\n\n if (validation.maxLength && value.length > validation.maxLength) {\n return `Maximum length is ${validation.maxLength} characters`;\n }\n\n // Validate pattern\n if (validation.pattern) {\n const pattern =\n typeof validation.pattern === 'string'\n ? new RegExp(validation.pattern)\n : validation.pattern;\n\n if (!pattern.test(value)) {\n // Provide more specific error message for integer validation\n if (!INTEGER_PATTERN.test(value) && /\\d/.test(value)) {\n return 'Value must be a valid integer (no decimals)';\n }\n return 'Value does not match the required pattern';\n }\n }\n }\n\n // Validate number range\n if (typeof value === 'number' || (typeof value === 'string' && !isNaN(Number(value)))) {\n const numValue = typeof value === 'number' ? value : Number(value);\n\n if (validation.min !== undefined && numValue < validation.min) {\n return `Minimum value is ${validation.min}`;\n }\n\n if (validation.max !== undefined && numValue > validation.max) {\n return `Maximum value is ${validation.max}`;\n }\n }\n\n // Check field conditions if defined\n if (validation.conditions && validation.conditions.length > 0) {\n // Note: This would need the current form values to evaluate conditions\n // This is intended to be used with React Hook Form's validation context\n // Implementation would depend on how conditions are evaluated in the form context\n }\n\n // If all validations pass\n return true;\n}\n\n/**\n * Map validation utilities\n */\n\n/**\n * Checks if a map entry at the given index has a duplicate key\n * @param entries - Array of map entries\n * @param currentIndex - Index of the entry to check\n * @returns true if the key at currentIndex is duplicated elsewhere in the array\n */\nexport function isDuplicateMapKey(entries: MapEntry[], currentIndex: number): boolean {\n if (!Array.isArray(entries) || entries.length <= 1) {\n return false;\n }\n\n const currentKeyValue = entries[currentIndex]?.key;\n\n // Don't consider empty keys as duplicates\n if (!currentKeyValue || currentKeyValue === '') {\n return false;\n }\n\n // Prefer strict equality to avoid cross-type false positives (e.g., 123 vs \"123\")\n // Treat empty string as non-duplicate as above.\n return entries.some((entry: MapEntry, i: number) => {\n if (i === currentIndex) return false;\n const key = entry?.key;\n if (key === '') return false;\n // If both are strings, compare strings\n if (typeof key === 'string' && typeof currentKeyValue === 'string') {\n return key === currentKeyValue;\n }\n // If both are numbers, compare numbers\n if (typeof key === 'number' && typeof currentKeyValue === 'number') {\n return Number.isNaN(key) ? Number.isNaN(currentKeyValue) : key === currentKeyValue;\n }\n // If both are booleans\n if (typeof key === 'boolean' && typeof currentKeyValue === 'boolean') {\n return key === currentKeyValue;\n }\n // For objects (including dates) fall back to reference equality\n if (\n typeof key === 'object' &&\n key !== null &&\n typeof currentKeyValue === 'object' &&\n currentKeyValue !== null\n ) {\n return key === currentKeyValue;\n }\n // Otherwise, consider different types as different keys\n return false;\n });\n}\n\n/**\n * Validates an array of map entries for duplicate keys\n * @param entries - Array of map entries to validate\n * @returns Validation error message if duplicates found, otherwise undefined\n */\nexport function validateMapEntries(entries: MapEntry[]): string | undefined {\n if (!Array.isArray(entries) || entries.length <= 1) {\n return undefined;\n }\n\n const keys = entries\n .map((entry) => entry?.key)\n .filter((key) => key !== undefined && key !== null && key !== '');\n\n const keyStrings = keys.map((key) => String(key));\n const uniqueKeyStrings = new Set(keyStrings);\n\n if (keyStrings.length !== uniqueKeyStrings.size) {\n return 'Duplicate keys are not allowed';\n }\n\n return undefined;\n}\n","import React from 'react';\nimport { FieldError } from 'react-hook-form';\n\nimport { getErrorMessage } from './validation';\n\ninterface ErrorMessageProps {\n /**\n * The error object from React Hook Form\n */\n error?: FieldError;\n\n /**\n * The ID of the error message for aria-errormessage references\n */\n id: string;\n\n /**\n * Optional custom error message to display instead of the error from React Hook Form\n */\n message?: string;\n\n /**\n * Optional additional CSS classes\n */\n className?: string;\n}\n\n/**\n * Displays validation error messages for form fields\n */\nexport function ErrorMessage({\n error,\n id,\n message,\n className = '',\n}: ErrorMessageProps): React.ReactElement | null {\n const errorMessage = message || getErrorMessage(error);\n\n if (!errorMessage) return null;\n\n return (\n <div id={id} className={`text-destructive mt-1 text-sm ${className}`} role=\"alert\">\n {errorMessage}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAa,kBAAkB;;;;;;;AAQ/B,MAAa,wBAAwB;;;;;AAMrC,MAAa,uBAAuB;;;;;;;ACdpC,SAAgB,cAAc,OAAwC;AACpE,QAAO,CAA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QAAQ,QAAQ,IAAI,QAAQ,UAAU,EAC/C;CAOF,MAAM,aAJO,QACV,KAAK,UAAU,OAAO,IAAI,CAC1B,QAAQ,QAAQ,QAAQ,UAAa,QAAQ,QAAQ,QAAQ,GAAG,CAE3C,KAAK,QAAQ,OAAO,IAAI,CAAC;CACjD,MAAM,mBAAmB,IAAI,IAAI,WAAW;AAE5C,KAAI,WAAW,WAAW,iBAAiB,KACzC,QAAO;;;;;;;;ACjOX,SAAgB,aAAa,EAC3B,OACA,IACA,SACA,YAAY,MACmC;CAC/C,MAAM,eAAe,WAAW,gBAAgB,MAAM;AAEtD,KAAI,CAAC,aAAc,QAAO;AAE1B,QACE,oBAAC;EAAQ;EAAI,WAAW,iCAAiC;EAAa,MAAK;YACxE;GACG"}
@@ -0,0 +1,122 @@
1
+ import React from "react";
2
+ import { Control, FieldValues, Path } from "react-hook-form";
3
+
4
+ //#region src/components/fields/CodeEditorField.d.ts
5
+
6
+ /**
7
+ * CodeEditorField component properties
8
+ */
9
+ interface CodeEditorFieldProps<TFieldValues extends FieldValues = FieldValues> {
10
+ /**
11
+ * Unique identifier for the field
12
+ */
13
+ id: string;
14
+ /**
15
+ * Optional CSS class name for the container
16
+ */
17
+ className?: string;
18
+ /**
19
+ * Field name for form control
20
+ */
21
+ name: Path<TFieldValues>;
22
+ /**
23
+ * React Hook Form control object
24
+ */
25
+ control: Control<TFieldValues>;
26
+ /**
27
+ * Field label
28
+ */
29
+ label?: string;
30
+ /**
31
+ * Helper text displayed below the field
32
+ */
33
+ helperText?: string;
34
+ /**
35
+ * Placeholder text when empty
36
+ */
37
+ placeholder?: string;
38
+ /**
39
+ * Programming language for syntax highlighting
40
+ */
41
+ language?: string;
42
+ /**
43
+ * Editor theme
44
+ */
45
+ theme?: string;
46
+ /**
47
+ * Editor height
48
+ */
49
+ height?: string;
50
+ /**
51
+ * Editor maximum height (with scrollbar for overflow)
52
+ */
53
+ maxHeight?: string;
54
+ /**
55
+ * Content size threshold for disabling syntax highlighting (default: 5000 chars)
56
+ */
57
+ performanceThreshold?: number;
58
+ /**
59
+ * Whether the field is required
60
+ */
61
+ required?: boolean;
62
+ /**
63
+ * Whether the field is disabled
64
+ */
65
+ disabled?: boolean;
66
+ /**
67
+ * Whether the field is read-only
68
+ */
69
+ readOnly?: boolean;
70
+ /**
71
+ * Custom validation function for code values
72
+ */
73
+ validateCode?: (value: string) => boolean | string;
74
+ }
75
+ /**
76
+ * CodeEditorField provides syntax-highlighted code editing with form integration.
77
+ *
78
+ * Features:
79
+ * - Syntax highlighting via @uiw/react-textarea-code-editor
80
+ * - React Hook Form integration with Controller
81
+ * - Configurable language support (JSON, TypeScript, etc.)
82
+ * - Performance optimizations with smart highlighting
83
+ * - Constrained height with automatic scrolling
84
+ * - Design system styling integration
85
+ *
86
+ * @example
87
+ * ```tsx
88
+ * <CodeEditorField
89
+ * id="contractAbi"
90
+ * name="contractSchema"
91
+ * control={control}
92
+ * label="Contract ABI"
93
+ * language="json"
94
+ * placeholder="Paste your ABI JSON here..."
95
+ * />
96
+ * ```
97
+ */
98
+ declare function CodeEditorField<TFieldValues extends FieldValues = FieldValues>({
99
+ id,
100
+ name,
101
+ control,
102
+ label,
103
+ helperText,
104
+ placeholder,
105
+ language,
106
+ theme,
107
+ height,
108
+ maxHeight,
109
+ performanceThreshold,
110
+ required,
111
+ disabled,
112
+ readOnly,
113
+ validateCode,
114
+ className
115
+ }: CodeEditorFieldProps<TFieldValues>): React.ReactElement;
116
+ declare namespace CodeEditorField {
117
+ var displayName: string;
118
+ }
119
+ //# sourceMappingURL=CodeEditorField.d.ts.map
120
+ //#endregion
121
+ export { CodeEditorField, CodeEditorFieldProps };
122
+ //# sourceMappingURL=code-editor-BKEEXGxt.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-BKEEXGxt.d.cts","names":[],"sources":["../src/components/fields/CodeEditorField.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAUA;AAAqC,UAApB,oBAAoB,CAAA,qBAAsB,WAAtB,GAAoC,WAApC,CAAA,CAAA;;;;MAc7B,MAAA;;;;EA2FQ,SAAA,CAAA,EAAA,MAAe;EAAA;;;MAC7B,EA5FM,IA4FN,CA5FW,YA4FX,CAAA;;;;SAIA,EA3FS,OA2FT,CA3FiB,YA2FjB,CAAA;;;;OAIA,CAAA,EAAA,MAAA;;;;YAIA,CAAA,EAAA,MAAA;;;;aAIsB,CAAA,EAAA,MAAA;;;;EAjBR,QAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAA,qCAAqC,cAAc;;;;;;;;;;;;;;;;;GAiBhE,qBAAqB,gBAAgB,KAAA,CAAM;kBAjB9B,eAAA"}