@shopware-ag/admin-extension-sdk
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -1,1 +0,1 @@ | ||
var te=Object.defineProperty;var D=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var I=(o,r,i)=>r in o?te(o,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[r]=i,w=(o,r)=>{for(var i in r||(r={}))ne.call(r,i)&&I(o,i,r[i]);if(D)for(var i of D(r))oe.call(r,i)&&I(o,i,r[i]);return o};(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o.sw={}))})(this,function(o){"use strict";function r(){return String(Date.now().toString(36)+Math.random().toString(36).substr(2))}function i(e,t){for(let s in e){const n=e[s];t.apply(this,[e,s,n]),h(n)&&i(n,t)}}function h(e){return e!==null&&typeof e=="object"}function O(e){H(e)}function x(e){z(e)}const y={};let m=!1;function E(){m||(m=!0,p("__function__",async({args:e,id:t})=>await Promise.resolve(y[t](...e))))}function H(e){i(e,(t,s,n)=>{if(typeof n=="function"){const a=r();y[a]=n,t[s]={__type__:"__function__",id:a},E()}})}function z(e){i(e,(t,s,n)=>{if(h(n)&&n.__type__&&n.__type__==="__function__"&&typeof n.id=="string"){const a=n.id;t[s]=(...d)=>l("__function__",{args:d,id:a})}})}const b=new Set;function l(e,t,s){const n=r(),a=t!=null?t:{},d={_type:e,_data:a,_callbackId:n};O(d);const u=JSON.stringify(d);let _=!1;const f=3e3;return new Promise((V,ee)=>{const S=function(L){if(typeof L.data!="string")return;let g;try{g=JSON.parse(L.data)}catch{return}!T(g)||g._callbackId===n&&(!g.hasOwnProperty("_response")||(window.removeEventListener("message",S),_||(_=!0,V(g._response))))};window.addEventListener("message",S),window.parent.__Cypress__?s?s.postMessage(u,window.parent.origin):window.postMessage(u,window.parent.origin):s?s.postMessage(u,window.parent.origin):window.parent.postMessage(u,window.parent.origin),setTimeout(()=>{_||ee("Send timeout expired. It could be possible that no handler for the postMessage request exists or that the handler freezed.")},f)})}function p(e,t){const s=async function(n){var f;if(typeof n.data!="string")return;let a;try{a=JSON.parse(n.data)}catch{return}if(!P(a)||a._type!==e)return;x(a);const d=await Promise.resolve(t(a._data,{_event_:n})),u={_callbackId:a._callbackId,_type:a._type,_response:d!=null?d:null},_=JSON.stringify(u);n.source?n.source.postMessage(_,{targetOrigin:(f=n.source.origin)!=null?f:"*"}):window.postMessage(_,window.origin)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)}function R(e,t){return p(e,t)}function c(e,t){return s=>l(e,w(w({},t),s))}function M(e){return t=>R(e,t)}(async()=>{p("__registerWindow__",(e,t)=>{t._event_.source?b.add(t._event_.source):b.add(window)}),await l("__registerWindow__",{})})().catch(e=>console.error(e));function P(e){const t=e;return!!t._type&&!!t._data&&!!t._callbackId}function T(e){const t=e;return!!t._type&&!!t.hasOwnProperty("_response")&&!!t._callbackId}const j=c("windowRedirect"),k=c("windowReload",{});var v=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",redirect:j,reload:k});const N=c("notificationDispatch");var C=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",dispatch:N});const J=c("contextLanguage",{}),U=M("contextLanguage"),$=c("contextEnvironment",{}),q=c("contextLocale",{}),A=M("contextLocale"),W=c("contextCurrency",{});var B=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",getLanguage:J,subscribeLanguage:U,getEnvironment:$,getLocale:q,subscribeLocale:A,getCurrency:W});const F=c("uiComponentSectionRenderer");var G=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",add:F});const K=e=>new URLSearchParams(window.location.search).get("location-id")===e,Q=e=>{if(e)return l("locationUpdateHeight",{height:e});const t=document.documentElement.scrollHeight;return l("locationUpdateHeight",{height:t})},X="sw-main-hidden";var Y=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",is:K,updateHeight:Q,MAIN_HIDDEN:X});const Z={componentSection:G};o.context=B,o.location=Y,o.notification=C,o.ui=Z,o.window=v,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"}); | ||
var ne=Object.defineProperty;var I=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var O=(o,r,s)=>r in o?ne(o,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[r]=s,h=(o,r)=>{for(var s in r||(r={}))oe.call(r,s)&&O(o,s,r[s]);if(I)for(var s of I(r))re.call(r,s)&&O(o,s,r[s]);return o};(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o.sw={}))})(this,function(o){"use strict";function r(){return String(Date.now().toString(36)+Math.random().toString(36).substr(2))}function s(e,t){for(let i in e){const n=e[i];t.apply(this,[e,i,n]),y(n)&&s(n,t)}}function y(e){return e!==null&&typeof e=="object"}function x(e){z(e)}function E(e){R(e)}const m={};let b=!1;function H(){b||(b=!0,p("__function__",async({args:e,id:t})=>await Promise.resolve(m[t](...e))))}function z(e){s(e,(t,i,n)=>{if(typeof n=="function"){const a=r();m[a]=n,t[i]={__type__:"__function__",id:a},H()}})}function R(e){s(e,(t,i,n)=>{if(y(n)&&n.__type__&&n.__type__==="__function__"&&typeof n.id=="string"){const a=n.id;t[i]=(...d)=>l("__function__",{args:d,id:a})}})}const M=new Set;function l(e,t,i){const n=r(),a=t!=null?t:{},d={_type:e,_data:a,_callbackId:n};x(d);const u=JSON.stringify(d);let _=!1;const f=3e3;return new Promise((ee,te)=>{const L=function(D){if(typeof D.data!="string")return;let g;try{g=JSON.parse(D.data)}catch{return}!j(g)||g._callbackId===n&&(!g.hasOwnProperty("_response")||(window.removeEventListener("message",L),_||(_=!0,ee(g._response))))};window.addEventListener("message",L),window.parent.__Cypress__?i?i.postMessage(u,window.parent.origin):window.postMessage(u,window.parent.origin):i?i.postMessage(u,window.parent.origin):window.parent.postMessage(u,window.parent.origin),setTimeout(()=>{_||te("Send timeout expired. It could be possible that no handler for the postMessage request exists or that the handler freezed.")},f)})}function p(e,t){const i=async function(n){var f;if(typeof n.data!="string")return;let a;try{a=JSON.parse(n.data)}catch{return}if(!T(a)||a._type!==e)return;E(a);const d=await Promise.resolve(t(a._data,{_event_:n})),u={_callbackId:a._callbackId,_type:a._type,_response:d!=null?d:null},_=JSON.stringify(u);n.source?n.source.postMessage(_,{targetOrigin:(f=n.source.origin)!=null?f:"*"}):window.postMessage(_,window.origin)};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)}function P(e,t){return p(e,t)}function c(e,t){return i=>l(e,h(h({},t),i))}function S(e){return t=>P(e,t)}(async()=>{p("__registerWindow__",(e,t)=>{t._event_.source?M.add(t._event_.source):M.add(window)}),await l("__registerWindow__",{})})().catch(e=>console.error(e));function T(e){const t=e;return!!t._type&&!!t._data&&!!t._callbackId}function j(e){const t=e;return!!t._type&&!!t.hasOwnProperty("_response")&&!!t._callbackId}const k=c("windowRedirect"),v=c("windowReload",{});var N=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",redirect:k,reload:v});const C=c("notificationDispatch");var J=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",dispatch:C});const U=c("contextLanguage",{}),$=S("contextLanguage"),q=c("contextEnvironment",{}),A=c("contextLocale",{}),W=S("contextLocale"),B=c("contextCurrency",{});var F=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",getLanguage:U,subscribeLanguage:$,getEnvironment:q,getLocale:A,subscribeLocale:W,getCurrency:B});const G=c("uiComponentSectionRenderer");var K=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",add:G});function w(){return new URLSearchParams(window.location.search).get("location-id")}const Q=e=>w()===e,X=e=>{if(e)return l("locationUpdateHeight",{height:e,locationId:w()});const t=document.documentElement.scrollHeight;return l("locationUpdateHeight",{height:t,locationId:w()})},Y="sw-main-hidden";var Z=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",is:Q,updateHeight:X,MAIN_HIDDEN:Y});const V={componentSection:K};o.context=F,o.location=Z,o.notification=J,o.ui=V,o.window=N,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"}); |
@@ -10,2 +10,6 @@ export declare const is: (location: string) => boolean; | ||
height: number; | ||
/** | ||
* The locationID of the current element | ||
*/ | ||
locationId: string | null; | ||
}; |
import { send } from '../channel'; | ||
function getLocationId() { | ||
const params = new URLSearchParams(window.location.search); | ||
return params.get('location-id'); | ||
} | ||
// TODO: add documentation | ||
export const is = (location) => { | ||
const params = new URLSearchParams(window.location.search); | ||
return params.get('location-id') === location; | ||
return getLocationId() === location; | ||
}; | ||
export const updateHeight = (height) => { | ||
if (height) { | ||
return send('locationUpdateHeight', { height }); | ||
return send('locationUpdateHeight', { | ||
height, | ||
locationId: getLocationId(), | ||
}); | ||
} | ||
// if no height is defined then send the current document height | ||
const currentHeight = document.documentElement.scrollHeight; | ||
return send('locationUpdateHeight', { height: currentHeight }); | ||
return send('locationUpdateHeight', { | ||
height: currentHeight, | ||
locationId: getLocationId(), | ||
}); | ||
}; | ||
@@ -15,0 +24,0 @@ // TODO: add startAutoResizer to update the height automatically |
{ | ||
"name": "@shopware-ag/admin-extension-sdk", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"repository": "git://github.com/shopware/admin-extension-sdk.git", | ||
@@ -5,0 +5,0 @@ "description": "The SDK for App iframes to communicate with the Shopware Adminstration", |
@@ -10,2 +10,6 @@ export declare const is: (location: string) => boolean; | ||
height: number; | ||
/** | ||
* The locationID of the current element | ||
*/ | ||
locationId: string | null; | ||
}; |
@@ -14,6 +14,9 @@ (function (factory) { | ||
const channel_1 = require("../channel"); | ||
function getLocationId() { | ||
const params = new URLSearchParams(window.location.search); | ||
return params.get('location-id'); | ||
} | ||
// TODO: add documentation | ||
const is = (location) => { | ||
const params = new URLSearchParams(window.location.search); | ||
return params.get('location-id') === location; | ||
return getLocationId() === location; | ||
}; | ||
@@ -23,7 +26,13 @@ exports.is = is; | ||
if (height) { | ||
return (0, channel_1.send)('locationUpdateHeight', { height }); | ||
return (0, channel_1.send)('locationUpdateHeight', { | ||
height, | ||
locationId: getLocationId(), | ||
}); | ||
} | ||
// if no height is defined then send the current document height | ||
const currentHeight = document.documentElement.scrollHeight; | ||
return (0, channel_1.send)('locationUpdateHeight', { height: currentHeight }); | ||
return (0, channel_1.send)('locationUpdateHeight', { | ||
height: currentHeight, | ||
locationId: getLocationId(), | ||
}); | ||
}; | ||
@@ -30,0 +39,0 @@ exports.updateHeight = updateHeight; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
116782
1805