@anubhav1ks/catalogue-designer

中文文档
0.1.14发布于 2026/11/06UNLICENSEDTypeScriptCommonJS近 30 天下载 2309

HTML based design editor

原始使用文档
文档目录8 节
  1. Installation
  2. Design editor
  3. Editor props
  4. Editor settings ( DesignEditorContext )
  5. Catalogue viewer
  6. React
  7. Viewer props
  8. Script tag (no React)

Catalogue Designer

A React design editor for building catalogues, and a viewer for showing them on any website.

  • Design editor: create and edit catalogue pages.
  • Catalogue viewer: show a finished catalogue, either as a React component or with a script tag.

The editor and the viewer use separate license keys. The editor key only opens the editor, and the viewer key only opens the viewer. A missing or wrong key shows an error message instead of the component.

Installation

npm install @anubhav1ks/catalogue-designer
# or
yarn add @anubhav1ks/catalogue-designer

Peer dependencies: react and react-dom (18). CKEditor is installed automatically with the package.


Design editor

import DesignEditor, { DesignEditorContext } from '@anubhav1ks/catalogue-designer';
import '@anubhav1ks/catalogue-designer/css/design-editor.css';

export default function App() {
  return (
    <DesignEditorContext.Provider
      value={{
        viewerScriptUrl: 'https://your-site.com/catalogue-viewer.js',
        viewerLicenseKey: 'YOUR-VIEWER-LICENSE-KEY',
      }}
    >
      <div style={{ height: '100vh' }}>
        <DesignEditor
          licenseKey="YOUR-EDITOR-LICENSE-KEY"
          value={design}
          onChange={(next) => save(next)}
        />
      </div>
    </DesignEditorContext.Provider>
  );
}

Editor props

PropTypeDefaultDescription
licenseKeystring—Required. Editor license key.
valueIDesign—Design to open.
onChange(design: IDesign) => void—Called whenever the design changes.
storageKeystring | false—Key for saving to the browser. false turns saving off.
heightnumber | string'100%'Editor height.
minHeightnumber | string600Minimum editor height.
classNamestring—Extra CSS class.
styleCSSProperties—Extra inline styles.

Editor settings (DesignEditorContext)

FieldTypeDescription
templatesany[]Templates shown in the editor.
shapesany[]Extra shapes.
viewerScriptUrlstringURL of catalogue-viewer.js. Turns on "Open preview in new tab".
viewerLicenseKeystringViewer key, added to the preview page and the embed code snippets.
plannumberCurrent plan level.
planConfigPartial<PlanConfig>Plans and which features each plan unlocks.
uploadFile(file: File) => Promise<string>Uploads a file and returns its URL.

Other exports: usePlan, DEFAULT_PLAN_CONFIG, clearSavedDesign, designStorageKey, parseCatalogueJson.


Catalogue viewer

Download the catalogue JSON from the editor (Preview & embed → Download catalogue JSON) and pass it to the viewer.

The viewer fills 100% of the width and height of its container, so give the parent element a height.

React

import { CatalogueViewer } from '@anubhav1ks/catalogue-designer/viewer';

<div style={{ height: 600 }}>
  <CatalogueViewer
    licenseKey="YOUR-VIEWER-LICENSE-KEY"
    design={catalogue}
    type="full"
    inView={true}
  />
</div>;

Single view

Shows only the pages, one at a time, with no toolbar, arrows or thumbnails. Visitors change pages by swiping, with the arrow keys, or with links on the page.

<div style={{ height: 600 }}>
  <CatalogueViewer
    licenseKey="YOUR-VIEWER-LICENSE-KEY"
    design={catalogue}
    type="single"
    inView={true}
    startPage={0}
  />
</div>

Animations and video (inView)

  • inView={true} plays page animations and autoplays videos.
  • inView={false} stops animations and pauses all videos and audio, including YouTube embeds.

Use it to pause catalogues the visitor can't see, for example in a carousel or a scrolling list:

const [visible, setVisible] = useState(false);
const ref = useRef<HTMLDivElement>(null);

useEffect(() => {
  const io = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));
  if (ref.current) io.observe(ref.current);
  return () => io.disconnect();
}, []);

<div ref={ref} style={{ height: 500 }}>
  <CatalogueViewer
    licenseKey="YOUR-VIEWER-LICENSE-KEY"
    design={catalogue}
    type="single"
    inView={visible}
  />
</div>;

By default, page-jump links on a page (next, previous, first, last, go to page) turn the viewer's own page. Pass onPageJump to handle them yourself, for example when each slide of your carousel is its own viewer:

<CatalogueViewer
  licenseKey="YOUR-VIEWER-LICENSE-KEY"
  design={catalogue}
  type="single"
  startPage={index}
  inView={index === activeSlide}
  onPageJump={(page) => setActiveSlide(page)}
/>

page is 0-based and already limited to the catalogue's pages. The second argument is the link's original target: a page number, or 'prev', 'next', 'first' or 'last'.

Viewer props

PropTypeDefaultDescription
licenseKeystring—Required. Viewer license key.
designIDesign | string—Catalogue JSON, as an object or a string.
srcstring—URL to load the catalogue JSON from (used when design is not given).
type'full' | 'single''full'full = toolbar, arrows, spreads, thumbnails. single = pages only.
inViewbooleantruetrue plays animations and video, false stops them.
widthnumber | string'100%'Viewer width.
heightnumber | string'100%'Viewer height.
mode'auto' | 'book' | 'single''auto'Page layout in full view. auto uses spreads on wide screens.
theme'light' | 'dark''light'Colour theme.
startPagenumber0Page to open on (0 = first page).
showThumbnailsbooleanfalseOpen with the thumbnail strip showing (full view only).
linkColorstring—Colour of link hotspots.
flipOnClickbooleanfalseClicking the left or right half of a page turns the page.
classNamestring—Extra CSS class.
styleCSSProperties—Extra inline styles.
onLoad(design) => void—Called when the catalogue has loaded.
onError(error) => void—Called when the catalogue can't be loaded.
onPageJump(page, target) => void—Called when a page-jump link is clicked, with the 0-based page to go to. When set, the viewer does not change page itself.

Script tag (no React)

Add catalogue-viewer.js (from dist/) to your page. Every element with data-catalogue-src or data-catalogue becomes a viewer.

<div
  data-catalogue-src="/catalogue.json"
  data-license-key="YOUR-VIEWER-LICENSE-KEY"
  data-type="single"
  data-in-view="true"
  style="height: 600px"
></div>
<script src="https://your-site.com/catalogue-viewer.js" defer></script>

You can also put the JSON inside the element:

<div data-catalogue data-license-key="YOUR-VIEWER-LICENSE-KEY" data-height="700">
  <script type="application/json">
    { ...catalogue JSON... }
  </script>
</div>
AttributeSame as prop
data-license-keylicenseKey
data-catalogue-srcsrc
data-typetype
data-in-viewinView ("false" to pause)
data-widthwidth
data-heightheight
data-modemode
data-themetheme
data-start-pagestartPage (starts at 1)
data-thumbnailsshowThumbnails
data-link-colorlinkColor
data-flip-on-clickflipOnClick

If the element has no height, it gets 640px.

JavaScript API

const viewer = window.CatalogueViewer.mount(element, {
  licenseKey: 'YOUR-VIEWER-LICENSE-KEY',
  src: '/catalogue.json',
  type: 'full',
});

viewer.update({ inView: false }); // change any prop later
viewer.unmount();

window.CatalogueViewer.autoMount(); // mount elements added to the page later

版本与发布记录

@anubhav1ks/catalogue-designer 共发布 15 个版本,首次发布于 2026/11/04;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.1.14latest2026/11/061 天前
0.1.132026/11/052 天前
0.1.112026/11/052 天前
0.1.122026/11/052 天前
0.1.102026/11/052 天前
0.1.82026/11/052 天前

关于 @anubhav1ks/catalogue-designer 的常见问题

@anubhav1ks/catalogue-designer 是什么?

HTML based design editor

如何安装 @anubhav1ks/catalogue-designer?

在项目目录运行 npm install @anubhav1ks/catalogue-designer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.2.0)、react-dom(^18.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@anubhav1ks/catalogue-designer 支持 TypeScript 吗?

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

@anubhav1ks/catalogue-designer 支持 ESM 还是 CommonJS?

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

@anubhav1ks/catalogue-designer 可以商用吗?

@anubhav1ks/catalogue-designer 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@anubhav1ks/catalogue-designer 的下载量有多少?

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

@anubhav1ks/catalogue-designer 还在维护吗?

最新版本 0.1.14 发布于 2026/11/06(1 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/11/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。