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 🙏

© 2024 – Pkg Stats / Ryan Hefner

solid-autocomplete

v0.6.0

Published

This module allows an HTML form to be populated with data from your Solid pod.

Downloads

3

Readme

solid-autocomplete

This module allows an HTML form to be populated with data from your Solid pod. As of now only data from a WebId profile document is supported. This is also part of a proof of concept programming, which aims at working with an existing software system called Indico.

Development

  1. Clone the repository
$ git clone [email protected]:janschill/solid-autocomplete.git
$ cd solid-autocomplete
  1. Install dependencies
$ npm ci
  1. Run webpack development server
$ npm start
  1. Copy index.html into dist/ directory
$ cp src/index.html dist/index.html

Usage

  1. Install Solid Autcomplete
npm i solid-autocomplete
  1. Import the library into your project
// const SolidAutocomplete = require("solid-autocomplete")
import SolidAutocomplete from "solid-autocomplete"
  1. Configuration
  • form: A form where it shall fill in the inputs. If this is not given it will naively grab the first it finds.
  • button: A button can be passed in that when pressed will trigger the autocomplete functionality.
  • createAutocompleteDomControls(): Helper method can create the button and input field for the WebId URL can be automatically generated
const solidAutocomplete = new SolidAutocomplete({ form, button })
// solidAutocomplete.createAutocompleteDomControls()
solidAutocomplete.setupSolidAutocomplete()

Indico

  1. Install solid-autocomplete in Indico
npm i solid-autocomplete
  1. Configure MutationObserver and Solid Autocomplete

TODO: Explain

// indico/modules/events/registration/client/js/solid.js
import SolidAutocomplete from 'solid-autocomplete';

function observeFormCreation() {
  const formId = 'registrationForm';
  const $conferencePage = document.querySelector('.conference-page');
  const targetNode = $conferencePage;
  const config = {attributes: false, childList: true, subtree: true};

  const callback = (mutationsList, observer) => {
    for (const mutation of mutationsList) {
      if (mutation.type === 'childList') {
        for (const node of mutation.addedNodes) {
          if (node.id === formId) {
            observer.disconnect();
            const solidAutocomplete = new SolidAutocomplete({form: node});
            solidAutocomplete.createAutocompleteDomControls(node);
            solidAutocomplete.setupSolidAutocomplete();
          }
        }
      }
    }
  };

  const observer = new MutationObserver(callback);
  observer.observe(targetNode, config);
}

document.addEventListener('DOMContentLoaded', async () => {
  observeFormCreation();
});
  1. Import script in event registration index
// indico/modules/events/registration/client/js/index.js
import './solid'

How Does the Library Work?

An input field is generated which will be used to fetch the WebId profile document. It also requires a base element, ideally the form with the input fields is given here. It then grabs all <input> and textarea> fields. Then the fields are mapped to available data in the fetched document and automatically filled in, if the inputs do not have any values. If the inputs have values prior to automatic filling, a DOM element is rendered which gives the user the option to either accept the new data or reject it and keep the filled in data.

How Are the Inputs Mapped to the Fetched Data?

HTML input fields carry a few attributes which can be used to identify what type of data it is describing.

Autocomplete

The first attribute, which is also used by the browser to suggest possible data to the user for the inputs is the autocomplete attribute. The HTML specification defines exactly what values need to be used for what type of data [Source]. If the autocomplete attribute exists on the inputs it is checked for any useful values and then looked up in the dictionary to mapped against the fetched data.

ID

TODO: explain

Name

TODO: explain

Label

If all the above mentioned approaches do not yield good results the last option is the label tag. The label tag should exist per HTML specification for every input. It can be easily found by following the id attribute of the input, as every label should also have a for attribute, which links the label and input together.

<label for="my-text-input">My text input</label>
<input id="my-text-input" type="text">

The value or textContent of a label describes what the user should provide in the linked input field. Unfortunately, to reason about the content of the label is not trivial, as it does not follow any conventions and can be in any language.

Dictionary

The dictionary is a simple key value store that maps possible entries for the above mentioned attributes against the VCARD vocabulary.

Preview

An example form showing conflicting data.

What Fields Can Be Detected?

Only fields that can be autocompleted by the browser are:

  • <input>
  • <textarea>
  • <select>

Additionally it needs

  1. Have a name and/or id attribute
  2. Be descendants of a element
  3. The form to have a submit button

Valid Fields

HTML autocomplete form inputs:

| ID | Description | | - | - | | name | “The field expects the value to be a person's full name. Using "name" rather than breaking the name down into its components is generally preferred” | | email | Email address |

For a complete list see link [2].

Features

  1. Authenticate to Solid Pod
  2. Fetch data from pod
    • From WebID profile document
    • From other resources?
  3. Put data into form inputs
    • Check for already filled in data, and ask for what to keep
    • Have checkbox to remember data? Save data in pod and use next time

Indico Example Fields

  • Title
  • First Name
  • Last Name
  • Email Address
  • Affiliation
  • Institutional Address
  • Country

Useful Links

  • [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
  • [2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill