jedison 1.0.0 → 1.1.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.
@@ -23,6 +23,7 @@ function sortObject(obj) {
23
23
  }, {});
24
24
  }
25
25
  function equal(a, b) {
26
+ if (a === b) return true;
26
27
  if (isObject(a) && isObject(b)) {
27
28
  a = sortObject(a);
28
29
  b = sortObject(b);
@@ -1832,6 +1833,12 @@ class Instance extends EventEmitter {
1832
1833
  };
1833
1834
  return Object.fromEntries(Object.entries(functionsObject).map(([functionName, functionValue]) => [functionName, functionValue(context)]));
1834
1835
  }
1836
+ purify(value) {
1837
+ if (typeof value === "string" && this.jedison.options.purifyData && typeof window !== "undefined" && window.DOMPurify) {
1838
+ value = window.DOMPurify.sanitize(value);
1839
+ }
1840
+ return value;
1841
+ }
1835
1842
  /**
1836
1843
  * Sets the instance value
1837
1844
  * @returns {*} The final value after constraint enforcement
@@ -1840,9 +1847,9 @@ class Instance extends EventEmitter {
1840
1847
  if (this.value === newValue) {
1841
1848
  return this.value;
1842
1849
  }
1843
- if (typeof this.value !== "object" && typeof newValue !== "object" && this.value === newValue) {
1844
- return this.value;
1845
- }
1850
+ const purifiedValue = this.purify(newValue);
1851
+ const wasPurified = newValue !== purifiedValue;
1852
+ newValue = purifiedValue;
1846
1853
  const enforceConst = getSchemaXOption(this.schema, "enforceConst") ?? this.jedison.options.enforceConst;
1847
1854
  if (isSet(enforceConst) && equal(enforceConst, true)) {
1848
1855
  const schemaConst = getSchemaConst(this.schema);
@@ -1850,8 +1857,7 @@ class Instance extends EventEmitter {
1850
1857
  newValue = schemaConst;
1851
1858
  }
1852
1859
  }
1853
- const valueChanged = different(this.value, newValue);
1854
- if (!valueChanged) {
1860
+ if (!wasPurified && !different(this.value, newValue)) {
1855
1861
  return this.value;
1856
1862
  }
1857
1863
  this.value = newValue;
@@ -2129,7 +2135,7 @@ class Editor {
2129
2135
  * Clean out HTML tags from txt
2130
2136
  */
2131
2137
  purifyContent(content, domPurifyOptions) {
2132
- if (this.instance.jedison.options.purifyHtml && window.DOMPurify) {
2138
+ if (this.instance.jedison.options.purifyHtml && typeof window !== "undefined" && window.DOMPurify) {
2133
2139
  return window.DOMPurify.sanitize(content, domPurifyOptions);
2134
2140
  } else {
2135
2141
  const tmp = document.createElement("div");
@@ -5388,6 +5394,7 @@ class Jedison extends EventEmitter {
5388
5394
  useConstraintAttributes: true,
5389
5395
  parseMarkdown: false,
5390
5396
  purifyHtml: true,
5397
+ purifyData: true,
5391
5398
  domPurifyOptions: {},
5392
5399
  mergeAllOf: false,
5393
5400
  enforceConst: false,