[{"data":1,"prerenderedAt":455},["ShallowReactive",2],{"quirekit-doc:\u002Fconcepts\u002Fextensions":3,"quirekit-source:core\u002Fshortcuts.ts":205,"mdc-5ht98-key":206},{"id":4,"title":5,"body":6,"description":193,"extension":194,"keywords":195,"locale":196,"meta":197,"navigation":198,"order":199,"path":200,"section":201,"seo":202,"stem":203,"__hash__":204},"docs\u002Fconcepts\u002Fextensions.zh-CN.md","扩展模型",{"type":7,"value":8,"toc":185},"minimark",[9,13,17,80,83,86,109,113,123,126,144,162,165,168],[10,11,12],"p",{},"编辑器能否输入标题、加粗文字或响应快捷键，都由安装的扩展决定。扩展把一种功能的配置、命令和生命周期放在一起，再交给 Editor 使用。",[14,15,16],"h2",{"id":16},"选哪一种扩展",[18,19,20,36],"table",{},[21,22,23],"thead",{},[24,25,26,30,33],"tr",{},[27,28,29],"th",{},"你要增加什么",[27,31,32],{},"使用什么",[27,34,35],{},"例子",[37,38,39,54,67],"tbody",{},[24,40,41,45,51],{},[42,43,44],"td",{},"一种行为，不增加正文结构",[42,46,47],{},[48,49,50],"code",{},"Extension",[42,52,53],{},"快捷键、历史记录",[24,55,56,59,64],{},[42,57,58],{},"一种正文结构",[42,60,61],{},[48,62,63],{},"Node",[42,65,66],{},"段落、图片、提示组",[24,68,69,72,77],{},[42,70,71],{},"附着在文字上的格式",[42,73,74],{},[48,75,76],{},"Mark",[42,78,79],{},"粗体、斜体、链接",[10,81,82],{},"StarterKit 是一组常用扩展的组合。你可以直接使用它，也可以按产品需要选择和配置其中的能力。",[14,84,85],{"id":85},"从快捷键开始",[10,87,88,89,92,93,96,97,100,101,104,105,108],{},"假设你希望用 ",[48,90,91],{},"Mod-Shift-b"," 执行加粗，不需要定义新节点，只需增加快捷键行为。示例的 ",[48,94,95],{},"core\u002Fshortcuts.ts"," 使用 ",[48,98,99],{},"Extension.create()","，在 ",[48,102,103],{},"addKeyboardShortcuts()"," 中调用现有的 ",[48,106,107],{},"toggleBold()","。",[110,111],"docs-recipe",{"name":112},"core\u002Fshortcuts",[10,114,115,118,119,122],{},[48,116,117],{},"this.editor"," 指向安装该扩展的实例。调用现有命令以后，加粗仍使用同一个选区，也可以通过原来的历史记录撤销。将扩展加入创建时的 ",[48,120,121],{},"extensions"," 数组即可安装。",[14,124,125],{"id":125},"配置与扩展现有功能",[10,127,128,131,132,135,136,139,140,143],{},[48,129,130],{},".configure(options)"," 调整扩展公开的选项；",[48,133,134],{},".extend(config)"," 在已有定义上增加或替换行为。扩展里的 ",[48,137,138],{},"addOptions()"," 提供默认配置，",[48,141,142],{},"addStorage()"," 保存实例运行状态。",[10,145,146,147,152,153,157,158,108],{},"配置和 storage 不会自动写入正文。需要随文档保存的业务字段，应定义为节点或标记属性。跟着",[148,149,151],"a",{"href":150},"\u002Fguide\u002Fbehavior","行为扩展教程","实现一个命令，再学习",[148,154,156],{"href":155},"\u002Fguide\u002Frules","输入规则与 PM 插件","和 ",[148,159,161],{"href":160},"\u002Fguide\u002Fnode-view","NodeView",[14,163,164],{"id":164},"当内容需要更多能力",[10,166,167],{},"定义 Node 只解决“文档里有什么”。HTML 输出、Canvas 布局、跨结构选择、DOCX 转换和 AI 读取分别需要对应的实现，不会由节点名自动推断。",[10,169,170,171,175,176,180,181,108],{},"首次开发内容扩展，可以跟着",[148,172,174],{"href":173},"\u002Fbuild\u002Fextension","提示组教程","逐项连接。接入现成功能时先查",[148,177,179],{"href":178},"\u002Fplugins","插件目录","；完整钩子和类型在",[148,182,184],{"href":183},"\u002Fapi\u002Fextensions","扩展 API",{"title":186,"searchDepth":187,"depth":187,"links":188},"",2,[189,190,191,192],{"id":16,"depth":187,"text":16},{"id":85,"depth":187,"text":85},{"id":125,"depth":187,"text":125},{"id":164,"depth":187,"text":164},"理解行为、节点和文字格式分别怎样加入编辑器。","md",null,"zh-CN",{},true,1,"\u002Fconcepts\u002Fextensions","核心概念",{"title":5,"description":193},"concepts\u002Fextensions.zh-CN","bdgu9FV_cA1pGb9-DCBXkwVUTVZTrbzaqYZayrvlQwg","import { Extension } from \"@quirekit\u002Fcore\";\n\n\u002F** A host-authored behavior extension using the same typed command registry as the toolbar. *\u002F\nexport const writingShortcuts = Extension.create({\n  name: \"writingShortcuts\",\n  \u002F** @returns A keyboard binding that participates in the editor's existing history. *\u002F\n  addKeyboardShortcuts() {\n    return { \"Mod-Shift-b\": () => this.editor?.commands.toggleBold() ?? false };\n  },\n});\n",{"data":207,"body":208},{},{"type":209,"children":210},"root",[211,449],{"type":212,"tag":213,"props":214,"children":218},"element","pre",{"className":215,"code":216,"language":217,"meta":186,"style":186},"language-ts shiki shiki-themes github-light github-light github-dark","import { Extension } from \"@quirekit\u002Fcore\";\n\n\u002F** A host-authored behavior extension using the same typed command registry as the toolbar. *\u002F\nexport const writingShortcuts = Extension.create({\n  name: \"writingShortcuts\",\n  \u002F** @returns A keyboard binding that participates in the editor's existing history. *\u002F\n  addKeyboardShortcuts() {\n    return { \"Mod-Shift-b\": () => this.editor?.commands.toggleBold() ?? false };\n  },\n});\n\n","ts",[219],{"type":212,"tag":48,"props":220,"children":221},{"__ignoreMap":186},[222,256,264,274,315,334,353,367,431,440],{"type":212,"tag":223,"props":224,"children":226},"span",{"class":225,"line":199},"line",[227,234,240,245,251],{"type":212,"tag":223,"props":228,"children":230},{"style":229},"--shiki-default:#D73A49;--shiki-light:#D73A49;--shiki-dark:#F97583",[231],{"type":232,"value":233},"text","import",{"type":212,"tag":223,"props":235,"children":237},{"style":236},"--shiki-default:#24292E;--shiki-light:#24292E;--shiki-dark:#E1E4E8",[238],{"type":232,"value":239}," { Extension } ",{"type":212,"tag":223,"props":241,"children":242},{"style":229},[243],{"type":232,"value":244},"from",{"type":212,"tag":223,"props":246,"children":248},{"style":247},"--shiki-default:#032F62;--shiki-light:#032F62;--shiki-dark:#9ECBFF",[249],{"type":232,"value":250}," \"@quirekit\u002Fcore\"",{"type":212,"tag":223,"props":252,"children":253},{"style":236},[254],{"type":232,"value":255},";\n",{"type":212,"tag":223,"props":257,"children":258},{"class":225,"line":187},[259],{"type":212,"tag":223,"props":260,"children":261},{"emptyLinePlaceholder":198},[262],{"type":232,"value":263},"\n",{"type":212,"tag":223,"props":265,"children":267},{"class":225,"line":266},3,[268],{"type":212,"tag":223,"props":269,"children":271},{"style":270},"--shiki-default:#6A737D;--shiki-light:#6A737D;--shiki-dark:#6A737D",[272],{"type":232,"value":273},"\u002F** A host-authored behavior extension using the same typed command registry as the toolbar. *\u002F\n",{"type":212,"tag":223,"props":275,"children":277},{"class":225,"line":276},4,[278,283,288,294,299,304,310],{"type":212,"tag":223,"props":279,"children":280},{"style":229},[281],{"type":232,"value":282},"export",{"type":212,"tag":223,"props":284,"children":285},{"style":229},[286],{"type":232,"value":287}," const",{"type":212,"tag":223,"props":289,"children":291},{"style":290},"--shiki-default:#005CC5;--shiki-light:#005CC5;--shiki-dark:#79B8FF",[292],{"type":232,"value":293}," writingShortcuts",{"type":212,"tag":223,"props":295,"children":296},{"style":229},[297],{"type":232,"value":298}," =",{"type":212,"tag":223,"props":300,"children":301},{"style":236},[302],{"type":232,"value":303}," Extension.",{"type":212,"tag":223,"props":305,"children":307},{"style":306},"--shiki-default:#6F42C1;--shiki-light:#6F42C1;--shiki-dark:#B392F0",[308],{"type":232,"value":309},"create",{"type":212,"tag":223,"props":311,"children":312},{"style":236},[313],{"type":232,"value":314},"({\n",{"type":212,"tag":223,"props":316,"children":318},{"class":225,"line":317},5,[319,324,329],{"type":212,"tag":223,"props":320,"children":321},{"style":236},[322],{"type":232,"value":323},"  name: ",{"type":212,"tag":223,"props":325,"children":326},{"style":247},[327],{"type":232,"value":328},"\"writingShortcuts\"",{"type":212,"tag":223,"props":330,"children":331},{"style":236},[332],{"type":232,"value":333},",\n",{"type":212,"tag":223,"props":335,"children":337},{"class":225,"line":336},6,[338,343,348],{"type":212,"tag":223,"props":339,"children":340},{"style":270},[341],{"type":232,"value":342},"  \u002F** ",{"type":212,"tag":223,"props":344,"children":345},{"style":229},[346],{"type":232,"value":347},"@returns",{"type":212,"tag":223,"props":349,"children":350},{"style":270},[351],{"type":232,"value":352}," A keyboard binding that participates in the editor's existing history. *\u002F\n",{"type":212,"tag":223,"props":354,"children":356},{"class":225,"line":355},7,[357,362],{"type":212,"tag":223,"props":358,"children":359},{"style":306},[360],{"type":232,"value":361},"  addKeyboardShortcuts",{"type":212,"tag":223,"props":363,"children":364},{"style":236},[365],{"type":232,"value":366},"() {\n",{"type":212,"tag":223,"props":368,"children":370},{"class":225,"line":369},8,[371,376,381,386,391,396,401,406,411,416,421,426],{"type":212,"tag":223,"props":372,"children":373},{"style":229},[374],{"type":232,"value":375},"    return",{"type":212,"tag":223,"props":377,"children":378},{"style":236},[379],{"type":232,"value":380}," { ",{"type":212,"tag":223,"props":382,"children":383},{"style":247},[384],{"type":232,"value":385},"\"Mod-Shift-b\"",{"type":212,"tag":223,"props":387,"children":388},{"style":236},[389],{"type":232,"value":390},": () ",{"type":212,"tag":223,"props":392,"children":393},{"style":229},[394],{"type":232,"value":395},"=>",{"type":212,"tag":223,"props":397,"children":398},{"style":290},[399],{"type":232,"value":400}," this",{"type":212,"tag":223,"props":402,"children":403},{"style":236},[404],{"type":232,"value":405},".editor?.commands.",{"type":212,"tag":223,"props":407,"children":408},{"style":306},[409],{"type":232,"value":410},"toggleBold",{"type":212,"tag":223,"props":412,"children":413},{"style":236},[414],{"type":232,"value":415},"() ",{"type":212,"tag":223,"props":417,"children":418},{"style":229},[419],{"type":232,"value":420},"??",{"type":212,"tag":223,"props":422,"children":423},{"style":290},[424],{"type":232,"value":425}," false",{"type":212,"tag":223,"props":427,"children":428},{"style":236},[429],{"type":232,"value":430}," };\n",{"type":212,"tag":223,"props":432,"children":434},{"class":225,"line":433},9,[435],{"type":212,"tag":223,"props":436,"children":437},{"style":236},[438],{"type":232,"value":439},"  },\n",{"type":212,"tag":223,"props":441,"children":443},{"class":225,"line":442},10,[444],{"type":212,"tag":223,"props":445,"children":446},{"style":236},[447],{"type":232,"value":448},"});\n",{"type":212,"tag":450,"props":451,"children":452},"style",{},[453],{"type":232,"value":454},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",1793045209087]