@ember-joinery/maskito 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/LICENSE.md +9 -0
- package/NOTICE +532 -0
- package/README.md +55 -2
- package/addon-main.cjs +4 -0
- package/declarations/components/masked-input.d.ts +30 -0
- package/declarations/components/masked-input.d.ts.map +1 -0
- package/declarations/components/phone-input.d.ts +167 -0
- package/declarations/components/phone-input.d.ts.map +1 -0
- package/declarations/index.d.ts +9 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/maskito.d.ts +42 -0
- package/declarations/maskito.d.ts.map +1 -0
- package/declarations/messages.d.ts +21 -0
- package/declarations/messages.d.ts.map +1 -0
- package/declarations/phone.d.ts +49 -0
- package/declarations/phone.d.ts.map +1 -0
- package/declarations/presets.d.ts +53 -0
- package/declarations/presets.d.ts.map +1 -0
- package/declarations/test-support/-private/typing.d.ts +28 -0
- package/declarations/test-support/-private/typing.d.ts.map +1 -0
- package/declarations/test-support/index.d.ts +3 -0
- package/declarations/test-support/index.d.ts.map +1 -0
- package/declarations/test-support/masked-input.d.ts +36 -0
- package/declarations/test-support/masked-input.d.ts.map +1 -0
- package/declarations/test-support/phone-input.d.ts +70 -0
- package/declarations/test-support/phone-input.d.ts.map +1 -0
- package/declarations/test-support.d.ts +2 -0
- package/dist/components/masked-input.js +31 -0
- package/dist/components/masked-input.js.map +1 -0
- package/dist/components/phone-input.js +374 -0
- package/dist/components/phone-input.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/maskito.js +87 -0
- package/dist/maskito.js.map +1 -0
- package/dist/messages.js +23 -0
- package/dist/messages.js.map +1 -0
- package/dist/phone.js +99 -0
- package/dist/phone.js.map +1 -0
- package/dist/presets.js +122 -0
- package/dist/presets.js.map +1 -0
- package/dist/test-support.js +330 -0
- package/dist/test-support.js.map +1 -0
- package/package.json +117 -3
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { type MaskitoOptions } from '@maskito/core';
|
|
3
|
+
import { ControllableState } from '@ember-joinery/primitives/controllable-state';
|
|
4
|
+
import { type IconNode } from '@ember-joinery/ember/components/icon';
|
|
5
|
+
import { type CountryCode, type MetadataJson } from '../phone.ts';
|
|
6
|
+
/** A country in the picker. */
|
|
7
|
+
export interface PhoneCountry {
|
|
8
|
+
/** Its ISO 3166 code, such as `GB`. */
|
|
9
|
+
code: CountryCode;
|
|
10
|
+
/** Its name, in `@locale`'s language. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Its calling code, without the `+`. */
|
|
13
|
+
callingCode: string;
|
|
14
|
+
/** Its flag, as an emoji. */
|
|
15
|
+
flag: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PhoneInputSignature {
|
|
18
|
+
Args: {
|
|
19
|
+
/**
|
|
20
|
+
* The number in E.164 form (`+12125550123`), or `null` while it is empty, when you control
|
|
21
|
+
* it. While a number is being typed it holds the digits so far, with the `+`.
|
|
22
|
+
*/
|
|
23
|
+
value?: string | null;
|
|
24
|
+
/** The number it starts with when you don't control it. */
|
|
25
|
+
defaultValue?: string | null;
|
|
26
|
+
/** Called with the new number (E.164, or `null`) whenever it changes. */
|
|
27
|
+
onValueChange?: (value: string | null) => void;
|
|
28
|
+
/** The country whose numbers are typed (ISO 3166), when you control it. */
|
|
29
|
+
country?: CountryCode;
|
|
30
|
+
/**
|
|
31
|
+
* The country it starts with: by default the country of its value, else the first of
|
|
32
|
+
* `@countries`, else `US`.
|
|
33
|
+
*/
|
|
34
|
+
defaultCountry?: CountryCode;
|
|
35
|
+
/** Called with the new country whenever it changes. */
|
|
36
|
+
onCountryChange?: (country: CountryCode) => void;
|
|
37
|
+
/** The countries the picker offers, in this order. Default: every country, by name. */
|
|
38
|
+
countries?: readonly CountryCode[];
|
|
39
|
+
/** Show numbers in the national format, `(212) 555-0123`; the calling code sits by the flag. */
|
|
40
|
+
national?: boolean;
|
|
41
|
+
/** libphonenumber-js metadata. Default its `min` metadata. */
|
|
42
|
+
metadata?: MetadataJson;
|
|
43
|
+
/** The language the countries are named in. Default the app's translator's, or the browser's. */
|
|
44
|
+
locale?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The country picker's whole accessible name. By default it is named after the input: its
|
|
47
|
+
* label and `country` (`Phone country`), so several phone inputs' pickers differ.
|
|
48
|
+
*/
|
|
49
|
+
countryLabel?: string;
|
|
50
|
+
/** The picker's chevron. Default lucide's `chevron-down`. */
|
|
51
|
+
icon?: IconNode;
|
|
52
|
+
/** Disables the input and the country picker. */
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/** Puts a hidden input by this name in a form, holding the number in E.164 form. */
|
|
55
|
+
formName?: string;
|
|
56
|
+
/** Its name, for `PhoneInputHarness` (`data-test-jn-name`). */
|
|
57
|
+
name?: string;
|
|
58
|
+
};
|
|
59
|
+
/** The `<input type="tel">`: give it `id`, `placeholder`, `aria-invalid`, `aria-describedby`… */
|
|
60
|
+
Element: HTMLInputElement;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A phone number input with a country picker, in shadcn's look: an Input Group whose addon is
|
|
64
|
+
* a Select of countries (each with its flag and calling code), and whose input
|
|
65
|
+
* `@maskito/phone` masks as it is typed in, by the rules libphonenumber-js has for the chosen
|
|
66
|
+
* country. Its value is the number in E.164 form, `+12125550123`, or `null` while it is empty:
|
|
67
|
+
*
|
|
68
|
+
* <PhoneInput @value={{this.phone}} @onValueChange={{this.setPhone}} />
|
|
69
|
+
* <PhoneInput @defaultCountry="GB" @national={{true}} />
|
|
70
|
+
*
|
|
71
|
+
* The picker shows the country of the value: a number from another country, set, pasted,
|
|
72
|
+
* dropped or autofilled, switches it, and choosing a country keeps the national number typed so
|
|
73
|
+
* far. `@countries` narrows the list.
|
|
74
|
+
*/
|
|
75
|
+
export default class PhoneInput extends Component<PhoneInputSignature> {
|
|
76
|
+
#private;
|
|
77
|
+
/** What was last typed; shown while it still stands for the value. */
|
|
78
|
+
private typed;
|
|
79
|
+
valueState: ControllableState<string | null>;
|
|
80
|
+
countryState: ControllableState<CountryCode>;
|
|
81
|
+
get metadata(): MetadataJson;
|
|
82
|
+
get national(): boolean;
|
|
83
|
+
/** The number, in E.164 form, or `null`. */
|
|
84
|
+
get value(): string | null;
|
|
85
|
+
/** The country shown: the value's, whose calling code decides, else the one chosen. */
|
|
86
|
+
get country(): CountryCode;
|
|
87
|
+
get callingCode(): string;
|
|
88
|
+
get flag(): string;
|
|
89
|
+
get countryName(): string;
|
|
90
|
+
/** The hidden `country` that follows the input's label in the picker's default name. */
|
|
91
|
+
get countryWordId(): string;
|
|
92
|
+
get locale(): string | undefined;
|
|
93
|
+
get displayNames(): Intl.DisplayNames;
|
|
94
|
+
nameOf(code: CountryCode): string;
|
|
95
|
+
/** The countries in the picker. */
|
|
96
|
+
get countries(): PhoneCountry[];
|
|
97
|
+
/** The mask for the country shown, made again only when the country or format changes. */
|
|
98
|
+
get options(): MaskitoOptions;
|
|
99
|
+
/** The last mask made, kept while it is for the same country, format and metadata. */
|
|
100
|
+
maskFor(country: CountryCode, national: boolean, metadata: MetadataJson): MaskitoOptions;
|
|
101
|
+
/** The E.164 form of what the input shows, or `null` when it shows no digits. */
|
|
102
|
+
toE164(text: string, country: CountryCode): string | null;
|
|
103
|
+
/** A number in E.164 form, as the input shows it for `country`. */
|
|
104
|
+
format(value: string, country: CountryCode): string;
|
|
105
|
+
/** The national part of a number in E.164 form, whole or begun. */
|
|
106
|
+
nationalNumberOf(value: string): string;
|
|
107
|
+
/** What the input shows: what was typed, while it stands for the value, else the value. */
|
|
108
|
+
get shown(): string;
|
|
109
|
+
/** The input changed (the mask has shaped it already). */
|
|
110
|
+
onText: (text: string) => void;
|
|
111
|
+
/** A country was chosen: the national number typed so far moves to its calling code. */
|
|
112
|
+
chooseCountry: (code: string) => void;
|
|
113
|
+
/**
|
|
114
|
+
* A whole number that arrives at once: pasted, dropped, autofilled, or filled in by a test.
|
|
115
|
+
* One that starts with `+` (or `00`) is read in its own country, which the picker switches
|
|
116
|
+
* to, and replaces what the input holds: the mask of the country shown would read its calling
|
|
117
|
+
* code as the first digits of a number of its own, and store another number. A number from a
|
|
118
|
+
* country `@countries` leaves out, or whose calling code is unknown, is turned away. Anything
|
|
119
|
+
* else is left to the mask (`undefined`).
|
|
120
|
+
*/
|
|
121
|
+
takeNumber(text: string): 'taken' | 'refused' | undefined;
|
|
122
|
+
/** Whether the mask of the country shown leaves `text` as it is: text it shaped itself. */
|
|
123
|
+
fitsMask(text: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Reads a whole number before the mask does, in the capture phase, so it goes before
|
|
126
|
+
* `{{maskito}}` in the template: a paste (its clipboard), a drop or a writing suggestion (its
|
|
127
|
+
* `beforeinput`), and an `input` no `beforeinput` announced, as Chrome's autofill and
|
|
128
|
+
* `fillIn()` send (with no `inputType`) and Firefox's (`insertReplacementText`). Typing has an
|
|
129
|
+
* `inputType` and is left alone, and so is text the mask shaped itself (the calling code its
|
|
130
|
+
* focus plugin puts in, with an `input` of no type). A number taken or turned away goes no
|
|
131
|
+
* further, and the input shows what the value now is.
|
|
132
|
+
*/
|
|
133
|
+
wholeNumbers: import("ember-modifier").FunctionBasedModifier<{
|
|
134
|
+
Args: {
|
|
135
|
+
Positional: unknown[];
|
|
136
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
137
|
+
};
|
|
138
|
+
Element: HTMLInputElement;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Names the picker after its input, `Phone country`, so a screen reader tells apart the
|
|
142
|
+
* pickers of a form with several phone inputs: the input's `aria-labelledby`, else its
|
|
143
|
+
* `<label>`s (given an id if they have none), then a hidden `country`; else its `aria-label`
|
|
144
|
+
* and `country`. `@countryLabel` names it instead.
|
|
145
|
+
*/
|
|
146
|
+
nameTrigger: import("ember-modifier").FunctionBasedModifier<{
|
|
147
|
+
Args: {
|
|
148
|
+
Positional: [string | undefined];
|
|
149
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
150
|
+
};
|
|
151
|
+
Element: HTMLElement;
|
|
152
|
+
}>;
|
|
153
|
+
/**
|
|
154
|
+
* Choosing a country sends focus to the input, to type the number; Escape, to the picker.
|
|
155
|
+
* It goes once the input shows the new country's mask, so that mask's calling code goes in.
|
|
156
|
+
*/
|
|
157
|
+
onCloseAutoFocus: (event: Event) => void;
|
|
158
|
+
onOpenChange: (open: boolean) => void;
|
|
159
|
+
registerInput: import("ember-modifier").FunctionBasedModifier<{
|
|
160
|
+
Args: {
|
|
161
|
+
Positional: unknown[];
|
|
162
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
163
|
+
};
|
|
164
|
+
Element: HTMLInputElement;
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=phone-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.d.ts","sourceRoot":"","sources":["../../src/components/phone-input.gts"],"names":[],"mappings":"AAghBA,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAO1C,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAA;AAIhF,OAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAQ1E,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAA;AAIpB,+BAA+B;AAC/B,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAA;IACjB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAA;IACnB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE;QACJ;;;W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;;OAKG;IACH,WAAW;;;;;;OAkCT;IAEF;;;OAGG;IACH,gBAAgB,GAAI,OAAO,KAAK,KAAG,IAAI,CAKtC;IAED,YAAY,GAAI,MAAM,OAAO,KAAG,IAAI,CAEnC;IAED,aAAa;;;;;;OAKX;CAsQH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as MaskedInput } from './components/masked-input';
|
|
2
|
+
export * from './components/masked-input';
|
|
3
|
+
export { default as PhoneInput } from './components/phone-input';
|
|
4
|
+
export * from './components/phone-input';
|
|
5
|
+
export * from './maskito.ts';
|
|
6
|
+
export * from './messages.ts';
|
|
7
|
+
export * from './phone.ts';
|
|
8
|
+
export * from './presets.ts';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAA;AACtE,cAAc,+BAA+B,CAAA;AAC7C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACpE,cAAc,8BAA8B,CAAA;AAC5C,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Modifier from 'ember-modifier';
|
|
2
|
+
import { type MaskitoOptions } from '@maskito/core';
|
|
3
|
+
export type { MaskitoOptions };
|
|
4
|
+
/** The input or textarea a mask goes on. */
|
|
5
|
+
export type MaskedElement = HTMLInputElement | HTMLTextAreaElement;
|
|
6
|
+
export interface MaskitoSignature {
|
|
7
|
+
Element: MaskedElement;
|
|
8
|
+
Args: {
|
|
9
|
+
/** The Maskito options, such as a preset's (`numberMask()`); none leaves the element alone. */
|
|
10
|
+
Positional: [options: MaskitoOptions | null | undefined];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Masks an `<input>` or `<textarea>` of your own as it is typed in, with
|
|
15
|
+
* [Maskito](https://maskito.dev): give it any Maskito options, such as those of a preset
|
|
16
|
+
* (`numberMask`, `dateMask`, `timeMask`…) or your own `{ mask: [...] }`.
|
|
17
|
+
*
|
|
18
|
+
* <input {{asInput}} {{maskito this.cardMask}} {{on "input" this.update}} />
|
|
19
|
+
*
|
|
20
|
+
* The mask shapes what is typed, pasted, dropped and autofilled, and every `input` listener on
|
|
21
|
+
* the element reads the masked text. New options replace the mask; none (`undefined`) takes it
|
|
22
|
+
* off; the same options object keeps the mask as it is, history and all, so build them once
|
|
23
|
+
* (a getter with `@cached`, a constant, or a helper whose arguments don't change). A value set
|
|
24
|
+
* from code isn't masked: put it through `maskText()` first, as `MaskedInput` does.
|
|
25
|
+
*
|
|
26
|
+
* It isn't named after the element: a binding named `input` would turn every `<input>` in the
|
|
27
|
+
* template into a call to it.
|
|
28
|
+
*/
|
|
29
|
+
export declare class maskito extends Modifier<MaskitoSignature> {
|
|
30
|
+
#private;
|
|
31
|
+
modify(element: MaskedElement, [options]: [MaskitoOptions | null | undefined]): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Text as the mask would shape it: what a value set from code looks like masked.
|
|
35
|
+
*
|
|
36
|
+
* maskText('5551234567', phoneMask) // '(555) 123-4567'
|
|
37
|
+
*
|
|
38
|
+
* Without options, or without text (`''`, `undefined`), it is returned as it is.
|
|
39
|
+
*/
|
|
40
|
+
export declare function maskText(text: string, options?: MaskitoOptions | null): string;
|
|
41
|
+
export declare function maskText(text: string | undefined, options?: MaskitoOptions | null): string | undefined;
|
|
42
|
+
//# sourceMappingURL=maskito.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maskito.d.ts","sourceRoot":"","sources":["../src/maskito.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9E,YAAY,EAAE,cAAc,EAAE,CAAA;AAE9B,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAElE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,aAAa,CAAA;IACtB,IAAI,EAAE;QACJ,+FAA+F;QAC/F,UAAU,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;KACzD,CAAA;CACF;AAqBD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,OAAQ,SAAQ,QAAQ,CAAC,gBAAgB,CAAC;;IAK5C,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI;CAiB9F;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,GAAG,MAAM,CAAA;AAC/E,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,GAC9B,MAAM,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every string `@ember-joinery/maskito` shows or announces itself, in English, for a
|
|
3
|
+
* translation catalog. An argument (`@countryLabel`) still beats each one.
|
|
4
|
+
*/
|
|
5
|
+
export declare const messages: {
|
|
6
|
+
country: {
|
|
7
|
+
id: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
namedCountry: {
|
|
11
|
+
id: string;
|
|
12
|
+
message: string;
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
countryWord: {
|
|
16
|
+
id: string;
|
|
17
|
+
message: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;CAYc,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MaskitoOptions } from '@maskito/core';
|
|
2
|
+
import { type CountryCode, type MetadataJson } from 'libphonenumber-js/core';
|
|
3
|
+
export type { CountryCode, MetadataJson };
|
|
4
|
+
/** libphonenumber-js's `min` metadata, the default everywhere here. */
|
|
5
|
+
export declare const phoneMetadata: MetadataJson;
|
|
6
|
+
/** What a phone mask is for: a country, shown with or without its calling code. */
|
|
7
|
+
export interface PhoneMaskOptions {
|
|
8
|
+
/** Show the national format, `(212) 555-0123`, rather than `+1 212 555-0123`. */
|
|
9
|
+
national?: boolean;
|
|
10
|
+
/** libphonenumber-js metadata. Default its `min` metadata. */
|
|
11
|
+
metadata?: MetadataJson;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Maskito options for one country's phone numbers (`@maskito/phone`, strict). In the
|
|
15
|
+
* international format, its calling code is fixed in front: it goes in when the input takes
|
|
16
|
+
* focus, as `@maskito/kit`'s focus plugin puts it (the mask needs it there before the first
|
|
17
|
+
* digit), and comes out again on blur if nothing follows it. Each call makes new options, as a
|
|
18
|
+
* phone mask keeps state of its own.
|
|
19
|
+
*/
|
|
20
|
+
export declare function phoneMask(country: CountryCode, { national, metadata }?: PhoneMaskOptions): MaskitoOptions;
|
|
21
|
+
/** Every country the metadata has numbers for, as ISO 3166 codes. */
|
|
22
|
+
export declare function phoneCountries(metadata?: MetadataJson): CountryCode[];
|
|
23
|
+
/** A country's calling code, without the `+`: `1` for `US`, `44` for `GB`. */
|
|
24
|
+
export declare function callingCode(country: CountryCode, metadata?: MetadataJson): string;
|
|
25
|
+
/** A country's flag, as the emoji its code spells in regional indicator letters. */
|
|
26
|
+
export declare function countryFlag(country: string): string;
|
|
27
|
+
/** The calling code an E.164 number (whole or begun) starts with, or `undefined`. */
|
|
28
|
+
export declare function callingCodeOf(value: string | null | undefined, metadata?: MetadataJson): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The country of an E.164 number: `current` when the number has its calling code (so a
|
|
31
|
+
* Canadian number stays Canadian while `+1` is typed), else the country the number belongs to,
|
|
32
|
+
* else the main country of its calling code (`US` for `+1`, `GB` for `+44`). `undefined` for a
|
|
33
|
+
* number with no calling code yet.
|
|
34
|
+
*/
|
|
35
|
+
export declare function countryOfPhone(value: string | null | undefined, current?: CountryCode, metadata?: MetadataJson): CountryCode | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a stored number is a valid phone number, for a validator. A number without a `+`
|
|
38
|
+
* is read as `country`'s. Uses libphonenumber-js's `min` metadata unless given other metadata,
|
|
39
|
+
* which checks a number's length for its country.
|
|
40
|
+
*
|
|
41
|
+
* isValidPhone('+12125550123') // true
|
|
42
|
+
*/
|
|
43
|
+
export declare function isValidPhone(value: string | null | undefined, country?: CountryCode, metadata?: MetadataJson): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* A stored number in international format (`+1 212 555 0123`), to show it outside an input.
|
|
46
|
+
* Anything that doesn't parse is shown as it is.
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatPhone(value: string | null | undefined, metadata?: MetadataJson): string;
|
|
49
|
+
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../src/phone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAA;AAE/B,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA;AAEzC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|
|
1
|
+
import type { MaskitoOptions } from '@maskito/core';
|
|
2
|
+
import { type MaskitoDateMode, type MaskitoDateParams, type MaskitoDateRangeParams, type MaskitoDateTimeParams, type MaskitoNumberParams, type MaskitoTimeMode, type MaskitoTimeParams } from '@maskito/kit';
|
|
3
|
+
export type { MaskitoDateMode, MaskitoDateParams, MaskitoDateRangeParams, MaskitoDateTimeParams, MaskitoNumberParams, MaskitoTimeMode, MaskitoTimeParams, };
|
|
4
|
+
/** A date preset's parameters: `@maskito/kit`'s, each optional. */
|
|
5
|
+
export type DateMaskParams = Partial<MaskitoDateParams>;
|
|
6
|
+
/** A time preset's parameters: `@maskito/kit`'s, each optional. */
|
|
7
|
+
export type TimeMaskParams = Partial<MaskitoTimeParams>;
|
|
8
|
+
/** A date and time preset's parameters: `@maskito/kit`'s, each optional. */
|
|
9
|
+
export type DateTimeMaskParams = Partial<MaskitoDateTimeParams>;
|
|
10
|
+
/** A date range preset's parameters: `@maskito/kit`'s, each optional. */
|
|
11
|
+
export type DateRangeMaskParams = Partial<MaskitoDateRangeParams>;
|
|
12
|
+
/**
|
|
13
|
+
* A number: digits, a decimal separator, a thousands separator, and a minus sign, a prefix or a
|
|
14
|
+
* postfix if you give them (`@maskito/kit`'s `maskitoNumber`).
|
|
15
|
+
*
|
|
16
|
+
* <MaskedInput @mask={{numberMask maximumFractionDigits=2 prefix="$"}} />
|
|
17
|
+
*
|
|
18
|
+
* `min` and `max` clamp it, and `locale` takes its separators from that locale.
|
|
19
|
+
*/
|
|
20
|
+
export declare function numberMask(params?: MaskitoNumberParams): MaskitoOptions;
|
|
21
|
+
/**
|
|
22
|
+
* A date (`@maskito/kit`'s `maskitoDate`): `dd/mm/yyyy` unless `mode` (`mm/dd/yyyy`,
|
|
23
|
+
* `yyyy/mm/dd`, `mm/yy`…) says otherwise, separated by `separator` (default `/`), within `min`
|
|
24
|
+
* and `max`. With `locale` (`en-US`, `de-DE`), the order and separator are that locale's.
|
|
25
|
+
*/
|
|
26
|
+
export declare function dateMask(params?: DateMaskParams): MaskitoOptions;
|
|
27
|
+
/**
|
|
28
|
+
* A time (`@maskito/kit`'s `maskitoTime`): `HH:MM` unless `mode` (`HH:MM:SS`, `HH:MM AA`, `MM:SS`…)
|
|
29
|
+
* says otherwise, with `step` for the arrow keys.
|
|
30
|
+
*/
|
|
31
|
+
export declare function timeMask(params?: TimeMaskParams): MaskitoOptions;
|
|
32
|
+
/** A date and a time (`@maskito/kit`'s `maskitoDateTime`): `dd/mm/yyyy, HH:MM` by default. */
|
|
33
|
+
export declare function dateTimeMask(params?: DateTimeMaskParams): MaskitoOptions;
|
|
34
|
+
/** Two dates (`@maskito/kit`'s `maskitoDateRange`): `dd/mm/yyyy – dd/mm/yyyy` by default. */
|
|
35
|
+
export declare function dateRangeMask(params?: DateRangeMaskParams): MaskitoOptions;
|
|
36
|
+
/**
|
|
37
|
+
* The number a `numberMask` input shows, or `NaN` while it shows none. Give it the preset's
|
|
38
|
+
* parameters, so it reads the same separators.
|
|
39
|
+
*
|
|
40
|
+
* parseNumber('$1,234.50', { prefix: '$' }) // 1234.5
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseNumber(text: string, params?: MaskitoNumberParams): number;
|
|
43
|
+
/** A number as a `numberMask` input with these parameters shows it. */
|
|
44
|
+
export declare function formatNumber(number: number | null, params?: MaskitoNumberParams): string;
|
|
45
|
+
/** The date a `dateMask` input shows, or `null` while it shows no whole date. */
|
|
46
|
+
export declare function parseDate(text: string, params?: DateMaskParams): Date | null;
|
|
47
|
+
/** A date as a `dateMask` input with these parameters shows it. */
|
|
48
|
+
export declare function formatDate(date: Date, params?: DateMaskParams): string;
|
|
49
|
+
/** The time a `timeMask` input shows, in milliseconds since midnight. */
|
|
50
|
+
export declare function parseTime(text: string, params?: TimeMaskParams): number;
|
|
51
|
+
/** A time, in milliseconds since midnight, as a `timeMask` input with these parameters shows it. */
|
|
52
|
+
export declare function formatTime(milliseconds: number, params?: TimeMaskParams): string;
|
|
53
|
+
//#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IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,mBAAwB,GAAG,MAAM,CAElF;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,GAAE,mBAAwB,GAAG,MAAM,CAE5F;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,GAAG,IAAI,GAAG,IAAI,CAEhF;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,cAAmB,GAAG,MAAM,CAE1E;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,GAAG,MAAM,CAE3E;AAED,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,GAAG,MAAM,CAEpF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type TextControl = HTMLInputElement | HTMLTextAreaElement;
|
|
2
|
+
/** Types `text` one character at a time at the caret (the end), as a keyboard does. */
|
|
3
|
+
export declare function typeText(element: TextControl, text: string): Promise<void>;
|
|
4
|
+
/** Presses Backspace `times` times with the caret at the end. */
|
|
5
|
+
export declare function backspace(element: TextControl, times?: number): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Presses Delete `times` times, starting with the caret at `at` (a character's index), as a
|
|
8
|
+
* keyboard does: the caret stays where it is and the text after it moves up.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deleteForward(element: TextControl, at: number, times?: number): Promise<void>;
|
|
11
|
+
/** Presses Ctrl+Z, which undoes the last edit. */
|
|
12
|
+
export declare function undo(element: TextControl): Promise<void>;
|
|
13
|
+
/** Presses Ctrl+Shift+Z, which redoes the edit undone last. */
|
|
14
|
+
export declare function redo(element: TextControl): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Drops `text` at the end, as a drag and drop of text does: a cancelable `beforeinput`
|
|
17
|
+
* (`insertFromDrop`, with the text as its `data` and on its `dataTransfer`), then, if nothing
|
|
18
|
+
* cancelled it, the insertion and an `input`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function dropText(element: TextControl, text: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Pastes `text` over what the element holds, as a user who selects it all and pastes does: a
|
|
23
|
+
* `paste` event with the text on its clipboard (which a component may take over), then, if
|
|
24
|
+
* nothing cancelled it, the insertion.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pasteText(element: TextControl, text: string): Promise<void>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=typing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typing.d.ts","sourceRoot":"","sources":["../../../src/test-support/-private/typing.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAoCzD,uFAAuF;AACvF,wBAAsB,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhF;AAED,iEAAiE;AACjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAU9E;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAU9F;AAKD,kDAAkD;AAClD,wBAAsB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9D;AAED,+DAA+D;AAC/D,wBAAsB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9D;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAahF;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { InputHarness } from '@ember-joinery/test-support';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `<MaskedInput>` from `@ember-joinery/maskito`. It is an `InputHarness` (its `value`,
|
|
4
|
+
* `label`, `fillIn()` and the rest), and it types the way a browser does, so the mask answers
|
|
5
|
+
* each keystroke as it would a user's.
|
|
6
|
+
*
|
|
7
|
+
* const price = new MaskedInputHarness('price') // <MaskedInput @name="price">
|
|
8
|
+
* await price.typeText('1234.5')
|
|
9
|
+
* assert.strictEqual(price.value, '1,234.5')
|
|
10
|
+
*
|
|
11
|
+
* `fillIn()` replaces the text at once, as autofill does, and the mask shapes the result.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MaskedInputHarness extends InputHarness {
|
|
14
|
+
static component: string;
|
|
15
|
+
/**
|
|
16
|
+
* Types `text` at the end, one character at a time, each with the `beforeinput` and `input`
|
|
17
|
+
* a keyboard sends; the mask turns away what doesn't fit.
|
|
18
|
+
*/
|
|
19
|
+
typeText(text: string): Promise<void>;
|
|
20
|
+
/** Presses Backspace at the end, `times` times; the mask steps over its fixed characters. */
|
|
21
|
+
backspace(times?: number): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Presses Delete `times` times with the caret at `at` (a character's index); the mask steps
|
|
24
|
+
* over its fixed characters.
|
|
25
|
+
*/
|
|
26
|
+
deleteForward(at: number, times?: number): Promise<void>;
|
|
27
|
+
/** Selects everything and pastes `text` over it, as a user does. */
|
|
28
|
+
paste(text: string): Promise<void>;
|
|
29
|
+
/** Drops `text` at the end, as a drag and drop does; the mask shapes it. */
|
|
30
|
+
drop(text: string): Promise<void>;
|
|
31
|
+
/** Presses Ctrl+Z: the mask undoes the last edit. */
|
|
32
|
+
undo(): Promise<void>;
|
|
33
|
+
/** Presses Ctrl+Shift+Z: the mask redoes the edit undone last. */
|
|
34
|
+
redo(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=masked-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masked-input.d.ts","sourceRoot":"","sources":["../../src/test-support/masked-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAW1D;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,OAAgB,SAAS,SAAiB;IAE1C;;;OAGG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C,6FAA6F;IACvF,SAAS,CAAC,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC;;;OAGG;IACG,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD,oEAAoE;IAC9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,4EAA4E;IACtE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,qDAAqD;IAC/C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,kEAAkE;IAC5D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InputHarness, SelectHarness } from '@ember-joinery/test-support';
|
|
2
|
+
import { Harness } from '@ember-joinery/test-support';
|
|
3
|
+
/**
|
|
4
|
+
* Drives a `<PhoneInput>` from `@ember-joinery/maskito`: its input (an `InputHarness`) and its
|
|
5
|
+
* country picker (a `SelectHarness`). It reads what the input shows, masked, and the country
|
|
6
|
+
* chosen; the number it stores, in E.164 form, is what `@onValueChange` hears.
|
|
7
|
+
*
|
|
8
|
+
* const phone = new PhoneInputHarness('phone') // <PhoneInput @name="phone">
|
|
9
|
+
* await phone.selectCountry('GB')
|
|
10
|
+
* await phone.typeText('7911123456')
|
|
11
|
+
* assert.strictEqual(phone.value, '+44 7911 123456')
|
|
12
|
+
* assert.strictEqual(phone.country, 'GB')
|
|
13
|
+
*/
|
|
14
|
+
export declare class PhoneInputHarness extends Harness {
|
|
15
|
+
static component: string;
|
|
16
|
+
/** The input, as an `InputHarness`: its `label`, `description`, `isInvalid`, `fillIn()`… */
|
|
17
|
+
get input(): InputHarness;
|
|
18
|
+
/** The country picker, as a `SelectHarness`: its `options`, `open()`, `typeahead()`… */
|
|
19
|
+
get picker(): SelectHarness;
|
|
20
|
+
/** The `<input type="tel">` itself. */
|
|
21
|
+
get control(): HTMLInputElement;
|
|
22
|
+
/** The Input Group around the input and the picker. */
|
|
23
|
+
get group(): HTMLElement;
|
|
24
|
+
/** What the input shows, masked: `+1 212 555-0123`. */
|
|
25
|
+
get value(): string;
|
|
26
|
+
/** The country shown, as its ISO 3166 code (`US`). */
|
|
27
|
+
get country(): string;
|
|
28
|
+
/** The name of the country shown, as the picker reads it to assistive technology. */
|
|
29
|
+
get countryName(): string;
|
|
30
|
+
/** The flag the picker shows. */
|
|
31
|
+
get flag(): string;
|
|
32
|
+
/** The calling code beside the flag (`+1`), in the national format; `''` otherwise. */
|
|
33
|
+
get callingCode(): string;
|
|
34
|
+
/** The input's accessible name. */
|
|
35
|
+
get label(): string;
|
|
36
|
+
/** The text of what the input's `aria-describedby` names. */
|
|
37
|
+
get description(): string;
|
|
38
|
+
/** The input's placeholder. */
|
|
39
|
+
get placeholder(): string;
|
|
40
|
+
/** Whether the input and the picker are disabled. */
|
|
41
|
+
get isDisabled(): boolean;
|
|
42
|
+
/** Whether the input is marked invalid (`aria-invalid`), which rings the whole group. */
|
|
43
|
+
get isInvalid(): boolean;
|
|
44
|
+
/** Whether the input has focus. */
|
|
45
|
+
get isFocused(): boolean;
|
|
46
|
+
/** The country codes the picker offers, in order. It opens the picker to read them. */
|
|
47
|
+
countries(): Promise<string[]>;
|
|
48
|
+
/** Opens the picker and chooses the country with this ISO 3166 code. */
|
|
49
|
+
selectCountry(code: string): Promise<void>;
|
|
50
|
+
/** Types `text` at the end, one character at a time, as a keyboard does. */
|
|
51
|
+
typeText(text: string): Promise<void>;
|
|
52
|
+
/** Presses Backspace at the end, `times` times. */
|
|
53
|
+
backspace(times?: number): Promise<void>;
|
|
54
|
+
/** Selects everything and pastes `text` over it; an international number switches country. */
|
|
55
|
+
paste(text: string): Promise<void>;
|
|
56
|
+
/** Drops `text` at the end, as a drag and drop does; an international number switches country. */
|
|
57
|
+
drop(text: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Replaces the text at once, with an `input` and no `inputType`, as Chrome's autofill does;
|
|
60
|
+
* an international number switches country, and the mask shapes anything else.
|
|
61
|
+
*/
|
|
62
|
+
fillIn(text: string): Promise<void>;
|
|
63
|
+
/** Empties the input. */
|
|
64
|
+
clear(): Promise<void>;
|
|
65
|
+
/** Moves focus to the input. */
|
|
66
|
+
focus(): Promise<void>;
|
|
67
|
+
/** Takes focus off the input; a calling code with nothing after it comes out. */
|
|
68
|
+
blur(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=phone-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.d.ts","sourceRoot":"","sources":["../../src/test-support/phone-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAE,OAAO,E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O,CAAC,IAAI,CAAC;IAIxC,kGAAkG;IAC5F,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,yBAAyB;IACnB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,gCAAgC;IAC1B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,iFAAiF;IAC3E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { nativeValue } from '@ember-joinery/primitives/native-value';
|
|
2
|
+
import { inputClasses } from '@ember-joinery/ember/components/input';
|
|
3
|
+
import { maskito, maskText } from '../maskito.js';
|
|
4
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
5
|
+
import { setComponentTemplate } from '@ember/component';
|
|
6
|
+
import templateOnly from '@ember/component/template-only';
|
|
7
|
+
|
|
8
|
+
const CLASSES = inputClasses();
|
|
9
|
+
/**
|
|
10
|
+
* A text input that masks what is typed in it, with [Maskito](https://maskito.dev): Joinery's
|
|
11
|
+
* Input, in shadcn's look, with a mask on it.
|
|
12
|
+
*
|
|
13
|
+
* <MaskedInput @mask={{numberMask maximumFractionDigits=2}} @onValueChange={{this.setPrice}} />
|
|
14
|
+
* <MaskedInput @mask={{this.phoneMask}} @defaultValue="5551234567" placeholder="(555) 555-5555" />
|
|
15
|
+
*
|
|
16
|
+
* Its value is the masked text, controlled or not (`@value`, `@defaultValue`,
|
|
17
|
+
* `@onValueChange`), as Input's is. A value you pass is shown masked: `5551234567` shows as
|
|
18
|
+
* `(555) 123-4567`, and `@onValueChange` hears the masked text the next time it changes.
|
|
19
|
+
*/
|
|
20
|
+
const MaskedInput = setComponentTemplate(precompileTemplate("<input class={{CLASSES}} data-slot=\"input\" data-test-jn=\"masked-input\" data-test-jn-name={{@name}} {{nativeValue value=(maskText @value @mask) defaultValue=(maskText @defaultValue @mask) onValueChange=@onValueChange}} {{maskito @mask}} ...attributes />", {
|
|
21
|
+
strictMode: true,
|
|
22
|
+
scope: () => ({
|
|
23
|
+
CLASSES,
|
|
24
|
+
nativeValue,
|
|
25
|
+
maskText,
|
|
26
|
+
maskito
|
|
27
|
+
})
|
|
28
|
+
}), templateOnly());
|
|
29
|
+
|
|
30
|
+
export { MaskedInput as default };
|
|
31
|
+
//# sourceMappingURL=masked-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masked-input.js","sources":["../../src/components/masked-input.gts"],"sourcesContent":["import type { TOC } from '@ember/component/template-only'\nimport type { MaskitoOptions } from '@maskito/core'\nimport { nativeValue, type NativeValueArgs } from '@ember-joinery/primitives/native-value'\nimport { inputClasses } from '@ember-joinery/ember/components/input'\nimport { maskito, maskText } from '../maskito.ts'\n\nexport interface MaskedInputSignature {\n Args: NativeValueArgs & {\n /**\n * The Maskito options: a preset's (`numberMask`, `dateMask`, `timeMask`…) or your own\n * (`{ mask: ['(', /\\d/, /\\d/, /\\d/, ')', …] }`). Without it, the input takes anything.\n */\n mask?: MaskitoOptions | null\n /** The input's name, for its harness (`data-test-jn-name`). Its form field name is `name`. */\n name?: string\n }\n /** A native `<input>`: give it `placeholder`, `inputmode`, `disabled`, `aria-invalid`… */\n Element: HTMLInputElement\n}\n\nconst CLASSES = inputClasses()\n\n/**\n * A text input that masks what is typed in it, with [Maskito](https://maskito.dev): Joinery's\n * Input, in shadcn's look, with a mask on it.\n *\n * <MaskedInput @mask={{numberMask maximumFractionDigits=2}} @onValueChange={{this.setPrice}} />\n * <MaskedInput @mask={{this.phoneMask}} @defaultValue=\"5551234567\" placeholder=\"(555) 555-5555\" />\n *\n * Its value is the masked text, controlled or not (`@value`, `@defaultValue`,\n * `@onValueChange`), as Input's is. A value you pass is shown masked: `5551234567` shows as\n * `(555) 123-4567`, and `@onValueChange` hears the masked text the next time it changes.\n */\nconst MaskedInput: TOC<MaskedInputSignature> = <template>\n <input\n class={{CLASSES}}\n data-slot=\"input\"\n data-test-jn=\"masked-input\"\n data-test-jn-name={{@name}}\n {{nativeValue\n value=(maskText @value @mask)\n defaultValue=(maskText @defaultValue @mask)\n onValueChange=@onValueChange\n }}\n {{maskito @mask}}\n ...attributes\n />\n</template>\n\nexport default MaskedInput\n"],"names":["CLASSES","inputClasses","MaskedInput","setComponentTemplate","precompileTemplate","strictMode","scope","nativeValue","maskText","maskito","templateOnly"],"mappings":";;;;;;;AAoBA,MAAMA,OAAA,GAAUC,YAAA,EAAA;AAEhB;;;;;;;;;;AAUC;AACD,MAAMC,WAAiB,GAAAC,oBAAA,CAAwBC,kBAAA,CAAA,kQAAA,EAc/C;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAN,OAAA;IAAAO,WAAA;IAAAC,QAAA;AAAAC,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAC,YAAA,EAAA;;"}
|