@aws/address-form-sdk-js 1.0.0 → 1.2.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.
@@ -1,4 +1,4 @@
1
- import { AutocompleteFilterPlaceType } from '@aws-sdk/client-geo-places';
1
+ import { AutocompleteFilterPlaceType, Address } from '@aws-sdk/client-geo-places';
2
2
  import { Config } from '../../types/config.ts';
3
3
  import { MapProps, MapStyle } from '../Map';
4
4
  import { MapMarkerProps } from '../MapMarker/index.tsx';
@@ -14,6 +14,7 @@ export interface AddressFormData {
14
14
  country?: string;
15
15
  originalPosition?: string;
16
16
  adjustedPosition?: string;
17
+ addressDetails?: Address;
17
18
  }
18
19
  export type AddressFormField = {
19
20
  id: FormFieldID;
@@ -37,6 +38,7 @@ export interface AddressFormProps {
37
38
  showAdjustPosition?: boolean;
38
39
  hide?: boolean;
39
40
  center?: number[];
41
+ zoom?: number;
40
42
  }>;
41
43
  className?: string;
42
44
  language?: string;
@@ -1,22 +1,31 @@
1
- import { AutocompleteFilterPlaceType } from '@aws-sdk/client-geo-places';
2
- import { ComponentProps, FormEvent, FunctionComponent, ReactNode } from 'react';
3
- import { AddressFormData } from '../AddressForm';
1
+ import { Address, AutocompleteFilterPlaceType, GetPlaceIntendedUse } from '@aws-sdk/client-geo-places';
2
+ import { ComponentProps, FunctionComponent, ReactNode } from 'react';
4
3
  import { AddressFormAddressFieldProps } from './AddressFormAddressField';
5
4
  import { AddressFormCountryFieldProps } from './AddressFormCountryField';
6
5
  import { AddressFormMapProps } from './AddressFormMap';
7
6
  import { AddressFormTextFieldProps } from './AddressFormTextField';
7
+ export interface AddressFormData {
8
+ placeId?: string;
9
+ addressLineOne?: string;
10
+ addressLineTwo?: string;
11
+ city?: string;
12
+ province?: string;
13
+ postalCode?: string;
14
+ country?: string;
15
+ originalPosition?: string;
16
+ adjustedPosition?: string;
17
+ addressDetails?: Address;
18
+ }
8
19
  export interface AddressFormProps extends AddressFormContentProps {
9
20
  apiKey: string;
10
21
  region: string;
11
- preventDefaultOnSubmit?: boolean;
12
22
  language?: string;
13
23
  politicalView?: string;
14
24
  showCurrentCountryResultsOnly?: boolean;
15
25
  allowedCountries?: string[];
16
26
  placeTypes?: AutocompleteFilterPlaceType[];
17
- onSubmit?: (event: FormEvent & {
18
- data: AddressFormData;
19
- }) => void;
27
+ initialMapCenter?: [number, number];
28
+ initialMapZoom?: number;
20
29
  }
21
30
  interface ChildComponents {
22
31
  AddressField: FunctionComponent<AddressFormAddressFieldProps>;
@@ -25,11 +34,11 @@ interface ChildComponents {
25
34
  TextField: FunctionComponent<AddressFormTextFieldProps>;
26
35
  }
27
36
  export declare const AddressForm: FunctionComponent<AddressFormProps> & ChildComponents;
37
+ export type SubmitHandler = (getData: (options: {
38
+ intendedUse: GetPlaceIntendedUse;
39
+ }) => Promise<AddressFormData>) => void;
28
40
  interface AddressFormContentProps extends Omit<ComponentProps<"form">, "onSubmit"> {
29
- preventDefaultOnSubmit?: boolean;
30
- onSubmit?: (event: FormEvent & {
31
- data: AddressFormData;
32
- }) => void;
41
+ onSubmit?: SubmitHandler;
33
42
  className?: string;
34
43
  children: ReactNode;
35
44
  }
@@ -1,7 +1,7 @@
1
- import { AddressFormData } from '../AddressForm';
2
1
  import { TypeaheadAPIName } from '../Typeahead/use-typeahead-query';
2
+ import { Field } from './AddressFormFields';
3
3
  export interface AddressFormAddressFieldProps {
4
- name: keyof AddressFormData;
4
+ name: Field;
5
5
  label: string;
6
6
  showCurrentLocation: boolean;
7
7
  apiName: string | TypeaheadAPIName | null;
@@ -0,0 +1,5 @@
1
+ interface AddressFormAutofillHandlerProps {
2
+ form: HTMLFormElement;
3
+ }
4
+ export declare const AddressFormAutofillHandler: ({ form }: AddressFormAutofillHandlerProps) => null;
5
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { AutocompleteFilterPlaceType } from '@aws-sdk/client-geo-places';
2
- import { AddressFormData } from '../AddressForm';
2
+ import { AddressFormData } from './AddressForm';
3
+ import { TypeaheadAPIName } from '../Typeahead/use-typeahead-query';
3
4
  export interface MapViewState {
4
5
  longitude: number;
5
6
  latitude: number;
@@ -10,6 +11,7 @@ export interface AddressFormContextType {
10
11
  region: string;
11
12
  data: AddressFormData;
12
13
  setData: (data: AddressFormData) => void;
14
+ resetData?: () => void;
13
15
  mapViewState?: MapViewState;
14
16
  setMapViewState: (mapViewState: MapViewState) => void;
15
17
  language?: string;
@@ -17,6 +19,10 @@ export interface AddressFormContextType {
17
19
  showCurrentCountryResultsOnly?: boolean;
18
20
  allowedCountries?: string[];
19
21
  placeTypes?: AutocompleteFilterPlaceType[];
22
+ isAutofill: boolean;
23
+ setIsAutofill: (isAutofill: boolean) => void;
24
+ typeaheadApiName: TypeaheadAPIName | null;
25
+ setTypeaheadApiName: (typeaheadApiName: TypeaheadAPIName | null) => void;
20
26
  }
21
27
  export declare const AddressFormContext: import('react').Context<AddressFormContextType | undefined>;
22
28
  export declare const useAddressFormContext: () => AddressFormContextType;
@@ -1,6 +1,6 @@
1
- import { AddressFormData } from '../AddressForm';
1
+ import { Field } from './AddressFormFields';
2
2
  export interface AddressFormCountryFieldProps {
3
- name: keyof AddressFormData;
3
+ name: Field;
4
4
  className?: string;
5
5
  label: string;
6
6
  placeholder?: string;
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
- import { AddressFormData } from '../AddressForm';
3
- export declare const Field: Record<string, keyof AddressFormData>;
2
+ import { AddressFormData } from './AddressForm';
3
+ export declare const Field: Record<string, keyof Omit<AddressFormData, "addressDetails">>;
4
4
  export type Field = (typeof Field)[keyof typeof Field];
5
5
  export declare const AddressFormFields: import('react').MemoExoticComponent<({ children }: PropsWithChildren) => import('react').ReactNode>;
@@ -1,4 +1,4 @@
1
- import { AutocompleteFilterPlaceType } from '@aws-sdk/client-geo-places';
1
+ import { AutocompleteFilterPlaceType, GeoPlacesClient } from '@aws-sdk/client-geo-places';
2
2
  import { FunctionComponent, PropsWithChildren } from 'react';
3
3
  export interface AddressFormProps extends PropsWithChildren {
4
4
  apiKey: string;
@@ -8,5 +8,8 @@ export interface AddressFormProps extends PropsWithChildren {
8
8
  showCurrentCountryResultsOnly?: boolean;
9
9
  allowedCountries?: string[];
10
10
  placeTypes?: AutocompleteFilterPlaceType[];
11
+ client?: GeoPlacesClient;
12
+ initialMapCenter?: [number, number];
13
+ initialMapZoom?: number;
11
14
  }
12
15
  export declare const AddressFormProvider: FunctionComponent<AddressFormProps>;
@@ -1,6 +1,6 @@
1
- import { AddressFormData } from '../AddressForm';
1
+ import { Field } from './AddressFormFields';
2
2
  export interface AddressFormTextFieldProps {
3
- name: keyof AddressFormData;
3
+ name: Field;
4
4
  className?: string;
5
5
  label: string;
6
6
  placeholder?: string;
@@ -1 +1 @@
1
- export { AddressForm } from './AddressForm';
1
+ export { AddressForm, type AddressFormData, type SubmitHandler } from './AddressForm';
@@ -1,18 +1,16 @@
1
1
  import { AutocompleteFilterPlaceType } from '@aws-sdk/client-geo-places';
2
- import { FormEvent } from 'react';
3
- import { AddressFormData } from '../AddressForm';
2
+ import { SubmitHandler } from './AddressForm';
4
3
  export interface RenderParams {
5
4
  root: string;
6
5
  apiKey: string;
7
6
  region: string;
8
- preventDefaultOnSubmit?: boolean;
9
7
  language?: string;
10
8
  politicalView?: string;
11
9
  showCurrentCountryResultsOnly?: boolean;
12
10
  allowedCountries?: string[];
13
11
  placeTypes?: AutocompleteFilterPlaceType[];
14
- onSubmit?: (event: FormEvent & {
15
- data: AddressFormData;
16
- }) => void;
12
+ onSubmit?: SubmitHandler;
13
+ initialMapCenter?: [number, number];
14
+ initialMapZoom?: number;
17
15
  }
18
16
  export declare const render: ({ root: selector, ...formProps }: RenderParams) => void;
@@ -1,2 +1,3 @@
1
1
  export declare const getBoolean: (props: Record<string, unknown>, name: string) => boolean | undefined;
2
2
  export declare const getString: (props: Record<string, unknown>, name: string) => string | undefined;
3
+ export declare const parsePosition: (position: string) => [number, number] | undefined;
@@ -0,0 +1,3 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { ButtonProps } from '../../Button';
3
+ export declare const AdjustButton: FunctionComponent<Omit<ButtonProps, "variant">>;
@@ -1,6 +1,8 @@
1
+ import { ColorScheme } from '../Map/index.tsx';
1
2
  export interface MapMarkerProps {
2
3
  adjustablePosition?: boolean;
3
4
  markerPosition?: [number, number];
4
5
  onSaveMarkerPosition?: (position: [number, number]) => void;
6
+ colorScheme?: ColorScheme;
5
7
  }
6
- export declare function MapMarker({ adjustablePosition, markerPosition, onSaveMarkerPosition }: MapMarkerProps): import("react/jsx-runtime").JSX.Element | undefined;
8
+ export declare function MapMarker({ adjustablePosition, markerPosition, onSaveMarkerPosition, colorScheme, }: MapMarkerProps): import("react/jsx-runtime").JSX.Element | undefined;
@@ -1,7 +1,9 @@
1
1
  import { Address } from '@aws-sdk/client-geo-places';
2
2
  import { TypeaheadAPIInput, TypeaheadAPIName } from './use-typeahead-query.ts';
3
3
  export interface TypeaheadOutput {
4
+ placeId?: string;
4
5
  addressLineOneField?: string;
6
+ addressLineTwoField?: string;
5
7
  fullAddress?: Address;
6
8
  position?: [number, number];
7
9
  }
@@ -17,5 +19,6 @@ export interface TypeaheadProps {
17
19
  onSelect: (value: TypeaheadOutput) => void;
18
20
  showCurrentLocation?: boolean;
19
21
  debounce?: number;
22
+ skipNextQuery?: boolean;
20
23
  }
21
24
  export declare const Typeahead: ({ apiName, ...props }: TypeaheadProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,5 +2,6 @@ export interface Country {
2
2
  code: string;
3
3
  name: string;
4
4
  position?: number[];
5
+ supported?: boolean;
5
6
  }
6
7
  export declare const countries: Country[];
@@ -1,18 +1,17 @@
1
- export { AddressForm, AddressFormMap } from './components/AddressForm';
2
- export { defaultAddressFormFields, FormFieldID } from './components/AddressForm/form-field';
3
- export { AddressForm as AddressFormReact } from './components/AddressFormReact/AddressForm';
4
- export { CountrySelect } from './components/CountrySelect';
5
- export type { CountrySelectProps } from './components/CountrySelect';
6
- export type { AddressFormProps, AddressFormMapProps, AddressFormField, AddressFormData, } from './components/AddressForm';
1
+ export { AddressForm, type AddressFormData, type SubmitHandler } from './components/AddressFormReact';
7
2
  export { AmazonLocationProvider } from './components/AmazonLocationProvider';
8
3
  export { Button } from './components/Button';
4
+ export { CountrySelect, type CountrySelectProps } from './components/CountrySelect';
5
+ export { Flex } from './components/Flex';
9
6
  export { FormField } from './components/FormField';
10
7
  export { Input } from './components/Input';
11
8
  export { LocateButton } from './components/LocateButton';
12
- export { Map } from './components/Map';
13
- export { getMapStyleType, getColorScheme } from './components/Map/utils';
14
- export type { ColorScheme } from './components/Map';
9
+ export { Map, type ColorScheme } from './components/Map';
15
10
  export { MapMarker } from './components/MapMarker';
16
11
  export { Typeahead } from './components/Typeahead';
17
12
  export { getIncludeCountriesFilter } from './utils/country-filter';
13
+ export { getMapStyleType, getColorScheme } from './components/Map/utils';
18
14
  export { countries } from './data/countries';
15
+ export { AddressForm as __AddressForm, AddressFormMap as __AddressFormMap } from './components/AddressForm';
16
+ export { defaultAddressFormFields as __defaultAddressFormFields, FormFieldID as __FormFieldID, } from './components/AddressForm/form-field';
17
+ export type { AddressFormProps as __AddressFormProps, AddressFormMapProps as __AddressFormMapProps, AddressFormField as __AddressFormField, AddressFormData as __AddressFormData, } from './components/AddressForm';
@@ -0,0 +1,24 @@
1
+ export type AutofillValues = Record<string, string>;
2
+ /**
3
+ * Detects browser autofill events on a form and executes a callback with the filled values.
4
+ *
5
+ * Uses CSS animations to detect when browsers autofill form fields. When autofill is detected,
6
+ * the callback is invoked with the form's current values after a debounced delay.
7
+ *
8
+ * @param form - The HTML form element to monitor for autofill events
9
+ * @param callback - Function called when autofill is detected, receives form values as key-value pairs
10
+ * @returns Cleanup function to remove event listeners and reset state
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const form = document.querySelector('form');
15
+ * const cleanup = detectAutofill(form, (values) => {
16
+ * console.log('Autofill detected:', values);
17
+ * // { addressLineOne: "123 Main St", city: "New York", ... }
18
+ * });
19
+ *
20
+ * // Later, clean up
21
+ * cleanup();
22
+ * ```
23
+ */
24
+ export declare const detectAutofill: (form: HTMLFormElement, callback: (values: AutofillValues) => void) => () => void;