@ekzo-dev/bootstrap-addons 5.3.6 → 5.3.8
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekzo-dev/bootstrap-addons",
|
|
3
3
|
"description": "Aurelia Bootstrap additional component",
|
|
4
|
-
"version": "5.3.
|
|
4
|
+
"version": "5.3.8",
|
|
5
5
|
"homepage": "https://github.com/ekzo-dev/aurelia-components/tree/main/packages/bootstrap-addons",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@js-temporal/polyfill": "^0.5.1",
|
|
18
18
|
"ajv": "^8.17.1",
|
|
19
19
|
"ajv-formats": "^3.0.1",
|
|
20
|
-
"json-schema-library": "^10.
|
|
20
|
+
"json-schema-library": "^10.5.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"aurelia": "^2.0.0-beta.25",
|
|
@@ -26,6 +26,7 @@ import Ajv2020 from 'ajv/dist/2020';
|
|
|
26
26
|
import addFormats from 'ajv-formats';
|
|
27
27
|
import { bindable, BindingMode, customElement } from 'aurelia';
|
|
28
28
|
import { parsePath } from 'immutable-json-patch';
|
|
29
|
+
import { compileSchema, JsonError, JsonSchema, SchemaNode } from 'json-schema-library';
|
|
29
30
|
|
|
30
31
|
const patternMap: Record<string, string> = {
|
|
31
32
|
'^[A-Za-z_][-A-Za-z0-9._]*$': '^[A-Za-z_][\\-A-Za-z0-9._]*$',
|
|
@@ -158,20 +159,38 @@ export class BsJsonInput {
|
|
|
158
159
|
|
|
159
160
|
addFormats(ajv);
|
|
160
161
|
let validate: ValidateFunction;
|
|
162
|
+
let schema: SchemaNode;
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
schema = compileSchema(rawJsonSchema as JsonSchema);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error('json-schema-library validator compilation error', e);
|
|
168
|
+
}
|
|
161
169
|
|
|
162
170
|
try {
|
|
163
171
|
validate = ajv.compile(rawJsonSchema);
|
|
164
172
|
} catch (e) {
|
|
165
|
-
console.error('
|
|
173
|
+
console.error('AJV validator compilation error', e);
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
return (json: unknown): ValidationError[] => {
|
|
169
177
|
// do not validate empty documents
|
|
170
|
-
if (json === undefined
|
|
178
|
+
if (json === undefined) return [];
|
|
171
179
|
|
|
172
|
-
|
|
180
|
+
let allErrors: ValidationError[] = [];
|
|
181
|
+
|
|
182
|
+
if (schema) {
|
|
183
|
+
const { errors } = schema.validate(json);
|
|
184
|
+
|
|
185
|
+
allErrors = rawThis.#processErrors(errors, json);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (validate) {
|
|
189
|
+
validate(json);
|
|
190
|
+
allErrors = allErrors.concat(rawThis.#processErrorsAjv(validate.errors, json));
|
|
191
|
+
}
|
|
173
192
|
|
|
174
|
-
return
|
|
193
|
+
return allErrors;
|
|
175
194
|
};
|
|
176
195
|
} else if (schemaVersion != null && !disabled) {
|
|
177
196
|
const ajv = rawThis.#initAjv(schemaVersion, ajvOptions);
|
|
@@ -182,7 +201,7 @@ export class BsJsonInput {
|
|
|
182
201
|
|
|
183
202
|
void ajv.validateSchema(json);
|
|
184
203
|
|
|
185
|
-
return rawThis.#
|
|
204
|
+
return rawThis.#processErrorsAjv(ajv.errors, json);
|
|
186
205
|
};
|
|
187
206
|
}
|
|
188
207
|
}
|
|
@@ -233,7 +252,7 @@ export class BsJsonInput {
|
|
|
233
252
|
return (schema.$defs ?? schema.definitions) as JSONSchemaDefinitions;
|
|
234
253
|
}
|
|
235
254
|
|
|
236
|
-
#
|
|
255
|
+
#processErrorsAjv(errors: ErrorObject[] | null, json: unknown): ValidationError[] {
|
|
237
256
|
const message = this.jsonSchema === true ? 'JSON is not a valid JSONSchema' : 'JSON does not match schema';
|
|
238
257
|
|
|
239
258
|
this.input.setCustomValidity(errors?.length ? message : '');
|
|
@@ -244,4 +263,16 @@ export class BsJsonInput {
|
|
|
244
263
|
severity: 'warning' as ValidationSeverity,
|
|
245
264
|
}));
|
|
246
265
|
}
|
|
266
|
+
|
|
267
|
+
#processErrors(errors: JsonError[] | null, json: unknown): ValidationError[] {
|
|
268
|
+
const message = this.jsonSchema === true ? 'JSON is not a valid JSONSchema' : 'JSON does not match schema';
|
|
269
|
+
|
|
270
|
+
this.input.setCustomValidity(errors?.length ? message : '');
|
|
271
|
+
|
|
272
|
+
return (errors || []).map((error) => ({
|
|
273
|
+
path: parsePath(json, error.data.pointer),
|
|
274
|
+
message: error.message || 'Unknown error',
|
|
275
|
+
severity: 'error' as ValidationSeverity,
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
247
278
|
}
|
|
@@ -49,6 +49,12 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
49
49
|
this.setPopperConfig();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
valueChanged(value: unknown): void {
|
|
53
|
+
if (this.multiple && !Array.isArray(value)) {
|
|
54
|
+
this.value = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
setPopperConfig() {
|
|
53
59
|
const { host } = this;
|
|
54
60
|
const parentModal = host.closest('.modal-body,.popover-body,.offcanvas-body');
|
|
@@ -78,9 +84,9 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
78
84
|
if (this.multiple) {
|
|
79
85
|
const { options, value } = this;
|
|
80
86
|
|
|
81
|
-
return (value
|
|
82
|
-
.map((val) => (options as ISelectOption[]).find((option) => option.value === val).text)
|
|
83
|
-
|
|
87
|
+
return Array.isArray(value)
|
|
88
|
+
? value.map((val) => (options as ISelectOption[]).find((option) => option.value === val).text).join(', ')
|
|
89
|
+
: '';
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
const { selectedOption, emptyOption } = this;
|
|
@@ -96,7 +102,7 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
96
102
|
return (
|
|
97
103
|
!this.disabled &&
|
|
98
104
|
((this.emptyOption && this.selectedOption?.value !== this.emptyOption.value) ||
|
|
99
|
-
(this.multiple && (this.value
|
|
105
|
+
(this.multiple && Array.isArray(this.value) && this.value.length > 0))
|
|
100
106
|
);
|
|
101
107
|
}
|
|
102
108
|
|