jedison 0.3.7 → 0.3.9

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.
@@ -128,7 +128,7 @@ function combineDeep(target, ...sources) {
128
128
  const overwriteExistingProperties = (obj1, obj2) => {
129
129
  Object.keys(obj2).forEach((key) => {
130
130
  if (key in obj1) {
131
- if (isSet(obj1[key]) && isSet(obj2[key]) && (isObject(obj1[key]) && isObject(obj2[key]) || isArray(obj1[key]) && isArray(obj2[key]) || isString(obj1[key]) && isString(obj2[key]) || isNumber(obj1[key]) && isNumber(obj2[key]) || isBoolean(obj1[key]) && isBoolean(obj2[key]))) {
131
+ if (isSet(obj1[key]) && isSet(obj2[key]) && (isObject(obj1[key]) && isObject(obj2[key]) || isArray(obj1[key]) && isArray(obj2[key]) || isString(obj1[key]) && isString(obj2[key]) || isNumber(obj1[key]) && isNumber(obj2[key]) || isBoolean(obj1[key]) && isBoolean(obj2[key]) || isNull(obj1[key]) && isNull(obj2[key]))) {
132
132
  if (isObject(obj1[key]) && isObject(obj2[key])) {
133
133
  overwriteExistingProperties(obj1[key], obj2[key]);
134
134
  } else {
@@ -1660,6 +1660,7 @@ class Instance extends EventEmitter {
1660
1660
  this.isDirty = false;
1661
1661
  this.watched = {};
1662
1662
  this.key = this.path.split(this.jedison.pathSeparator).pop();
1663
+ this.arrayTemplateData = config.arrayTemplateData || {};
1663
1664
  this.init();
1664
1665
  }
1665
1666
  /**
@@ -1798,6 +1799,16 @@ class Instance extends EventEmitter {
1798
1799
  getValue() {
1799
1800
  return clone(this.value);
1800
1801
  }
1802
+ /**
1803
+ * Returns the data that will replace placeholders in titles, descriptions (e.g. "{{ i1 }} {{ value.title }}")
1804
+ */
1805
+ getTemplateData() {
1806
+ return {
1807
+ ...this.arrayTemplateData,
1808
+ value: this.getValue(),
1809
+ settings: this.jedison.options.settings
1810
+ };
1811
+ }
1801
1812
  /**
1802
1813
  * Sets the instance value
1803
1814
  */
@@ -2063,16 +2074,15 @@ class Editor {
2063
2074
  return content;
2064
2075
  }
2065
2076
  getTitle() {
2066
- if (this.title) {
2067
- return this.title;
2068
- }
2077
+ let titleFromSchema = false;
2069
2078
  this.title = this.instance.getKey();
2070
2079
  const schemaTitle = getSchemaTitle(this.instance.schema);
2071
2080
  if (isSet(schemaTitle)) {
2072
- this.title = compileTemplate(schemaTitle, {
2073
- value: this.instance.getValue(),
2074
- settings: this.instance.jedison.options.settings
2075
- });
2081
+ this.title = schemaTitle;
2082
+ titleFromSchema = true;
2083
+ }
2084
+ if (titleFromSchema) {
2085
+ this.title = compileTemplate(this.title, this.instance.getTemplateData());
2076
2086
  this.title = this.getHtmlFromMarkdown(this.title);
2077
2087
  const domPurifyOptions = combineDeep({}, this.instance.jedison.options.domPurifyOptions, {
2078
2088
  FORBID_TAGS: ["p"]
@@ -2087,10 +2097,7 @@ class Editor {
2087
2097
  }
2088
2098
  const schemaDescription = getSchemaDescription(this.instance.schema);
2089
2099
  if (isSet(schemaDescription)) {
2090
- this.description = compileTemplate(schemaDescription, {
2091
- value: this.instance.getValue(),
2092
- settings: this.instance.jedison.options.settings
2093
- });
2100
+ this.description = compileTemplate(schemaDescription, this.instance.getTemplateData());
2094
2101
  this.description = this.getHtmlFromMarkdown(this.description);
2095
2102
  const domPurifyOptions = this.instance.jedison.options.domPurifyOptions;
2096
2103
  this.purifyContent(this.description, domPurifyOptions);
@@ -2249,6 +2256,14 @@ class InstanceIfThenElse extends Instance {
2249
2256
  this.activeInstance.register();
2250
2257
  this.instances.forEach((instance, index2) => {
2251
2258
  instance.off("notifyParent");
2259
+ if (instance.children && isObject(value)) {
2260
+ instance.children.forEach((child) => {
2261
+ const shouldUpdateValue = child.isMultiple && hasOwn(value, child.getKey());
2262
+ if (shouldUpdateValue) {
2263
+ child.setValue(value[child.getKey()], false, "api");
2264
+ }
2265
+ });
2266
+ }
2252
2267
  const startingValue = this.instanceStartingValues[index2];
2253
2268
  const currentValue = instance.getValue();
2254
2269
  let instanceValue = value;
@@ -2348,6 +2363,7 @@ class InstanceMultiple extends Instance {
2348
2363
  this.schemas = [];
2349
2364
  this.switcherOptionValues = [];
2350
2365
  this.switcherOptionsLabels = [];
2366
+ this.isMultiple = true;
2351
2367
  this.on("set-value", () => {
2352
2368
  this.onSetValue();
2353
2369
  });
@@ -2733,7 +2749,7 @@ class InstanceArray extends Instance {
2733
2749
  this.refreshChildren();
2734
2750
  });
2735
2751
  }
2736
- createItemInstance() {
2752
+ createItemInstance(index2) {
2737
2753
  let schema;
2738
2754
  const itemsCount = this.children.length;
2739
2755
  const schemaItems = getSchemaItems(this.schema);
@@ -2747,7 +2763,11 @@ class InstanceArray extends Instance {
2747
2763
  jedison: this.jedison,
2748
2764
  schema,
2749
2765
  path: this.path + this.jedison.pathSeparator + itemsCount,
2750
- parent: this
2766
+ parent: this,
2767
+ arrayTemplateData: {
2768
+ i0: index2,
2769
+ i1: index2 + 1
2770
+ }
2751
2771
  });
2752
2772
  }
2753
2773
  setDefaultValue() {
@@ -2798,8 +2818,8 @@ class InstanceArray extends Instance {
2798
2818
  if (!isArray(value)) {
2799
2819
  return;
2800
2820
  }
2801
- value.forEach((itemValue) => {
2802
- const child = this.createItemInstance(itemValue);
2821
+ value.forEach((itemValue, index2) => {
2822
+ const child = this.createItemInstance(index2);
2803
2823
  this.children.push(child);
2804
2824
  child.setValue(itemValue, false);
2805
2825
  });
@@ -6058,7 +6078,7 @@ class Theme {
6058
6078
  icon: "add"
6059
6079
  });
6060
6080
  const fieldset = this.getFieldset();
6061
- const { legend, infoContainer } = this.getLegend({
6081
+ const { legend, infoContainer, legendText } = this.getLegend({
6062
6082
  content: config.title,
6063
6083
  id: config.id,
6064
6084
  titleHidden: config.titleHidden
@@ -6112,6 +6132,7 @@ class Theme {
6112
6132
  ariaLive,
6113
6133
  propertiesActivators,
6114
6134
  legend,
6135
+ legendText,
6115
6136
  infoContainer
6116
6137
  };
6117
6138
  }