@versatiles/svelte 0.1.0 → 0.1.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.
@@ -5,14 +5,13 @@ const dispatch = createEventDispatcher();
|
|
5
5
|
export let placeholder = "";
|
6
6
|
export let minChar = 0;
|
7
7
|
export let maxItems = 10;
|
8
|
-
export let initialText = "";
|
9
8
|
export let items;
|
10
9
|
let inputElement;
|
11
10
|
let autocompleteElement;
|
12
11
|
let isOpen = false;
|
13
12
|
let results = [];
|
14
|
-
let inputText = initialText;
|
15
13
|
let selectedIndex = 0;
|
14
|
+
let inputText = "";
|
16
15
|
const regExpEscape = (s) => s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
|
17
16
|
if (inputText.length >= minChar) {
|
18
17
|
const r = filterResults();
|
@@ -24,6 +23,12 @@ if (inputText.length >= minChar) {
|
|
24
23
|
inputText = "";
|
25
24
|
}
|
26
25
|
}
|
26
|
+
export function setInputText(text) {
|
27
|
+
console.log(text);
|
28
|
+
inputText = text;
|
29
|
+
results = filterResults();
|
30
|
+
close(0);
|
31
|
+
}
|
27
32
|
function onChange() {
|
28
33
|
if (inputText.length >= minChar) {
|
29
34
|
results = filterResults();
|
@@ -4,11 +4,11 @@ declare class __sveltets_Render<T> {
|
|
4
4
|
placeholder?: string;
|
5
5
|
minChar?: number;
|
6
6
|
maxItems?: number;
|
7
|
-
initialText?: string;
|
8
7
|
items: {
|
9
8
|
key: string;
|
10
9
|
value: T;
|
11
10
|
}[];
|
11
|
+
setInputText?: ((text: string) => void) | undefined;
|
12
12
|
};
|
13
13
|
events(): {
|
14
14
|
change: CustomEvent<any>;
|
@@ -21,5 +21,6 @@ export type AutoCompleteProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
21
21
|
export type AutoCompleteEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
22
22
|
export type AutoCompleteSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
23
23
|
export default class AutoComplete<T> extends SvelteComponent<AutoCompleteProps<T>, AutoCompleteEvents<T>, AutoCompleteSlots<T>> {
|
24
|
+
get setInputText(): (text: string) => void;
|
24
25
|
}
|
25
26
|
export {};
|
@@ -8,13 +8,14 @@ import BasicMap from "../BasicMap/BasicMap.svelte";
|
|
8
8
|
import { isDarkMode } from "../../utils/style.js";
|
9
9
|
let bboxes = void 0;
|
10
10
|
let mapContainer;
|
11
|
+
let autoComplete = void 0;
|
11
12
|
const worldBBox = [-180, -85, 180, 85];
|
12
13
|
const startTime = Date.now();
|
13
14
|
export let selectedBBox = worldBBox;
|
14
15
|
let map;
|
15
|
-
let initialCountry = getCountry();
|
16
16
|
onMount(async () => {
|
17
17
|
bboxes = await loadBBoxes();
|
18
|
+
start();
|
18
19
|
});
|
19
20
|
function handleMapReady(event) {
|
20
21
|
map = event.detail.map;
|
@@ -76,6 +77,13 @@ function handleMapReady(event) {
|
|
76
77
|
}
|
77
78
|
});
|
78
79
|
map.on("mouseup", () => dragging = false);
|
80
|
+
start();
|
81
|
+
}
|
82
|
+
function start() {
|
83
|
+
if (!bboxes) return;
|
84
|
+
if (!map) return;
|
85
|
+
if (!autoComplete) return;
|
86
|
+
autoComplete.setInputText(getCountry());
|
79
87
|
}
|
80
88
|
function redrawBBox() {
|
81
89
|
const bboxSource = map.getSource("bbox");
|
@@ -105,8 +113,8 @@ function flyTo(bbox) {
|
|
105
113
|
<AutoComplete
|
106
114
|
items={bboxes}
|
107
115
|
placeholder="Find country, region or city …"
|
108
|
-
initialText={initialCountry}
|
109
116
|
on:change={(e) => flyTo(e.detail)}
|
117
|
+
bind:this={autoComplete}
|
110
118
|
/>
|
111
119
|
</div>
|
112
120
|
{/if}
|