✨ feat(vscode): 代码阅读 React 组件卡片按钩子分区:状态 / 引用 / 读取的数据 / 派生值 / 副作用 / 事件处理;副作用、处理函数成子卡片放进卡片那一行下面(库规则新增把子块放进属性表某一行的机制,事件处理表点名称展开)

This commit is contained in:
cruldra committed 2026-10-03 03:11:46 +08:00
1 parent 15f3a6600d
commit ee807ec7a4
19 files changed
+1057 -56

No files matched your search

+14 -4
View File
@@ -31,9 +31,17 @@ interface BlockViewBase {
attributes: BlockAttributes
/** 库规则的卡片才有:种类的名字、颜色和图标(RuleCard.badge)。预览同类块一样默认收起它的子块。 */
badge?: KindBadge
/** 库规则放进父卡片里的子块才有(见 RuleSlot):画在父卡片属性表第 row 行下面,不排在父卡片的子块里。 */
slot?: BlockSlot
children: BlockView[]
}
/** 子块画在父卡片的哪儿:属性表第 row 行下面;item 是讲它的那个子行,点那个子行的第一格才展开(见 RuleSlot.item)。 */
export interface BlockSlot {
row: number
item?: number
}
/**
* 发给 webview 的一块(可序列化):函数、类、枚举、异常、导入、常量、变量块和库规则的卡片预览时是属性表,注释块是 Markdown 说明,其余是一行译文。
* 一行译文下面依次是:跨几行写的调用摊开各个实参的表(TextTranslation.table),块的说明(TextBlock.doc,翻译插件给的 Markdown 原文)。
@@ -325,6 +333,7 @@ export function toBlockViews(
return plain({ ...replacement.as, node: block.node, header: span, children: kept, ...(attributes && { attributes }) }, span, id, scope)
}
const { kind, badge, rows, defines, attributes } = replacement
const slots = new Map((replacement.slots ?? []).map(({ block: child, row, item }): [CodeBlock, BlockSlot] => [child, { row, ...(item !== undefined && { item }) }]))
const { anchor, inner } = anchors.place(scope, kind, defines && source.slice(defines.startIndex, defines.endIndex), rowsText(span))
return {
id,
@@ -335,18 +344,19 @@ export function toBlockViews(
...(defines && { defines: { startIndex: defines.startIndex, endIndex: defines.endIndex } }),
attributes: { ...blockAttributes(block), ...attributes, kind },
badge,
children: list(kept, `${id}.`, inner),
children: list(kept, `${id}.`, inner, 0, slots),
properties: rows,
}
}
/** 一串兄弟块转成视图数据;略去的块不占位置,id 按出了块的往下数。 */
function list(siblings: readonly CodeBlock[], prefix: string, scope: string, from = 0): BlockView[] {
/** 一串兄弟块转成视图数据;略去的块不占位置,id 按出了块的往下数。slots 是父卡片放进它属性表里的那几块(见 BlockSlot)。 */
function list(siblings: readonly CodeBlock[], prefix: string, scope: string, from = 0, slots?: ReadonlyMap<CodeBlock, BlockSlot>): BlockView[] {
const spans = blockSpans(siblings, source)
const views: BlockView[] = []
siblings.forEach((block, i) => {
const view = build(block, spans[i], `${prefix}${from + views.length}`, scope)
const slot = slots?.get(block)
if (view)
views.push(view)
views.push(slot ? { ...view, slot } : view)
})
return views
}