@ekzo-dev/bootstrap-addons 5.3.4 → 5.3.6
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 +3 -2
- package/src/forms/json-input/json-input.ts +14 -11
- package/src/forms/select/select.ts +12 -17
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.6",
|
|
5
5
|
"homepage": "https://github.com/ekzo-dev/aurelia-components/tree/main/packages/bootstrap-addons",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"@types/json-schema": "^7.0.14",
|
|
17
17
|
"@js-temporal/polyfill": "^0.5.1",
|
|
18
18
|
"ajv": "^8.17.1",
|
|
19
|
-
"ajv-formats": "^3.0.1"
|
|
19
|
+
"ajv-formats": "^3.0.1",
|
|
20
|
+
"json-schema-library": "^10.2.1"
|
|
20
21
|
},
|
|
21
22
|
"peerDependencies": {
|
|
22
23
|
"aurelia": "^2.0.0-beta.25",
|
|
@@ -20,12 +20,12 @@ import type {
|
|
|
20
20
|
import { coerceBoolean } from '@ekzo-dev/toolkit';
|
|
21
21
|
import { JsonEditor } from '@ekzo-dev/vanilla-jsoneditor';
|
|
22
22
|
import { faUpRightAndDownLeftFromCenter } from '@fortawesome/free-solid-svg-icons/faUpRightAndDownLeftFromCenter';
|
|
23
|
-
import Ajv, { ErrorObject, Options } from 'ajv';
|
|
23
|
+
import Ajv, { ErrorObject, Options, ValidateFunction } from 'ajv';
|
|
24
24
|
import Ajv2019 from 'ajv/dist/2019';
|
|
25
25
|
import Ajv2020 from 'ajv/dist/2020';
|
|
26
26
|
import addFormats from 'ajv-formats';
|
|
27
27
|
import { bindable, BindingMode, customElement } from 'aurelia';
|
|
28
|
-
import {
|
|
28
|
+
import { parsePath } from 'immutable-json-patch';
|
|
29
29
|
|
|
30
30
|
const patternMap: Record<string, string> = {
|
|
31
31
|
'^[A-Za-z_][-A-Za-z0-9._]*$': '^[A-Za-z_][\\-A-Za-z0-9._]*$',
|
|
@@ -76,12 +76,13 @@ export class BsJsonInput {
|
|
|
76
76
|
|
|
77
77
|
onRenderValue = (props: RenderValueProps): RenderValueComponentDescription[] => {
|
|
78
78
|
let result: RenderValueComponentDescription[] | null;
|
|
79
|
-
const { jsonSchema } = this;
|
|
79
|
+
// const { jsonSchema } = this;
|
|
80
80
|
const { editorModule } = this.editorComponent;
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
// TODO: this does not support bundled schemas and complex refs. So need to make own implementation later
|
|
83
|
+
// if (jsonSchema && typeof jsonSchema === 'object') {
|
|
84
|
+
// result = editorModule.renderJSONSchemaEnum(props, jsonSchema, this.#getSchemaDefinitions(jsonSchema));
|
|
85
|
+
// }
|
|
85
86
|
|
|
86
87
|
return result ?? editorModule.renderValue(props);
|
|
87
88
|
};
|
|
@@ -156,15 +157,17 @@ export class BsJsonInput {
|
|
|
156
157
|
const ajv = rawThis.#initAjv(jsonSchema.$schema as string, ajvOptions);
|
|
157
158
|
|
|
158
159
|
addFormats(ajv);
|
|
159
|
-
|
|
160
|
+
let validate: ValidateFunction;
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
try {
|
|
163
|
+
validate = ajv.compile(rawJsonSchema);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.error('Validator compilation error.', e);
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
return (json: unknown): ValidationError[] => {
|
|
166
169
|
// do not validate empty documents
|
|
167
|
-
if (json === undefined) return [];
|
|
170
|
+
if (json === undefined || !validate) return [];
|
|
168
171
|
|
|
169
172
|
validate(json);
|
|
170
173
|
|
|
@@ -236,7 +239,7 @@ export class BsJsonInput {
|
|
|
236
239
|
this.input.setCustomValidity(errors?.length ? message : '');
|
|
237
240
|
|
|
238
241
|
return (errors || []).map((error) => ({
|
|
239
|
-
path: parsePath(json
|
|
242
|
+
path: parsePath(json, error.instancePath),
|
|
240
243
|
message: error.message || 'Unknown error',
|
|
241
244
|
severity: 'warning' as ValidationSeverity,
|
|
242
245
|
}));
|
|
@@ -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;
|