@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/esm/index.js
CHANGED
|
@@ -56,13 +56,6 @@ function addFormatHint(element, parts, state) {
|
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
function addRequiredHint(element, parts, state) {
|
|
60
|
-
if (element.required) {
|
|
61
|
-
parts.push(t("hintRequired", state));
|
|
62
|
-
} else {
|
|
63
|
-
parts.push(t("hintOptional", state));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
59
|
function addPatternHint(element, parts, state) {
|
|
67
60
|
if (element.pattern) {
|
|
68
61
|
parts.push(t("hintPattern", state, { pattern: element.pattern }));
|
|
@@ -70,7 +63,6 @@ function addPatternHint(element, parts, state) {
|
|
|
70
63
|
}
|
|
71
64
|
function makeFieldHint(element, state) {
|
|
72
65
|
const parts = [];
|
|
73
|
-
addRequiredHint(element, parts, state);
|
|
74
66
|
addLengthHint(element, parts, state);
|
|
75
67
|
if (element.type !== "slider") {
|
|
76
68
|
addRangeHint(element, parts, state);
|
|
@@ -899,10 +891,10 @@ function updateTextareaField(element, fieldPath, value, context) {
|
|
|
899
891
|
}
|
|
900
892
|
|
|
901
893
|
// src/components/number.ts
|
|
902
|
-
function
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
894
|
+
function createNumberRangeHint(element, input) {
|
|
895
|
+
const hint = document.createElement("span");
|
|
896
|
+
hint.className = "number-range-hint";
|
|
897
|
+
hint.style.cssText = `
|
|
906
898
|
position: absolute;
|
|
907
899
|
top: 50%;
|
|
908
900
|
transform: translateY(-50%);
|
|
@@ -913,38 +905,30 @@ function createNumberCounter(element, input) {
|
|
|
913
905
|
background: var(--fb-background-color);
|
|
914
906
|
padding: 0 4px;
|
|
915
907
|
`;
|
|
916
|
-
const
|
|
908
|
+
const min = element.min;
|
|
909
|
+
const max = element.max;
|
|
910
|
+
let rangeText = "";
|
|
911
|
+
if (min != null && max != null) {
|
|
912
|
+
rangeText = `${min} \u2013 ${max}`;
|
|
913
|
+
} else if (max != null) {
|
|
914
|
+
rangeText = `\u2264${max}`;
|
|
915
|
+
} else if (min != null) {
|
|
916
|
+
rangeText = `\u2265${min}`;
|
|
917
|
+
}
|
|
918
|
+
hint.textContent = rangeText;
|
|
919
|
+
const updateColor = () => {
|
|
917
920
|
const val = input.value ? parseFloat(input.value) : null;
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
if (val == null || min != null && val < min) {
|
|
925
|
-
if (min != null && max != null) {
|
|
926
|
-
counter.textContent = `${min}-${max}`;
|
|
927
|
-
} else if (max != null) {
|
|
928
|
-
counter.textContent = `\u2264${max}`;
|
|
929
|
-
} else if (min != null) {
|
|
930
|
-
counter.textContent = `\u2265${min}`;
|
|
931
|
-
}
|
|
932
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
933
|
-
} else if (max != null && val > max) {
|
|
934
|
-
counter.textContent = `${val}/${max}`;
|
|
935
|
-
counter.style.color = "var(--fb-error-color)";
|
|
921
|
+
if (val != null) {
|
|
922
|
+
const belowMin = min != null && val < min;
|
|
923
|
+
const aboveMax = max != null && val > max;
|
|
924
|
+
hint.style.color = belowMin || aboveMax ? "var(--fb-error-color)" : "var(--fb-text-secondary-color)";
|
|
936
925
|
} else {
|
|
937
|
-
|
|
938
|
-
counter.textContent = `${val}/${max}`;
|
|
939
|
-
} else {
|
|
940
|
-
counter.textContent = `${val}`;
|
|
941
|
-
}
|
|
942
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
926
|
+
hint.style.color = "var(--fb-text-secondary-color)";
|
|
943
927
|
}
|
|
944
928
|
};
|
|
945
|
-
input.addEventListener("input",
|
|
946
|
-
|
|
947
|
-
return
|
|
929
|
+
input.addEventListener("input", updateColor);
|
|
930
|
+
updateColor();
|
|
931
|
+
return hint;
|
|
948
932
|
}
|
|
949
933
|
function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
950
934
|
const state = ctx.state;
|
|
@@ -971,7 +955,7 @@ function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
971
955
|
}
|
|
972
956
|
inputWrapper.appendChild(numberInput);
|
|
973
957
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
974
|
-
const counter =
|
|
958
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
975
959
|
inputWrapper.appendChild(counter);
|
|
976
960
|
}
|
|
977
961
|
wrapper.appendChild(inputWrapper);
|
|
@@ -1022,7 +1006,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
1022
1006
|
}
|
|
1023
1007
|
inputContainer.appendChild(numberInput);
|
|
1024
1008
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
1025
|
-
const counter =
|
|
1009
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
1026
1010
|
inputContainer.appendChild(counter);
|
|
1027
1011
|
}
|
|
1028
1012
|
itemWrapper.appendChild(inputContainer);
|
|
@@ -1294,10 +1278,12 @@ function renderSelectElement(element, ctx, wrapper, pathKey) {
|
|
|
1294
1278
|
selectInput.addEventListener("change", handleChange);
|
|
1295
1279
|
}
|
|
1296
1280
|
wrapper.appendChild(selectInput);
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1281
|
+
if (!state.config.readonly) {
|
|
1282
|
+
const selectHint = document.createElement("p");
|
|
1283
|
+
selectHint.className = "text-xs text-gray-500 mt-1";
|
|
1284
|
+
selectHint.textContent = makeFieldHint(element, state);
|
|
1285
|
+
wrapper.appendChild(selectHint);
|
|
1286
|
+
}
|
|
1301
1287
|
}
|
|
1302
1288
|
function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
|
|
1303
1289
|
const state = ctx.state;
|
|
@@ -1430,10 +1416,12 @@ function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
|
|
|
1430
1416
|
values.forEach((value) => addSelectItem(value));
|
|
1431
1417
|
updateAddButton();
|
|
1432
1418
|
updateRemoveButtons();
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1419
|
+
if (!state.config.readonly) {
|
|
1420
|
+
const hint = document.createElement("p");
|
|
1421
|
+
hint.className = "text-xs text-gray-500 mt-1";
|
|
1422
|
+
hint.textContent = makeFieldHint(element, state);
|
|
1423
|
+
wrapper.appendChild(hint);
|
|
1424
|
+
}
|
|
1437
1425
|
}
|
|
1438
1426
|
function validateSelectElement(element, key, context) {
|
|
1439
1427
|
const errors = [];
|
|
@@ -2859,14 +2847,16 @@ function renderColourElement(element, ctx, wrapper, pathKey) {
|
|
|
2859
2847
|
const editUI = createEditColourUI(initialValue, pathKey, ctx);
|
|
2860
2848
|
wrapper.appendChild(editUI);
|
|
2861
2849
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2850
|
+
if (!state.config.readonly) {
|
|
2851
|
+
const colourHint = document.createElement("p");
|
|
2852
|
+
colourHint.className = "mt-1";
|
|
2853
|
+
colourHint.style.cssText = `
|
|
2854
|
+
font-size: var(--fb-font-size-small);
|
|
2855
|
+
color: var(--fb-text-secondary-color);
|
|
2856
|
+
`;
|
|
2857
|
+
colourHint.textContent = makeFieldHint(element, state);
|
|
2858
|
+
wrapper.appendChild(colourHint);
|
|
2859
|
+
}
|
|
2870
2860
|
}
|
|
2871
2861
|
function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
|
|
2872
2862
|
const state = ctx.state;
|
|
@@ -3004,14 +2994,16 @@ function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
|
|
|
3004
2994
|
values.forEach((value) => addColourItem(value));
|
|
3005
2995
|
updateAddButton();
|
|
3006
2996
|
updateRemoveButtons();
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
2997
|
+
if (!state.config.readonly) {
|
|
2998
|
+
const hint = document.createElement("p");
|
|
2999
|
+
hint.className = "mt-1";
|
|
3000
|
+
hint.style.cssText = `
|
|
3001
|
+
font-size: var(--fb-font-size-small);
|
|
3002
|
+
color: var(--fb-text-secondary-color);
|
|
3003
|
+
`;
|
|
3004
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3005
|
+
wrapper.appendChild(hint);
|
|
3006
|
+
}
|
|
3015
3007
|
}
|
|
3016
3008
|
function validateColourElement(element, key, context) {
|
|
3017
3009
|
const errors = [];
|
|
@@ -3323,14 +3315,16 @@ function renderSliderElement(element, ctx, wrapper, pathKey) {
|
|
|
3323
3315
|
state.config.readonly
|
|
3324
3316
|
);
|
|
3325
3317
|
wrapper.appendChild(sliderUI);
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3318
|
+
if (!state.config.readonly) {
|
|
3319
|
+
const hint = document.createElement("p");
|
|
3320
|
+
hint.className = "mt-1";
|
|
3321
|
+
hint.style.cssText = `
|
|
3322
|
+
font-size: var(--fb-font-size-small);
|
|
3323
|
+
color: var(--fb-text-secondary-color);
|
|
3324
|
+
`;
|
|
3325
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3326
|
+
wrapper.appendChild(hint);
|
|
3327
|
+
}
|
|
3334
3328
|
}
|
|
3335
3329
|
function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
|
|
3336
3330
|
if (element.min === void 0 || element.min === null) {
|
|
@@ -3479,14 +3473,16 @@ function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
|
|
|
3479
3473
|
values.forEach((value) => addSliderItem(value));
|
|
3480
3474
|
updateAddButton();
|
|
3481
3475
|
updateRemoveButtons();
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3476
|
+
if (!state.config.readonly) {
|
|
3477
|
+
const hint = document.createElement("p");
|
|
3478
|
+
hint.className = "mt-1";
|
|
3479
|
+
hint.style.cssText = `
|
|
3480
|
+
font-size: var(--fb-font-size-small);
|
|
3481
|
+
color: var(--fb-text-secondary-color);
|
|
3482
|
+
`;
|
|
3483
|
+
hint.textContent = makeFieldHint(element, state);
|
|
3484
|
+
wrapper.appendChild(hint);
|
|
3485
|
+
}
|
|
3490
3486
|
}
|
|
3491
3487
|
function validateSliderElement(element, key, context) {
|
|
3492
3488
|
const errors = [];
|