@dk-address/core 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dyrhoi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @dk-address/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The behaviour of a Danish address field without a framework: search on [KDS Adressevælger](https://confluence.kds.dk/spaces/ADV/pages/234782998), caret placement and the details lookup. Use it from vanilla JavaScript, Vue, Svelte or web components. For React, use [`@dk-address/react`](https://www.npmjs.com/package/@dk-address/react).
4
+
5
+ ```sh
6
+ npm i @dk-address/core
7
+ ```
8
+
9
+ Read the [Core reference](https://dk-address.dyrhoi.com/docs/reference/core) to connect it to your own input.
@@ -0,0 +1,11 @@
1
+ import type { AccessAddress, AccessAddressSuggestion, Suggestion } from "@dk-address/client";
2
+ /**
3
+ * KDS only matches whole house numbers, so `Vesterbrogade 2, 1620` finds nothing while
4
+ * someone types "28". This matches the street's house numbers by prefix instead.
5
+ */
6
+ export declare function matchHouseNumbers(accessAddresses: readonly AccessAddress[], typed: string): AccessAddressSuggestion[];
7
+ /**
8
+ * Server results first, then prefix matches the server did not already return, either as
9
+ * the access address itself or as one of its addresses.
10
+ */
11
+ export declare function mergeSuggestions(server: readonly Suggestion[], local: readonly Suggestion[], limit: number): Suggestion[];
@@ -0,0 +1,35 @@
1
+ const collator = new Intl.Collator("da", { numeric: true, sensitivity: "base" });
2
+ /**
3
+ * KDS only matches whole house numbers, so `Vesterbrogade 2, 1620` finds nothing while
4
+ * someone types "28". This matches the street's house numbers by prefix instead.
5
+ */
6
+ export function matchHouseNumbers(accessAddresses, typed) {
7
+ const prefix = typed.trim().toLowerCase();
8
+ if (!prefix)
9
+ return [];
10
+ return accessAddresses
11
+ .filter((accessAddress) => accessAddress.houseNumber.toLowerCase().startsWith(prefix))
12
+ .toSorted((a, b) => collator.compare(a.houseNumber, b.houseNumber))
13
+ .map((accessAddress) => ({
14
+ type: "accessAddress",
15
+ id: accessAddress.id,
16
+ label: accessAddress.label,
17
+ streetName: accessAddress.streetName,
18
+ houseNumber: accessAddress.houseNumber,
19
+ }));
20
+ }
21
+ /**
22
+ * Server results first, then prefix matches the server did not already return, either as
23
+ * the access address itself or as one of its addresses.
24
+ */
25
+ export function mergeSuggestions(server, local, limit) {
26
+ const seen = new Set();
27
+ for (const suggestion of server) {
28
+ if ("id" in suggestion)
29
+ seen.add(suggestion.id);
30
+ if (suggestion.type === "address")
31
+ seen.add(suggestion.accessAddressId);
32
+ }
33
+ const extra = local.filter((suggestion) => !("id" in suggestion) || !seen.has(suggestion.id));
34
+ return [...server, ...extra].slice(0, limit);
35
+ }
@@ -0,0 +1,5 @@
1
+ export { createAddressAutosuggest, type AddressAutosuggest, type AutosuggestOptions, type AutosuggestState, type AutosuggestStatus, type Caret, type SelectedDetails, type SelectedSuggestion, type Selection, } from "./store.ts";
2
+ export { matchHouseNumbers, mergeSuggestions } from "./house-numbers.ts";
3
+ export { planSelection, type SelectionPlan, type SlotKind, type SlotTemplate } from "./refine.ts";
4
+ export { readSlot, type Slot } from "./slot.ts";
5
+ export { suggestionKey } from "@dk-address/client";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { createAddressAutosuggest, } from "./store.js";
2
+ export { matchHouseNumbers, mergeSuggestions } from "./house-numbers.js";
3
+ export { planSelection } from "./refine.js";
4
+ export { readSlot } from "./slot.js";
5
+ export { suggestionKey } from "@dk-address/client";
@@ -0,0 +1,34 @@
1
+ import type { SearchKind, Suggestion } from "@dk-address/client";
2
+ /** What the empty gap at the caret is waiting for. */
3
+ export type SlotKind = "houseNumber" | "unit";
4
+ /**
5
+ * The text around the gap a refinement leaves at the caret. While the input still starts
6
+ * with `before` and ends with `after`, whatever sits between them is the slot.
7
+ */
8
+ export interface SlotTemplate {
9
+ before: string;
10
+ after: string;
11
+ kind: SlotKind;
12
+ /** Set for `houseNumber` slots: the street the house number belongs to. */
13
+ streetId?: string;
14
+ }
15
+ export type SelectionPlan = {
16
+ /** Not done yet: put `value` in the input, move the caret, keep the list open and search again. */
17
+ action: "refine";
18
+ value: string;
19
+ caret: number;
20
+ template: SlotTemplate | null;
21
+ } | {
22
+ /** Done: put `value` in the input, close the list and look up the details. */
23
+ action: "complete";
24
+ value: string;
25
+ caret: number;
26
+ };
27
+ /**
28
+ * Decide what picking a suggestion does to the input. The gap uses KDS's own punctuation,
29
+ * so typing into it produces the canonical title:
30
+ *
31
+ * street Vesterbrogade |, 1620 København V
32
+ * access address Vesterbrogade 28, |, 1620 København V (address search only)
33
+ */
34
+ export declare function planSelection(suggestion: Suggestion, kind: SearchKind): SelectionPlan;
package/dist/refine.js ADDED
@@ -0,0 +1,41 @@
1
+ function refine(before, after, kind, streetId) {
2
+ return {
3
+ action: "refine",
4
+ value: before + after,
5
+ caret: before.length,
6
+ template: streetId ? { before, after, kind, streetId } : { before, after, kind },
7
+ };
8
+ }
9
+ function refineAtEnd(value) {
10
+ return { action: "refine", value, caret: value.length, template: null };
11
+ }
12
+ function complete(value) {
13
+ return { action: "complete", value, caret: value.length };
14
+ }
15
+ /**
16
+ * Decide what picking a suggestion does to the input. The gap uses KDS's own punctuation,
17
+ * so typing into it produces the canonical title:
18
+ *
19
+ * street Vesterbrogade |, 1620 København V
20
+ * access address Vesterbrogade 28, |, 1620 København V (address search only)
21
+ */
22
+ export function planSelection(suggestion, kind) {
23
+ switch (suggestion.type) {
24
+ case "streetName":
25
+ return refineAtEnd(`${suggestion.streetName} `);
26
+ case "streetNameNumber":
27
+ return refineAtEnd(suggestion.label);
28
+ case "street":
29
+ return refine(`${suggestion.streetName} `, `, ${suggestion.postalCode} ${suggestion.postalDistrict}`, "houseNumber", suggestion.id);
30
+ case "accessAddress": {
31
+ if (kind === "accessAddress")
32
+ return complete(suggestion.label);
33
+ const prefix = `${suggestion.streetName} ${suggestion.houseNumber}, `;
34
+ if (!suggestion.label.startsWith(prefix))
35
+ return refineAtEnd(suggestion.label);
36
+ return refine(prefix, `, ${suggestion.label.slice(prefix.length)}`, "unit");
37
+ }
38
+ case "address":
39
+ return complete(suggestion.label);
40
+ }
41
+ }
package/dist/slot.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { SlotKind, SlotTemplate } from "./refine.ts";
2
+ export interface Slot {
3
+ /** Index in the input value where the slot starts. */
4
+ start: number;
5
+ /** Index in the input value where the slot ends. */
6
+ end: number;
7
+ kind: SlotKind;
8
+ /** What the user has typed into the slot so far. */
9
+ text: string;
10
+ }
11
+ /** Find the slot in `value`, or `null` once the user has edited outside it. */
12
+ export declare function readSlot(value: string, template: SlotTemplate): Slot | null;
package/dist/slot.js ADDED
@@ -0,0 +1,11 @@
1
+ /** Find the slot in `value`, or `null` once the user has edited outside it. */
2
+ export function readSlot(value, template) {
3
+ const { before, after } = template;
4
+ if (value.length < before.length + after.length)
5
+ return null;
6
+ if (!value.startsWith(before) || !value.endsWith(after))
7
+ return null;
8
+ const start = before.length;
9
+ const end = value.length - after.length;
10
+ return { start, end, kind: template.kind, text: value.slice(start, end) };
11
+ }
@@ -0,0 +1,69 @@
1
+ import { type AccessAddress, type AccessAddressSuggestion, type Address, type AddressSuggestion, type AdressevaelgerClient, type SearchKind, type Suggestion } from "@dk-address/client";
2
+ import { type Slot } from "./slot.ts";
3
+ export type AutosuggestStatus = "idle" | "loading" | "success" | "error";
4
+ /** The suggestion types that finish a search. */
5
+ export type SelectedSuggestion = AddressSuggestion | AccessAddressSuggestion;
6
+ export type SelectedDetails = Address | AccessAddress;
7
+ export interface Selection {
8
+ suggestion: SelectedSuggestion;
9
+ /** `loading` while details are fetched. Always `success` when `fetchDetails` is off. */
10
+ status: "loading" | "success" | "error";
11
+ details: SelectedDetails | null;
12
+ error: unknown;
13
+ }
14
+ /** Where the input's caret should go. `revision` changes every time the store moves it. */
15
+ export interface Caret {
16
+ position: number;
17
+ revision: number;
18
+ }
19
+ export interface AutosuggestState {
20
+ value: string;
21
+ /** Set when the store wants the caret moved (after a pick). `null` while the user types. */
22
+ caret: Caret | null;
23
+ /** The gap a refinement left, while the user is filling it. */
24
+ slot: Slot | null;
25
+ suggestions: readonly Suggestion[];
26
+ status: AutosuggestStatus;
27
+ error: unknown;
28
+ /** Whether the suggestion list should show. Bindings also hide it when it is empty. */
29
+ open: boolean;
30
+ selection: Selection | null;
31
+ }
32
+ export interface AutosuggestOptions {
33
+ /** Defaults to `createClient()`. */
34
+ client?: AdressevaelgerClient;
35
+ /** Defaults to `"address"`. */
36
+ kind?: SearchKind;
37
+ /** Delay before searching while typing. Defaults to 100. Picks search immediately. */
38
+ debounceMs?: number;
39
+ /** 1 to 200. Defaults to KDS's 100. */
40
+ limit?: number;
41
+ municipalityCodes?: readonly (string | number)[];
42
+ includeProvisional?: boolean;
43
+ /**
44
+ * Fetch the street's house numbers after a street is picked and match them by prefix
45
+ * (KDS itself only matches whole house numbers). About 20 KB gzipped per street. Defaults to true.
46
+ */
47
+ houseNumberPrefix?: boolean;
48
+ /** Look up the full address after a final pick. Defaults to true. */
49
+ fetchDetails?: boolean;
50
+ /** Called after a final pick, once details are loaded (or straight away without `fetchDetails`). */
51
+ onSelect?: (selection: Selection) => void;
52
+ }
53
+ export interface AddressAutosuggest {
54
+ getState(): AutosuggestState;
55
+ subscribe(listener: () => void): () => void;
56
+ /** Call on every input change. */
57
+ setInput(value: string): void;
58
+ /** Pick a suggestion: refines the text or finishes the search depending on its type. */
59
+ select(suggestion: Suggestion): Promise<void>;
60
+ /** Prefill from a stored id (an address id, or an access address id when `kind` is `accessAddress`). */
61
+ selectById(id: string): Promise<Selection | null>;
62
+ setOpen(open: boolean): void;
63
+ /** Change options. Changing `kind`, `limit`, `municipalityCodes` or `includeProvisional` searches again. */
64
+ setOptions(options: AutosuggestOptions): void;
65
+ clear(): void;
66
+ /** Cancel pending timers and requests. The store stays usable afterwards. */
67
+ destroy(): void;
68
+ }
69
+ export declare function createAddressAutosuggest(initialOptions?: AutosuggestOptions): AddressAutosuggest;
package/dist/store.js ADDED
@@ -0,0 +1,318 @@
1
+ import { createClient, isAbortError, sanitizeQuery, } from "@dk-address/client";
2
+ import { matchHouseNumbers, mergeSuggestions } from "./house-numbers.js";
3
+ import { planSelection } from "./refine.js";
4
+ import { readSlot } from "./slot.js";
5
+ const DEFAULT_LIMIT = 100;
6
+ const initialState = {
7
+ value: "",
8
+ caret: null,
9
+ slot: null,
10
+ suggestions: [],
11
+ status: "idle",
12
+ error: null,
13
+ open: false,
14
+ selection: null,
15
+ };
16
+ export function createAddressAutosuggest(initialOptions = {}) {
17
+ let rawOptions = initialOptions;
18
+ let defaultClient;
19
+ const client = () => rawOptions.client ?? (defaultClient ??= createClient());
20
+ const kind = () => rawOptions.kind ?? "address";
21
+ let state = initialState;
22
+ const listeners = new Set();
23
+ let template = null;
24
+ let serverResults = [];
25
+ let serverResultsFor = null;
26
+ let timer;
27
+ let searchController;
28
+ let detailsController;
29
+ let searchSequence = 0;
30
+ let caretRevision = 0;
31
+ const streets = new Map();
32
+ function setState(patch) {
33
+ state = { ...state, ...patch };
34
+ for (const listener of listeners)
35
+ listener();
36
+ }
37
+ function moveCaret(position) {
38
+ caretRevision += 1;
39
+ return { position, revision: caretRevision };
40
+ }
41
+ function localMatches(slot) {
42
+ if (rawOptions.houseNumberPrefix === false ||
43
+ slot?.kind !== "houseNumber" ||
44
+ !template?.streetId) {
45
+ return [];
46
+ }
47
+ const accessAddresses = streets.get(template.streetId);
48
+ return Array.isArray(accessAddresses) ? matchHouseNumbers(accessAddresses, slot.text) : [];
49
+ }
50
+ function currentSuggestions() {
51
+ const server = serverResultsFor === state.value ? serverResults : [];
52
+ return mergeSuggestions(server, localMatches(state.slot), rawOptions.limit ?? DEFAULT_LIMIT);
53
+ }
54
+ function prefetchStreet(streetId) {
55
+ if (streets.has(streetId))
56
+ return;
57
+ streets.set(streetId, "loading");
58
+ client()
59
+ .getStreetAccessAddresses(streetId)
60
+ .then((accessAddresses) => {
61
+ streets.set(streetId, accessAddresses);
62
+ if (template?.streetId === streetId && state.slot?.kind === "houseNumber") {
63
+ setState({ suggestions: currentSuggestions() });
64
+ }
65
+ }, () => {
66
+ // Prefix matching is a bonus; without it the server's exact matches still show.
67
+ streets.delete(streetId);
68
+ });
69
+ }
70
+ function cancelSearch() {
71
+ clearTimeout(timer);
72
+ timer = undefined;
73
+ searchController?.abort();
74
+ searchController = undefined;
75
+ searchSequence += 1;
76
+ }
77
+ function scheduleSearch(immediate) {
78
+ clearTimeout(timer);
79
+ timer = undefined;
80
+ const value = state.value;
81
+ if (!sanitizeQuery(value)) {
82
+ cancelSearch();
83
+ serverResults = [];
84
+ serverResultsFor = value;
85
+ setState({ suggestions: [], status: "idle", error: null, open: false });
86
+ return;
87
+ }
88
+ const debounceMs = rawOptions.debounceMs ?? 100;
89
+ if (immediate || debounceMs <= 0) {
90
+ void runSearch(value);
91
+ }
92
+ else {
93
+ timer = setTimeout(() => void runSearch(value), debounceMs);
94
+ }
95
+ }
96
+ async function runSearch(value) {
97
+ timer = undefined;
98
+ searchController?.abort();
99
+ const controller = new AbortController();
100
+ searchController = controller;
101
+ searchSequence += 1;
102
+ const sequence = searchSequence;
103
+ setState({ status: "loading", error: null });
104
+ try {
105
+ const results = await client().search(value, {
106
+ kind: kind(),
107
+ limit: rawOptions.limit,
108
+ municipalityCodes: rawOptions.municipalityCodes,
109
+ includeProvisional: rawOptions.includeProvisional,
110
+ signal: controller.signal,
111
+ });
112
+ if (sequence !== searchSequence || value !== state.value)
113
+ return;
114
+ serverResults = results;
115
+ serverResultsFor = value;
116
+ setState({ status: "success", suggestions: currentSuggestions() });
117
+ }
118
+ catch (error) {
119
+ if (sequence !== searchSequence || isAbortError(error) || value !== state.value)
120
+ return;
121
+ serverResults = [];
122
+ serverResultsFor = value;
123
+ setState({ status: "error", error, suggestions: currentSuggestions() });
124
+ }
125
+ finally {
126
+ if (searchController === controller)
127
+ searchController = undefined;
128
+ }
129
+ }
130
+ async function loadDetails(suggestion) {
131
+ detailsController?.abort();
132
+ const controller = new AbortController();
133
+ detailsController = controller;
134
+ const isCurrent = () => !controller.signal.aborted && state.selection?.suggestion === suggestion;
135
+ try {
136
+ const details = suggestion.type === "address"
137
+ ? await client().getAddress(suggestion.id, { signal: controller.signal })
138
+ : await client().getAccessAddress(suggestion.id, { signal: controller.signal });
139
+ if (!isCurrent())
140
+ return;
141
+ if (!details) {
142
+ setState({
143
+ selection: {
144
+ suggestion,
145
+ status: "error",
146
+ details: null,
147
+ error: new Error(`KDS has no ${suggestion.type} with id ${suggestion.id}`),
148
+ },
149
+ });
150
+ return;
151
+ }
152
+ const selection = { suggestion, status: "success", details, error: null };
153
+ setState({ selection });
154
+ rawOptions.onSelect?.(selection);
155
+ }
156
+ catch (error) {
157
+ if (!isCurrent() || isAbortError(error))
158
+ return;
159
+ setState({ selection: { suggestion, status: "error", details: null, error } });
160
+ }
161
+ }
162
+ const store = {
163
+ getState: () => state,
164
+ subscribe(listener) {
165
+ listeners.add(listener);
166
+ return () => listeners.delete(listener);
167
+ },
168
+ setInput(value) {
169
+ if (value === state.value)
170
+ return;
171
+ let slot = null;
172
+ if (template) {
173
+ slot = readSlot(value, template);
174
+ if (!slot)
175
+ template = null;
176
+ }
177
+ const selection = state.selection?.suggestion.label === value ? state.selection : null;
178
+ if (!selection)
179
+ detailsController?.abort();
180
+ setState({ value, caret: null, slot, selection, open: sanitizeQuery(value) !== "" });
181
+ // Show prefix matches straight away instead of waiting for the debounced search.
182
+ const local = localMatches(slot);
183
+ if (local.length > 0)
184
+ setState({ suggestions: currentSuggestions() });
185
+ scheduleSearch(false);
186
+ },
187
+ async select(suggestion) {
188
+ const plan = planSelection(suggestion, kind());
189
+ if (plan.action === "refine") {
190
+ template = plan.template;
191
+ if (template?.streetId && rawOptions.houseNumberPrefix !== false)
192
+ prefetchStreet(template.streetId);
193
+ detailsController?.abort();
194
+ setState({
195
+ value: plan.value,
196
+ caret: moveCaret(plan.caret),
197
+ slot: template ? readSlot(plan.value, template) : null,
198
+ selection: null,
199
+ open: true,
200
+ });
201
+ scheduleSearch(true);
202
+ return;
203
+ }
204
+ if (suggestion.type !== "address" && suggestion.type !== "accessAddress")
205
+ return;
206
+ cancelSearch();
207
+ template = null;
208
+ const fetchDetails = rawOptions.fetchDetails !== false;
209
+ const selection = {
210
+ suggestion,
211
+ status: fetchDetails ? "loading" : "success",
212
+ details: null,
213
+ error: null,
214
+ };
215
+ setState({
216
+ value: plan.value,
217
+ caret: moveCaret(plan.caret),
218
+ slot: null,
219
+ open: false,
220
+ selection,
221
+ });
222
+ if (fetchDetails) {
223
+ await loadDetails(suggestion);
224
+ }
225
+ else {
226
+ rawOptions.onSelect?.(selection);
227
+ }
228
+ },
229
+ async selectById(id) {
230
+ cancelSearch();
231
+ template = null;
232
+ detailsController?.abort();
233
+ const controller = new AbortController();
234
+ detailsController = controller;
235
+ const signal = controller.signal;
236
+ try {
237
+ const details = kind() === "address"
238
+ ? await client().getAddress(id, { signal })
239
+ : await client().getAccessAddress(id, { signal });
240
+ if (signal.aborted || !details)
241
+ return null;
242
+ const suggestion = details.type === "address"
243
+ ? {
244
+ type: "address",
245
+ id: details.id,
246
+ label: details.label,
247
+ accessAddressId: details.accessAddress.id,
248
+ }
249
+ : {
250
+ type: "accessAddress",
251
+ id: details.id,
252
+ label: details.label,
253
+ streetName: details.streetName,
254
+ houseNumber: details.houseNumber,
255
+ };
256
+ const selection = { suggestion, status: "success", details, error: null };
257
+ serverResults = [];
258
+ serverResultsFor = null;
259
+ setState({
260
+ value: details.label,
261
+ caret: moveCaret(details.label.length),
262
+ slot: null,
263
+ suggestions: [],
264
+ status: "idle",
265
+ error: null,
266
+ open: false,
267
+ selection,
268
+ });
269
+ rawOptions.onSelect?.(selection);
270
+ return selection;
271
+ }
272
+ catch (error) {
273
+ if (signal.aborted || isAbortError(error))
274
+ return null;
275
+ setState({ status: "error", error });
276
+ return null;
277
+ }
278
+ },
279
+ setOpen(open) {
280
+ if (open !== state.open)
281
+ setState({ open });
282
+ },
283
+ setOptions(next) {
284
+ const before = rawOptions;
285
+ rawOptions = { ...rawOptions, ...next };
286
+ const kindChanged = (before.kind ?? "address") !== kind();
287
+ // A new client is used from the next search on. Searching again here would loop in
288
+ // React components that create their client inline on every render.
289
+ const searchChanged = kindChanged ||
290
+ before.limit !== rawOptions.limit ||
291
+ before.includeProvisional !== rawOptions.includeProvisional ||
292
+ String(before.municipalityCodes ?? "") !== String(rawOptions.municipalityCodes ?? "");
293
+ if (kindChanged) {
294
+ template = null;
295
+ detailsController?.abort();
296
+ setState({ slot: null, selection: null });
297
+ }
298
+ if (searchChanged && sanitizeQuery(state.value)) {
299
+ serverResultsFor = null;
300
+ setState({ open: true });
301
+ scheduleSearch(true);
302
+ }
303
+ },
304
+ clear() {
305
+ cancelSearch();
306
+ detailsController?.abort();
307
+ template = null;
308
+ serverResults = [];
309
+ serverResultsFor = null;
310
+ setState({ ...initialState, caret: moveCaret(0) });
311
+ },
312
+ destroy() {
313
+ cancelSearch();
314
+ detailsController?.abort();
315
+ },
316
+ };
317
+ return store;
318
+ }
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@dk-address/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Framework-free state machine for Danish address autocomplete on KDS Adressevælger, with caret placement.",
5
+ "keywords": [
6
+ "address",
7
+ "adressevaelger",
8
+ "autocomplete",
9
+ "danish",
10
+ "dar",
11
+ "dawa",
12
+ "denmark",
13
+ "kds"
14
+ ],
15
+ "homepage": "https://dk-address.dyrhoi.com/docs",
16
+ "bugs": "https://github.com/Dyrhoi/dk-address/issues",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Dyrhoi/dk-address.git",
21
+ "directory": "packages/core"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
39
+ "lint": "bun lint --deny-warnings",
40
+ "typecheck": "bun check",
41
+ "test": "vitest run"
42
+ },
43
+ "dependencies": {
44
+ "@dk-address/client": "0.1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@repo/kds-fixtures": "0.0.0",
48
+ "@repo/oxlint-config": "0.0.0",
49
+ "@repo/typescript-config": "0.0.0",
50
+ "@types/bun": "1.4.5",
51
+ "vitest": "5.1.1"
52
+ },
53
+ "main": "./dist/index.js",
54
+ "types": "./dist/index.d.ts"
55
+ }