Skip to content
全新发布

PDF SDK 与 AI 文档处理

在 GitHub 获取完整的私有化部署SDK 包及 AI 智能文档处理能力,一键部署,快速构建您的文档处理工作流。

弹出菜单

弹出菜单是出现在批注、文本选区、内容编辑器和裁剪页面工具上方的浮动右键菜单。WebViewer 暴露四个弹出菜单属性,每个都实现 UI.Popup 接口,可读取、添加和替换其操作项。

UI.Popup 接口

四个弹出菜单属性均由 api_helpers/createPopupAPI.js 构建,各实现:

方法签名用途
add(items, dataElement?)(items: Array|object, dataElement?: string) => this在指定 dataElement 的项之后插入(省略则插入开头)。非数组会被包装。
update(items?)(items?: Array|object) => this替换所有弹出项(undefined 则清空)。
getItems()() => Array<object>返回当前弹出项。

移除项,使用 UI.disableElements 并传入项的 dataElement

四个弹出菜单

UI.textPopup

文本选区右键菜单。

javascript
/**
 * @name UI.textPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */
UI.textPopup.getItems();        // => [{ type, dataElement, ... }, ...]

默认操作:复制、高亮、下划线、删除线、波浪线。

UI.annotationPopup

选中批注的右键菜单。

javascript
/**
 * @name UI.annotationPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

默认操作随批注类型变化:回复、复制、属性、设置、删除。链接和擦除-密文批注仅显示删除;密文显示属性+删除;表单字段显示属性/复制/删除。

UI.contentEditorPopup

内容编辑器右键菜单。

javascript
/**
 * @name UI.contentEditorPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

默认操作:复制、删除、属性。

UI.cropPagePopup

裁剪页面组件右键菜单。

javascript
/**
 * @name UI.cropPagePopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

默认操作:裁剪、关闭/退出。

项结构

弹出项与工具栏项共享描述符结构——typeactionButtonstatefulButtontoggleElementButtontoolButton)、dataElementiconlabelonClick。弹出组件(components/Popups/)通过 CustomButton 和类型化 Button 分支渲染项,过滤掉 dataElement 被禁用的项。

定位

弹出位置由 helpers/getPopupPosition.js 计算——getAnnotationPopupPositionBasedOn(rect, pageNumber, popup, documentViewerKey=1, position='right') 返回 { left, top }。它通过 core.pageToWindow 将页面空间批注角点转为窗口坐标,再在滚动容器视口内夹取(优先批注下方,回退到上方或空间更多的一侧)。

示例

向批注弹出菜单添加自定义操作

javascript
UI.annotationPopup.add({
  type: 'actionButton',
  dataElement: 'myAnnotAction',
  label: 'Send to backend',
  onClick: () => { /* … */ },
});

替换文本弹出菜单操作

javascript
UI.textPopup.update([
  { type: 'actionButton', dataElement: 'copyTextButton',  label: 'Copy' },
  { type: 'toolButton',   dataElement: 'highlightToolButton', label: 'Highlight' },
]);

移除某项

javascript
UI.disableElements(['replyButton']);   // 从批注弹出菜单移除回复操作

内部说明

  • 弹出项数组位于 viewer store(textPopup[]annotationPopup[]contentEditorPopup[]cropPagePopup[]),通过封装的 viewerStore.dispatch('getPopupItems')(popupDataElement) 访问。
  • 弹出组件通过 useViewer.getPopupItems(<key>) 读取项并按 isElementDisabled 过滤。
  • store 中的 showAnnotationPopup / popoverChanged 标志控制弹出可见性时机。

相关