"use client"; import { createReactBlockSpec } from "@blocknote/react"; export const progressBlock = createReactBlockSpec( { type: "progressMeter", propSchema: { percent: { default: 0, type: "number" }, auto: { default: true, type: "boolean" }, summary: { default: "", type: "string" }, }, content: "inline", }, { render: ({ block, editor }) => { const percent = block.props.percent ?? 0; const handleToggle = () => { editor.updateBlock(block, { props: { auto: !block.props.auto } }); }; const handleBarClick = () => { if (block.props.auto) return; const input = window.prompt("设置进度(0-100)", percent.toString()); if (!input) return; const value = Number.parseInt(input, 10); if (Number.isNaN(value)) return; editor.updateBlock(block, { props: { percent: Math.min(100, Math.max(0, value)) }, }); }; return (
{block.props.summary || "暂无条目"}
{percent}%
); }, }, )();