@juspay/svelte-ui-components 4.27.6 → 4.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -36
- package/dist/Animations/ModalAnimation.svelte +15 -1
- package/dist/Animations/OverlayAnimation.svelte +7 -1
- package/dist/AreaChart/AreaChart.svelte +366 -85
- package/dist/AspectRatio/AspectRatio.svelte +51 -0
- package/dist/AspectRatio/AspectRatio.svelte.d.ts +3 -0
- package/dist/AspectRatio/properties.d.ts +27 -0
- package/dist/AspectRatio/properties.js +1 -0
- package/dist/Banner/Banner.svelte +10 -4
- package/dist/Banner/properties.d.ts +8 -0
- package/dist/BarChart/BarChart.svelte +156 -49
- package/dist/Book/Book.svelte +14 -1
- package/dist/BrandLoader/BrandLoader.svelte +76 -12
- package/dist/Button/Button.svelte +56 -11
- package/dist/Calendar/Calendar.svelte +88 -61
- package/dist/Card/Card.svelte +1 -1
- package/dist/Carousel/Carousel.svelte +6 -3
- package/dist/ChatComposer/ChatComposer.svelte +54 -4
- package/dist/ChatComposer/dictationState.d.ts +15 -0
- package/dist/ChatComposer/dictationState.js +9 -0
- package/dist/ChatComposer/properties.d.ts +28 -1
- package/dist/ChatMessage/ChatMessage.svelte +27 -1
- package/dist/CheckListItem/CheckListItem.svelte +3 -3
- package/dist/Checkbox/Checkbox.svelte +84 -3
- package/dist/Checkbox/properties.d.ts +45 -13
- package/dist/ChipInput/ChipInput.svelte +70 -3
- package/dist/ChipInput/properties.d.ts +16 -0
- package/dist/Choicebox/Choicebox.svelte +156 -1
- package/dist/Choicebox/group.d.ts +63 -0
- package/dist/Choicebox/group.js +127 -0
- package/dist/Choicebox/properties.d.ts +46 -0
- package/dist/ColorPicker/ColorPicker.svelte +169 -20
- package/dist/ColorPicker/properties.d.ts +16 -0
- package/dist/Combobox/Combobox.svelte +87 -25
- package/dist/Combobox/properties.d.ts +23 -0
- package/dist/CommandMenu/CommandMenu.svelte +27 -11
- package/dist/ContextMenu/ContextMenu.svelte +31 -37
- package/dist/DateRangePicker/DateRangePicker.svelte +171 -73
- package/dist/DeltaIndicator/DeltaIndicator.svelte +3 -3
- package/dist/Draggable/Draggable.svelte +12 -7
- package/dist/DualAxisBarChart/DualAxisBarChart.svelte +11 -4
- package/dist/EmptyState/EmptyState.svelte +1 -1
- package/dist/FileDropzoneTrigger/FileDropzoneTrigger.svelte +1 -1
- package/dist/FileInput/FileInput.svelte +50 -1
- package/dist/FileInput/properties.d.ts +7 -0
- package/dist/FunnelChart/FunnelChart.svelte +40 -12
- package/dist/FunnelChart/properties.d.ts +7 -1
- package/dist/Gallery/Gallery.svelte +20 -13
- package/dist/Gallery/properties.d.ts +8 -0
- package/dist/GridItem/GridItem.svelte +31 -1
- package/dist/HITL/HITL.svelte +35 -9
- package/dist/Icon/Icon.svelte +19 -3
- package/dist/Input/Input.svelte +24 -10
- package/dist/Input/properties.d.ts +37 -1
- package/dist/InputButton/InputButton.svelte +86 -11
- package/dist/InputButton/properties.d.ts +10 -1
- package/dist/Label/Label.svelte +54 -0
- package/dist/Label/Label.svelte.d.ts +3 -0
- package/dist/Label/properties.d.ts +26 -0
- package/dist/Label/properties.js +1 -0
- package/dist/LineChart/LineChart.svelte +385 -94
- package/dist/ListItem/ListItem.svelte +121 -15
- package/dist/Loader/Loader.svelte +22 -2
- package/dist/LoadingDots/LoadingDots.svelte +21 -0
- package/dist/MediaUpload/MediaUpload.svelte +13 -3
- package/dist/Menu/Menu.svelte +56 -28
- package/dist/Modal/Modal.svelte +77 -42
- package/dist/Pagination/Pagination.svelte +9 -2
- package/dist/Phone/Phone.svelte +4 -0
- package/dist/PieChart/PieChart.svelte +282 -38
- package/dist/PieChart/properties.d.ts +9 -0
- package/dist/Pill/Pill.svelte +14 -5
- package/dist/Progress/Progress.svelte +20 -0
- package/dist/Radio/Radio.svelte +58 -1
- package/dist/Radio/properties.d.ts +23 -0
- package/dist/RatingGroup/RatingGroup.svelte +283 -0
- package/dist/RatingGroup/RatingGroup.svelte.d.ts +4 -0
- package/dist/RatingGroup/properties.d.ts +73 -0
- package/dist/RatingGroup/properties.js +1 -0
- package/dist/RelativeTime/RelativeTime.svelte +1 -1
- package/dist/SankeyChart/SankeyChart.svelte +272 -50
- package/dist/SankeyChart/properties.d.ts +9 -0
- package/dist/Scroller/Scroller.svelte +37 -2
- package/dist/Select/Select.svelte +166 -46
- package/dist/Select/properties.d.ts +7 -0
- package/dist/Separator/Separator.svelte +48 -0
- package/dist/Separator/Separator.svelte.d.ts +3 -0
- package/dist/Separator/properties.d.ts +22 -0
- package/dist/Separator/properties.js +1 -0
- package/dist/Sheet/Sheet.svelte +60 -21
- package/dist/Shimmer/Shimmer.svelte +15 -0
- package/dist/Slider/Slider.svelte +87 -6
- package/dist/Slider/properties.d.ts +26 -0
- package/dist/Snippet/Snippet.svelte +4 -0
- package/dist/Snippet/copyState.svelte.d.ts +13 -1
- package/dist/Snippet/copyState.svelte.js +27 -1
- package/dist/Snippet/properties.d.ts +7 -0
- package/dist/SoundKit/SoundKit.js +9 -8
- package/dist/SplitInput/SplitInput.svelte +68 -2
- package/dist/SplitInput/properties.d.ts +23 -0
- package/dist/StatCard/StatCard.svelte +6 -6
- package/dist/Status/Status.svelte +2 -2
- package/dist/Stepper/Step.svelte +19 -6
- package/dist/Stepper/Stepper.svelte +108 -35
- package/dist/Table/BuiltinCell.svelte +2 -2
- package/dist/Table/Table.svelte +373 -55
- package/dist/Table/properties.d.ts +134 -3
- package/dist/Tabs/Tabs.svelte +263 -65
- package/dist/Tabs/properties.d.ts +23 -0
- package/dist/TaskList/TaskList.svelte +14 -5
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte +23 -0
- package/dist/ThinkingIndicator/ThinkingIndicator.svelte +13 -5
- package/dist/Toast/Toast.svelte +27 -2
- package/dist/Toggle/Toggle.svelte +79 -7
- package/dist/Toggle/Toggle.svelte.d.ts +1 -1
- package/dist/Toggle/properties.d.ts +30 -7
- package/dist/ToolCallLog/ToolCallLog.svelte +59 -21
- package/dist/ToolCallLog/properties.d.ts +10 -0
- package/dist/Toolbar/Toolbar.svelte +1 -1
- package/dist/Tooltip/Tooltip.svelte +20 -2
- package/dist/Tooltip/tooltip-action.js +39 -4
- package/dist/TypewriterText/TypewriterText.svelte +34 -2
- package/dist/TypewriterText/properties.d.ts +18 -5
- package/dist/_chart/ChartContainer.svelte +12 -0
- package/dist/_chart/ChartTooltip.svelte +18 -4
- package/dist/_chart/Legend.svelte +21 -0
- package/dist/_chart/Legend.svelte.d.ts +15 -0
- package/dist/_chart/geometry.d.ts +54 -1
- package/dist/_chart/geometry.js +122 -14
- package/dist/_chart/interactions.d.ts +5 -1
- package/dist/_chart/interactions.js +9 -5
- package/dist/_chart/scales.js +16 -0
- package/dist/_chart/temporal.d.ts +45 -0
- package/dist/_chart/temporal.js +116 -0
- package/dist/_field/description.d.ts +50 -0
- package/dist/_field/description.js +51 -0
- package/dist/_interaction/dismissal.d.ts +67 -0
- package/dist/_interaction/dismissal.js +137 -0
- package/dist/_interaction/focus.d.ts +73 -0
- package/dist/_interaction/focus.js +143 -0
- package/dist/assets/star.svg +5 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +21 -1
- package/dist/reduced-motion.svelte.d.ts +37 -0
- package/dist/reduced-motion.svelte.js +44 -0
- package/dist/styles/theme-dark.css +778 -0
- package/dist/types.d.ts +4 -2
- package/dist/utils.d.ts +62 -1
- package/dist/utils.js +80 -21
- package/dist-codemod/{bin.js → codemod/bin.js} +13 -2
- package/dist-codemod/{cli.js → codemod/cli.js} +48 -3
- package/dist-codemod/codemod/migrate-audit.js +395 -0
- package/dist-codemod/codemod/migration-assets/legacy-display.css +120 -0
- package/dist-codemod/codemod/migration-assets/legacy-palette.css +106 -0
- package/dist-codemod/codemod/migration-assets/wc-display.json +492 -0
- package/dist-codemod/migrate/analyze.js +804 -0
- package/dist-codemod/migrate/chart-tooltip-selector.js +301 -0
- package/dist-wc/index.js +13992 -4323
- package/package.json +13 -6
- package/dist/Modal/focus-trap.d.ts +0 -42
- package/dist/Modal/focus-trap.js +0 -57
- /package/dist-codemod/{legacy-pairs.js → codemod/legacy-pairs.js} +0 -0
- /package/dist-codemod/{transform.js → codemod/transform.js} +0 -0
- /package/dist-codemod/{wc-children.js → codemod/wc-children.js} +0 -0
package/dist/types.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ import type { HTMLAttributes } from 'svelte/elements';
|
|
|
8
8
|
* which native types a consumer may ask for. The four added beyond the original
|
|
9
9
|
* text/tel/password/email/number all keep `value` a plain string with no parallel
|
|
10
10
|
* `checked`/`files` model, so Input's existing value plumbing covers them unchanged.
|
|
11
|
-
* `validateInput()` switches on dataType with no default branch,
|
|
12
|
-
*
|
|
11
|
+
* `validateInput()` switches on dataType with no default branch, so `number`,
|
|
12
|
+
* `time`, `date`, `search` and `url` are never validated by it and are always
|
|
13
|
+
* reported Valid. That limit is stated on `Input`'s own `dataType` prop too — a
|
|
14
|
+
* consumer picking a dataType reads the prop, not this union.
|
|
13
15
|
*
|
|
14
16
|
* Deliberately NOT included: checkbox and radio (driven by `checked`, which Input has
|
|
15
17
|
* no prop for), and file (rejects scripted `value` writes outright). Those need new
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
import type { CustomValidator, Hsv, Hsl, InputDataType, Rgb, ValidationState } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A phone-number shape a consumer opts into, as the pair of patterns the
|
|
4
|
+
* in-progress/committed distinction needs.
|
|
5
|
+
*
|
|
6
|
+
* Presets exist because `tel` cannot have a correct universal *format* rule --
|
|
7
|
+
* only a universal *character* rule (see `validateE164Shape`). A market-specific
|
|
8
|
+
* format is a real requirement and belongs to whoever knows the market, so it is
|
|
9
|
+
* named, exported and opted into rather than assumed.
|
|
10
|
+
*/
|
|
11
|
+
export type TelPreset = {
|
|
12
|
+
/** Matches a complete, committed number. */
|
|
13
|
+
readonly valid: RegExp;
|
|
14
|
+
/** Matches a number still being typed. Must accept every prefix of `valid`. */
|
|
15
|
+
readonly inProgress: RegExp;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Ten digits beginning 6-9 -- an Indian mobile number.
|
|
19
|
+
*
|
|
20
|
+
* This was the UNCONDITIONAL default for `dataType="tel"`. A consumer outside
|
|
21
|
+
* India got `+33 6 12 34 56 78` and `(555) 123-4567` marked Invalid by a rule
|
|
22
|
+
* they never chose and could not see, which is the worst shape for a default to
|
|
23
|
+
* fail in: correct input, silently rejected, no message naming the market.
|
|
24
|
+
* It is still here, still correct for the market it describes, and now has to be
|
|
25
|
+
* asked for.
|
|
26
|
+
*/
|
|
27
|
+
export declare const TEL_PRESET_IN_MOBILE: TelPreset;
|
|
28
|
+
/** Every preset this library ships, by name. */
|
|
29
|
+
export declare const TEL_PRESETS: Readonly<Record<string, TelPreset>>;
|
|
30
|
+
/** Optional, additive settings for `validateInput`. */
|
|
31
|
+
export type ValidateInputOptions = {
|
|
32
|
+
/**
|
|
33
|
+
* Format rule for `dataType="tel"` when no `validPattern` is supplied. Null or
|
|
34
|
+
* omitted keeps the locale-neutral character check described on
|
|
35
|
+
* `validateInput`.
|
|
36
|
+
*/
|
|
37
|
+
readonly telPreset?: TelPreset | null;
|
|
38
|
+
};
|
|
2
39
|
/**
|
|
3
40
|
* @description A common function to validate value provided inside the input component
|
|
4
41
|
* @param inputValue String value coming from input field
|
|
@@ -6,9 +43,23 @@ import type { CustomValidator, Hsv, Hsl, InputDataType, Rgb, ValidationState } f
|
|
|
6
43
|
* @param validPattern Regular expression which is supposed to be applied on the input string
|
|
7
44
|
* @param inProgressPattern Regular expression which is supposed to be applied on the input string while input is in progress
|
|
8
45
|
* @param customValidators Array of customer validator functions
|
|
46
|
+
* @param options Optional settings; see `ValidateInputOptions`
|
|
9
47
|
* @returns ValidationState : InProgress | Valid | Invalid
|
|
48
|
+
*
|
|
49
|
+
* Only `email`, `tel`, `password` and `text` are validated here. `number`,
|
|
50
|
+
* `time`, `date`, `search` and `url` have NO branch and always return 'Valid'
|
|
51
|
+
* before custom validators run -- the browser's own constraint validation is the
|
|
52
|
+
* only thing checking them. That is a real gap rather than a deliberate policy,
|
|
53
|
+
* and it is stated on `Input`'s `dataType` prop as well as here, because a
|
|
54
|
+
* consumer choosing a dataType reads the prop and not this file.
|
|
55
|
+
*
|
|
56
|
+
* `tel` with no `validPattern` checks the CHARACTERS a number may contain and
|
|
57
|
+
* nothing about its national format (see `validateE164Shape`). It used to apply
|
|
58
|
+
* an Indian mobile pattern unconditionally; that rule is now
|
|
59
|
+
* `TEL_PRESET_IN_MOBILE`, passed through `options.telPreset` here or through
|
|
60
|
+
* `Input`'s `validationPattern` / `inProgressPattern` props.
|
|
10
61
|
*/
|
|
11
|
-
export declare function validateInput(inputValue: string, dataType: InputDataType, validPattern: RegExp | null, inProgressPattern: RegExp | null, customValidators: CustomValidator[]): ValidationState;
|
|
62
|
+
export declare function validateInput(inputValue: string, dataType: InputDataType, validPattern: RegExp | null, inProgressPattern: RegExp | null, customValidators: CustomValidator[], options?: ValidateInputOptions): ValidationState;
|
|
12
63
|
/**
|
|
13
64
|
* @description Creates a debouncer function that delays invoking the provided callback until a specified delay period has elapsed since the last invocation.
|
|
14
65
|
* @param delay The delay period in milliseconds before invoking the callback.
|
|
@@ -35,6 +86,16 @@ export declare function clampInt(v: string, min: number, max: number): number;
|
|
|
35
86
|
* bubble and leaves it running in the message body rendered inside it.
|
|
36
87
|
*/
|
|
37
88
|
export declare function prefersReducedMotion(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Leading-edge throttle, despite the name: the first call runs immediately and
|
|
91
|
+
* every call within `delay` of it is dropped, rather than the last one being
|
|
92
|
+
* deferred as a debounce would. Modal relies on exactly that — the first
|
|
93
|
+
* dismissal must be acted on at once, and the repeats it guards against are the
|
|
94
|
+
* ones to discard.
|
|
95
|
+
*
|
|
96
|
+
* Not exported from the package; renaming it is a free change whenever the
|
|
97
|
+
* mismatch stops being worth the note.
|
|
98
|
+
*/
|
|
38
99
|
export declare function createDebouncer(delay: number): <T extends unknown[]>(callback: (...args: T) => void, ...args: T) => void;
|
|
39
100
|
export declare function lockBodyScroll(): void;
|
|
40
101
|
export declare function unlockBodyScroll(): void;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ten digits beginning 6-9 -- an Indian mobile number.
|
|
3
|
+
*
|
|
4
|
+
* This was the UNCONDITIONAL default for `dataType="tel"`. A consumer outside
|
|
5
|
+
* India got `+33 6 12 34 56 78` and `(555) 123-4567` marked Invalid by a rule
|
|
6
|
+
* they never chose and could not see, which is the worst shape for a default to
|
|
7
|
+
* fail in: correct input, silently rejected, no message naming the market.
|
|
8
|
+
* It is still here, still correct for the market it describes, and now has to be
|
|
9
|
+
* asked for.
|
|
10
|
+
*/
|
|
11
|
+
export const TEL_PRESET_IN_MOBILE = {
|
|
12
|
+
valid: /^[6-9][0-9]{9}$/,
|
|
13
|
+
inProgress: /^[6-9][0-9]{0,9}$/
|
|
14
|
+
};
|
|
15
|
+
/** Every preset this library ships, by name. */
|
|
16
|
+
export const TEL_PRESETS = {
|
|
17
|
+
'in-mobile': TEL_PRESET_IN_MOBILE
|
|
18
|
+
};
|
|
19
|
+
/** Digits a number can hold under E.164, which caps the subscriber number at 15. */
|
|
20
|
+
const E164_MAX_DIGITS = 15;
|
|
21
|
+
/** Shortest real number anywhere; below this a number is still being typed. */
|
|
22
|
+
const TEL_MIN_DIGITS = 4;
|
|
23
|
+
/**
|
|
24
|
+
* The only rule about phone numbers that holds in every market: which
|
|
25
|
+
* CHARACTERS one may contain, and how many digits it may hold. Length, leading
|
|
26
|
+
* digit and grouping are all national, so none of them are asserted here.
|
|
27
|
+
*
|
|
28
|
+
* Rejects letters and stray punctuation, accepts `+33 6 12 34 56 78`,
|
|
29
|
+
* `(555) 123-4567` and `9876543210` alike.
|
|
30
|
+
*/
|
|
31
|
+
function validateE164Shape(phoneNumber) {
|
|
32
|
+
if (phoneNumber.length === 0) {
|
|
33
|
+
return 'InProgress';
|
|
34
|
+
}
|
|
35
|
+
// A leading + is part of the international prefix and may appear only first.
|
|
36
|
+
const body = phoneNumber.startsWith('+') ? phoneNumber.slice(1) : phoneNumber;
|
|
37
|
+
if (/[^0-9\s()\-.]/.test(body)) {
|
|
38
|
+
return 'Invalid';
|
|
39
|
+
}
|
|
40
|
+
const digits = body.replace(/[^0-9]/g, '');
|
|
41
|
+
if (digits.length > E164_MAX_DIGITS) {
|
|
42
|
+
return 'Invalid';
|
|
43
|
+
}
|
|
44
|
+
return digits.length >= TEL_MIN_DIGITS ? 'Valid' : 'InProgress';
|
|
45
|
+
}
|
|
1
46
|
/**
|
|
2
47
|
* @description A common function to validate value provided inside the input component
|
|
3
48
|
* @param inputValue String value coming from input field
|
|
@@ -5,9 +50,23 @@
|
|
|
5
50
|
* @param validPattern Regular expression which is supposed to be applied on the input string
|
|
6
51
|
* @param inProgressPattern Regular expression which is supposed to be applied on the input string while input is in progress
|
|
7
52
|
* @param customValidators Array of customer validator functions
|
|
53
|
+
* @param options Optional settings; see `ValidateInputOptions`
|
|
8
54
|
* @returns ValidationState : InProgress | Valid | Invalid
|
|
55
|
+
*
|
|
56
|
+
* Only `email`, `tel`, `password` and `text` are validated here. `number`,
|
|
57
|
+
* `time`, `date`, `search` and `url` have NO branch and always return 'Valid'
|
|
58
|
+
* before custom validators run -- the browser's own constraint validation is the
|
|
59
|
+
* only thing checking them. That is a real gap rather than a deliberate policy,
|
|
60
|
+
* and it is stated on `Input`'s `dataType` prop as well as here, because a
|
|
61
|
+
* consumer choosing a dataType reads the prop and not this file.
|
|
62
|
+
*
|
|
63
|
+
* `tel` with no `validPattern` checks the CHARACTERS a number may contain and
|
|
64
|
+
* nothing about its national format (see `validateE164Shape`). It used to apply
|
|
65
|
+
* an Indian mobile pattern unconditionally; that rule is now
|
|
66
|
+
* `TEL_PRESET_IN_MOBILE`, passed through `options.telPreset` here or through
|
|
67
|
+
* `Input`'s `validationPattern` / `inProgressPattern` props.
|
|
9
68
|
*/
|
|
10
|
-
export function validateInput(inputValue, dataType, validPattern, inProgressPattern, customValidators) {
|
|
69
|
+
export function validateInput(inputValue, dataType, validPattern, inProgressPattern, customValidators, options = {}) {
|
|
11
70
|
let validationResult = 'Valid';
|
|
12
71
|
switch (dataType) {
|
|
13
72
|
case 'email':
|
|
@@ -16,7 +75,7 @@ export function validateInput(inputValue, dataType, validPattern, inProgressPatt
|
|
|
16
75
|
case 'tel':
|
|
17
76
|
validationResult =
|
|
18
77
|
validPattern === null
|
|
19
|
-
? validatePhoneNumber(inputValue)
|
|
78
|
+
? validatePhoneNumber(inputValue, options.telPreset ?? null)
|
|
20
79
|
: validateTextWithPattern(inputValue, validPattern, inProgressPattern);
|
|
21
80
|
break;
|
|
22
81
|
case 'password':
|
|
@@ -118,30 +177,20 @@ function validateEmailInput(emailId) {
|
|
|
118
177
|
return 'Valid';
|
|
119
178
|
}
|
|
120
179
|
/**
|
|
121
|
-
* @description Validates
|
|
122
|
-
*
|
|
123
|
-
* @link https://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number
|
|
180
|
+
* @description Validates a phone number against an opted-in preset, or against
|
|
181
|
+
* the locale-neutral character rule when none is given.
|
|
124
182
|
* @param phoneNumber
|
|
183
|
+
* @param preset Market-specific format, or null for no format rule at all
|
|
125
184
|
* @returns ValidationState
|
|
126
185
|
*/
|
|
127
|
-
function validatePhoneNumber(phoneNumber) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const inProgressPattern = new RegExp('^[6-9]{1}[0-9]{0,9}$');
|
|
131
|
-
if (validationPattern.test(phoneNumber)) {
|
|
132
|
-
return 'Valid';
|
|
133
|
-
}
|
|
134
|
-
else if (inProgressPattern.test(phoneNumber) || phoneNumber.length === 0) {
|
|
135
|
-
return 'InProgress';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
return 'Invalid';
|
|
139
|
-
}
|
|
186
|
+
function validatePhoneNumber(phoneNumber, preset) {
|
|
187
|
+
if (preset === null) {
|
|
188
|
+
return validateE164Shape(phoneNumber);
|
|
140
189
|
}
|
|
141
|
-
|
|
142
|
-
|
|
190
|
+
if (preset.valid.test(phoneNumber)) {
|
|
191
|
+
return 'Valid';
|
|
143
192
|
}
|
|
144
|
-
return phoneNumber
|
|
193
|
+
return preset.inProgress.test(phoneNumber) || phoneNumber.length === 0 ? 'InProgress' : 'Invalid';
|
|
145
194
|
}
|
|
146
195
|
/**
|
|
147
196
|
* @description Creates a debouncer function that delays invoking the provided callback until a specified delay period has elapsed since the last invocation.
|
|
@@ -296,6 +345,16 @@ export function prefersReducedMotion() {
|
|
|
296
345
|
typeof window.matchMedia === 'function' &&
|
|
297
346
|
window.matchMedia('(prefers-reduced-motion: reduce)').matches);
|
|
298
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Leading-edge throttle, despite the name: the first call runs immediately and
|
|
350
|
+
* every call within `delay` of it is dropped, rather than the last one being
|
|
351
|
+
* deferred as a debounce would. Modal relies on exactly that — the first
|
|
352
|
+
* dismissal must be acted on at once, and the repeats it guards against are the
|
|
353
|
+
* ones to discard.
|
|
354
|
+
*
|
|
355
|
+
* Not exported from the package; renaming it is a free change whenever the
|
|
356
|
+
* mismatch stops being worth the note.
|
|
357
|
+
*/
|
|
299
358
|
export function createDebouncer(delay) {
|
|
300
359
|
let lastCallTime = 0;
|
|
301
360
|
return function (callback, ...args) {
|
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
// not reuse cli.ts's own "am I the entry point" check — the bin is reached
|
|
7
7
|
// through an npm symlink, whose path never matches the real module URL, so
|
|
8
8
|
// that check would silently run nothing.
|
|
9
|
+
//
|
|
10
|
+
// This same check also gates the `migrate` subcommand (migrate-audit.ts):
|
|
11
|
+
// it imports `analyzeStylesheet`/`analyzeSvelte` from `../migrate/analyze.ts`,
|
|
12
|
+
// which imports `svelte/compiler` at module load too — unconditionally, for
|
|
13
|
+
// both functions, since that import sits above the split between them. This
|
|
14
|
+
// check runs, and can fail, before `cli.ts` is even imported, so it covers
|
|
15
|
+
// that path regardless of how `cli.ts` itself reaches migrate-audit.ts —
|
|
16
|
+
// which it now does with a dynamic `import()` inside `run` (see that
|
|
17
|
+
// function's doc comment in cli.ts), specifically so the classic prop-rename
|
|
18
|
+
// command below does not pay this same resolution cost, or fail the same
|
|
19
|
+
// way, for a dependency only the audit needs.
|
|
9
20
|
const REQUIRED = ['svelte/compiler'];
|
|
10
21
|
const missing = REQUIRED.filter((specifier) => {
|
|
11
22
|
try {
|
|
@@ -23,8 +34,8 @@ if (missing.length > 0) {
|
|
|
23
34
|
process.exitCode = 1;
|
|
24
35
|
}
|
|
25
36
|
else {
|
|
26
|
-
const {
|
|
27
|
-
const summary =
|
|
37
|
+
const { run } = await import("./cli.js");
|
|
38
|
+
const summary = await run(process.argv.slice(2), (line) => {
|
|
28
39
|
console.log(line);
|
|
29
40
|
});
|
|
30
41
|
process.exitCode = summary.exitCode;
|
|
@@ -6,6 +6,7 @@ import { transformSvelte } from "./transform.js";
|
|
|
6
6
|
import { findChildrenAssignments } from "./wc-children.js";
|
|
7
7
|
const USAGE = [
|
|
8
8
|
'Usage: npx sui-codemod [--dry-run] <path...>',
|
|
9
|
+
' npx sui-codemod migrate [--dry-run] <path>',
|
|
9
10
|
' (inside this repository: node scripts/codemod/cli.ts ...)',
|
|
10
11
|
'',
|
|
11
12
|
'Prepares a @juspay/svelte-ui-components consumer for 4.0.0: renames every',
|
|
@@ -18,9 +19,17 @@ const USAGE = [
|
|
|
18
19
|
'',
|
|
19
20
|
'Paths may be files or directories; directories are walked recursively,',
|
|
20
21
|
'skipping node_modules, .git, .svelte-kit, dist, dist-wc, build, coverage,',
|
|
21
|
-
'playwright-report and test-results.'
|
|
22
|
+
'playwright-report and test-results.',
|
|
23
|
+
'',
|
|
24
|
+
'Run `sui-codemod migrate <path> --help` instead to audit a project for',
|
|
25
|
+
'the seven 4.28.0 breaking changes (a different, single-project subcommand',
|
|
26
|
+
'-- see migrate-audit.ts).'
|
|
22
27
|
].join('\n');
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Exported for `migrate-audit.ts`'s own consumer file walk, so the two
|
|
30
|
+
* subcommands can never drift on what "skip node_modules et al." means.
|
|
31
|
+
*/
|
|
32
|
+
export const SKIPPED_DIRECTORIES = new Set([
|
|
24
33
|
'node_modules',
|
|
25
34
|
'.git',
|
|
26
35
|
'.svelte-kit',
|
|
@@ -166,9 +175,45 @@ export function runCodemod(argv, log) {
|
|
|
166
175
|
warnings
|
|
167
176
|
};
|
|
168
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* `sui-codemod`'s single entry point, callable directly by `bin.ts` and by
|
|
180
|
+
* tests: a leading `migrate` positional routes to the 4.28.0 breaking-change
|
|
181
|
+
* audit (`migrate-audit.ts`), matching `npm run migrate`'s findings but
|
|
182
|
+
* runnable against a project that only has the published package installed;
|
|
183
|
+
* anything else goes to `runCodemod`, unchanged from before this existed.
|
|
184
|
+
*
|
|
185
|
+
* A subcommand rather than a flag (`--migrate`) because the two take a
|
|
186
|
+
* different argv shape -- `runCodemod` accepts a variadic list of paths,
|
|
187
|
+
* `migrate` takes exactly one project root, mirroring `chart-tooltip-selector.ts`
|
|
188
|
+
* and `scripts/migrate/cli.ts` -- and because `migrate`'s own `--dry-run`
|
|
189
|
+
* means "preview the tooltip selector rewrite", a different question from
|
|
190
|
+
* `runCodemod`'s "preview the prop rename", so the two need separate
|
|
191
|
+
* `parseArgs` calls rather than one shared flag set. The trade-off is a
|
|
192
|
+
* consumer directory literally named `migrate` colliding with the
|
|
193
|
+
* subcommand if passed as this package's own single positional; no such
|
|
194
|
+
* conflict exists for `runCodemod`'s variadic form.
|
|
195
|
+
*
|
|
196
|
+
* `migrate-audit.ts` is imported dynamically here, inside the branch that
|
|
197
|
+
* actually needs it, rather than as a static top-level import. A static
|
|
198
|
+
* import is resolved and linked -- by Node, at module load, before any of
|
|
199
|
+
* this file's own code runs -- regardless of whether `argv` ever asks for
|
|
200
|
+
* `migrate`; `migrate-audit.ts` in turn imports `../migrate/analyze.ts`
|
|
201
|
+
* unconditionally, so a static import here would mean every invocation of
|
|
202
|
+
* `runCodemod`'s own prop-rename command, the one this package has shipped
|
|
203
|
+
* since 4.0.0, pays that resolution cost too, and fails outright if it
|
|
204
|
+
* can't be satisfied. A dynamic import defers that cost, and that failure
|
|
205
|
+
* mode, to only the invocations that actually take this branch.
|
|
206
|
+
*/
|
|
207
|
+
export async function run(argv, log) {
|
|
208
|
+
if (argv[0] === 'migrate') {
|
|
209
|
+
const { runMigrateAudit } = await import("./migrate-audit.js");
|
|
210
|
+
return runMigrateAudit(argv.slice(1), log);
|
|
211
|
+
}
|
|
212
|
+
return runCodemod(argv, log);
|
|
213
|
+
}
|
|
169
214
|
const entryPoint = process.argv.at(1) ?? '';
|
|
170
215
|
if (entryPoint !== '' && import.meta.url === pathToFileURL(entryPoint).href) {
|
|
171
|
-
const summary =
|
|
216
|
+
const summary = await run(process.argv.slice(2), (line) => {
|
|
172
217
|
console.log(line);
|
|
173
218
|
});
|
|
174
219
|
process.exitCode = summary.exitCode;
|