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

driver-js-dynamic-wrapper

v0.3.0

Published

A wrapper around driver.js to make handling dynamic elements become simpler

Downloads

113

Readme

Purpose

Driver.js is a nice and easy to use library for highlighted showcase tour. The only cumbersome use case for me was handling steps on dynamically created elements. There is an issue, where multiple driver solution was proposed. So, I've used that one, and created this wrapper to handle edge cases (mostly) by plugin.

Usage and demo

Install using npm:

$ npm install driver-js-dynamic-wrapper

Get started:

import Driver from 'driver-js-dynamic-wrapper'
import 'driver.js/dist/driver.min.css';

Creating multiple steps on dynamic elements. Original source

Problem explanation

Problem occurs when defining the steps via original defineSteps(). Here library iterates throw DOM elements and skip step if it's not available. So in result dynamically created steps(delayed) are omitted. To "fix" that you should refresh steps before moving into dynamically created element.

  • Refreshing steps meant to update original driver.js steps to make it catch all currently visible DOM elements defined in steps configuration.
  • Consider you move from first steps to second. The 2nd step highlight dynamically created element after some action. For example redirection to next page action take a 500ms. To make refreshSteps() "pick up" step you should delay before.
  • Delaying is possible to do inside onNext() or onPrevious() functions inside steps configuration JSON. In more advanced scenario you could wait for some AJAX request, etc. then call refreshSteps()

Initial call

const driver = new Driver();
const mainConfig = {...}; // driver.js options 

driver
    .init(mainConfig)
    .defineSteps(stepsConfig(driver))     
    .start();

Defining a steps

Back to example with two steps, where 2nd step highlight dynamically created element

const stepsConfig = (Driver) => [
  {
    element: "#step-1",
    popover: {
      title: "first title ...",
      description: "first description ...",
    },
    async onNext(Element) {
      // prevent double click
      if (Driver.lockClick) return Driver.preventMove();

      Driver.handleNext(Element).preventMove();

      if (Driver.elementIsVisible) {
        Driver.continue();
        return;
      }

    // required delay to make DOM element #step-2 became visible
    // I use delay() as promise-based function, but it possible to wrap code bellow with setTimeout()
    // await delay(500)

      Driver.refreshSteps().continue();
    },
  },
  {
    element: "#step-2",
    popover: {
      title: "second title ...",
      description: "second description ...",
    },
  },
]; 

API

I didn't touch original driver.js code, you can access all the methods of driver.js. Some of this methods have the same name as in original plugin. They do the same functionality. I've duplicated them to make it chainable.

| method | description | | -------------------------- | ----------------------------------------------------------------------------------- | | init(opt = {}) | initialize instance; receives all original options from driver.js | | handleNext({ node }) | locks double click; handle step number; should always be called inside onNext() | | handlePrevious({ node }) | locks double click; handle step number; should always be called inside onPrevious() | | defineSteps(steps = []) | set steps; receives Array of step's definition. | | refreshSteps() | refresh steps for tour; should be called after delay to catch DOM elements | | reset() | reset all steps and the tour to 0 | | start(stepNumber = 0) | start tour from specified step, accept numbers | | preventMove() | prevent moving next step | | continue() | continue tour; it tries to get next visible step and start tour from it |


| getter | description | | ------------------ | ------------------------------------------ | | elementIsVisible | check if current step's element is visible |

Examples

Useful

  • function delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }   
  • stacking bug when animated with children of fixed elements

    https://github.com/kamranahmedse/driver.js/issues/133#issuecomment-549714982

        div#driver-highlighted-element-stage, div#driver-page-overlay {
        background: transparent !important;
        outline: 5000px solid rgba(0, 0, 0, .75)
        }
  • link to vue-js plugin

TO-DO

  • [ ] add TS support
  • [ ] add tests
  • [ ] add example with multiple scenarios
  • [ ] add Cypress-like get() syntax to catch elements automatically without manual timeout