1/* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import {BaseElement} from '../BaseElement.js'; 16import './LitMainMenuItem.js'; 17import './LitMainMenuGroup.js'; 18import {LitMainMenuGroup} from './LitMainMenuGroup.js'; 19import {LitMainMenuItem} from './LitMainMenuItem.js'; 20 21const initHtmlStyle = ` 22 <style> 23 :host{ 24 width: 248px; 25 height: 100vh; 26 display: flex; 27 flex-direction: column; 28 background-color: #fff; 29 } 30 .menu-body ::-webkit-scrollbar-thumb 31 { 32 background-color: var(--dark-background,#FFFFFF); 33 border-radius:10px; 34 35 } 36 .menu-body ::-webkit-scrollbar-track 37 { 38 border-radius:10px; 39 background-color:#F5F5F5; 40 41 } 42 .header{ 43 display: flex; 44 width: 100%; 45 height: 56px; 46 font-size: 1.4rem; 47 padding-left: 20px; 48 gap: 0 20px; 49 box-sizing: border-box; 50 grid-template-columns: min-content 1fr min-content; 51 grid-template-rows: auto; 52 color: #47A7E0; 53 background-color: var(--dark-background1); 54 border-bottom: 1px solid var(--dark-background1,#EFEFEF); 55 } 56 .bottom{ 57 width: 100%; 58 display: flex; 59 justify-content: space-between; 60 } 61 .header *{ 62 user-select: none; 63 align-self: center; 64 } 65 *{ 66 box-sizing: border-box; 67 } 68 </style> 69 `; 70 71export class LitMainMenu extends BaseElement { 72 static get observedAttributes() { 73 return []; 74 } 75 76 get menus() { 77 return this._menus; 78 } 79 80 set menus(value) { 81 this._menus = value; 82 this.shadowRoot.querySelectorAll('lit-main-menu-group').forEach((a) => a.remove()); 83 let menuBody = this.shadowRoot.querySelector('.menu-body'); 84 if (this.getAttribute('main_menu') === '1' && window.localStorage.getItem('Theme') === 'dark') { 85 this.style.backgroundColor = '#262f3c'; 86 } else { 87 this.style.backgroundColor = '#fff'; 88 } 89 value === null || value === void 0 ? void 0 : value.forEach((item) => { 90 let group = new LitMainMenuGroup(); 91 group.setAttribute('title', item.title || ''); 92 if (item.describe !== '') { 93 group.setAttribute('describe', item.describe || ''); 94 } else { 95 group.removeAttribute('describe'); 96 } 97 group.setAttribute('icon', item.icon || ''); 98 if (item.collapsed) { 99 group.setAttribute('collapsed', ''); 100 } else { 101 group.removeAttribute('collapsed'); 102 } 103 let groupName = group.shadowRoot.querySelector('.group-name'); 104 let groupDescribe = group.shadowRoot.querySelector('.group-describe'); 105 menuBody === null || menuBody === void 0 ? void 0 : menuBody.appendChild(group); 106 let itemChildren; 107 (itemChildren = item.children) === null || itemChildren === void 0 ? void 0 : itemChildren.forEach((item) => { 108 if (item.fileModel !== undefined && item.fileModel === 'db') { 109 return; 110 } 111 this.notChildren(item, group, groupName, groupDescribe); 112 }); 113 }); 114 } 115 116 notChildren(item, group, groupName, groupDescribe) { 117 let th = new LitMainMenuItem(); 118 th.setAttribute('icon', item.icon || ''); 119 th.setAttribute('title', item.title || ''); 120 if (this.getAttribute('main_menu') === '1' && window.localStorage.getItem('Theme') === 'dark') { 121 groupName.style.color = 'white'; 122 groupDescribe.style.color = 'white'; 123 th.style.color = 'white'; 124 } else { 125 groupName.style.color = 'black'; 126 groupDescribe.style.color = 'black'; 127 th.style.color = 'black'; 128 } 129 if (item.fileChoose) { 130 th.setAttribute('file', ''); 131 th.addEventListener('file-change', (e) => { 132 if (item.fileHandler && !th.disabled) { 133 item.fileHandler(e); 134 } 135 }); 136 } else { 137 th.removeAttribute('file'); 138 th.addEventListener('click', (e) => { 139 if (item.clickHandler && !th.disabled) { 140 item.clickHandler(item); 141 } 142 }); 143 } 144 if (item.multi) { 145 th.multi = true; 146 } 147 if (item.disabled !== undefined) { 148 th.disabled = item.disabled; 149 } 150 group === null || group === void 0 ? void 0 : group.appendChild(th); 151 } 152 153 initElements() { 154 let slotItem; 155 let st = (slotItem = this.shadowRoot) === null || slotItem === void 0 ? void 0 : slotItem.querySelector('#st'); 156 st === null || st === void 0 ? void 0 : st.addEventListener('slotchange', (e) => { 157 let slotEle; 158 this.slotElements = st === null || st === void 0 ? void 0 : st.assignedElements(); 159 (slotEle = this.slotElements) === null || slotEle === void 0 ? void 0 : slotEle.forEach((it) => { 160 it.querySelectorAll('lit-main-menu-item').forEach((cell) => { 161 }); 162 }); 163 }); 164 } 165 166 initHtml() { 167 return ` 168 ${initHtmlStyle} 169 <div class="header" name="header"> 170 <span>Memory Dotting</span> 171 <div class="menu-button"> 172 <lit-icon name="menu" size="20" color="var(blue,#4D4D4D)"></lit-icon> 173 </div> 174 </div> 175 <div class="menu-body" style="overflow: auto;overflow-x:hidden;height: 100%"> 176 <slot id="st" ></slot> 177 </div> 178 `; 179 } 180} 181 182if (!customElements.get('lit-main-menu')) { 183 customElements.define('lit-main-menu', LitMainMenu); 184} 185