| 1 |
var openStationGutenbergDropReceiver=function(p){"use strict";const k=".block-editor-block-list__layout",y="[data-block]",x='iframe[name="editor-canvas"]';function F(t,e,n){const r=t.querySelector(x);if(!r)return{doc:t,x:e,y:n};let o=null;try{o=r.contentDocument}catch{o=null}if(!o)return{doc:t,x:e,y:n};const i=r.getBoundingClientRect();return{doc:o,x:e-i.left,y:n-i.top}}function E(t){return!!t&&t.nodeType===1}function I(t){return Array.from(t.children).filter(e=>E(e)&&e.hasAttribute("data-block"))}function g(t){const e=t.parentElement?.closest(y);return e?e.getAttribute("data-block")??"":""}function C(t){if(t.classList.contains("is-horizontal"))return!0;const e=t.ownerDocument.defaultView;if(!e)return!1;const n=e.getComputedStyle(t);return n.display==="flex"&&(n.flexDirection==="row"||n.flexDirection==="row-reverse")}function j(t,e,n){const r=t.elementFromPoint(e,n);if(!r)return null;const o=r.closest(k),i=r.closest(y);if(E(i)&&(!o||o.contains(i))){const c=i.parentElement?.closest(k);if(!c)return null;const w=I(c).indexOf(i);if(w===-1)return null;const d=i.getBoundingClientRect(),X=C(c)?e>d.left+d.width/2:n>d.top+d.height/2;return{rootClientId:g(c),index:w+(X?1:0)}}const a=o;if(!a)return null;const u=I(a),f=C(a);for(let c=0;c<u.length;c++){const v=u[c].getBoundingClientRect();if(f?v.left>e:v.top>n)return{rootClientId:g(a),index:c}}return{rootClientId:g(a),index:u.length}}function _(t,e){return!t||!e?t===e:t.rootClientId===e.rootClientId&&t.index===e.index}function P(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function S(t){const e=t.trimStart().toLowerCase();return!(e.startsWith("javascript:")||e.startsWith("data:")||e.startsWith("vbscript:"))}function D(t){if(t.kind==="attachment"){if(!t.url||!S(t.url))return null;const r=t.mime||"";return r.startsWith("image/")?{name:"core/image",attributes:{id:t.id,url:t.url,alt:t.alt||"",caption:""}}:r.startsWith("video/")?{name:"core/video",attributes:{id:t.id,src:t.url}}:r.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.kind==="upload"||!t.url||!S(t.url))return null;const e=P(t.title||t.url);return{name:"core/paragraph",attributes:{content:`<a href="${P(t.url)}">${e}</a>`}}}async function B(){return new Promise((t,e)=>{let n=0;const r=300,o=()=>{const i=window.wp;if(i?.blocks&&i.data){t({blocks:i.blocks,data:i.data});return}if(n++,n>r){e(new Error("desktop-mode/gutenberg-drop-receiver: timed out waiting for wp.blocks + wp.data"));return}requestAnimationFrame(o)};o()})}let l=null;function m(t,e,n){const r=n?{doc:n,x:t,y:e}:F(document,t,e),o=j(r.doc,r.x,r.y);if(_(o,l))return;l=o;const i=window.wp?.data?.dispatch("core/block-editor");i&&(o?i.showInsertionPoint(o.rootClientId||void 0,o.index,{operation:"insert"}):i.hideInsertionPoint())}function b(){const t=l!==null;l=null,t&&window.wp?.data?.dispatch("core/block-editor")?.hideInsertionPoint()}async function O(t,e,n){const r=D(t);if(!r){b();return}e&&m(e.x,e.y,n);const o=l;b();const{blocks:i,data:a}=await B(),u=i.createBlock(r.name,r.attributes),f=a.dispatch("core/block-editor");o?f.insertBlocks([u],o.index,o.rootClientId||void 0):f.insertBlocks([u])}function L(t){if(window.parent!==window)try{window.parent.postMessage({type:"os-drop-failed",reason:t},window.location.origin)}catch{}}function R(t){if(!t||typeof t!="object")return!1;const e=t;if(e.type!=="os-drop")return!1;const n=e.payload;return!n||typeof n!="object"?!1:n.kind==="attachment"||n.kind==="post"||n.kind==="user"}let s=null;function T(t){const e=t.dataTransfer?.types;if(!e)return!1;const n=e;if(typeof n.includes=="function")return n.includes("Files");if(typeof n.contains=="function")return n.contains("Files");for(let r=0;r<n.length;r++)if(n[r]==="Files")return!0;return!1}function H(t){if(!t||typeof t!="object")return!1;const e=t;if(e.type!=="os-drag-over")return!1;const n=e.payload;return!n||typeof n!="object"?!1:n.kind==="attachment"||n.kind==="post"||n.kind==="user"||n.kind==="upload"}function W(t){if(!t||typeof t!="object")return!1;const e=t;if(e.type!=="os-drag-move")return!1;const n=e.position;return!!n&&typeof n.x=="number"&&typeof n.y=="number"}function q(t){return!!t&&typeof t=="object"&&t.type==="os-drag-leave"}function N(t){if(!s||T(t))return;t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy");const e=A(t);e&&m(t.clientX,t.clientY,e)}function A(t){return t.target?.ownerDocument??void 0}function z(t){if(!s)return;if(T(t)){s=null;return}const e=s;s=null,t.preventDefault(),t.stopPropagation(),typeof t.stopImmediatePropagation=="function"&&t.stopImmediatePropagation();const n=A(t);O(e,{x:t.clientX,y:t.clientY},n).catch(r=>{const o=r instanceof Error?r.message:String(r);console.error("[openstation] Gutenberg drop receiver native-drop insert failed:",r),L(o)})}function M(t){const e=t;e.__openStationDropReceiverAttached||(e.__openStationDropReceiverAttached=!0,t.addEventListener("drop",z,!0),t.addEventListener("dragover",N,!0))}function h(){M(document),document.querySelectorAll("iframe").forEach(t=>{try{const e=t.contentDocument;e&&M(e)}catch{}})}function G(){const t=window.location.origin;window.addEventListener("message",e=>{if(e.origin===t){if(H(e.data)){s=e.data.payload;return}if(W(e.data)){s&&m(e.data.position.x,e.data.position.y);return}if(q(e.data)){s=null,b();return}R(e.data)&&(s=null,O(e.data.payload,e.data.position).catch(n=>{const r=n instanceof Error?n.message:String(n);console.error("[openstation] Gutenberg drop receiver insert failed:",n),L(r)}))}}),h(),typeof MutationObserver<"u"&&document.documentElement&&new MutationObserver(e=>{for(const n of e)for(const r of Array.from(n.addedNodes))if(r instanceof HTMLIFrameElement||r instanceof Element&&r.querySelector?.("iframe")){h();return}}).observe(document.documentElement,{childList:!0,subtree:!0}),document.addEventListener("load",e=>{e.target instanceof HTMLIFrameElement&&h()},!0)}return G(),p.buildBlockSpec=D,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"}),p}({}); |