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

dc-visualization-sdk

v1.1.0

Published

[![Amplience Dynamic Content](./media/header.png)](https://amplience.com/dynamic-content)

Downloads

40,409

Readme

Amplience Dynamic Content

dc-visualization-sdk

tests npm version

dc-visualization-sdk enables real time visualizations that can be used in the Content Form in the Dynamic Content (DC) App.

Installation

Using npm:

npm install dc-visualization-sdk --save

Using yarn:

yarn add dc-visualization-sdk

Using cdn:

<script src="https://unpkg.com/dc-visualization-sdk/dist/lib/dc-visualization-sdk.umd.js"></script>

Usage

In order to create a connection to DC you first need to initiate the SDK with init() method. Once connected you are given an SDK object you can use to subscribe to change events in the content form <sdk>.form.changed(<callback>), amongst other things.

Examples of this are shown below:

import { init } from 'dc-visualization-sdk';
const sdk = await init();
const unsubscribe = sdk.form.changed((model) => {
  // handle form model change
});

or

const visSDK = require('dc-visualization-sdk');
visSDK.init().then((sdk) => {
  const unsubscribe = sdk.form.changed((model) => {
    // handle form model change
  });
});

Form

The Form class allows you to retrieve the current state of the Content Form as well as subscribe to changes that take place while editing. This lets you create real time visualizations that are not dependent on the content item being saved.

Note: These methods will only return content when the form content is valid (e.g. if a required field is missing no content will be returned). Additionally methods are not available when the form is not visible, such as the Snapshot Browser or Edition contexts.

In addition you can set the same parameters that are available in the Delivery API, see the table below for more information.

Options

These options are shared between form.get(), form.change() and form.save().

| key | description | value | default | | -------------- | --------------------------------------------------------------------------------------------------------- | ----------------------- | ----------- | | format | Either return child content in the tree as a link (linked) or have the data hydrated inline (inlined). | 'inlined', 'linked' | 'inlined' | | depth | Either return all linked content (all) or just the root content item (root). | 'all', 'root' | 'all' | | allowInvalid | Whether or not to allow invalid content to be returned on change. e.g minItems requirements being ignored | true, false | false |

form.get()

This method will retrieve the current state of the form. By default JSON is returned as a fully hydrated tree, to change this see the table above for a full list of options.

Note: this method is only available in the Production Content Form

const options = {
  format: 'linked'
  depth: 'all'
};

sdk.form.get(options).then(model => {
    // handle form model
});

form.saved()

This method is for subscribing to the save event in the Content Form while editing. You provide a callback which will execute on every save. The method returns an unsubscribe function that when called will stop any further executions of the callback.

By default JSON is returned as a fully hydrated tree, to change this see the table above for a full list of options.

Note: this method is only available in the Production Content Form

const unsubscribe = sdk.form.saved((model) => {
  // handle form model
});

form.changed()

This method is for subscribing to changes that happen within the Content Form while editing. You provide a callback which will execute on every change. The method returns an unsubscribe function that when called will stop any further executions of the callback.

By default JSON is returned as it would be from the Content Delivery API (CDv2), you can also choose to use the legacy JSON-LD format (CDv1). See the table above for a full list of options..

Note: this method is only available in the Production Content Form

const unsubscribe = sdk.form.changed((model) => {
  // handle form model
});

Locale

The Locale class allows you to retrieve the currently selected locale in the visualization options and watch for changes to this option.

locale.get()

This method will retrieve the current locale selected in the visualization options. The method returns a promise that resolves either to the selected locale string e.g. 'en-GB' or null if none are selected.

const value = await sdk.locale.get();

console.log(value);
// 'en-GB'

locale.changed()

This method is for subscribing to changes to the selected locale in the visualization options. You provide a callback which will execute on every change. The method returns an unsubscribe function that when called will stop any further executions of the callback.

const unsubscribe = sdk.locale.changed((model) => {
  // handle locale change
});

Device

The Device class allows you to retrieve the currently selected device in the visualization options and watch for changes to this option.

device.get()

This method will retrieve the current device selected in the visualization options. The method returns a promise that resolves to the selected device.

const device = await sdk.device.get();

device.changed()

This method is for subscribing to changes to the selected device in the visualization options. You provide a callback which will execute on every change. The method returns an unsubscribe function that when called will stop any further executions of the callback.

const unsubscribe = sdk.device.changed((model) => {
  // handle settings change
});

Settings

The Settings class allows you to retrieve your DC visualization settings.

settings.get()

This method will retrieve the current visualization settings for the hub that the content item being visualized is in. The method returns a promise that resolves to a settings object.

const settings = await sdk.settings.get();
{
  "vse": "<vse url>",
  "devices": [
    {
      "name": "Desktop",
      "width": 1024,
      "height": 768,
      "orientate": true
    },
    {
      "name": "Tablet",
      "width": 640,
      "height": 768,
      "orientate": true
    },
    {
      "name": "Mobile",
      "width": 320,
      "height": 512,
      "orientate": true
    },
    {
      "name": "Desktop Large",
      "width": 1440,
      "height": 900,
      "orientate": true
    }
  ]
}

Context

The Context class allows you to retrieve the current meta data of the selected content item. and watch for changes to this option.

context.get()

This method will retrieve the current meta data of the selected content item. The method returns a promise that resolves to the Context object

const context = await sdk.context.get();

context.changed()

This method is for subscribing to changes to the context object. You provide a callback which will execute on every change. The method returns an unsubscribe function that when called will stop any further executions of the callback.

const unsubscribe = sdk.context.changed((model) => {
  // handle settings change
});