jedison 1.6.1 → 1.7.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.
@@ -2556,18 +2556,22 @@ class InstanceIfThenElse extends Instance {
2556
2556
  });
2557
2557
  }
2558
2558
  const startingValue = this.instanceStartingValues[index2];
2559
- const currentValue = instance.getValue();
2560
2559
  let instanceValue = value;
2561
2560
  if (isObject(startingValue) && isObject(value)) {
2562
- if (indexChanged) {
2561
+ if (indexChanged && initiator !== "api") {
2563
2562
  instanceValue = overwriteExistingProperties(startingValue, withoutIf);
2564
- this.jedison.updateInstancesWatchedData();
2565
2563
  } else {
2564
+ const audacity = this.jedison.options.audacity;
2565
+ if (audacity && initiator === "api" && index2 === fittestIndex) {
2566
+ const prePassValue = mergeDeep({}, instance.getValue(), value);
2567
+ instance.setValue(prePassValue, false, "api");
2568
+ }
2569
+ const currentValue = instance.getValue();
2566
2570
  instanceValue = overwriteExistingProperties(currentValue, value);
2567
2571
  }
2568
- if (initiator === "api") {
2569
- instanceValue = overwriteExistingProperties(currentValue, value);
2570
- }
2572
+ }
2573
+ if (indexChanged) {
2574
+ this.jedison.updateInstancesWatchedData();
2571
2575
  }
2572
2576
  instance.setValue(instanceValue, false, initiator);
2573
2577
  instance.on("notifyParent", (initiator2) => {
@@ -3150,6 +3154,17 @@ class InstanceArray extends Instance {
3150
3154
  this.emit("item-add", initiator, instance);
3151
3155
  this.jedison.emit("item-add", initiator, instance);
3152
3156
  }
3157
+ addItemAfter(afterIndex, initiator) {
3158
+ const tempEditor = this.createItemInstance();
3159
+ const raw = this.getValueRaw();
3160
+ const value = isArray(raw) ? clone(raw) : [];
3161
+ value.splice(afterIndex + 1, 0, tempEditor.getValueRaw());
3162
+ tempEditor.destroy();
3163
+ this.setValue(value, true, initiator);
3164
+ const instance = this.children[afterIndex + 1];
3165
+ this.emit("item-add", initiator, instance);
3166
+ this.jedison.emit("item-add", initiator, instance);
3167
+ }
3153
3168
  deleteItem(itemIndex, initiator) {
3154
3169
  const raw = this.getValueRaw();
3155
3170
  if (!isArray(raw)) {
@@ -4325,7 +4340,7 @@ class EditorObjectCategories extends EditorObject {
4325
4340
  categoryName = defaultLabel;
4326
4341
  }
4327
4342
  if (!categoriesMap.has(categoryName)) {
4328
- categoriesMap.set(categoryName, { children: [], id: pathToAttribute(child.path) });
4343
+ categoriesMap.set(categoryName, { children: [], id: this.getIdFromPath(child.path) });
4329
4344
  }
4330
4345
  categoriesMap.get(categoryName).children.push(child);
4331
4346
  });
@@ -4425,7 +4440,7 @@ class EditorObjectNav extends EditorObject {
4425
4440
  this.instance.children.forEach((child, index2) => {
4426
4441
  if (!this.isChildVisible(child)) return;
4427
4442
  const active = index2 === this.activeTabIndex;
4428
- const id = pathToAttribute(child.path);
4443
+ const id = this.getIdFromPath(child.path);
4429
4444
  const schemaTitle = getSchemaTitle(child.schema);
4430
4445
  const navWarning = getSchemaXOption(this.instance.schema, "navWarning") ?? true;
4431
4446
  const navWarningMessage = getSchemaXOption(this.instance.schema, "navWarningMessage");
@@ -4509,6 +4524,7 @@ class EditorArray extends Editor {
4509
4524
  const schemaMoveUpContent = getSchemaXOption(this.instance.schema, "arrayMoveUpContent");
4510
4525
  const schemaMoveDownContent = getSchemaXOption(this.instance.schema, "arrayMoveDownContent");
4511
4526
  const schemaDragContent = getSchemaXOption(this.instance.schema, "arrayDragContent");
4527
+ const schemaAddAfterContent = getSchemaXOption(this.instance.schema, "arrayAddAfterContent");
4512
4528
  const deleteBtn = this.theme.getDeleteItemBtn({
4513
4529
  content: schemaDeleteContent ?? this.instance.jedison.translator.translate("arrayDelete")
4514
4530
  });
@@ -4521,6 +4537,9 @@ class EditorArray extends Editor {
4521
4537
  const dragBtn = this.theme.getDragItemBtn({
4522
4538
  content: schemaDragContent ?? this.instance.jedison.translator.translate("arrayDrag")
4523
4539
  });
4540
+ const addAfterBtn = this.theme.getAddAfterItemBtn({
4541
+ content: schemaAddAfterContent ?? this.instance.jedison.translator.translate("arrayAddAfter")
4542
+ });
4524
4543
  const btnGroup = this.theme.getBtnGroup();
4525
4544
  deleteBtn.addEventListener("click", () => {
4526
4545
  const schemaConfirm = getSchemaXOption(this.instance.schema, "arrayDeleteConfirm");
@@ -4548,13 +4567,17 @@ class EditorArray extends Editor {
4548
4567
  this.activeItemIndex = toIndex;
4549
4568
  this.instance.move(index2, toIndex, "user");
4550
4569
  });
4570
+ addAfterBtn.addEventListener("click", () => {
4571
+ this.activeItemIndex = index2 + 1;
4572
+ this.instance.addItemAfter(index2, "user");
4573
+ });
4551
4574
  if (index2 === 0) {
4552
4575
  moveUpBtn.setAttribute("always-disabled", true);
4553
4576
  }
4554
4577
  if (index2 === this.instance.children.length - 1) {
4555
4578
  moveDownBtn.setAttribute("always-disabled", true);
4556
4579
  }
4557
- return { deleteBtn, moveUpBtn, moveDownBtn, btnGroup, dragBtn };
4580
+ return { deleteBtn, moveUpBtn, moveDownBtn, btnGroup, dragBtn, addAfterBtn };
4558
4581
  }
4559
4582
  isSortable() {
4560
4583
  return window.Sortable && isSet(getSchemaXOption(this.instance.schema, "sortable"));
@@ -4580,10 +4603,18 @@ class EditorArray extends Editor {
4580
4603
  if (isSet(maxItems2) && enforceMaxItems && maxItems2 <= this.instance.value.length) {
4581
4604
  this.control.addBtn.setAttribute("disabled", "");
4582
4605
  this.control.addBtn.setAttribute("always-disabled", true);
4606
+ this.control.childrenSlot.querySelectorAll(".jedi-array-add-after").forEach((btn) => {
4607
+ btn.setAttribute("disabled", "");
4608
+ btn.setAttribute("always-disabled", true);
4609
+ });
4583
4610
  } else {
4584
4611
  if (!this.disabled && !this.readOnly) {
4585
4612
  this.control.addBtn.removeAttribute("disabled");
4586
4613
  this.control.addBtn.removeAttribute("always-disabled");
4614
+ this.control.childrenSlot.querySelectorAll(".jedi-array-add-after").forEach((btn) => {
4615
+ btn.removeAttribute("disabled");
4616
+ btn.removeAttribute("always-disabled");
4617
+ });
4587
4618
  }
4588
4619
  }
4589
4620
  }
@@ -4592,9 +4623,10 @@ class EditorArray extends Editor {
4592
4623
  const minItems2 = getSchemaMinItems(this.instance.schema);
4593
4624
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
4594
4625
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
4626
+ const arrayAddAfter = getSchemaXOption(this.instance.schema, "arrayAddAfter") ?? this.instance.jedison.options.arrayAddAfter;
4595
4627
  this.control.childrenSlot.innerHTML = "";
4596
4628
  this.instance.children.forEach((child, index2) => {
4597
- const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup } = this.getButtons(index2);
4629
+ const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup, addAfterBtn } = this.getButtons(index2);
4598
4630
  const { container, arrayActions, body } = this.theme.getArrayItem({
4599
4631
  readOnly: this.instance.isReadOnly(),
4600
4632
  index: index2
@@ -4610,6 +4642,9 @@ class EditorArray extends Editor {
4610
4642
  if (this.isSortable()) {
4611
4643
  btnGroup.appendChild(dragBtn);
4612
4644
  }
4645
+ if (isSet(arrayAddAfter) && arrayAddAfter === true) {
4646
+ btnGroup.appendChild(addAfterBtn);
4647
+ }
4613
4648
  this.control.childrenSlot.appendChild(container);
4614
4649
  body.appendChild(child.ui.control.container);
4615
4650
  if (this.disabled || this.instance.isReadOnly()) {
@@ -4711,6 +4746,7 @@ class EditorArrayTable extends EditorArray {
4711
4746
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
4712
4747
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
4713
4748
  const arrayButtonsPosition = getSchemaXOption(this.instance.schema, "arrayButtonsPosition") ?? this.instance.jedison.options.arrayButtonsPosition;
4749
+ const arrayAddAfter = getSchemaXOption(this.instance.schema, "arrayAddAfter") ?? this.instance.jedison.options.arrayAddAfter;
4714
4750
  const th = this.theme.getTableHeader();
4715
4751
  const { label } = this.theme.getFakeLabel({
4716
4752
  content: "Controls",
@@ -4748,7 +4784,7 @@ class EditorArrayTable extends EditorArray {
4748
4784
  this.instance.children.forEach((child, index2) => {
4749
4785
  const tbodyRow = document.createElement("tr");
4750
4786
  const buttonsTd = this.theme.getTableDefinition({ isButtonColumn: true });
4751
- const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup } = this.getButtons(index2);
4787
+ const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup, addAfterBtn } = this.getButtons(index2);
4752
4788
  if (this.isSortable()) {
4753
4789
  btnGroup.appendChild(dragBtn);
4754
4790
  }
@@ -4759,6 +4795,9 @@ class EditorArrayTable extends EditorArray {
4759
4795
  btnGroup.appendChild(moveUpBtn);
4760
4796
  btnGroup.appendChild(moveDownBtn);
4761
4797
  }
4798
+ if (isSet(arrayAddAfter) && arrayAddAfter === true) {
4799
+ btnGroup.appendChild(addAfterBtn);
4800
+ }
4762
4801
  buttonsTd.appendChild(btnGroup);
4763
4802
  if (arrayButtonsPosition === "left") {
4764
4803
  tbodyRow.appendChild(buttonsTd);
@@ -4836,6 +4875,7 @@ class EditorArrayTableObject extends EditorArray {
4836
4875
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
4837
4876
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
4838
4877
  const arrayButtonsPosition = getSchemaXOption(this.instance.schema, "arrayButtonsPosition") ?? this.instance.jedison.options.arrayButtonsPosition;
4878
+ const arrayAddAfter = getSchemaXOption(this.instance.schema, "arrayAddAfter") ?? this.instance.jedison.options.arrayAddAfter;
4839
4879
  const th = this.theme.getTableHeader();
4840
4880
  const { label } = this.theme.getFakeLabel({
4841
4881
  content: "Controls",
@@ -4879,7 +4919,7 @@ class EditorArrayTableObject extends EditorArray {
4879
4919
  this.instance.children.forEach((child, index2) => {
4880
4920
  const tbodyRow = document.createElement("tr");
4881
4921
  const buttonsTd = this.theme.getTableDefinition({ isButtonColumn: true });
4882
- const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup } = this.getButtons(index2);
4922
+ const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup, addAfterBtn } = this.getButtons(index2);
4883
4923
  if (this.isSortable()) {
4884
4924
  btnGroup.appendChild(dragBtn);
4885
4925
  }
@@ -4890,6 +4930,9 @@ class EditorArrayTableObject extends EditorArray {
4890
4930
  btnGroup.appendChild(moveUpBtn);
4891
4931
  btnGroup.appendChild(moveDownBtn);
4892
4932
  }
4933
+ if (isSet(arrayAddAfter) && arrayAddAfter === true) {
4934
+ btnGroup.appendChild(addAfterBtn);
4935
+ }
4893
4936
  buttonsTd.appendChild(btnGroup);
4894
4937
  if (arrayButtonsPosition === "left") {
4895
4938
  tbodyRow.appendChild(buttonsTd);
@@ -5104,13 +5147,14 @@ class EditorArrayNav extends EditorArray {
5104
5147
  });
5105
5148
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
5106
5149
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
5150
+ const arrayAddAfter = getSchemaXOption(this.instance.schema, "arrayAddAfter") ?? this.instance.jedison.options.arrayAddAfter;
5107
5151
  this.control.childrenSlot.appendChild(row);
5108
5152
  row.appendChild(tabListCol);
5109
5153
  row.appendChild(tabContentCol);
5110
5154
  tabListCol.appendChild(tabList);
5111
5155
  tabContentCol.appendChild(tabContent);
5112
5156
  this.instance.children.forEach((child, index2) => {
5113
- const { deleteBtn, moveUpBtn, moveDownBtn, btnGroup } = this.getButtons(index2);
5157
+ const { deleteBtn, moveUpBtn, moveDownBtn, btnGroup, addAfterBtn } = this.getButtons(index2);
5114
5158
  if (isSet(arrayDelete) && arrayDelete === true) {
5115
5159
  btnGroup.appendChild(deleteBtn);
5116
5160
  }
@@ -5118,6 +5162,9 @@ class EditorArrayNav extends EditorArray {
5118
5162
  btnGroup.appendChild(moveUpBtn);
5119
5163
  btnGroup.appendChild(moveDownBtn);
5120
5164
  }
5165
+ if (isSet(arrayAddAfter) && arrayAddAfter === true) {
5166
+ btnGroup.appendChild(addAfterBtn);
5167
+ }
5121
5168
  this.control.childrenSlot.appendChild(child.ui.control.container);
5122
5169
  const schemaTitle = getSchemaTitle(child.schema);
5123
5170
  const childTitle = isSet(schemaTitle) ? schemaTitle + " " + (index2 + 1) : child.getKey();
@@ -5129,7 +5176,7 @@ class EditorArrayNav extends EditorArray {
5129
5176
  titleTemplate = compileTemplate(template, data) ?? childTitle;
5130
5177
  }
5131
5178
  const active = index2 === this.activeItemIndex;
5132
- const id = pathToAttribute(child.path);
5179
+ const id = this.getIdFromPath(child.path);
5133
5180
  const navWarning = getSchemaXOption(this.instance.schema, "navWarning") ?? true;
5134
5181
  const navWarningMessage = getSchemaXOption(this.instance.schema, "navWarningMessage");
5135
5182
  const { list, arrayActions } = this.theme.getTab({
@@ -6024,6 +6071,7 @@ const defaultTranslations = {
6024
6071
  arrayMoveDown: "Move down",
6025
6072
  arrayDrag: "Drag",
6026
6073
  arrayAdd: "Add item",
6074
+ arrayAddAfter: "Add after",
6027
6075
  arrayConfirmDelete: "Are you sure you want to delete this item?",
6028
6076
  objectAddProperty: "Add property",
6029
6077
  objectPropertyAdded: "field was added to the form",
@@ -6279,6 +6327,7 @@ class Jedison extends EventEmitter {
6279
6327
  arrayDeleteConfirm: true,
6280
6328
  arrayMove: true,
6281
6329
  arrayAdd: true,
6330
+ arrayAddAfter: false,
6282
6331
  objectAdd: true,
6283
6332
  arrayButtonsPosition: "left",
6284
6333
  startCollapsed: false,
@@ -6312,7 +6361,8 @@ class Jedison extends EventEmitter {
6312
6361
  enforceMaxItems: true,
6313
6362
  enforceEnum: true,
6314
6363
  subErrors: false,
6315
- debug: false
6364
+ debug: false,
6365
+ audacity: true
6316
6366
  }, options);
6317
6367
  this.rootName = "#";
6318
6368
  this.pathSeparator = "/";
@@ -6523,6 +6573,9 @@ class Jedison extends EventEmitter {
6523
6573
  node.oneOf[index2] = this.refParser.expand(subschema);
6524
6574
  });
6525
6575
  }
6576
+ if (isObject(node.items) && this.refParser.hasRef(node.items)) {
6577
+ node.items = this.refParser.expand(node.items);
6578
+ }
6526
6579
  });
6527
6580
  }
6528
6581
  if (this.isEditor) {
@@ -7392,6 +7445,17 @@ class Theme {
7392
7445
  html.classList.add("jedi-array-add");
7393
7446
  return html;
7394
7447
  }
7448
+ /**
7449
+ * Array "add after" item button
7450
+ */
7451
+ getAddAfterItemBtn(config) {
7452
+ const addAfterItemBtn = this.getButton({
7453
+ content: config.content,
7454
+ icon: "add"
7455
+ });
7456
+ addAfterItemBtn.classList.add("jedi-array-add-after");
7457
+ return addAfterItemBtn;
7458
+ }
7395
7459
  /**
7396
7460
  * Array "delete" item button
7397
7461
  */