@fkui/logic 6.14.0 → 6.16.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.
@@ -36,1254 +36,1360 @@ export declare interface AllowListValidatorConfig extends ValidatorOptions {
36
36
  }
37
37
 
38
38
  /**
39
- * List of all available builtin validators.
39
+ * [Assertion function][ts-handbook] to assert that a nullable Vue ref holds a
40
+ * non-null value. Typically used with template refs but any nullable ref can be
41
+ * used.
40
42
  *
41
- * @public
42
- */
43
- export declare const availableValidators: Validator[];
44
-
45
- /**
46
- * A string with 3-16 digits, for example "0123456789"
47
- *
48
- * @public
49
- */
50
- export declare type BankAccountNumberString = string;
51
-
52
- /**
53
- * A string with 7-8 digits separated by hyphen, for example "999-9996"
54
- *
55
- * @public
56
- */
57
- export declare type BankgiroString = string;
58
-
59
- /**
60
- * @public
61
- */
62
- export declare interface BlacklistValidatorConfig extends ValidatorOptions {
63
- values: string | string[] | number | number[];
64
- }
65
-
66
- /**
67
- * A string of 4-5 digits where last digit may be separated by hyphen, for
68
- * example "5678-1"
69
- *
70
- * @public
71
- */
72
- export declare type ClearingnumberString = string;
73
-
74
- /**
75
- * @public
76
- */
77
- export declare const configLogic: FKUIConfigLogic;
78
-
79
- /**
80
- * @public
81
- */
82
- export declare interface CookieOptions {
83
- name: string;
84
- value: string;
85
- keepAnyExistingCookie?: boolean;
86
- /** `max-age` parameter, default: 12h */
87
- timeLimitSeconds?: number;
88
- }
89
-
90
- /**
91
- * A string in format YYYY-MM-DD, for example 2021-02-03
92
- *
93
- * @public
94
- */
95
- export declare type DateString = string;
96
-
97
- /**
98
- * Executes a function when it stops being invoked for n seconds. Usually used together with resize,
99
- * scroll and keyup/keydown-events to improve application's performance.
100
- *
101
- * Example:
102
- *
103
- * ```
104
- * window.addEventListener(
105
- * 'resize',
106
- * debounce(computationalHeavyFunction, 1000),
107
- * );
108
- * ```
109
- *
110
- * This will call the `computationalHeavyFunction` once if the resize-event hasn't been sent for 1000 ms.
111
- *
112
- * Example with immediate-flag:
113
- *
114
- * ```
115
- * window.addEventListener(
116
- * 'resize',
117
- * debounce(computationalHeavyFunction, 1000, true),
118
- * );
119
- * ```
120
- *
121
- * This will call the `computationalHeavyFunction` once BEFORE the resize-event has finished,
122
- * and thereafter will not be able to be called again until the timeout has finished
123
- *
124
- * @public
125
- * @param func - Function to be debounced.
126
- * @param delay - Function execution threshold in milliseconds.
127
- * @param immediate - Whether the function should be called at the beginning of the delay (Before the timeout) instead of the end.
128
- * Default is false.
129
- */
130
- export declare function debounce<TThis, TArgs extends unknown[], TReturn>(this: TThis, func: (this: TThis, ...args: TArgs) => TReturn, delay: number, immediate?: boolean): (...args: TArgs) => void;
131
-
132
- /**
133
- * @public
134
- */
135
- export declare interface DecimalValidatorConfig extends ValidatorOptions {
136
- minDecimals: number;
137
- maxDecimals: number;
138
- }
139
-
140
- /**
141
- * Decorates an original error with more information while
142
- * keeping the original intact.
143
- *
144
- * @public
145
- */
146
- export declare class DecoratedError extends Error {
147
- cause: Error;
148
- constructor(message: string, cause: Error);
149
- /**
150
- * Get the direct cause of this error, the one that triggered
151
- * this error.
152
- */
153
- getCause(): Error;
154
- /**
155
- * Get the root cause of this error, the first error that occured.
156
- */
157
- getRootCause(): Error;
158
- }
159
-
160
- /**
161
- * Perform a deep clone of the given value.
162
- *
163
- * This function supports cloning:
43
+ * Throws {@link MissingValueError} if the ref holds `null` or `undefined`, or
44
+ * the ref itself is `null` or `undefined`.
164
45
  *
165
- * - Primitive types such as booleans, numbers and strings
166
- * - Arrays and objects
167
- * - Classes
168
- * - `Date`,
169
- * - `Map`,
170
- * - `RegExp`
171
- * - `Set`
172
- * - `Symbol`
46
+ * [ts-handbook]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
173
47
  *
174
- * The following values are NOT cloned:
48
+ * @example
175
49
  *
176
- * - `Error` (and subclasses) - Cloned value will reference the same Error instance.
177
- * - DOM `Node` (and subclasses) - Cloned value will return the same DOM reference.
178
- * - `Function` (and arrow functions) - Cloned value will be an empty object `{}`
179
- *
180
- * @public
181
- * @param value - The value to recursively clone.
182
- * @returns Returns the deep cloned value.
183
- */
184
- export declare function deepClone<T>(value: T): T;
185
-
186
- /**
187
- * @public
188
- */
189
- export declare function deleteCookie(name: string): void;
190
-
191
- /**
192
- * Compares the position of the given node against another node in any document.
50
+ * ```ts
51
+ * const element = useTemplateRef("my-template-ref");
52
+ * // ^? Readonly<ShallowRef<HTMLElement | null>>
193
53
  *
194
- * Unset elements (e.g. `null`) are undefined behaviour but the current
195
- * non-contractural behaviour is to put them at the end of the sorted
196
- * array. The caller should ensure those elements are removed before sorting.
54
+ * assertRef(element);
197
55
  *
198
- * @example
199
- * ```ts
200
- * const sorted = listOfElements.sort(documentOrderComparator);
56
+ * // element is now guaranteed to be a HTMLElement ref
201
57
  * ```
202
58
  *
203
59
  * @public
204
- */
205
- export declare function documentOrderComparator<T extends Node>(a?: T | null, b?: T | null): number;
206
-
207
- declare namespace DomUtils {
208
- export {
209
- addFocusListener,
210
- documentOrderComparator,
211
- focus_2 as focus,
212
- isFocusable,
213
- isTabbable,
214
- findTabbableElements,
215
- focusFirst,
216
- focusLast,
217
- restoreFocus,
218
- saveFocus,
219
- FocusOptions_2 as FocusOptions,
220
- popFocus,
221
- pushFocus,
222
- StackHandle,
223
- handleTab,
224
- isValidatableFormElement,
225
- isVisible,
226
- isVisibleInViewport,
227
- removeFocusListener,
228
- scrollTo_2 as scrollTo,
229
- ScrollToOptions_2 as ScrollToOptions
230
- }
231
- }
232
- export { DomUtils }
233
-
234
- /**
235
- * @public
236
- */
237
- export declare const ElementIdService: ElementIdServiceInterface;
238
-
239
- /**
240
- * @public
241
- */
242
- export declare interface ElementIdServiceInterface {
243
- /**
244
- * Returns an element id in the following format: `fkui-vue-element-<elementId>`.
245
- */
246
- generateElementId(prefix?: string): string;
247
- /**
248
- * Resets the internal state.
249
- */
250
- reset(): void;
251
- }
252
-
253
- /**
254
- * @public
255
- */
256
- export declare interface ElementValidatorsReference {
257
- validators: Validator[];
258
- validatorConfigs: ValidatorConfigs;
259
- baseValidatorConfigs?: ValidatorConfigs;
260
- element: ValidatableHTMLElement;
261
- instant: boolean;
262
- }
263
-
264
- /**
265
- * @public
266
- */
267
- export declare interface EmailValidatorConfig extends ValidatorOptions {
268
- maxLength: number;
269
- }
270
-
271
- /**
272
- * Assert that a value is set and throw a {@link MissingValueError} if it is not,
273
- * i.e., both null and undefined values will throw an error. This can be nice to
274
- * use when transforming data between view model and rest api model.
275
- *
276
- * @public
277
- * @param value - the value asserted to be set.
60
+ * @since v6.15.0
61
+ * @param ref - the value asserted to be a ref.
278
62
  * @param message - an optional exception message to use if the check fails.
279
- * @returns the value unambiguously defined.
280
63
  * @throws {@link MissingValueError} if value is not set.
281
64
  */
282
- export declare function ensureSet<T>(value: T | undefined | null, message?: string): T | never;
283
-
284
- /**
285
- * @public
286
- */
287
- export declare function findCookie(name: string): string | undefined;
288
-
289
- /**
290
- * Find all visible and tabbable elements.
291
- *
292
- * @public
293
- * @param root - Element or document to find tabbable elements in.
294
- * @returns List of matching elements
295
- */
296
- export declare function findTabbableElements(root: HTMLElement | Document): HTMLElement[];
297
-
298
- /**
299
- * Configuration parameters specific to FKUI Logic
300
- *
301
- * @public
302
- */
303
- export declare interface FKUIConfigLogic {
304
- production: boolean;
305
- }
306
-
307
- /**
308
- * Takes an optionally nested textobject structure and convert to a flat
309
- * structure. Nested keys are joined with a dot ".". Deep nesting is supported.
310
- *
311
- * Given the following:
312
- * ```
313
- * {
314
- * "foo": {
315
- * "bar": "text"
316
- * }
317
- * }
318
- * ```
319
- *
320
- * It would produce the following output:
321
- * ```
322
- * {
323
- * "foo.bar": "text"
324
- * }
325
- * ```
326
- *
327
- * If the src object is already flat the output will be the same.
328
- *
329
- * @public
330
- * @param src - Source data
331
- * @param destination - Destination to write temporary result to.
332
- * @param prefix - If set this is prefixed to all keys.
333
- */
334
- export declare function flatten(src: NestedStringRecord, destination?: Record<string, string>, prefix?: string): Record<string, string>;
335
-
336
- /**
337
- * Give focus to a given element.
338
- *
339
- * For convenience it will ignore `null` and `undefined` as element parameter.
340
- *
341
- * If in a Vue context, please refer to the `focus` method included in `@fkui/vue`.
342
- *
343
- * @public
344
- * @param element - Element to focus.
345
- * @param options - Focus options. If you pass boolean `true` or `false` it sets the `force` option.
346
- */
347
- declare function focus_2(element: Element | null | undefined, options?: boolean | FocusOptions_2): void;
348
- export { focus_2 as focus }
349
-
350
- /**
351
- * Focus first focusable element among given root element's hierarchy.
352
- *
353
- * @public
354
- * @param rootElement - Root element.
355
- */
356
- export declare function focusFirst(rootElement: HTMLElement): void;
357
-
358
- /**
359
- * Focus last focusable element among given root element's hierarchy.
360
- *
361
- * @public
362
- * @param rootElement - Root element.
363
- */
364
- export declare function focusLast(rootElement: HTMLElement): void;
365
-
366
- /**
367
- * Options for {@link focus}.
368
- *
369
- * @public
370
- */
371
- declare interface FocusOptions_2 {
372
- /**
373
- * If set to `true` `tabindex="-1"` will be added as needed so any element
374
- * can be focused.
375
- */
376
- force?: boolean;
377
- /**
378
- * By default the element is scrolled into view. Set this to `true` to prevent this behavior.
379
- *
380
- * See full description of [`preventScroll` at
381
- * MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#parameters)
382
- */
383
- preventScroll?: boolean;
384
- /**
385
- * By default the element is scrolled into view centered vertically. Set this to `true` to
386
- * scroll such that the elements top is at the top of the viewport.
387
- *
388
- * It will utilize the `scrollIntoView` function, see full description of [`scrollIntoView` at
389
- * MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
390
- */
391
- scrollToTop?: boolean;
392
- }
393
- export { FocusOptions_2 as FocusOptions }
394
-
395
- /**
396
- * @public
397
- */
398
- export declare function formatClearingNumberForBackend(value: ClearingnumberString): string | undefined;
399
-
400
- /**
401
- * Format number with thousand separator and use comma as decimal separator.
402
- *
403
- * @public
404
- */
405
- export declare function formatNumber(value: number | string | undefined | null, decimals?: number): string | undefined;
406
-
407
- /**
408
- * @public
409
- */
410
- export declare function formatPercent(modelValue: number | string | undefined | null, decimals?: number): string | undefined;
411
-
412
- /**
413
- * Formats personnummer to a 10-digit string.
414
- *
415
- * @public
416
- */
417
- export declare function formatPersonnummer(value: PersonnummerString | null | undefined): string | undefined;
418
-
419
- /**
420
- * Formats personnummer to a 8-digit date.
421
- *
422
- * @public
423
- */
424
- export declare function formatPersonnummerToDate(value: PersonnummerString | undefined): FDate | undefined;
425
-
426
- /**
427
- * @public
428
- */
429
- export declare function formatPostalCode(value: string | undefined | null): string | undefined;
430
-
431
- /**
432
- * @public
433
- */
434
- export declare function getErrorMessages(): Record<string, string>;
435
-
436
- /**
437
- * Handle tab focus between given containers focusable elements
438
- *
439
- * @public
440
- * @param event - tab KeyboardEvent
441
- * @param container - containing focusable elements
442
- */
443
- export declare function handleTab(event: KeyboardEvent, container: HTMLElement): void;
444
-
445
- /**
446
- * @public
447
- */
448
- export declare interface InvalidDatesValidatorConfig extends ValidatorOptions {
449
- dates: string[];
450
- }
65
+ export declare function assertRef<T>(ref: {
66
+ value: T | null;
67
+ } | undefined | null, message?: string): asserts ref is {
68
+ value: T;
69
+ };
451
70
 
452
71
  /**
453
- * @public
454
- */
455
- export declare interface InvalidWeekdaysValidatorConfig extends ValidatorOptions {
456
- days: number[];
457
- }
458
-
459
- /**
460
- * Determine if a value is empty.
461
- *
462
- * A value is considered empty if it is:
72
+ * [Assertion function][ts-handbook] to assert that a value is set.
73
+ * Any value that is not null or undefined is considered set including falsy values such as 0 or "".
463
74
  *
464
- * - `undefined`
465
- * - `null`
466
- * - empty string `""`.
75
+ * Throws {@link MissingValueError} if value is not set.
467
76
  *
468
- * @public
469
- * @param value - value to check if it is empty
470
- */
471
- export declare function isEmpty(value: string | undefined | null): value is "" | undefined | null;
472
-
473
- /**
474
- * Check if an element is focusable (visible and either interactive or with
475
- * tabindex). This includes programatically focusable elements.
77
+ * [ts-handbook]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
476
78
  *
477
- * @public
478
- * @param element - An `Element` for which to test focusability.
479
- * @returns `true` if the element is focusable, otherwise `false`.
480
- */
481
- export declare function isFocusable(element: Element): boolean;
482
-
483
- /**
484
- * @public
485
- */
486
- export declare function isInvalidDatesConfig(value: Partial<InvalidDatesValidatorConfig>): value is InvalidDatesValidatorConfig;
487
-
488
- /**
489
- * @public
490
- */
491
- export declare function isInvalidWeekdaysConfig(value: Partial<InvalidWeekdaysValidatorConfig>): value is InvalidWeekdaysValidatorConfig;
492
-
493
- /* Excluded from this release type: isRadiobuttonOrCheckbox */
494
-
495
- /**
496
- * Determine if a value is set. If it is undefined or null, this function
497
- * returns false.
498
- *
499
- * @public
500
- * @param value - the value for which to determine if it is set
501
- */
502
- export declare function isSet<T>(value: T | undefined | null): value is T;
503
-
504
- /**
505
- * @public
506
- */
507
- export declare function isString(value: string | unknown): boolean;
508
-
509
- /**
510
- * Check if an element is tabbable (visible and either interactive or
511
- * non-negative tabindex). This does not include programatically focusable
512
- * elements.
513
- *
514
- * @public
515
- * @param element - An `Element` for which to test focusability.
516
- * @returns `true` if the element is focusable, otherwise `false`.
517
- */
518
- export declare function isTabbable(element: Element): boolean;
519
-
520
- /**
521
- * Check if element is a form element
522
- *
523
- * Also see {@link isValidatableHTMLElement} for a similar function but
524
- * including HTMLFieldSetElement.
525
- *
526
- * @public
527
- * @param element - Element to test
528
- */
529
- export declare function isValidatableFormElement(element: Element): element is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
530
-
531
- /**
532
- * Returns true if given element is a validatable element.
533
- *
534
- * Also see {@link isValidatableFormElement} for a similar function but
535
- * excluding HTMLFieldSetElement.
536
- *
537
- * @public
538
- * @param element - Element to test
539
- */
540
- export declare function isValidatableHTMLElement(element: Element): element is ValidatableHTMLElement;
541
-
542
- /**
543
- * Check if an element is visible in the dom
544
- *
545
- * @public
546
- */
547
- export declare function isVisible(element: HTMLElement): boolean;
548
-
549
- /**
550
- * Check if an element is fully visible in the viewport
551
- *
552
- * @public
553
- */
554
- export declare function isVisibleInViewport(element: Element): boolean;
555
-
556
- /**
557
- * @public
558
- */
559
- export declare interface MatchesValidatorConfig extends ValidatorOptions {
560
- /** Identifier of another input field */
561
- id?: string;
562
- }
563
-
564
- /**
565
- * @public
566
- */
567
- export declare interface MaxDateValidatorConfig extends ValidatorOptions {
568
- limit: string;
569
- }
570
-
571
- /**
572
- * @public
573
- */
574
- export declare interface MaxLengthValidatorConfig extends ValidatorOptions {
575
- length: number;
576
- }
577
-
578
- /**
579
- * @public
580
- */
581
- export declare interface MinDateValidatorConfig extends ValidatorOptions {
582
- limit: string;
583
- }
584
-
585
- /**
586
- * @public
587
- */
588
- export declare interface MinLengthValidatorConfig extends ValidatorOptions {
589
- length: number;
590
- }
591
-
592
- /**
593
- * An error indicating that a mandatory value is not set.
594
- *
595
- * @public
596
- */
597
- export declare class MissingValueError extends Error {
598
- constructor(message?: string);
599
- }
600
-
601
- /**
602
- * @public
603
- */
604
- export declare interface NestedStringRecord {
605
- [key: string]: string | NestedStringRecord;
606
- }
607
-
608
- /* Excluded from this release type: normalizeDateFormat */
609
-
610
- /**
611
- * A string with 6 digits followed by additional 4 digits separated by a hyphen,
612
- * for example "999999-9999".
613
- *
614
- * @public
615
- */
616
- export declare type OrganisationsnummerString = string;
617
-
618
- /**
619
- * @public
620
- */
621
- export declare function parseBankAccountNumber(value: string): BankAccountNumberString | undefined;
622
-
623
- /**
624
- * @public
625
- */
626
- export declare function parseBankgiro(value: string): BankgiroString | undefined;
627
-
628
- /**
629
- * @public
630
- */
631
- export declare function parseClearingNumber(value: string): ClearingnumberString | undefined;
632
-
633
- /**
634
- * @public
635
- */
636
- export declare function parseDate(value: string): DateString | undefined;
637
-
638
- /**
639
- * @public
640
- */
641
- export declare function parseNumber(value: string): number | undefined;
642
-
643
- /**
644
- * @public
645
- */
646
- export declare function parseOrganisationsnummer(value: string): OrganisationsnummerString | undefined;
647
-
648
- /**
649
- * @public
650
- */
651
- export declare function parsePercent(viewValue: string): number;
652
-
653
- /**
654
- * Parses 10- and 12-digit personnummers.
655
- *
656
- * @public
657
- */
658
- export declare function parsePersonnummer(value: string | null | undefined, now?: FDate): PersonnummerString | undefined;
659
-
660
- /**
661
- * Parses 10- and 12-digit personnummers with Luhn validation.
662
- *
663
- * @public
664
- */
665
- export declare function parsePersonnummerLuhn(value: string | null | undefined): PersonnummerString | undefined;
666
-
667
- /**
668
- * @public
669
- */
670
- export declare function parsePlusgiro(value: string): PlusgiroString | undefined;
671
-
672
- /**
673
- * @public
674
- */
675
- export declare function parsePostalCode(value: string): PostalCodeString | undefined;
676
-
677
- /**
678
- * Describes the event that is dispatched during input if no instant validation.
679
- *
680
- * @public
681
- */
682
- export declare interface PendingValidityEvent {
683
- }
684
-
685
- /**
686
- * This feature can be used by creating a new file with something like:
687
- *
688
- * ```
689
- * export const MyCustomPersistenceService = new PersistenceService<MyCustomApplicationModel>();
690
- * ```
691
- *
692
- * There is also a simplified version in {@link SimplePersistenceService}.
693
- *
694
- * @public
695
- */
696
- export declare class PersistenceService<T> implements PersistenceServiceInterface<T> {
697
- private cache;
698
- constructor();
699
- set(key: string, value: T): void;
700
- get(key: string): T;
701
- find(key: string): T | undefined;
702
- remove(key: string): void;
703
- /* Excluded from this release type: isSessionPresent */
704
- }
705
-
706
- /**
707
- * @public
708
- */
709
- export declare interface PersistenceServiceInterface<T> {
710
- set(key: string, value: T): void;
711
- get(key: string): T;
712
- find(key: string): T | undefined;
713
- remove(key: string): void;
714
- }
715
-
716
- /**
717
- * A 12-digit string including hyphen separator, for example "99999999-9999"
718
- *
719
- * @public
720
- */
721
- export declare type PersonnummerString = string;
722
-
723
- /**
724
- * A string containing of digits separated by spaces and hyphen, see spec-file for
725
- * examples
726
- *
727
- * @public
728
- */
729
- export declare type PlusgiroString = string;
730
-
731
- /**
732
- * Restore the focus on the last element from the stack
733
- *
734
- * @public
735
- * @throws Error when pop is called on an empty focus stack
736
- * @throws Error when pop is called without a valid StackHandle
737
- */
738
- export declare function popFocus(handle: StackHandle): void;
739
-
740
- /**
741
- * A 5-digit string with space separator, for example "932 22"
742
- *
743
- * @public
744
- */
745
- export declare type PostalCodeString = string;
746
-
747
- /**
748
- * Save current active element focus on the stack and set focus on element
749
- *
750
- * @public
751
- * @param element - The element to set focus on
752
- */
753
- export declare function pushFocus(element?: Element | null): StackHandle;
754
-
755
- /**
756
- * Remove listener for each item in the list of elements
757
- *
758
- * @public
759
- */
760
- export declare function removeFocusListener(elements: HTMLElement[], listener: ((event: Event) => unknown) | (() => unknown)): void;
761
-
762
- /**
763
- * Restore focus to a previous element. Use this in combination with {@link saveFocus}
764
- *
765
- * @public
766
- */
767
- export declare function restoreFocus(): void;
768
-
769
- /**
770
- * Save a DOM reference to the active element for later use.
771
- *
772
- * @public
773
- * @param document - Document element
774
- */
775
- export declare function saveFocus(document: Document): void;
776
-
777
- /**
778
- * Default delay in milliseconds for {@link waitForScreenReader}
779
- *
780
- * @public
781
- */
782
- export declare const SCREEN_READER_DELAY = 100;
783
-
784
- /**
785
- * Scroll to element with scroll options.
786
- *
787
- * @public
788
- * @param element - Element to scroll into view
789
- * @param options - scroll options (duration, offset)
790
- */
791
- declare function scrollTo_2(element: Element, options: ScrollToOptions_2): Promise<void>;
792
-
793
- /**
794
- * Scroll to element
795
- *
796
- * @public
797
- * @param element - Element to scroll into view
798
- * @param offset - Set vertical offset, default 0px
799
- */
800
- declare function scrollTo_2(element: Element, offset?: number): Promise<void>;
801
- export { scrollTo_2 as scrollTo }
802
-
803
- /**
804
- * Optional arguments for scrollTo.
805
- *
806
- * @public
807
- * @param duration - Duration in milliseconds
808
- * @param offset - Set vertical offset, default 0px
809
- */
810
- declare interface ScrollToOptions_2 {
811
- duration?: number;
812
- offset?: number;
813
- }
814
- export { ScrollToOptions_2 as ScrollToOptions }
815
-
816
- /**
817
- * @public
818
- */
819
- export declare function setCookie(options: CookieOptions): void;
820
-
821
- /**
822
- * This feature can be used by creating a new file with something like:
79
+ * @example
823
80
  *
824
81
  * ```ts
825
- * export const MyAwesomePersistenceService = new SimplePersistenceService<MyAwesomeModel>("my-awesome-key");
826
- * ```
82
+ * const value = getValue();
83
+ * // ^? string | null
827
84
  *
828
- * There is also a more advanced version in {@link PersistenceService}.
85
+ * assertSet(value);
829
86
  *
830
- * @public
831
- */
832
- export declare class SimplePersistenceService<T> implements SimplePersistenceServiceInterface<T> {
833
- private persistenceService;
834
- private key;
835
- constructor(key: string);
836
- set(value: T): void;
837
- get(): T;
838
- find(): T | undefined;
839
- remove(): void;
840
- }
841
-
842
- /**
843
- * @public
844
- */
845
- export declare interface SimplePersistenceServiceInterface<T> {
846
- set(value: T): void;
847
- get(): T;
848
- find(): T | undefined;
849
- remove(): void;
850
- }
851
-
852
- /**
853
- * @public
854
- */
855
- export declare interface StackHandle {
856
- [sym]: number;
857
- }
858
-
859
- /** @public */
860
- export declare function stripNull<T>(obj: T): T;
861
-
862
- /** @public */
863
- export declare function stripNull(obj: null): undefined;
864
-
865
- /** @public */
866
- export declare function stripNull(obj: number): number;
867
-
868
- /** @public */
869
- export declare function stripNull(obj: string): string;
870
-
871
- /**
872
- * Strips all whitespace from the text (not only leading and trailing)
873
- *
874
- * @public
875
- * @param text - Text to strip whitespace from.
876
- * @returns Text with whitespace stripped.
877
- */
878
- export declare function stripWhitespace(text: string): string;
879
-
880
- declare const sym: unique symbol;
881
-
882
- /**
883
- * Takes a string containing only numbers and checks that the checksum is correct
884
- * according to the Luhn Algorithm.
885
- *
886
- * @public
887
- * @param inputString - A string containing only numbers
888
- */
889
- export declare function testLuhnChecksum(inputString: string): boolean;
890
-
891
- /**
892
- * @public
893
- */
894
- export declare type TranslateFunction = (key: string, defaultValueOrArgs?: string | Record<string, unknown>, args?: Record<string, unknown>) => string;
895
-
896
- /**
897
- * @public
898
- */
899
- export declare interface TranslationProviderInterface {
900
- readonly currentLanguage: string;
901
- changeLanguage(language: string): Promise<void> | Promise<TranslateFunction>;
902
- translate(key: string, defaultValueOrArgs?: string | Record<string, unknown>, args?: Record<string, unknown>): string;
903
- }
904
-
905
- /**
906
- * @public
907
- */
908
- export declare const TranslationService: TranslationServiceInterface;
909
-
910
- /**
911
- * @public
912
- */
913
- export declare interface TranslationServiceInterface {
914
- provider: TranslationProviderInterface;
915
- changeProvider(provider: TranslationProviderInterface): void;
916
- }
917
-
918
- /**
919
- * @public
920
- */
921
- export declare type ValidatableHTMLElement = HTMLDivElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLFieldSetElement;
922
-
923
- /**
924
- * Event used to trigger validation.
925
- *
926
- * @public
927
- */
928
- export declare interface ValidateEvent {
929
- }
930
-
931
- /**
932
- * Emitted when the validation configuration is updated and includes the current configuration.
933
- *
934
- * @public
935
- */
936
- export declare interface ValidationConfigUpdateDetail {
937
- /** Current configuration */
938
- config: ValidatorConfigs;
939
- }
940
-
941
- /**
942
- * Builder to create validation error message map.
943
- *
944
- * @public
945
- */
946
- export declare class ValidationErrorMessageBuilder {
947
- /**
948
- * Create a new builder.
949
- */
950
- static create(): ValidationErrorMessageBuilder;
951
- private validatorMessageMap;
952
- private constructor();
953
- /**
954
- * Map the validator name message towards an error message.
955
- *
956
- * @param validatorName - the name of the validator
957
- * @param message - the error message
958
- * @param elementType - limit to a specific element type
959
- */
960
- map(validatorName: ValidatorName, message: string, elementType?: "text" | "radio" | "checkbox" | "select" | "textarea"): this;
961
- /**
962
- * Validators that coexists on same element can have a combined message,
963
- * i.e. if a element have the `required` and the `personnummer` validator
964
- * the required error message could be combined with
965
- * `mapCombined('required','personnummer', 'You must enter a social security number!');`.
966
- *
967
- * @param validatorName - the name of the validator
968
- * @param dependentValidatorName - the name of the combined validator
969
- * @param message - the error message
970
- * @param elementType - limit to a specific element type
971
- */
972
- mapCombined(validatorName: ValidatorName, dependentValidatorName: ValidatorName, message: string, elementType?: "text" | "radio" | "checkbox" | "select" | "textarea"): this;
973
- /**
974
- * Build the translation map.
975
- *
976
- * @returns the created map.
977
- */
978
- build(): Record<string, string>;
979
- }
980
-
981
- /**
982
- * Result of {@link ValidationServiceInterface.validateElement}.
983
- *
984
- * @public
985
- */
986
- export declare interface ValidationResult {
987
- /**
988
- * `true` if the element is valid and have no validation errors.
989
- */
990
- isValid: boolean;
991
- /**
992
- * `true` if the field has been touched, i.e. the user has interacted with
993
- * it.
994
- */
995
- isTouched: boolean;
996
- /**
997
- * `true` if the field has been submitted (or attempted to be submitted)
998
- */
999
- isSubmitted: boolean;
1000
- /**
1001
- * Validation error message.
1002
- *
1003
- * `null` if no validation error is present.
1004
- */
1005
- error: string | null;
1006
- }
1007
-
1008
- /**
1009
- * @public
1010
- */
1011
- export declare const ValidationService: ValidationServiceInterface;
1012
-
1013
- /**
1014
- * @public
1015
- */
1016
- export declare interface ValidationServiceInterface {
1017
- /* Excluded from this release type: getElementsAndValidators */
1018
- /**
1019
- * Whether any of the fields are touched
1020
- */
1021
- readonly isAnyTouched: boolean;
1022
- /* Excluded from this release type: validationErrorMessages */
1023
- /* Excluded from this release type: resolveValidityModeWhenError */
1024
- /**
1025
- * Check if given element(s) are valid.
1026
- *
1027
- * When passing multiple elements all of them must be valid. For non-input
1028
- * elements (fieldsets, divs, etc) it checks whenever all descendants are
1029
- * valid. Returns `true` if array is empty.
1030
- *
1031
- * Note: this function does not update the validity state (i.e. run
1032
- * validators) but only checks the current state! Use
1033
- * {@link ValidationServiceInterface.validateElement} to update state.
1034
- *
1035
- * @public
1036
- * @deprecated Use {@link ValidationServiceInterface.validateElement} instead.
1037
- * @param src - Element instance or id.
1038
- * @param root - Element (or document) to query when looking up elements by id.
1039
- * @returns Resolves to `true` if all given elements (or descendants) are valid. Empty array resolves to `true`.
1040
- */
1041
- isValid(src: string | string[] | Element | Element[] | null, root?: Document | Element): Promise<boolean>;
1042
- /**
1043
- * Add translations for validators.
1044
- * New translations will be merged with existing
1045
- * translations and overwritten if they already exists.
1046
- * @see {@link ValidationErrorMessageBuilder}
1047
- *
1048
- * @public
1049
- * @param validationErrorMessageMap - the map with translation for validators
1050
- */
1051
- addValidationErrorMessages(validationErrorMessageMap: Record<ValidatorName | string, string>): void;
1052
- /**
1053
- * Register a validator.
1054
- * To be used when a customer validator is needed.
1055
- *
1056
- * @param validator - the validator to register
1057
- */
1058
- registerValidator<TConfig = ValidatorConfig>(validator: Validator<TConfig>): void;
1059
- /**
1060
- * Remove element from ValidationService.
1061
- *
1062
- * @param element - Element to remove validators from.
1063
- */
1064
- removeValidatorsFromElement(element: ValidatableHTMLElement): void;
1065
- /**
1066
- * Add validators to an element.
1067
- *
1068
- * @param element - the element to add validator to
1069
- * @param validatorConfigs - the defintion of validators to be addede.
1070
- * @param isBaseConfigs - is a boolean which indicates if this configuration
1071
- * should always lay as a base configuration even if overlaying code is
1072
- * changing its validators.
1073
- *
1074
- * As an example there is FEmailTextField which sets its own EmailValidator
1075
- * in the constructor. Then the app-code can add its own validatorsConfig on
1076
- * top of that (example: `required: { enabled: $someValue } }`). Setting
1077
- * isBaseConfigs to true preserves the validatorConfig set by
1078
- * FEmailTextField as the app code changes the required validatorConfig
1079
- * (which triggers `addValidatorsToElement()` again)
1080
- *
1081
- * @see {@link ValidityEvent} dispatched during blur and change
1082
- * @see {@link PendingValidityEvent} dispatched during input
1083
- */
1084
- addValidatorsToElement(element: ValidatableHTMLElement, validatorConfigs: ValidatorConfigs, isBaseConfigs?: boolean): void;
1085
- /**
1086
- * Set or update validation state on element(s).
1087
- *
1088
- * Can be used to restore state after page reload, or to set all elements in
1089
- * a subform to submitted.
1090
- *
1091
- * If passed element is a not a validatable element, the state of all
1092
- * validatable children is updated instead.
1093
- *
1094
- * @see {@link ValidityEvent} validityMode
1095
- *
1096
- * @public
1097
- * @deprecated Use {@link ValidationServiceInterface.setSubmitted},
1098
- * {@link ValidationServiceInterface.setTouched},
1099
- * {@link ValidationServiceInterface.setError},
1100
- * {@link ValidationServiceInterface.resetState} or request a specific
1101
- * function is added if you have another use-case.
1102
- * @param element - Element instance or id
1103
- * @param validationState - The state to be set
1104
- */
1105
- setState(element: string | Element | null, validationState: ValidationState): void;
1106
- /**
1107
- * Set `submitted` flag on the given Element.
1108
- *
1109
- * If passed element is not a validatable element the state of all
1110
- * validatable children is updated instead.
1111
- *
1112
- * @public
1113
- * @param element - Element instance or id.
1114
- */
1115
- setSubmitted(element: string | Element | null): void;
1116
- /**
1117
- * Set `touched` flag on the given Element.
1118
- *
1119
- * If passed element is not a validatable element the state of all
1120
- * validatable children is updated instead.
1121
- *
1122
- * @public
1123
- * @param element - Element instance or id.
1124
- */
1125
- setTouched(element: string | Element | null): void;
1126
- /**
1127
- * Set element as invalid with the given strnig as error message.
1128
- *
1129
- * @public
1130
- * @param element - Element instance or id.
1131
- * @param message - Error message to present.
1132
- */
1133
- setError(element: string | Element | null, message: string): void;
1134
- /**
1135
- * Reset validation status for given element
1136
- * If passed element is a not a validatable element, the state of all validatable
1137
- * children is updated instead.
1138
- *
1139
- * @param element - Element instance or id
1140
- */
1141
- resetState(element: string | Element | null): void;
1142
- /**
1143
- * Update validation status of given element.
1144
- *
1145
- * @public
1146
- * @param element - Element instance or id. Element must be attached to `document`.
1147
- */
1148
- validateElement(element: string | Element | null): Promise<ValidationResult>;
1149
- /**
1150
- * Validate all validatable descendants of given element.
1151
- *
1152
- * @public
1153
- * @param root - The top element to validate.
1154
- */
1155
- validateAllElements(root: string | Element): Promise<void>;
1156
- /**
1157
- * Clears all validation states.
1158
- */
1159
- clearAllStates(): void;
1160
- /**
1161
- * Gets a registered validator by its name, i.e., {@link Validator.name}.
1162
- *
1163
- * @public
1164
- * @param name - The name of the validator to retrieve.
1165
- * @returns The registered validator with the given name.
1166
- * @throws Error if no validator has been registered by the provided name.
1167
- */
1168
- getValidatorByName<TConfig = ValidatorConfig>(name: ValidatorName): Validator<TConfig>;
1169
- }
1170
-
1171
- /**
1172
- * Describes the initial state of the validator.
1173
- * @see {@link ValidationServiceInterface} setState
1174
- *
1175
- * @public
1176
- */
1177
- export declare interface ValidationState {
1178
- touched?: boolean;
1179
- submitted?: boolean;
1180
- serverError?: string;
1181
- }
1182
-
1183
- /**
1184
- * Describes an input validator.
1185
- *
1186
- * @public
1187
- */
1188
- export declare interface Validator<TConfig = ValidatorConfig> {
1189
- /**
1190
- * The name of the validator.
1191
- */
1192
- name: ValidatorName;
1193
- /**
1194
- * Validation method
1195
- */
1196
- validation(value: string, element: ValidatableHTMLElement, config: Partial<TConfig>): boolean;
1197
- /**
1198
- * Optional instant validation
1199
- */
1200
- instant?: boolean;
1201
- }
1202
-
1203
- /**
1204
- * Describes the configuration of a validator.
1205
- *
1206
- * @public
1207
- */
1208
- export declare type ValidatorConfig = Record<string, string | number | boolean | string[] | unknown[]> & ValidatorOptions;
1209
-
1210
- /**
1211
- * Describes the configuration of several validators,
1212
- * e.g `{ 'maxLength': { 'length: 13 }, 'minLength' { 'length: 12 }}`
1213
- *
1214
- * @public
1215
- */
1216
- export declare type ValidatorConfigs = Record<ValidatorName | string, ValidatorConfig | undefined>;
1217
-
1218
- /**
1219
- * Type for validator name, i.e. keys in inputValidators.
87
+ * // value is now guaranteed to be non-null
88
+ * ```
1220
89
  *
1221
90
  * @public
1222
- */
1223
- export declare type ValidatorName = string;
1224
-
1225
- /**
1226
- * @public
1227
- */
1228
- export declare interface ValidatorOptions {
1229
- /**
1230
- * Custom error message.
1231
- */
1232
- errorMessage?: string;
1233
- /**
1234
- * If the validator should validate on each change.
1235
- */
1236
- instant?: boolean;
1237
- /**
1238
- * If the validator should validate/run.
91
+ * @since v6.15.0
92
+ * @param value - the value asserted to be set.
93
+ * @param message - an optional exception message to use if the check fails.
94
+ * @throws {@link MissingValueError} if value is not set.
1239
95
  */
1240
- enabled?: boolean;
1241
- }
1242
-
1243
- /**
1244
- * @public
1245
- */
1246
- export declare function validChecksum(value: string): boolean;
1247
-
1248
- /**
1249
- * Describes the event that is dispatched by the validator.
1250
- *
1251
- * @public
1252
- */
1253
- export declare interface ValidityEvent {
1254
- target: ValidatableHTMLElement;
1255
- elementId: string;
1256
- isValid: boolean;
1257
- validationMessage: string;
1258
- validityMode: ValidityMode;
1259
- nativeEvent: ValidityNativeEvent;
1260
- }
1261
-
1262
- /**
1263
- * @public
1264
- */
1265
- export declare type ValidityMode = "INITIAL" | "ERROR" | "VALID";
1266
-
1267
- /**
1268
- * @public
1269
- */
1270
- export declare type ValidityNativeEvent = "input" | "change" | "blur" | "validate";
1271
-
1272
- /**
1273
- * @public
1274
- */
1275
- export declare function validLimit(limit: unknown): string;
1276
-
1277
- /**
1278
- * Defer execution of passed function to allow screen reader to update.
1279
- * Used if screen reader has not been updated with changed or added
1280
- * aria attributes before interaction.
1281
- *
1282
- * See issue:
1283
- * https://github.com/nvaccess/nvda/issues/12738
1284
- *
1285
- * @public
1286
- */
1287
- export declare function waitForScreenReader<TReturn = void>(callback: () => TReturn, delay?: number): Promise<TReturn>;
1288
-
1289
- export { }
96
+ export declare function assertSet<T>(value: T | undefined | null, message?: string): asserts value is T;
97
+
98
+ /**
99
+ * List of all available builtin validators.
100
+ *
101
+ * @public
102
+ */
103
+ export declare const availableValidators: Validator[];
104
+
105
+ /**
106
+ * A string with 3-16 digits, for example "0123456789"
107
+ *
108
+ * @public
109
+ */
110
+ export declare type BankAccountNumberString = string;
111
+
112
+ /**
113
+ * A string with 7-8 digits separated by hyphen, for example "999-9996"
114
+ *
115
+ * @public
116
+ */
117
+ export declare type BankgiroString = string;
118
+
119
+ /**
120
+ * @public
121
+ */
122
+ export declare interface BlacklistValidatorConfig extends ValidatorOptions {
123
+ values: string | string[] | number | number[];
124
+ }
125
+
126
+ /**
127
+ * A string of 4-5 digits where last digit may be separated by hyphen, for
128
+ * example "5678-1"
129
+ *
130
+ * @public
131
+ */
132
+ export declare type ClearingnumberString = string;
133
+
134
+ /**
135
+ * @public
136
+ */
137
+ export declare const configLogic: FKUIConfigLogic;
138
+
139
+ /**
140
+ * @public
141
+ */
142
+ export declare interface CookieOptions {
143
+ name: string;
144
+ value: string;
145
+ keepAnyExistingCookie?: boolean;
146
+ /** `max-age` parameter, default: 12h */
147
+ timeLimitSeconds?: number;
148
+ }
149
+
150
+ /**
151
+ * A string in format YYYY-MM-DD, for example 2021-02-03
152
+ *
153
+ * @public
154
+ */
155
+ export declare type DateString = string;
156
+
157
+ /**
158
+ * Executes a function when it stops being invoked for n seconds. Usually used together with resize,
159
+ * scroll and keyup/keydown-events to improve application's performance.
160
+ *
161
+ * Example:
162
+ *
163
+ * ```
164
+ * window.addEventListener(
165
+ * 'resize',
166
+ * debounce(computationalHeavyFunction, 1000),
167
+ * );
168
+ * ```
169
+ *
170
+ * This will call the `computationalHeavyFunction` once if the resize-event hasn't been sent for 1000 ms.
171
+ *
172
+ * Example with immediate-flag:
173
+ *
174
+ * ```
175
+ * window.addEventListener(
176
+ * 'resize',
177
+ * debounce(computationalHeavyFunction, 1000, true),
178
+ * );
179
+ * ```
180
+ *
181
+ * This will call the `computationalHeavyFunction` once BEFORE the resize-event has finished,
182
+ * and thereafter will not be able to be called again until the timeout has finished
183
+ *
184
+ * @public
185
+ * @param func - Function to be debounced.
186
+ * @param delay - Function execution threshold in milliseconds.
187
+ * @param immediate - Whether the function should be called at the beginning of the delay (Before the timeout) instead of the end.
188
+ * Default is false.
189
+ */
190
+ export declare function debounce<TThis, TArgs extends unknown[], TReturn>(this: TThis, func: (this: TThis, ...args: TArgs) => TReturn, delay: number, immediate?: boolean): (...args: TArgs) => void;
191
+
192
+ /**
193
+ * @public
194
+ */
195
+ export declare interface DecimalValidatorConfig extends ValidatorOptions {
196
+ minDecimals: number;
197
+ maxDecimals: number;
198
+ }
199
+
200
+ /**
201
+ * Decorates an original error with more information while
202
+ * keeping the original intact.
203
+ *
204
+ * @public
205
+ */
206
+ export declare class DecoratedError extends Error {
207
+ cause: Error;
208
+ constructor(message: string, cause: Error);
209
+ /**
210
+ * Get the direct cause of this error, the one that triggered
211
+ * this error.
212
+ */
213
+ getCause(): Error;
214
+ /**
215
+ * Get the root cause of this error, the first error that occured.
216
+ */
217
+ getRootCause(): Error;
218
+ }
219
+
220
+ /**
221
+ * Perform a deep clone of the given value.
222
+ *
223
+ * This function supports cloning:
224
+ *
225
+ * - Primitive types such as booleans, numbers and strings
226
+ * - Arrays and objects
227
+ * - Classes
228
+ * - `Date`,
229
+ * - `Map`,
230
+ * - `RegExp`
231
+ * - `Set`
232
+ * - `Symbol`
233
+ *
234
+ * The following values are NOT cloned:
235
+ *
236
+ * - `Error` (and subclasses) - Cloned value will reference the same Error instance.
237
+ * - DOM `Node` (and subclasses) - Cloned value will return the same DOM reference.
238
+ * - `Function` (and arrow functions) - Cloned value will be an empty object `{}`
239
+ *
240
+ * @public
241
+ * @param value - The value to recursively clone.
242
+ * @returns Returns the deep cloned value.
243
+ */
244
+ export declare function deepClone<T>(value: T): T;
245
+
246
+ /**
247
+ * @public
248
+ */
249
+ export declare function deleteCookie(name: string): void;
250
+
251
+ /**
252
+ * Compares the position of the given node against another node in any document.
253
+ *
254
+ * Unset elements (e.g. `null`) are undefined behaviour but the current
255
+ * non-contractural behaviour is to put them at the end of the sorted
256
+ * array. The caller should ensure those elements are removed before sorting.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * const sorted = listOfElements.sort(documentOrderComparator);
261
+ * ```
262
+ *
263
+ * @public
264
+ */
265
+ export declare function documentOrderComparator<T extends Node>(a?: T | null, b?: T | null): number;
266
+
267
+ declare namespace DomUtils {
268
+ export {
269
+ addFocusListener,
270
+ documentOrderComparator,
271
+ focus_2 as focus,
272
+ isFocusable,
273
+ isTabbable,
274
+ findTabbableElements,
275
+ focusFirst,
276
+ focusLast,
277
+ restoreFocus,
278
+ saveFocus,
279
+ FocusOptions_2 as FocusOptions,
280
+ popFocus,
281
+ pushFocus,
282
+ StackHandle,
283
+ handleTab,
284
+ isValidatableFormElement,
285
+ isVisible,
286
+ isVisibleInViewport,
287
+ removeFocusListener,
288
+ scrollTo_2 as scrollTo,
289
+ ScrollToOptions_2 as ScrollToOptions
290
+ }
291
+ }
292
+ export { DomUtils }
293
+
294
+ /**
295
+ * @public
296
+ */
297
+ export declare const ElementIdService: ElementIdServiceInterface;
298
+
299
+ /**
300
+ * @public
301
+ */
302
+ export declare interface ElementIdServiceInterface {
303
+ /**
304
+ * Returns an element id in the following format: `fkui-vue-element-<elementId>`.
305
+ */
306
+ generateElementId(prefix?: string): string;
307
+ /**
308
+ * Resets the internal state.
309
+ */
310
+ reset(): void;
311
+ }
312
+
313
+ /**
314
+ * @public
315
+ */
316
+ export declare interface ElementValidatorsReference {
317
+ validators: Validator[];
318
+ validatorConfigs: ValidatorConfigs;
319
+ baseValidatorConfigs?: ValidatorConfigs;
320
+ element: ValidatableHTMLElement;
321
+ instant: boolean;
322
+ }
323
+
324
+ /**
325
+ * @public
326
+ */
327
+ export declare interface EmailValidatorConfig extends ValidatorOptions {
328
+ maxLength: number;
329
+ }
330
+
331
+ /**
332
+ * Assert that a value is set and throw a {@link MissingValueError} if it is not,
333
+ * i.e., both null and undefined values will throw an error. This can be nice to
334
+ * use when transforming data between view model and rest api model.
335
+ *
336
+ * @public
337
+ * @param value - the value asserted to be set.
338
+ * @param message - an optional exception message to use if the check fails.
339
+ * @returns the value unambiguously defined.
340
+ * @throws {@link MissingValueError} if value is not set.
341
+ */
342
+ export declare function ensureSet<T>(value: T | undefined | null, message?: string): T | never;
343
+
344
+ /**
345
+ * @public
346
+ */
347
+ export declare function findCookie(name: string): string | undefined;
348
+
349
+ /**
350
+ * Find all visible and tabbable elements.
351
+ *
352
+ * @public
353
+ * @param root - Element or document to find tabbable elements in.
354
+ * @returns List of matching elements
355
+ */
356
+ export declare function findTabbableElements(root: HTMLElement | Document): HTMLElement[];
357
+
358
+ /**
359
+ * Configuration parameters specific to FKUI Logic
360
+ *
361
+ * @public
362
+ */
363
+ export declare interface FKUIConfigLogic {
364
+ production: boolean;
365
+ }
366
+
367
+ /**
368
+ * Takes an optionally nested textobject structure and convert to a flat
369
+ * structure. Nested keys are joined with a dot ".". Deep nesting is supported.
370
+ *
371
+ * Given the following:
372
+ * ```
373
+ * {
374
+ * "foo": {
375
+ * "bar": "text"
376
+ * }
377
+ * }
378
+ * ```
379
+ *
380
+ * It would produce the following output:
381
+ * ```
382
+ * {
383
+ * "foo.bar": "text"
384
+ * }
385
+ * ```
386
+ *
387
+ * If the src object is already flat the output will be the same.
388
+ *
389
+ * @public
390
+ * @param src - Source data
391
+ * @param destination - Destination to write temporary result to.
392
+ * @param prefix - If set this is prefixed to all keys.
393
+ */
394
+ export declare function flatten(src: NestedStringRecord, destination?: Record<string, string>, prefix?: string): Record<string, string>;
395
+
396
+ /**
397
+ * Give focus to a given element.
398
+ *
399
+ * For convenience it will ignore `null` and `undefined` as element parameter.
400
+ *
401
+ * If in a Vue context, please refer to the `focus` method included in `@fkui/vue`.
402
+ *
403
+ * @public
404
+ * @param element - Element to focus.
405
+ * @param options - Focus options. If you pass boolean `true` or `false` it sets the `force` option.
406
+ */
407
+ declare function focus_2(element: Element | null | undefined, options?: boolean | FocusOptions_2): void;
408
+ export { focus_2 as focus }
409
+
410
+ /**
411
+ * Focus first focusable element among given root element's hierarchy.
412
+ *
413
+ * @public
414
+ * @param rootElement - Root element.
415
+ */
416
+ export declare function focusFirst(rootElement: HTMLElement): void;
417
+
418
+ /**
419
+ * Focus last focusable element among given root element's hierarchy.
420
+ *
421
+ * @public
422
+ * @param rootElement - Root element.
423
+ */
424
+ export declare function focusLast(rootElement: HTMLElement): void;
425
+
426
+ /**
427
+ * Options for {@link focus}.
428
+ *
429
+ * @public
430
+ */
431
+ declare interface FocusOptions_2 {
432
+ /**
433
+ * If set to `true` `tabindex="-1"` will be added as needed so any element
434
+ * can be focused.
435
+ */
436
+ force?: boolean;
437
+ /**
438
+ * By default the element is scrolled into view. Set this to `true` to prevent this behavior.
439
+ *
440
+ * See full description of [`preventScroll` at
441
+ * MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#parameters)
442
+ */
443
+ preventScroll?: boolean;
444
+ /**
445
+ * By default the element is scrolled into view centered vertically. Set this to `true` to
446
+ * scroll such that the elements top is at the top of the viewport.
447
+ *
448
+ * It will utilize the `scrollIntoView` function, see full description of [`scrollIntoView` at
449
+ * MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
450
+ */
451
+ scrollToTop?: boolean;
452
+ }
453
+ export { FocusOptions_2 as FocusOptions }
454
+
455
+ /**
456
+ * @public
457
+ */
458
+ export declare function formatClearingNumberForBackend(value: ClearingnumberString): string | undefined;
459
+
460
+ /**
461
+ * Format number with thousand separator and use comma as decimal separator.
462
+ *
463
+ * @public
464
+ */
465
+ export declare function formatNumber(value: number | string | undefined | null, decimals?: number): string | undefined;
466
+
467
+ /**
468
+ * @public
469
+ */
470
+ export declare function formatPercent(modelValue: number | string | undefined | null, decimals?: number): string | undefined;
471
+
472
+ /**
473
+ * Formats personnummer to a 10-digit string.
474
+ *
475
+ * @public
476
+ */
477
+ export declare function formatPersonnummer(value: PersonnummerString | null | undefined): string | undefined;
478
+
479
+ /**
480
+ * Formats personnummer to a 8-digit date.
481
+ *
482
+ * @public
483
+ */
484
+ export declare function formatPersonnummerToDate(value: PersonnummerString | undefined): FDate | undefined;
485
+
486
+ /**
487
+ * @public
488
+ */
489
+ export declare function formatPostalCode(value: string | undefined | null): string | undefined;
490
+
491
+ /**
492
+ * @public
493
+ */
494
+ export declare function getErrorMessages(): Record<string, string>;
495
+
496
+ /**
497
+ * Handle tab focus between given containers focusable elements
498
+ *
499
+ * @public
500
+ * @param event - tab KeyboardEvent
501
+ * @param container - containing focusable elements
502
+ */
503
+ export declare function handleTab(event: KeyboardEvent, container: HTMLElement): void;
504
+
505
+ /**
506
+ * @public
507
+ */
508
+ export declare interface InvalidDatesValidatorConfig extends ValidatorOptions {
509
+ dates: string[];
510
+ }
511
+
512
+ /**
513
+ * @public
514
+ */
515
+ export declare interface InvalidWeekdaysValidatorConfig extends ValidatorOptions {
516
+ days: number[];
517
+ }
518
+
519
+ /**
520
+ * Determine if a value is empty.
521
+ *
522
+ * A value is considered empty if it is:
523
+ *
524
+ * - `undefined`
525
+ * - `null`
526
+ * - empty string `""`.
527
+ *
528
+ * @public
529
+ * @param value - value to check if it is empty
530
+ */
531
+ export declare function isEmpty(value: string | undefined | null): value is "" | undefined | null;
532
+
533
+ /**
534
+ * Check if an element is focusable (visible and either interactive or with
535
+ * tabindex). This includes programatically focusable elements.
536
+ *
537
+ * @public
538
+ * @param element - An `Element` for which to test focusability.
539
+ * @returns `true` if the element is focusable, otherwise `false`.
540
+ */
541
+ export declare function isFocusable(element: Element): boolean;
542
+
543
+ /**
544
+ * @public
545
+ */
546
+ export declare function isInvalidDatesConfig(value: Partial<InvalidDatesValidatorConfig>): value is InvalidDatesValidatorConfig;
547
+
548
+ /**
549
+ * @public
550
+ */
551
+ export declare function isInvalidWeekdaysConfig(value: Partial<InvalidWeekdaysValidatorConfig>): value is InvalidWeekdaysValidatorConfig;
552
+
553
+ /* Excluded from this release type: isRadiobuttonOrCheckbox */
554
+
555
+ /**
556
+ * Determine if a value is set. If it is undefined or null, this function
557
+ * returns false.
558
+ *
559
+ * @public
560
+ * @param value - the value for which to determine if it is set
561
+ */
562
+ export declare function isSet<T>(value: T | undefined | null): value is T;
563
+
564
+ /**
565
+ * @public
566
+ */
567
+ export declare function isString(value: string | unknown): boolean;
568
+
569
+ /**
570
+ * Check if an element is tabbable (visible and either interactive or
571
+ * non-negative tabindex). This does not include programatically focusable
572
+ * elements.
573
+ *
574
+ * @public
575
+ * @param element - An `Element` for which to test focusability.
576
+ * @returns `true` if the element is focusable, otherwise `false`.
577
+ */
578
+ export declare function isTabbable(element: Element): boolean;
579
+
580
+ /**
581
+ * Check if element is a form element
582
+ *
583
+ * Also see {@link isValidatableHTMLElement} for a similar function but
584
+ * including HTMLFieldSetElement.
585
+ *
586
+ * @public
587
+ * @param element - Element to test
588
+ */
589
+ export declare function isValidatableFormElement(element: Element): element is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
590
+
591
+ /**
592
+ * Returns true if given element is a validatable element.
593
+ *
594
+ * Also see {@link isValidatableFormElement} for a similar function but
595
+ * excluding HTMLFieldSetElement.
596
+ *
597
+ * @public
598
+ * @param element - Element to test
599
+ */
600
+ export declare function isValidatableHTMLElement(element: Element): element is ValidatableHTMLElement;
601
+
602
+ /**
603
+ * Check if an element is visible in the dom
604
+ *
605
+ * @public
606
+ */
607
+ export declare function isVisible(element: HTMLElement): boolean;
608
+
609
+ /**
610
+ * Check if an element is fully visible in the viewport
611
+ *
612
+ * @public
613
+ */
614
+ export declare function isVisibleInViewport(element: Element): boolean;
615
+
616
+ /**
617
+ * @public
618
+ */
619
+ export declare interface MatchesValidatorConfig extends ValidatorOptions {
620
+ /** Identifier of another input field */
621
+ id?: string;
622
+ }
623
+
624
+ /**
625
+ * @public
626
+ */
627
+ export declare interface MaxDateValidatorConfig extends ValidatorOptions {
628
+ limit: string;
629
+ }
630
+
631
+ /**
632
+ * @public
633
+ */
634
+ export declare interface MaxLengthValidatorConfig extends ValidatorOptions {
635
+ length: number;
636
+ }
637
+
638
+ /**
639
+ * @public
640
+ */
641
+ export declare interface MinDateValidatorConfig extends ValidatorOptions {
642
+ limit: string;
643
+ }
644
+
645
+ /**
646
+ * @public
647
+ */
648
+ export declare interface MinLengthValidatorConfig extends ValidatorOptions {
649
+ length: number;
650
+ }
651
+
652
+ /**
653
+ * An error indicating that a mandatory value is not set.
654
+ *
655
+ * @public
656
+ */
657
+ export declare class MissingValueError extends Error {
658
+ constructor(message?: string);
659
+ }
660
+
661
+ /**
662
+ * @public
663
+ */
664
+ export declare interface NestedStringRecord {
665
+ [key: string]: string | NestedStringRecord;
666
+ }
667
+
668
+ /* Excluded from this release type: normalizeDateFormat */
669
+
670
+ /**
671
+ * A string with 6 digits followed by additional 4 digits separated by a hyphen,
672
+ * for example "999999-9999".
673
+ *
674
+ * @public
675
+ */
676
+ export declare type OrganisationsnummerString = string;
677
+
678
+ /**
679
+ * @public
680
+ */
681
+ export declare function parseBankAccountNumber(value: string): BankAccountNumberString | undefined;
682
+
683
+ /**
684
+ * @public
685
+ */
686
+ export declare function parseBankgiro(value: string): BankgiroString | undefined;
687
+
688
+ /**
689
+ * @public
690
+ */
691
+ export declare function parseClearingNumber(value: string): ClearingnumberString | undefined;
692
+
693
+ /**
694
+ * @public
695
+ */
696
+ export declare function parseDate(value: string): DateString | undefined;
697
+
698
+ /**
699
+ * @public
700
+ */
701
+ export declare function parseNumber(value: string): number | undefined;
702
+
703
+ /**
704
+ * @public
705
+ */
706
+ export declare function parseOrganisationsnummer(value: string): OrganisationsnummerString | undefined;
707
+
708
+ /**
709
+ * @public
710
+ */
711
+ export declare function parsePercent(viewValue: string): number;
712
+
713
+ /**
714
+ * Parses 10- and 12-digit personnummers.
715
+ *
716
+ * @public
717
+ */
718
+ export declare function parsePersonnummer(value: string | null | undefined, now?: FDate): PersonnummerString | undefined;
719
+
720
+ /**
721
+ * Parses 10- and 12-digit personnummers with Luhn validation.
722
+ *
723
+ * @public
724
+ */
725
+ export declare function parsePersonnummerLuhn(value: string | null | undefined): PersonnummerString | undefined;
726
+
727
+ /**
728
+ * @public
729
+ */
730
+ export declare function parsePlusgiro(value: string): PlusgiroString | undefined;
731
+
732
+ /**
733
+ * @public
734
+ */
735
+ export declare function parsePostalCode(value: string): PostalCodeString | undefined;
736
+
737
+ /**
738
+ * Describes the event that is dispatched during input if no instant validation.
739
+ *
740
+ * @public
741
+ */
742
+ export declare interface PendingValidityEvent {
743
+ }
744
+
745
+ /**
746
+ * This feature can be used by creating a new file with something like:
747
+ *
748
+ * ```
749
+ * export const MyCustomPersistenceService = new PersistenceService<MyCustomApplicationModel>();
750
+ * ```
751
+ *
752
+ * There is also a simplified version in {@link SimplePersistenceService}.
753
+ *
754
+ * @public
755
+ */
756
+ export declare class PersistenceService<T> implements PersistenceServiceInterface<T> {
757
+ private cache;
758
+ constructor();
759
+ set(key: string, value: T): void;
760
+ get(key: string): T;
761
+ find(key: string): T | undefined;
762
+ remove(key: string): void;
763
+ /* Excluded from this release type: isSessionPresent */
764
+ }
765
+
766
+ /**
767
+ * @public
768
+ */
769
+ export declare interface PersistenceServiceInterface<T> {
770
+ set(key: string, value: T): void;
771
+ get(key: string): T;
772
+ find(key: string): T | undefined;
773
+ remove(key: string): void;
774
+ }
775
+
776
+ /**
777
+ * A 12-digit string including hyphen separator, for example "99999999-9999"
778
+ *
779
+ * @public
780
+ */
781
+ export declare type PersonnummerString = string;
782
+
783
+ /**
784
+ * A string containing of digits separated by spaces and hyphen, see spec-file for
785
+ * examples
786
+ *
787
+ * @public
788
+ */
789
+ export declare type PlusgiroString = string;
790
+
791
+ /**
792
+ * Restore the focus on the last element from the stack
793
+ *
794
+ * @public
795
+ * @throws Error when pop is called on an empty focus stack
796
+ * @throws Error when pop is called without a valid StackHandle
797
+ */
798
+ export declare function popFocus(handle: StackHandle): void;
799
+
800
+ /**
801
+ * A 5-digit string with space separator, for example "932 22"
802
+ *
803
+ * @public
804
+ */
805
+ export declare type PostalCodeString = string;
806
+
807
+ /**
808
+ * Save current active element focus on the stack and set focus on element
809
+ *
810
+ * @public
811
+ * @param element - The element to set focus on
812
+ */
813
+ export declare function pushFocus(element?: Element | null): StackHandle;
814
+
815
+ /**
816
+ * Remove listener for each item in the list of elements
817
+ *
818
+ * @public
819
+ */
820
+ export declare function removeFocusListener(elements: HTMLElement[], listener: ((event: Event) => unknown) | (() => unknown)): void;
821
+
822
+ /**
823
+ * Restore focus to a previous element. Use this in combination with {@link saveFocus}
824
+ *
825
+ * @public
826
+ */
827
+ export declare function restoreFocus(): void;
828
+
829
+ /**
830
+ * Save a DOM reference to the active element for later use.
831
+ *
832
+ * @public
833
+ * @param document - Document element
834
+ */
835
+ export declare function saveFocus(document: Document): void;
836
+
837
+ /**
838
+ * Default delay in milliseconds for {@link waitForScreenReader}
839
+ *
840
+ * @public
841
+ */
842
+ export declare const SCREEN_READER_DELAY = 100;
843
+
844
+ /**
845
+ * Scroll to element with scroll options.
846
+ *
847
+ * @public
848
+ * @param element - Element to scroll into view
849
+ * @param options - scroll options (duration, offset)
850
+ */
851
+ declare function scrollTo_2(element: Element, options: ScrollToOptions_2): Promise<void>;
852
+
853
+ /**
854
+ * Scroll to element
855
+ *
856
+ * @public
857
+ * @param element - Element to scroll into view
858
+ * @param offset - Set vertical offset, default 0px
859
+ */
860
+ declare function scrollTo_2(element: Element, offset?: number): Promise<void>;
861
+ export { scrollTo_2 as scrollTo }
862
+
863
+ /**
864
+ * Optional arguments for scrollTo.
865
+ *
866
+ * @public
867
+ * @param duration - Duration in milliseconds
868
+ * @param offset - Set vertical offset, default 0px
869
+ */
870
+ declare interface ScrollToOptions_2 {
871
+ duration?: number;
872
+ offset?: number;
873
+ }
874
+ export { ScrollToOptions_2 as ScrollToOptions }
875
+
876
+ /**
877
+ * @public
878
+ */
879
+ export declare function setCookie(options: CookieOptions): void;
880
+
881
+ /**
882
+ * This feature can be used by creating a new file with something like:
883
+ *
884
+ * ```ts
885
+ * export const MyAwesomePersistenceService = new SimplePersistenceService<MyAwesomeModel>("my-awesome-key");
886
+ * ```
887
+ *
888
+ * There is also a more advanced version in {@link PersistenceService}.
889
+ *
890
+ * @public
891
+ */
892
+ export declare class SimplePersistenceService<T> implements SimplePersistenceServiceInterface<T> {
893
+ private persistenceService;
894
+ private key;
895
+ constructor(key: string);
896
+ set(value: T): void;
897
+ get(): T;
898
+ find(): T | undefined;
899
+ remove(): void;
900
+ }
901
+
902
+ /**
903
+ * @public
904
+ */
905
+ export declare interface SimplePersistenceServiceInterface<T> {
906
+ set(value: T): void;
907
+ get(): T;
908
+ find(): T | undefined;
909
+ remove(): void;
910
+ }
911
+
912
+ /**
913
+ * @public
914
+ */
915
+ export declare interface StackHandle {
916
+ [sym]: number;
917
+ }
918
+
919
+ /** @public */
920
+ export declare function stripNull<T>(obj: T): T;
921
+
922
+ /** @public */
923
+ export declare function stripNull(obj: null): undefined;
924
+
925
+ /** @public */
926
+ export declare function stripNull(obj: number): number;
927
+
928
+ /** @public */
929
+ export declare function stripNull(obj: string): string;
930
+
931
+ /**
932
+ * Strips all whitespace from the text (not only leading and trailing)
933
+ *
934
+ * @public
935
+ * @param text - Text to strip whitespace from.
936
+ * @returns Text with whitespace stripped.
937
+ */
938
+ export declare function stripWhitespace(text: string): string;
939
+
940
+ declare const sym: unique symbol;
941
+
942
+ /**
943
+ * Takes a string containing only numbers and checks that the checksum is correct
944
+ * according to the Luhn Algorithm.
945
+ *
946
+ * @public
947
+ * @param inputString - A string containing only numbers
948
+ */
949
+ export declare function testLuhnChecksum(inputString: string): boolean;
950
+
951
+ /**
952
+ * @public
953
+ */
954
+ export declare type TranslateFunction = (key: string, defaultValueOrArgs?: string | Record<string, unknown>, args?: Record<string, unknown>) => string;
955
+
956
+ /**
957
+ * @public
958
+ */
959
+ export declare interface TranslationProviderInterface {
960
+ readonly currentLanguage: string;
961
+ changeLanguage(language: string): Promise<void> | Promise<TranslateFunction>;
962
+ translate(key: string, defaultValueOrArgs?: string | Record<string, unknown>, args?: Record<string, unknown>): string;
963
+ }
964
+
965
+ /**
966
+ * @public
967
+ */
968
+ export declare const TranslationService: TranslationServiceInterface;
969
+
970
+ /**
971
+ * @public
972
+ */
973
+ export declare interface TranslationServiceInterface {
974
+ provider: TranslationProviderInterface;
975
+ changeProvider(provider: TranslationProviderInterface): void;
976
+ }
977
+
978
+ /**
979
+ * @public
980
+ */
981
+ export declare type ValidatableHTMLElement = HTMLDivElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLFieldSetElement;
982
+
983
+ /**
984
+ * Event used to trigger validation.
985
+ *
986
+ * @public
987
+ */
988
+ export declare interface ValidateEvent {
989
+ }
990
+
991
+ /**
992
+ * Emitted when the validation configuration is updated and includes the current configuration.
993
+ *
994
+ * @public
995
+ */
996
+ export declare interface ValidationConfigUpdateDetail {
997
+ /** Current configuration */
998
+ config: ValidatorConfigs;
999
+ }
1000
+
1001
+ /**
1002
+ * Builder to create validation error message map.
1003
+ *
1004
+ * @public
1005
+ */
1006
+ export declare class ValidationErrorMessageBuilder {
1007
+ /**
1008
+ * Create a new builder.
1009
+ */
1010
+ static create(): ValidationErrorMessageBuilder;
1011
+ private validatorMessageMap;
1012
+ private constructor();
1013
+ /**
1014
+ * Map the validator name message towards an error message.
1015
+ *
1016
+ * @param validatorName - the name of the validator
1017
+ * @param message - the error message
1018
+ * @param elementType - limit to a specific element type
1019
+ */
1020
+ map(validatorName: ValidatorName, message: string, elementType?: "text" | "radio" | "checkbox" | "select" | "textarea"): this;
1021
+ /**
1022
+ * Validators that coexists on same element can have a combined message,
1023
+ * i.e. if a element have the `required` and the `personnummer` validator
1024
+ * the required error message could be combined with
1025
+ * `mapCombined('required','personnummer', 'You must enter a social security number!');`.
1026
+ *
1027
+ * @param validatorName - the name of the validator
1028
+ * @param dependentValidatorName - the name of the combined validator
1029
+ * @param message - the error message
1030
+ * @param elementType - limit to a specific element type
1031
+ */
1032
+ mapCombined(validatorName: ValidatorName, dependentValidatorName: ValidatorName, message: string, elementType?: "text" | "radio" | "checkbox" | "select" | "textarea"): this;
1033
+ /**
1034
+ * Build the translation map.
1035
+ *
1036
+ * @returns the created map.
1037
+ */
1038
+ build(): Record<string, string>;
1039
+ }
1040
+
1041
+ /**
1042
+ * Result of {@link ValidationServiceInterface.validateElement}.
1043
+ *
1044
+ * @public
1045
+ */
1046
+ export declare interface ValidationResult {
1047
+ /**
1048
+ * `true` if the element is valid and have no validation errors.
1049
+ */
1050
+ isValid: boolean;
1051
+ /**
1052
+ * `true` if the field has been touched, i.e. the user has interacted with
1053
+ * it.
1054
+ */
1055
+ isTouched: boolean;
1056
+ /**
1057
+ * `true` if the field has been submitted (or attempted to be submitted)
1058
+ */
1059
+ isSubmitted: boolean;
1060
+ /**
1061
+ * Validation error message.
1062
+ *
1063
+ * `null` if no validation error is present.
1064
+ */
1065
+ error: string | null;
1066
+ }
1067
+
1068
+ /**
1069
+ * @public
1070
+ */
1071
+ export declare const ValidationService: ValidationServiceInterface;
1072
+
1073
+ /**
1074
+ * @public
1075
+ */
1076
+ export declare interface ValidationServiceInterface {
1077
+ /* Excluded from this release type: getElementsAndValidators */
1078
+ /**
1079
+ * Whether any of the fields are touched
1080
+ */
1081
+ readonly isAnyTouched: boolean;
1082
+ /* Excluded from this release type: validationErrorMessages */
1083
+ /* Excluded from this release type: resolveValidityModeWhenError */
1084
+ /**
1085
+ * Check if given element(s) are valid.
1086
+ *
1087
+ * When passing multiple elements all of them must be valid. For non-input
1088
+ * elements (fieldsets, divs, etc) it checks whenever all descendants are
1089
+ * valid. Returns `true` if array is empty.
1090
+ *
1091
+ * Note: this function does not update the validity state (i.e. run
1092
+ * validators) but only checks the current state! Use
1093
+ * {@link ValidationServiceInterface.validateElement} to update state.
1094
+ *
1095
+ * @public
1096
+ * @deprecated Use {@link ValidationServiceInterface.validateElement} instead.
1097
+ * @param src - Element instance or id.
1098
+ * @param root - Element (or document) to query when looking up elements by id.
1099
+ * @returns Resolves to `true` if all given elements (or descendants) are valid. Empty array resolves to `true`.
1100
+ */
1101
+ isValid(src: string | string[] | Element | Element[] | null, root?: Document | Element): Promise<boolean>;
1102
+ /**
1103
+ * Add translations for validators.
1104
+ * New translations will be merged with existing
1105
+ * translations and overwritten if they already exists.
1106
+ * @see {@link ValidationErrorMessageBuilder}
1107
+ *
1108
+ * @public
1109
+ * @deprecated Use `setErrorMessages()`.
1110
+ * @param validationErrorMessageMap - the map with translation for validators
1111
+ */
1112
+ addValidationErrorMessages(validationErrorMessageMap: Record<ValidatorName | string, string>): void;
1113
+ /**
1114
+ * Set error messages for one or more validators.
1115
+ *
1116
+ * The mapping should contain an object with the validator descriptor as key
1117
+ * and the error message as value. A descriptor is a dot separated list of keywords:
1118
+ *
1119
+ * - One or more validator names.
1120
+ * - An input type (`text`, `radio`, `checkbox`, `select` or `textarea`).
1121
+ *
1122
+ * When multiple validator names are given the first one is the validator
1123
+ * yielding the error and any subsequent validators is used when the first
1124
+ * validator is combined with these validators (no matter if those yield an
1125
+ * error or not).
1126
+ *
1127
+ * - `required` - the error message when `required` yields an error.
1128
+ * - `required.date` - the error message when `required` yields an error on an
1129
+ * input field which also uses the `date` validator.
1130
+ * - `required.radio` - the error message when `required` yield an error on an
1131
+ * input field of type radiobutton.
1132
+ * - `required.whitelist.textarea` - the error message when `required` yield an
1133
+ * error on an textarea which also uses the `whitelist` validator.
1134
+ *
1135
+ * New translations will be merged with existing messages and overwritten if
1136
+ * they already exists. Do note that if a more specific error message
1137
+ * already exists the specific one will not be affected (e.g. setting the
1138
+ * error for `required` whould not affect `required.radio` if it exists).
1139
+ *
1140
+ * Set `clear` to `true` to reset all previous messages (overwrite instead
1141
+ * of merge).
1142
+ *
1143
+ * @see {@link ValidationErrorMessageBuilder}
1144
+ *
1145
+ * @public
1146
+ * @param messages - the map with error messages for validators
1147
+ */
1148
+ setErrorMessages(messages: Record<string, string>, options?: {
1149
+ clear?: boolean;
1150
+ }): void;
1151
+ /**
1152
+ * Clears any previous set error messages for validators (including default
1153
+ * texts)
1154
+ *
1155
+ * @public
1156
+ */
1157
+ clearErrorMessages(): void;
1158
+ /**
1159
+ * Register a validator.
1160
+ * To be used when a customer validator is needed.
1161
+ *
1162
+ * @param validator - the validator to register
1163
+ */
1164
+ registerValidator<TConfig = ValidatorConfig>(validator: Validator<TConfig>): void;
1165
+ /**
1166
+ * Remove element from ValidationService.
1167
+ *
1168
+ * @param element - Element to remove validators from.
1169
+ */
1170
+ removeValidatorsFromElement(element: ValidatableHTMLElement): void;
1171
+ /**
1172
+ * Add validators to an element.
1173
+ *
1174
+ * @param element - the element to add validator to
1175
+ * @param validatorConfigs - the defintion of validators to be addede.
1176
+ * @param isBaseConfigs - is a boolean which indicates if this configuration
1177
+ * should always lay as a base configuration even if overlaying code is
1178
+ * changing its validators.
1179
+ *
1180
+ * As an example there is FEmailTextField which sets its own EmailValidator
1181
+ * in the constructor. Then the app-code can add its own validatorsConfig on
1182
+ * top of that (example: `required: { enabled: $someValue } }`). Setting
1183
+ * isBaseConfigs to true preserves the validatorConfig set by
1184
+ * FEmailTextField as the app code changes the required validatorConfig
1185
+ * (which triggers `addValidatorsToElement()` again)
1186
+ *
1187
+ * @see {@link ValidityEvent} dispatched during blur and change
1188
+ * @see {@link PendingValidityEvent} dispatched during input
1189
+ */
1190
+ addValidatorsToElement(element: ValidatableHTMLElement, validatorConfigs: ValidatorConfigs, isBaseConfigs?: boolean): void;
1191
+ /**
1192
+ * Set or update validation state on element(s).
1193
+ *
1194
+ * Can be used to restore state after page reload, or to set all elements in
1195
+ * a subform to submitted.
1196
+ *
1197
+ * If passed element is a not a validatable element, the state of all
1198
+ * validatable children is updated instead.
1199
+ *
1200
+ * @see {@link ValidityEvent} validityMode
1201
+ *
1202
+ * @public
1203
+ * @deprecated Use {@link ValidationServiceInterface.setSubmitted},
1204
+ * {@link ValidationServiceInterface.setTouched},
1205
+ * {@link ValidationServiceInterface.setError},
1206
+ * {@link ValidationServiceInterface.resetState} or request a specific
1207
+ * function is added if you have another use-case.
1208
+ * @param element - Element instance or id
1209
+ * @param validationState - The state to be set
1210
+ */
1211
+ setState(element: string | Element | null, validationState: ValidationState): void;
1212
+ /**
1213
+ * Set `submitted` flag on the given Element.
1214
+ *
1215
+ * If passed element is not a validatable element the state of all
1216
+ * validatable children is updated instead.
1217
+ *
1218
+ * @public
1219
+ * @param element - Element instance or id.
1220
+ */
1221
+ setSubmitted(element: string | Element | null): void;
1222
+ /**
1223
+ * Set `touched` flag on the given Element.
1224
+ *
1225
+ * If passed element is not a validatable element the state of all
1226
+ * validatable children is updated instead.
1227
+ *
1228
+ * @public
1229
+ * @param element - Element instance or id.
1230
+ */
1231
+ setTouched(element: string | Element | null): void;
1232
+ /**
1233
+ * Set element as invalid with the given strnig as error message.
1234
+ *
1235
+ * @public
1236
+ * @param element - Element instance or id.
1237
+ * @param message - Error message to present.
1238
+ */
1239
+ setError(element: string | Element | null, message: string): void;
1240
+ /**
1241
+ * Reset validation status for given element
1242
+ * If passed element is a not a validatable element, the state of all validatable
1243
+ * children is updated instead.
1244
+ *
1245
+ * @param element - Element instance or id
1246
+ */
1247
+ resetState(element: string | Element | null): void;
1248
+ /**
1249
+ * Update validation status of given element.
1250
+ *
1251
+ * @public
1252
+ * @param element - Element instance or id. Element must be attached to `document`.
1253
+ */
1254
+ validateElement(element: string | Element | null): Promise<ValidationResult>;
1255
+ /**
1256
+ * Validate all validatable descendants of given element.
1257
+ *
1258
+ * @public
1259
+ * @param root - The top element to validate.
1260
+ */
1261
+ validateAllElements(root: string | Element): Promise<void>;
1262
+ /**
1263
+ * Clears all validation states.
1264
+ */
1265
+ clearAllStates(): void;
1266
+ /**
1267
+ * Gets a registered validator by its name, i.e., {@link Validator.name}.
1268
+ *
1269
+ * @public
1270
+ * @param name - The name of the validator to retrieve.
1271
+ * @returns The registered validator with the given name.
1272
+ * @throws Error if no validator has been registered by the provided name.
1273
+ */
1274
+ getValidatorByName<TConfig = ValidatorConfig>(name: ValidatorName): Validator<TConfig>;
1275
+ }
1276
+
1277
+ /**
1278
+ * Describes the initial state of the validator.
1279
+ * @see {@link ValidationServiceInterface} setState
1280
+ *
1281
+ * @public
1282
+ */
1283
+ export declare interface ValidationState {
1284
+ touched?: boolean;
1285
+ submitted?: boolean;
1286
+ serverError?: string;
1287
+ }
1288
+
1289
+ /**
1290
+ * Describes an input validator.
1291
+ *
1292
+ * @public
1293
+ */
1294
+ export declare interface Validator<TConfig = ValidatorConfig> {
1295
+ /**
1296
+ * The name of the validator.
1297
+ */
1298
+ name: ValidatorName;
1299
+ /**
1300
+ * Validation method
1301
+ */
1302
+ validation(value: string, element: ValidatableHTMLElement, config: Partial<TConfig>): boolean;
1303
+ /**
1304
+ * Optional instant validation
1305
+ */
1306
+ instant?: boolean;
1307
+ }
1308
+
1309
+ /**
1310
+ * Describes the configuration of a validator.
1311
+ *
1312
+ * @public
1313
+ */
1314
+ export declare type ValidatorConfig = Record<string, string | number | boolean | string[] | unknown[]> & ValidatorOptions;
1315
+
1316
+ /**
1317
+ * Describes the configuration of several validators,
1318
+ * e.g `{ 'maxLength': { 'length: 13 }, 'minLength' { 'length: 12 }}`
1319
+ *
1320
+ * @public
1321
+ */
1322
+ export declare type ValidatorConfigs = Record<ValidatorName | string, ValidatorConfig | undefined>;
1323
+
1324
+ /**
1325
+ * Type for validator name, i.e. keys in inputValidators.
1326
+ *
1327
+ * @public
1328
+ */
1329
+ export declare type ValidatorName = string;
1330
+
1331
+ /**
1332
+ * @public
1333
+ */
1334
+ export declare interface ValidatorOptions {
1335
+ /**
1336
+ * Custom error message.
1337
+ */
1338
+ errorMessage?: string;
1339
+ /**
1340
+ * If the validator should validate on each change.
1341
+ */
1342
+ instant?: boolean;
1343
+ /**
1344
+ * If the validator should validate/run.
1345
+ */
1346
+ enabled?: boolean;
1347
+ }
1348
+
1349
+ /**
1350
+ * @public
1351
+ */
1352
+ export declare function validChecksum(value: string): boolean;
1353
+
1354
+ /**
1355
+ * Describes the event that is dispatched by the validator.
1356
+ *
1357
+ * @public
1358
+ */
1359
+ export declare interface ValidityEvent {
1360
+ target: ValidatableHTMLElement;
1361
+ elementId: string;
1362
+ isValid: boolean;
1363
+ validationMessage: string;
1364
+ validityMode: ValidityMode;
1365
+ nativeEvent: ValidityNativeEvent;
1366
+ }
1367
+
1368
+ /**
1369
+ * @public
1370
+ */
1371
+ export declare type ValidityMode = "INITIAL" | "ERROR" | "VALID";
1372
+
1373
+ /**
1374
+ * @public
1375
+ */
1376
+ export declare type ValidityNativeEvent = "input" | "change" | "blur" | "validate";
1377
+
1378
+ /**
1379
+ * @public
1380
+ */
1381
+ export declare function validLimit(limit: unknown): string;
1382
+
1383
+ /**
1384
+ * Defer execution of passed function to allow screen reader to update.
1385
+ * Used if screen reader has not been updated with changed or added
1386
+ * aria attributes before interaction.
1387
+ *
1388
+ * See issue:
1389
+ * https://github.com/nvaccess/nvda/issues/12738
1390
+ *
1391
+ * @public
1392
+ */
1393
+ export declare function waitForScreenReader<TReturn = void>(callback: () => TReturn, delay?: number): Promise<TReturn>;
1394
+
1395
+ export { }