jedison 0.3.25 → 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.
- package/CHANGELOG.md +10 -1
- package/dist/cjs/jedison.cjs +1 -1
- package/dist/cjs/jedison.cjs.map +1 -1
- package/dist/esm/jedison.js +39 -25
- package/dist/esm/jedison.js.map +1 -1
- package/dist/umd/jedison.umd.js +1 -1
- package/dist/umd/jedison.umd.js.map +1 -1
- package/package.json +5 -3
package/dist/esm/jedison.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
2396
|
+
this.ifThenElseSchemas.push({
|
|
2398
2397
|
if: schemaIf,
|
|
2399
2398
|
then: isSet(schemaThen) ? schemaThen : {}
|
|
2400
2399
|
});
|
|
2401
|
-
this.
|
|
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.
|
|
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);
|
|
@@ -4618,7 +4620,9 @@ class EditorStringJodit extends EditorString {
|
|
|
4618
4620
|
this.jodit.events.on("change", () => {
|
|
4619
4621
|
const joditValue = this.jodit.value;
|
|
4620
4622
|
if (joditValue !== this.instance.getValue()) {
|
|
4623
|
+
const savedSelection = this.jodit.selection.save();
|
|
4621
4624
|
this.instance.setValue(joditValue, true, "user");
|
|
4625
|
+
this.jodit.selection.restore(savedSelection);
|
|
4622
4626
|
}
|
|
4623
4627
|
});
|
|
4624
4628
|
}
|
|
@@ -4631,7 +4635,10 @@ class EditorStringJodit extends EditorString {
|
|
|
4631
4635
|
}
|
|
4632
4636
|
refreshUI() {
|
|
4633
4637
|
super.refreshUI();
|
|
4634
|
-
|
|
4638
|
+
const joditInstanceValue = this.instance.getValue();
|
|
4639
|
+
if (this.jodit.value !== joditInstanceValue) {
|
|
4640
|
+
this.jodit.value = joditInstanceValue;
|
|
4641
|
+
}
|
|
4635
4642
|
}
|
|
4636
4643
|
destroy() {
|
|
4637
4644
|
this.jodit.destruct();
|
|
@@ -5580,16 +5587,6 @@ class Jedison extends EventEmitter {
|
|
|
5580
5587
|
unregister(instance) {
|
|
5581
5588
|
this.instances.delete(instance.path);
|
|
5582
5589
|
}
|
|
5583
|
-
logIfEditor(...params) {
|
|
5584
|
-
if (this.isEditor) {
|
|
5585
|
-
console.log(...params);
|
|
5586
|
-
}
|
|
5587
|
-
}
|
|
5588
|
-
warnIfEditor(...params) {
|
|
5589
|
-
if (this.isEditor) {
|
|
5590
|
-
console.warn(...params);
|
|
5591
|
-
}
|
|
5592
|
-
}
|
|
5593
5590
|
/**
|
|
5594
5591
|
* Creates a json instance and dereference schema on the fly if needed.
|
|
5595
5592
|
*/
|
|
@@ -5823,7 +5820,10 @@ class Jedison extends EventEmitter {
|
|
|
5823
5820
|
}
|
|
5824
5821
|
}
|
|
5825
5822
|
class RefParser {
|
|
5826
|
-
constructor() {
|
|
5823
|
+
constructor(options = {}) {
|
|
5824
|
+
this.options = Object.assign({
|
|
5825
|
+
detectRecursion: true
|
|
5826
|
+
}, options);
|
|
5827
5827
|
this.refs = {};
|
|
5828
5828
|
this.data = {};
|
|
5829
5829
|
this.iterations = 0;
|
|
@@ -5844,7 +5844,10 @@ class RefParser {
|
|
|
5844
5844
|
if (missingRefs.length) {
|
|
5845
5845
|
console.warn("Missing refs:", JSON.stringify(missingRefs));
|
|
5846
5846
|
}
|
|
5847
|
-
|
|
5847
|
+
if (this.options.detectRecursion) {
|
|
5848
|
+
this.cycles = this.findRecursiveRefs(this.refs);
|
|
5849
|
+
this.markRecursiveSchemas();
|
|
5850
|
+
}
|
|
5848
5851
|
}
|
|
5849
5852
|
refsResolved() {
|
|
5850
5853
|
return Object.values(this.refs).every((value) => {
|
|
@@ -5924,7 +5927,18 @@ class RefParser {
|
|
|
5924
5927
|
return [...cycles];
|
|
5925
5928
|
}
|
|
5926
5929
|
hasRefCycles() {
|
|
5927
|
-
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
|
+
}
|
|
5928
5942
|
}
|
|
5929
5943
|
expand(schema) {
|
|
5930
5944
|
const cloneSchema = JSON.parse(JSON.stringify(schema));
|