@dmitryvim/form-builder 0.2.8 → 0.2.9

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.
@@ -417,7 +417,7 @@ function renderMultipleTextElement(element, ctx, wrapper, pathKey) {
417
417
  font-size: var(--fb-font-size);
418
418
  transition: all var(--fb-transition-duration);
419
419
  `;
420
- addBtn.textContent = `+ Add ${element.label || "Text"}`;
420
+ addBtn.textContent = "+";
421
421
  addBtn.addEventListener("mouseenter", () => {
422
422
  addBtn.style.backgroundColor = "var(--fb-background-hover-color)";
423
423
  });
@@ -670,7 +670,7 @@ function renderMultipleTextareaElement(element, ctx, wrapper, pathKey) {
670
670
  removeBtn = document.createElement("button");
671
671
  removeBtn.type = "button";
672
672
  removeBtn.className = "remove-item-btn mt-1 px-2 py-1 text-red-600 hover:bg-red-50 rounded text-sm";
673
- removeBtn.innerHTML = "\u2715 Remove";
673
+ removeBtn.innerHTML = "\u2715";
674
674
  removeBtn.onclick = () => {
675
675
  const currentIndex = Array.from(container.children).indexOf(
676
676
  item
@@ -698,7 +698,7 @@ function renderMultipleTextareaElement(element, ctx, wrapper, pathKey) {
698
698
  const addBtn = document.createElement("button");
699
699
  addBtn.type = "button";
700
700
  addBtn.className = "add-textarea-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm";
701
- addBtn.textContent = `+ Add ${element.label || "Textarea"}`;
701
+ addBtn.textContent = "+";
702
702
  addBtn.onclick = () => {
703
703
  values.push(element.default || "");
704
704
  addTextareaItem(element.default || "");
@@ -841,7 +841,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
841
841
  const addBtn = document.createElement("button");
842
842
  addBtn.type = "button";
843
843
  addBtn.className = "add-number-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm";
844
- addBtn.textContent = `+ Add ${element.label || "Number"}`;
844
+ addBtn.textContent = "+";
845
845
  addBtn.onclick = () => {
846
846
  values.push(element.default || "");
847
847
  addNumberItem(element.default || "");
@@ -1127,7 +1127,7 @@ function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
1127
1127
  const addBtn = document.createElement("button");
1128
1128
  addBtn.type = "button";
1129
1129
  addBtn.className = "add-select-btn mt-2 px-3 py-1 text-blue-600 border border-blue-300 rounded hover:bg-blue-50 text-sm";
1130
- addBtn.textContent = `+ Add ${element.label || "Selection"}`;
1130
+ addBtn.textContent = "+";
1131
1131
  addBtn.onclick = () => {
1132
1132
  var _a2, _b2;
1133
1133
  const defaultValue = element.default || ((_b2 = (_a2 = element.options) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.value) || "";
@@ -2660,7 +2660,7 @@ function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
2660
2660
  font-size: var(--fb-font-size);
2661
2661
  transition: all var(--fb-transition-duration);
2662
2662
  `;
2663
- addBtn.textContent = `+ Add ${element.label || "Colour"}`;
2663
+ addBtn.textContent = "+";
2664
2664
  addBtn.addEventListener("mouseenter", () => {
2665
2665
  addBtn.style.backgroundColor = "var(--fb-background-hover-color)";
2666
2666
  });
@@ -3125,7 +3125,7 @@ function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
3125
3125
  font-size: var(--fb-font-size);
3126
3126
  transition: all var(--fb-transition-duration);
3127
3127
  `;
3128
- addBtn.textContent = `+ Add ${element.label || "Slider"}`;
3128
+ addBtn.textContent = "+";
3129
3129
  addBtn.addEventListener("mouseenter", () => {
3130
3130
  addBtn.style.backgroundColor = "var(--fb-background-hover-color)";
3131
3131
  });
@@ -3442,15 +3442,10 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3442
3442
  header.className = "flex justify-between items-center mb-4";
3443
3443
  const left = document.createElement("div");
3444
3444
  left.className = "flex-1";
3445
- const right = document.createElement("div");
3446
- right.className = "flex gap-2";
3447
3445
  const itemsWrap = document.createElement("div");
3448
3446
  itemsWrap.className = "space-y-4";
3449
3447
  containerWrap.appendChild(header);
3450
3448
  header.appendChild(left);
3451
- if (!state.config.readonly) {
3452
- header.appendChild(right);
3453
- }
3454
3449
  if (!ctx.state.config.readonly) {
3455
3450
  const hintsElement = createPrefillHints(element, element.key);
3456
3451
  if (hintsElement) {
@@ -3464,8 +3459,21 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3464
3459
  const createAddButton = () => {
3465
3460
  const add = document.createElement("button");
3466
3461
  add.type = "button";
3467
- add.className = "px-3 py-1.5 bg-blue-600 text-white text-sm rounded-lg hover:bg-blue-700 transition-colors";
3468
- add.textContent = t("addElement", state);
3462
+ add.className = "add-container-btn mt-2 px-3 py-1 rounded";
3463
+ add.style.cssText = `
3464
+ color: var(--fb-primary-color);
3465
+ border: var(--fb-border-width) solid var(--fb-primary-color);
3466
+ background-color: transparent;
3467
+ font-size: var(--fb-font-size);
3468
+ transition: all var(--fb-transition-duration);
3469
+ `;
3470
+ add.textContent = "+";
3471
+ add.addEventListener("mouseenter", () => {
3472
+ add.style.backgroundColor = "var(--fb-background-hover-color)";
3473
+ });
3474
+ add.addEventListener("mouseleave", () => {
3475
+ add.style.backgroundColor = "transparent";
3476
+ });
3469
3477
  add.onclick = () => {
3470
3478
  var _a2;
3471
3479
  if (countItems() < max) {
@@ -3496,8 +3504,19 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3496
3504
  if (!state.config.readonly) {
3497
3505
  const rem = document.createElement("button");
3498
3506
  rem.type = "button";
3499
- rem.className = "absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors";
3500
- rem.textContent = "\xD7";
3507
+ rem.className = "absolute top-2 right-2 px-2 py-1 rounded";
3508
+ rem.style.cssText = `
3509
+ color: var(--fb-error-color);
3510
+ background-color: transparent;
3511
+ transition: background-color var(--fb-transition-duration);
3512
+ `;
3513
+ rem.textContent = "\u2715";
3514
+ rem.addEventListener("mouseenter", () => {
3515
+ rem.style.backgroundColor = "var(--fb-background-hover-color)";
3516
+ });
3517
+ rem.addEventListener("mouseleave", () => {
3518
+ rem.style.backgroundColor = "transparent";
3519
+ });
3501
3520
  rem.onclick = () => {
3502
3521
  item.remove();
3503
3522
  updateAddButton();
@@ -3513,16 +3532,14 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3513
3532
  };
3514
3533
  const updateAddButton = () => {
3515
3534
  const currentCount = countItems();
3516
- const addBtn = right.querySelector("button");
3517
- if (addBtn) {
3518
- addBtn.disabled = currentCount >= max;
3519
- addBtn.style.opacity = currentCount >= max ? "0.5" : "1";
3535
+ const existingAddBtn = containerWrap.querySelector(".add-container-btn");
3536
+ if (existingAddBtn) {
3537
+ existingAddBtn.disabled = currentCount >= max;
3538
+ existingAddBtn.style.opacity = currentCount >= max ? "0.5" : "1";
3539
+ existingAddBtn.style.pointerEvents = currentCount >= max ? "none" : "auto";
3520
3540
  }
3521
3541
  left.innerHTML = `<span>${element.label || element.key}</span> <span class="text-sm text-gray-500">(${currentCount}/${max === Infinity ? "\u221E" : max})</span>`;
3522
3542
  };
3523
- if (!state.config.readonly) {
3524
- right.appendChild(createAddButton());
3525
- }
3526
3543
  if (pre && Array.isArray(pre)) {
3527
3544
  pre.forEach((prefillObj, idx) => {
3528
3545
  var _a2;
@@ -3552,8 +3569,19 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3552
3569
  if (!state.config.readonly) {
3553
3570
  const rem = document.createElement("button");
3554
3571
  rem.type = "button";
3555
- rem.className = "absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors";
3556
- rem.textContent = "\xD7";
3572
+ rem.className = "absolute top-2 right-2 px-2 py-1 rounded";
3573
+ rem.style.cssText = `
3574
+ color: var(--fb-error-color);
3575
+ background-color: transparent;
3576
+ transition: background-color var(--fb-transition-duration);
3577
+ `;
3578
+ rem.textContent = "\u2715";
3579
+ rem.addEventListener("mouseenter", () => {
3580
+ rem.style.backgroundColor = "var(--fb-background-hover-color)";
3581
+ });
3582
+ rem.addEventListener("mouseleave", () => {
3583
+ rem.style.backgroundColor = "transparent";
3584
+ });
3557
3585
  rem.onclick = () => {
3558
3586
  item.remove();
3559
3587
  updateAddButton();
@@ -3592,8 +3620,19 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3592
3620
  item.appendChild(childWrapper);
3593
3621
  const rem = document.createElement("button");
3594
3622
  rem.type = "button";
3595
- rem.className = "absolute top-2 right-2 w-6 h-6 bg-red-500 text-white rounded-full text-xs hover:bg-red-600 transition-colors";
3596
- rem.textContent = "\xD7";
3623
+ rem.className = "absolute top-2 right-2 px-2 py-1 rounded";
3624
+ rem.style.cssText = `
3625
+ color: var(--fb-error-color);
3626
+ background-color: transparent;
3627
+ transition: background-color var(--fb-transition-duration);
3628
+ `;
3629
+ rem.textContent = "\u2715";
3630
+ rem.addEventListener("mouseenter", () => {
3631
+ rem.style.backgroundColor = "var(--fb-background-hover-color)";
3632
+ });
3633
+ rem.addEventListener("mouseleave", () => {
3634
+ rem.style.backgroundColor = "transparent";
3635
+ });
3597
3636
  rem.onclick = () => {
3598
3637
  if (countItems() > min) {
3599
3638
  item.remove();
@@ -3606,6 +3645,9 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3606
3645
  }
3607
3646
  }
3608
3647
  containerWrap.appendChild(itemsWrap);
3648
+ if (!state.config.readonly) {
3649
+ containerWrap.appendChild(createAddButton());
3650
+ }
3609
3651
  updateAddButton();
3610
3652
  wrapper.appendChild(containerWrap);
3611
3653
  }