@ekzo-dev/bootstrap-addons 5.3.5 → 5.3.7
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.7",
|
|
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
|
}
|
|
@@ -33,27 +33,18 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
33
33
|
|
|
34
34
|
filter: string = '';
|
|
35
35
|
|
|
36
|
-
optionsCount: number = 0;
|
|
37
|
-
|
|
38
|
-
deactivating: boolean = false;
|
|
39
|
-
|
|
40
36
|
emptyOption?: ISelectOption;
|
|
41
37
|
|
|
42
38
|
popperConfig: Partial<Options> | Tooltip.PopperConfigFunction | null = null;
|
|
43
39
|
|
|
44
40
|
binding() {
|
|
45
41
|
super.binding();
|
|
46
|
-
this.deactivating = false;
|
|
47
42
|
|
|
48
43
|
if (this.multiple && !Array.isArray(this.value)) {
|
|
49
44
|
this.value = [];
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
unbinding() {
|
|
54
|
-
this.deactivating = true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
48
|
attached() {
|
|
58
49
|
this.setPopperConfig();
|
|
59
50
|
}
|
|
@@ -100,6 +91,8 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
100
91
|
}
|
|
101
92
|
|
|
102
93
|
get showClear(): boolean {
|
|
94
|
+
console.warn(`BsSelect #${this.id}: get showClear`);
|
|
95
|
+
|
|
103
96
|
return (
|
|
104
97
|
!this.disabled &&
|
|
105
98
|
((this.emptyOption && this.selectedOption?.value !== this.emptyOption.value) ||
|
|
@@ -119,14 +112,18 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
119
112
|
this.control.dispatchEvent(change);
|
|
120
113
|
}
|
|
121
114
|
|
|
122
|
-
get
|
|
123
|
-
const
|
|
115
|
+
get optionsCount(): number {
|
|
116
|
+
const { options } = this;
|
|
117
|
+
const isObj = options instanceof Object && options.constructor === Object;
|
|
124
118
|
|
|
125
|
-
|
|
119
|
+
return isObj ? Object.keys(options).length : (options as []).length;
|
|
120
|
+
}
|
|
126
121
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
get selectedOption(): ISelectOption | undefined {
|
|
123
|
+
console.warn(`BsSelect #${this.id}: get selectedOption`);
|
|
124
|
+
if (this.multiple) return;
|
|
125
|
+
|
|
126
|
+
const { value, emptyValue, matcher } = this;
|
|
130
127
|
let { options } = this;
|
|
131
128
|
let emptyOption: ISelectOption;
|
|
132
129
|
|
|
@@ -134,8 +131,6 @@ export class BsSelect extends BaseBsSelect implements ICustomElementViewModel {
|
|
|
134
131
|
options = Object.entries(options);
|
|
135
132
|
}
|
|
136
133
|
|
|
137
|
-
this.optionsCount = (options as []).length;
|
|
138
|
-
|
|
139
134
|
const isEntries = Array.isArray(options[0]);
|
|
140
135
|
let option = (options as Array<ISelectOption | readonly [unknown, string]>).find((option) => {
|
|
141
136
|
const optionValue: unknown = isEntries ? option[0] : (option as ISelectOption).value;
|