UNPKG

2.74 kBSource Map (JSON)View Raw
1{"version":3,"file":"vue-next-level-scroll.min.js","sources":["../src/index.js"],"sourcesContent":["export default {\n functional: true,\n render(h, { children, data, props: { target, scrollFunction, shouldNavigate = false, navigationType = 'push', tag = 'div' }, parent: { $router }, _ssrNode }) {\n const clickFunction = () => {\n const fn = scrollFunction || defaultScrollFunction\n fn(target, { shouldNavigate, navigationType, $router })\n }\n\n return h(tag, {\n ...data,\n on: {\n // Ignore scroll function on server side\n click: _ssrNode || process.server ? undefined : clickFunction\n }\n }, children)\n }\n}\n\nconst defaultScrollFunction = async (rawTarget, { shouldNavigate, navigationType, $router }) => {\n const target = (typeof rawTarget === 'function') ? await rawTarget() : rawTarget\n // If no target given, auto scroll to top\n if (!target) {\n window.scroll({\n top: 0,\n behavior: 'smooth'\n })\n if (shouldNavigate && $router) {\n const currentRoute = $router.currentRoute\n const hash = currentRoute.hash\n const fullPath = currentRoute.fullPath\n const newPath = fullPath.replace(hash, '')\n navigate($router, newPath, navigationType)\n }\n return\n }\n\n const node = document.querySelector(target)\n\n // If target prop is present but the node does not exist, send an error\n if (!node) {\n // eslint-disable-next-line no-console\n return console.error(`Could not scroll to ${target}`)\n }\n\n node.scrollIntoView({\n behavior: 'smooth'\n })\n\n if (shouldNavigate && $router) {\n navigate($router, target, navigationType)\n }\n}\n\nconst navigate = ($router, path, type) => { $router[type](path) }\n"],"names":["h","children","data","props","target","scrollFunction","shouldNavigate","navigationType","tag","$router","parent","_ssrNode","process","server","undefined","defaultScrollFunction","rawTarget","currentRoute","hash","fullPath","newPath","node","$await_4","document","querySelector","scrollIntoView","console","error","scroll","replace","navigate","path","type"],"mappings":"8MACc,kBACLA,SAAKC,IAAAA,SAAUC,IAAAA,SAAMC,MAASC,IAAAA,OAAQC,IAAAA,mBAAgBC,eAAAA,oBAAwBC,eAAAA,aAAiB,aAAQC,IAAAA,aAAM,QAAmBC,IAAVC,OAAUD,QAAWE,IAAAA,gBAMzIX,EAAEQ,mBACJN,aAGMS,GAAYC,QAAQC,YAASC,EATlB,YACTT,GAAkBU,GAC1BX,qDASFH,KAIDc,EAAwB,SAAOC,gDAC7BZ,EAQIa,EACAC,EACAC,EACAC,EAMJC,aAlB0Cf,eAAgBC,IAAAA,eAAgBE,IAAAA,wDAC3C,mBAAdO,kBAAkCA,iBAAcA,oCAAxDM,MAiBFC,SAASC,cAAcpB,OAQ/BqB,yBACO,WAGRnB,GAAkBG,KACXA,EAASL,EAAQG,UARnBmB,QAAQC,oCAA6BvB,aAnBrCwB,YACA,WACK,WAERtB,GAAkBG,MACCA,EAAQQ,eAChBA,EAAaC,OACTD,EAAaE,WACdA,EAASU,QAAQX,EAAM,MAC9BT,EAASW,EAASb,sCAsB3BuB,EAAW,SAACrB,EAASsB,EAAMC,KAAmBA,GAAMD"}
\No newline at end of file