Przejdź do głównej zawartości

Class: InpostGeowidgetManager

InPost Geowidget v5.

Two things about this widget are easy to get wrong and cost a broken checkout:

  1. It reports the picked point through a GLOBAL function, named by the onpoint attribute — not through an event listener. Each instance registers its own uniquely named function so two maps on one page cannot overwrite each other, and removes it on teardown.
  2. Its token is read once, when the element connects to the document. Setting the attribute afterwards is silently ignored: the first open looks fine (the script is still loading, so the upgrade happens after the attribute lands) and the SECOND opens an empty map. Hence the imperative creation with attributes set up-front.
  3. The global callback receives the point payload FLAT, not wrapped in { detail }. The widget only wraps the payload in a CustomEvent when no global function is registered — and this manager always registers one. Reading event.detail.name alone silently drops every selection: the map works, but picking a point does nothing.

Extends

Constructors

Constructor

new InpostGeowidgetManager(options): InpostGeowidgetManager

Parameters

options

PickupWidgetMountOptions

Returns

InpostGeowidgetManager

Inherited from

AbstractPickupWidgetManager.constructor

Properties

container

protected container: HTMLElement | null = null

Inherited from

AbstractPickupWidgetManager.container


descriptor

protected readonly descriptor: PickupWidgetDescriptor

Inherited from

AbstractPickupWidgetManager.descriptor


element

protected element: HTMLElement | null = null

Inherited from

AbstractPickupWidgetManager.element


onSelect

protected readonly onSelect: (point) => void

Parameters

point

PickupPointSelection

Returns

void

Inherited from

AbstractPickupWidgetManager.onSelect


token

protected readonly token: string

Inherited from

AbstractPickupWidgetManager.token

Methods

afterAssetsLoaded()

protected afterAssetsLoaded(_assets): void

The carrier's assets are in the document and the mount element is already in place.

Nothing to do by default: a widget that is a custom element is picked up by the browser itself, whenever the script defines it. A carrier that builds its maps in a one-off scan overrides this — and may throw, because a map that cannot be built has to be visible to the storefront as a failure rather than as a silently empty frame.

Parameters

_assets

PickupWidgetAssetsState

Returns

void

Inherited from

AbstractPickupWidgetManager.afterAssetsLoaded


applyDescriptorAttributes()

protected applyDescriptorAttributes(element): void

Apply the descriptor's attributes to a freshly created element.

Parameters

element

HTMLElement

Returns

void

Inherited from

AbstractPickupWidgetManager.applyDescriptorAttributes


createElement()

protected createElement(): HTMLElement

Create the element the carrier's script turns into a map, with its attributes already set.

Attributes MUST be in place before the element enters the document: a custom element reads its configuration once, when it is connected, and a token set afterwards is ignored. That failure is invisible on the first open (the script is still loading, so the upgrade happens after the attribute lands) and appears only on the second — which is why it belongs here rather than in every storefront that renders a map.

Returns

HTMLElement

Overrides

AbstractPickupWidgetManager.createElement


destroy()

destroy(): void

Remove the widget and release everything it registered. Safe to call more than once.

Returns

void

Inherited from

AbstractPickupWidgetManager.destroy


mount()

mount(container): Promise<void>

Mount the widget: the element enters the document FIRST, the carrier's assets follow.

That order is the whole difference between a map and an empty frame. A carrier whose widget is a plain element scans the document ONCE, when its script finishes loading, and never looks again — so an element inserted after that scan is never turned into a map, and nothing reports a failure. Waiting for the script before inserting made that the normal case; the custom-element carrier survived it only because a browser upgrades elements whenever they are defined, whenever that happens to be. Inserting first is correct for both.

A failure removes the element again. An empty box left in the checkout reads as a map that is still loading, and the storefront needs the rejection to fall back to point search.

Parameters

container

HTMLElement

Returns

Promise<void>

Inherited from

AbstractPickupWidgetManager.mount


subscribe()

protected subscribe(): void

Start listening for the buyer's choice.

Returns

void

Overrides

AbstractPickupWidgetManager.subscribe


unsubscribe()

protected unsubscribe(): void

Stop listening and release anything registered globally.

Returns

void

Overrides

AbstractPickupWidgetManager.unsubscribe