jedison 0.3.21 → 0.3.23

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.
@@ -1810,11 +1810,15 @@ class Instance extends EventEmitter {
1810
1810
  * Returns the data that will replace placeholders in titles, descriptions (e.g. "{{ i1 }} {{ value.title }}")
1811
1811
  */
1812
1812
  getTemplateData() {
1813
- return {
1813
+ const templateData = {
1814
1814
  ...this.arrayTemplateData,
1815
1815
  value: this.getValue(),
1816
1816
  settings: this.jedison.options.settings
1817
1817
  };
1818
+ if (this.parent) {
1819
+ templateData.parent = this.parent.getTemplateData();
1820
+ }
1821
+ return templateData;
1818
1822
  }
1819
1823
  /**
1820
1824
  * Sets the instance value
@@ -1927,6 +1931,7 @@ class Editor {
1927
1931
  this.purifyEnabled = false;
1928
1932
  this.title = null;
1929
1933
  this.description = null;
1934
+ this.storedEventListeners = [];
1930
1935
  this.init();
1931
1936
  this.build();
1932
1937
  this.setAttributes();
@@ -2035,6 +2040,20 @@ class Editor {
2035
2040
  */
2036
2041
  addEventListeners() {
2037
2042
  }
2043
+ /**
2044
+ * Clears any stored event listeners that might persist
2045
+ * This method can be overridden by subclasses to provide custom cleanup logic
2046
+ */
2047
+ clearStoredEventListeners() {
2048
+ if (this.storedEventListeners) {
2049
+ this.storedEventListeners.forEach((listener) => {
2050
+ if (listener.element && listener.handler) {
2051
+ listener.element.removeEventListener(listener.eventType || "click", listener.handler);
2052
+ }
2053
+ });
2054
+ }
2055
+ this.storedEventListeners = [];
2056
+ }
2038
2057
  /**
2039
2058
  * Shows validation error messages in the editor container.
2040
2059
  */
@@ -2191,6 +2210,29 @@ class Editor {
2191
2210
  sanitize(value) {
2192
2211
  return value;
2193
2212
  }
2213
+ /**
2214
+ * Refreshes the JSON data input size to match content
2215
+ */
2216
+ refreshJsonDataInputSize() {
2217
+ if (this.control && this.control.jsonData && this.control.jsonData.input) {
2218
+ const input = this.control.jsonData.input;
2219
+ input.style.height = "auto";
2220
+ input.style.height = input.scrollHeight + "px";
2221
+ setTimeout(() => {
2222
+ if (input) {
2223
+ input.scrollTop = 0;
2224
+ }
2225
+ });
2226
+ }
2227
+ }
2228
+ /**
2229
+ * Refreshes the JSON data input with current instance value
2230
+ */
2231
+ refreshJsonData() {
2232
+ if (this.control && this.control.jsonData && this.control.jsonData.input) {
2233
+ this.control.jsonData.input.value = JSON.stringify(this.instance.getValue(), null, 2);
2234
+ }
2235
+ }
2194
2236
  /**
2195
2237
  * Destroys the editor
2196
2238
  */
@@ -3632,19 +3674,6 @@ class EditorObject extends Editor {
3632
3674
  });
3633
3675
  }
3634
3676
  }
3635
- refreshJsonDataInputSize() {
3636
- const input = this.control.jsonData.input;
3637
- input.style.height = "auto";
3638
- input.style.height = input.scrollHeight + "px";
3639
- setTimeout(() => {
3640
- if (input) {
3641
- input.scrollTop = 0;
3642
- }
3643
- });
3644
- }
3645
- refreshJsonData() {
3646
- this.control.jsonData.input.value = JSON.stringify(this.instance.getValue(), null, 2);
3647
- }
3648
3677
  refreshEditors() {
3649
3678
  while (this.control.childrenSlot.firstChild) {
3650
3679
  this.control.childrenSlot.removeChild(this.control.childrenSlot.firstChild);
@@ -3803,15 +3832,32 @@ class EditorArray extends Editor {
3803
3832
  startCollapsed: getSchemaXOption(this.instance.schema, "startCollapsed") ?? this.instance.jedison.options.startCollapsed,
3804
3833
  readOnly: this.instance.isReadOnly(),
3805
3834
  info: this.getInfo(),
3835
+ editJsonData: getSchemaXOption(this.instance.schema, "editJsonData") ?? this.instance.jedison.options.editJsonData,
3806
3836
  arrayAdd: getSchemaXOption(this.instance.schema, "arrayAdd") ?? this.instance.jedison.options.arrayAdd,
3807
3837
  arrayAddContent: getSchemaXOption(this.instance.schema, "arrayAddContent") ?? this.instance.jedison.translator.translate("arrayAdd"),
3808
3838
  collapseToggleContent: getSchemaXOption(this.instance.schema, "collapseToggleContent") ?? this.instance.jedison.translator.translate("collapseToggle")
3809
3839
  });
3840
+ this.control.jsonData.input.value = JSON.stringify(this.instance.getValue(), null, 2);
3810
3841
  }
3811
3842
  addEventListeners() {
3812
3843
  this.control.addBtn.addEventListener("click", () => {
3813
3844
  this.instance.addItem("user");
3814
3845
  });
3846
+ this.addJsonDataEventListeners();
3847
+ }
3848
+ addJsonDataEventListeners() {
3849
+ this.control.jsonData.saveBtn.addEventListener("click", () => {
3850
+ try {
3851
+ const inputValue = JSON.parse(this.control.jsonData.input.value);
3852
+ this.instance.setValue(inputValue, true, "user");
3853
+ this.control.jsonData.dialog.close();
3854
+ } catch (error) {
3855
+ alert("Invalid JSON");
3856
+ }
3857
+ });
3858
+ this.control.jsonData.toggle.addEventListener("click", () => {
3859
+ this.refreshJsonDataInputSize();
3860
+ });
3815
3861
  }
3816
3862
  getErrorFeedback(config) {
3817
3863
  return this.theme.getAlert(config);
@@ -3897,6 +3943,7 @@ class EditorArray extends Editor {
3897
3943
  }
3898
3944
  }
3899
3945
  refreshUI() {
3946
+ super.refreshUI();
3900
3947
  const minItems2 = getSchemaMinItems(this.instance.schema);
3901
3948
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
3902
3949
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
@@ -3935,6 +3982,7 @@ class EditorArray extends Editor {
3935
3982
  child.ui.refreshUI();
3936
3983
  });
3937
3984
  this.refreshAddBtn();
3985
+ this.refreshJsonData();
3938
3986
  }
3939
3987
  }
3940
3988
  class EditorArrayTable extends EditorArray {
@@ -3946,6 +3994,7 @@ class EditorArrayTable extends EditorArray {
3946
3994
  this.activeItemIndex = this.instance.value.length;
3947
3995
  this.instance.addItem("user");
3948
3996
  });
3997
+ this.addJsonDataEventListeners();
3949
3998
  }
3950
3999
  isSortable() {
3951
4000
  return window.Sortable && isSet(getSchemaXOption(this.instance.schema, "sortable"));
@@ -4007,6 +4056,7 @@ class EditorArrayTable extends EditorArray {
4007
4056
  });
4008
4057
  this.refreshSortable(table.tbody);
4009
4058
  this.refreshAddBtn();
4059
+ this.refreshJsonData();
4010
4060
  this.refreshDisabledState();
4011
4061
  this.refreshScrollPosition(table.container);
4012
4062
  table.container.addEventListener("scroll", () => {
@@ -4056,6 +4106,7 @@ class EditorArrayTableObject extends EditorArray {
4056
4106
  this.activeItemIndex = this.instance.value.length;
4057
4107
  this.instance.addItem("user");
4058
4108
  });
4109
+ this.addJsonDataEventListeners();
4059
4110
  }
4060
4111
  isSortable() {
4061
4112
  return window.Sortable && isSet(getSchemaXOption(this.instance.schema, "sortable"));
@@ -4133,6 +4184,7 @@ class EditorArrayTableObject extends EditorArray {
4133
4184
  });
4134
4185
  this.refreshSortable(table.tbody);
4135
4186
  this.refreshAddBtn();
4187
+ this.refreshJsonData();
4136
4188
  this.refreshDisabledState();
4137
4189
  this.refreshScrollPosition(table.container);
4138
4190
  table.container.addEventListener("scroll", () => {
@@ -4253,10 +4305,11 @@ class EditorArrayNav extends EditorArray {
4253
4305
  this.activeItemIndex = this.instance.value.length;
4254
4306
  this.instance.addItem("user");
4255
4307
  });
4308
+ this.addJsonDataEventListeners();
4256
4309
  }
4257
4310
  refreshUI() {
4258
- this.refreshDisabledState();
4259
4311
  this.control.childrenSlot.innerHTML = "";
4312
+ this.clearStoredEventListeners();
4260
4313
  const format2 = getSchemaXOption(this.instance.schema, "format");
4261
4314
  const formatParts = format2.split("-");
4262
4315
  const variant = formatParts[1];
@@ -4292,12 +4345,7 @@ class EditorArrayNav extends EditorArray {
4292
4345
  const schemaOptionTitleTemplate = getSchemaXOption(this.instance.schema, "titleTemplate");
4293
4346
  if (schemaOptionTitleTemplate) {
4294
4347
  const template = schemaOptionTitleTemplate;
4295
- const data = {
4296
- i0: index2,
4297
- i1: index2 + 1,
4298
- value: child.getValue(),
4299
- settings: this.instance.jedison.options.settings
4300
- };
4348
+ const data = child.getTemplateData();
4301
4349
  titleTemplate = compileTemplate(template, data) ?? childTitle;
4302
4350
  }
4303
4351
  const active = index2 === this.activeItemIndex;
@@ -4309,8 +4357,14 @@ class EditorArrayNav extends EditorArray {
4309
4357
  active
4310
4358
  });
4311
4359
  arrayActions.appendChild(btnGroup);
4312
- list.addEventListener("click", () => {
4360
+ const clickHandler = () => {
4313
4361
  this.activeItemIndex = index2;
4362
+ };
4363
+ list.addEventListener("click", clickHandler);
4364
+ this.storedEventListeners.push({
4365
+ element: list,
4366
+ handler: clickHandler,
4367
+ eventType: "click"
4314
4368
  });
4315
4369
  this.theme.setTabPaneAttributes(child.ui.control.container, active, id);
4316
4370
  tabList.appendChild(list);
@@ -4327,7 +4381,9 @@ class EditorArrayNav extends EditorArray {
4327
4381
  moveDownBtn.setAttribute("disabled", "");
4328
4382
  }
4329
4383
  });
4384
+ this.refreshDisabledState();
4330
4385
  this.refreshAddBtn();
4386
+ this.refreshJsonData();
4331
4387
  }
4332
4388
  }
4333
4389
  class EditorMultiple extends Editor {
@@ -6580,7 +6636,7 @@ class Theme {
6580
6636
  });
6581
6637
  const fieldset = this.getFieldset();
6582
6638
  const info = this.getInfo(config.info);
6583
- const { legend, legendText } = this.getLegend({
6639
+ const { legend, legendText, infoContainer } = this.getLegend({
6584
6640
  content: config.title,
6585
6641
  id: config.id,
6586
6642
  titleHidden: config.titleHidden
@@ -6588,6 +6644,9 @@ class Theme {
6588
6644
  const description = this.getDescription({
6589
6645
  content: config.description
6590
6646
  });
6647
+ const jsonData = this.getJsonData({
6648
+ id: "json-data-" + config.id
6649
+ });
6591
6650
  const collapse = this.getCollapse({
6592
6651
  id: collapseId,
6593
6652
  startCollapsed: config.startCollapsed
@@ -6604,9 +6663,12 @@ class Theme {
6604
6663
  this.infoAsModal(info, config.id, config.info);
6605
6664
  }
6606
6665
  container.appendChild(fieldset);
6666
+ if (config.editJsonData) {
6667
+ container.appendChild(jsonData.dialog);
6668
+ }
6607
6669
  fieldset.appendChild(legend);
6608
6670
  if (isObject(config.info)) {
6609
- legendText.appendChild(info.container);
6671
+ infoContainer.appendChild(info.container);
6610
6672
  }
6611
6673
  fieldset.appendChild(collapse);
6612
6674
  collapse.appendChild(body);
@@ -6616,6 +6678,9 @@ class Theme {
6616
6678
  body.appendChild(messages);
6617
6679
  legend.appendChild(actions);
6618
6680
  actions.appendChild(btnGroup);
6681
+ if (config.editJsonData) {
6682
+ btnGroup.appendChild(jsonData.toggle);
6683
+ }
6619
6684
  if (isSet(config.arrayAdd) && config.arrayAdd === true) {
6620
6685
  btnGroup.appendChild(addBtn);
6621
6686
  }
@@ -6633,6 +6698,7 @@ class Theme {
6633
6698
  childrenSlot,
6634
6699
  btnGroup,
6635
6700
  addBtn,
6701
+ jsonData,
6636
6702
  legend,
6637
6703
  legendText
6638
6704
  };
@@ -8394,6 +8460,7 @@ class ThemeBootstrap5 extends Theme {
8394
8460
  const index = {
8395
8461
  Schema,
8396
8462
  Utils,
8463
+ Editor,
8397
8464
  EditorBoolean,
8398
8465
  EditorBooleanRadios: EditorRadios,
8399
8466
  EditorBooleanSelect,