@haklex/rich-ext-poll

中文文档
0.66.0发布于 2026/11/15MITTypeScriptES Module构建来源已验证近 30 天下载 1.3万

Reader-facing vote/poll widget extension

原始使用文档
文档目录16 节
  1. Installation
  2. Peer Dependencies
  3. Usage
  4. Register nodes
  5. Provide a data adapter
  6. Extract poll metadata for SSR
  7. Tree-shake the default renderer
  8. Import styles
  9. Exports
  10. Nodes
  11. Renderers
  12. Slot Key
  13. Types
  14. Sub-path Exports
  15. Part of Haklex
  16. License

@haklex/rich-ext-poll

Reader-facing vote/poll widget extension. Single- or multi-choice polls with optional close time and result-visibility policy for the Haklex rich editor.

Installation

pnpm add @haklex/rich-ext-poll

Peer Dependencies

PackageVersion
@haklex/rich-editorworkspace
@haklex/rich-editor-uiworkspace
lexical^0.45.0
lucide-react^1.0.0
react>=19

Usage

Register nodes

Editor (read + write):

import { pollEditNodes } from '@haklex/rich-ext-poll/edit';

const editorConfig = { nodes: [...pollEditNodes] };

Static / read-only:

import { pollNodes } from '@haklex/rich-ext-poll/node';

const staticConfig = { nodes: [...pollNodes] };

Provide a data adapter

The renderer reads tallies and submits votes through a PollDataAdapter. Wrap the renderer with PollDataProvider:

import { PollDataProvider } from '@haklex/rich-ext-poll/renderer';

<PollDataProvider adapter={myAdapter} initialStates={initial}>
  <RichRenderer value={state} />
</PollDataProvider>;

Without an adapter the renderer falls back to a static read-only display.

Extract poll metadata for SSR

import { extractPolls } from '@haklex/rich-ext-poll/node';

const polls = extractPolls(serializedEditorState);

Tree-shake the default renderer

The default PollRenderer is not statically imported by PollNode. To keep it out of your bundle, register only pollNodes and supply your own renderer through RendererConfig:

import { POLL_NODE_KEY, pollNodes } from '@haklex/rich-ext-poll/node';
import type { RichRendererModule } from '@haklex/rich-compose';

const lightPollModule: RichRendererModule = {
  name: 'poll',
  nodes: pollNodes,
  renderers: { [POLL_NODE_KEY]: MyLightPollRenderer },
};

@haklex/rich-compose ships a pollModule that lazy-loads the default renderer via lazyRenderers; importing the module above instead keeps the heavy default chunk out entirely.

Import styles

import '@haklex/rich-ext-poll/style.css';

Exports

Nodes

ExportDescription
PollNodeStatic (read-only) poll node
PollEditNodeEdit-mode poll node with interactive UI
$createPollNode() / $isPollNode()Lexical helpers
pollNodesArray of static nodes for config registration
pollEditNodesArray of edit nodes for config registration
extractPolls(state)Extract poll metadata from editor state for SSR

Renderers

ExportDescription
PollRendererStatic poll renderer with vote display
PollEditDecoratorEdit-mode decorator with poll configuration
PollDataProviderContext provider for vote tally adapter
usePollData()Hook to access poll data context

Slot Key

ExportDescription
POLL_NODE_KEY'Poll' constant for RendererConfig slot lookup

Types

ExportDescription
PollChoiceIndividual poll choice type
PollConfigPoll configuration (choices, close time, visibility)
PollDataAdapterAdapter interface for vote submission and tally
SerializedPollNodeSerialized poll node type

Sub-path Exports

PathDescription
@haklex/rich-ext-pollFull exports (node + renderer + edit)
@haklex/rich-ext-poll/nodeLightweight node + slot key + types — no default renderer
@haklex/rich-ext-poll/rendererDefault PollRenderer (heavy) + PollDataProvider
@haklex/rich-ext-poll/editEdit-mode node + PollEditDecorator
@haklex/rich-ext-poll/staticConvenience: node + renderer (SSR bundle)
@haklex/rich-ext-poll/style.cssStylesheet

Part of Haklex

This package is part of the Haklex rich editor ecosystem.

License

MIT

版本与发布记录

@haklex/rich-ext-poll 共发布 121 个版本,首次发布于 2026/05/10;过去 12 个月发布了 121 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.66.0latest2026/11/151 天前
0.65.72026/11/143 天前
0.65.62026/11/124 天前
0.65.52026/11/124 天前
0.65.42026/11/124 天前
0.65.32026/11/124 天前

关于 @haklex/rich-ext-poll 的常见问题

@haklex/rich-ext-poll 是什么?

Reader-facing vote/poll widget extension

如何安装 @haklex/rich-ext-poll?

在项目目录运行 npm install @haklex/rich-ext-poll,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=19)、lexical(^0.53.0)、lucide-react(^1.0.0)、@lexical/react(^0.53.0)、@haklex/rich-editor(^0.66.0)、@haklex/rich-editor-ui(^0.66.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@haklex/rich-ext-poll 支持 TypeScript 吗?

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

@haklex/rich-ext-poll 支持 ESM 还是 CommonJS?

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

@haklex/rich-ext-poll 可以商用吗?

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

@haklex/rich-ext-poll 的下载量有多少?

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

@haklex/rich-ext-poll 还在维护吗?

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