MCPcopy Create free account
hub / github.com/71/logseq-snippets / saveState

Method saveState

script-block.js:87–107  ·  view source on GitHub ↗
(x = state)

Source from the content-addressed store, hash-verified

85 pattern = this.getAttribute("pattern") ?? "(<script-block state=').+('>)",
86 patternRe = new RegExp(pattern);
87 const saveState = (x = state) => {
88 const json = JSON.stringify(x),
89 block = this.closest("[blockid]"),
90 blockId = block.getAttribute("blockid");
91
92 requestAnimationFrame(() => {
93 const textarea = document.getElementById("edit-block-1-" + blockId),
94 escaped = json.replace(/&/g, "&amp;").replace(/'/g, "&apos;")
95 .replace(/</g, "&lt;").replace(/>/g, "&gt;")
96 .replace(/\r\n/g, "&#13;").replace(/[\r\n]/g, "&#13;");
97
98 textarea.value = textarea.value.replace(
99 pattern,
100 (_, before, after) => before + escaped + after,
101 );
102 setTimeout(() => {
103 textarea.dispatchEvent(new KeyboardEvent("keydown", { keyCode: 27 }));
104 }, 100);
105 });
106 block.click();
107 };
108
109 const body = this.innerHTML.slice(4, this.innerHTML.length - 3),
110 f = Function("save", "html", "svg", body),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected