jedison 1.20.1 → 1.21.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 -0
- package/dist/cjs/jedison.cjs +1 -1
- package/dist/cjs/jedison.cjs.map +1 -1
- package/dist/esm/jedison.js +63 -7
- 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 +3 -1
package/dist/esm/jedison.js
CHANGED
|
@@ -350,6 +350,9 @@ function getSchemaContains(schema) {
|
|
|
350
350
|
function getSchemaDefault(schema) {
|
|
351
351
|
return clone(schema.default);
|
|
352
352
|
}
|
|
353
|
+
function getSchemaDeprecated(schema) {
|
|
354
|
+
return isBoolean(schema.deprecated) ? clone(schema.deprecated) : void 0;
|
|
355
|
+
}
|
|
353
356
|
function getSchemaDependentRequired(schema) {
|
|
354
357
|
return isObject$1(schema.dependentRequired) ? clone(schema.dependentRequired) : void 0;
|
|
355
358
|
}
|
|
@@ -1721,6 +1724,10 @@ class Validator {
|
|
|
1721
1724
|
constructor(config = {}) {
|
|
1722
1725
|
this.refParser = config.refParser;
|
|
1723
1726
|
this.constraints = config.constraints ?? {};
|
|
1727
|
+
if (isArray(this.constraints)) {
|
|
1728
|
+
console.warn('Jedison: option "constraints" must be an object keyed by constraint name, not an array. Ignoring the value.');
|
|
1729
|
+
this.constraints = {};
|
|
1730
|
+
}
|
|
1724
1731
|
this.assertFormat = config.assertFormat ? config.assertFormat : false;
|
|
1725
1732
|
this.translator = config.translator ? config.translator : false;
|
|
1726
1733
|
this.subErrors = config.subErrors ?? false;
|
|
@@ -1906,6 +1913,10 @@ class Instance extends EventEmitter {
|
|
|
1906
1913
|
setUI() {
|
|
1907
1914
|
if (this.jedison.isEditor) {
|
|
1908
1915
|
const EditorClass = this.jedison.uiResolver.getClass(this.schema);
|
|
1916
|
+
if (!EditorClass) {
|
|
1917
|
+
console.error(`Jedison: no editor could be resolved for the schema at "${this.path}". The field will not be rendered.`, this.schema);
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1909
1920
|
this.ui = new EditorClass(this);
|
|
1910
1921
|
}
|
|
1911
1922
|
}
|
|
@@ -2159,6 +2170,15 @@ class Instance extends EventEmitter {
|
|
|
2159
2170
|
}
|
|
2160
2171
|
return this.parent ? this.parent.isReadOnly() : false;
|
|
2161
2172
|
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Returns true if this instance's own schema is marked deprecated.
|
|
2175
|
+
* Unlike isReadOnly(), this does not cascade to/from the parent: per the
|
|
2176
|
+
* JSON Schema spec, "deprecated" applies only to the exact instance
|
|
2177
|
+
* location it's declared on.
|
|
2178
|
+
*/
|
|
2179
|
+
isDeprecated() {
|
|
2180
|
+
return getSchemaDeprecated(this.schema) === true;
|
|
2181
|
+
}
|
|
2162
2182
|
/**
|
|
2163
2183
|
* Destroy the instance and it's children
|
|
2164
2184
|
*/
|
|
@@ -2186,6 +2206,7 @@ class Editor {
|
|
|
2186
2206
|
this.control = null;
|
|
2187
2207
|
this.disabled = false;
|
|
2188
2208
|
this.readOnly = this.instance.isReadOnly();
|
|
2209
|
+
this.deprecated = this.instance.isDeprecated();
|
|
2189
2210
|
this.showingValidationErrors = false;
|
|
2190
2211
|
this.markdownEnabled = false;
|
|
2191
2212
|
this.purifyEnabled = false;
|
|
@@ -2196,6 +2217,7 @@ class Editor {
|
|
|
2196
2217
|
this.build();
|
|
2197
2218
|
this.setAttributes();
|
|
2198
2219
|
this.setReadOnlyAttribute();
|
|
2220
|
+
this.setDeprecatedAttribute();
|
|
2199
2221
|
this.addEventListeners();
|
|
2200
2222
|
this.setVisibility();
|
|
2201
2223
|
this.setContainerAttributes();
|
|
@@ -2213,6 +2235,15 @@ class Editor {
|
|
|
2213
2235
|
}
|
|
2214
2236
|
static resolves(schema) {
|
|
2215
2237
|
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Resolution priority used by UiResolver to order candidate editors before
|
|
2240
|
+
* scanning them with resolves(). Higher values are tried first. Editors
|
|
2241
|
+
* that don't override this share the default and keep their relative
|
|
2242
|
+
* declaration order (stable sort).
|
|
2243
|
+
*/
|
|
2244
|
+
static priority() {
|
|
2245
|
+
return 0;
|
|
2246
|
+
}
|
|
2216
2247
|
/**
|
|
2217
2248
|
* Whether this editor already renders a heading for each of its children
|
|
2218
2249
|
* (e.g. an accordion toggle or a nav tab label), so a child editor can
|
|
@@ -2353,6 +2384,17 @@ class Editor {
|
|
|
2353
2384
|
});
|
|
2354
2385
|
}
|
|
2355
2386
|
}
|
|
2387
|
+
/**
|
|
2388
|
+
* Marks the control container so integrators can target deprecated fields
|
|
2389
|
+
* via CSS/JS and decide what to do with them (badge, hide, warn, etc.).
|
|
2390
|
+
* Theme-agnostic: operates on the built DOM rather than the theme's
|
|
2391
|
+
* control-building methods, so it applies uniformly across all themes.
|
|
2392
|
+
*/
|
|
2393
|
+
setDeprecatedAttribute() {
|
|
2394
|
+
if (this.deprecated) {
|
|
2395
|
+
this.control.container.classList.add("jedi-deprecated");
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2356
2398
|
getIdFromPath(path) {
|
|
2357
2399
|
const optionId = this.instance.jedison.getOption("id");
|
|
2358
2400
|
return optionId ? optionId + "-" + pathToAttribute(path) : pathToAttribute(path);
|
|
@@ -7064,9 +7106,12 @@ class EditorStringFilepond extends EditorString {
|
|
|
7064
7106
|
super.destroy();
|
|
7065
7107
|
}
|
|
7066
7108
|
}
|
|
7109
|
+
function byPriorityDescending(a, b) {
|
|
7110
|
+
return b.priority() - a.priority();
|
|
7111
|
+
}
|
|
7067
7112
|
class UiResolver {
|
|
7068
7113
|
constructor(options) {
|
|
7069
|
-
this.customEditors = options.customEditors ?? [];
|
|
7114
|
+
this.customEditors = [...options.customEditors ?? []].sort(byPriorityDescending);
|
|
7070
7115
|
this.refParser = options.refParser ?? null;
|
|
7071
7116
|
this.editors = [
|
|
7072
7117
|
EditorNumberInputNullable,
|
|
@@ -7113,17 +7158,25 @@ class UiResolver {
|
|
|
7113
7158
|
EditorArrayNav,
|
|
7114
7159
|
EditorArray,
|
|
7115
7160
|
EditorNull
|
|
7116
|
-
];
|
|
7161
|
+
].sort(byPriorityDescending);
|
|
7117
7162
|
}
|
|
7118
7163
|
getClass(schema) {
|
|
7119
7164
|
for (const editor of this.customEditors) {
|
|
7120
|
-
|
|
7121
|
-
|
|
7165
|
+
try {
|
|
7166
|
+
if (editor.resolves(schema, this.refParser)) {
|
|
7167
|
+
return editor;
|
|
7168
|
+
}
|
|
7169
|
+
} catch (e) {
|
|
7170
|
+
console.error(`Editor "${editor.name || "custom editor"}" threw while resolving the schema and will be skipped.`, e);
|
|
7122
7171
|
}
|
|
7123
7172
|
}
|
|
7124
7173
|
for (const editor of this.editors) {
|
|
7125
|
-
|
|
7126
|
-
|
|
7174
|
+
try {
|
|
7175
|
+
if (editor.resolves(schema, this.refParser)) {
|
|
7176
|
+
return editor;
|
|
7177
|
+
}
|
|
7178
|
+
} catch (e) {
|
|
7179
|
+
console.error(`Editor "${editor.name || "built-in editor"}" threw while resolving the schema and will be skipped.`, e);
|
|
7127
7180
|
}
|
|
7128
7181
|
}
|
|
7129
7182
|
return null;
|
|
@@ -7409,6 +7462,7 @@ class JsonWalker {
|
|
|
7409
7462
|
}
|
|
7410
7463
|
}
|
|
7411
7464
|
}
|
|
7465
|
+
const version = "1.21.0";
|
|
7412
7466
|
class Jedison extends EventEmitter {
|
|
7413
7467
|
/**
|
|
7414
7468
|
* Creates a Jedison instance.
|
|
@@ -7449,7 +7503,7 @@ class Jedison extends EventEmitter {
|
|
|
7449
7503
|
data: void 0,
|
|
7450
7504
|
assertFormat: false,
|
|
7451
7505
|
customEditors: [],
|
|
7452
|
-
constraints:
|
|
7506
|
+
constraints: {},
|
|
7453
7507
|
hiddenInputAttributes: {},
|
|
7454
7508
|
id: "",
|
|
7455
7509
|
radiosInline: false,
|
|
@@ -7928,6 +7982,7 @@ class Jedison extends EventEmitter {
|
|
|
7928
7982
|
});
|
|
7929
7983
|
}
|
|
7930
7984
|
}
|
|
7985
|
+
Jedison.version = version;
|
|
7931
7986
|
class RefParser {
|
|
7932
7987
|
constructor(options = {}) {
|
|
7933
7988
|
this.options = Object.assign({
|
|
@@ -12145,6 +12200,7 @@ const index = {
|
|
|
12145
12200
|
ThemeBootstrap5,
|
|
12146
12201
|
RefParser,
|
|
12147
12202
|
Create: Jedison,
|
|
12203
|
+
version,
|
|
12148
12204
|
SchemaGenerator,
|
|
12149
12205
|
applyOverlay
|
|
12150
12206
|
};
|