jedison 1.7.0 → 1.8.0

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.
@@ -2584,6 +2584,7 @@ class InstanceIfThenElse extends Instance {
2584
2584
  if (initiator === "api" && this.hasNullableFields(this.activeInstance)) {
2585
2585
  this.activeInstance.setValue(value, false, "secondary");
2586
2586
  }
2587
+ this.activeInstance.register();
2587
2588
  this.value = this.activeInstance.getValueRaw();
2588
2589
  }
2589
2590
  getWithoutIfValueFromValue(value) {
@@ -4486,14 +4487,49 @@ class EditorArray extends Editor {
4486
4487
  editJsonData: getSchemaXOption(this.instance.schema, "editJsonData") ?? this.instance.jedison.options.editJsonData,
4487
4488
  arrayAdd: getSchemaXOption(this.instance.schema, "arrayAdd") ?? this.instance.jedison.options.arrayAdd,
4488
4489
  arrayAddContent: getSchemaXOption(this.instance.schema, "arrayAddContent") ?? this.instance.jedison.translator.translate("arrayAdd"),
4490
+ arrayFooterAdd: getSchemaXOption(this.instance.schema, "arrayFooterAdd") ?? this.instance.jedison.options.arrayFooterAdd,
4491
+ arrayFooterAddContent: getSchemaXOption(this.instance.schema, "arrayFooterAddContent") ?? this.instance.jedison.translator.translate("arrayAdd"),
4492
+ arrayFooterButtonsPosition: getSchemaXOption(this.instance.schema, "arrayFooterButtonsPosition") ?? this.instance.jedison.options.arrayFooterButtonsPosition,
4493
+ arrayDeleteAll: getSchemaXOption(this.instance.schema, "arrayDeleteAll") ?? this.instance.jedison.options.arrayDeleteAll,
4494
+ arrayDeleteAllContent: getSchemaXOption(this.instance.schema, "arrayDeleteAllContent") ?? this.instance.jedison.translator.translate("arrayDeleteAll"),
4495
+ arrayFooterDeleteAll: getSchemaXOption(this.instance.schema, "arrayFooterDeleteAll") ?? this.instance.jedison.options.arrayFooterDeleteAll,
4496
+ arrayFooterDeleteAllContent: getSchemaXOption(this.instance.schema, "arrayFooterDeleteAllContent") ?? this.instance.jedison.translator.translate("arrayDeleteAll"),
4489
4497
  collapseToggleContent: getSchemaXOption(this.instance.schema, "collapseToggleContent") ?? this.instance.jedison.translator.translate("collapseToggle")
4490
4498
  });
4491
4499
  this.control.jsonData.input.value = JSON.stringify(this.instance.getValue(), null, 2);
4492
4500
  }
4501
+ deleteAllItems() {
4502
+ const schemaConfirm = getSchemaXOption(this.instance.schema, "arrayDeleteConfirm");
4503
+ const globalConfirm = this.instance.jedison.options.arrayDeleteConfirm;
4504
+ const shouldConfirm = isSet(schemaConfirm) ? schemaConfirm : globalConfirm;
4505
+ const doDeleteAll = () => {
4506
+ this.instance.setValue([], true, "user");
4507
+ };
4508
+ if (shouldConfirm) {
4509
+ if (window.confirm(this.instance.jedison.translator.translate("arrayConfirmDeleteAll"))) {
4510
+ doDeleteAll();
4511
+ }
4512
+ } else {
4513
+ doDeleteAll();
4514
+ }
4515
+ }
4493
4516
  addEventListeners() {
4494
4517
  this.control.addBtn.addEventListener("click", () => {
4495
4518
  this.instance.addItem("user");
4496
4519
  });
4520
+ this.control.footerAddBtn.addEventListener("click", () => {
4521
+ this.instance.addItem("user");
4522
+ });
4523
+ if (this.control.deleteAllBtn) {
4524
+ this.control.deleteAllBtn.addEventListener("click", () => {
4525
+ this.deleteAllItems();
4526
+ });
4527
+ }
4528
+ if (this.control.footerDeleteAllBtn) {
4529
+ this.control.footerDeleteAllBtn.addEventListener("click", () => {
4530
+ this.deleteAllItems();
4531
+ });
4532
+ }
4497
4533
  this.addJsonDataEventListeners();
4498
4534
  }
4499
4535
  addJsonDataEventListeners() {
@@ -4597,12 +4633,33 @@ class EditorArray extends Editor {
4597
4633
  });
4598
4634
  }
4599
4635
  }
4636
+ refreshDeleteAllBtn() {
4637
+ if (!this.control.deleteAllBtn && !this.control.footerDeleteAllBtn) return;
4638
+ const isEmpty = this.instance.value.length === 0;
4639
+ const cannotDeleteAll = isEmpty;
4640
+ const btns = [this.control.deleteAllBtn, this.control.footerDeleteAllBtn].filter(Boolean);
4641
+ if (cannotDeleteAll || this.disabled || this.readOnly) {
4642
+ btns.forEach((btn) => {
4643
+ btn.setAttribute("disabled", "");
4644
+ btn.setAttribute("always-disabled", true);
4645
+ });
4646
+ } else {
4647
+ if (!this.disabled && !this.readOnly) {
4648
+ btns.forEach((btn) => {
4649
+ btn.removeAttribute("disabled");
4650
+ btn.removeAttribute("always-disabled");
4651
+ });
4652
+ }
4653
+ }
4654
+ }
4600
4655
  refreshAddBtn() {
4601
4656
  const maxItems2 = getSchemaMaxItems(this.instance.schema);
4602
4657
  const enforceMaxItems = getSchemaXOption(this.instance.schema, "enforceMaxItems") ?? this.instance.jedison.options.enforceMaxItems;
4603
4658
  if (isSet(maxItems2) && enforceMaxItems && maxItems2 <= this.instance.value.length) {
4604
4659
  this.control.addBtn.setAttribute("disabled", "");
4605
4660
  this.control.addBtn.setAttribute("always-disabled", true);
4661
+ this.control.footerAddBtn.setAttribute("disabled", "");
4662
+ this.control.footerAddBtn.setAttribute("always-disabled", true);
4606
4663
  this.control.childrenSlot.querySelectorAll(".jedi-array-add-after").forEach((btn) => {
4607
4664
  btn.setAttribute("disabled", "");
4608
4665
  btn.setAttribute("always-disabled", true);
@@ -4611,6 +4668,8 @@ class EditorArray extends Editor {
4611
4668
  if (!this.disabled && !this.readOnly) {
4612
4669
  this.control.addBtn.removeAttribute("disabled");
4613
4670
  this.control.addBtn.removeAttribute("always-disabled");
4671
+ this.control.footerAddBtn.removeAttribute("disabled");
4672
+ this.control.footerAddBtn.removeAttribute("always-disabled");
4614
4673
  this.control.childrenSlot.querySelectorAll(".jedi-array-add-after").forEach((btn) => {
4615
4674
  btn.removeAttribute("disabled");
4616
4675
  btn.removeAttribute("always-disabled");
@@ -4662,6 +4721,7 @@ class EditorArray extends Editor {
4662
4721
  child.ui.refreshUI();
4663
4722
  });
4664
4723
  this.refreshAddBtn();
4724
+ this.refreshDeleteAllBtn();
4665
4725
  this.refreshJsonData();
4666
4726
  this.refreshLegendWarning();
4667
4727
  }
@@ -4734,6 +4794,20 @@ class EditorArrayTable extends EditorArray {
4734
4794
  this.activeItemIndex = this.instance.value.length;
4735
4795
  this.instance.addItem("user");
4736
4796
  });
4797
+ this.control.footerAddBtn.addEventListener("click", () => {
4798
+ this.activeItemIndex = this.instance.value.length;
4799
+ this.instance.addItem("user");
4800
+ });
4801
+ if (this.control.deleteAllBtn) {
4802
+ this.control.deleteAllBtn.addEventListener("click", () => {
4803
+ this.deleteAllItems();
4804
+ });
4805
+ }
4806
+ if (this.control.footerDeleteAllBtn) {
4807
+ this.control.footerDeleteAllBtn.addEventListener("click", () => {
4808
+ this.deleteAllItems();
4809
+ });
4810
+ }
4737
4811
  this.addJsonDataEventListeners();
4738
4812
  }
4739
4813
  isSortable() {
@@ -4813,6 +4887,7 @@ class EditorArrayTable extends EditorArray {
4813
4887
  });
4814
4888
  this.refreshSortable(table.tbody);
4815
4889
  this.refreshAddBtn();
4890
+ this.refreshDeleteAllBtn();
4816
4891
  this.refreshJsonData();
4817
4892
  this.refreshDisabledState();
4818
4893
  this.refreshScrollPosition(table.container);
@@ -4863,6 +4938,20 @@ class EditorArrayTableObject extends EditorArray {
4863
4938
  this.activeItemIndex = this.instance.value.length;
4864
4939
  this.instance.addItem("user");
4865
4940
  });
4941
+ this.control.footerAddBtn.addEventListener("click", () => {
4942
+ this.activeItemIndex = this.instance.value.length;
4943
+ this.instance.addItem("user");
4944
+ });
4945
+ if (this.control.deleteAllBtn) {
4946
+ this.control.deleteAllBtn.addEventListener("click", () => {
4947
+ this.deleteAllItems();
4948
+ });
4949
+ }
4950
+ if (this.control.footerDeleteAllBtn) {
4951
+ this.control.footerDeleteAllBtn.addEventListener("click", () => {
4952
+ this.deleteAllItems();
4953
+ });
4954
+ }
4866
4955
  this.addJsonDataEventListeners();
4867
4956
  }
4868
4957
  isSortable() {
@@ -4957,6 +5046,7 @@ class EditorArrayTableObject extends EditorArray {
4957
5046
  });
4958
5047
  this.refreshSortable(table.tbody);
4959
5048
  this.refreshAddBtn();
5049
+ this.refreshDeleteAllBtn();
4960
5050
  this.refreshJsonData();
4961
5051
  this.refreshDisabledState();
4962
5052
  this.refreshScrollPosition(table.container);
@@ -5128,6 +5218,22 @@ class EditorArrayNav extends EditorArray {
5128
5218
  this.activeItemIndex = this.instance.value.length;
5129
5219
  this.instance.addItem("user");
5130
5220
  });
5221
+ this.control.footerAddBtn.addEventListener("click", () => {
5222
+ this.activeItemIndex = this.instance.value.length;
5223
+ this.instance.addItem("user");
5224
+ });
5225
+ if (this.control.deleteAllBtn) {
5226
+ this.control.deleteAllBtn.addEventListener("click", () => {
5227
+ this.activeItemIndex = 0;
5228
+ this.deleteAllItems();
5229
+ });
5230
+ }
5231
+ if (this.control.footerDeleteAllBtn) {
5232
+ this.control.footerDeleteAllBtn.addEventListener("click", () => {
5233
+ this.activeItemIndex = 0;
5234
+ this.deleteAllItems();
5235
+ });
5236
+ }
5131
5237
  this.addJsonDataEventListeners();
5132
5238
  }
5133
5239
  refreshUI() {
@@ -5213,6 +5319,7 @@ class EditorArrayNav extends EditorArray {
5213
5319
  });
5214
5320
  this.refreshDisabledState();
5215
5321
  this.refreshAddBtn();
5322
+ this.refreshDeleteAllBtn();
5216
5323
  this.refreshJsonData();
5217
5324
  }
5218
5325
  }
@@ -6073,6 +6180,8 @@ const defaultTranslations = {
6073
6180
  arrayAdd: "Add item",
6074
6181
  arrayAddAfter: "Add after",
6075
6182
  arrayConfirmDelete: "Are you sure you want to delete this item?",
6183
+ arrayDeleteAll: "Delete all items",
6184
+ arrayConfirmDeleteAll: "Are you sure you want to delete all items?",
6076
6185
  objectAddProperty: "Add property",
6077
6186
  objectPropertyAdded: "field was added to the form",
6078
6187
  objectPropertyRemoved: "field was removed from the form",
@@ -6118,6 +6227,8 @@ const translations = {
6118
6227
  arrayDrag: "Drag",
6119
6228
  arrayAdd: "Add item",
6120
6229
  arrayConfirmDelete: "Are you sure you want to delete this item?",
6230
+ arrayDeleteAll: "Delete all items",
6231
+ arrayConfirmDeleteAll: "Are you sure you want to delete all items?",
6121
6232
  objectAddProperty: "Add property",
6122
6233
  objectPropertyAdded: "field was added to the form",
6123
6234
  objectPropertyRemoved: "field was removed from the form",
@@ -6162,6 +6273,8 @@ const translations = {
6162
6273
  arrayDrag: "Ziehen",
6163
6274
  arrayAdd: "Element hinzufügen",
6164
6275
  arrayConfirmDelete: "Möchten Sie dieses Element wirklich löschen?",
6276
+ arrayDeleteAll: "Alle Elemente löschen",
6277
+ arrayConfirmDeleteAll: "Möchten Sie wirklich alle Elemente löschen?",
6165
6278
  objectAddProperty: "Eigenschaft hinzufügen",
6166
6279
  objectPropertyAdded: "Feld wurde dem Formular hinzugefügt",
6167
6280
  objectPropertyRemoved: "Feld wurde aus dem Formular entfernt",
@@ -6206,6 +6319,8 @@ const translations = {
6206
6319
  arrayDrag: "Trascina",
6207
6320
  arrayAdd: "Aggiungi elemento",
6208
6321
  arrayConfirmDelete: "Sei sicuro di voler eliminare questo elemento?",
6322
+ arrayDeleteAll: "Elimina tutti gli elementi",
6323
+ arrayConfirmDeleteAll: "Sei sicuro di voler eliminare tutti gli elementi?",
6209
6324
  objectAddProperty: "Aggiungi proprietà",
6210
6325
  objectPropertyAdded: "Campo aggiunto al modulo",
6211
6326
  objectPropertyRemoved: "Campo rimosso dal modulo",
@@ -6250,6 +6365,8 @@ const translations = {
6250
6365
  arrayDrag: "Arrastrar",
6251
6366
  arrayAdd: "Agregar elemento",
6252
6367
  arrayConfirmDelete: "¿Estás seguro de que deseas eliminar este elemento?",
6368
+ arrayDeleteAll: "Eliminar todos los elementos",
6369
+ arrayConfirmDeleteAll: "¿Está seguro de que desea eliminar todos los elementos?",
6253
6370
  objectAddProperty: "Agregar propiedad",
6254
6371
  objectPropertyAdded: "campo fue añadido al formulario",
6255
6372
  objectPropertyRemoved: "campo fue eliminado del formulario",
@@ -6328,6 +6445,10 @@ class Jedison extends EventEmitter {
6328
6445
  arrayMove: true,
6329
6446
  arrayAdd: true,
6330
6447
  arrayAddAfter: false,
6448
+ arrayFooterAdd: false,
6449
+ arrayFooterButtonsPosition: "right",
6450
+ arrayDeleteAll: false,
6451
+ arrayFooterDeleteAll: false,
6331
6452
  objectAdd: true,
6332
6453
  arrayButtonsPosition: "left",
6333
6454
  startCollapsed: false,
@@ -7150,6 +7271,16 @@ class Theme {
7150
7271
  html.classList.add("jedi-editor-card-body");
7151
7272
  return html;
7152
7273
  }
7274
+ /**
7275
+ * A footer for array cards
7276
+ */
7277
+ getArrayFooter() {
7278
+ const html = document.createElement("div");
7279
+ html.classList.add("jedi-array-footer");
7280
+ html.style.display = "flex";
7281
+ html.style.alignItems = "center";
7282
+ return html;
7283
+ }
7153
7284
  /**
7154
7285
  * Wrapper for editor actions buttons
7155
7286
  */
@@ -7445,6 +7576,17 @@ class Theme {
7445
7576
  html.classList.add("jedi-array-add");
7446
7577
  return html;
7447
7578
  }
7579
+ /**
7580
+ * Array "delete all" button
7581
+ */
7582
+ getArrayBtnDeleteAll(config) {
7583
+ const html = this.getButton({
7584
+ content: config.content,
7585
+ icon: "delete"
7586
+ });
7587
+ html.classList.add("jedi-array-delete-all");
7588
+ return html;
7589
+ }
7448
7590
  /**
7449
7591
  * Array "add after" item button
7450
7592
  */
@@ -7766,6 +7908,13 @@ class Theme {
7766
7908
  const addBtn = this.getArrayBtnAdd({
7767
7909
  content: config.arrayAddContent
7768
7910
  });
7911
+ const footerAddBtn = this.getArrayBtnAdd({
7912
+ content: config.arrayFooterAddContent
7913
+ });
7914
+ const deleteAllBtn = config.arrayDeleteAll === true ? this.getArrayBtnDeleteAll({ content: config.arrayDeleteAllContent }) : null;
7915
+ const footerDeleteAllBtn = config.arrayFooterDeleteAll === true ? this.getArrayBtnDeleteAll({ content: config.arrayFooterDeleteAllContent }) : null;
7916
+ const footerBtnGroup = this.getBtnGroup();
7917
+ const footer = this.getArrayFooter();
7769
7918
  const fieldset = this.getFieldset();
7770
7919
  const info = this.getInfo(config.info);
7771
7920
  const { legend, legendText, infoContainer, right } = this.getLegend({
@@ -7818,6 +7967,9 @@ class Theme {
7818
7967
  if (config.editJsonData) {
7819
7968
  btnGroup.appendChild(jsonData.toggle);
7820
7969
  }
7970
+ if (deleteAllBtn) {
7971
+ btnGroup.appendChild(deleteAllBtn);
7972
+ }
7821
7973
  if (isSet(config.arrayAdd) && config.arrayAdd === true) {
7822
7974
  btnGroup.appendChild(addBtn);
7823
7975
  }
@@ -7825,6 +7977,20 @@ class Theme {
7825
7977
  if (config.enableCollapseToggle) {
7826
7978
  actions.appendChild(collapseToggle);
7827
7979
  }
7980
+ const showFooter = (config.arrayFooterAdd === true || config.arrayFooterDeleteAll === true) && config.readOnly === false;
7981
+ if (showFooter) {
7982
+ if (footerDeleteAllBtn) {
7983
+ footerBtnGroup.appendChild(footerDeleteAllBtn);
7984
+ }
7985
+ if (config.arrayFooterAdd === true) {
7986
+ footerBtnGroup.appendChild(footerAddBtn);
7987
+ }
7988
+ if (config.arrayFooterButtonsPosition === "right") {
7989
+ footerBtnGroup.style.marginLeft = "auto";
7990
+ }
7991
+ footer.appendChild(footerBtnGroup);
7992
+ collapse.appendChild(footer);
7993
+ }
7828
7994
  return {
7829
7995
  container,
7830
7996
  collapseToggle,
@@ -7838,7 +8004,10 @@ class Theme {
7838
8004
  jsonData,
7839
8005
  legend,
7840
8006
  legendText,
7841
- switcherSlot
8007
+ switcherSlot,
8008
+ footerAddBtn,
8009
+ deleteAllBtn,
8010
+ footerDeleteAllBtn
7842
8011
  };
7843
8012
  }
7844
8013
  getArrayItem(config = {}) {
@@ -8629,6 +8798,11 @@ class ThemeBootstrap3 extends Theme {
8629
8798
  html.style.paddingBottom = "0";
8630
8799
  return html;
8631
8800
  }
8801
+ getArrayFooter() {
8802
+ const footer = super.getArrayFooter();
8803
+ footer.classList.add("panel-footer");
8804
+ return footer;
8805
+ }
8632
8806
  getBtnGroup() {
8633
8807
  const html = super.getBtnGroup();
8634
8808
  html.classList.add("btn-group");
@@ -8983,6 +9157,11 @@ class ThemeBootstrap4 extends Theme {
8983
9157
  html.classList.add("pb-0");
8984
9158
  return html;
8985
9159
  }
9160
+ getArrayFooter() {
9161
+ const footer = super.getArrayFooter();
9162
+ footer.classList.add("card-footer");
9163
+ return footer;
9164
+ }
8986
9165
  getBtnGroup() {
8987
9166
  const html = super.getBtnGroup();
8988
9167
  html.classList.add("btn-group");
@@ -9364,6 +9543,11 @@ class ThemeBootstrap5 extends Theme {
9364
9543
  html.classList.add("pb-0");
9365
9544
  return html;
9366
9545
  }
9546
+ getArrayFooter() {
9547
+ const footer = super.getArrayFooter();
9548
+ footer.classList.add("card-footer");
9549
+ return footer;
9550
+ }
9367
9551
  getControlSlot() {
9368
9552
  const controlSlot = super.getControlSlot();
9369
9553
  controlSlot.classList.add("mb-3");