diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index cd6ed80..c9762d7 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies working-directory: web - run: bun install --frozen-lockfile + run: bun install - name: Build working-directory: web diff --git a/CHANGELOG.md b/CHANGELOG.md index e103257..c060bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased ++ [优化] 优化节点插件SDK及HTML节点插件交互。 + ## v0.8.0 - 2026-07-15 + [新增] 画布节点插件系统:支持通过 URL 动态安装/启用/更新/卸载远程节点插件。 diff --git a/plugins/canvas/html/package.json b/plugins/canvas/html/package.json index 4916781..89f1f9e 100644 --- a/plugins/canvas/html/package.json +++ b/plugins/canvas/html/package.json @@ -1,6 +1,6 @@ { "name": "canvas-plugin-html", - "version": "1.0.0", + "version": "1.1.0", "private": true, "type": "module", "description": "Infinite Canvas HTML 节点插件", diff --git a/plugins/canvas/html/src/index.tsx b/plugins/canvas/html/src/index.tsx index 1175ed8..1700511 100644 --- a/plugins/canvas/html/src/index.tsx +++ b/plugins/canvas/html/src/index.tsx @@ -1,10 +1,68 @@ // HTML 节点:沙箱 iframe 渲染 HTML,{{input}} 会替换为上游文本节点内容。 -import { definePlugin, useMemo, useState } from "@infinite-canvas/plugin-sdk"; +// 交互:预览态 iframe 默认 pointer-events:none —— 鼠标事件穿透到宿主节点体, +// 因此点节点任意位置都能拖动,无需在节点上加任何标题栏/按钮。 +// 「编辑/预览」与「交互」开关都放在节点外的悬浮工具条(toolbar 扩展点),状态存 metadata。 +import { definePlugin, useMemo, useRef, useState } from "@infinite-canvas/plugin-sdk"; import type { CanvasNodeContentProps } from "@infinite-canvas/plugin-sdk"; +// 源码编辑器行高/字号,行号槽与文本域必须完全一致才能对齐 +const EDITOR_FONT = 12; +const EDITOR_LINE = 20; + +function HtmlEditor({ ctx, value }: { ctx: CanvasNodeContentProps["ctx"]; value: string }) { + const gutterRef = useRef(null); + // 行数:按换行统计,至少 1 行;value 变化时重算 + const lineCount = useMemo(() => Math.max(1, value.split("\n").length), [value]); + const [scrollTop, setScrollTop] = useState(0); + + const codeStyle = { fontFamily: "monospace", fontSize: EDITOR_FONT, lineHeight: `${EDITOR_LINE}px`, boxSizing: "border-box" } as const; + + return ( +
e.stopPropagation()}> + {/* 行号槽:跟随文本域滚动,不可单独滚动 */} +
+ {/* 用负 margin 让整列跟随 scrollTop 平移,和 textarea 同步 */} +
+ {Array.from({ length: lineCount }, (_, i) => ( +
{i + 1}
+ ))} +
+
+