jedison 0.2.2 → 0.3.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.
@@ -3319,6 +3319,12 @@ class EditorNumberInput extends EditorNumber {
3319
3319
  const value = this.sanitize(this.control.input.value);
3320
3320
  this.instance.setValue(value, true, "user");
3321
3321
  });
3322
+ this.control.input.addEventListener("focus", () => {
3323
+ this.control.input.value = this.instance.getValue().toString;
3324
+ });
3325
+ this.control.input.addEventListener("blur", () => {
3326
+ this.refreshUI();
3327
+ });
3322
3328
  }
3323
3329
  refreshUI() {
3324
3330
  super.refreshUI();
@@ -3729,16 +3735,116 @@ class EditorArray extends Editor {
3729
3735
  }
3730
3736
  class EditorArrayTable extends EditorArray {
3731
3737
  static resolves(schema, refParser) {
3732
- const schemaItems = getSchemaItems(schema);
3738
+ return getSchemaType(schema) === "array" && getSchemaXOption(schema, "format") === "table-generic";
3739
+ }
3740
+ addEventListeners() {
3741
+ this.control.addBtn.addEventListener("click", () => {
3742
+ this.activeItemIndex = this.instance.value.length;
3743
+ this.instance.addItem("user");
3744
+ });
3745
+ }
3746
+ isSortable() {
3747
+ return window.Sortable && isSet(getSchemaXOption(this.instance.schema, "sortable"));
3748
+ }
3749
+ refreshUI() {
3750
+ this.control.childrenSlot.innerHTML = "";
3751
+ const table = this.theme.getTable();
3752
+ this.control.childrenSlot.appendChild(table.container);
3753
+ const th = this.theme.getTableHeader();
3754
+ const { label } = this.theme.getFakeLabel({
3755
+ content: "Controls",
3756
+ visuallyHidden: true
3757
+ });
3758
+ th.appendChild(label);
3759
+ table.thead.appendChild(th);
3760
+ if (this.instance.children.length) {
3761
+ const schemaItems = getSchemaItems(this.instance.schema);
3762
+ const thTitle = this.theme.getTableHeader();
3763
+ if (schemaItems.title) {
3764
+ const fakeLabel = this.theme.getFakeLabel({
3765
+ content: schemaItems.title
3766
+ });
3767
+ thTitle.appendChild(fakeLabel.label);
3768
+ }
3769
+ const schemaXInfo = getSchemaXOption(schemaItems, "info");
3770
+ if (isSet(schemaXInfo)) {
3771
+ const infoContent = this.getInfo(schemaItems);
3772
+ const info = this.theme.getInfo(infoContent);
3773
+ if (schemaXInfo.variant === "modal") {
3774
+ this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path), infoContent);
3775
+ }
3776
+ thTitle.appendChild(info.container);
3777
+ }
3778
+ table.thead.appendChild(thTitle);
3779
+ }
3780
+ const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
3781
+ const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
3782
+ this.instance.children.forEach((child, index2) => {
3783
+ const tbodyRow = document.createElement("tr");
3784
+ const buttonsTd = this.theme.getTableDefinition();
3785
+ const { deleteBtn, moveUpBtn, moveDownBtn, dragBtn, btnGroup } = this.getButtons(index2);
3786
+ if (this.isSortable()) {
3787
+ btnGroup.appendChild(dragBtn);
3788
+ }
3789
+ if (isSet(arrayDelete) && arrayDelete === true) {
3790
+ btnGroup.appendChild(deleteBtn);
3791
+ }
3792
+ if (isSet(arrayMove) && arrayMove === true) {
3793
+ btnGroup.appendChild(moveUpBtn);
3794
+ btnGroup.appendChild(moveDownBtn);
3795
+ }
3796
+ buttonsTd.appendChild(btnGroup);
3797
+ tbodyRow.appendChild(buttonsTd);
3798
+ const td = this.theme.getTableDefinition();
3799
+ child.ui.adaptForTable(child, td);
3800
+ td.appendChild(child.ui.control.container);
3801
+ tbodyRow.appendChild(td);
3802
+ table.tbody.appendChild(tbodyRow);
3803
+ });
3804
+ this.refreshSortable(table.tbody);
3805
+ this.refreshDisabledState();
3806
+ this.refreshScrollPosition(table.container);
3807
+ table.container.addEventListener("scroll", () => {
3808
+ this.lastScrollTop = table.container.scrollTop;
3809
+ this.lastScrollLeft = table.container.scrollLeft;
3810
+ });
3811
+ }
3812
+ refreshScrollPosition(element) {
3813
+ element.scroll({
3814
+ top: this.lastScrollTop,
3815
+ left: this.lastScrollLeft
3816
+ });
3817
+ }
3818
+ refreshSortable(container) {
3819
+ if (this.isSortable()) {
3820
+ if (this.sortable) {
3821
+ this.sortable.destroy();
3822
+ }
3823
+ this.sortable = window.Sortable.create(container, {
3824
+ animation: 150,
3825
+ handle: ".jedi-array-drag",
3826
+ disabled: this.disabled || this.readOnly,
3827
+ onEnd: (evt) => {
3828
+ this.instance.move(evt.oldIndex, evt.newIndex);
3829
+ }
3830
+ });
3831
+ }
3832
+ }
3833
+ }
3834
+ class EditorArrayTableObject extends EditorArray {
3835
+ static resolves(schema, refParser) {
3836
+ let schemaItems = getSchemaItems(schema);
3733
3837
  if (!schemaItems) {
3734
3838
  return false;
3735
3839
  }
3736
- const expandedSchemaItems = refParser.expand(schemaItems);
3737
- const itemType = getSchemaType(expandedSchemaItems);
3840
+ if (refParser) {
3841
+ schemaItems = refParser.expand(schemaItems);
3842
+ }
3843
+ const itemType = getSchemaType(schemaItems);
3738
3844
  if (!itemType) {
3739
3845
  return false;
3740
3846
  }
3741
- return getSchemaType(schema) === "array" && itemType === "object" && getSchemaXOption(schema, "format") === "table";
3847
+ return getSchemaType(schema) === "array" && itemType === "object" && getSchemaXOption(schema, "format") === "table-object";
3742
3848
  }
3743
3849
  addEventListeners() {
3744
3850
  this.control.addBtn.addEventListener("click", () => {
@@ -3760,9 +3866,11 @@ class EditorArrayTable extends EditorArray {
3760
3866
  });
3761
3867
  th.appendChild(label);
3762
3868
  table.thead.appendChild(th);
3763
- const schemaItems = getSchemaItems(this.instance.schema);
3764
- const expandedSchemaItems = this.instance.jedison.refParser.expand(schemaItems);
3765
- const itemProperties = getSchemaProperties(expandedSchemaItems);
3869
+ let schemaItems = getSchemaItems(this.instance.schema);
3870
+ if (this.instance.jedison.refParser) {
3871
+ schemaItems = this.instance.jedison.refParser.expand(schemaItems);
3872
+ }
3873
+ const itemProperties = getSchemaProperties(schemaItems);
3766
3874
  Object.values(itemProperties).forEach((propertySchema) => {
3767
3875
  const th2 = this.theme.getTableHeader();
3768
3876
  if (propertySchema.title) {
@@ -4366,6 +4474,7 @@ class UiResolver {
4366
4474
  EditorObject,
4367
4475
  EditorArrayChoices,
4368
4476
  EditorArrayCheckboxes,
4477
+ EditorArrayTableObject,
4369
4478
  EditorArrayTable,
4370
4479
  EditorArrayNav,
4371
4480
  EditorArray,