1 line
8.9 KiB
Plaintext
1 line
8.9 KiB
Plaintext
{"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 debug.info(\"Creating portal target\");\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 if (!targetEl || targetEl.nodeType == \"HTML\") {\n targetEl = document.querySelector(\"body\");\n }\n console.info(`Targeting '${target}' to `, targetEl);\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 if (document.readyState === 'ready' || document.readyState === 'complete') {\n debug.info(\"Page already loaded\");\n createPortalTarget();\n } else {\n window.addEventListener(\"load\", () => {\n debug.info(\"Page not yet loaded\");\n createPortalTarget();\n });\n }\n\n Vue.component('p-easeinout', {\n template: `\n <transition name=\"p-easeinout\"\n ><slot></slot>\n </transition>`\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 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 template: `\n <div\n ><mounting-portal ref='portal'\n mount-to=\"#p-sidebar-mount\"\n class=\"(right?'p-sidebar-right ':'')\"\n append\n transition=\"p-easeinout\"\n ><div ref='container' v-if=\"value\"\n :class=\"'p-sidebar ' + (right?'p-sidebar-right ':'') + (shadow?'p-sidebar-shadow ':'')\"\n ><slot></slot></div\n ></mounting-portal>\n </div>\n `,\n });\n },\n};"],"names":["wrapper","contentwrapper","resizeObserver","debug","createPortalTarget","target","offsetref","initializeWrapperContent","info","document","querySelector","createElement","setAttribute","appendChild","targetEl","nodeType","console","childNodes","length","rePosition","setOffset","right","el","ResizeObserver","wx","getBoundingClientRect","width","style","setProperty","observe","insertBefore","nextSibling","reference","ref","offsetTop","height","marginTop","install","Vue","use","PortalVue","readyState","window","addEventListener","component","template","props","value","type","Boolean","shadow","String","offsetRef","data","resizeobserver","computed","methods","watch","newVal","this","$refs","portal","mounted"],"mappings":"oWAUIA,QACAC,eACAC,eALAC,MAAQ,2DAAa,sBAahBC,mBAAmBC,OAAQC,eAC5BC,0BAA2B,KAC/BJ,MAAMK,KAAK,0BAGXR,QAAUS,SAASC,cAAc,sBAC5BV,UACDO,0BAA2B,EAE3BP,QAAUS,SAASE,cAAc,OACjCX,QAAQY,aAAa,KAAM,sBAG/BX,eAAiBQ,SAASC,cAAc,6BACnCT,iBACDM,0BAA2B,EAE3BN,eAAiBQ,SAASE,cAAc,OACxCV,eAAeW,aAAa,KAAM,4BAClCZ,QAAQa,YAAYZ,iBAGpBM,yBAA0B,KAEtBO,SAAWL,SAASC,cAAcL,YACjCS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