import injectEBLogo from "./injectEBLogo"; const { apiFetch } = wp; const { parse } = wp.blocks; window.onload = function () { injectEBLogo(); document .querySelector("#eb-export-icon") .addEventListener("click", function (e) { e.preventDefault(); const title = wp.data .select("core/editor") .getEditedPostAttribute("title"); const content = wp.data.select("core/editor").getEditedPostContent(); const id = wp.data.select("core/editor").getCurrentPostId(); const type = wp.data.select("core/editor").getCurrentPostType(); const isEditedPostEmpty = wp.data .select("core/editor") .isEditedPostEmpty(); const { insertBlocks } = wp.data.dispatch("core/block-editor"); const data = { title: title, content: content }; if (!isEditedPostEmpty) { // Store in database then send data in cloud // wp.data.dispatch("core/editor").savePost(); // test item for insert block const item = '\r\n

TEST world

\r\n\r\n\r\n\r\n
Save 20%
Free shipping on all orders
\r\n'; insertBlocks(parse(item)); return; apiFetch({ path: `/wp/v2/${type}s/${id}`, method: "POST", // data: data data: { title: title, content: item }, }).then((res) => { const postData = { __file: "wp_block", ...data, }; }); } }); };