@netwo/devkit 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +45 -2
- package/fesm2022/netwo-devkit-angular-forms.mjs +2125 -0
- package/fesm2022/netwo-devkit-angular-forms.mjs.map +1 -0
- package/fesm2022/netwo-devkit-angular.mjs +3782 -0
- package/fesm2022/netwo-devkit-angular.mjs.map +1 -0
- package/fesm2022/netwo-devkit.mjs +1910 -0
- package/fesm2022/netwo-devkit.mjs.map +1 -0
- package/package.json +55 -3
- package/types/netwo-devkit-angular-forms.d.ts +516 -0
- package/types/netwo-devkit-angular.d.ts +1670 -0
- package/types/netwo-devkit.d.ts +781 -0
|
@@ -0,0 +1,2125 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { isSignal, inject, Injector, signal, DestroyRef, afterNextRender, untracked, effect, ChangeDetectorRef, computed, input, linkedSignal, booleanAttribute, HostBinding, Input, Directive, Pipe } from '@angular/core';
|
|
3
|
+
import { setActiveConsumer } from '@angular/core/primitives/signals';
|
|
4
|
+
import { outputFromObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
5
|
+
import { Validators, FormControl, NgControl, PristineChangeEvent, TouchedChangeEvent, StatusChangeEvent, ValueChangeEvent, isFormControl, FormGroup, FormArray } from '@angular/forms';
|
|
6
|
+
import { isArray, isNullable, isString, isDateInRange, isEmpty, parseFrenchPhoneNumber, getPhoneNumberUtil, isNumber, cidrIsNetworkAddress, luhn, isNotNullable, isObject, ONCE, strictComparer, deepEqual, identity } from '@netwo/devkit';
|
|
7
|
+
import { toLazySignal } from 'ngxtension/to-lazy-signal';
|
|
8
|
+
import { Subject, filter, map, merge, startWith, switchMap, NEVER, Observable, Subscription } from 'rxjs';
|
|
9
|
+
import * as i1 from '@netwo/devkit/angular';
|
|
10
|
+
import { getRootInjector, DisabledStateDirective, RequiredStateDirective, fromNextRender } from '@netwo/devkit/angular';
|
|
11
|
+
import { PhoneNumberType } from 'google-libphonenumber';
|
|
12
|
+
import { DateTime } from 'luxon';
|
|
13
|
+
import { createInjectionToken } from 'ngxtension/create-injection-token';
|
|
14
|
+
import { validate as validate$1, required } from '@angular/forms/signals';
|
|
15
|
+
import { assertInjector } from 'ngxtension/assert-injector';
|
|
16
|
+
|
|
17
|
+
function createGroupValidator(targetControlName, errorKey, validateFn, options) {
|
|
18
|
+
const errorConflict = options?.errorConflict ?? 'skip';
|
|
19
|
+
const targetControlNames = isArray(targetControlName)
|
|
20
|
+
? targetControlName
|
|
21
|
+
: [targetControlName];
|
|
22
|
+
return (control) => {
|
|
23
|
+
const error = validateFn(control);
|
|
24
|
+
for (const name of targetControlNames) {
|
|
25
|
+
const targetControl = control.get(name);
|
|
26
|
+
if (!targetControl)
|
|
27
|
+
continue;
|
|
28
|
+
let errors = targetControl.errors ? { ...targetControl.errors } : null;
|
|
29
|
+
if (!error && errors?.[errorKey]) {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
31
|
+
delete errors[errorKey];
|
|
32
|
+
const hasOtherErrors = Object.keys(errors).length > 0;
|
|
33
|
+
errors = hasOtherErrors ? errors : null;
|
|
34
|
+
}
|
|
35
|
+
else if (error && !errors?.[errorKey]) {
|
|
36
|
+
const errorsLength = errors ? Object.keys(errors).length : 0;
|
|
37
|
+
if (errorConflict === 'append') {
|
|
38
|
+
errors = { ...(errors ?? {}), ...error };
|
|
39
|
+
}
|
|
40
|
+
else if (errorConflict === 'overwrite' || !errorsLength) {
|
|
41
|
+
errors = error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
targetControl.setErrors(errors, { emitEvent: true });
|
|
45
|
+
}
|
|
46
|
+
return error;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Default, empty message catalog.
|
|
52
|
+
*
|
|
53
|
+
* Used as a fallback when no messages are provided (e.g. isolated devkit unit
|
|
54
|
+
* tests) so that validators never crash. Applications are expected to override
|
|
55
|
+
* it via {@link provideValidatorMessagesToken}.
|
|
56
|
+
*/
|
|
57
|
+
const DEFAULT_VALIDATOR_MESSAGES = {
|
|
58
|
+
alphaNumeric: '',
|
|
59
|
+
arcepSlicePrefix: '',
|
|
60
|
+
companyType: '',
|
|
61
|
+
dataVolumeRangeInteger: '',
|
|
62
|
+
differentDate: '',
|
|
63
|
+
email: '',
|
|
64
|
+
esignatureField: '',
|
|
65
|
+
fileType: '',
|
|
66
|
+
frenchPhoneNumber: '',
|
|
67
|
+
ipv4: '',
|
|
68
|
+
ipv4WithoutMask: '',
|
|
69
|
+
kvk: '',
|
|
70
|
+
legalIdentifierRcs: '',
|
|
71
|
+
legalIdentifierVatFr: '',
|
|
72
|
+
mobilePhoneNumber: '',
|
|
73
|
+
nafApe: '',
|
|
74
|
+
portabilityPrefix: '',
|
|
75
|
+
portableApnfNumber: '',
|
|
76
|
+
required: '',
|
|
77
|
+
requiredTrue: '',
|
|
78
|
+
rio: '',
|
|
79
|
+
siren: '',
|
|
80
|
+
siret: '',
|
|
81
|
+
unique: '',
|
|
82
|
+
url: '',
|
|
83
|
+
vatFr: '',
|
|
84
|
+
vatNl: '',
|
|
85
|
+
cidrIsNetworkAddress: () => '',
|
|
86
|
+
dataVolumeRange: () => '',
|
|
87
|
+
dateRange: () => '',
|
|
88
|
+
length: () => '',
|
|
89
|
+
lengthRange: () => '',
|
|
90
|
+
max: () => '',
|
|
91
|
+
maxFileSize: () => '',
|
|
92
|
+
maxLength: () => '',
|
|
93
|
+
maxTextLength: () => '',
|
|
94
|
+
min: () => '',
|
|
95
|
+
minLength: () => '',
|
|
96
|
+
minTextLength: () => '',
|
|
97
|
+
range: () => '',
|
|
98
|
+
simNumber: () => '',
|
|
99
|
+
textLength: () => '',
|
|
100
|
+
textLengthRange: () => '',
|
|
101
|
+
};
|
|
102
|
+
const [injectValidatorMessages, provideValidatorMessagesToken, VALIDATOR_MESSAGES,] = /* @__PURE__ */ createInjectionToken(() => DEFAULT_VALIDATOR_MESSAGES);
|
|
103
|
+
/**
|
|
104
|
+
* Resolves the validator messages outside of an Angular injection context.
|
|
105
|
+
*
|
|
106
|
+
* Validators are called eagerly (e.g. during class-field initialization or
|
|
107
|
+
* `fb.control(...)`) so they cannot rely on `inject()`. This helper reads the
|
|
108
|
+
* token from the root injector, mirroring how `LOCALE_ID` is resolved.
|
|
109
|
+
*
|
|
110
|
+
* Falls back to {@link DEFAULT_VALIDATOR_MESSAGES} if the root injector is not
|
|
111
|
+
* set yet or the token is not provided.
|
|
112
|
+
*/
|
|
113
|
+
function getValidatorMessages() {
|
|
114
|
+
try {
|
|
115
|
+
return (getRootInjector().get(VALIDATOR_MESSAGES, null, { optional: true }) ??
|
|
116
|
+
DEFAULT_VALIDATOR_MESSAGES);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return DEFAULT_VALIDATOR_MESSAGES;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const ALPHA_NUMERIC_REGEX$1 = /^[a-zA-Z\d]*$/;
|
|
124
|
+
const ARCEP_SLICE_PREFIX_REGEX$1 = /^0[1-5|9]\d{4,7}$/;
|
|
125
|
+
const ICCID_MIN_LENGTH$1 = 17;
|
|
126
|
+
const ICCID_MAX_LENGTH$1 = 20;
|
|
127
|
+
const ESIGNATURE_SIGNER_MIN_LENGTH$1 = 1;
|
|
128
|
+
const ESIGNATURE_SIGNER_MAX_LENGTH$1 = 254;
|
|
129
|
+
const ESIGNATURE_SIGNER_REGEX$1 = /^(?!\s)[0-9A-Za-zĄÀÁÂÃÄÅÇĆÈÉÊËĘÌÍÎÏŁÑŃÒÓÔÕÖŚÙÚÛÜÝŹŻąàáâãäåæçćèéêëęìíîïłñńòóôõöśùúûüýÿźżßĀāĂăĈĉĊċČčĎďĐđĒēĔĕĖėĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŽžſøØÆȘșȚț`'() -]+(?<!\s)$/;
|
|
130
|
+
const KVK_LENGTH$1 = 8;
|
|
131
|
+
const KVK_REGEX$1 = /^[0-9]{8}$/;
|
|
132
|
+
const NAF_APE_LENGTH$1 = 5;
|
|
133
|
+
const NAF_APE_REGEX$1 = /^[0-9]{4}[A-Z]$/;
|
|
134
|
+
const NSCE_LENGTH$1 = 13;
|
|
135
|
+
const PORTABILITY_PREFIX_LENGTH$1 = 6;
|
|
136
|
+
const PORTABILITY_PREFIX_REGEX$1 = /^0\d{5}$/;
|
|
137
|
+
const PORTABILITY_NUMBER_REGEX$1 = /^0[1-59][0-9]{8}$/;
|
|
138
|
+
const RCS_REGEX$1 = /^.+ [AB] ([0-9]{9})$/;
|
|
139
|
+
const RCS_NEW_REGEX = /^([0-9]{3} ?[0-9]{3} ?[0-9]{3}) R\.?C\.?S\.? .+$/;
|
|
140
|
+
const RIO_LENGTH$1 = 12;
|
|
141
|
+
const RIO_REGEX$1 = /^[A-Za-z0-9][A-Za-z0-9][A-Z][A-Z0-9+]{6}[A-Z0-9+]{3}$/; // Ex: AAZQQQQQQ222;
|
|
142
|
+
const SIREN_LENGTH$1 = 9;
|
|
143
|
+
const SIRET_LENGTH$1 = 14;
|
|
144
|
+
const URL_REGEX$1 = /^https?:\/\/(www.)?[-a-zA-Z0-9@:%._+~#=]+\.[a-zA-Z0-9()]+[-a-zA-Z0-9()@:%_+.~#?&/=]*$/;
|
|
145
|
+
const VAT_FR_LENGTH$1 = 13;
|
|
146
|
+
const VAT_FR_REGEX$1 = /^FR([0-9]{2})([0-9]{9})$/;
|
|
147
|
+
const VAT_NL_LENGTH$1 = 14;
|
|
148
|
+
const VAT_NL_REGEX$1 = /^NL[0-9]{9}B[0-9]{2}$/;
|
|
149
|
+
function lengthOrSize$1(value) {
|
|
150
|
+
if (isNullable(value))
|
|
151
|
+
return null;
|
|
152
|
+
if (isArray(value) || (isString(value) && !!value))
|
|
153
|
+
return value.length;
|
|
154
|
+
if (value instanceof Set)
|
|
155
|
+
return value.size;
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const customFileTypes$1 = ['csv', 'xlsx'];
|
|
159
|
+
const FILE_TYPES_MAP$1 = {
|
|
160
|
+
csv: [
|
|
161
|
+
'text/csv',
|
|
162
|
+
'application/csv',
|
|
163
|
+
'application/x-csv',
|
|
164
|
+
'text/comma-separated-values',
|
|
165
|
+
'text/x-comma-separated-values',
|
|
166
|
+
'application/vnd.ms-excel',
|
|
167
|
+
],
|
|
168
|
+
xlsx: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
169
|
+
};
|
|
170
|
+
function getFileTypes$1(fileTypes) {
|
|
171
|
+
return fileTypes.reduce((acc, fileType) => {
|
|
172
|
+
const type = FILE_TYPES_MAP$1[fileType] ?? [fileType];
|
|
173
|
+
acc.push(...type);
|
|
174
|
+
return acc;
|
|
175
|
+
}, []);
|
|
176
|
+
}
|
|
177
|
+
function validatorDataVolumeRange$1(min, max) {
|
|
178
|
+
return (control) => {
|
|
179
|
+
if (isNullable(control.value))
|
|
180
|
+
return null;
|
|
181
|
+
const range = validatorRange$1(min, max)(control);
|
|
182
|
+
const messages = getValidatorMessages();
|
|
183
|
+
if (range) {
|
|
184
|
+
return {
|
|
185
|
+
dataVolumeRange: messages.dataVolumeRange({
|
|
186
|
+
minVolume: min,
|
|
187
|
+
maxVolume: max,
|
|
188
|
+
}),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (!Number.isInteger(control.value)) {
|
|
192
|
+
return {
|
|
193
|
+
dataVolumeRange: messages.dataVolumeRangeInteger,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function validatorDateRange$1(range, useTime = false) {
|
|
200
|
+
return (control) => {
|
|
201
|
+
if (isNullable(control.value) ||
|
|
202
|
+
isDateInRange(range, control.value, useTime)) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const [startDate, endDate] = range;
|
|
206
|
+
const error = getValidatorMessages().dateRange({
|
|
207
|
+
startDate: startDate ?? undefined,
|
|
208
|
+
endDate: endDate ?? undefined,
|
|
209
|
+
useTime,
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
dateRange: {
|
|
213
|
+
startDate,
|
|
214
|
+
endDate,
|
|
215
|
+
actualDate: control.value,
|
|
216
|
+
error,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function validatorDifferentDate$1(date) {
|
|
222
|
+
return ({ value }) => {
|
|
223
|
+
if (!value)
|
|
224
|
+
return null;
|
|
225
|
+
const curDateStr = DateTime.fromJSDate(value).toISODate({
|
|
226
|
+
format: 'basic',
|
|
227
|
+
});
|
|
228
|
+
const dateStr = DateTime.fromJSDate(date).toISODate({
|
|
229
|
+
format: 'basic',
|
|
230
|
+
});
|
|
231
|
+
return curDateStr === dateStr
|
|
232
|
+
? {
|
|
233
|
+
differentDate: {
|
|
234
|
+
date,
|
|
235
|
+
error: getValidatorMessages().differentDate,
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
: null;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function validatorEmail$1(control) {
|
|
242
|
+
if (!Validators.email(control))
|
|
243
|
+
return null;
|
|
244
|
+
return { email: getValidatorMessages().email };
|
|
245
|
+
}
|
|
246
|
+
function validatorFileType$1(...fileTypes) {
|
|
247
|
+
return ({ value }) => {
|
|
248
|
+
if (isNullable(value) || getFileTypes$1(fileTypes).includes(value.type))
|
|
249
|
+
return null;
|
|
250
|
+
return {
|
|
251
|
+
fileType: {
|
|
252
|
+
requiredFileTypes: fileTypes,
|
|
253
|
+
actualFileType: value.type,
|
|
254
|
+
error: getValidatorMessages().fileType,
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function validatorFrenchPhoneNumber$1({ value, }) {
|
|
260
|
+
if (isEmpty(value))
|
|
261
|
+
return null;
|
|
262
|
+
return parseFrenchPhoneNumber(value)
|
|
263
|
+
? null
|
|
264
|
+
: {
|
|
265
|
+
frenchPhoneNumber: getValidatorMessages().frenchPhoneNumber,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function validatorLength$1(requiredLength) {
|
|
269
|
+
return ({ value }) => {
|
|
270
|
+
const actualLength = lengthOrSize$1(value);
|
|
271
|
+
if (actualLength === null || actualLength === requiredLength)
|
|
272
|
+
return null;
|
|
273
|
+
return {
|
|
274
|
+
length: {
|
|
275
|
+
requiredLength,
|
|
276
|
+
actualLength,
|
|
277
|
+
error: getValidatorMessages().length({ requiredLength }),
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function validatorLengthRange$1(range) {
|
|
283
|
+
const { min = -Infinity, max = Infinity } = range;
|
|
284
|
+
return ({ value }) => {
|
|
285
|
+
const actualLength = lengthOrSize$1(value);
|
|
286
|
+
if (actualLength === null || (actualLength >= min && actualLength <= max))
|
|
287
|
+
return null;
|
|
288
|
+
return {
|
|
289
|
+
textLength: {
|
|
290
|
+
minLength: min,
|
|
291
|
+
maxLength: max,
|
|
292
|
+
actualLength,
|
|
293
|
+
error: getValidatorMessages().lengthRange({ min, max }),
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function validatorMax$1(max) {
|
|
299
|
+
return (control) => {
|
|
300
|
+
const error = Validators.max(max)(control);
|
|
301
|
+
if (!error)
|
|
302
|
+
return null;
|
|
303
|
+
return {
|
|
304
|
+
max: {
|
|
305
|
+
...error.max,
|
|
306
|
+
error: getValidatorMessages().max({ max }),
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function validatorMaxLength$1(maxLength) {
|
|
312
|
+
return (control) => {
|
|
313
|
+
const error = Validators.maxLength(maxLength)(control);
|
|
314
|
+
if (!error)
|
|
315
|
+
return null;
|
|
316
|
+
return {
|
|
317
|
+
maxLength: {
|
|
318
|
+
...error.maxLength,
|
|
319
|
+
error: getValidatorMessages().maxLength({ maxLength }),
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function validatorMaxFileSize$1(maxFileSize) {
|
|
325
|
+
return ({ value }) => {
|
|
326
|
+
if (isNullable(value) || value.size < maxFileSize)
|
|
327
|
+
return null;
|
|
328
|
+
return {
|
|
329
|
+
maxFileSize: {
|
|
330
|
+
requiredFileSize: maxFileSize,
|
|
331
|
+
actualFileSize: value.size,
|
|
332
|
+
error: getValidatorMessages().maxFileSize({ size: maxFileSize }),
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function validatorMaxTextLength$1(maxTextLength) {
|
|
338
|
+
return ({ value }) => {
|
|
339
|
+
if (!value || value.length <= maxTextLength)
|
|
340
|
+
return null;
|
|
341
|
+
return {
|
|
342
|
+
textLength: {
|
|
343
|
+
maxTextLength,
|
|
344
|
+
actualTextLength: value.length,
|
|
345
|
+
error: getValidatorMessages().maxTextLength({ maxTextLength }),
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function validatorMin$1(min) {
|
|
351
|
+
return (control) => {
|
|
352
|
+
const error = Validators.min(min)(control);
|
|
353
|
+
if (!error)
|
|
354
|
+
return null;
|
|
355
|
+
return {
|
|
356
|
+
min: {
|
|
357
|
+
...error.min,
|
|
358
|
+
error: getValidatorMessages().min({ min }),
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function validatorMinLength$1(minLength) {
|
|
364
|
+
return (control) => {
|
|
365
|
+
const error = Validators.minLength(minLength)(control);
|
|
366
|
+
if (!error)
|
|
367
|
+
return null;
|
|
368
|
+
return {
|
|
369
|
+
minLength: {
|
|
370
|
+
...error.minLength,
|
|
371
|
+
error: getValidatorMessages().minLength({ minLength }),
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function validatorMinTextLength$1(minTextLength) {
|
|
377
|
+
return ({ value }) => {
|
|
378
|
+
if (!value || value.length >= minTextLength)
|
|
379
|
+
return null;
|
|
380
|
+
return {
|
|
381
|
+
textLength: {
|
|
382
|
+
minTextLength,
|
|
383
|
+
actualTextLength: value.length,
|
|
384
|
+
error: getValidatorMessages().minTextLength({ minTextLength }),
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function validatorMobilePhoneNumber$1({ value, }) {
|
|
390
|
+
if (isNullable(value))
|
|
391
|
+
return null;
|
|
392
|
+
if (getPhoneNumberUtil().isPossibleNumber(value) &&
|
|
393
|
+
getPhoneNumberUtil().getNumberType(value) === PhoneNumberType.MOBILE) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
mobilePhoneNumber: getValidatorMessages().mobilePhoneNumber,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Validate that the provided number start by "01", "02", "03", "04", "05" ou "09".
|
|
402
|
+
* "06" and "07" are Mobile specific, and "08" are custom number excluded from our portability flow.
|
|
403
|
+
* @param value French phone number to validate
|
|
404
|
+
* @returns `null` if valid, or a `FormErrors` object with a `frenchPhoneNumber` key if invalid
|
|
405
|
+
*/
|
|
406
|
+
function validatorPortableApnfNumber$1({ value, }) {
|
|
407
|
+
if (isEmpty(value))
|
|
408
|
+
return null;
|
|
409
|
+
const parsed = parseFrenchPhoneNumber(value);
|
|
410
|
+
if (parsed && PORTABILITY_NUMBER_REGEX$1.test(parsed)) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
error: getValidatorMessages().portableApnfNumber,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function validatorRange$1(min, max) {
|
|
418
|
+
return ({ value }) => {
|
|
419
|
+
if (isNullable(value) || (value >= min && value <= max))
|
|
420
|
+
return null;
|
|
421
|
+
return {
|
|
422
|
+
range: {
|
|
423
|
+
min,
|
|
424
|
+
max,
|
|
425
|
+
actual: value,
|
|
426
|
+
error: getValidatorMessages().range({ min, max }),
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const validatorRequired$1 = (control) => {
|
|
432
|
+
const error = Validators.required(control);
|
|
433
|
+
if (!error)
|
|
434
|
+
return null;
|
|
435
|
+
return {
|
|
436
|
+
required: getValidatorMessages().required,
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
function validatorRequiredTrue$1(control) {
|
|
440
|
+
if (Validators.requiredTrue(control)) {
|
|
441
|
+
return { requiredTrue: getValidatorMessages().requiredTrue };
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
function validatorTextLength$1(requiredLength) {
|
|
446
|
+
return ({ value }) => {
|
|
447
|
+
if (!value || value.length === requiredLength)
|
|
448
|
+
return null;
|
|
449
|
+
return {
|
|
450
|
+
textLength: {
|
|
451
|
+
requiredLength,
|
|
452
|
+
actualLength: value.length,
|
|
453
|
+
error: getValidatorMessages().textLength({ requiredLength }),
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function validatorTextLengthRange$1(minTextLength, maxTextLength) {
|
|
459
|
+
return ({ value }) => {
|
|
460
|
+
if (!value ||
|
|
461
|
+
(value.length >= minTextLength && value.length <= maxTextLength))
|
|
462
|
+
return null;
|
|
463
|
+
return {
|
|
464
|
+
textLength: {
|
|
465
|
+
minTextLength,
|
|
466
|
+
maxTextLength,
|
|
467
|
+
actualLength: value.length,
|
|
468
|
+
error: getValidatorMessages().textLengthRange({
|
|
469
|
+
min: minTextLength,
|
|
470
|
+
max: maxTextLength,
|
|
471
|
+
}),
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function validatorUnique$1(comparedValues, config) {
|
|
477
|
+
return ({ value }) => {
|
|
478
|
+
if (isNullable(value))
|
|
479
|
+
return null;
|
|
480
|
+
const innerValues = isArray(value) ? value : [value];
|
|
481
|
+
const innerComparedValues = isSignal(comparedValues)
|
|
482
|
+
? comparedValues()
|
|
483
|
+
: (comparedValues ?? []);
|
|
484
|
+
const hasDuplicate = new Set(innerValues).size !== innerValues.length;
|
|
485
|
+
return hasDuplicate ||
|
|
486
|
+
innerValues.find((value) => innerComparedValues.includes(value))
|
|
487
|
+
? {
|
|
488
|
+
unique: config?.message ?? getValidatorMessages().unique,
|
|
489
|
+
}
|
|
490
|
+
: null;
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function validatorUrl$1(control) {
|
|
494
|
+
// Match constraint "http_url_check" in database
|
|
495
|
+
const error = Validators.pattern(URL_REGEX$1)(control);
|
|
496
|
+
if (!error)
|
|
497
|
+
return null;
|
|
498
|
+
return {
|
|
499
|
+
url: getValidatorMessages().url,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function genIpv4Regex$1(authorizedMasks) {
|
|
503
|
+
const octet = '(?:25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)';
|
|
504
|
+
const maskPart = authorizedMasks?.length
|
|
505
|
+
? `(?:\\/(?:${authorizedMasks.join('|')}))?`
|
|
506
|
+
: '';
|
|
507
|
+
const pattern = `^(${octet}\\.){3}${octet}${maskPart}$`;
|
|
508
|
+
return new RegExp(pattern);
|
|
509
|
+
}
|
|
510
|
+
function validatorArcepSlicePrefix$1(control) {
|
|
511
|
+
if (Validators.pattern(ARCEP_SLICE_PREFIX_REGEX$1)(control)) {
|
|
512
|
+
return {
|
|
513
|
+
arcepSlicePrefix: getValidatorMessages().arcepSlicePrefix,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
const VALID_COMPANY_TYPES$1 = [
|
|
519
|
+
'Association',
|
|
520
|
+
'EI',
|
|
521
|
+
'EURL',
|
|
522
|
+
'SARL',
|
|
523
|
+
'SASU',
|
|
524
|
+
'SAS',
|
|
525
|
+
'SA',
|
|
526
|
+
'SNC',
|
|
527
|
+
'SCS',
|
|
528
|
+
'SCA',
|
|
529
|
+
'SMF',
|
|
530
|
+
];
|
|
531
|
+
function validatorCompanyType$1({ value, }) {
|
|
532
|
+
if (isEmpty(value) || VALID_COMPANY_TYPES$1.includes(value))
|
|
533
|
+
return null;
|
|
534
|
+
return {
|
|
535
|
+
companyType: getValidatorMessages().companyType,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const MAX_MASK$1 = 32;
|
|
539
|
+
const MIN_MASK$1 = 0;
|
|
540
|
+
function getAuthroizedMaskArr(masks) {
|
|
541
|
+
if (isNumber(masks))
|
|
542
|
+
return [masks];
|
|
543
|
+
if (isArray(masks))
|
|
544
|
+
return masks;
|
|
545
|
+
const min = masks.min ?? MIN_MASK$1;
|
|
546
|
+
const max = (masks.max ?? MAX_MASK$1) + 1;
|
|
547
|
+
return Array.from({ length: max - min }, (_, i) => i + min);
|
|
548
|
+
}
|
|
549
|
+
function validatorIpv4WithMask$1(authorizedMasks = { min: MIN_MASK$1, max: MAX_MASK$1 }) {
|
|
550
|
+
return ({ value }) => {
|
|
551
|
+
if (isNullable(value))
|
|
552
|
+
return null;
|
|
553
|
+
const innerValues = isString(value) ? [value] : value;
|
|
554
|
+
if (!innerValues.length)
|
|
555
|
+
return null;
|
|
556
|
+
const authorizedMasksArr = getAuthroizedMaskArr(authorizedMasks);
|
|
557
|
+
const regExp = genIpv4Regex$1(authorizedMasksArr);
|
|
558
|
+
const hasError = innerValues.some((innerValue) => Validators.pattern(regExp)(new FormControl(innerValue)));
|
|
559
|
+
if (hasError) {
|
|
560
|
+
return {
|
|
561
|
+
ipv4: getValidatorMessages().ipv4,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function validatorIpv4WithoutMask$1(control) {
|
|
568
|
+
if (isEmpty(control.value))
|
|
569
|
+
return null;
|
|
570
|
+
if (Validators.pattern(genIpv4Regex$1(null))(control)) {
|
|
571
|
+
return {
|
|
572
|
+
portabilityPrefix: getValidatorMessages().ipv4WithoutMask,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
function validatorCidrIsNetworkAddress$1({ value, }) {
|
|
578
|
+
if (isNullable(value))
|
|
579
|
+
return null;
|
|
580
|
+
const innerValues = isString(value) ? [value] : value;
|
|
581
|
+
if (!innerValues.length)
|
|
582
|
+
return null;
|
|
583
|
+
const invalidNetworks = innerValues.reduce((acc, innerValue) => {
|
|
584
|
+
if (!cidrIsNetworkAddress(innerValue))
|
|
585
|
+
acc.push(innerValue);
|
|
586
|
+
return acc;
|
|
587
|
+
}, []);
|
|
588
|
+
if (!invalidNetworks.length)
|
|
589
|
+
return null;
|
|
590
|
+
return {
|
|
591
|
+
cidrIsNetworkAddress: getValidatorMessages().cidrIsNetworkAddress({
|
|
592
|
+
invalidNetworks,
|
|
593
|
+
}),
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function validatorKvk$1(control) {
|
|
597
|
+
if (isEmpty(control.value))
|
|
598
|
+
return null;
|
|
599
|
+
const length = validatorTextLength$1(KVK_LENGTH$1)(control);
|
|
600
|
+
if (length)
|
|
601
|
+
return length;
|
|
602
|
+
if (Validators.pattern(KVK_REGEX$1)(control)) {
|
|
603
|
+
return {
|
|
604
|
+
kvk: getValidatorMessages().kvk,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
function validatorNafApe$1(control) {
|
|
610
|
+
if (isEmpty(control.value))
|
|
611
|
+
return null;
|
|
612
|
+
const length = validatorTextLength$1(NAF_APE_LENGTH$1)(control);
|
|
613
|
+
if (length)
|
|
614
|
+
return length;
|
|
615
|
+
if (Validators.pattern(NAF_APE_REGEX$1)(control)) {
|
|
616
|
+
return {
|
|
617
|
+
nafApe: getValidatorMessages().nafApe,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
function validatorPortabilityPrefix$1(control) {
|
|
623
|
+
if (isEmpty(control.value))
|
|
624
|
+
return null;
|
|
625
|
+
const length = validatorTextLength$1(PORTABILITY_PREFIX_LENGTH$1)(control);
|
|
626
|
+
if (length)
|
|
627
|
+
return length;
|
|
628
|
+
if (Validators.pattern(PORTABILITY_PREFIX_REGEX$1)(control)) {
|
|
629
|
+
return {
|
|
630
|
+
portabilityPrefix: getValidatorMessages().portabilityPrefix,
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
function validatorEsignatureSignerField$1(control) {
|
|
636
|
+
if (isEmpty(control.value))
|
|
637
|
+
return null;
|
|
638
|
+
const length = validatorTextLengthRange$1(ESIGNATURE_SIGNER_MIN_LENGTH$1, ESIGNATURE_SIGNER_MAX_LENGTH$1)(control);
|
|
639
|
+
if (length)
|
|
640
|
+
return length;
|
|
641
|
+
if (Validators.pattern(ESIGNATURE_SIGNER_REGEX$1)(control)) {
|
|
642
|
+
return {
|
|
643
|
+
esignatureField: getValidatorMessages().esignatureField,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
function validatorRio$1(control) {
|
|
649
|
+
if (isEmpty(control.value))
|
|
650
|
+
return null;
|
|
651
|
+
const length = validatorTextLength$1(RIO_LENGTH$1)(control);
|
|
652
|
+
if (length)
|
|
653
|
+
return length;
|
|
654
|
+
if (Validators.pattern(RIO_REGEX$1)(control)) {
|
|
655
|
+
return {
|
|
656
|
+
rio: getValidatorMessages().rio,
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
function validatorSimNumber$1(nsceEnabled = false) {
|
|
662
|
+
return (control) => {
|
|
663
|
+
if (isEmpty(control.value))
|
|
664
|
+
return null;
|
|
665
|
+
const minLength = nsceEnabled ? NSCE_LENGTH$1 : ICCID_MIN_LENGTH$1;
|
|
666
|
+
const length = validatorTextLengthRange$1(minLength, ICCID_MAX_LENGTH$1)(control);
|
|
667
|
+
if (length)
|
|
668
|
+
return length;
|
|
669
|
+
if (luhn(control.value))
|
|
670
|
+
return null;
|
|
671
|
+
return {
|
|
672
|
+
simNumber: getValidatorMessages().simNumber({ nsceEnabled }),
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function validatorSiren$1(control) {
|
|
677
|
+
if (isEmpty(control.value))
|
|
678
|
+
return null;
|
|
679
|
+
const length = validatorTextLength$1(SIREN_LENGTH$1)(control);
|
|
680
|
+
if (length)
|
|
681
|
+
return length;
|
|
682
|
+
if (luhn(control.value))
|
|
683
|
+
return null;
|
|
684
|
+
return {
|
|
685
|
+
siren: getValidatorMessages().siren,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
// TODO(@Gillian): should remove param when a solution is found to handle siret-input
|
|
689
|
+
function validatorSiret$1(omitSiren = false) {
|
|
690
|
+
return (control) => {
|
|
691
|
+
if (isEmpty(control.value) ||
|
|
692
|
+
(omitSiren && control.value.length <= SIREN_LENGTH$1))
|
|
693
|
+
return null;
|
|
694
|
+
const length = validatorTextLength$1(SIRET_LENGTH$1)(control);
|
|
695
|
+
if (length)
|
|
696
|
+
return length;
|
|
697
|
+
if (luhn(control.value))
|
|
698
|
+
return null;
|
|
699
|
+
return {
|
|
700
|
+
siret: getValidatorMessages().siret,
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function validatorVatNl$1(control) {
|
|
705
|
+
if (isEmpty(control.value))
|
|
706
|
+
return null;
|
|
707
|
+
const length = validatorTextLength$1(VAT_NL_LENGTH$1)(control);
|
|
708
|
+
if (length)
|
|
709
|
+
return length;
|
|
710
|
+
return Validators.pattern(VAT_NL_REGEX$1)(control)
|
|
711
|
+
? {
|
|
712
|
+
vatNl: getValidatorMessages().vatNl,
|
|
713
|
+
}
|
|
714
|
+
: null;
|
|
715
|
+
}
|
|
716
|
+
function validatorVatFr$1(control) {
|
|
717
|
+
if (isEmpty(control.value))
|
|
718
|
+
return null;
|
|
719
|
+
const length = validatorTextLength$1(VAT_FR_LENGTH$1)(control);
|
|
720
|
+
if (length)
|
|
721
|
+
return length;
|
|
722
|
+
return Validators.pattern(VAT_FR_REGEX$1)(control)
|
|
723
|
+
? {
|
|
724
|
+
vatNl: getValidatorMessages().vatFr,
|
|
725
|
+
}
|
|
726
|
+
: null;
|
|
727
|
+
}
|
|
728
|
+
function validatorAlphaNumeric$1(control) {
|
|
729
|
+
if (isEmpty(control.value))
|
|
730
|
+
return null;
|
|
731
|
+
return Validators.pattern(ALPHA_NUMERIC_REGEX$1)(control)
|
|
732
|
+
? {
|
|
733
|
+
alphaNumeric: getValidatorMessages().alphaNumeric,
|
|
734
|
+
}
|
|
735
|
+
: null;
|
|
736
|
+
}
|
|
737
|
+
const groupValidatorLegalIdentifierRcs$1 =
|
|
738
|
+
/* @__PURE__ */ createGroupValidator('rcs', 'legalIdentifierRcs', ({ value, }) => {
|
|
739
|
+
if (!value.legalIdentifier || !value.rcs)
|
|
740
|
+
return null;
|
|
741
|
+
const groups = RCS_REGEX$1.exec(value.rcs) ?? RCS_NEW_REGEX.exec(value.rcs);
|
|
742
|
+
const siren = groups?.at(1)?.replaceAll(' ', '');
|
|
743
|
+
if (!siren) {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
return value.legalIdentifier && siren === value.legalIdentifier
|
|
747
|
+
? null
|
|
748
|
+
: {
|
|
749
|
+
legalIdentifierRcs: getValidatorMessages().legalIdentifierRcs,
|
|
750
|
+
};
|
|
751
|
+
});
|
|
752
|
+
const groupValidatorLegalIdentifierVatFr$1 =
|
|
753
|
+
/* @__PURE__ */ createGroupValidator('vatNumber', 'legalIdentifierVatFr', ({ value, }) => {
|
|
754
|
+
if (!value.legalIdentifier || !value.vatNumber)
|
|
755
|
+
return null;
|
|
756
|
+
const isChecksumValid = (value, siren) => {
|
|
757
|
+
const groups = VAT_FR_REGEX$1.exec(value);
|
|
758
|
+
const checksumString = groups?.at(1);
|
|
759
|
+
const sirenString = groups?.at(2);
|
|
760
|
+
const checksum = checksumString ? Number.parseInt(checksumString) : 0;
|
|
761
|
+
const vatSiren = sirenString ? Number.parseInt(sirenString) : 0;
|
|
762
|
+
return (sirenString === siren && checksum === (12 + 3 * (vatSiren % 97)) % 97);
|
|
763
|
+
};
|
|
764
|
+
return value.legalIdentifier &&
|
|
765
|
+
isChecksumValid(value.vatNumber, value.legalIdentifier)
|
|
766
|
+
? null
|
|
767
|
+
: {
|
|
768
|
+
legalIdentifierVatFr: getValidatorMessages().legalIdentifierVatFr,
|
|
769
|
+
};
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
773
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
774
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
775
|
+
function injectNgControl(options) {
|
|
776
|
+
const ngControl = inject(NgControl, options);
|
|
777
|
+
return ngControl && patchNgControl(ngControl, inject(Injector));
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Ensures that injected NgControl instances expose the Reactive Forms APIs
|
|
781
|
+
* commonly expected by third-party libraries.
|
|
782
|
+
*
|
|
783
|
+
* Standard Reactive Forms controls are returned unchanged.
|
|
784
|
+
* Signal Forms interop controls are wrapped in an adapter providing
|
|
785
|
+
* observable-based APIs such as valueChanges, statusChanges and events.
|
|
786
|
+
*/
|
|
787
|
+
function patchNgControl(ngControl, injector) {
|
|
788
|
+
if (isSignalFormsInteropControl(ngControl)) {
|
|
789
|
+
return new InteropNgControl(ngControl, injector);
|
|
790
|
+
}
|
|
791
|
+
return ngControl;
|
|
792
|
+
}
|
|
793
|
+
function isSignalFormsInteropControl(ngControl) {
|
|
794
|
+
return !('valueChanges' in ngControl);
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Angular Signal Forms provides its own InteropNgControl implementation
|
|
798
|
+
* to improve compatibility with Reactive Forms APIs.
|
|
799
|
+
*
|
|
800
|
+
* However, Angular explicitly documents that this interoperability layer
|
|
801
|
+
* does not implement the full NgControl / AbstractControl contract.
|
|
802
|
+
*
|
|
803
|
+
* Some third-party components assume that injected NgControl instances
|
|
804
|
+
* expose APIs such as `valueChanges`, `statusChanges`, `events`,
|
|
805
|
+
* `hasValidator()` or `updateValueAndValidity()`.
|
|
806
|
+
*
|
|
807
|
+
* When used with Signal Forms, these APIs may be missing, causing runtime
|
|
808
|
+
* errors despite the object being typed as NgControl.
|
|
809
|
+
*
|
|
810
|
+
* This adapter patches Angular's interop implementation and exposes the
|
|
811
|
+
* most commonly expected Reactive Forms APIs by bridging Signal Forms
|
|
812
|
+
* state into RxJS observables.
|
|
813
|
+
*/
|
|
814
|
+
class InteropNgControl {
|
|
815
|
+
constructor(ngControl, injector) {
|
|
816
|
+
this.ngControl = ngControl;
|
|
817
|
+
this._events = new Subject();
|
|
818
|
+
this._statusChanges = new Subject();
|
|
819
|
+
this._valueChanges = new Subject();
|
|
820
|
+
this.ready = signal(false, /* @ts-ignore */
|
|
821
|
+
...(ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []));
|
|
822
|
+
this.control = this;
|
|
823
|
+
const destroyRef = injector.get(DestroyRef);
|
|
824
|
+
destroyRef.onDestroy(() => {
|
|
825
|
+
this._events.complete();
|
|
826
|
+
this._statusChanges.complete();
|
|
827
|
+
this._valueChanges.complete();
|
|
828
|
+
});
|
|
829
|
+
afterNextRender(() => this.ready.set(true), { injector });
|
|
830
|
+
untracked(() => {
|
|
831
|
+
effect(() => {
|
|
832
|
+
const value = this.pristine;
|
|
833
|
+
if (isNotNullable(value)) {
|
|
834
|
+
this._events.next(new PristineChangeEvent(value, this.control));
|
|
835
|
+
}
|
|
836
|
+
}, { injector });
|
|
837
|
+
effect(() => {
|
|
838
|
+
const value = this.touched;
|
|
839
|
+
if (isNotNullable(value)) {
|
|
840
|
+
this._events.next(new TouchedChangeEvent(value, this.control));
|
|
841
|
+
}
|
|
842
|
+
}, { injector });
|
|
843
|
+
effect(() => {
|
|
844
|
+
const value = this.status;
|
|
845
|
+
if (isNotNullable(value)) {
|
|
846
|
+
this._statusChanges.next(value);
|
|
847
|
+
this._events.next(new StatusChangeEvent(value, this.control));
|
|
848
|
+
}
|
|
849
|
+
}, { injector });
|
|
850
|
+
effect(() => {
|
|
851
|
+
const _value = this.value;
|
|
852
|
+
this._valueChanges.next(_value);
|
|
853
|
+
this._events.next(new ValueChangeEvent(_value, this.control));
|
|
854
|
+
}, { injector });
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
get events() {
|
|
858
|
+
return this._events.asObservable();
|
|
859
|
+
}
|
|
860
|
+
get statusChanges() {
|
|
861
|
+
return this._statusChanges.asObservable();
|
|
862
|
+
}
|
|
863
|
+
get valueChanges() {
|
|
864
|
+
return this._valueChanges.asObservable();
|
|
865
|
+
}
|
|
866
|
+
get value() {
|
|
867
|
+
if (!this.ready())
|
|
868
|
+
return null;
|
|
869
|
+
return this.ngControl.value;
|
|
870
|
+
}
|
|
871
|
+
get valid() {
|
|
872
|
+
if (!this.ready())
|
|
873
|
+
return null;
|
|
874
|
+
return this.ngControl.valid;
|
|
875
|
+
}
|
|
876
|
+
get invalid() {
|
|
877
|
+
if (!this.ready())
|
|
878
|
+
return null;
|
|
879
|
+
return this.ngControl.invalid;
|
|
880
|
+
}
|
|
881
|
+
get pending() {
|
|
882
|
+
if (!this.ready())
|
|
883
|
+
return null;
|
|
884
|
+
return this.ngControl.pending;
|
|
885
|
+
}
|
|
886
|
+
get disabled() {
|
|
887
|
+
if (!this.ready())
|
|
888
|
+
return null;
|
|
889
|
+
return this.ngControl.disabled;
|
|
890
|
+
}
|
|
891
|
+
get enabled() {
|
|
892
|
+
if (!this.ready())
|
|
893
|
+
return null;
|
|
894
|
+
return this.ngControl.enabled;
|
|
895
|
+
}
|
|
896
|
+
get errors() {
|
|
897
|
+
if (!this.ready())
|
|
898
|
+
return null;
|
|
899
|
+
return this.ngControl.errors;
|
|
900
|
+
}
|
|
901
|
+
get pristine() {
|
|
902
|
+
if (!this.ready())
|
|
903
|
+
return null;
|
|
904
|
+
return this.ngControl.pristine;
|
|
905
|
+
}
|
|
906
|
+
get dirty() {
|
|
907
|
+
if (!this.ready())
|
|
908
|
+
return null;
|
|
909
|
+
return this.ngControl.dirty;
|
|
910
|
+
}
|
|
911
|
+
get touched() {
|
|
912
|
+
if (!this.ready())
|
|
913
|
+
return null;
|
|
914
|
+
return this.ngControl.touched;
|
|
915
|
+
}
|
|
916
|
+
get untouched() {
|
|
917
|
+
if (!this.ready())
|
|
918
|
+
return null;
|
|
919
|
+
return this.ngControl.untouched;
|
|
920
|
+
}
|
|
921
|
+
get status() {
|
|
922
|
+
if (!this.ready())
|
|
923
|
+
return null;
|
|
924
|
+
return this.ngControl.status;
|
|
925
|
+
}
|
|
926
|
+
get valueAccessor() {
|
|
927
|
+
return this.ngControl.valueAccessor;
|
|
928
|
+
}
|
|
929
|
+
set valueAccessor(valueAccessor) {
|
|
930
|
+
this.ngControl.valueAccessor = valueAccessor;
|
|
931
|
+
}
|
|
932
|
+
hasValidator(validator) {
|
|
933
|
+
return this.ngControl.control?.hasValidator(validator) ?? false;
|
|
934
|
+
}
|
|
935
|
+
updateValueAndValidity() {
|
|
936
|
+
this.ngControl.control?.updateValueAndValidity();
|
|
937
|
+
}
|
|
938
|
+
markAsTouched() {
|
|
939
|
+
// ignore
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function injectCva() {
|
|
944
|
+
return inject(CvaDirective);
|
|
945
|
+
}
|
|
946
|
+
const NoValue = /* @__PURE__ */ Symbol();
|
|
947
|
+
function isWriteValueEvent(value) {
|
|
948
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
949
|
+
return isObject(value) && value.type === 'writeValue';
|
|
950
|
+
}
|
|
951
|
+
function toCvaValue(cva, options) {
|
|
952
|
+
const { equal, initialValue } = options ?? {};
|
|
953
|
+
const initialValue$ = ONCE.pipe(filter(() => !cva.hasNoValue), map(() => cva.value));
|
|
954
|
+
const value$ = merge(initialValue$, cva.valueChanges$).pipe(startWith(initialValue), map((value) => value ?? initialValue));
|
|
955
|
+
return toLazySignal(value$, {
|
|
956
|
+
...(equal
|
|
957
|
+
? {
|
|
958
|
+
equal: (a, b) => {
|
|
959
|
+
if (isNullable(a) || isNullable(b))
|
|
960
|
+
return a === b;
|
|
961
|
+
return equal(a, b);
|
|
962
|
+
},
|
|
963
|
+
}
|
|
964
|
+
: {}),
|
|
965
|
+
requireSync: true,
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Control value accessor host directive
|
|
970
|
+
* Enable the ability to use the ReactiveForm directive on the host component
|
|
971
|
+
*/
|
|
972
|
+
class CvaDirective {
|
|
973
|
+
// NgControl instance.
|
|
974
|
+
set ngControl(ngControl) {
|
|
975
|
+
this._explicitNgControl = ngControl;
|
|
976
|
+
this._stateChange();
|
|
977
|
+
}
|
|
978
|
+
get ngControl() {
|
|
979
|
+
return this._implicitNgControl ?? this._explicitNgControl;
|
|
980
|
+
}
|
|
981
|
+
set value(value) {
|
|
982
|
+
this.setValue(value, { source: 'user' });
|
|
983
|
+
}
|
|
984
|
+
get value() {
|
|
985
|
+
return untracked(this.valueSignal);
|
|
986
|
+
}
|
|
987
|
+
get hasValue() {
|
|
988
|
+
return untracked(this._valueSignal) !== NoValue;
|
|
989
|
+
}
|
|
990
|
+
get hasNoValue() {
|
|
991
|
+
return !this.hasValue;
|
|
992
|
+
}
|
|
993
|
+
set disabled(value) {
|
|
994
|
+
this.setDisabledState(value);
|
|
995
|
+
}
|
|
996
|
+
get disabled() {
|
|
997
|
+
if (isNotNullable(this.ngControl?.disabled)) {
|
|
998
|
+
return this.ngControl.disabled;
|
|
999
|
+
}
|
|
1000
|
+
return this._disabledState.disabled();
|
|
1001
|
+
}
|
|
1002
|
+
set required(value) {
|
|
1003
|
+
this.setRequiredState(value);
|
|
1004
|
+
}
|
|
1005
|
+
get required() {
|
|
1006
|
+
if (this.ngControl?.control) {
|
|
1007
|
+
return (this.ngControl.control.hasValidator(Validators.required) ||
|
|
1008
|
+
this.ngControl.control.hasValidator(validatorRequired$1));
|
|
1009
|
+
}
|
|
1010
|
+
return this._requiredState.required();
|
|
1011
|
+
}
|
|
1012
|
+
// Error state
|
|
1013
|
+
get errorState() {
|
|
1014
|
+
return !!this._errorState;
|
|
1015
|
+
}
|
|
1016
|
+
constructor() {
|
|
1017
|
+
this._explicitNgControl = null;
|
|
1018
|
+
this._implicitNgControl = injectNgControl({
|
|
1019
|
+
host: true,
|
|
1020
|
+
optional: true,
|
|
1021
|
+
});
|
|
1022
|
+
// Change detector reference
|
|
1023
|
+
this._cdr = inject(ChangeDetectorRef, { host: true });
|
|
1024
|
+
// Destroy ref
|
|
1025
|
+
this._destroyRef = inject(DestroyRef);
|
|
1026
|
+
// Disabled state directive
|
|
1027
|
+
this._disabledState = inject(DisabledStateDirective, {
|
|
1028
|
+
self: true,
|
|
1029
|
+
});
|
|
1030
|
+
// Required state directive
|
|
1031
|
+
this._requiredState = inject(RequiredStateDirective, {
|
|
1032
|
+
self: true,
|
|
1033
|
+
});
|
|
1034
|
+
this._valueSignal = signal(NoValue, /* @ts-ignore */
|
|
1035
|
+
...(ngDevMode ? [{ debugName: "_valueSignal" }] : /* istanbul ignore next */ []));
|
|
1036
|
+
this.valueSignal = computed(() => {
|
|
1037
|
+
const value = this._valueSignal();
|
|
1038
|
+
if (value === NoValue) {
|
|
1039
|
+
throw new Error(`Value has not been initialized. Call input 'value' or use a reactive form controller.`);
|
|
1040
|
+
}
|
|
1041
|
+
return value;
|
|
1042
|
+
}, /* @ts-ignore */
|
|
1043
|
+
...(ngDevMode ? [{ debugName: "valueSignal" }] : /* istanbul ignore next */ []));
|
|
1044
|
+
this._errorState = null;
|
|
1045
|
+
// Emits when state of the control has been changed
|
|
1046
|
+
this._stateChanges$ = new Subject();
|
|
1047
|
+
this.stateChanges$ = this._stateChanges$.asObservable();
|
|
1048
|
+
this.valueChanges$ = this.stateChanges$.pipe(filter((state) => isWriteValueEvent(state) && state.emitEvent), map(() => this.value));
|
|
1049
|
+
this.compareWithInput = input(strictComparer(), { ...(ngDevMode ? { debugName: "compareWithInput" } : /* istanbul ignore next */ {}),
|
|
1050
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
1051
|
+
alias: 'compareWith' });
|
|
1052
|
+
this._compareWith = linkedSignal(() => this.compareWithInput(), /* @ts-ignore */
|
|
1053
|
+
...(ngDevMode ? [{ debugName: "_compareWith" }] : /* istanbul ignore next */ []));
|
|
1054
|
+
// Emits when value has been changed
|
|
1055
|
+
this.valueChange = outputFromObservable(this.valueChanges$);
|
|
1056
|
+
// Emits when required state has been changed
|
|
1057
|
+
this.requiredChanges$ = this.stateChanges$.pipe(filter((state) => state === 'setRequiredState'), map(() => this.required));
|
|
1058
|
+
// Emits when disabled state has been changed
|
|
1059
|
+
this.disabledChanges$ = this.stateChanges$.pipe(filter((state) => state === 'setDisabledState'), map(() => this.disabled));
|
|
1060
|
+
// Emits when the validity of control has been changed
|
|
1061
|
+
this.errorStateChanges$ = this.stateChanges$.pipe(filter((state) => state === 'updateErrorState'), map(() => this.errorState));
|
|
1062
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1063
|
+
this.onChange = () => { };
|
|
1064
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1065
|
+
this.onTouched = () => { };
|
|
1066
|
+
if (this.ngControl) {
|
|
1067
|
+
this.ngControl.valueAccessor = this;
|
|
1068
|
+
}
|
|
1069
|
+
fromNextRender()
|
|
1070
|
+
.pipe(switchMap(() => this.ngControl?.control?.events ?? NEVER), takeUntilDestroyed(this._destroyRef))
|
|
1071
|
+
.subscribe(() => this._cdr.markForCheck());
|
|
1072
|
+
}
|
|
1073
|
+
ngDoCheck() {
|
|
1074
|
+
this.setRequiredState(this.required);
|
|
1075
|
+
this.updateErrorState();
|
|
1076
|
+
}
|
|
1077
|
+
ngOnDestroy() {
|
|
1078
|
+
this._stateChanges$.complete();
|
|
1079
|
+
}
|
|
1080
|
+
writeValue(value) {
|
|
1081
|
+
this._setValue(value, { source: 'program-accessor' });
|
|
1082
|
+
}
|
|
1083
|
+
registerOnChange(fn) {
|
|
1084
|
+
this.onChange = fn;
|
|
1085
|
+
}
|
|
1086
|
+
registerOnTouched(fn) {
|
|
1087
|
+
this.onTouched = () => {
|
|
1088
|
+
fn();
|
|
1089
|
+
this.updateErrorState();
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
setDisabledState(isDisabled) {
|
|
1093
|
+
if (isDisabled === this._disabledState.disabled()) {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
const previousConsumer = setActiveConsumer(null);
|
|
1097
|
+
try {
|
|
1098
|
+
this._disabledState.disabled.set(isDisabled);
|
|
1099
|
+
}
|
|
1100
|
+
finally {
|
|
1101
|
+
setActiveConsumer(previousConsumer);
|
|
1102
|
+
}
|
|
1103
|
+
this._stateChange('setDisabledState');
|
|
1104
|
+
}
|
|
1105
|
+
setRequiredState(isRequired) {
|
|
1106
|
+
if (isRequired === this._requiredState.required()) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
const previousConsumer = setActiveConsumer(null);
|
|
1110
|
+
try {
|
|
1111
|
+
this._requiredState.required.set(isRequired);
|
|
1112
|
+
}
|
|
1113
|
+
finally {
|
|
1114
|
+
setActiveConsumer(previousConsumer);
|
|
1115
|
+
}
|
|
1116
|
+
this._stateChange('setRequiredState');
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Need re-validates errors on every CD iteration to make sure we are also
|
|
1120
|
+
* covering non-control errors, errors that happens outside of this control
|
|
1121
|
+
*/
|
|
1122
|
+
updateErrorState() {
|
|
1123
|
+
const control = this.ngControl ? this.ngControl.control : null;
|
|
1124
|
+
const newStatusIsError = control?.invalid && control.touched;
|
|
1125
|
+
const newErrorState = newStatusIsError ? control.errors : null;
|
|
1126
|
+
if (!deepEqual(this._errorState, newErrorState)) {
|
|
1127
|
+
this._errorState = newErrorState;
|
|
1128
|
+
this._stateChange('updateErrorState');
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Used to change the value of a control.
|
|
1133
|
+
* @param value the value to be applied
|
|
1134
|
+
* @param notifyAccessor @default true whether to emit "onChange" event.
|
|
1135
|
+
* @param notifyControl @default true trigger "valueChanges" stream.
|
|
1136
|
+
* Should be "false", if the change is made programmatically (internally) by the control, "true" otherwise
|
|
1137
|
+
*/
|
|
1138
|
+
setValue(value, options) {
|
|
1139
|
+
const { notifyAccessor = true, notifyControl = true, source } = options;
|
|
1140
|
+
const change = this._setValue(value, {
|
|
1141
|
+
source,
|
|
1142
|
+
emitEvent: notifyControl,
|
|
1143
|
+
});
|
|
1144
|
+
if (change && notifyAccessor) {
|
|
1145
|
+
this.onChange(value);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
_setValue(value, options) {
|
|
1149
|
+
const { emitEvent = true, source } = options;
|
|
1150
|
+
const compareWith = untracked(this._compareWith);
|
|
1151
|
+
const curValue = untracked(this._valueSignal);
|
|
1152
|
+
const change = curValue === NoValue || !compareWith(value, curValue);
|
|
1153
|
+
if (change) {
|
|
1154
|
+
this._valueSignal.set(value);
|
|
1155
|
+
if (curValue !== NoValue) {
|
|
1156
|
+
this._stateChange({
|
|
1157
|
+
emitEvent,
|
|
1158
|
+
source,
|
|
1159
|
+
type: 'writeValue',
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return change;
|
|
1164
|
+
}
|
|
1165
|
+
// mark parent control as touched
|
|
1166
|
+
markAsTouched() {
|
|
1167
|
+
this.ngControl?.control?.markAsTouched();
|
|
1168
|
+
}
|
|
1169
|
+
_stateChange(kind = 'unknown') {
|
|
1170
|
+
this._stateChanges$.next(kind);
|
|
1171
|
+
this._cdr.markForCheck();
|
|
1172
|
+
}
|
|
1173
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CvaDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1174
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: CvaDirective, isStandalone: true, inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: false, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: false, isRequired: false, transformFunction: booleanAttribute }, required: { classPropertyName: "required", publicName: "required", isSignal: false, isRequired: false, transformFunction: booleanAttribute }, compareWithInput: { classPropertyName: "compareWithInput", publicName: "compareWith", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "valueChange" }, host: { properties: { "class.n-error-state": "this.errorState" } }, hostDirectives: [{ directive: i1.DisabledStateDirective }, { directive: i1.RequiredStateDirective }], ngImport: i0 }); }
|
|
1175
|
+
}
|
|
1176
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: CvaDirective, decorators: [{
|
|
1177
|
+
type: Directive,
|
|
1178
|
+
args: [{
|
|
1179
|
+
hostDirectives: [DisabledStateDirective, RequiredStateDirective],
|
|
1180
|
+
}]
|
|
1181
|
+
}], ctorParameters: () => [], propDecorators: { value: [{
|
|
1182
|
+
type: Input
|
|
1183
|
+
}], disabled: [{
|
|
1184
|
+
type: Input,
|
|
1185
|
+
args: [{ transform: booleanAttribute }]
|
|
1186
|
+
}], required: [{
|
|
1187
|
+
type: Input,
|
|
1188
|
+
args: [{ transform: booleanAttribute }]
|
|
1189
|
+
}], errorState: [{
|
|
1190
|
+
type: HostBinding,
|
|
1191
|
+
args: ['class.n-error-state']
|
|
1192
|
+
}], compareWithInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "compareWith", required: false }] }], valueChange: [{ type: i0.Output, args: ["valueChange"] }] } });
|
|
1193
|
+
|
|
1194
|
+
const EMPTY_ERROR = '';
|
|
1195
|
+
function getFormErrorMessage(error) {
|
|
1196
|
+
if (isString(error))
|
|
1197
|
+
return error;
|
|
1198
|
+
if (isObject(error) && 'error' in error && isString(error.error)) {
|
|
1199
|
+
return error.error;
|
|
1200
|
+
}
|
|
1201
|
+
if (isBaseNgValidationError(error)) {
|
|
1202
|
+
return error.message ?? getSignalFormErrorMessage(error.kind);
|
|
1203
|
+
}
|
|
1204
|
+
return undefined;
|
|
1205
|
+
}
|
|
1206
|
+
function genericFormErrorMessage(errors) {
|
|
1207
|
+
return getFormErrorMessage(Object.values(errors)[0]);
|
|
1208
|
+
}
|
|
1209
|
+
class GenericFormErrorMessagePipe {
|
|
1210
|
+
transform(errors) {
|
|
1211
|
+
return genericFormErrorMessage(errors);
|
|
1212
|
+
}
|
|
1213
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: GenericFormErrorMessagePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1214
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: GenericFormErrorMessagePipe, isStandalone: true, name: "genericFormErrorMessage" }); }
|
|
1215
|
+
}
|
|
1216
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: GenericFormErrorMessagePipe, decorators: [{
|
|
1217
|
+
type: Pipe,
|
|
1218
|
+
args: [{ name: 'genericFormErrorMessage' }]
|
|
1219
|
+
}] });
|
|
1220
|
+
function isBaseNgValidationError(src) {
|
|
1221
|
+
return isObject(src) && 'kind' in src && isString(src.kind);
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Maps an Angular signal-forms validation error `kind` to a localized message
|
|
1225
|
+
* resolved from the {@link ValidatorMessages} token, reusing the same keys as
|
|
1226
|
+
* the reactive validators.
|
|
1227
|
+
*/
|
|
1228
|
+
function getSignalFormErrorMessage(kind) {
|
|
1229
|
+
const messages = getValidatorMessages();
|
|
1230
|
+
switch (kind) {
|
|
1231
|
+
case 'email':
|
|
1232
|
+
return messages.email;
|
|
1233
|
+
case 'minLength':
|
|
1234
|
+
return messages.minLength({ minLength: 0 });
|
|
1235
|
+
case 'required':
|
|
1236
|
+
return messages.required;
|
|
1237
|
+
case 'requiredTrue':
|
|
1238
|
+
return messages.requiredTrue;
|
|
1239
|
+
default:
|
|
1240
|
+
return undefined;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
class ReplayControlValueObservable extends Observable {
|
|
1245
|
+
constructor(input) {
|
|
1246
|
+
super((subscriber) => input.valueChanges
|
|
1247
|
+
.pipe(
|
|
1248
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
1249
|
+
map(() => input.getRawValue()), startWith(input.getRawValue()))
|
|
1250
|
+
.subscribe(subscriber));
|
|
1251
|
+
}
|
|
1252
|
+
static of(input) {
|
|
1253
|
+
return new ReplayControlValueObservable(input);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* @important
|
|
1259
|
+
* If the control value is updated using `setValue` or `patchValue`
|
|
1260
|
+
* with `{ emitEvent: false }`, the underlying observable will not emit.
|
|
1261
|
+
* As a result, this signal will NOT be updated and may become out of sync
|
|
1262
|
+
* with the actual control value.
|
|
1263
|
+
*
|
|
1264
|
+
* Always ensure `emitEvent` is not set to `false`, or manually trigger
|
|
1265
|
+
* a synchronization if you intentionally suppress events.
|
|
1266
|
+
*/
|
|
1267
|
+
function controlSignal(control, options) {
|
|
1268
|
+
return toLazySignal(ReplayControlValueObservable.of(control), {
|
|
1269
|
+
equal: options?.equal,
|
|
1270
|
+
injector: options?.injector,
|
|
1271
|
+
requireSync: true,
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const ALPHA_NUMERIC_REGEX = /^[a-zA-Z\d]*$/;
|
|
1276
|
+
const ARCEP_SLICE_PREFIX_REGEX = /^0[1-5|9]\d{4,7}$/;
|
|
1277
|
+
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
1278
|
+
const ESIGNATURE_SIGNER_MIN_LENGTH = 1;
|
|
1279
|
+
const ESIGNATURE_SIGNER_MAX_LENGTH = 254;
|
|
1280
|
+
const ESIGNATURE_SIGNER_REGEX = /^(?!\s)[0-9A-Za-zĄÀÁÂÃÄÅÇĆÈÉÊËĘÌÍÎÏŁÑŃÒÓÔÕÖŚÙÚÛÜÝŹŻąàáâãäåæçćèéêëęìíîïłñńòóôõöśùúûüýÿźżßĀāĂăĈĉĊċČčĎďĐđĒēĔĕĖėĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŽžſøØÆȘșȚț`'() -]+(?<!\s)$/;
|
|
1281
|
+
const ICCID_MIN_LENGTH = 17;
|
|
1282
|
+
const ICCID_MAX_LENGTH = 20;
|
|
1283
|
+
const KVK_LENGTH = 8;
|
|
1284
|
+
const KVK_REGEX = /^[0-9]{8}$/;
|
|
1285
|
+
const NAF_APE_LENGTH = 5;
|
|
1286
|
+
const NAF_APE_REGEX = /^[0-9]{4}[A-Z]$/;
|
|
1287
|
+
const NSCE_LENGTH = 13;
|
|
1288
|
+
const PORTABILITY_PREFIX_LENGTH = 6;
|
|
1289
|
+
const PORTABILITY_PREFIX_REGEX = /^0\d{5}$/;
|
|
1290
|
+
const PORTABILITY_NUMBER_REGEX = /^0[1-59][0-9]{8}$/;
|
|
1291
|
+
const RCS_REGEX = /^.+ [AB] ([0-9]{9})$/;
|
|
1292
|
+
const RIO_LENGTH = 12;
|
|
1293
|
+
const RIO_REGEX = /^[A-Za-z0-9][A-Za-z0-9][A-Z][A-Z0-9+]{6}[A-Z0-9+]{3}$/;
|
|
1294
|
+
const SIREN_LENGTH = 9;
|
|
1295
|
+
const SIRET_LENGTH = 14;
|
|
1296
|
+
const URL_REGEX = /^https?:\/\/(www.)?[-a-zA-Z0-9@:%._+~#=]+\.[a-zA-Z0-9()]+[-a-zA-Z0-9()@:%_+.~#?&/=]*$/;
|
|
1297
|
+
const VAT_FR_LENGTH = 13;
|
|
1298
|
+
const VAT_FR_REGEX = /^FR([0-9]{2})([0-9]{9})$/;
|
|
1299
|
+
const VAT_NL_LENGTH = 14;
|
|
1300
|
+
const VAT_NL_REGEX = /^NL[0-9]{9}B[0-9]{2}$/;
|
|
1301
|
+
function validate(path, logic, config) {
|
|
1302
|
+
validate$1(path, (context) => {
|
|
1303
|
+
if (config?.when && !config.when(context))
|
|
1304
|
+
return undefined;
|
|
1305
|
+
return logic(context);
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
function validationError(kind, message, data = {}) {
|
|
1309
|
+
return { kind, message, ...data };
|
|
1310
|
+
}
|
|
1311
|
+
function lengthOrSize(value) {
|
|
1312
|
+
if (isNullable(value))
|
|
1313
|
+
return null;
|
|
1314
|
+
if (isArray(value) || (isString(value) && !!value))
|
|
1315
|
+
return value.length;
|
|
1316
|
+
if (value instanceof Set)
|
|
1317
|
+
return value.size;
|
|
1318
|
+
return null;
|
|
1319
|
+
}
|
|
1320
|
+
const customFileTypes = ['csv', 'xlsx'];
|
|
1321
|
+
const FILE_TYPES_MAP = {
|
|
1322
|
+
csv: [
|
|
1323
|
+
'text/csv',
|
|
1324
|
+
'application/csv',
|
|
1325
|
+
'application/x-csv',
|
|
1326
|
+
'text/comma-separated-values',
|
|
1327
|
+
'text/x-comma-separated-values',
|
|
1328
|
+
'application/vnd.ms-excel',
|
|
1329
|
+
],
|
|
1330
|
+
xlsx: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
1331
|
+
};
|
|
1332
|
+
function getFileTypes(fileTypes) {
|
|
1333
|
+
return fileTypes.reduce((acc, fileType) => {
|
|
1334
|
+
const type = FILE_TYPES_MAP[fileType] ?? [fileType];
|
|
1335
|
+
acc.push(...type);
|
|
1336
|
+
return acc;
|
|
1337
|
+
}, []);
|
|
1338
|
+
}
|
|
1339
|
+
function isSignalValidatorConfig(value) {
|
|
1340
|
+
return !!value && typeof value === 'object' && 'when' in value;
|
|
1341
|
+
}
|
|
1342
|
+
function splitFileTypesAndConfig(fileTypesOrConfig) {
|
|
1343
|
+
const maybeConfig = fileTypesOrConfig.at(-1);
|
|
1344
|
+
if (isSignalValidatorConfig(maybeConfig)) {
|
|
1345
|
+
return {
|
|
1346
|
+
fileTypes: fileTypesOrConfig.slice(0, -1),
|
|
1347
|
+
config: maybeConfig,
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
return { fileTypes: fileTypesOrConfig };
|
|
1351
|
+
}
|
|
1352
|
+
function splitBooleanAndConfig(valueOrConfig, config, defaultValue = false) {
|
|
1353
|
+
if (isSignalValidatorConfig(valueOrConfig)) {
|
|
1354
|
+
return { value: defaultValue, config: valueOrConfig };
|
|
1355
|
+
}
|
|
1356
|
+
return { value: valueOrConfig ?? defaultValue, config };
|
|
1357
|
+
}
|
|
1358
|
+
function validatorDataVolumeRange(path, min, max, config) {
|
|
1359
|
+
validate(path, ({ value }) => {
|
|
1360
|
+
const innerValue = value();
|
|
1361
|
+
if (isNullable(innerValue))
|
|
1362
|
+
return undefined;
|
|
1363
|
+
const messages = getValidatorMessages();
|
|
1364
|
+
if (innerValue < min || innerValue > max) {
|
|
1365
|
+
return validationError('dataVolumeRange', messages.dataVolumeRange({ minVolume: min, maxVolume: max }), { minVolume: min, maxVolume: max, actual: innerValue });
|
|
1366
|
+
}
|
|
1367
|
+
if (!Number.isInteger(innerValue)) {
|
|
1368
|
+
return validationError('dataVolumeRange', messages.dataVolumeRangeInteger);
|
|
1369
|
+
}
|
|
1370
|
+
return undefined;
|
|
1371
|
+
}, config);
|
|
1372
|
+
}
|
|
1373
|
+
function validatorDateRange(path, range, useTimeOrConfig, config) {
|
|
1374
|
+
const { value: useTime, config: innerConfig } = splitBooleanAndConfig(useTimeOrConfig, config);
|
|
1375
|
+
validate(path, ({ value }) => {
|
|
1376
|
+
const innerValue = value();
|
|
1377
|
+
if (isNullable(innerValue) || isDateInRange(range, innerValue, useTime)) {
|
|
1378
|
+
return undefined;
|
|
1379
|
+
}
|
|
1380
|
+
const [startDate, endDate] = range;
|
|
1381
|
+
return validationError('dateRange', getValidatorMessages().dateRange({
|
|
1382
|
+
startDate: startDate ?? undefined,
|
|
1383
|
+
endDate: endDate ?? undefined,
|
|
1384
|
+
useTime,
|
|
1385
|
+
}), { startDate, endDate, actualDate: innerValue });
|
|
1386
|
+
}, innerConfig);
|
|
1387
|
+
}
|
|
1388
|
+
function validatorDifferentDate(path, date, config) {
|
|
1389
|
+
validate(path, ({ value }) => {
|
|
1390
|
+
const innerValue = value();
|
|
1391
|
+
if (!innerValue)
|
|
1392
|
+
return undefined;
|
|
1393
|
+
const curDateStr = DateTime.fromJSDate(innerValue).toISODate({
|
|
1394
|
+
format: 'basic',
|
|
1395
|
+
});
|
|
1396
|
+
const dateStr = DateTime.fromJSDate(date).toISODate({ format: 'basic' });
|
|
1397
|
+
return curDateStr === dateStr
|
|
1398
|
+
? validationError('differentDate', getValidatorMessages().differentDate, {
|
|
1399
|
+
date,
|
|
1400
|
+
})
|
|
1401
|
+
: undefined;
|
|
1402
|
+
}, config);
|
|
1403
|
+
}
|
|
1404
|
+
function validatorEmail(path, config) {
|
|
1405
|
+
validate(path, ({ value }) => {
|
|
1406
|
+
const innerValue = value();
|
|
1407
|
+
return isEmpty(innerValue) || EMAIL_REGEX.test(innerValue)
|
|
1408
|
+
? undefined
|
|
1409
|
+
: validationError('email', getValidatorMessages().email);
|
|
1410
|
+
}, config);
|
|
1411
|
+
}
|
|
1412
|
+
function validatorEsignatureSignerField(path, config) {
|
|
1413
|
+
validatorTextLengthRange(path, ESIGNATURE_SIGNER_MIN_LENGTH, ESIGNATURE_SIGNER_MAX_LENGTH, config);
|
|
1414
|
+
validate(path, ({ value }) => {
|
|
1415
|
+
const innerValue = value();
|
|
1416
|
+
return isEmpty(innerValue) ||
|
|
1417
|
+
innerValue.length < ESIGNATURE_SIGNER_MIN_LENGTH ||
|
|
1418
|
+
innerValue.length > ESIGNATURE_SIGNER_MAX_LENGTH ||
|
|
1419
|
+
ESIGNATURE_SIGNER_REGEX.test(innerValue)
|
|
1420
|
+
? undefined
|
|
1421
|
+
: validationError('esignatureField', getValidatorMessages().esignatureField);
|
|
1422
|
+
}, config);
|
|
1423
|
+
}
|
|
1424
|
+
function validatorFileType(path, ...fileTypesOrConfig) {
|
|
1425
|
+
const { fileTypes, config } = splitFileTypesAndConfig(fileTypesOrConfig);
|
|
1426
|
+
validate(path, ({ value }) => {
|
|
1427
|
+
const innerValue = value();
|
|
1428
|
+
if (isNullable(innerValue) ||
|
|
1429
|
+
getFileTypes(fileTypes).includes(innerValue.type)) {
|
|
1430
|
+
return undefined;
|
|
1431
|
+
}
|
|
1432
|
+
return validationError('fileType', getValidatorMessages().fileType, {
|
|
1433
|
+
requiredFileTypes: fileTypes,
|
|
1434
|
+
actualFileType: innerValue.type,
|
|
1435
|
+
});
|
|
1436
|
+
}, config);
|
|
1437
|
+
}
|
|
1438
|
+
function validatorFrenchPhoneNumber(path, config) {
|
|
1439
|
+
validate(path, ({ value }) => {
|
|
1440
|
+
const innerValue = value();
|
|
1441
|
+
return isEmpty(innerValue) || parseFrenchPhoneNumber(innerValue)
|
|
1442
|
+
? undefined
|
|
1443
|
+
: validationError('frenchPhoneNumber', getValidatorMessages().frenchPhoneNumber);
|
|
1444
|
+
}, config);
|
|
1445
|
+
}
|
|
1446
|
+
function validatorLength(path, requiredLength, config) {
|
|
1447
|
+
validate(path, ({ value }) => {
|
|
1448
|
+
const actualLength = lengthOrSize(value());
|
|
1449
|
+
return actualLength === null || actualLength === requiredLength
|
|
1450
|
+
? undefined
|
|
1451
|
+
: validationError('length', getValidatorMessages().length({ requiredLength }), { requiredLength, actualLength });
|
|
1452
|
+
}, config);
|
|
1453
|
+
}
|
|
1454
|
+
function validatorLengthRange(path, range, config) {
|
|
1455
|
+
const { min = -Infinity, max = Infinity } = range;
|
|
1456
|
+
validate(path, ({ value }) => {
|
|
1457
|
+
const actualLength = lengthOrSize(value());
|
|
1458
|
+
return actualLength === null ||
|
|
1459
|
+
(actualLength >= min && actualLength <= max)
|
|
1460
|
+
? undefined
|
|
1461
|
+
: validationError('textLength', getValidatorMessages().lengthRange({ min, max }), { minLength: min, maxLength: max, actualLength });
|
|
1462
|
+
}, config);
|
|
1463
|
+
}
|
|
1464
|
+
function validatorMax(path, max, config) {
|
|
1465
|
+
validate(path, ({ value }) => {
|
|
1466
|
+
const actual = value();
|
|
1467
|
+
return isNullable(actual) || actual <= max
|
|
1468
|
+
? undefined
|
|
1469
|
+
: validationError('max', getValidatorMessages().max({ max }), {
|
|
1470
|
+
max,
|
|
1471
|
+
actual,
|
|
1472
|
+
});
|
|
1473
|
+
}, config);
|
|
1474
|
+
}
|
|
1475
|
+
function validatorMaxLength(path, maxLength, config) {
|
|
1476
|
+
validate(path, ({ value }) => {
|
|
1477
|
+
const actualLength = lengthOrSize(value());
|
|
1478
|
+
return actualLength === null || actualLength <= maxLength
|
|
1479
|
+
? undefined
|
|
1480
|
+
: validationError('maxLength', getValidatorMessages().maxLength({ maxLength }), { maxLength, actualLength });
|
|
1481
|
+
}, config);
|
|
1482
|
+
}
|
|
1483
|
+
function validatorMaxFileSize(path, maxFileSize, config) {
|
|
1484
|
+
validate(path, ({ value }) => {
|
|
1485
|
+
const innerValue = value();
|
|
1486
|
+
return isNullable(innerValue) || innerValue.size < maxFileSize
|
|
1487
|
+
? undefined
|
|
1488
|
+
: validationError('maxFileSize', getValidatorMessages().maxFileSize({ size: maxFileSize }), { requiredFileSize: maxFileSize, actualFileSize: innerValue.size });
|
|
1489
|
+
}, config);
|
|
1490
|
+
}
|
|
1491
|
+
function validatorMaxTextLength(path, maxTextLength, config) {
|
|
1492
|
+
validate(path, ({ value }) => {
|
|
1493
|
+
const innerValue = value();
|
|
1494
|
+
return !innerValue || innerValue.length <= maxTextLength
|
|
1495
|
+
? undefined
|
|
1496
|
+
: validationError('textLength', getValidatorMessages().maxTextLength({ maxTextLength }), { maxTextLength, actualTextLength: innerValue.length });
|
|
1497
|
+
}, config);
|
|
1498
|
+
}
|
|
1499
|
+
function validatorMin(path, min, config) {
|
|
1500
|
+
validate(path, ({ value }) => {
|
|
1501
|
+
const actual = value();
|
|
1502
|
+
return isNullable(actual) || actual >= min
|
|
1503
|
+
? undefined
|
|
1504
|
+
: validationError('min', getValidatorMessages().min({ min }), {
|
|
1505
|
+
min,
|
|
1506
|
+
actual,
|
|
1507
|
+
});
|
|
1508
|
+
}, config);
|
|
1509
|
+
}
|
|
1510
|
+
function validatorMinLength(path, minLength, config) {
|
|
1511
|
+
validate(path, ({ value }) => {
|
|
1512
|
+
const actualLength = lengthOrSize(value());
|
|
1513
|
+
return actualLength === null || actualLength >= minLength
|
|
1514
|
+
? undefined
|
|
1515
|
+
: validationError('minLength', getValidatorMessages().minLength({ minLength }), { minLength, actualLength });
|
|
1516
|
+
}, config);
|
|
1517
|
+
}
|
|
1518
|
+
function validatorMinTextLength(path, minTextLength, config) {
|
|
1519
|
+
validate(path, ({ value }) => {
|
|
1520
|
+
const innerValue = value();
|
|
1521
|
+
return !innerValue || innerValue.length >= minTextLength
|
|
1522
|
+
? undefined
|
|
1523
|
+
: validationError('textLength', getValidatorMessages().minTextLength({ minTextLength }), { minTextLength, actualTextLength: innerValue.length });
|
|
1524
|
+
}, config);
|
|
1525
|
+
}
|
|
1526
|
+
function validatorMobilePhoneNumber(path, config) {
|
|
1527
|
+
validate(path, ({ value }) => {
|
|
1528
|
+
const innerValue = value();
|
|
1529
|
+
if (isNullable(innerValue))
|
|
1530
|
+
return undefined;
|
|
1531
|
+
return getPhoneNumberUtil().isPossibleNumber(innerValue) &&
|
|
1532
|
+
getPhoneNumberUtil().getNumberType(innerValue) ===
|
|
1533
|
+
PhoneNumberType.MOBILE
|
|
1534
|
+
? undefined
|
|
1535
|
+
: validationError('mobilePhoneNumber', getValidatorMessages().mobilePhoneNumber);
|
|
1536
|
+
}, config);
|
|
1537
|
+
}
|
|
1538
|
+
function validatorPortableApnfNumber(path, config) {
|
|
1539
|
+
validate(path, ({ value }) => {
|
|
1540
|
+
const innerValue = value();
|
|
1541
|
+
if (isEmpty(innerValue))
|
|
1542
|
+
return undefined;
|
|
1543
|
+
const parsed = parseFrenchPhoneNumber(innerValue);
|
|
1544
|
+
return parsed && PORTABILITY_NUMBER_REGEX.test(parsed)
|
|
1545
|
+
? undefined
|
|
1546
|
+
: validationError('error', getValidatorMessages().portableApnfNumber);
|
|
1547
|
+
}, config);
|
|
1548
|
+
}
|
|
1549
|
+
function validatorRange(path, min, max, config) {
|
|
1550
|
+
validate(path, ({ value }) => {
|
|
1551
|
+
const actual = value();
|
|
1552
|
+
return isNullable(actual) || (actual >= min && actual <= max)
|
|
1553
|
+
? undefined
|
|
1554
|
+
: validationError('range', getValidatorMessages().range({ min, max }), {
|
|
1555
|
+
min,
|
|
1556
|
+
max,
|
|
1557
|
+
actual,
|
|
1558
|
+
});
|
|
1559
|
+
}, config);
|
|
1560
|
+
}
|
|
1561
|
+
function validatorRequired(path, config) {
|
|
1562
|
+
required(path, {
|
|
1563
|
+
message: getValidatorMessages().required,
|
|
1564
|
+
when: config?.when,
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
function validatorRequiredTrue(path, config) {
|
|
1568
|
+
validate(path, ({ value }) => value() === true
|
|
1569
|
+
? undefined
|
|
1570
|
+
: validationError('requiredTrue', getValidatorMessages().requiredTrue), config);
|
|
1571
|
+
}
|
|
1572
|
+
function validatorTextLength(path, requiredLength, config) {
|
|
1573
|
+
validate(path, ({ value }) => {
|
|
1574
|
+
const innerValue = value();
|
|
1575
|
+
return !innerValue || innerValue.length === requiredLength
|
|
1576
|
+
? undefined
|
|
1577
|
+
: validationError('textLength', getValidatorMessages().textLength({ requiredLength }), { requiredLength, actualLength: innerValue.length });
|
|
1578
|
+
}, config);
|
|
1579
|
+
}
|
|
1580
|
+
function validatorTextLengthRange(path, minTextLength, maxTextLength, config) {
|
|
1581
|
+
validate(path, ({ value }) => {
|
|
1582
|
+
const innerValue = value();
|
|
1583
|
+
return !innerValue ||
|
|
1584
|
+
(innerValue.length >= minTextLength &&
|
|
1585
|
+
innerValue.length <= maxTextLength)
|
|
1586
|
+
? undefined
|
|
1587
|
+
: validationError('textLength', getValidatorMessages().textLengthRange({
|
|
1588
|
+
min: minTextLength,
|
|
1589
|
+
max: maxTextLength,
|
|
1590
|
+
}), {
|
|
1591
|
+
minTextLength,
|
|
1592
|
+
maxTextLength,
|
|
1593
|
+
actualLength: innerValue.length,
|
|
1594
|
+
});
|
|
1595
|
+
}, config);
|
|
1596
|
+
}
|
|
1597
|
+
function validatorUnique(path, comparedValues, config) {
|
|
1598
|
+
validate(path, ({ value }) => {
|
|
1599
|
+
const innerValue = value();
|
|
1600
|
+
if (isNullable(innerValue))
|
|
1601
|
+
return undefined;
|
|
1602
|
+
const innerValues = isArray(innerValue) ? innerValue : [innerValue];
|
|
1603
|
+
const innerComparedValues = isSignal(comparedValues)
|
|
1604
|
+
? comparedValues()
|
|
1605
|
+
: (comparedValues ?? []);
|
|
1606
|
+
const hasDuplicate = new Set(innerValues).size !== innerValues.length;
|
|
1607
|
+
return hasDuplicate ||
|
|
1608
|
+
innerValues.find((innerValue) => innerComparedValues.includes(innerValue))
|
|
1609
|
+
? validationError('unique', config?.message ?? getValidatorMessages().unique)
|
|
1610
|
+
: undefined;
|
|
1611
|
+
}, config);
|
|
1612
|
+
}
|
|
1613
|
+
function validatorUrl(path, config) {
|
|
1614
|
+
validate(path, ({ value }) => {
|
|
1615
|
+
const innerValue = value();
|
|
1616
|
+
return isEmpty(innerValue) || URL_REGEX.test(innerValue)
|
|
1617
|
+
? undefined
|
|
1618
|
+
: validationError('url', getValidatorMessages().url);
|
|
1619
|
+
}, config);
|
|
1620
|
+
}
|
|
1621
|
+
function genIpv4Regex(authorizedMasks) {
|
|
1622
|
+
const octet = '(?:25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)';
|
|
1623
|
+
const maskPart = authorizedMasks?.length
|
|
1624
|
+
? `(?:\\/(?:${authorizedMasks.join('|')}))?`
|
|
1625
|
+
: '';
|
|
1626
|
+
const pattern = `^(${octet}\\.){3}${octet}${maskPart}$`;
|
|
1627
|
+
return new RegExp(pattern);
|
|
1628
|
+
}
|
|
1629
|
+
function validatorArcepSlicePrefix(path, config) {
|
|
1630
|
+
validate(path, ({ value }) => {
|
|
1631
|
+
const innerValue = value();
|
|
1632
|
+
return isEmpty(innerValue) || ARCEP_SLICE_PREFIX_REGEX.test(innerValue)
|
|
1633
|
+
? undefined
|
|
1634
|
+
: validationError('arcepSlicePrefix', getValidatorMessages().arcepSlicePrefix);
|
|
1635
|
+
}, config);
|
|
1636
|
+
}
|
|
1637
|
+
const VALID_COMPANY_TYPES = [
|
|
1638
|
+
'Association',
|
|
1639
|
+
'EI',
|
|
1640
|
+
'EURL',
|
|
1641
|
+
'SARL',
|
|
1642
|
+
'SASU',
|
|
1643
|
+
'SAS',
|
|
1644
|
+
'SA',
|
|
1645
|
+
'SNC',
|
|
1646
|
+
'SCS',
|
|
1647
|
+
'SCA',
|
|
1648
|
+
'SMF',
|
|
1649
|
+
];
|
|
1650
|
+
function validatorCompanyType(path, config) {
|
|
1651
|
+
validate(path, ({ value }) => {
|
|
1652
|
+
const innerValue = value();
|
|
1653
|
+
return isEmpty(innerValue) || VALID_COMPANY_TYPES.includes(innerValue)
|
|
1654
|
+
? undefined
|
|
1655
|
+
: validationError('companyType', getValidatorMessages().companyType);
|
|
1656
|
+
}, config);
|
|
1657
|
+
}
|
|
1658
|
+
const MAX_MASK = 32;
|
|
1659
|
+
const MIN_MASK = 0;
|
|
1660
|
+
function getAuthorizedMaskArr(masks) {
|
|
1661
|
+
if (isNumber(masks))
|
|
1662
|
+
return [masks];
|
|
1663
|
+
if (isArray(masks))
|
|
1664
|
+
return masks;
|
|
1665
|
+
const min = masks.min ?? MIN_MASK;
|
|
1666
|
+
const max = (masks.max ?? MAX_MASK) + 1;
|
|
1667
|
+
return Array.from({ length: max - min }, (_, i) => i + min);
|
|
1668
|
+
}
|
|
1669
|
+
function validatorIpv4WithMask(path, authorizedMasks = { min: MIN_MASK, max: MAX_MASK }, config) {
|
|
1670
|
+
validate(path, ({ value }) => {
|
|
1671
|
+
const innerValue = value();
|
|
1672
|
+
if (isNullable(innerValue))
|
|
1673
|
+
return undefined;
|
|
1674
|
+
const innerValues = isString(innerValue) ? [innerValue] : innerValue;
|
|
1675
|
+
if (!innerValues.length)
|
|
1676
|
+
return undefined;
|
|
1677
|
+
const regExp = genIpv4Regex(getAuthorizedMaskArr(authorizedMasks));
|
|
1678
|
+
const hasError = innerValues.some((innerValue) => !regExp.test(innerValue));
|
|
1679
|
+
return hasError
|
|
1680
|
+
? validationError('ipv4', getValidatorMessages().ipv4)
|
|
1681
|
+
: undefined;
|
|
1682
|
+
}, config);
|
|
1683
|
+
}
|
|
1684
|
+
function validatorIpv4WithoutMask(path, config) {
|
|
1685
|
+
validate(path, ({ value }) => {
|
|
1686
|
+
const innerValue = value();
|
|
1687
|
+
return isEmpty(innerValue) || genIpv4Regex(null).test(innerValue)
|
|
1688
|
+
? undefined
|
|
1689
|
+
: validationError('portabilityPrefix', getValidatorMessages().ipv4WithoutMask);
|
|
1690
|
+
}, config);
|
|
1691
|
+
}
|
|
1692
|
+
function validatorCidrIsNetworkAddress(path, config) {
|
|
1693
|
+
validate(path, ({ value }) => {
|
|
1694
|
+
const innerValue = value();
|
|
1695
|
+
if (isNullable(innerValue))
|
|
1696
|
+
return undefined;
|
|
1697
|
+
const innerValues = isString(innerValue) ? [innerValue] : innerValue;
|
|
1698
|
+
if (!innerValues.length)
|
|
1699
|
+
return undefined;
|
|
1700
|
+
const invalidNetworks = innerValues.reduce((acc, innerValue) => {
|
|
1701
|
+
if (!cidrIsNetworkAddress(innerValue))
|
|
1702
|
+
acc.push(innerValue);
|
|
1703
|
+
return acc;
|
|
1704
|
+
}, []);
|
|
1705
|
+
return invalidNetworks.length
|
|
1706
|
+
? validationError('cidrIsNetworkAddress', getValidatorMessages().cidrIsNetworkAddress({ invalidNetworks }), { invalidNetworks })
|
|
1707
|
+
: undefined;
|
|
1708
|
+
}, config);
|
|
1709
|
+
}
|
|
1710
|
+
function validatorKvk(path, config) {
|
|
1711
|
+
validatorTextLength(path, KVK_LENGTH, config);
|
|
1712
|
+
validate(path, ({ value }) => {
|
|
1713
|
+
const innerValue = value();
|
|
1714
|
+
return isEmpty(innerValue) ||
|
|
1715
|
+
innerValue.length !== KVK_LENGTH ||
|
|
1716
|
+
KVK_REGEX.test(innerValue)
|
|
1717
|
+
? undefined
|
|
1718
|
+
: validationError('kvk', getValidatorMessages().kvk);
|
|
1719
|
+
}, config);
|
|
1720
|
+
}
|
|
1721
|
+
function validatorNafApe(path, config) {
|
|
1722
|
+
validatorTextLength(path, NAF_APE_LENGTH, config);
|
|
1723
|
+
validate(path, ({ value }) => {
|
|
1724
|
+
const innerValue = value();
|
|
1725
|
+
return isEmpty(innerValue) ||
|
|
1726
|
+
innerValue.length !== NAF_APE_LENGTH ||
|
|
1727
|
+
NAF_APE_REGEX.test(innerValue)
|
|
1728
|
+
? undefined
|
|
1729
|
+
: validationError('nafApe', getValidatorMessages().nafApe);
|
|
1730
|
+
}, config);
|
|
1731
|
+
}
|
|
1732
|
+
function validatorPortabilityPrefix(path, config) {
|
|
1733
|
+
validatorTextLength(path, PORTABILITY_PREFIX_LENGTH, config);
|
|
1734
|
+
validate(path, ({ value }) => {
|
|
1735
|
+
const innerValue = value();
|
|
1736
|
+
return isEmpty(innerValue) ||
|
|
1737
|
+
innerValue.length !== PORTABILITY_PREFIX_LENGTH ||
|
|
1738
|
+
PORTABILITY_PREFIX_REGEX.test(innerValue)
|
|
1739
|
+
? undefined
|
|
1740
|
+
: validationError('portabilityPrefix', getValidatorMessages().portabilityPrefix);
|
|
1741
|
+
}, config);
|
|
1742
|
+
}
|
|
1743
|
+
function validatorRio(path, config) {
|
|
1744
|
+
validatorTextLength(path, RIO_LENGTH, config);
|
|
1745
|
+
validate(path, ({ value }) => {
|
|
1746
|
+
const innerValue = value();
|
|
1747
|
+
return isEmpty(innerValue) ||
|
|
1748
|
+
innerValue.length !== RIO_LENGTH ||
|
|
1749
|
+
RIO_REGEX.test(innerValue)
|
|
1750
|
+
? undefined
|
|
1751
|
+
: validationError('rio', getValidatorMessages().rio);
|
|
1752
|
+
}, config);
|
|
1753
|
+
}
|
|
1754
|
+
function validatorSimNumber(path, nsceEnabledOrConfig, config) {
|
|
1755
|
+
const { value: nsceEnabled, config: innerConfig } = splitBooleanAndConfig(nsceEnabledOrConfig, config);
|
|
1756
|
+
const minLength = nsceEnabled ? NSCE_LENGTH : ICCID_MIN_LENGTH;
|
|
1757
|
+
validatorTextLengthRange(path, minLength, ICCID_MAX_LENGTH, innerConfig);
|
|
1758
|
+
validate(path, ({ value }) => {
|
|
1759
|
+
const innerValue = value();
|
|
1760
|
+
return isEmpty(innerValue) ||
|
|
1761
|
+
innerValue.length < minLength ||
|
|
1762
|
+
innerValue.length > ICCID_MAX_LENGTH ||
|
|
1763
|
+
luhn(innerValue)
|
|
1764
|
+
? undefined
|
|
1765
|
+
: validationError('simNumber', getValidatorMessages().simNumber({ nsceEnabled }));
|
|
1766
|
+
}, innerConfig);
|
|
1767
|
+
}
|
|
1768
|
+
function validatorSiren(path, config) {
|
|
1769
|
+
validatorTextLength(path, SIREN_LENGTH, config);
|
|
1770
|
+
validate(path, ({ value }) => {
|
|
1771
|
+
const innerValue = value();
|
|
1772
|
+
return isEmpty(innerValue) ||
|
|
1773
|
+
innerValue.length !== SIREN_LENGTH ||
|
|
1774
|
+
luhn(innerValue)
|
|
1775
|
+
? undefined
|
|
1776
|
+
: validationError('siren', getValidatorMessages().siren);
|
|
1777
|
+
}, config);
|
|
1778
|
+
}
|
|
1779
|
+
function validatorSiret(path, omitSirenOrConfig, config) {
|
|
1780
|
+
const { value: omitSiren, config: innerConfig } = splitBooleanAndConfig(omitSirenOrConfig, config);
|
|
1781
|
+
validate(path, ({ value }) => {
|
|
1782
|
+
const innerValue = value();
|
|
1783
|
+
if (isEmpty(innerValue) ||
|
|
1784
|
+
(omitSiren && innerValue.length <= SIREN_LENGTH)) {
|
|
1785
|
+
return undefined;
|
|
1786
|
+
}
|
|
1787
|
+
if (innerValue.length !== SIRET_LENGTH) {
|
|
1788
|
+
return validationError('textLength', getValidatorMessages().textLength({ requiredLength: SIRET_LENGTH }), { requiredLength: SIRET_LENGTH, actualLength: innerValue.length });
|
|
1789
|
+
}
|
|
1790
|
+
return luhn(innerValue)
|
|
1791
|
+
? undefined
|
|
1792
|
+
: validationError('siret', getValidatorMessages().siret);
|
|
1793
|
+
}, innerConfig);
|
|
1794
|
+
}
|
|
1795
|
+
function validatorVatNl(path, config) {
|
|
1796
|
+
validatorTextLength(path, VAT_NL_LENGTH, config);
|
|
1797
|
+
validate(path, ({ value }) => {
|
|
1798
|
+
const innerValue = value();
|
|
1799
|
+
return isEmpty(innerValue) ||
|
|
1800
|
+
innerValue.length !== VAT_NL_LENGTH ||
|
|
1801
|
+
VAT_NL_REGEX.test(innerValue)
|
|
1802
|
+
? undefined
|
|
1803
|
+
: validationError('vatNl', getValidatorMessages().vatNl);
|
|
1804
|
+
}, config);
|
|
1805
|
+
}
|
|
1806
|
+
function validatorVatFr(path, config) {
|
|
1807
|
+
validatorTextLength(path, VAT_FR_LENGTH, config);
|
|
1808
|
+
validate(path, ({ value }) => {
|
|
1809
|
+
const innerValue = value();
|
|
1810
|
+
return isEmpty(innerValue) ||
|
|
1811
|
+
innerValue.length !== VAT_FR_LENGTH ||
|
|
1812
|
+
VAT_FR_REGEX.test(innerValue)
|
|
1813
|
+
? undefined
|
|
1814
|
+
: validationError('vatNl', getValidatorMessages().vatFr);
|
|
1815
|
+
}, config);
|
|
1816
|
+
}
|
|
1817
|
+
function validatorAlphaNumeric(path, config) {
|
|
1818
|
+
validate(path, ({ value }) => {
|
|
1819
|
+
const innerValue = value();
|
|
1820
|
+
return isEmpty(innerValue) || ALPHA_NUMERIC_REGEX.test(innerValue)
|
|
1821
|
+
? undefined
|
|
1822
|
+
: validationError('alphaNumeric', getValidatorMessages().alphaNumeric);
|
|
1823
|
+
}, config);
|
|
1824
|
+
}
|
|
1825
|
+
function groupValidatorLegalIdentifierRcs(path, config) {
|
|
1826
|
+
validate(path, ({ value }) => {
|
|
1827
|
+
const innerValue = value();
|
|
1828
|
+
if (!innerValue.legalIdentifier || !innerValue.rcs)
|
|
1829
|
+
return undefined;
|
|
1830
|
+
const groups = RCS_REGEX.exec(innerValue.rcs);
|
|
1831
|
+
const siren = groups?.at(1);
|
|
1832
|
+
return siren === innerValue.legalIdentifier
|
|
1833
|
+
? undefined
|
|
1834
|
+
: validationError('legalIdentifierRcs', getValidatorMessages().legalIdentifierRcs);
|
|
1835
|
+
}, config);
|
|
1836
|
+
}
|
|
1837
|
+
function groupValidatorLegalIdentifierVatFr(path, config) {
|
|
1838
|
+
validate(path, ({ value }) => {
|
|
1839
|
+
const innerValue = value();
|
|
1840
|
+
if (!innerValue.legalIdentifier || !innerValue.vatNumber)
|
|
1841
|
+
return undefined;
|
|
1842
|
+
return isVatFrChecksumValid(innerValue.vatNumber, innerValue.legalIdentifier)
|
|
1843
|
+
? undefined
|
|
1844
|
+
: validationError('legalIdentifierVatFr', getValidatorMessages().legalIdentifierVatFr);
|
|
1845
|
+
}, config);
|
|
1846
|
+
}
|
|
1847
|
+
function isVatFrChecksumValid(value, siren) {
|
|
1848
|
+
const groups = VAT_FR_REGEX.exec(value);
|
|
1849
|
+
const checksumString = groups?.at(1);
|
|
1850
|
+
const sirenString = groups?.at(2);
|
|
1851
|
+
const checksum = checksumString ? Number.parseInt(checksumString) : 0;
|
|
1852
|
+
const vatSiren = sirenString ? Number.parseInt(sirenString) : 0;
|
|
1853
|
+
return sirenString === siren && checksum === (12 + 3 * (vatSiren % 97)) % 97;
|
|
1854
|
+
}
|
|
1855
|
+
const validators = {
|
|
1856
|
+
alphaNumeric: validatorAlphaNumeric,
|
|
1857
|
+
arcepSlicePrefix: validatorArcepSlicePrefix,
|
|
1858
|
+
cidrIsNetworkAddress: validatorCidrIsNetworkAddress,
|
|
1859
|
+
companyType: validatorCompanyType,
|
|
1860
|
+
dataVolumeRange: validatorDataVolumeRange,
|
|
1861
|
+
dateRange: validatorDateRange,
|
|
1862
|
+
differentDate: validatorDifferentDate,
|
|
1863
|
+
email: validatorEmail,
|
|
1864
|
+
esignatureSignerField: validatorEsignatureSignerField,
|
|
1865
|
+
fileType: validatorFileType,
|
|
1866
|
+
frenchPhoneNumber: validatorFrenchPhoneNumber,
|
|
1867
|
+
ipv4WithMask: validatorIpv4WithMask,
|
|
1868
|
+
ipv4WithoutMask: validatorIpv4WithoutMask,
|
|
1869
|
+
kvk: validatorKvk,
|
|
1870
|
+
legalIdentifierRcs: groupValidatorLegalIdentifierRcs,
|
|
1871
|
+
legalIdentifierVatFr: groupValidatorLegalIdentifierVatFr,
|
|
1872
|
+
length: validatorLength,
|
|
1873
|
+
lengthRange: validatorLengthRange,
|
|
1874
|
+
max: validatorMax,
|
|
1875
|
+
maxFileSize: validatorMaxFileSize,
|
|
1876
|
+
maxLength: validatorMaxLength,
|
|
1877
|
+
maxTextLength: validatorMaxTextLength,
|
|
1878
|
+
min: validatorMin,
|
|
1879
|
+
minLength: validatorMinLength,
|
|
1880
|
+
minTextLength: validatorMinTextLength,
|
|
1881
|
+
mobilePhoneNumber: validatorMobilePhoneNumber,
|
|
1882
|
+
nafApe: validatorNafApe,
|
|
1883
|
+
portabilityPrefix: validatorPortabilityPrefix,
|
|
1884
|
+
portableApnfNumber: validatorPortableApnfNumber,
|
|
1885
|
+
range: validatorRange,
|
|
1886
|
+
required: validatorRequired,
|
|
1887
|
+
requiredTrue: validatorRequiredTrue,
|
|
1888
|
+
rio: validatorRio,
|
|
1889
|
+
simNumber: validatorSimNumber,
|
|
1890
|
+
siren: validatorSiren,
|
|
1891
|
+
siret: validatorSiret,
|
|
1892
|
+
textLength: validatorTextLength,
|
|
1893
|
+
textLengthRange: validatorTextLengthRange,
|
|
1894
|
+
unique: validatorUnique,
|
|
1895
|
+
url: validatorUrl,
|
|
1896
|
+
vatFr: validatorVatFr,
|
|
1897
|
+
vatNl: validatorVatNl,
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
var signalValidators$1 = /*#__PURE__*/Object.freeze({
|
|
1901
|
+
__proto__: null,
|
|
1902
|
+
MAX_MASK: MAX_MASK,
|
|
1903
|
+
MIN_MASK: MIN_MASK,
|
|
1904
|
+
NSCE_LENGTH: NSCE_LENGTH,
|
|
1905
|
+
SIRET_LENGTH: SIRET_LENGTH,
|
|
1906
|
+
URL_REGEX: URL_REGEX,
|
|
1907
|
+
customFileTypes: customFileTypes,
|
|
1908
|
+
groupValidatorLegalIdentifierRcs: groupValidatorLegalIdentifierRcs,
|
|
1909
|
+
groupValidatorLegalIdentifierVatFr: groupValidatorLegalIdentifierVatFr,
|
|
1910
|
+
validationError: validationError,
|
|
1911
|
+
validatorAlphaNumeric: validatorAlphaNumeric,
|
|
1912
|
+
validatorArcepSlicePrefix: validatorArcepSlicePrefix,
|
|
1913
|
+
validatorCidrIsNetworkAddress: validatorCidrIsNetworkAddress,
|
|
1914
|
+
validatorCompanyType: validatorCompanyType,
|
|
1915
|
+
validatorDataVolumeRange: validatorDataVolumeRange,
|
|
1916
|
+
validatorDateRange: validatorDateRange,
|
|
1917
|
+
validatorDifferentDate: validatorDifferentDate,
|
|
1918
|
+
validatorEmail: validatorEmail,
|
|
1919
|
+
validatorEsignatureSignerField: validatorEsignatureSignerField,
|
|
1920
|
+
validatorFileType: validatorFileType,
|
|
1921
|
+
validatorFrenchPhoneNumber: validatorFrenchPhoneNumber,
|
|
1922
|
+
validatorIpv4WithMask: validatorIpv4WithMask,
|
|
1923
|
+
validatorIpv4WithoutMask: validatorIpv4WithoutMask,
|
|
1924
|
+
validatorKvk: validatorKvk,
|
|
1925
|
+
validatorLength: validatorLength,
|
|
1926
|
+
validatorLengthRange: validatorLengthRange,
|
|
1927
|
+
validatorMax: validatorMax,
|
|
1928
|
+
validatorMaxFileSize: validatorMaxFileSize,
|
|
1929
|
+
validatorMaxLength: validatorMaxLength,
|
|
1930
|
+
validatorMaxTextLength: validatorMaxTextLength,
|
|
1931
|
+
validatorMin: validatorMin,
|
|
1932
|
+
validatorMinLength: validatorMinLength,
|
|
1933
|
+
validatorMinTextLength: validatorMinTextLength,
|
|
1934
|
+
validatorMobilePhoneNumber: validatorMobilePhoneNumber,
|
|
1935
|
+
validatorNafApe: validatorNafApe,
|
|
1936
|
+
validatorPortabilityPrefix: validatorPortabilityPrefix,
|
|
1937
|
+
validatorPortableApnfNumber: validatorPortableApnfNumber,
|
|
1938
|
+
validatorRange: validatorRange,
|
|
1939
|
+
validatorRequired: validatorRequired,
|
|
1940
|
+
validatorRequiredTrue: validatorRequiredTrue,
|
|
1941
|
+
validatorRio: validatorRio,
|
|
1942
|
+
validatorSimNumber: validatorSimNumber,
|
|
1943
|
+
validatorSiren: validatorSiren,
|
|
1944
|
+
validatorSiret: validatorSiret,
|
|
1945
|
+
validatorTextLength: validatorTextLength,
|
|
1946
|
+
validatorTextLengthRange: validatorTextLengthRange,
|
|
1947
|
+
validatorUnique: validatorUnique,
|
|
1948
|
+
validatorUrl: validatorUrl,
|
|
1949
|
+
validatorVatFr: validatorVatFr,
|
|
1950
|
+
validatorVatNl: validatorVatNl,
|
|
1951
|
+
validators: validators
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
function assertIsFormControl(control) {
|
|
1955
|
+
if (!isFormControl(control)) {
|
|
1956
|
+
throw new Error(`The control is not a FormControl`);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
function isFormGroup(value) {
|
|
1961
|
+
return value instanceof FormGroup;
|
|
1962
|
+
}
|
|
1963
|
+
function isFormArray(value) {
|
|
1964
|
+
return value instanceof FormArray;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
1968
|
+
const INVALID_FORM_KEY = 'invalidForm';
|
|
1969
|
+
function connectCtrlToCva(cva, control, mapperOrOpts, options) {
|
|
1970
|
+
const [{ modelToView, notifyModel = (value) => cva.setValue(value, {
|
|
1971
|
+
source: 'program-control',
|
|
1972
|
+
}), notifyView = (value, options) => control.patchValue(value, options), viewToModel, }, { injector, immediate = false },] = normalizeOptions(mapperOrOpts, options);
|
|
1973
|
+
return assertInjector(connectCtrlToCva, injector, () => {
|
|
1974
|
+
const destroyRef = inject(DestroyRef);
|
|
1975
|
+
const cdr = inject(ChangeDetectorRef);
|
|
1976
|
+
const injector = inject(Injector);
|
|
1977
|
+
const connector = () => {
|
|
1978
|
+
const initialValue = control.getRawValue();
|
|
1979
|
+
const parent = cva.ngControl
|
|
1980
|
+
? patchNgControl(cva.ngControl, injector).control
|
|
1981
|
+
: undefined;
|
|
1982
|
+
if (parent) {
|
|
1983
|
+
// add validator to automatically propagate the error from inner control
|
|
1984
|
+
const propagatedValidator = () => control.valid || control.disabled
|
|
1985
|
+
? null
|
|
1986
|
+
: { [INVALID_FORM_KEY]: true, ...control.errors };
|
|
1987
|
+
parent.addValidators(propagatedValidator);
|
|
1988
|
+
destroyRef.onDestroy(() => parent.removeValidators(propagatedValidator));
|
|
1989
|
+
// propagate mark all as touched to inner control
|
|
1990
|
+
const markAllAsTouched = parent.markAllAsTouched.bind(parent);
|
|
1991
|
+
parent.markAllAsTouched = () => {
|
|
1992
|
+
markAllAsTouched();
|
|
1993
|
+
control.markAllAsTouched.call(control);
|
|
1994
|
+
cdr.markForCheck();
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
let sub = Subscription.EMPTY;
|
|
1998
|
+
const listen = () =>
|
|
1999
|
+
// propagate value to inner control
|
|
2000
|
+
(sub = cva.valueChanges$
|
|
2001
|
+
.pipe(takeUntilDestroyed(destroyRef))
|
|
2002
|
+
.subscribe((value) => {
|
|
2003
|
+
notifyView(isNotNullable(value) ? modelToView(value) : initialValue, { emitEvent: false });
|
|
2004
|
+
}));
|
|
2005
|
+
const unlisten = () => sub.unsubscribe();
|
|
2006
|
+
listen();
|
|
2007
|
+
control.statusChanges
|
|
2008
|
+
.pipe(takeUntilDestroyed(destroyRef))
|
|
2009
|
+
.subscribe((status) => {
|
|
2010
|
+
if (status === 'INVALID' || status === 'VALID') {
|
|
2011
|
+
cva.ngControl?.control?.updateValueAndValidity({
|
|
2012
|
+
emitEvent: false,
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
cva._stateChange();
|
|
2016
|
+
});
|
|
2017
|
+
// on each new value from inner control we change the value of cva
|
|
2018
|
+
control.valueChanges
|
|
2019
|
+
.pipe(map(() => control.getRawValue()), takeUntilDestroyed(destroyRef))
|
|
2020
|
+
.subscribe((value) => {
|
|
2021
|
+
unlisten();
|
|
2022
|
+
notifyModel(viewToModel(value));
|
|
2023
|
+
listen();
|
|
2024
|
+
});
|
|
2025
|
+
let enabledStateMap = new WeakMap();
|
|
2026
|
+
// propagate disabled state to inner control
|
|
2027
|
+
cva.disabledChanges$
|
|
2028
|
+
.pipe(startWith(cva.disabled), takeUntilDestroyed(destroyRef))
|
|
2029
|
+
.subscribe((disabled) => {
|
|
2030
|
+
if (disabled) {
|
|
2031
|
+
storeEnabledStates(control, enabledStateMap);
|
|
2032
|
+
control.disable({ emitEvent: false });
|
|
2033
|
+
}
|
|
2034
|
+
else {
|
|
2035
|
+
restoreEnabledStates(control, enabledStateMap);
|
|
2036
|
+
enabledStateMap = new WeakMap();
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
// propagate required state to inner control
|
|
2040
|
+
cva.requiredChanges$
|
|
2041
|
+
.pipe(startWith(cva.required), takeUntilDestroyed(destroyRef))
|
|
2042
|
+
.subscribe((required) => {
|
|
2043
|
+
if (required) {
|
|
2044
|
+
control.addValidators(validatorRequired$1);
|
|
2045
|
+
}
|
|
2046
|
+
else {
|
|
2047
|
+
control.removeValidators(validatorRequired$1);
|
|
2048
|
+
}
|
|
2049
|
+
control.updateValueAndValidity({ emitEvent: false });
|
|
2050
|
+
});
|
|
2051
|
+
// initialize first value
|
|
2052
|
+
try {
|
|
2053
|
+
const value = cva.value;
|
|
2054
|
+
if (isNotNullable(value)) {
|
|
2055
|
+
const viewValue = modelToView(value);
|
|
2056
|
+
notifyView(viewValue);
|
|
2057
|
+
}
|
|
2058
|
+
// eslint-disable-next-line no-empty
|
|
2059
|
+
}
|
|
2060
|
+
catch (_ignore) { }
|
|
2061
|
+
};
|
|
2062
|
+
if (immediate) {
|
|
2063
|
+
connector();
|
|
2064
|
+
}
|
|
2065
|
+
else {
|
|
2066
|
+
afterNextRender({ earlyRead: connector });
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
function normalizeOptions(mapperOrOpts, options) {
|
|
2071
|
+
if (mapperOrOpts &&
|
|
2072
|
+
'modelToView' in mapperOrOpts &&
|
|
2073
|
+
'modelToView' in mapperOrOpts) {
|
|
2074
|
+
return [mapperOrOpts, options ?? {}];
|
|
2075
|
+
}
|
|
2076
|
+
return [
|
|
2077
|
+
{
|
|
2078
|
+
modelToView: identity,
|
|
2079
|
+
viewToModel: identity,
|
|
2080
|
+
},
|
|
2081
|
+
mapperOrOpts ?? {},
|
|
2082
|
+
];
|
|
2083
|
+
}
|
|
2084
|
+
function storeEnabledStates(control, map) {
|
|
2085
|
+
map.set(control, control.enabled);
|
|
2086
|
+
if (isFormGroup(control)) {
|
|
2087
|
+
Object.values(control.controls).forEach((item) => storeEnabledStates(item, map));
|
|
2088
|
+
}
|
|
2089
|
+
if (isFormArray(control)) {
|
|
2090
|
+
control.controls.forEach((item) => storeEnabledStates(item, map));
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
function restoreEnabledStates(control, map) {
|
|
2094
|
+
const wasEnabled = map.get(control);
|
|
2095
|
+
if (wasEnabled === undefined)
|
|
2096
|
+
return;
|
|
2097
|
+
if (wasEnabled) {
|
|
2098
|
+
control.enable({ emitEvent: false });
|
|
2099
|
+
}
|
|
2100
|
+
else {
|
|
2101
|
+
control.disable({ emitEvent: false });
|
|
2102
|
+
}
|
|
2103
|
+
if (isFormGroup(control)) {
|
|
2104
|
+
Object.values(control.controls).forEach((item) => restoreEnabledStates(item, map));
|
|
2105
|
+
}
|
|
2106
|
+
if (isFormArray(control)) {
|
|
2107
|
+
control.controls.forEach((item) => restoreEnabledStates(item, map));
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
class ReplayControlStatusObservable extends Observable {
|
|
2112
|
+
constructor(input) {
|
|
2113
|
+
super((subscriber) => input.statusChanges.pipe(startWith(input.status)).subscribe(subscriber));
|
|
2114
|
+
}
|
|
2115
|
+
static of(input) {
|
|
2116
|
+
return new ReplayControlStatusObservable(input);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* Generated bundle index. Do not edit.
|
|
2122
|
+
*/
|
|
2123
|
+
|
|
2124
|
+
export { CvaDirective, DEFAULT_VALIDATOR_MESSAGES, EMPTY_ERROR, GenericFormErrorMessagePipe, INVALID_FORM_KEY, MAX_MASK$1 as MAX_MASK, MIN_MASK$1 as MIN_MASK, NSCE_LENGTH$1 as NSCE_LENGTH, ReplayControlStatusObservable, ReplayControlValueObservable, SIRET_LENGTH$1 as SIRET_LENGTH, URL_REGEX$1 as URL_REGEX, VALIDATOR_MESSAGES, assertIsFormControl, connectCtrlToCva, controlSignal, createGroupValidator, customFileTypes$1 as customFileTypes, genericFormErrorMessage, getFormErrorMessage, getValidatorMessages, groupValidatorLegalIdentifierRcs$1 as groupValidatorLegalIdentifierRcs, groupValidatorLegalIdentifierVatFr$1 as groupValidatorLegalIdentifierVatFr, injectCva, injectNgControl, injectValidatorMessages, isFormArray, isFormGroup, isWriteValueEvent, patchNgControl, provideValidatorMessagesToken, signalValidators$1 as signalValidators, toCvaValue, validationError, validatorAlphaNumeric$1 as validatorAlphaNumeric, validatorArcepSlicePrefix$1 as validatorArcepSlicePrefix, validatorCidrIsNetworkAddress$1 as validatorCidrIsNetworkAddress, validatorCompanyType$1 as validatorCompanyType, validatorDataVolumeRange$1 as validatorDataVolumeRange, validatorDateRange$1 as validatorDateRange, validatorDifferentDate$1 as validatorDifferentDate, validatorEmail$1 as validatorEmail, validatorEsignatureSignerField$1 as validatorEsignatureSignerField, validatorFileType$1 as validatorFileType, validatorFrenchPhoneNumber$1 as validatorFrenchPhoneNumber, validatorIpv4WithMask$1 as validatorIpv4WithMask, validatorIpv4WithoutMask$1 as validatorIpv4WithoutMask, validatorKvk$1 as validatorKvk, validatorLength$1 as validatorLength, validatorLengthRange$1 as validatorLengthRange, validatorMax$1 as validatorMax, validatorMaxFileSize$1 as validatorMaxFileSize, validatorMaxLength$1 as validatorMaxLength, validatorMaxTextLength$1 as validatorMaxTextLength, validatorMin$1 as validatorMin, validatorMinLength$1 as validatorMinLength, validatorMinTextLength$1 as validatorMinTextLength, validatorMobilePhoneNumber$1 as validatorMobilePhoneNumber, validatorNafApe$1 as validatorNafApe, validatorPortabilityPrefix$1 as validatorPortabilityPrefix, validatorPortableApnfNumber$1 as validatorPortableApnfNumber, validatorRange$1 as validatorRange, validatorRequired$1 as validatorRequired, validatorRequiredTrue$1 as validatorRequiredTrue, validatorRio$1 as validatorRio, validatorSimNumber$1 as validatorSimNumber, validatorSiren$1 as validatorSiren, validatorSiret$1 as validatorSiret, validatorTextLength$1 as validatorTextLength, validatorTextLengthRange$1 as validatorTextLengthRange, validatorUnique$1 as validatorUnique, validatorUrl$1 as validatorUrl, validatorVatFr$1 as validatorVatFr, validatorVatNl$1 as validatorVatNl, validators };
|
|
2125
|
+
//# sourceMappingURL=netwo-devkit-angular-forms.mjs.map
|