@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/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 createNumberCounter(element, input) {
903
- const counter = document.createElement("span");
904
- counter.className = "number-counter";
905
- counter.style.cssText = `
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 updateCounter = () => {
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
- const min = element.min;
919
- const max = element.max;
920
- if (min == null && max == null) {
921
- counter.textContent = "";
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
- if (max != null) {
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", updateCounter);
946
- updateCounter();
947
- return counter;
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 = createNumberCounter(element, numberInput);
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 = createNumberCounter(element, numberInput);
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
- 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);
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
- const hint = document.createElement("p");
1434
- hint.className = "text-xs text-gray-500 mt-1";
1435
- hint.textContent = makeFieldHint(element, state);
1436
- wrapper.appendChild(hint);
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
- const colourHint = document.createElement("p");
2863
- colourHint.className = "mt-1";
2864
- colourHint.style.cssText = `
2865
- font-size: var(--fb-font-size-small);
2866
- color: var(--fb-text-secondary-color);
2867
- `;
2868
- colourHint.textContent = makeFieldHint(element, state);
2869
- wrapper.appendChild(colourHint);
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
- const hint = document.createElement("p");
3008
- hint.className = "mt-1";
3009
- hint.style.cssText = `
3010
- font-size: var(--fb-font-size-small);
3011
- color: var(--fb-text-secondary-color);
3012
- `;
3013
- hint.textContent = makeFieldHint(element, state);
3014
- wrapper.appendChild(hint);
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
- const hint = document.createElement("p");
3327
- hint.className = "mt-1";
3328
- hint.style.cssText = `
3329
- font-size: var(--fb-font-size-small);
3330
- color: var(--fb-text-secondary-color);
3331
- `;
3332
- hint.textContent = makeFieldHint(element, state);
3333
- wrapper.appendChild(hint);
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
- const hint = document.createElement("p");
3483
- hint.className = "mt-1";
3484
- hint.style.cssText = `
3485
- font-size: var(--fb-font-size-small);
3486
- color: var(--fb-text-secondary-color);
3487
- `;
3488
- hint.textContent = makeFieldHint(element, state);
3489
- wrapper.appendChild(hint);
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 = [];