PublisherConnector is a class object that allows you to interact with the CHILI Publisher editorObject via postMessage without the complexity of postMessage.

Overview

PublisherConnector

PublisherConnector is a class object that allows you to interact with the CHILI Editor editorObject via postMessage without the complexity of postMessage.

Why choose this over interacting with the editorObject directly?

  • The first and most obvious reason is CORS - by using PublisherConnector you do not have to worry about CNAME/domain or reverse proxy tricks.
  • The documentation of each function of PublisherConnector (really the editorObject) is the most complete documentation in existence.
  • Works with CHILI publisher Online.
  • Promise based and modern.

Installation

You can install PublisherConnector via npm

npm i @chili-publish/publisher-connector

or through yarn

yarn add @chili-publish/publisher-connector

Usage

  1. Import PublisherConnector.
import {PublisherConnector} from "@chili-publish/publisher-connector";
  1. Get the HTMLIFrameElement which contains the CHILI Editor.
const iframe = document.getElementById("editor-iframe");
  1. Create an instance of PublisherConnector by using the build method and passing the HTMLIFrameElement (created above) as a parameter. The build method returns a promise, which when resolved has the instance of the PublisherConnector.
PublisherConnector.build(iframe).then(
    publisherConnector => publisherConnector.alert("Hi!")
);

🚨️ IMPORTANT 🛑

The PublisherConnector build method must be called before the IFrame loads the Editor. This is due to how Penpal, the library the PublisherConnector is built on, functions.

If you set the src attribute of the IFrame in your HTML and have a script tag that runs the build method, then everything will be fine. The issue is only if you were to wait until IFrame was loaded before calling the build method.

For example this would be fine - assuming PublisherConnector was packaged (using Parcel, Webpack, etc.) into a browser safe JS file called publisher-connector-packaged.js:

">
<body>
<iframe id="editor-iframe" style="width:1200px; height:800px"
        src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGvqoB1a0YvkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q==">iframe>
<script type="module">
    import {PublisherConnector} from './publisher-connector-packaged.js';

    const iframe = document.getElementById("editor-iframe");

    (async () => {
        const publisherConnector = await PublisherConnector.build(iframe);
        const documentName = await publisherConnector.getObject("document.name");
        console.log(documentName);
    })();
script>
body>

API Reference

Differences with editorObject

The PublisherConnector class and editorObject object share many similarities. This is not odd as the PublisherConnector is an interface for interacting with the editorObject via postMessage. Below will mark any key differences.

Naming

A small, but important difference is that the methods from the PublisherConnector uses common JavaScript naming - camel case. This differs from the Pascal case used by the editorObject.

So editorObject.GetObject becomes publisherConnector.getObject.

So editorObject.SetProperty becomes publisherConnector.setProperty.

Promise Return

While the editorObject methods return without delay, the PublisherConnector uses postMessage. This means that the message must be serialized, sent, deserialized across from one window to another.

To make this easy, the PublisherConnector methods return a Promise.

So instead of:

const documentId = editorObject.GetObject("document.id");
console.log(documentId);

You would do:

console.log(documentId) );">
publisherConnector.getObject("document.id").then(
    documentId => console.log(documentId)
);

or use await, in a function marked async:

const documentId = await publisherConnector.getObject("document.id");
console.log(documentId);

Just like editorObject methods, if something goes wrong, an error will be thrown.

Events

The PublisherConnector does events completely different from what is documented for the editorObject.

To use events with the editorObject, it involved called the editorObject.AddListener method and then defining a function on window.OnEditorEvent that took a string for events. The OnEditorEvent function would typically have a switch case or a series of if/else to determine which event was called.

PublisherConnector makes things much simpler. If you want to listen to an event and then do something, then name it and add a callback function.

console.log("Frame moved with id " + target) );">
await publisherConnector.addListener(
  "FrameMoveFinished", 
  target => console.log("Frame moved with id " + target)
);

Removing an event is pretty much the same.

await publisherConnector.removeListener("FrameMoveFinished");

Getting PublisherConnector

When not using postMessage, there were two common methods to get the editorObject.

  • Editor page would allow you to set a callback using GetEditor on the IFrame contentWindow to get the editorObject
  • DocumentFullyLoaded event was called by default, so you could wait until that event was fired and sent to window.OnEventEvent to get the editorObject directly from the IFrame contentWindow

Neither of these methods are possible now, and you will need to use the build method on PublisherConnector. See Usage above.

Limitations

PublisherConnector is built on Penpal, which means that it inherits all same limitations.

Browser Support

PublisherConnector runs successfully on the most recent versions of Chrome, Firefox, Safari, and Edge. Internet Explorer is not supported.

Errors

See Penpal Errors

Comments
  • [BUG] Publisher Interface cannot be bunbled with Webpack 4

    [BUG] Publisher Interface cannot be bunbled with Webpack 4

    Describe the bug

    When trying to bundle a project that has @chili-publish/publisher-interface with Webpack 4.x you receive an error message:

    ERROR in ./node_modules/@chili-publish/publisher-interface/lib/PublisherInterface.js 10:32
    Module parse failed: Unexpected token (10:32)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    | 
    | class $0370263bd5c7e7d2$export$a13915682e709c4f {
    >     chiliEventListenerCallbacks = new Map();
    |     // eslint-disable-next-line @typescript-eslint/no-empty-function
    |     constructor(){}
     @ ./src/index.js 5:0-72 16:17-35
    

    If you bundle with Webpack 5.1.0 or higher, you receive no error message

    To Reproduce

    Steps to reproduce the behavior:

    1. Go to https://replit.com/@scrowe/Webpack-4#package.json
    2. Run npm run build and see error
    3. Change the package.json version of webpack to
        "webpack": "5.1.0",
        "webpack-cli": "^4.10.0"
    

    The only reason we update webpack-cli too, is because the older CLI version does not work with 5.

    4.Run npm run build and see no error

    Solution

    Use Webpack 5 (or other bundler like Parcel, Vite, etc) for you bundling needs.

    bug 
    opened by seancrowe 3
  • [QUESTION] Blocked with

    [QUESTION] Blocked with "accessing a cross-origin frame" error

    Hello, I was on PublisherConnector before and my code was working, since I upgrade to PublisherInterface, I always get "EXTERNAL ERROR: Blocked a frame with origin "https://domain" from accessing a cross-origin frame." I followed the documentation and the process. I'm on symfony and front with twig. Here is my code: (async () => { try { const publisherInterface = await PublisherInterface.build(iframe); await publisherInterface.addListener( "DocumentFullyRendered", target => { $('.zoom').on('click', (e)=>{ zoom(e, publisherInterface); }); } ); } catch (e) { console.log(e); }; })();

    It's not even doing the build.

    question 
    opened by Darpen 1
  • Typo on wiki

    Typo on wiki

    Missing quote "FrameMovedFinished" on Wiki code block here:

    https://github.com/chili-publish/publisher-interface/wiki/Differences-With-editorObject

    window.OnEditorEvent = (eventName, targetId) => {
      if (eventName == "FrameMovedFinished) {
        console.log("Frame with id " + targetId + " was moved");
      }
    }
    
    question 
    opened by bnzo 1
  • [FEATURE] Tests

    [FEATURE] Tests

    What

    Adds testing to the library.

    Please review the README at ./test/README.md, as I will assume that has already been read.

    This is meant to be ran on merge requests, and if accepted the Github Action will need to be modified.

    Why

    Playwright

    Playwright was an easy choice as it allows simple testing with very little configuration.

    • playwright package contains the browsers for testing
    • @playwright\test package contains the testing script

    The testing script we use is ./test/PublisherInterface.spec.ts

    testServer.js

    This file spins up a simple test server on localhost:3001. This server is very simple, and thus it seemed silly to use the many libraries that do the same but increase package dependency by times 4 or 5. This is a simple script which requires no dependencies.

    The server is not configurable (outside of changing the script), but our testing is not foreseen to require configuration. The only special thing is that you can pass in the argument --url to have the server load index.html with a specific URL in an iframe.

    index.html

    This file will run the tests found in ./test/tests. It is a very simple file that is highly coupled to testServer.js as it expects the src attribute on the div to be replaced by the the server script.

    There is one function window.runTest(), which expects a single parameter of the name of the test file to run from ./test/tests

    run_tests.js

    This file has snake_case to signify that something is not normal. This is a meta script which glues together the build, copy, server start, and Playwright testing.

    There is some hacky stuff going on here due issue with spawn() with shell:true that I had on Ubuntu 22.04. See commit 6d2f98a7dc12ce052247cea2ebfe86cfd88faf0f - I spent too long trying to find a legit fix, but at this moment it is either a Linux configuration issue (with Node behavior) or a bug in Node v14 and v16.

    enhancement ready to merge 
    opened by seancrowe 1
  • [Feature] Rebranding to publisher-interface

    [Feature] Rebranding to publisher-interface

    This pull request provides all the rebranding for PublisherConnector to PublisherInterface.

    All that needs to be done is the following:

    • Reviewed by @brapoprod, keep in mind @brapoprod that this will create a new library in npm called @chili-publish/publisher-interface
      • Make sure I spelled everything correct
    • One of us will then need to rename the repo to publisher-interface
    • Merge the request
    • publish-release-on-npm workflow should publish the new library

    Let's discuss what we should do with @chili-publish/publisher-connecter on npm see: https://github.com/chili-publish/publisher-connector/issues/11

    enhancement ready for review 
    opened by seancrowe 1
  • [Feature] Add pass-through for debug and timeout

    [Feature] Add pass-through for debug and timeout

    This will allow optional ability to use penpal features for timeout and debugging

    This is being requested by clients to handle the situation where penpal fails to connect. The timeout would allow for an error to handle.

    enhancement 
    opened by seancrowe 1
  • Bump terser from 5.13.1 to 5.14.2

    Bump terser from 5.13.1 to 5.14.2

    Bumps terser from 5.13.1 to 5.14.2.

    Changelog

    Sourced from terser's changelog.

    v5.14.2

    • Security fix for RegExps that should not be evaluated (regexp DDOS)
    • Source maps improvements (#1211)
    • Performance improvements in long property access evaluation (#1213)

    v5.14.1

    • keep_numbers option added to TypeScript defs (#1208)
    • Fixed parsing of nested template strings (#1204)

    v5.14.0

    • Switched to @​jridgewell/source-map for sourcemap generation (#1190, #1181)
    • Fixed source maps with non-terminated segments (#1106)
    • Enabled typescript types to be imported from the package (#1194)
    • Extra DOM props have been added (#1191)
    • Delete the AST while generating code, as a means to save RAM
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • [BUG] Fix events expecting a string instead of a string[]

    [BUG] Fix events expecting a string instead of a string[]

    Simple mistake, not caught by the tests. Tests probably need to cover more use cases of features. Who wants to volunteer to right tests?

    Will bump version once approved, or @brapoprod feel free to bump versions to 0.3.x

    bug ready for review ready to merge 
    opened by seancrowe 0
  • [Bug #23] webpack4 compatibility

    [Bug #23] webpack4 compatibility

    This fixes #23 by using tsc instead of Parcel to handle TypeScript compiling and targeting ES2015. As far as I am aware there is no downside to targeting ES2015 over modern ES versions, especially when our web build is already targeting less modern JS.

    Will bump version of package once approved, or @brapoprod feel to free to bump to 0.3.x

    bug ready for review ready to merge 
    opened by seancrowe 0
  • [FEATURE] Add alias for editorObject

    [FEATURE] Add alias for editorObject

    Many integrations will need to move over to Publisher Interface and all there code will use PascalCase function calls. This provides an easy alias to make it easier to those code bases to upgrade to Publisher Interface.

    This does not solve the fact that these functions still return a Promise.

    enhancement ready for review ready to merge 
    opened by seancrowe 0
  • [FEATURE] Feature/backwards compatible auto add listener

    [FEATURE] Feature/backwards compatible auto add listener

    This meant to be merged in https://github.com/chili-publish/publisher-interface/pull/15

    This is more than just a convenience feature. This is also there to allow developers to emulate the fact that certain events like DocumentFullyLoaded and DocumentSaved where fired off automatically in the current implementation.

    enhancement ready for review ready to merge 
    opened by seancrowe 0
  • Get all variables associated with a frame.

    Get all variables associated with a frame.

    Bit of a long shot, but I was wondering if there was any functionality that would get all the variables associated with a particular frame?

    A bit of context. I have a text frame that contains three short text variables, a long text variable and a list variable. On selecting that text frame I want to get the objects for these five variables. So I can then display custom input fields for these five variables etc.

    I'm able to get one of the five variables by setting the variable in the text frame's "Frame Link Settings" in the Chili BackOffice and using the following:

    await publisher.addListener("SelectedFrameChanged", async target => {
         const variable = await publisher.getObject('document.selectedFrame.linkSettings.variable');
    });
    

    But this is obviously only one of the five.

    I'm also aware that I can get all of the variables in the document by using the following:

    await publisher.getObject("document.variables");

    and then loop through etc as in the Chili Publisher documentation. But I just want the five variables associated with this frame.

    I've had a look through the Chili Publisher docs, but I was curious if anything like the following exists:

    await publisher.addListener("SelectedFrameChanged", async target => {
         const variables = await publisher.executeFunction("document.selectedFrame","GetVariables");
    });
    

    Or if there is any other way to possibly achieve this functionality? Or if I'm going about it in the complete wrong way.

    Any help at all would be appreciated.

    Cheers

    question 
    opened by danielkjcoles 2
  • [NEWS] Rebranding, and what to about @chili-publish/publisher-connector ?

    [NEWS] Rebranding, and what to about @chili-publish/publisher-connector ?

    What is going on?

    Hello everyone, we are rebranding Publisher Connector to Publisher Interface. This will be the only and last time there will be a rebranding for this library.

    The reason behind this rebranding is that "connectors" will have a new and distinct meaning with our new platform. The meaning is so distinct that we see major confusion among clients (new and legacy) if a publisher connector could mean this library or part of our connector system.

    It is an unfortunately situation, but it must be dealt with.

    Another reason for the rebranding is that in about 60 days, this will be the most popular library from CHILI publish. Over one hundred clients will be transitioning to using it. Therefore, it is even more important that the library standout from other similar named features.

    This rebranding goes from this repo all the way to the NPM package. See PR https://github.com/chili-publish/publisher-connector/pull/12

    Will this break my integration?

    @chili-publish/publisher-connector is still up on NPM. So no. Will it be updated moving forward? That is what this question is about.

    However, if your moving to @chili-publish/publisher-interface then the only issue will be that the unpkg file will change both in location and name. Everything else will work the same.

    What to do with publisher-connector?

    How should we handle publisher-connector on NPM as the rebranding will break future updates?

    question 
    opened by seancrowe 3
  • [QUESTION] How to call build method before editor loads?

    [QUESTION] How to call build method before editor loads?

    From the README...

    The PublisherConnector build method must be called before the IFrame loads the Editor.

    This part I'm not clear on. The example in the readme shows an iframe with a src attribute containing a valid editor URL. This should cause the editor in the iframe to load before the build method fires, right? Unless I'm missing something...

    I'm attempting to implement it in React with a ref to the iframe, but can't get it to load the editor. Tried withholding the src URL, setting it later, etc, to no avail. When I set the editor iframe src URL I get a blank editor screen and the error:

    "Uncaught DOMException: Failed to set the 'domain' property on 'Document': 'localhost' is not a suffix of ************.chili-publish-sandbox.online'."

    Any ideas would be great. Thanks.

    question 
    opened by devwax 2
Owner
CHILI publish
CHILI publish
API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

?? Open Sauced Nest Supabase API ?? The path to your next Open Source contribution ?? Prerequisites In order to run the project we need the following

TED Vortex (Teodor-Eugen Duțulescu) 13 Dec 18, 2022
CSS selectors complexity and performance analyzer

analyze-css CSS selectors complexity and performance analyzer. analyze-css is built as a set of rules bound to events fired by CSS parser. Each rule c

Maciej Brencz 680 Dec 16, 2022
A postMessage bridge to connect to dapps loaded into an iframe.

cardano-dapp-connector-bridge A postMessage bridge to connect to dApps loaded into an iframe. Motivation In April 2022, browser extensions are the onl

Tastenkunst GmbH 15 Oct 11, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
Get, change, and otherwise interact with your notes in Obsidian via a REST API.

Local REST API for Obsidian See our interactive docs: https://coddingtonbear.github.io/obsidian-local-rest-api/ Have you ever needed to automate inter

Adam Coddington 157 Dec 22, 2022
Cindy Dorantes 12 Oct 18, 2022
Small library to create classes without using class syntax.

Clazz.js Small library to create classes without using class syntax. Compatibility For internet explorer 11 or higher. Example <script src="Clazz.js">

Emanuel R. Vásquez 1 Dec 25, 2021
Prop-Proxy allows you to intercept getters and setters of class attributes through decorators

Prop-Proxy Proxy for class properties Prop-Proxy allows you to intercept getters and setters of class attributes through decorators Installation This

Leonardo Kaynan 6 Dec 15, 2022
A package that allows your bot of discord.js v13 & v14 to create the new awesome Discord Modals and interact with them

A package that allows your bot of discord.js v13 & v14 to create the new awesome Discord Modals and interact with them

MateoDeveloper 85 Dec 23, 2022
A secondhand marketplace where you can post items for sale, interact with sellers, save items you are interested in.

Curbside - the secondhand market place that's actually pleasant to use Post items for sale, interact with sellers, save items you are interested in. A

Curbside 14 Sep 9, 2022
On this page, you can save and load all the awesome books you have and save the name and the author into the local storage. this project uses Javascript to interact with the pages

Awesome Books: refactor to use JavaScript classes In this project, We add the links to the applications into the final project Getting Started if you

Cesar Valencia 8 Nov 29, 2022
An easy-to-use jQuery plugin that allows the user to pick an icon from a responsive icon browser and shows the corresponding icon class in an input element.

Font Awesome Browser An easy-to-use jQuery plugin that allows the user to pick an icon from a responsive icon browser and shows the corresponding icon

Gianluca Chiarani 1 May 1, 2021
This is a project based on a game Leaderboard. You can interact with an API inserting your user name and score. Built with HTML, CSS, JavaScript and WEBPACK

Leaderboard: Leaderboard project - Microverse Acces link Check the live version here Built With HTML CSS JavaScript VScode Webpack GitFlow Quick view

Vitor Guedes Madeira 11 Oct 8, 2022
This is a project that allows users to add/remove books from a list. we accomplish this by using a JavaScript object. Built with JavaScript, Html and CSS.

Awesome-book This is a project that allows users to add/remove book from a list. we accomplish this by usig javascript oject. Built With HTML5 CSS3 Ja

Juan Fco. Rosario Suli 6 May 27, 2022
Calculating Pi number without limitation until 10k digits or more in your browser powered by JS without any third party library!

PI Calculator Web JS (Online) Calculating Pi number without limitation until 10k digits or more in your browser powered by JS without any third party

Max Base 6 Jul 27, 2022
A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

Instagram Without APIs Instagram Scraping in August 2022, no credentials required This is a Node.js library, are you looking for the same in PHP? go t

Francesco Orsi 28 Dec 29, 2022
Multithread emulator. The wrun allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file

wrun This lib allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file. This means tha

Felippe Regazio 9 Nov 5, 2022
Read without losing the plot. Well Read helps you organize your notes about books you're reading, so you're never lost when starting a new volume.

Well Read Well Read is a website for tracking your reading of long book series. I made this to track how many pages I read in a session and to better

null 3 Dec 15, 2022