jedison 1.9.1 → 1.10.1

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.
@@ -1821,8 +1821,6 @@ class Instance extends EventEmitter {
1821
1821
  this.children = [];
1822
1822
  this.ui = null;
1823
1823
  this.isDirty = false;
1824
- this.cachedErrors = null;
1825
- this.cachedErrorsValue = void 0;
1826
1824
  this.watched = {};
1827
1825
  this.key = this.path.split(this.jedison.pathSeparator).pop();
1828
1826
  this.arrayTemplateData = config.arrayTemplateData || {};
@@ -2034,7 +2032,6 @@ class Instance extends EventEmitter {
2034
2032
  }
2035
2033
  this.value = newValue;
2036
2034
  this.isDirty = true;
2037
- this.cachedErrors = null;
2038
2035
  this.emit("set-value", newValue, initiator);
2039
2036
  this.emit("change", initiator);
2040
2037
  this.jedison.emit("instance-change", this, initiator);
@@ -2055,15 +2052,9 @@ class Instance extends EventEmitter {
2055
2052
  if (!this.isActive) {
2056
2053
  return [];
2057
2054
  }
2058
- if (this.cachedErrorsValue === this.value && this.cachedErrors !== null) {
2059
- return this.cachedErrors;
2060
- }
2061
- const errors = removeDuplicatesFromArray(
2055
+ return removeDuplicatesFromArray(
2062
2056
  this.jedison.validator.getErrors(this.getValueRaw(), this.originalSchema, this.getKey(), this.path)
2063
2057
  );
2064
- this.cachedErrorsValue = this.value;
2065
- this.cachedErrors = errors;
2066
- return errors;
2067
2058
  }
2068
2059
  /**
2069
2060
  * Returns true if any leaf descendant is showing validation errors.
@@ -2481,6 +2472,7 @@ class Editor {
2481
2472
  * Destroys the editor
2482
2473
  */
2483
2474
  destroy() {
2475
+ this.clearStoredEventListeners();
2484
2476
  if (this.control.container && this.control.container.parentNode) {
2485
2477
  this.control.container.parentNode.removeChild(this.control.container);
2486
2478
  }
@@ -2699,6 +2691,9 @@ class InstanceIfThenElse extends Instance {
2699
2691
  return this.activeInstance ? this.activeInstance.hasNestedValidationErrors() : false;
2700
2692
  }
2701
2693
  destroy() {
2694
+ if (this.instanceWithoutIf) {
2695
+ this.instanceWithoutIf.destroy();
2696
+ }
2702
2697
  this.instances.forEach((instance) => {
2703
2698
  instance.destroy();
2704
2699
  });
@@ -2933,7 +2928,6 @@ class InstanceObject extends Instance {
2933
2928
  Object.keys(value).forEach((propertyName) => {
2934
2929
  const matchesPattern = compiledPatterns.some((re) => re.test(propertyName));
2935
2930
  if (!hasOwn(this.properties, propertyName) && !matchesPattern) {
2936
- console.warn("deleting", propertyName);
2937
2931
  delete value[propertyName];
2938
2932
  }
2939
2933
  });
@@ -4894,7 +4888,7 @@ class EditorArrayTable extends EditorArray {
4894
4888
  const infoContent = this.getInfo(schemaItems);
4895
4889
  const info = this.theme.getInfo(infoContent);
4896
4890
  if (schemaXInfo.variant === "modal") {
4897
- this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path), infoContent);
4891
+ this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path) + "-item", infoContent);
4898
4892
  }
4899
4893
  thTitle.appendChild(info.container);
4900
4894
  }
@@ -5032,7 +5026,7 @@ class EditorArrayTableObject extends EditorArray {
5032
5026
  schemaItems = this.instance.jedison.refParser.expand(schemaItems);
5033
5027
  }
5034
5028
  const itemProperties = getSchemaProperties(schemaItems);
5035
- Object.values(itemProperties).forEach((propertySchema) => {
5029
+ Object.entries(itemProperties).forEach(([propertyKey, propertySchema]) => {
5036
5030
  const th2 = this.theme.getTableHeader();
5037
5031
  if (propertySchema.title) {
5038
5032
  const fakeLabel = this.theme.getFakeLabel({
@@ -5045,7 +5039,7 @@ class EditorArrayTableObject extends EditorArray {
5045
5039
  const infoContent = this.getInfo(propertySchema);
5046
5040
  const info = this.theme.getInfo(infoContent);
5047
5041
  if (schemaXInfo.variant === "modal") {
5048
- this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path), infoContent);
5042
+ this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path) + "-" + propertyKey, infoContent);
5049
5043
  }
5050
5044
  th2.appendChild(info.container);
5051
5045
  }
@@ -5393,6 +5387,16 @@ class EditorMultiple extends Editor {
5393
5387
  if (this.embedSwitcher) {
5394
5388
  this.control.header.style.display = "none";
5395
5389
  }
5390
+ this.instance.on("change", () => {
5391
+ const jedison = this.instance.jedison;
5392
+ const errors = jedison.getErrors(["error", "warning"]);
5393
+ const prefix = this.instance.path + "/";
5394
+ for (const inst of jedison.instances.values()) {
5395
+ if (inst.ui && inst.path.startsWith(prefix)) {
5396
+ inst.ui.showValidationErrors(errors);
5397
+ }
5398
+ }
5399
+ });
5396
5400
  }
5397
5401
  adaptForTable(td) {
5398
5402
  this.theme.adaptForTableMultipleControl(this.control, td);
@@ -5632,6 +5636,69 @@ class EditorStringJodit extends EditorString {
5632
5636
  super.destroy();
5633
5637
  }
5634
5638
  }
5639
+ class EditorStringPickr extends EditorString {
5640
+ static resolves(schema) {
5641
+ const format2 = getSchemaXOption(schema, "format");
5642
+ return isSet(format2) && format2 === "pickr" && window.Pickr && getSchemaType(schema) === "string";
5643
+ }
5644
+ build() {
5645
+ this.control = this.theme.getPlaceholderControl({
5646
+ title: this.getTitle(),
5647
+ description: this.getDescription(),
5648
+ id: this.getIdFromPath(this.instance.path),
5649
+ titleIconClass: getSchemaXOption(this.instance.schema, "titleIconClass"),
5650
+ titleHidden: getSchemaXOption(this.instance.schema, "titleHidden"),
5651
+ info: this.getInfo()
5652
+ });
5653
+ const pickrOptions = getSchemaXOption(this.instance.schema, "pickr") ?? {};
5654
+ try {
5655
+ this.pickr = window.Pickr.create({
5656
+ el: this.control.placeholder,
5657
+ default: this.instance.getValue() || "#000000",
5658
+ comparison: false,
5659
+ ...pickrOptions
5660
+ });
5661
+ const updateValue = (color) => {
5662
+ const value = color ? color.toHEXA().toString() : "";
5663
+ this.updatingFromPickr = true;
5664
+ this.instance.setValue(value, true, "user");
5665
+ this.updatingFromPickr = false;
5666
+ };
5667
+ this.pickr.on("change", (color) => {
5668
+ updateValue(color);
5669
+ this.pickr.applyColor(true);
5670
+ });
5671
+ this.pickr.on("save", updateValue);
5672
+ this.pickr.on("hide", () => updateValue(this.pickr.getColor()));
5673
+ this.refreshUI();
5674
+ } catch (e) {
5675
+ console.error("Pickr is not available or not loaded correctly.", e);
5676
+ }
5677
+ }
5678
+ addEventListeners() {
5679
+ }
5680
+ refreshUI() {
5681
+ if (!this.pickr) return;
5682
+ this.refreshTemplates();
5683
+ if (this.disabled) {
5684
+ this.pickr.disable();
5685
+ } else {
5686
+ this.pickr.enable();
5687
+ }
5688
+ if (!this.updatingFromPickr) {
5689
+ const value = this.instance.getValue();
5690
+ if (value) {
5691
+ this.pickr.setColor(value, true);
5692
+ }
5693
+ }
5694
+ }
5695
+ destroy() {
5696
+ if (this.pickr) {
5697
+ this.pickr.destroyAndRemove();
5698
+ }
5699
+ super.destroy();
5700
+ }
5701
+ }
5635
5702
  class EditorStringFlatpickr extends EditorString {
5636
5703
  static resolves(schema) {
5637
5704
  const format2 = getSchemaXOption(schema, "format");
@@ -5775,16 +5842,20 @@ class EditorNumberRaty extends EditorNumber {
5775
5842
  });
5776
5843
  try {
5777
5844
  const ratyOptions = getSchemaXOption(this.instance.schema, "raty") ?? {};
5778
- this.raty = new Raty(this.control.placeholder, Object.assign({}, ratyOptions), {
5845
+ this.raty = new Raty(this.control.placeholder, Object.assign({}, ratyOptions, {
5779
5846
  click: (score) => {
5780
5847
  this.instance.setValue(score, true, "user");
5781
5848
  }
5782
- });
5849
+ }));
5783
5850
  this.raty.init();
5784
5851
  } catch (e) {
5785
5852
  console.error("Raty is not available or not loaded correctly.", e);
5786
5853
  }
5787
5854
  }
5855
+ adaptForTable() {
5856
+ this.theme.visuallyHidden(this.control.label);
5857
+ this.theme.visuallyHidden(this.control.description);
5858
+ }
5788
5859
  refreshDisabledState() {
5789
5860
  if (this.disabled || this.readOnly) {
5790
5861
  this.raty.readOnly(true);
@@ -6152,6 +6223,7 @@ class UiResolver {
6152
6223
  EditorStringSimpleMDE,
6153
6224
  EditorStringQuill,
6154
6225
  EditorStringJodit,
6226
+ EditorStringPickr,
6155
6227
  EditorStringFlatpickr,
6156
6228
  EditorStringIMask,
6157
6229
  EditorStringAce,
@@ -6639,13 +6711,15 @@ class Jedison extends EventEmitter {
6639
6711
  }, 0);
6640
6712
  }
6641
6713
  });
6642
- document.addEventListener("focus", (event) => {
6714
+ this._onFocus = (event) => {
6643
6715
  this.lastKeyEvent = null;
6644
6716
  this.lastFocusedId = event.target.id;
6645
- }, true);
6646
- document.addEventListener("keydown", (event) => {
6717
+ };
6718
+ this._onKeydown = (event) => {
6647
6719
  this.lastKeyEvent = event;
6648
- });
6720
+ };
6721
+ document.addEventListener("focus", this._onFocus, true);
6722
+ document.addEventListener("keydown", this._onKeydown);
6649
6723
  }
6650
6724
  }
6651
6725
  updateInstancesWatchedData() {
@@ -6957,6 +7031,10 @@ class Jedison extends EventEmitter {
6957
7031
  * Destroy the root instance and it's children
6958
7032
  */
6959
7033
  destroy() {
7034
+ if (this._onFocus) {
7035
+ document.removeEventListener("focus", this._onFocus, true);
7036
+ document.removeEventListener("keydown", this._onKeydown);
7037
+ }
6960
7038
  this.root.destroy();
6961
7039
  if (this.options.container) {
6962
7040
  this.container.innerHTML = "";
@@ -7465,7 +7543,7 @@ class Theme {
7465
7543
  const html = document.createElement("dialog");
7466
7544
  html.classList.add("jedi-properties-slot");
7467
7545
  html.setAttribute("id", config.id);
7468
- window.addEventListener("click", (event) => {
7546
+ html.addEventListener("click", (event) => {
7469
7547
  if (event.target === html) {
7470
7548
  html.close();
7471
7549
  }
@@ -7476,7 +7554,7 @@ class Theme {
7476
7554
  const html = document.createElement("dialog");
7477
7555
  html.classList.add("jedi-quick-add-property-slot");
7478
7556
  html.setAttribute("id", config.id);
7479
- window.addEventListener("click", (event) => {
7557
+ html.addEventListener("click", (event) => {
7480
7558
  if (event.target === html) {
7481
7559
  html.close();
7482
7560
  }
@@ -7490,7 +7568,7 @@ class Theme {
7490
7568
  const dialog = document.createElement("dialog");
7491
7569
  dialog.classList.add("jedi-json-data");
7492
7570
  dialog.setAttribute("id", config.id);
7493
- window.addEventListener("click", (event) => {
7571
+ dialog.addEventListener("click", (event) => {
7494
7572
  if (event.target === dialog) {
7495
7573
  dialog.close();
7496
7574
  }
@@ -7754,6 +7832,7 @@ class Theme {
7754
7832
  icon: "close"
7755
7833
  });
7756
7834
  dialog.classList.add("jedi-modal-dialog");
7835
+ dialog.setAttribute("id", id + "-modal");
7757
7836
  title.classList.add("jedi-modal-title");
7758
7837
  if (isString(config.title)) {
7759
7838
  title.innerHTML = config.title;
@@ -7764,7 +7843,7 @@ class Theme {
7764
7843
  }
7765
7844
  closeBtn.classList.add("jedi-modal-close");
7766
7845
  closeBtn.setAttribute("always-enabled", "");
7767
- window.addEventListener("click", (event) => {
7846
+ dialog.addEventListener("click", (event) => {
7768
7847
  if (event.target === dialog) {
7769
7848
  dialog.close();
7770
7849
  }
@@ -9910,6 +9989,7 @@ const index = {
9910
9989
  EditorStringSelect,
9911
9990
  EditorStringTextarea,
9912
9991
  EditorStringAwesomplete,
9992
+ EditorStringPickr,
9913
9993
  EditorStringInput,
9914
9994
  EditorNumberRange,
9915
9995
  EditorNumber,