@dmitryvim/form-builder 0.2.12 → 0.2.14
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/browser/formbuilder.min.js +74 -74
- package/dist/browser/{formbuilder.v0.2.12.min.js → formbuilder.v0.2.14.min.js} +74 -74
- package/dist/cjs/index.cjs +78 -82
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +78 -82
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +74 -74
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -61,13 +61,6 @@ function addFormatHint(element, parts, state) {
|
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function addRequiredHint(element, parts, state) {
|
|
65
|
-
if (element.required) {
|
|
66
|
-
parts.push(t("hintRequired", state));
|
|
67
|
-
} else {
|
|
68
|
-
parts.push(t("hintOptional", state));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
64
|
function addPatternHint(element, parts, state) {
|
|
72
65
|
if (element.pattern) {
|
|
73
66
|
parts.push(t("hintPattern", state, { pattern: element.pattern }));
|
|
@@ -75,7 +68,6 @@ function addPatternHint(element, parts, state) {
|
|
|
75
68
|
}
|
|
76
69
|
function makeFieldHint(element, state) {
|
|
77
70
|
const parts = [];
|
|
78
|
-
addRequiredHint(element, parts, state);
|
|
79
71
|
addLengthHint(element, parts, state);
|
|
80
72
|
if (element.type !== "slider") {
|
|
81
73
|
addRangeHint(element, parts, state);
|
|
@@ -910,10 +902,10 @@ function updateTextareaField(element, fieldPath, value, context) {
|
|
|
910
902
|
}
|
|
911
903
|
|
|
912
904
|
// src/components/number.ts
|
|
913
|
-
function
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
|
|
905
|
+
function createNumberRangeHint(element, input) {
|
|
906
|
+
const hint = document.createElement("span");
|
|
907
|
+
hint.className = "number-range-hint";
|
|
908
|
+
hint.style.cssText = `
|
|
917
909
|
position: absolute;
|
|
918
910
|
top: 50%;
|
|
919
911
|
transform: translateY(-50%);
|
|
@@ -924,38 +916,30 @@ function createNumberCounter(element, input) {
|
|
|
924
916
|
background: var(--fb-background-color);
|
|
925
917
|
padding: 0 4px;
|
|
926
918
|
`;
|
|
927
|
-
const
|
|
919
|
+
const min = element.min;
|
|
920
|
+
const max = element.max;
|
|
921
|
+
let rangeText = "";
|
|
922
|
+
if (min != null && max != null) {
|
|
923
|
+
rangeText = `${min} \u2013 ${max}`;
|
|
924
|
+
} else if (max != null) {
|
|
925
|
+
rangeText = `\u2264${max}`;
|
|
926
|
+
} else if (min != null) {
|
|
927
|
+
rangeText = `\u2265${min}`;
|
|
928
|
+
}
|
|
929
|
+
hint.textContent = rangeText;
|
|
930
|
+
const updateColor = () => {
|
|
928
931
|
const val = input.value ? parseFloat(input.value) : null;
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
|
-
if (val == null || min != null && val < min) {
|
|
936
|
-
if (min != null && max != null) {
|
|
937
|
-
counter.textContent = `${min}-${max}`;
|
|
938
|
-
} else if (max != null) {
|
|
939
|
-
counter.textContent = `\u2264${max}`;
|
|
940
|
-
} else if (min != null) {
|
|
941
|
-
counter.textContent = `\u2265${min}`;
|
|
942
|
-
}
|
|
943
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
944
|
-
} else if (max != null && val > max) {
|
|
945
|
-
counter.textContent = `${val}/${max}`;
|
|
946
|
-
counter.style.color = "var(--fb-error-color)";
|
|
932
|
+
if (val != null) {
|
|
933
|
+
const belowMin = min != null && val < min;
|
|
934
|
+
const aboveMax = max != null && val > max;
|
|
935
|
+
hint.style.color = belowMin || aboveMax ? "var(--fb-error-color)" : "var(--fb-text-secondary-color)";
|
|
947
936
|
} else {
|
|
948
|
-
|
|
949
|
-
counter.textContent = `${val}/${max}`;
|
|
950
|
-
} else {
|
|
951
|
-
counter.textContent = `${val}`;
|
|
952
|
-
}
|
|
953
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
937
|
+
hint.style.color = "var(--fb-text-secondary-color)";
|
|
954
938
|
}
|
|
955
939
|
};
|
|
956
|
-
input.addEventListener("input",
|
|
957
|
-
|
|
958
|
-
return
|
|
940
|
+
input.addEventListener("input", updateColor);
|
|
941
|
+
updateColor();
|
|
942
|
+
return hint;
|
|
959
943
|
}
|
|
960
944
|
function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
961
945
|
const state = ctx.state;
|
|
@@ -982,7 +966,7 @@ function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
982
966
|
}
|
|
983
967
|
inputWrapper.appendChild(numberInput);
|
|
984
968
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
985
|
-
const counter =
|
|
969
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
986
970
|
inputWrapper.appendChild(counter);
|
|
987
971
|
}
|
|
988
972
|
wrapper.appendChild(inputWrapper);
|
|
@@ -1034,7 +1018,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
1034
1018
|
}
|
|
1035
1019
|
inputContainer.appendChild(numberInput);
|
|
1036
1020
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
1037
|
-
const counter =
|
|
1021
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
1038
1022
|
inputContainer.appendChild(counter);
|
|
1039
1023
|
}
|
|
1040
1024
|
itemWrapper.appendChild(inputContainer);
|
|
@@ -1309,10 +1293,12 @@ function renderSelectElement(element, ctx, wrapper, pathKey) {
|
|
|
1309
1293
|
selectInput.addEventListener("change", handleChange);
|
|
1310
1294
|
}
|
|
1311
1295
|
wrapper.appendChild(selectInput);
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1296
|
+
if (!state.config.readonly) {
|
|
1297
|
+
const selectHint = document.createElement("p");
|
|
1298
|
+
selectHint.className = "text-xs text-gray-500 mt-1";
|
|
1299
|
+
selectHint.textContent = makeFieldHint(element, state);
|
|
1300
|
+
wrapper.appendChild(selectHint);
|
|
1301
|
+
}
|
|
1316
1302
|
}
|
|
1317
1303
|
function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
|
|
1318
1304
|
var _a, _b, _c, _d;
|
|
@@ -1447,10 +1433,12 @@ function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
|
|
|
1447
1433
|
values.forEach((value) => addSelectItem(value));
|
|
1448
1434
|
updateAddButton();
|
|
1449
1435
|
updateRemoveButtons();
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1436
|
+
if (!state.config.readonly) {
|
|
1437
|
+
const hint = document.createElement("p");
|
|
1438
|
+
hint.className = "text-xs text-gray-500 mt-1";
|
|
1439
|
+
hint.textContent = makeFieldHint(element, state);
|
|
1440
|
+
wrapper.appendChild(hint);
|
|
1441
|
+
}
|
|
1454
1442
|
}
|
|
1455
1443
|
function validateSelectElement(element, key, context) {
|
|
1456
1444
|
var _a;
|
|
@@ -2897,14 +2885,16 @@ function renderColourElement(element, ctx, wrapper, pathKey) {
|
|
|
2897
2885
|
const editUI = createEditColourUI(initialValue, pathKey, ctx);
|
|
2898
2886
|
wrapper.appendChild(editUI);
|
|
2899
2887
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2888
|
+
if (!state.config.readonly) {
|
|
2889
|
+
const colourHint = document.createElement("p");
|
|
2890
|
+
colourHint.className = "mt-1";
|
|
2891
|
+
colourHint.style.cssText = `
|
|
2892
|
+
font-size: var(--fb-font-size-small);
|
|
2893
|
+
color: var(--fb-text-secondary-color);
|
|
2894
|
+
`;
|
|
2895
|
+
colourHint.textContent = makeFieldHint(element, state);
|
|
2896
|
+
wrapper.appendChild(colourHint);
|
|
2897
|
+
}
|
|
2908
2898
|
}
|
|
2909
2899
|
function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
|
|
2910
2900
|
var _a, _b;
|
|
@@ -3043,14 +3033,16 @@ function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
|
|
|
3043
3033
|
values.forEach((value) => addColourItem(value));
|
|
3044
3034
|
updateAddButton();
|
|
3045
3035
|
updateRemoveButtons();
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3036
|
+
if (!state.config.readonly) {
|
|
3037
|
+
const hint = document.createElement("p");
|
|
3038
|
+
hint.className = "mt-1";
|
|
3039
|
+
hint.style.cssText = `
|
|
3040
|
+
font-size: var(--fb-font-size-small);
|
|
3041
|
+
color: var(--fb-text-secondary-color);
|
|
3042
|
+
`;
|
|
3043
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3044
|
+
wrapper.appendChild(hint);
|
|
3045
|
+
}
|
|
3054
3046
|
}
|
|
3055
3047
|
function validateColourElement(element, key, context) {
|
|
3056
3048
|
var _a, _b, _c;
|
|
@@ -3367,14 +3359,16 @@ function renderSliderElement(element, ctx, wrapper, pathKey) {
|
|
|
3367
3359
|
state.config.readonly
|
|
3368
3360
|
);
|
|
3369
3361
|
wrapper.appendChild(sliderUI);
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3362
|
+
if (!state.config.readonly) {
|
|
3363
|
+
const hint = document.createElement("p");
|
|
3364
|
+
hint.className = "mt-1";
|
|
3365
|
+
hint.style.cssText = `
|
|
3366
|
+
font-size: var(--fb-font-size-small);
|
|
3367
|
+
color: var(--fb-text-secondary-color);
|
|
3368
|
+
`;
|
|
3369
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3370
|
+
wrapper.appendChild(hint);
|
|
3371
|
+
}
|
|
3378
3372
|
}
|
|
3379
3373
|
function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
|
|
3380
3374
|
var _a, _b;
|
|
@@ -3524,14 +3518,16 @@ function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
|
|
|
3524
3518
|
values.forEach((value) => addSliderItem(value));
|
|
3525
3519
|
updateAddButton();
|
|
3526
3520
|
updateRemoveButtons();
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3521
|
+
if (!state.config.readonly) {
|
|
3522
|
+
const hint = document.createElement("p");
|
|
3523
|
+
hint.className = "mt-1";
|
|
3524
|
+
hint.style.cssText = `
|
|
3525
|
+
font-size: var(--fb-font-size-small);
|
|
3526
|
+
color: var(--fb-text-secondary-color);
|
|
3527
|
+
`;
|
|
3528
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3529
|
+
wrapper.appendChild(hint);
|
|
3530
|
+
}
|
|
3535
3531
|
}
|
|
3536
3532
|
function validateSliderElement(element, key, context) {
|
|
3537
3533
|
var _a, _b, _c;
|