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