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

@aptoma/drpublish-plugin-api

v3.17.1

Published

DrPublish Plugin API ====================

Downloads

109

Readme

DrPublish Plugin API

The DrPublish plugin API allows you to plug your own web-apps into DrPublish to extend the feature set of the DrPublish writer. Your web-apps will be allowed to create, read, update and delete content in the DrPublish writer in real-time.

These web-apps can be deployed and run on any location of your choice, be it your in-house servers or some cloud location. It follows from this that you can write these web-apps in the backend programming language of your choice.

How to get started

Install the plugin through NPM:

npm install --save @aptoma/drpublish-plugin-api

Take a look at the example plugin to see how to get started. There you will see a few simple examples of sending data between the plugin and DrPublish.

How the API works

The apps are loaded directly in iframes (i.e. the src= of the iframe points directly to the URL as given in the DrPublish config) and all communication between the app and DrPublish is sent using postMessage (a standardized method for cross-domain frame communication).

PostMessage works by one side listening for incoming messages, and determining whether to act upon that message or not depending on its origin host, its origin frame and its contents.

In DrPublish, these binding are written in js/classes/binds/\*.js, and are mapped through js/classes/controller/AppEvents.js, which also handles delegation of events from DrPublish to apps.

On the plugin side, the files PluginAPI.js, AH5Communicator.js and articleCommunicator.js provide functions for sending and receiving all the supported postMessage calls without the caller having to know what is being done.

Behind the scenes, the API files wrap the incoming parameters in a JSON object, adds on the name of sending plugin and what method on the remote side it wants to call, and send this over postMessage using a thin jQuery PM wrapper.

DrPublish then determines which function should be called, executes it, wraps its response in a JSON object, and returns it to the sending plugin. The plugin then receives this reply, and sends the received data to a callback (if any is specified).

Custom configuration

Plugins can ask for and specify a customized configuration object. The API function to retrieve the configuration option is pluginAPI.getConfiguration, and you can find documentation on that in the pluginAPI module.

To specify the format of the configuration object the App needs to provide an URL where other applications (in most cases DrPublish's App Admin tool) can recieve an JSON schema describing the desired configuration setup. In case of DrPublish this URL is then registered alongside the URL to the app in the Publication configuration.

A simple example JSON schema for an image app could look like:

{
    "search": {
        "type": "string",
        "title": "Default Search",
        "required": true
    },
    "images": {
        "type": "array",
        "title": "Image Sizes",
        "items": {
            "type": "object",
            "title": "Image Size",
            "properties": {
                "name": {
                    "type": "string",
                    "title": "name",
                    "required": true
                },
                "filter": {
                    "type": "string",
                    "title": "Filter",
                    "enum": [
                        "grayscale",
                        "sepia",
                        "none"
                    ]
                },
                "height": {
                    "type": "integer",
                    "title": "Height"
                }
            }
        }
    }
}

Debugging

Enable debugging by setting the AppAPI.DEBUG flag to TRUE; If you then open up your browser JS console, you will see output detailing everything interesting that is happening under the bonnet. Note especially warnings and errors since these indicate that something of special interest has happened.

API Documentation

see DOCUMENTATION