@chili-publish/publisher-interface

中文文档
1.0.1发布于 2023/10/18MITTypeScriptCommonJS近 30 天下载 3357

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

原始使用文档
文档目录6 节
  1. Contents
  2. Installation
  3. Dependencies
  4. Browser Support
  5. Your Own iframe
  6. Debugging

CHILI Publisher Interface

The Publisher Interface library simplifies integration with CHILI GraFx Publisher by providing a straightforward means to interact with the editorObject via postMessage. This library greatly simplifies the complexity of dealing with the same-origin policy in all browsers including Chromium-based browsers.

Notes:

  • The Publisher JavaScript API has maintained stability for years. Thus this library reaching major version 1.x signifies that future updates will primarily address bug fixes, and should be rare. In this case, no updates is a good sign.
  • Some use cases may not be supported by Publisher Interface. Refer to here for unsupported use cases.
  • Previously named Publisher Connector, the project has been renamed to Publisher Interface to avert confusion with future connectors plugin systems. Please update your project if you utilized the old name and library.
  • As of 2023, this is the only officially supported way to integrate CHILI GraFx Publisher.

This project is officially supported by CHILI publish.

Contents


📘 Full documentation is available on the wiki.

Installation

Install Publisher Interface using npm, yarn, bun, or directly in the browser via unpkg.

// npm
npm i @chili-publish/publisher-interface

// yarn
yarn add @chili-publish/publisher-interface

// bun
bun install @chili-publish/publisher-interface

// browser
import {PublisherInterface} from "https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js";

Dependencies

The Publisher Interface has 1 dependency which is the Penpal library.

All other dependencies are only for the developer tools such as auto generating docs, testing, and packaging. Developer dependencies will not always be up-to-date, and that is okay because our focus is to keep to keep the package up-to-date , and the developer tools only when releasing a new version.

This means that there are very little security concerns, and the limitations are the same as those found in Penpal

Browser Support

Publisher Interface runs successfully on CHILI GraFx and any version greater on or above 6.5.5. It is also built to run on the most recent versions of Chrome, Firefox, Safari, and Edge. Internet Explorer is not supported.


Getting Started

Begin by pulling the package from unpkg, or import it if installed via NPM, yarn, or bun.

//unpkg
import {PublisherInterface} from "https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js";

// npm, yarn, bun
import {PublisherInterface} from "@chili-publish/publisher-interface";

Subsequently, within your JavaScript code:

  • Retrieve the containing element
  • Invoke the buildOnElement method
const editorDiv = document.getElementById("editor-div");
const publisher = PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0").then(
    publisher => publisher.alert("Hi!")
);

The code above will create an iframe on the element with id "editor-div" using the URL passed in the function as the src.

For iframe styling, use publisher.iframe.

const editorDiv = document.getElementById("editor-div");
const publisher = PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0").then(
    publisher => {
        publisher.iframe.classList.add("coolIFrameStyleInCSS");
    }
);


We can also use the async and await syntax. Here is the above example using async/await:

const editorDiv = document.getElementById("editor-div");
const publisher = await PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0");
publisher.iframe.classList.add("coolIFrameStyleInCSS");

Here is a complete example:

<body>
    <div id="editor-div"></div>
    <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=Sczs1ruhiZcaFiqg0G0"></iframe>
    <script type="module">
        import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
    
        const element = document.getElementById("editor-div");
    
        (async () => {
            const publisher = await PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0");
            
            publisher.iframe.classList.add("coolIFrameStyleInCSS");
            
            const documentName = await publisher.getObject("document.name");
            
            console.log(documentName);
        })();
    </script>
</body>

Your Own iframe

In versions before 1.0, you would need to use your own iframe when building the PublisherInterface class.

To utilize your iframe, employ the buildWithIframe() method.

<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=Sczs1ruhiZcaFiqg0G0"></iframe>
    <script type="module">
        import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
    
        const iframe = document.getElementById("editor-iframe");
    
        (async () => {
            const publisher = await PublisherInterface.buildWithIframe(iframe);
            const documentName = await publisher.getObject("document.name");
            console.log(documentName);
        })();
    </script>
</body>


🚨 Important - buildWithIframe() will not resolve if the iframe loads before build() is called. Prefer using buildOnElement().


Debugging

Activate debugging by passing {debug: true} as the commonBuildOptions in your build function.

// If you are letting the iframe be built on an element
PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0", {debug: true})

// If you are using your own iframe
PublisherInterface.buildWithIframe(iframe, {debug: true});

This will display messages in the console about the communication between the iframe and the main page.


To handle potential connection failures, define a timeout as demonstrated below.

// If you are letting the iframe be built on an element
PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0", {debug: true, timeout: 10000})

// If you are using your own iframe
PublisherInterface.buildWithIframe(iframe, {debug: true, timeout: 10000});

If the connection is not established before the timeout, an exception will be thrown. In the example below, the build method will throw a timeout after 10 seconds if no connection is established.


To read more, check out our documentation.

版本与发布记录

@chili-publish/publisher-interface 共发布 10 个版本,首次发布于 2022/10/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2023/10/183 年前
1.0.02023/10/103 年前
0.4.02023/07/133 年前
0.3.62023/07/073 年前
0.3.52023/04/053 年前
0.3.42022/11/223 年前

关于 @chili-publish/publisher-interface 的常见问题

@chili-publish/publisher-interface 是什么?

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

如何安装 @chili-publish/publisher-interface?

在项目目录运行 npm install @chili-publish/publisher-interface,或使用 pnpm add / yarn add / bun add。

@chili-publish/publisher-interface 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chili-publish/publisher-interface 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@chili-publish/publisher-interface 可以商用吗?

@chili-publish/publisher-interface 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chili-publish/publisher-interface 的下载量有多少?

根据 npm 官方下载统计,@chili-publish/publisher-interface 在 2026/10/10 – 2026/11/08 这 30 天内被下载 3,357 次,日均约 112 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chili-publish/publisher-interface 还在维护吗?

最新版本 1.0.1 发布于 2023/10/18(3 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/10/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。