{"version":3,"file":"psidebar-vue.min.js","sources":["../../src/util/psidebar-vue.js"],"sourcesContent":["/* eslint no-unused-vars: warn */\n/* eslint max-len: [\"error\", { \"code\": 160 }] */\n/* eslint-disable no-trailing-spaces */\n/* eslint-disable no-console */\n/* eslint-env es6*/\nimport PortalVue from '../portal-vue/portal-vue.esm';\nimport Debugger from './debugger';\nlet debug = new Debugger(\"p-sidebar\");\n\n\nlet wrapper;\nlet contentwrapper;\nlet resizeObserver;\n/**\n * Create a new wrapper Around the \n * @param {String} target Query string to select root element next to which the sidebar will be placed. \n * Defaults to body\n * @param {String} offsetref Query string to select element that should appear above the sidebar. \n * Defaults to none\n */\nfunction createPortalTarget(target,offsetref) {\n let initializeWrapperContent = false;\n // First check if the sidebar wrapper already exists. \n // Creating the wrappers over and over again is a recipe for disaster.\n wrapper = document.querySelector(\"#p-sidebar-wrapper\");\n if (!wrapper) {\n initializeWrapperContent = true;\n // Otherwise, create it.\n wrapper = document.createElement(\"div\");\n wrapper.setAttribute(\"id\", \"p-sidebar-wrapper\");\n }\n // First check if the contentwrapper already exists\n contentwrapper = document.querySelector(\"#p-sidebar-contentwrapper\");\n if (!contentwrapper) {\n initializeWrapperContent = true;\n // Otherwise, create it.\n contentwrapper = document.createElement(\"div\");\n contentwrapper.setAttribute(\"id\", \"p-sidebar-contentwrapper\");\n wrapper.appendChild(contentwrapper);\n }\n\n if (initializeWrapperContent) {\n // Find containing target (otherwise use body)\n let targetEl = document.querySelector(target);\n console.info(`Targeting '${target}' to `, targetEl);\n if (!targetEl || targetEl.nodeType == \"HTML\") {\n targetEl = document.querySelector(\"body\");\n }\n \n // Move all target content parts to content wrapper....\n while (targetEl.childNodes.length > 0) {\n contentwrapper.appendChild(targetEl.childNodes[0]);\n }\n // Add sidebar wrapper to target Element\n targetEl.appendChild(wrapper);\n }\n // The actual target is created in a reposition call\n rePosition(false);\n // The \n setOffset(offsetref);\n}\n\n/**\n * Position a (new) sidebar element on the left or right \n * @param {Boolean} right Set to true to put the sidebar on the right\n */\nfunction rePosition(right) {\n // Place the portal target on the right place in the DOM.\n // Find or create the portal target.\n let el = document.querySelector(`#p-sidebar-mount`);\n if (!el) {\n el = document.createElement(\"div\");\n el.setAttribute(\"id\", `p-sidebar-mount`);\n\n // Initialize a resizeObser\n resizeObserver = new ResizeObserver(() => {\n let wx = 0 - el.getBoundingClientRect().width;\n wx += (wx != 0) ? \"px\" : \"\";\n el.style.setProperty(\"--p-sidebar-hideoffset\", wx);\n });\n resizeObserver.observe(el);\n\n }\n if (right) {\n wrapper.insertBefore(el, contentwrapper.nextSibling);\n } else {\n wrapper.insertBefore(el, contentwrapper);\n }\n}\n\n/**\n * Set the proper offset from the top on the sidebar related to the reference element \n * @param {String} reference Reference target for setting view height\n */\nfunction setOffset(reference) {\n const ref = reference ? document.querySelector(reference) : null;\n if (ref) {\n let offsetTop = (ref ? ref.offsetTop : 0);\n offsetTop += (offsetTop != 0) ? \"px\" : \"\";\n const el = document.querySelector(`#p-sidebar-mount`);\n if (el) {\n el.style.height = `calc( 100vh - ${offsetTop})`;\n el.style.marginTop = offsetTop;\n }\n }\n}\n\nexport default {\n install(Vue /* ,options */) {\n Vue.use(PortalVue);\n /* Create the portal target on initialization.\n Defaults to body. Offset and final position set through sidebar parameter.\n */\n window.addEventListener(\"load\", () => {\n createPortalTarget();\n });\n\n Vue.component('p-easeinout',{\n template: `\n \n `\n });\n\n Vue.component('p-sidebar', {\n props: {\n value: {\n type: Boolean,\n 'default': true,\n },\n right: {\n type: Boolean,\n 'default': false,\n },\n shadow: {\n type: Boolean,\n 'default': false,\n },\n target: {\n type: String,\n 'default': 'body',\n },\n offsetRef: {\n type: String,\n 'default': '',\n }\n },\n data() {\n return {\n wrapper: null,\n contentwrapper: null,\n resizeobserver: null,\n };\n },\n computed: {\n },\n methods: {\n\n },\n watch: {\n right(newVal) {\n rePosition(newVal);\n },\n offsetRef(reference) {\n setOffset(reference,this.$refs.portal);\n }\n },\n mounted() {\n debug.info(\"OffsetRef\",this.offsetRef);\n setOffset(this.offsetRef);\n debug.info(\"Right\",this.right);\n rePosition(this.right);\n },\n unmounted() {\n\n },\n template: `\n
\n
\n `,\n });\n },\n};"],"names":["wrapper","contentwrapper","resizeObserver","debug","rePosition","right","el","document","querySelector","createElement","setAttribute","ResizeObserver","wx","getBoundingClientRect","width","style","setProperty","observe","insertBefore","nextSibling","setOffset","reference","ref","offsetTop","height","marginTop","install","Vue","use","PortalVue","window","addEventListener","target","offsetref","initializeWrapperContent","appendChild","targetEl","console","info","nodeType","childNodes","length","createPortalTarget","component","template","props","value","type","Boolean","shadow","String","offsetRef","data","resizeobserver","computed","methods","watch","newVal","this","$refs","portal","mounted","unmounted"],"mappings":"oWAUIA,QACAC,eACAC,eALAC,MAAQ,2DAAa,sBA2DhBC,WAAWC,WAGZC,GAAKC,SAASC,cAAe,oBAC5BF,KACDA,GAAMC,SAASE,cAAc,OAC7BH,GAAGI,aAAa,KAAO,mBAGvBR,eAAiB,IAAIS,gBAAe,SAC5BC,GAAK,EAAIN,GAAGO,wBAAwBC,MACxCF,IAAa,GAANA,GAAW,KAAO,GACzBN,GAAGS,MAAMC,YAAY,yBAA0BJ,OAEnDV,eAAee,QAAQX,KAGvBD,MACAL,QAAQkB,aAAaZ,GAAIL,eAAekB,aAExCnB,QAAQkB,aAAaZ,GAAIL,yBAQxBmB,UAAUC,iBACTC,IAAMD,UAAYd,SAASC,cAAca,WAAa,QACxDC,IAAK,KACDC,UAAaD,IAAMA,IAAIC,UAAY,EACvCA,WAA2B,GAAbA,UAAkB,KAAO,SACjCjB,GAAKC,SAASC,cAAe,oBAC/BF,KACAA,GAAGS,MAAMS,OAAU,iBAAgBD,aACnCjB,GAAGS,MAAMU,UAAYF,yBAKlB,CACXG,QAAQC,KACJA,IAAIC,IAAIC,oBAIRC,OAAOC,iBAAiB,QAAQ,eA7FZC,OAAOC,eAC3BC,0BAA2B,KAG/BlC,QAAUO,SAASC,cAAc,sBAC5BR,UACDkC,0BAA2B,EAE3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