jedison 0.3.26 → 1.0.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.
@@ -1651,6 +1651,7 @@ class Instance extends EventEmitter {
1651
1651
  this.jedison = config.jedison;
1652
1652
  this.path = config.path || this.jedison.rootName;
1653
1653
  this.schema = config.schema;
1654
+ this.originalSchema = config.originalSchema ?? clone(config.schema);
1654
1655
  this.value = isSet(config.value) ? config.value : void 0;
1655
1656
  this.isActive = true;
1656
1657
  this.parent = config.parent || null;
@@ -1875,7 +1876,7 @@ class Instance extends EventEmitter {
1875
1876
  if (!this.isActive) {
1876
1877
  return [];
1877
1878
  }
1878
- const errors = this.jedison.validator.getErrors(this.getValue(), this.schema, this.getKey(), this.path);
1879
+ const errors = this.jedison.validator.getErrors(this.getValue(), this.originalSchema, this.getKey(), this.path);
1879
1880
  return removeDuplicatesFromArray(errors);
1880
1881
  }
1881
1882
  /**
@@ -2294,12 +2295,12 @@ class InstanceIfThenElse extends Instance {
2294
2295
  this.activeInstance = null;
2295
2296
  this.index = 0;
2296
2297
  this.schemas = [];
2297
- this.ifThenElseShemas = [];
2298
+ this.ifThenElseSchemas = [];
2298
2299
  this.traverseSchema(this.schema);
2299
2300
  delete this.schema.if;
2300
2301
  delete this.schema.then;
2301
2302
  delete this.schema.else;
2302
- this.ifThenElseShemas.forEach((item) => {
2303
+ this.ifThenElseSchemas.forEach((item) => {
2303
2304
  if (isSet(item.then)) {
2304
2305
  this.schemas.push(mergeDeep({}, clone(this.schema), item.then));
2305
2306
  }
@@ -2314,6 +2315,7 @@ class InstanceIfThenElse extends Instance {
2314
2315
  this.instanceWithoutIf = this.jedison.createInstance({
2315
2316
  jedison: this.jedison,
2316
2317
  schema: schemaClone,
2318
+ originalSchema: this.originalSchema,
2317
2319
  path: this.path,
2318
2320
  parent: this.parent
2319
2321
  });
@@ -2321,6 +2323,7 @@ class InstanceIfThenElse extends Instance {
2321
2323
  const instance = this.jedison.createInstance({
2322
2324
  jedison: this.jedison,
2323
2325
  schema,
2326
+ originalSchema: this.originalSchema,
2324
2327
  path: this.path,
2325
2328
  parent: this.parent
2326
2329
  });
@@ -2385,20 +2388,16 @@ class InstanceIfThenElse extends Instance {
2385
2388
  }
2386
2389
  return value;
2387
2390
  }
2388
- switchInstance(index2) {
2389
- this.index = index2;
2390
- this.activeInstance = this.instances[this.index];
2391
- }
2392
2391
  traverseSchema(schema) {
2393
2392
  const schemaIf = getSchemaIf(schema);
2394
2393
  if (isSet(schemaIf)) {
2395
2394
  const schemaThen = getSchemaThen(schema);
2396
2395
  const schemaElse = getSchemaElse(schema);
2397
- this.ifThenElseShemas.push({
2396
+ this.ifThenElseSchemas.push({
2398
2397
  if: schemaIf,
2399
2398
  then: isSet(schemaThen) ? schemaThen : {}
2400
2399
  });
2401
- this.ifThenElseShemas.push({
2400
+ this.ifThenElseSchemas.push({
2402
2401
  if: schemaIf,
2403
2402
  else: isSet(schemaElse) ? schemaElse : {}
2404
2403
  });
@@ -2438,7 +2437,7 @@ class InstanceIfThenElse extends Instance {
2438
2437
  */
2439
2438
  getFittestIndex(value) {
2440
2439
  let fittestIndex = this.index;
2441
- this.ifThenElseShemas.forEach((schema, index2) => {
2440
+ this.ifThenElseSchemas.forEach((schema, index2) => {
2442
2441
  if (schema.if === true) {
2443
2442
  fittestIndex = 0;
2444
2443
  } else if (schema.if === false) {
@@ -2626,6 +2625,7 @@ class InstanceObject extends Instance {
2626
2625
  const schema = schemaProperties[key];
2627
2626
  this.properties[key] = { schema };
2628
2627
  let musstCreateChild = true;
2628
+ const isRecursive = isSet(schema["x-recursive"]);
2629
2629
  const optionsDeactivateNonRequired = this.jedison.options.deactivateNonRequired;
2630
2630
  const deactivateNonRequired = getSchemaXOption(this.schema, "deactivateNonRequired");
2631
2631
  const schemaDeactivateNonRequired = getSchemaXOption(schema, "deactivateNonRequired");
@@ -2638,6 +2638,9 @@ class InstanceObject extends Instance {
2638
2638
  if (!this.isRequired(key) && isSet(schemaDeactivateNonRequired) && schemaDeactivateNonRequired === true) {
2639
2639
  musstCreateChild = false;
2640
2640
  }
2641
+ if (!this.isRequired(key) && isRecursive) {
2642
+ musstCreateChild = false;
2643
+ }
2641
2644
  if (musstCreateChild) {
2642
2645
  this.createChild(schema, key);
2643
2646
  }
@@ -4608,7 +4611,6 @@ class EditorStringJodit extends EditorString {
4608
4611
  };
4609
4612
  const joditSchemaOptions = getSchemaXOption(this.instance.schema, "jodit") ?? {};
4610
4613
  const joditOptions = Object.assign({}, joditDefaultOptions, joditSchemaOptions);
4611
- console.log("joditOptions", joditOptions, getSchemaXOption(this.instance.schema, "jodit"));
4612
4614
  this.jodit = window.Jodit.make(this.control.input, joditOptions);
4613
4615
  } catch (e) {
4614
4616
  console.error("Jodit is not available or not loaded correctly.", e);
@@ -5585,16 +5587,6 @@ class Jedison extends EventEmitter {
5585
5587
  unregister(instance) {
5586
5588
  this.instances.delete(instance.path);
5587
5589
  }
5588
- logIfEditor(...params) {
5589
- if (this.isEditor) {
5590
- console.log(...params);
5591
- }
5592
- }
5593
- warnIfEditor(...params) {
5594
- if (this.isEditor) {
5595
- console.warn(...params);
5596
- }
5597
- }
5598
5590
  /**
5599
5591
  * Creates a json instance and dereference schema on the fly if needed.
5600
5592
  */
@@ -5828,7 +5820,10 @@ class Jedison extends EventEmitter {
5828
5820
  }
5829
5821
  }
5830
5822
  class RefParser {
5831
- constructor() {
5823
+ constructor(options = {}) {
5824
+ this.options = Object.assign({
5825
+ detectRecursion: true
5826
+ }, options);
5832
5827
  this.refs = {};
5833
5828
  this.data = {};
5834
5829
  this.iterations = 0;
@@ -5849,7 +5844,10 @@ class RefParser {
5849
5844
  if (missingRefs.length) {
5850
5845
  console.warn("Missing refs:", JSON.stringify(missingRefs));
5851
5846
  }
5852
- this.cycles = this.findRecursiveRefs(this.refs);
5847
+ if (this.options.detectRecursion) {
5848
+ this.cycles = this.findRecursiveRefs(this.refs);
5849
+ this.markRecursiveSchemas();
5850
+ }
5853
5851
  }
5854
5852
  refsResolved() {
5855
5853
  return Object.values(this.refs).every((value) => {
@@ -5929,7 +5927,18 @@ class RefParser {
5929
5927
  return [...cycles];
5930
5928
  }
5931
5929
  hasRefCycles() {
5932
- return this.cycles.length > 0;
5930
+ return this.options.detectRecursion && this.cycles.length > 0;
5931
+ }
5932
+ markRecursiveSchemas() {
5933
+ const cycleRefs = /* @__PURE__ */ new Set();
5934
+ this.cycles.forEach((cycle) => {
5935
+ cycle.split(" → ").forEach((ref) => cycleRefs.add(ref));
5936
+ });
5937
+ for (const schema of Object.values(this.data)) {
5938
+ if (schema && schema.$ref && cycleRefs.has(schema.$ref)) {
5939
+ schema["x-recursive"] = true;
5940
+ }
5941
+ }
5933
5942
  }
5934
5943
  expand(schema) {
5935
5944
  const cloneSchema = JSON.parse(JSON.stringify(schema));