import { LitElement, html, css } from 'lit-element'; import { cache } from 'lit-html/directives/cache'; import menu from '../config/menu.yml'; import router from '../services/router'; import watchMedia from '../hooks/watchMedia'; import { t } from '../directives/i18n'; function createNotificationsRoot() { const root = document.createElement('div'); Object.assign(root.style, { position: 'fixed', right: '10px', bottom: '10px', zIndex: 50, width: '320px' }); document.body.appendChild(root); return root; } export default class App extends LitElement { static cName = 'casl-docs'; static properties = { ready: { type: Boolean }, _isMobile: { type: Boolean }, _route: { type: Object }, }; constructor() { super(); this._route = null; this._notificationsRoot = null; this._menu = null; this._isMobile = false; this.ready = false; this._unwatch = []; } connectedCallback() { super.connectedCallback(); this._unwatch.push(router.observe((route) => { this._route = route.response; this._closeMenu(); }, { initial: true })); this._unwatch.push(watchMedia('(min-width: 768px)', v => this._isMobile = !v)); document.addEventListener('keypress', (event) => { // ctrl + shift + v if (event.ctrlKey && event.shiftKey && event.keyCode === 22) { console.log(process.env.COMMIT_HASH || 'unknown'); } }, false); } disconnectedCallback() { super.disconnectedCallback(); this._unwatch.forEach(unwatch => unwatch()); } updated() { this._menu = this._menu || this.shadowRoot.querySelector('menu-drawer'); } _toggleMenu() { if (this._menu) { this._menu.toggle(); } } _closeMenu() { if (this._menu) { this._menu.close(); } } notify(message, options = {}) { const notification = document.createElement('app-notification'); notification.message = message; if (typeof options.onClick === 'function') { notification.addEventListener('click', options.onClick, false); } this._notificationsRoot = this._notificationsRoot || createNotificationsRoot(); this._notificationsRoot.appendChild(notification); } _renderDrawerMenu(sidebar) { if (!this._isMobile) { return null; } return html` ${sidebar}