@ideal-postcodes/address-finder
Advanced tools
Comparing version 4.3.0 to 4.4.0
@@ -595,2 +595,3 @@ /** | ||
updateContexts(contexts: ContextStore): void; | ||
filteredContexts(): ContextDetails[]; | ||
/** | ||
@@ -660,2 +661,3 @@ * Render available country options | ||
query(): string; | ||
clearInput(): void; | ||
/** | ||
@@ -662,0 +664,0 @@ * Set address finder suggestions |
@@ -357,2 +357,18 @@ "use strict"; | ||
} | ||
filteredContexts() { | ||
const q = this.query(); | ||
if (q.trim().length === 0) | ||
return this.contextSuggestions; | ||
const f = q.toLowerCase().trim().replace(/\s+/g, " "); | ||
const regexp = new RegExp("^" + f); | ||
return this.contextSuggestions.filter((e) => { | ||
if (regexp.test(e.description.toLowerCase())) | ||
return true; | ||
if (e.iso_2.toLowerCase() === f) | ||
return true; | ||
if (e.iso_3.toLowerCase() === f) | ||
return true; | ||
return false; | ||
}); | ||
} | ||
/** | ||
@@ -363,3 +379,3 @@ * Render available country options | ||
this.list.innerHTML = ""; | ||
this.contextSuggestions.forEach((contextDetails, i) => { | ||
this.filteredContexts().forEach((contextDetails, i) => { | ||
const { description } = contextDetails; | ||
@@ -566,2 +582,5 @@ const li = this.options.document.createElement("li"); | ||
} | ||
clearInput() { | ||
(0, jsutil_1.update)(this.input, ""); | ||
} | ||
/** | ||
@@ -799,3 +818,3 @@ * Set address finder suggestions | ||
if (key === "Enter") { | ||
const contextDetails = c.contextSuggestions[c.current]; | ||
const contextDetails = c.filteredContexts()[c.current]; | ||
if (contextDetails) | ||
@@ -802,0 +821,0 @@ c.fsm.send({ type: "SELECT_COUNTRY", contextDetails }); |
@@ -59,27 +59,11 @@ import { StateMachine } from "@xstate/fsm"; | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
export type ViewMachine = StateMachine.Machine<Context, Events, States>; | ||
/** | ||
* @hidden | ||
*/ | ||
export type ViewService = StateMachine.Service<Context, Events, States>; | ||
/** | ||
* @hidden | ||
*/ | ||
interface Create { | ||
(options: CreateOptions): ViewService; | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
export interface CreateOptions { | ||
c: Controller; | ||
} | ||
/** | ||
* Creates a finite state machine that drives Address Finder UI | ||
* @hidden | ||
*/ | ||
export declare const create: Create; | ||
export {}; |
@@ -5,44 +5,3 @@ "use strict"; | ||
const fsm_1 = require("@xstate/fsm"); | ||
/** | ||
* @hidden | ||
*/ | ||
const INPUT = { INPUT: { actions: "input" } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const CLOSE = { CLOSE: "closed" }; | ||
/** | ||
* @hidden | ||
*/ | ||
const SUGGEST = { | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
const NOTIFY = { | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
const NEXT = { NEXT: { actions: ["next", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const PREVIOUS = { PREVIOUS: { actions: ["previous", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const RESET = { RESET: { actions: ["resetCurrent", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const CHANGE_COUNTRY = { | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
}; | ||
/** | ||
* Creates a finite state machine that drives Address Finder UI | ||
* @hidden | ||
*/ | ||
// @hidden | ||
const create = ({ c }) => { | ||
@@ -71,18 +30,30 @@ const machine = (0, fsm_1.createMachine)({ | ||
on: { | ||
...CLOSE, | ||
...SUGGEST, | ||
...NOTIFY, | ||
...INPUT, | ||
...CHANGE_COUNTRY, | ||
CLOSE: "closed", | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
INPUT: { actions: "input" }, | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
}, | ||
}, | ||
suggesting_country: { | ||
entry: ["renderContexts", "gotoCurrent", "expand", "addCountryHint"], | ||
exit: ["resetCurrent", "gotoCurrent", "contract", "clearHint"], | ||
entry: [ | ||
"clearInput", | ||
"renderContexts", | ||
"gotoCurrent", | ||
"expand", | ||
"addCountryHint", | ||
], | ||
exit: [ | ||
"resetCurrent", | ||
"gotoCurrent", | ||
"contract", | ||
"clearHint", | ||
"clearInput", | ||
], | ||
on: { | ||
...CLOSE, | ||
...NOTIFY, | ||
...NEXT, | ||
...PREVIOUS, | ||
...RESET, | ||
CLOSE: "closed", | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
NEXT: { actions: ["next", "gotoCurrent"] }, | ||
PREVIOUS: { actions: ["previous", "gotoCurrent"] }, | ||
RESET: { actions: ["resetCurrent", "gotoCurrent"] }, | ||
INPUT: { | ||
@@ -101,10 +72,10 @@ actions: ["countryInput"], | ||
on: { | ||
...CLOSE, | ||
...SUGGEST, | ||
...NOTIFY, | ||
...INPUT, | ||
...CHANGE_COUNTRY, | ||
...NEXT, | ||
...PREVIOUS, | ||
...RESET, | ||
CLOSE: "closed", | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
INPUT: { actions: "input" }, | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
NEXT: { actions: ["next", "gotoCurrent"] }, | ||
PREVIOUS: { actions: ["previous", "gotoCurrent"] }, | ||
RESET: { actions: ["resetCurrent", "gotoCurrent"] }, | ||
SELECT_ADDRESS: { target: "closed", actions: ["selectAddress"] }, | ||
@@ -125,2 +96,6 @@ }, | ||
}, | ||
// Empties current input | ||
clearInput: () => { | ||
c.clearInput(); | ||
}, | ||
/** | ||
@@ -149,3 +124,5 @@ * Updates current li in list to active descendant | ||
*/ | ||
countryInput: () => { }, | ||
countryInput: () => { | ||
c.renderContexts(); | ||
}, | ||
/** | ||
@@ -152,0 +129,0 @@ * Clears ARIA announcement fields |
@@ -595,2 +595,3 @@ /** | ||
updateContexts(contexts: ContextStore): void; | ||
filteredContexts(): ContextDetails[]; | ||
/** | ||
@@ -660,2 +661,3 @@ * Render available country options | ||
query(): string; | ||
clearInput(): void; | ||
/** | ||
@@ -662,0 +664,0 @@ * Set address finder suggestions |
@@ -350,2 +350,18 @@ /** | ||
} | ||
filteredContexts() { | ||
const q = this.query(); | ||
if (q.trim().length === 0) | ||
return this.contextSuggestions; | ||
const f = q.toLowerCase().trim().replace(/\s+/g, " "); | ||
const regexp = new RegExp("^" + f); | ||
return this.contextSuggestions.filter((e) => { | ||
if (regexp.test(e.description.toLowerCase())) | ||
return true; | ||
if (e.iso_2.toLowerCase() === f) | ||
return true; | ||
if (e.iso_3.toLowerCase() === f) | ||
return true; | ||
return false; | ||
}); | ||
} | ||
/** | ||
@@ -356,3 +372,3 @@ * Render available country options | ||
this.list.innerHTML = ""; | ||
this.contextSuggestions.forEach((contextDetails, i) => { | ||
this.filteredContexts().forEach((contextDetails, i) => { | ||
const { description } = contextDetails; | ||
@@ -559,2 +575,5 @@ const li = this.options.document.createElement("li"); | ||
} | ||
clearInput() { | ||
update(this.input, ""); | ||
} | ||
/** | ||
@@ -791,3 +810,3 @@ * Set address finder suggestions | ||
if (key === "Enter") { | ||
const contextDetails = c.contextSuggestions[c.current]; | ||
const contextDetails = c.filteredContexts()[c.current]; | ||
if (contextDetails) | ||
@@ -794,0 +813,0 @@ c.fsm.send({ type: "SELECT_COUNTRY", contextDetails }); |
@@ -59,27 +59,11 @@ import { StateMachine } from "@xstate/fsm"; | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
export type ViewMachine = StateMachine.Machine<Context, Events, States>; | ||
/** | ||
* @hidden | ||
*/ | ||
export type ViewService = StateMachine.Service<Context, Events, States>; | ||
/** | ||
* @hidden | ||
*/ | ||
interface Create { | ||
(options: CreateOptions): ViewService; | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
export interface CreateOptions { | ||
c: Controller; | ||
} | ||
/** | ||
* Creates a finite state machine that drives Address Finder UI | ||
* @hidden | ||
*/ | ||
export declare const create: Create; | ||
export {}; |
103
esm/state.js
import { createMachine, interpret } from "@xstate/fsm"; | ||
/** | ||
* @hidden | ||
*/ | ||
const INPUT = { INPUT: { actions: "input" } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const CLOSE = { CLOSE: "closed" }; | ||
/** | ||
* @hidden | ||
*/ | ||
const SUGGEST = { | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
const NOTIFY = { | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
const NEXT = { NEXT: { actions: ["next", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const PREVIOUS = { PREVIOUS: { actions: ["previous", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const RESET = { RESET: { actions: ["resetCurrent", "gotoCurrent"] } }; | ||
/** | ||
* @hidden | ||
*/ | ||
const CHANGE_COUNTRY = { | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
}; | ||
/** | ||
* Creates a finite state machine that drives Address Finder UI | ||
* @hidden | ||
*/ | ||
// @hidden | ||
export const create = ({ c }) => { | ||
@@ -67,18 +26,30 @@ const machine = createMachine({ | ||
on: { | ||
...CLOSE, | ||
...SUGGEST, | ||
...NOTIFY, | ||
...INPUT, | ||
...CHANGE_COUNTRY, | ||
CLOSE: "closed", | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
INPUT: { actions: "input" }, | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
}, | ||
}, | ||
suggesting_country: { | ||
entry: ["renderContexts", "gotoCurrent", "expand", "addCountryHint"], | ||
exit: ["resetCurrent", "gotoCurrent", "contract", "clearHint"], | ||
entry: [ | ||
"clearInput", | ||
"renderContexts", | ||
"gotoCurrent", | ||
"expand", | ||
"addCountryHint", | ||
], | ||
exit: [ | ||
"resetCurrent", | ||
"gotoCurrent", | ||
"contract", | ||
"clearHint", | ||
"clearInput", | ||
], | ||
on: { | ||
...CLOSE, | ||
...NOTIFY, | ||
...NEXT, | ||
...PREVIOUS, | ||
...RESET, | ||
CLOSE: "closed", | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
NEXT: { actions: ["next", "gotoCurrent"] }, | ||
PREVIOUS: { actions: ["previous", "gotoCurrent"] }, | ||
RESET: { actions: ["resetCurrent", "gotoCurrent"] }, | ||
INPUT: { | ||
@@ -97,10 +68,10 @@ actions: ["countryInput"], | ||
on: { | ||
...CLOSE, | ||
...SUGGEST, | ||
...NOTIFY, | ||
...INPUT, | ||
...CHANGE_COUNTRY, | ||
...NEXT, | ||
...PREVIOUS, | ||
...RESET, | ||
CLOSE: "closed", | ||
SUGGEST: { target: "suggesting", actions: ["updateSuggestions"] }, | ||
NOTIFY: { target: "notifying", actions: ["updateMessage"] }, | ||
INPUT: { actions: "input" }, | ||
CHANGE_COUNTRY: { target: "suggesting_country" }, | ||
NEXT: { actions: ["next", "gotoCurrent"] }, | ||
PREVIOUS: { actions: ["previous", "gotoCurrent"] }, | ||
RESET: { actions: ["resetCurrent", "gotoCurrent"] }, | ||
SELECT_ADDRESS: { target: "closed", actions: ["selectAddress"] }, | ||
@@ -121,2 +92,6 @@ }, | ||
}, | ||
// Empties current input | ||
clearInput: () => { | ||
c.clearInput(); | ||
}, | ||
/** | ||
@@ -145,3 +120,5 @@ * Updates current li in list to active descendant | ||
*/ | ||
countryInput: () => { }, | ||
countryInput: () => { | ||
c.renderContexts(); | ||
}, | ||
/** | ||
@@ -148,0 +125,0 @@ * Clears ARIA announcement fields |
{ | ||
"name": "@ideal-postcodes/address-finder", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "Address Finder JS library backed by the Ideal Postcodes UK address search API", | ||
@@ -108,3 +108,3 @@ "main": "dist/index.js", | ||
"@ideal-postcodes/jsutil": "6.2.0", | ||
"@xstate/fsm": "~1.6.0", | ||
"@xstate/fsm": "~2.1.0", | ||
"lodash": "~4.17.21" | ||
@@ -111,0 +111,0 @@ }, |
246666
6978
+ Added@xstate/fsm@2.1.0(transitive)
- Removed@xstate/fsm@1.6.5(transitive)
Updated@xstate/fsm@~2.1.0