easy-forms-core 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/easy-form.d.ts +10 -2
- package/dist/easy-form.js +122 -1
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.js +122 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/easy-form.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tipos de campos soportados
|
|
3
3
|
*/
|
|
4
|
-
type FieldType = 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'switch' | 'date' | 'file' | 'array' | 'group' | 'row' | 'custom' | 'quantity' | 'accordion-select' | 'image-grid-select' | 'otp' | 'file-drop' | 'map' | 'rating' | 'slider';
|
|
4
|
+
type FieldType = 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'switch' | 'date' | 'file' | 'array' | 'group' | 'row' | 'custom' | 'quantity' | 'accordion-select' | 'image-grid-select' | 'otp' | 'file-drop' | 'map' | 'rating' | 'slider' | 'colorpicker';
|
|
5
5
|
/**
|
|
6
6
|
* Tipos de validaciones soportadas
|
|
7
7
|
*/
|
|
@@ -248,6 +248,14 @@ interface SliderField extends BaseField {
|
|
|
248
248
|
step?: number;
|
|
249
249
|
showValue?: boolean;
|
|
250
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Campo colorpicker (selección de color hex)
|
|
253
|
+
*/
|
|
254
|
+
interface ColorpickerField extends BaseField {
|
|
255
|
+
type: 'colorpicker';
|
|
256
|
+
/** Valor por defecto en hex (ej. #6366f1). Default: #000000 */
|
|
257
|
+
defaultValue?: string;
|
|
258
|
+
}
|
|
251
259
|
/**
|
|
252
260
|
* Campo array
|
|
253
261
|
*/
|
|
@@ -332,7 +340,7 @@ interface OTPField extends BaseField {
|
|
|
332
340
|
/**
|
|
333
341
|
* Unión de todos los tipos de campos
|
|
334
342
|
*/
|
|
335
|
-
type Field = TextField | PasswordField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | FileDropField | MapField | RatingField | SliderField | ArrayField | GroupField | RowField | CustomField | QuantityField | AccordionSelectField | ImageGridSelectField | OTPField;
|
|
343
|
+
type Field = TextField | PasswordField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | FileDropField | MapField | RatingField | SliderField | ColorpickerField | ArrayField | GroupField | RowField | CustomField | QuantityField | AccordionSelectField | ImageGridSelectField | OTPField;
|
|
336
344
|
/**
|
|
337
345
|
* Step para formularios wizard
|
|
338
346
|
*/
|
package/dist/easy-form.js
CHANGED
|
@@ -63,6 +63,7 @@ var SchemaParser = class {
|
|
|
63
63
|
"map",
|
|
64
64
|
"rating",
|
|
65
65
|
"slider",
|
|
66
|
+
"colorpicker",
|
|
66
67
|
"array",
|
|
67
68
|
"group",
|
|
68
69
|
"row",
|
|
@@ -109,6 +110,16 @@ var SchemaParser = class {
|
|
|
109
110
|
);
|
|
110
111
|
}
|
|
111
112
|
break;
|
|
113
|
+
case "colorpicker":
|
|
114
|
+
if ("defaultValue" in field && field.defaultValue != null) {
|
|
115
|
+
const hex = /^#[0-9A-Fa-f]{6}$/;
|
|
116
|
+
if (!hex.test(String(field.defaultValue))) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Field "${field.name}" de tipo colorpicker debe tener defaultValue en formato hex (#RRGGBB)`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
125
|
/**
|
|
@@ -178,6 +189,11 @@ var SchemaParser = class {
|
|
|
178
189
|
defaults.max = 5;
|
|
179
190
|
}
|
|
180
191
|
break;
|
|
192
|
+
case "colorpicker":
|
|
193
|
+
if (!("defaultValue" in field) || field.defaultValue == null) {
|
|
194
|
+
defaults.defaultValue = "#000000";
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
181
197
|
}
|
|
182
198
|
return { ...defaults, ...field };
|
|
183
199
|
}
|
|
@@ -311,6 +327,46 @@ function getBaseStyles(colors) {
|
|
|
311
327
|
min-width: 2rem;
|
|
312
328
|
font-weight: 500;
|
|
313
329
|
}
|
|
330
|
+
.easy-form-color-wrapper {
|
|
331
|
+
display: flex;
|
|
332
|
+
align-items: center;
|
|
333
|
+
gap: 0.75rem;
|
|
334
|
+
}
|
|
335
|
+
.easy-form-color-wrapper input[type="color"] {
|
|
336
|
+
width: 2.2rem;
|
|
337
|
+
height: 2.2rem;
|
|
338
|
+
min-width: 2.2rem;
|
|
339
|
+
min-height: 2.2rem;
|
|
340
|
+
padding: 0 !important;
|
|
341
|
+
margin: 0;
|
|
342
|
+
cursor: pointer;
|
|
343
|
+
border: 1px solid var(--easy-form-border);
|
|
344
|
+
border-radius: 2px;
|
|
345
|
+
background: transparent;
|
|
346
|
+
flex-shrink: 0;
|
|
347
|
+
}
|
|
348
|
+
.easy-form-color-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
|
|
349
|
+
padding: 0;
|
|
350
|
+
}
|
|
351
|
+
.easy-form-color-wrapper input[type="color"]::-webkit-color-swatch {
|
|
352
|
+
border: none;
|
|
353
|
+
border-radius: 1px;
|
|
354
|
+
}
|
|
355
|
+
.easy-form-color-wrapper input[type="color"]::-moz-color-swatch {
|
|
356
|
+
border: none;
|
|
357
|
+
border-radius: 1px;
|
|
358
|
+
}
|
|
359
|
+
.easy-form-color-text {
|
|
360
|
+
flex: 1;
|
|
361
|
+
min-width: 0;
|
|
362
|
+
color: var(--easy-form-text);
|
|
363
|
+
background: var(--easy-form-background);
|
|
364
|
+
border: 1px solid var(--easy-form-border);
|
|
365
|
+
border-radius: 4px;
|
|
366
|
+
padding: 0.5rem 0.75rem;
|
|
367
|
+
font-family: ui-monospace, 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
|
|
368
|
+
font-size: 0.875rem;
|
|
369
|
+
}
|
|
314
370
|
.easy-form-rating {
|
|
315
371
|
display: inline-flex;
|
|
316
372
|
gap: 0.25rem;
|
|
@@ -431,7 +487,7 @@ function getBaseStyles(colors) {
|
|
|
431
487
|
.easy-form-submit-wrapper .easy-form-submit {
|
|
432
488
|
min-width: 100px;
|
|
433
489
|
}
|
|
434
|
-
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
|
|
490
|
+
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), textarea, select {
|
|
435
491
|
width: 100%;
|
|
436
492
|
padding: 0.5rem;
|
|
437
493
|
font-size: 1rem;
|
|
@@ -2696,6 +2752,9 @@ var StateManager = class {
|
|
|
2696
2752
|
}
|
|
2697
2753
|
}
|
|
2698
2754
|
break;
|
|
2755
|
+
case "colorpicker":
|
|
2756
|
+
values[field.name] = field.defaultValue ?? "#000000";
|
|
2757
|
+
break;
|
|
2699
2758
|
default:
|
|
2700
2759
|
values[field.name] = null;
|
|
2701
2760
|
}
|
|
@@ -4934,6 +4993,66 @@ var SliderInput = class extends BaseInput {
|
|
|
4934
4993
|
}
|
|
4935
4994
|
};
|
|
4936
4995
|
|
|
4996
|
+
// src/components/inputs/color-input.ts
|
|
4997
|
+
var HEX_REGEX = /^#?([0-9A-Fa-f]{6})$/;
|
|
4998
|
+
function toHex(value) {
|
|
4999
|
+
const m = value.match(HEX_REGEX);
|
|
5000
|
+
if (m) return `#${m[1].toLowerCase()}`;
|
|
5001
|
+
if (/^[0-9A-Fa-f]{6}$/.test(value)) return `#${value.toLowerCase()}`;
|
|
5002
|
+
return "#000000";
|
|
5003
|
+
}
|
|
5004
|
+
var ColorInput = class extends BaseInput {
|
|
5005
|
+
render() {
|
|
5006
|
+
const colorField = this.field;
|
|
5007
|
+
const defaultValue = colorField.defaultValue ?? "#000000";
|
|
5008
|
+
const currentValue = this.value != null && typeof this.value === "string" ? toHex(this.value) : defaultValue;
|
|
5009
|
+
const wrapper = document.createElement("div");
|
|
5010
|
+
wrapper.className = "easy-form-color-wrapper";
|
|
5011
|
+
const colorPicker = document.createElement("input");
|
|
5012
|
+
colorPicker.type = "color";
|
|
5013
|
+
colorPicker.value = currentValue;
|
|
5014
|
+
colorPicker.setAttribute("value", currentValue);
|
|
5015
|
+
colorPicker.setAttribute("aria-label", this.field.label || "Color");
|
|
5016
|
+
colorPicker.id = `${this.getFieldId()}-picker`;
|
|
5017
|
+
if (this.field.disabled) colorPicker.setAttribute("disabled", "true");
|
|
5018
|
+
const textInput = document.createElement("input");
|
|
5019
|
+
textInput.type = "text";
|
|
5020
|
+
textInput.value = currentValue;
|
|
5021
|
+
textInput.setAttribute("aria-label", `${this.field.label || "Color"} (hex)`);
|
|
5022
|
+
textInput.placeholder = "#000000";
|
|
5023
|
+
textInput.className = "easy-form-color-text";
|
|
5024
|
+
this.applyCommonProps(textInput);
|
|
5025
|
+
const syncFromPicker = () => {
|
|
5026
|
+
const value = colorPicker.value || "#000000";
|
|
5027
|
+
const hex = toHex(value);
|
|
5028
|
+
textInput.value = hex;
|
|
5029
|
+
this.onChange(hex);
|
|
5030
|
+
};
|
|
5031
|
+
const syncFromText = () => {
|
|
5032
|
+
const raw = textInput.value.trim();
|
|
5033
|
+
const value = raw.startsWith("#") ? raw : `#${raw}`;
|
|
5034
|
+
if (/^#[0-9A-Fa-f]{6}$/.test(value)) {
|
|
5035
|
+
const hex = toHex(value);
|
|
5036
|
+
colorPicker.value = hex;
|
|
5037
|
+
this.onChange(hex);
|
|
5038
|
+
}
|
|
5039
|
+
};
|
|
5040
|
+
colorPicker.addEventListener("input", syncFromPicker);
|
|
5041
|
+
colorPicker.addEventListener("change", () => {
|
|
5042
|
+
syncFromPicker();
|
|
5043
|
+
this.onBlur();
|
|
5044
|
+
});
|
|
5045
|
+
textInput.addEventListener("input", syncFromText);
|
|
5046
|
+
textInput.addEventListener("blur", () => {
|
|
5047
|
+
syncFromText();
|
|
5048
|
+
this.onBlur();
|
|
5049
|
+
});
|
|
5050
|
+
wrapper.appendChild(colorPicker);
|
|
5051
|
+
wrapper.appendChild(textInput);
|
|
5052
|
+
return this.createFieldContainer(wrapper);
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
|
|
4937
5056
|
// src/components/inputs/index.ts
|
|
4938
5057
|
function createInput(field, value, error, onChange, onBlur) {
|
|
4939
5058
|
switch (field.type) {
|
|
@@ -4966,6 +5085,8 @@ function createInput(field, value, error, onChange, onBlur) {
|
|
|
4966
5085
|
return new RatingInput(field, value, error, onChange, onBlur).render();
|
|
4967
5086
|
case "slider":
|
|
4968
5087
|
return new SliderInput(field, value, error, onChange, onBlur).render();
|
|
5088
|
+
case "colorpicker":
|
|
5089
|
+
return new ColorInput(field, value, error, onChange, onBlur).render();
|
|
4969
5090
|
case "quantity":
|
|
4970
5091
|
return new QuantityInput(field, value, error, onChange, onBlur).render();
|
|
4971
5092
|
case "accordion-select":
|