@elle96/ng-json-schema-manager 0.1.4 → 0.2.1

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/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, SimpleChanges, OnInit } from '@angular/core';
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,9 @@ 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
+ /** Last value emitted through valueChange (same reference the parent gets back through `data`/`value`). */
210
+ private lastEmitted;
211
+ constructor(schemaService: JsonSchemaFormService, resolver: JsonSchemaResolverService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions, stylesService: JsonSchemaStylesService);
158
212
  ngOnChanges(changes: SimpleChanges): void;
159
213
  ngOnDestroy(): void;
160
214
  /**
@@ -165,22 +219,17 @@ declare class JsonSchemaFormComponent implements OnChanges, OnDestroy {
165
219
  validate(): boolean;
166
220
  private buildForm;
167
221
  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
222
  onRootReplaced(control: AbstractControl): void;
175
223
  private attachValueSub;
176
224
  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>;
225
+ 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
226
  }
179
227
 
180
228
  declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
181
229
  private readonly schemaService;
182
230
  private readonly validation;
183
231
  private readonly cdr;
232
+ private readonly options;
184
233
  schema: JsonSchema;
185
234
  control: AbstractControl;
186
235
  label: string;
@@ -200,7 +249,7 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
200
249
  /** Tracks whether this primitive control has been touched (for OnPush CD). */
201
250
  isTouched: boolean;
202
251
  private valueSub?;
203
- constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef);
252
+ constructor(schemaService: JsonSchemaFormService, validation: JsonSchemaValidationService, cdr: ChangeDetectorRef, options: JsonSchemaFormOptions | null);
204
253
  ngOnInit(): void;
205
254
  ngOnDestroy(): void;
206
255
  /** Called on blur of primitive inputs to trigger CD after Angular marks the control as touched. */
@@ -209,7 +258,10 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
209
258
  badgeClass(badge: string): string;
210
259
  get nodeKind(): 'oneOf' | 'anyOf' | 'allOf' | 'object' | 'array' | 'primitive';
211
260
  get resolvedType(): JsonSchema['type'] | 'enum';
212
- get inputKind(): 'text' | 'textarea' | 'select' | 'checkbox';
261
+ get decimalSeparator(): DecimalSeparator;
262
+ /** `multipleOf` of this node's own schema, exposed as step metadata. */
263
+ get numericStep(): string;
264
+ get inputKind(): 'text' | 'number' | 'textarea' | 'select' | 'checkbox';
213
265
  get inputType(): string;
214
266
  get controlAsGroup(): FormGroup;
215
267
  get controlAsFormControl(): FormControl;
@@ -243,7 +295,7 @@ declare class JsonSchemaNodeComponent implements OnInit, OnDestroy {
243
295
  private applyConditional;
244
296
  private applyDependencies;
245
297
  private mergeSchemas;
246
- static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent, never>;
298
+ static ɵfac: i0.ɵɵFactoryDeclaration<JsonSchemaNodeComponent, [null, null, null, { optional: true; }]>;
247
299
  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
300
  }
249
301
 
@@ -253,5 +305,16 @@ declare class JsonSchemaFormModule {
253
305
  static ɵinj: i0.ɵɵInjectorDeclaration<JsonSchemaFormModule>;
254
306
  }
255
307
 
256
- export { JsonSchemaFormComponent, JsonSchemaFormModule, JsonSchemaFormService, JsonSchemaNodeComponent, JsonSchemaResolverService, JsonSchemaStylesService, JsonSchemaValidationService };
257
- export type { JsonSchema, JsonSchemaArray, JsonSchemaBase, JsonSchemaCombinators, JsonSchemaDraft, JsonSchemaObject, JsonSchemaPrimitive, JsonSchemaType, SchemaError, SchemaFieldContext };
308
+ /**
309
+ * Coerces values to the types declared by the schema so that the emitted value respects it:
310
+ * - `number`/`integer` numeric strings become JSON numbers (comma or dot as separator);
311
+ * - empty numeric values (`""`, whitespace, `null`) leave the key absent, never `""` or `0`;
312
+ * - integers with decimals are converted to their number but never truncated (validation reports them);
313
+ * - non-numeric strings are left unchanged (validation reports them).
314
+ * Descends into properties, patternProperties, additionalProperties, items, prefixItems and combinators.
315
+ * The same function feeds both the Ajv validation and the emitted value.
316
+ */
317
+ declare function normalizeValue(schema: JsonSchema, value: unknown): unknown;
318
+
319
+ export { JsonSchemaFormComponent, JsonSchemaFormModule, JsonSchemaFormOptions, JsonSchemaFormService, JsonSchemaNodeComponent, JsonSchemaResolverService, JsonSchemaStylesService, JsonSchemaValidationService, NumericInputDirective, formatNumeric, localizeNumbers, normalizeValue, parseNumericText, sanitizeNumericText };
320
+ 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.1.4",
3
+ "version": "0.2.1",
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": {