@stubber/form-fields 2.2.0 → 2.2.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.
|
@@ -12,13 +12,12 @@
|
|
|
12
12
|
|
|
13
13
|
<script>import { Button } from "@stubber/ui/button";
|
|
14
14
|
import * as Collapsible from "@stubber/ui/collapsible";
|
|
15
|
+
import { Label } from "@stubber/ui/label";
|
|
15
16
|
import { get as get_store_value } from "svelte/store";
|
|
16
|
-
import
|
|
17
|
+
import FieldExprToggle from "../FieldExprToggle.svelte";
|
|
17
18
|
import FieldMessage from "../FieldMessage.svelte";
|
|
18
19
|
import FormField from "../form-field.svelte";
|
|
19
20
|
import { build_field } from "../utils";
|
|
20
|
-
import FieldExprToggle from "../FieldExprToggle.svelte";
|
|
21
|
-
import { Label } from "@stubber/ui/label";
|
|
22
21
|
export let fieldStore;
|
|
23
22
|
const new_entry_field = $fieldStore?.params?.new_entry_field || {
|
|
24
23
|
fieldtype: "text"
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
<script context="module">import {} from "../interfaces";
|
|
2
2
|
</script>
|
|
3
3
|
|
|
4
|
-
<script>import intlTelInput from "intl-tel-input";
|
|
5
|
-
import "intl-tel-input/
|
|
4
|
+
<script>import intlTelInput, { Iti } from "intl-tel-input";
|
|
5
|
+
import "intl-tel-input/styles";
|
|
6
6
|
import FieldLabel from "../FieldLabel.svelte";
|
|
7
7
|
import FieldMessage from "../FieldMessage.svelte";
|
|
8
8
|
import { set_value_details } from "../utils";
|
|
9
9
|
export let fieldStore;
|
|
10
|
-
let iti;
|
|
10
|
+
let iti = null;
|
|
11
11
|
function setupInput(input_element) {
|
|
12
|
+
setup_intl_tel_input(input_element);
|
|
13
|
+
}
|
|
14
|
+
async function setup_intl_tel_input(input_element) {
|
|
12
15
|
iti = intlTelInput(input_element, {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
fetch("https://ipapi.co/json")
|
|
16
|
+
loadUtils: () => import("intl-tel-input/utils"),
|
|
17
|
+
initialCountryLookup: async () => {
|
|
18
|
+
const res = await fetch("https://ipapi.co/json");
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
return data?.country_code || "us";
|
|
16
21
|
},
|
|
17
|
-
|
|
22
|
+
separateDialCode: false
|
|
18
23
|
});
|
|
19
24
|
const itis = document.querySelectorAll("div.iti");
|
|
20
25
|
itis.forEach((iti2) => {
|
|
21
26
|
iti2.style["width"] = "100%";
|
|
22
27
|
});
|
|
23
28
|
input_element.addEventListener("countrychange", () => set_number_details());
|
|
29
|
+
await iti.promise;
|
|
24
30
|
set_number_details();
|
|
25
31
|
}
|
|
26
|
-
$: if ($fieldStore.value) set_number_details();
|
|
27
32
|
let last_set_value = null;
|
|
28
33
|
function set_number_details(force = false) {
|
|
29
34
|
if (!iti) return;
|
|
@@ -31,9 +36,8 @@ function set_number_details(force = false) {
|
|
|
31
36
|
last_set_value = $fieldStore.value;
|
|
32
37
|
const formatted_number = iti.getNumber();
|
|
33
38
|
const is_valid = iti.isValidNumber();
|
|
34
|
-
const country_data = iti.
|
|
35
|
-
|
|
36
|
-
if (is_valid && (force || formatted_number !== $fieldStore.value)) {
|
|
39
|
+
const country_data = iti.getSelectedCountry();
|
|
40
|
+
if (is_valid && formatted_number !== $fieldStore.value) {
|
|
37
41
|
$fieldStore.value = formatted_number;
|
|
38
42
|
}
|
|
39
43
|
if ($fieldStore.value) {
|
|
@@ -43,24 +47,19 @@ function set_number_details(force = false) {
|
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
if ($fieldStore.value) {
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
$fieldStore.value = $fieldStore.value || "";
|
|
49
|
-
set_number_details(true);
|
|
50
|
-
}, 100);
|
|
51
|
-
}
|
|
52
50
|
</script>
|
|
53
51
|
|
|
54
52
|
<FieldLabel {fieldStore} />
|
|
55
53
|
<div
|
|
56
|
-
class="
|
|
54
|
+
class="relative mt-2 flex w-full space-x-4 rounded-md bg-surface-100 focus:outline-primary-400"
|
|
57
55
|
>
|
|
58
56
|
<input
|
|
59
57
|
use:setupInput
|
|
60
58
|
bind:value={$fieldStore.value}
|
|
59
|
+
on:input={() => set_number_details()}
|
|
61
60
|
type="tel"
|
|
62
61
|
id={$fieldStore.id}
|
|
63
|
-
class="
|
|
62
|
+
class="shadow-xs flex h-9 w-full min-w-0 rounded-md border border-input bg-background px-3 py-1 text-base outline-none ring-offset-background transition-[color,box-shadow] selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid]:border-destructive aria-[invalid]:ring-destructive/50 aria-[invalid]:focus-visible:ring-destructive/50 md:text-sm dark:bg-input/30"
|
|
64
63
|
aria-invalid={$fieldStore.validation_result?.type == "error" ? true : undefined}
|
|
65
64
|
aria-describedby="message-{$fieldStore.id}"
|
|
66
65
|
/>
|
|
@@ -6,7 +6,7 @@ export interface ITelephoneFieldParams {
|
|
|
6
6
|
export interface ITelephoneField extends IBaseField<ITelephoneFieldParams> {
|
|
7
7
|
fieldtype: "telephone";
|
|
8
8
|
}
|
|
9
|
-
import "intl-tel-input/
|
|
9
|
+
import "intl-tel-input/styles";
|
|
10
10
|
declare const __propDef: {
|
|
11
11
|
props: {
|
|
12
12
|
fieldStore: Writable<IBuiltField<ITelephoneFieldParams>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stubber/form-fields",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "An automatic form builder based on field specifications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"fast-equals": "^5.0.1",
|
|
75
75
|
"github-markdown-css": "^5.2.0",
|
|
76
76
|
"html5-qrcode": "^2.3.8",
|
|
77
|
-
"intl-tel-input": "^
|
|
77
|
+
"intl-tel-input": "^29.1.1",
|
|
78
78
|
"jsonata": "^2.0.3",
|
|
79
79
|
"lodash-es": "^4.17.21",
|
|
80
80
|
"markdown-it": "^13.0.1",
|