@elle96/ng-json-schema-manager 0.1.3 → 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 +1031 -632
- package/fesm2022/elle96-ng-json-schema-manager.mjs.map +1 -1
- package/index.d.ts +94 -10
- 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,
|
|
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,14 +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;
|
|
185
|
+
private readonly cdr;
|
|
186
|
+
private readonly options;
|
|
139
187
|
schema: JsonSchema;
|
|
140
188
|
value?: unknown;
|
|
141
189
|
data?: unknown;
|
|
142
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;
|
|
143
196
|
formReady: EventEmitter<FormGroup<any>>;
|
|
144
197
|
valueChange: EventEmitter<unknown>;
|
|
145
198
|
schemaReady: EventEmitter<JsonSchema>;
|
|
@@ -150,22 +203,31 @@ declare class JsonSchemaFormComponent implements OnChanges, OnDestroy {
|
|
|
150
203
|
errorsMap: Map<string, string[]>;
|
|
151
204
|
schemaErrorList: SchemaError[];
|
|
152
205
|
loading: boolean;
|
|
206
|
+
/** When true, all field errors are shown regardless of touched/dirty state. */
|
|
207
|
+
showErrors: boolean;
|
|
153
208
|
private valueSub?;
|
|
154
|
-
constructor(schemaService: JsonSchemaFormService, resolver: JsonSchemaResolverService, validation: JsonSchemaValidationService, stylesService: JsonSchemaStylesService);
|
|
209
|
+
constructor(schemaService: JsonSchemaFormService, resolver: JsonSchemaResolverService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions, stylesService: JsonSchemaStylesService);
|
|
155
210
|
ngOnChanges(changes: SimpleChanges): void;
|
|
156
211
|
ngOnDestroy(): void;
|
|
212
|
+
/**
|
|
213
|
+
* Marks all fields as touched and forces error display across the entire form.
|
|
214
|
+
* Call this from an external "Save" or "Submit" button to show all validation errors at once.
|
|
215
|
+
* Returns true if the form is valid, false otherwise.
|
|
216
|
+
*/
|
|
217
|
+
validate(): boolean;
|
|
157
218
|
private buildForm;
|
|
158
219
|
private updateErrors;
|
|
159
220
|
onRootReplaced(control: AbstractControl): void;
|
|
160
221
|
private attachValueSub;
|
|
161
222
|
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaFormComponent, never>;
|
|
162
|
-
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>;
|
|
163
224
|
}
|
|
164
225
|
|
|
165
226
|
declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
166
227
|
private readonly schemaService;
|
|
167
228
|
private readonly validation;
|
|
168
229
|
private readonly cdr;
|
|
230
|
+
private readonly options;
|
|
169
231
|
schema: JsonSchema;
|
|
170
232
|
control: AbstractControl;
|
|
171
233
|
label: string;
|
|
@@ -175,20 +237,29 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
175
237
|
parent?: FormGroup | FormArray;
|
|
176
238
|
controlKey?: string | number;
|
|
177
239
|
allowAdditionalProperties: boolean;
|
|
240
|
+
/** When true, errors are shown regardless of touched/dirty state (e.g. triggered by an external save button). */
|
|
241
|
+
showErrors: boolean;
|
|
178
242
|
controlReplaced: EventEmitter<AbstractControl<any, any, any>>;
|
|
179
243
|
selectedOneOf: number;
|
|
180
244
|
selectedAnyOf: Set<number>;
|
|
181
245
|
newPropertyKey: string;
|
|
182
246
|
propertyError: string;
|
|
247
|
+
/** Tracks whether this primitive control has been touched (for OnPush CD). */
|
|
248
|
+
isTouched: boolean;
|
|
183
249
|
private valueSub?;
|
|
184
|
-
constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef);
|
|
250
|
+
constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions | null);
|
|
185
251
|
ngOnInit(): void;
|
|
186
252
|
ngOnDestroy(): void;
|
|
253
|
+
/** Called on blur of primitive inputs to trigger CD after Angular marks the control as touched. */
|
|
254
|
+
onBlur(): void;
|
|
187
255
|
isSimpleChild(key: string): boolean;
|
|
188
256
|
badgeClass(badge: string): string;
|
|
189
257
|
get nodeKind(): 'oneOf' | 'anyOf' | 'allOf' | 'object' | 'array' | 'primitive';
|
|
190
258
|
get resolvedType(): JsonSchema['type'] | 'enum';
|
|
191
|
-
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';
|
|
192
263
|
get inputType(): string;
|
|
193
264
|
get controlAsGroup(): FormGroup;
|
|
194
265
|
get controlAsFormControl(): FormControl;
|
|
@@ -199,6 +270,8 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
199
270
|
get complexKeys(): string[];
|
|
200
271
|
get canAddProperty(): boolean;
|
|
201
272
|
get errorsForPath(): string[];
|
|
273
|
+
/** Combined errors: Ajv errors from errorsMap + Angular validator errors on the control. */
|
|
274
|
+
get allErrors(): string[];
|
|
202
275
|
get metaBadges(): string[];
|
|
203
276
|
get activeVariant(): JsonSchema | null;
|
|
204
277
|
get mergedAllOf(): JsonSchema[];
|
|
@@ -220,8 +293,8 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
|
|
|
220
293
|
private applyConditional;
|
|
221
294
|
private applyDependencies;
|
|
222
295
|
private mergeSchemas;
|
|
223
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent,
|
|
224
|
-
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; }; }, { "controlReplaced": "controlReplaced"; }, never, never, true, never>;
|
|
296
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent, [null, null, null, { optional: true; }]>;
|
|
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>;
|
|
225
298
|
}
|
|
226
299
|
|
|
227
300
|
declare class JsonSchemaFormModule {
|
|
@@ -230,5 +303,16 @@ declare class JsonSchemaFormModule {
|
|
|
230
303
|
static ɵinj: i0.ɵɵInjectorDeclaration<JsonSchemaFormModule>;
|
|
231
304
|
}
|
|
232
305
|
|
|
233
|
-
|
|
234
|
-
|
|
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": {
|