[{"data":1,"prerenderedAt":643},["ShallowReactive",2],{"quirekit-doc:\u002Fen\u002Fapi\u002Feditor":3},{"id":4,"title":5,"body":6,"description":632,"extension":633,"keywords":634,"locale":635,"meta":636,"navigation":637,"order":71,"path":638,"section":639,"seo":640,"stem":641,"__hash__":642},"docs\u002Fapi\u002Feditor.en.md","Editor: state, commands and lifetime",{"type":7,"value":8,"toc":625},"minimark",[9,24,29,58,182,201,214,218,222,375,386,390,464,470,489,492,496,583,586,589,593,611,614,621],[10,11,12,13,18,19,23],"p",{},"Use ",[14,15,17],"a",{"href":16},"\u002Fen\u002Fbuild","the complete product"," to see these methods together. This page explains invocation semantics; ",[14,20,22],{"href":21},"\u002Fen\u002Fapi\u002Fcore","Core API"," retains full source signatures.",[25,26,28],"h2",{"id":27},"creation-and-state","Creation and state",[10,30,31,35,36,39,40,39,43,39,46,49,50,53,54,57],{},[32,33,34],"code",{},"new Editor(options)"," establishes schema, commands and create-time extensions. Common options are ",[32,37,38],{},"extensions",", ",[32,41,42],{},"content",[32,44,45],{},"editable",[32,47,48],{},"element"," and ",[32,51,52],{},"mode",". Do not pass browser DOM during SSR. Install an adapter before explicit mounting. Incompatible schema changes need a new session and migration rather than assuming ",[32,55,56],{},"setOptions({ extensions })"," hot-recompiles the model.",[59,60,65],"pre",{"className":61,"code":62,"language":63,"meta":64,"style":64},"language-ts shiki shiki-themes github-light github-light github-dark","const editor = new Editor({ extensions, content, editable: true })\nconst view = editor.mount({ element, mode: 'canvas', id: 'main' })\nconst pm = editor.state.pm\nconst { from, to } = pm.selection\nconst document = editor.state.doc\n","ts","",[32,66,67,100,131,144,169],{"__ignoreMap":64},[68,69,72,76,80,83,86,90,94,97],"span",{"class":70,"line":71},"line",1,[68,73,75],{"class":74},"sDD9d","const",[68,77,79],{"class":78},"sUNQB"," editor",[68,81,82],{"class":74}," =",[68,84,85],{"class":74}," new",[68,87,89],{"class":88},"sgQzM"," Editor",[68,91,93],{"class":92},"sVPnS","({ extensions, content, editable: ",[68,95,96],{"class":78},"true",[68,98,99],{"class":92}," })\n",[68,101,103,105,108,110,113,116,119,123,126,129],{"class":70,"line":102},2,[68,104,75],{"class":74},[68,106,107],{"class":78}," view",[68,109,82],{"class":74},[68,111,112],{"class":92}," editor.",[68,114,115],{"class":88},"mount",[68,117,118],{"class":92},"({ element, mode: ",[68,120,122],{"class":121},"s-HEn","'canvas'",[68,124,125],{"class":92},", id: ",[68,127,128],{"class":121},"'main'",[68,130,99],{"class":92},[68,132,134,136,139,141],{"class":70,"line":133},3,[68,135,75],{"class":74},[68,137,138],{"class":78}," pm",[68,140,82],{"class":74},[68,142,143],{"class":92}," editor.state.pm\n",[68,145,147,149,152,155,157,160,163,166],{"class":70,"line":146},4,[68,148,75],{"class":74},[68,150,151],{"class":92}," { ",[68,153,154],{"class":78},"from",[68,156,39],{"class":92},[68,158,159],{"class":78},"to",[68,161,162],{"class":92}," } ",[68,164,165],{"class":74},"=",[68,167,168],{"class":92}," pm.selection\n",[68,170,172,174,177,179],{"class":70,"line":171},5,[68,173,75],{"class":74},[68,175,176],{"class":78}," document",[68,178,82],{"class":74},[68,180,181],{"class":92}," editor.state.doc\n",[10,183,184,185,188,189,192,193,196,197,200],{},"External ",[32,186,187],{},"editor.state"," is a QuireKit wrapper with native PM state at ",[32,190,191],{},".pm",". A raw command's contextual ",[32,194,195],{},"state"," is the shared-transaction PM facade, where ",[32,198,199],{},"state.selection"," is direct. Keep those contexts distinct.",[10,202,203,204,208,209,213],{},"See ",[14,205,207],{"href":206},"\u002Fen\u002Fapi\u002Foptions","options and events"," for all creation, replacement and event fields, and ",[14,210,212],{"href":211},"\u002Fen\u002Fconcepts\u002Fselection","selections"," for caret, range and node targets.",[215,216],"docs-api",{"name":217},"QuireEditorState",[25,219,221],{"id":220},"reading-and-writing","Reading and writing",[223,224,225,241],"table",{},[226,227,228],"thead",{},[229,230,231,235,238],"tr",{},[232,233,234],"th",{},"Method",[232,236,237],{},"Input → result",[232,239,240],{},"Effects and use",[242,243,244,258,271,284,297,310,323,336,349,362],"tbody",{},[229,245,246,252,255],{},[247,248,249],"td",{},[32,250,251],{},"getJSON()",[247,253,254],{},"none → canonical JSON",[247,256,257],{},"Serialize explicitly for persistence\u002Fdownload\u002Fconversion, not each input projection",[229,259,260,265,268],{},[247,261,262],{},[32,263,264],{},"getHTML()",[247,266,267],{},"none → HTML",[247,269,270],{},"Uses installed serializers, not paginated Canvas pixels",[229,272,273,278,281],{},[247,274,275],{},[32,276,277],{},"getText(options?)",[247,279,280],{},"text serialization options → string",[247,282,283],{},"Plain text with optional block separators and node serializers",[229,285,286,291,294],{},[247,287,288],{},[32,289,290],{},"getMarkdown()",[247,292,293],{},"none → string",[247,295,296],{},"Uses installed Markdown conversion rules",[229,298,299,304,307],{},[247,300,301],{},[32,302,303],{},"commands.setContent(content, options)",[247,305,306],{},"compatible content\u002Foptions → boolean",[247,308,309],{},"Ordinary content replacement; does not replace all top-node attributes",[229,311,312,317,320],{},[247,313,314],{},[32,315,316],{},"commands.replaceDocument(content, options)",[247,318,319],{},"complete document → boolean",[247,321,322],{},"Restore files including root attributes, reset selection to start, commit with import origin\u002Fnon-history",[229,324,325,330,333],{},[247,326,327],{},[32,328,329],{},"commands.insertContent(content)",[247,331,332],{},"text\u002FHTML\u002FJSON → boolean",[247,334,335],{},"Insert at current selection through command\u002Fhistory semantics",[229,337,338,343,346],{},[247,339,340],{},[32,341,342],{},"isActive(name, attrs?)",[247,344,345],{},"Node\u002FMark name and conditions → boolean",[247,347,348],{},"Read formatting, not executability or persistence",[229,350,351,356,359],{},[247,352,353],{},[32,354,355],{},"setEditable(value, emitUpdate?)",[247,357,358],{},"boolean → void",[247,360,361],{},"Update edit policy; may emit update by default; host permissions still need projection",[229,363,364,369,372],{},[247,365,366],{},[32,367,368],{},"setOptions(options)",[247,370,371],{},"partial options → void",[247,373,374],{},"Update options, without assuming schema recompilation or content migration",[10,376,377,378,382,383,385],{},"Choose invalid-content policy explicitly and ",[14,379,381],{"href":380},"\u002Fen\u002Fguide\u002Fcontent","validate independently"," before restoring. ",[32,384,264],{}," requires a DOM document and cannot simply be assumed available on a server. Command handling, actual document change and persistence acknowledgement are separate results.",[25,387,389],{"id":388},"three-command-modes","Three command modes",[59,391,393],{"className":61,"code":392,"language":63,"meta":64,"style":64},"editor.commands.toggleBold()\neditor.chain().focus().toggleBold().run()\neditor.can().toggleBold()\neditor.can().chain().toggleBold().run()\n",[32,394,395,406,431,444],{"__ignoreMap":64},[68,396,397,400,403],{"class":70,"line":71},[68,398,399],{"class":92},"editor.commands.",[68,401,402],{"class":88},"toggleBold",[68,404,405],{"class":92},"()\n",[68,407,408,411,414,417,420,422,424,426,429],{"class":70,"line":102},[68,409,410],{"class":92},"editor.",[68,412,413],{"class":88},"chain",[68,415,416],{"class":92},"().",[68,418,419],{"class":88},"focus",[68,421,416],{"class":92},[68,423,402],{"class":88},[68,425,416],{"class":92},[68,427,428],{"class":88},"run",[68,430,405],{"class":92},[68,432,433,435,438,440,442],{"class":70,"line":133},[68,434,410],{"class":92},[68,436,437],{"class":88},"can",[68,439,416],{"class":92},[68,441,402],{"class":88},[68,443,405],{"class":92},[68,445,446,448,450,452,454,456,458,460,462],{"class":70,"line":146},[68,447,410],{"class":92},[68,449,437],{"class":88},[68,451,416],{"class":92},[68,453,413],{"class":88},[68,455,416],{"class":92},[68,457,402],{"class":88},[68,459,416],{"class":92},[68,461,428],{"class":88},[68,463,405],{"class":92},[10,465,466,467,469],{},"Custom raw commands use the supplied ",[32,468,229],{}," and dispatch guard. Dry runs must not perform networking, dialogs or real-state writes. A false result must not be displayed as success.",[10,471,472,475,476,479,480,483,484,488],{},[32,473,474],{},"can()"," is not a permission check, and ",[32,477,478],{},"setEditable(false)"," does not block every programmatic command. A false ",[32,481,482],{},"run()"," does not automatically revert other steps in the chain; see ",[14,485,487],{"href":486},"\u002Fen\u002Fconcepts\u002Fcommands","commands and transactions",".",[215,490],{"name":491},"CommandProps",[25,493,495],{"id":494},"mounting-and-exit","Mounting and exit",[223,497,498,510],{},[226,499,500],{},[229,501,502,504,507],{},[232,503,234],{},[232,505,506],{},"Result",[232,508,509],{},"Lifetime",[242,511,512,525,545,558,571],{},[229,513,514,519,522],{},[247,515,516],{},[32,517,518],{},"mount({ element, mode, id?, editable? })",[247,520,521],{},"mounted view",[247,523,524],{},"First is primary; later calls add views, read-only by default",[229,526,527,532,534],{},[247,528,529],{},[32,530,531],{},"mount(element)",[247,533,521],{},[247,535,536,537,540,541,544],{},"Compatibility shorthand selects ",[32,538,539],{},"html",", not native ",[32,542,543],{},"dom","; tutorials use explicit options",[229,546,547,552,555],{},[247,548,549],{},[32,550,551],{},"changeMode(mode, options?)",[247,553,554],{},"replacement primary view",[247,556,557],{},"Preserve Core content\u002Fhistory; register the mode first",[229,559,560,565,568],{},[247,561,562],{},[32,563,564],{},"unmount()",[247,566,567],{},"void",[247,569,570],{},"Release every view while retaining Core state",[229,572,573,578,580],{},[247,574,575],{},[32,576,577],{},"destroy()",[247,579,567],{},[247,581,582],{},"Final destruction; no later commands or mounting",[215,584],{"name":585},"QuireEditorMountOptions",[215,587],{"name":588},"QuireEditorChangeModeOptions",[25,590,592],{"id":591},"events","Events",[10,594,595,598,599,602,603,606,607,610],{},[32,596,597],{},"on('transaction', listener)"," observes accepted state. Use ",[32,600,601],{},"update"," for content, ",[32,604,605],{},"selectionUpdate"," for selection, and focus events only when consumed. Release host subscriptions using the same function reference with ",[32,608,609],{},"off",". The reference makes one bounded control projection from transaction events and publishes saving state separately.",[215,612],{"name":613},"QuireEditorTransactionEvent",[10,615,203,616,620],{},[14,617,619],{"href":618},"\u002Fen\u002Fbuild\u002Fcommands","the complete session"," for dirty state and concurrent saving.",[622,623,624],"style",{},"html pre.shiki code .sDD9d, html code.shiki .sDD9d{--shiki-default:#D73A49;--shiki-light:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sUNQB, html code.shiki .sUNQB{--shiki-default:#005CC5;--shiki-light:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sgQzM, html code.shiki .sgQzM{--shiki-default:#6F42C1;--shiki-light:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVPnS, html code.shiki .sVPnS{--shiki-default:#24292E;--shiki-light:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s-HEn, html code.shiki .s-HEn{--shiki-default:#032F62;--shiki-light:#032F62;--shiki-dark:#9ECBFF}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);}",{"title":64,"searchDepth":102,"depth":102,"links":626},[627,628,629,630,631],{"id":27,"depth":102,"text":28},{"id":220,"depth":102,"text":221},{"id":388,"depth":102,"text":389},{"id":494,"depth":102,"text":495},{"id":591,"depth":102,"text":592},"Task-oriented arguments, results, state shape and lifecycle effects.","md",null,"en",{},true,"\u002Fen\u002Fapi\u002Feditor","API and reference",{"title":5,"description":632},"api\u002Feditor.en","jWkFyVk5ZYrxWd2gGlu5i1l39moXlKIKn3vLFW6Dnl4",1793045209945]