@elle96/ng-json-schema-manager 0.1.4 → 0.2.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/README.md +7 -7
- package/fesm2022/elle96-ng-json-schema-manager.mjs +933 -653
- package/fesm2022/elle96-ng-json-schema-manager.mjs.map +1 -1
- package/index.d.ts +76 -15
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AbstractControl, FormGroup, FormArray, FormControl } from '@angular/forms';
|
|
1
|
+
import { AbstractControl, ControlValueAccessor, FormGroup, FormArray, FormControl } from '@angular/forms';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { OnChanges, OnDestroy, EventEmitter, ChangeDetectorRef,
|
|
3
|
+
import { OnChanges, ElementRef, Renderer2, SimpleChanges, OnDestroy, EventEmitter, ChangeDetectorRef, OnInit } from '@angular/core';
|
|
4
4
|
import { ErrorObject } from 'ajv';
|
|
5
5
|
|
|
6
6
|
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
@@ -132,15 +132,67 @@ declare class JsonSchemaStylesService {
|
|
|
132
132
|
static ɵprov: i0.ɵɵInjectableDeclaration<JsonSchemaStylesService>;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/** Character shown between the integer and decimal part of a number. */
|
|
136
|
+
type DecimalSeparator = '.' | ',';
|
|
137
|
+
/**
|
|
138
|
+
* Options shared by every node of a form. Provided by `jsm-json-schema-form`, so each form instance has its own.
|
|
139
|
+
*/
|
|
140
|
+
declare class JsonSchemaFormOptions {
|
|
141
|
+
decimalSeparator: DecimalSeparator;
|
|
142
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaFormOptions, never>;
|
|
143
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<JsonSchemaFormOptions>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Keeps digits, a leading minus and a single decimal separator (written with `separator`);
|
|
147
|
+
* `,` and `.` are both accepted as input.
|
|
148
|
+
*/
|
|
149
|
+
declare function sanitizeNumericText(text: string, separator: DecimalSeparator): string;
|
|
150
|
+
/** Text → model: empty → `null`, a complete number → number, anything else stays a string (validation reports it). */
|
|
151
|
+
declare function parseNumericText(text: string): number | string | null;
|
|
152
|
+
/** Model → text shown in the input. */
|
|
153
|
+
declare function formatNumeric(value: unknown, separator: DecimalSeparator): string;
|
|
154
|
+
/** Shows decimals with the configured separator inside messages ("must be >= 0.1" → "must be >= 0,1"). */
|
|
155
|
+
declare function localizeNumbers(message: string, separator: DecimalSeparator): string;
|
|
156
|
+
/**
|
|
157
|
+
* `ControlValueAccessor` for `number`/`integer` fields. The input is a text field (`inputmode="decimal"`), so the
|
|
158
|
+
* decimal comma is accepted, and the model always holds a JSON number once the text is a complete number.
|
|
159
|
+
* It never writes to the control while rendering or when the text is unchanged.
|
|
160
|
+
*/
|
|
161
|
+
declare class NumericInputDirective implements ControlValueAccessor, OnChanges {
|
|
162
|
+
private readonly _el;
|
|
163
|
+
private readonly _renderer;
|
|
164
|
+
jsmDecimalSeparator: DecimalSeparator;
|
|
165
|
+
private _model;
|
|
166
|
+
private _onChange;
|
|
167
|
+
private _onTouched;
|
|
168
|
+
constructor(_el: ElementRef<HTMLInputElement>, _renderer: Renderer2);
|
|
169
|
+
private _show;
|
|
170
|
+
ngOnChanges(changes: SimpleChanges): void;
|
|
171
|
+
writeValue(value: unknown): void;
|
|
172
|
+
registerOnChange(fn: (value: unknown) => void): void;
|
|
173
|
+
registerOnTouched(fn: () => void): void;
|
|
174
|
+
setDisabledState(isDisabled: boolean): void;
|
|
175
|
+
onInput(): void;
|
|
176
|
+
onBlur(): void;
|
|
177
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NumericInputDirective, never>;
|
|
178
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<NumericInputDirective, "input[jsmNumeric]", never, { "jsmDecimalSeparator": { "alias": "jsmDecimalSeparator"; "required": false; }; }, {}, never, never, true, never>;
|
|
179
|
+
}
|
|
180
|
+
|
|
135
181
|
declare class JsonSchemaFormComponent implements OnChanges, OnDestroy {
|
|
136
182
|
private readonly schemaService;
|
|
137
183
|
private readonly resolver;
|
|
138
184
|
private readonly validation;
|
|
139
185
|
private readonly cdr;
|
|
186
|
+
private readonly options;
|
|
140
187
|
schema: JsonSchema;
|
|
141
188
|
value?: unknown;
|
|
142
189
|
data?: unknown;
|
|
143
190
|
allowAdditionalProperties: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Decimal separator of number/integer fields. `,` shows and accepts `0,5` (both `,` and `.` are accepted as input
|
|
193
|
+
* either way); the emitted value is always a JSON number.
|
|
194
|
+
*/
|
|
195
|
+
decimalSeparator: DecimalSeparator;
|
|
144
196
|
formReady: EventEmitter<FormGroup<any>>;
|
|
145
197
|
valueChange: EventEmitter<unknown>;
|
|
146
198
|
schemaReady: EventEmitter<JsonSchema>;
|
|
@@ -154,7 +206,7 @@ declare class JsonSchemaFormComponent implements OnChanges, OnDestroy {
|
|
|
154
206
|
/** When true, all field errors are shown regardless of touched/dirty state. */
|
|
155
207
|
showErrors: boolean;
|
|
156
208
|
private valueSub?;
|
|
157
|
-
constructor(schemaService: JsonSchemaFormService, resolver: JsonSchemaResolverService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, stylesService: JsonSchemaStylesService);
|
|
209
|
+
constructor(schemaService: JsonSchemaFormService, resolver: JsonSchemaResolverService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions, stylesService: JsonSchemaStylesService);
|
|
158
210
|
ngOnChanges(changes: SimpleChanges): void;
|
|
159
211
|
ngOnDestroy(): void;
|
|
160
212
|
/**
|
|
@@ -165,22 +217,17 @@ declare class JsonSchemaFormComponent implements OnChanges, OnDestroy {
|
|
|
165
217
|
validate(): boolean;
|
|
166
218
|
private buildForm;
|
|
167
219
|
private updateErrors;
|
|
168
|
-
/**
|
|
169
|
-
* Recursively coerces string values to numbers/booleans where the schema declares
|
|
170
|
-
* type "number" or "integer". This is needed because <input type="number"> always
|
|
171
|
-
* returns a string to Angular's FormControl, but Ajv validates against the JSON type.
|
|
172
|
-
*/
|
|
173
|
-
private normalizeValue;
|
|
174
220
|
onRootReplaced(control: AbstractControl): void;
|
|
175
221
|
private attachValueSub;
|
|
176
222
|
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaFormComponent, never>;
|
|
177
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<JsonSchemaFormComponent, "jsm-json-schema-form", never, { "schema": { "alias": "schema"; "required": true; }; "value": { "alias": "value"; "required": false; }; "data": { "alias": "data"; "required": false; }; "allowAdditionalProperties": { "alias": "allowAdditionalProperties"; "required": false; }; }, { "formReady": "formReady"; "valueChange": "valueChange"; "schemaReady": "schemaReady"; "schemaErrors": "schemaErrors"; }, never, never, true, never>;
|
|
223
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<JsonSchemaFormComponent, "jsm-json-schema-form", never, { "schema": { "alias": "schema"; "required": true; }; "value": { "alias": "value"; "required": false; }; "data": { "alias": "data"; "required": false; }; "allowAdditionalProperties": { "alias": "allowAdditionalProperties"; "required": false; }; "decimalSeparator": { "alias": "decimalSeparator"; "required": false; }; }, { "formReady": "formReady"; "valueChange": "valueChange"; "schemaReady": "schemaReady"; "schemaErrors": "schemaErrors"; }, never, never, true, never>;
|
|
178
224
|
}
|
|
179
225
|
|
|
180
226
|
declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
181
227
|
private readonly schemaService;
|
|
182
228
|
private readonly validation;
|
|
183
229
|
private readonly cdr;
|
|
230
|
+
private readonly options;
|
|
184
231
|
schema: JsonSchema;
|
|
185
232
|
control: AbstractControl;
|
|
186
233
|
label: string;
|
|
@@ -200,7 +247,7 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
200
247
|
/** Tracks whether this primitive control has been touched (for OnPush CD). */
|
|
201
248
|
isTouched: boolean;
|
|
202
249
|
private valueSub?;
|
|
203
|
-
constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef);
|
|
250
|
+
constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions | null);
|
|
204
251
|
ngOnInit(): void;
|
|
205
252
|
ngOnDestroy(): void;
|
|
206
253
|
/** Called on blur of primitive inputs to trigger CD after Angular marks the control as touched. */
|
|
@@ -209,7 +256,10 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
209
256
|
badgeClass(badge: string): string;
|
|
210
257
|
get nodeKind(): 'oneOf' | 'anyOf' | 'allOf' | 'object' | 'array' | 'primitive';
|
|
211
258
|
get resolvedType(): JsonSchema['type'] | 'enum';
|
|
212
|
-
get
|
|
259
|
+
get decimalSeparator(): DecimalSeparator;
|
|
260
|
+
/** `multipleOf` of this node's own schema, exposed as step metadata. */
|
|
261
|
+
get numericStep(): string;
|
|
262
|
+
get inputKind(): 'text' | 'number' | 'textarea' | 'select' | 'checkbox';
|
|
213
263
|
get inputType(): string;
|
|
214
264
|
get controlAsGroup(): FormGroup;
|
|
215
265
|
get controlAsFormControl(): FormControl;
|
|
@@ -243,7 +293,7 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
243
293
|
private applyConditional;
|
|
244
294
|
private applyDependencies;
|
|
245
295
|
private mergeSchemas;
|
|
246
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent,
|
|
296
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent, [null, null, null, { optional: true; }]>;
|
|
247
297
|
static ɵcmp: i0.ɵɵComponentDeclaration<JsonSchemaNodeComponent, "jsm-schema-node", never, { "schema": { "alias": "schema"; "required": true; }; "control": { "alias": "control"; "required": true; }; "label": { "alias": "label"; "required": false; }; "required": { "alias": "required"; "required": false; }; "path": { "alias": "path"; "required": false; }; "errorsMap": { "alias": "errorsMap"; "required": false; }; "parent": { "alias": "parent"; "required": false; }; "controlKey": { "alias": "controlKey"; "required": false; }; "allowAdditionalProperties": { "alias": "allowAdditionalProperties"; "required": false; }; "showErrors": { "alias": "showErrors"; "required": false; }; }, { "controlReplaced": "controlReplaced"; }, never, never, true, never>;
|
|
248
298
|
}
|
|
249
299
|
|
|
@@ -253,5 +303,16 @@ declare class JsonSchemaFormModule {
|
|
|
253
303
|
static ɵinj: i0.ɵɵInjectorDeclaration<JsonSchemaFormModule>;
|
|
254
304
|
}
|
|
255
305
|
|
|
256
|
-
|
|
257
|
-
|
|
306
|
+
/**
|
|
307
|
+
* Coerces values to the types declared by the schema so that the emitted value respects it:
|
|
308
|
+
* - `number`/`integer` numeric strings become JSON numbers (comma or dot as separator);
|
|
309
|
+
* - empty numeric values (`""`, whitespace, `null`) leave the key absent, never `""` or `0`;
|
|
310
|
+
* - integers with decimals are converted to their number but never truncated (validation reports them);
|
|
311
|
+
* - non-numeric strings are left unchanged (validation reports them).
|
|
312
|
+
* Descends into properties, patternProperties, additionalProperties, items, prefixItems and combinators.
|
|
313
|
+
* The same function feeds both the Ajv validation and the emitted value.
|
|
314
|
+
*/
|
|
315
|
+
declare function normalizeValue(schema: JsonSchema, value: unknown): unknown;
|
|
316
|
+
|
|
317
|
+
export { JsonSchemaFormComponent, JsonSchemaFormModule, JsonSchemaFormOptions, JsonSchemaFormService, JsonSchemaNodeComponent, JsonSchemaResolverService, JsonSchemaStylesService, JsonSchemaValidationService, NumericInputDirective, formatNumeric, localizeNumbers, normalizeValue, parseNumericText, sanitizeNumericText };
|
|
318
|
+
export type { DecimalSeparator, JsonSchema, JsonSchemaArray, JsonSchemaBase, JsonSchemaCombinators, JsonSchemaDraft, JsonSchemaObject, JsonSchemaPrimitive, JsonSchemaType, SchemaError, SchemaFieldContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elle96/ng-json-schema-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Angular JSON Schema form renderer with Tailwind styling, external $ref support, and reactive forms.",
|
|
5
5
|
"homepage": "https://luigiellebalotta.github.io/json-schema-manager/",
|
|
6
6
|
"repository": {
|