@bpmn-io/diagram-js-canvas-lock

中文文档
0.1.0发布于 2026/07/01MITES Module零依赖近 30 天下载 4万

A diagram-js plugin for locking the canvas

原始使用文档
文档目录11 节
  1. Features
  2. Installation
  3. Usage
  4. Integrating with diagram-js-canvas-lock
  5. 1. Query the lock state (pull)
  6. 2. React to lock changes (push)
  7. 3. Make an interaction vetoable ( *.allowed convention)
  8. 4. Style locked state (CSS hook)
  9. Public contract summary
  10. Development
  11. License

diagram-js-canvas-lock

CI

This module extends diagram-js-based editors with a canvas lock feature.

Features

  • lock and unlock canvas programmatically

Installation

Install via npm:

npm install @bpmn-io/diagram-js-canvas-lock

Usage

Use as an extension for bpmn-js:

import CanvasLockModule from '@bpmn-io/diagram-js-canvas-lock';

const modeler = new BpmnModeler({
  additionalModules: [
    CanvasLockModule
  ]
});

Lock and unlock the canvas through the canvasLock service:

const canvasLock = modeler.get('canvasLock');

canvasLock.lock();

canvasLock.isLocked(); // true

canvasLock.unlock();

Integrating with diagram-js-canvas-lock

By design, this module has no knowledge of the other diagram-js plugins running alongside it. Instead it exposes a small, stable contract that any plugin can integrate with. If your plugin adds interactive UI (pads, overlays, menus, ...), respect the lock through one or more of the following.

1. Query the lock state (pull)

Guard your own entry points with canvasLock.isLocked():

MyPad.prototype.canOpen = function(target) {
  if (this._canvasLock.isLocked()) {
    return false;
  }

  // ...
};

canvasLock is an optional dependency – resolve it via the injector so your plugin keeps working in editors without canvas lock:

function MyPad(injector) {
  this._canvasLock = injector.get('canvasLock', false);
}

MyPad.prototype.isLocked = function() {
  return this._canvasLock && this._canvasLock.isLocked();
};

MyPad.$inject = [ 'injector' ];

2. React to lock changes (push)

Subscribe to the canvasLock.changed event to tear down or restore UI when the lock is toggled:

eventBus.on('canvasLock.changed', function(event) {
  if (event.locked) {
    myPad.close();
  }
});

3. Make an interaction vetoable (*.allowed convention)

Following the diagram-js convention, fire an <x>.allowed event before opening and bail if any listener returns false. Canvas lock (and other features) can then veto the interaction without knowing about your plugin:

MyPad.prototype.open = function(target) {
  if (this._eventBus.fire('myPad.open.allowed', { target: target }) === false) {
    return;
  }

  // ...
};

4. Style locked state (CSS hook)

While locked, the canvas container carries the djs-canvas-locked class. Use it to hide or dim plugin UI purely visually:

.djs-canvas-locked .my-pad {
  display: none;
}

Public contract summary

SurfaceTypeDescription
canvasLock.lock() / unlock()APIToggle the lock.
canvasLock.isLocked()APIQuery the current lock state.
canvasLock.changedEventFired with { locked } whenever the lock toggles.
djs-canvas-lockedCSS classAdded to the canvas container while locked.

Development

npm install

npm start

License

MIT

版本与发布记录

@bpmn-io/diagram-js-canvas-lock 共发布 1 个版本,首次发布于 2026/07/01;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/07/014 个月前

关于 @bpmn-io/diagram-js-canvas-lock 的常见问题

@bpmn-io/diagram-js-canvas-lock 是什么?

A diagram-js plugin for locking the canvas

如何安装 @bpmn-io/diagram-js-canvas-lock?

在项目目录运行 npm install @bpmn-io/diagram-js-canvas-lock,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:diagram-js(>= 15.16.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bpmn-io/diagram-js-canvas-lock 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bpmn-io__diagram-js-canvas-lock 是否存在。

@bpmn-io/diagram-js-canvas-lock 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bpmn-io/diagram-js-canvas-lock 可以商用吗?

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

@bpmn-io/diagram-js-canvas-lock 的下载量有多少?

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

@bpmn-io/diagram-js-canvas-lock 还在维护吗?

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