npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@placefield/widget

v0.1.2

Published

Typed loader helpers for the PlaceField browser widget.

Downloads

16

Readme

@placefield/widget

Typed loader helpers for the hosted PlaceField browser widget.

This package is for bundler-based browser apps that want TypeScript types and a clean import path while still using the supported hosted PlaceField bundles from https://cdn.placefield.dev.

It does not embed a PlaceField API key, does not call the PlaceField API by itself, and does not replace backend/API integrations. Browser widget integrations use public pf_pub_... keys. Keep secret pf_live_... keys on your backend.

Install

npm install @placefield/widget

Full Widget

import {
  createPlaceFieldWidget,
  type PlaceFieldAutocompleteResult,
  type PlaceFieldWidgetOptions
} from "@placefield/widget";

const options: PlaceFieldWidgetOptions = {
  key: "pf_pub_xxx",
  geoBias: "country",
  typePreset: "default",
  lang: "en",
  mobile: "fullscreen",
  fields: {
    id: "#location_id",
    country: "#country",
    hierarchy: "#hierarchy",
    lat: "#lat",
    lon: "#lon"
  },
  onSelect(result: PlaceFieldAutocompleteResult) {
    console.log(result.id, result.label);
  }
};

const widget = await createPlaceFieldWidget("#city", options);

// Later, if needed:
widget.destroy();

createPlaceFieldWidget(...) loads:

  • https://cdn.placefield.dev/placefield-widget.css
  • https://cdn.placefield.dev/placefield-widget.min.js

Then it calls PlaceField.widget(...) with typed options.

Basic JS

import { attachPlaceField } from "@placefield/widget";

const autocomplete = await attachPlaceField("#city", {
  key: "pf_pub_xxx",
  geoBias: "country",
  typePreset: "default",
  onSelect(result) {
    console.log(result);
  }
});

autocomplete.destroy();

attachPlaceField(...) loads:

  • https://cdn.placefield.dev/placefield.css
  • https://cdn.placefield.dev/placefield.min.js

Then it calls PlaceField.attach(...) with typed options.

Loader Only

If you want to load the hosted assets and call the browser global yourself:

import { loadPlaceFieldWidget } from "@placefield/widget";

const PlaceField = await loadPlaceFieldWidget();

PlaceField.widget?.("#city", {
  key: "pf_pub_xxx",
  mobile: "fullscreen"
});

Framework Usage

Call the helpers only in browser/client code, after the input exists in the DOM. For React, that usually means inside useEffect.

import { useEffect, useRef } from "react";
import {
  createPlaceFieldWidget,
  type PlaceFieldAutocompleteResult,
  type PlaceFieldWidgetInstance,
  type PlaceFieldWidgetOptions
} from "@placefield/widget";

export function CityField() {
  const inputRef = useRef<HTMLInputElement | null>(null);

  useEffect(() => {
    let widget: PlaceFieldWidgetInstance | undefined;

    if (!inputRef.current) {
      return undefined;
    }

    const options: PlaceFieldWidgetOptions = {
      key: "pf_pub_xxx",
      geoBias: "country",
      onSelect(result: PlaceFieldAutocompleteResult) {
        console.log(result.id, result.label);
      }
    };

    createPlaceFieldWidget(inputRef.current, options).then((instance) => {
      widget = instance;
    });

    return () => {
      widget?.destroy();
    };
  }, []);

  return <input ref={inputRef} id="city" name="city" autoComplete="off" />;
}

Loader Options

The default loader uses the production CDN. You can override asset URLs for testing or self-hosted deployments:

await createPlaceFieldWidget("#city", options, {
  assetBaseUrl: "https://cdn.example.com/placefield",
  timeoutMs: 10000
});

Available loader options include:

  • assetBaseUrl
  • scriptUrl
  • stylesheetUrl
  • loadStyles
  • timeoutMs
  • nonce, scriptNonce, stylesheetNonce
  • integrity, scriptIntegrity, stylesheetIntegrity
  • crossOrigin

Terms

This package is proprietary PlaceField integration software, not an open-source license grant. It is provided for PlaceField integrations and is governed by the PlaceField commercial terms at https://placefield.dev/terms. PlaceField API and hosted widget usage require a valid PlaceField key.