| 1 |
var openStationGutenbergDropReceiver=function(s){"use strict";function u(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function f(t){const e=t.trimStart().toLowerCase();return!(e.startsWith("javascript:")||e.startsWith("data:")||e.startsWith("vbscript:"))}function l(t){if(t.kind==="attachment"){if(!t.url||!f(t.url))return null;const n=t.mime||"";return n.startsWith("image/")?{name:"core/image",attributes:{id:t.id,url:t.url,alt:t.alt||"",caption:""}}:n.startsWith("video/")?{name:"core/video",attributes:{id:t.id,src:t.url}}:n.startsWith("audio/")?{name:"core/audio",attributes:{id:t.id,src:t.url}}:{name:"core/file",attributes:{id:t.id,href:t.url,fileName:t.title}}}if(!t.url||!f(t.url))return null;const e=u(t.title||t.url);return{name:"core/paragraph",attributes:{content:`<a href="${u(t.url)}">${e}</a>`}}}async function b(){return new Promise((t,e)=>{let r=0;const n=300,o=()=>{const a=window.wp;if(a?.blocks&&a.data){t({blocks:a.blocks,data:a.data});return}if(r++,r>n){e(new Error("desktop-mode/gutenberg-drop-receiver: timed out waiting for wp.blocks + wp.data"));return}requestAnimationFrame(o)};o()})}async function d(t){const e=l(t);if(!e)return;const{blocks:r,data:n}=await b(),o=r.createBlock(e.name,e.attributes);n.dispatch("core/block-editor").insertBlocks([o])}function p(t){if(window.parent!==window)try{window.parent.postMessage({type:"os-drop-failed",reason:t},window.location.origin)}catch{}}function v(t){if(!t||typeof t!="object")return!1;const e=t;if(e.type!=="os-drop")return!1;const r=e.payload;return!r||typeof r!="object"?!1:r.kind==="attachment"||r.kind==="post"||r.kind==="user"}let i=null;function m(t){const e=t.dataTransfer?.types;if(!e)return!1;const r=e;if(typeof r.includes=="function")return r.includes("Files");if(typeof r.contains=="function")return r.contains("Files");for(let n=0;n<r.length;n++)if(r[n]==="Files")return!0;return!1}function w(t){if(!t||typeof t!="object")return!1;const e=t;if(e.type!=="os-drag-over")return!1;const r=e.payload;return!r||typeof r!="object"?!1:r.kind==="attachment"||r.kind==="post"||r.kind==="user"}function h(t){return!!t&&typeof t=="object"&&t.type==="os-drag-leave"}function k(t){i&&(m(t)||(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")))}function E(t){if(!i)return;if(m(t)){i=null;return}const e=i;i=null,t.preventDefault(),t.stopPropagation(),typeof t.stopImmediatePropagation=="function"&&t.stopImmediatePropagation(),d(e).catch(r=>{const n=r instanceof Error?r.message:String(r);console.error("[openstation] Gutenberg drop receiver native-drop insert failed:",r),p(n)})}function g(t){const e=t;e.__openStationDropReceiverAttached||(e.__openStationDropReceiverAttached=!0,t.addEventListener("drop",E,!0),t.addEventListener("dragover",k,!0))}function c(){g(document),document.querySelectorAll("iframe").forEach(t=>{try{const e=t.contentDocument;e&&g(e)}catch{}})}function y(){const t=window.location.origin;window.addEventListener("message",e=>{if(e.origin===t){if(w(e.data)){i=e.data.payload;return}if(h(e.data)){i=null;return}v(e.data)&&(i=null,d(e.data.payload).catch(r=>{const n=r instanceof Error?r.message:String(r);console.error("[openstation] Gutenberg drop receiver insert failed:",r),p(n)}))}}),c(),typeof MutationObserver<"u"&&document.documentElement&&new MutationObserver(e=>{for(const r of e)for(const n of Array.from(r.addedNodes))if(n instanceof HTMLIFrameElement||n instanceof Element&&n.querySelector?.("iframe")){c();return}}).observe(document.documentElement,{childList:!0,subtree:!0}),document.addEventListener("load",e=>{e.target instanceof HTMLIFrameElement&&c()},!0)}return y(),s.buildBlockSpec=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s}({}); |