chore: 初始化 BlockFlow Workbench 仓库
建立前端与 Tauri 桌面端的首个版本提交,包含核心编辑器、项目文件读写、测试与构建配置。 补充 Git 忽略规则和换行规范,排除依赖、构建产物、本地运行日志与临时验证文件,方便在其他电脑继续开发。
This commit is contained in:
43
src/editor/extensions/LoopBlockExtension.ts
Normal file
43
src/editor/extensions/LoopBlockExtension.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { mergeAttributes, Node } from "@tiptap/core"
|
||||
|
||||
export const LoopBlockExtension = Node.create({
|
||||
name: "loopBlock",
|
||||
group: "block",
|
||||
content: "block+",
|
||||
defining: true,
|
||||
isolating: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
id: { default: null },
|
||||
source: { default: "items" },
|
||||
itemName: { default: "item" },
|
||||
indexName: { default: "" }
|
||||
}
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [{ tag: "section[data-blockflow-loop]" }]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes, node }) {
|
||||
const suffix = node.attrs.indexName ? ` index ${node.attrs.indexName}` : ""
|
||||
return [
|
||||
"section",
|
||||
mergeAttributes(HTMLAttributes, {
|
||||
"data-blockflow-loop": "",
|
||||
"data-block-id": node.attrs.id,
|
||||
"data-source": node.attrs.source,
|
||||
"data-item-name": node.attrs.itemName,
|
||||
"data-index-name": node.attrs.indexName,
|
||||
class: "bf-structured-block"
|
||||
}),
|
||||
[
|
||||
"div",
|
||||
{ class: "bf-block-heading bf-loop-heading", contenteditable: "false" },
|
||||
`▾ for ${node.attrs.itemName} in ${node.attrs.source}${suffix}`
|
||||
],
|
||||
["div", { class: "bf-block-content" }, 0]
|
||||
]
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user