underpost 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/.dockerignore +13 -13
  2. package/.env.development +7 -7
  3. package/.env.production +7 -7
  4. package/.env.test +7 -7
  5. package/.github/workflows/publish.yml +26 -0
  6. package/.github/workflows/test.yml +80 -0
  7. package/.nycrc +9 -9
  8. package/.prettierignore +12 -12
  9. package/.prettierrc +9 -9
  10. package/.vscode/extensions.json +72 -72
  11. package/.vscode/settings.json +100 -99
  12. package/Dockerfile +89 -89
  13. package/LICENSE +21 -21
  14. package/README.md +96 -96
  15. package/bin/db.js +172 -119
  16. package/bin/deploy.js +607 -661
  17. package/bin/file.js +93 -92
  18. package/bin/index.js +76 -53
  19. package/bin/ssl.js +55 -64
  20. package/bin/util.js +182 -182
  21. package/bin/vs.js +35 -35
  22. package/conf.js +251 -249
  23. package/docker-compose.yml +67 -67
  24. package/jsconfig.json +7 -7
  25. package/jsdoc.json +32 -32
  26. package/nodemon.json +6 -6
  27. package/package.json +137 -132
  28. package/prometheus.yml +36 -36
  29. package/setup.sh +24 -24
  30. package/src/api/core/core.controller.js +69 -69
  31. package/src/api/core/core.model.js +11 -11
  32. package/src/api/core/core.router.js +23 -23
  33. package/src/api/core/core.service.js +29 -29
  34. package/src/api/crypto/crypto.controller.js +51 -51
  35. package/src/api/crypto/crypto.model.js +23 -23
  36. package/src/api/crypto/crypto.router.js +20 -20
  37. package/src/api/crypto/crypto.service.js +64 -64
  38. package/src/api/default/default.controller.js +69 -69
  39. package/src/api/default/default.model.js +20 -20
  40. package/src/api/default/default.router.js +23 -23
  41. package/src/api/default/default.service.js +31 -31
  42. package/src/api/file/file.controller.js +53 -51
  43. package/src/api/file/file.model.js +19 -19
  44. package/src/api/file/file.router.js +21 -20
  45. package/src/api/file/file.service.js +76 -70
  46. package/src/api/instance/instance.controller.js +69 -69
  47. package/src/api/instance/instance.model.js +36 -36
  48. package/src/api/instance/instance.router.js +33 -33
  49. package/src/api/instance/instance.service.js +48 -48
  50. package/src/api/test/test.controller.js +59 -59
  51. package/src/api/test/test.model.js +14 -14
  52. package/src/api/test/test.router.js +21 -21
  53. package/src/api/test/test.service.js +35 -35
  54. package/src/api/user/user.build.js +16 -0
  55. package/src/api/user/user.controller.js +70 -70
  56. package/src/api/user/user.model.js +65 -65
  57. package/src/api/user/user.router.js +345 -345
  58. package/src/api/user/user.service.js +479 -479
  59. package/src/api.js +23 -23
  60. package/src/client/Default.index.js +40 -40
  61. package/src/client/components/core/Account.js +290 -290
  62. package/src/client/components/core/AgGrid.js +160 -160
  63. package/src/client/components/core/Auth.js +19 -19
  64. package/src/client/components/core/Badge.js +32 -32
  65. package/src/client/components/core/{BlockChain.js → Blockchain.js} +41 -41
  66. package/src/client/components/core/Blog.js +9 -9
  67. package/src/client/components/core/BtnIcon.js +101 -94
  68. package/src/client/components/core/CalendarCore.js +458 -319
  69. package/src/client/components/core/Chat.js +64 -64
  70. package/src/client/components/core/ColorPalette.js +5267 -5267
  71. package/src/client/components/core/CommonJs.js +735 -732
  72. package/src/client/components/core/Content.js +193 -49
  73. package/src/client/components/core/Css.js +1064 -1027
  74. package/src/client/components/core/CssCore.js +817 -796
  75. package/src/client/components/core/D3Chart.js +44 -44
  76. package/src/client/components/core/Docs.js +229 -229
  77. package/src/client/components/core/DropDown.js +164 -164
  78. package/src/client/components/core/EventsUI.js +46 -54
  79. package/src/client/components/core/FileExplorer.js +699 -624
  80. package/src/client/components/core/FullScreen.js +45 -45
  81. package/src/client/components/core/Input.js +346 -259
  82. package/src/client/components/core/JoyStick.js +77 -77
  83. package/src/client/components/core/Keyboard.js +73 -73
  84. package/src/client/components/core/LoadingAnimation.js +179 -157
  85. package/src/client/components/core/LogIn.js +187 -181
  86. package/src/client/components/core/LogOut.js +58 -52
  87. package/src/client/components/core/Logger.js +26 -26
  88. package/src/client/components/core/Modal.js +1612 -1596
  89. package/src/client/components/core/NotificationManager.js +84 -84
  90. package/src/client/components/core/Panel.js +613 -413
  91. package/src/client/components/core/PanelForm.js +468 -0
  92. package/src/client/components/core/Polyhedron.js +162 -162
  93. package/src/client/components/core/Recover.js +204 -204
  94. package/src/client/components/core/Responsive.js +53 -53
  95. package/src/client/components/core/RichText.js +51 -27
  96. package/src/client/components/core/Router.js +76 -77
  97. package/src/client/components/core/Scroll.js +34 -0
  98. package/src/client/components/core/SignUp.js +125 -125
  99. package/src/client/components/core/SocketIo.js +72 -72
  100. package/src/client/components/core/Stream.js +113 -113
  101. package/src/client/components/core/ToggleSwitch.js +87 -87
  102. package/src/client/components/core/ToolTip.js +26 -26
  103. package/src/client/components/core/Translate.js +437 -408
  104. package/src/client/components/core/Validator.js +100 -100
  105. package/src/client/components/core/VanillaJs.js +460 -457
  106. package/src/client/components/core/Wallet.js +106 -106
  107. package/src/client/components/core/Webhook.js +25 -25
  108. package/src/client/components/core/Worker.js +272 -272
  109. package/src/client/components/default/CommonDefault.js +29 -29
  110. package/src/client/components/default/CssDefault.js +13 -13
  111. package/src/client/components/default/ElementsDefault.js +38 -38
  112. package/src/client/components/default/LogInDefault.js +41 -41
  113. package/src/client/components/default/LogOutDefault.js +28 -28
  114. package/src/client/components/default/MenuDefault.js +389 -389
  115. package/src/client/components/default/RoutesDefault.js +48 -48
  116. package/src/client/components/default/SettingsDefault.js +16 -16
  117. package/src/client/components/default/SignUpDefault.js +9 -9
  118. package/src/client/components/default/SocketIoDefault.js +54 -54
  119. package/src/client/components/default/TranslateDefault.js +7 -7
  120. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  121. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  122. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  123. package/src/client/public/default/browserconfig.xml +11 -11
  124. package/src/client/public/default/manifest.webmanifest +68 -68
  125. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  126. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  127. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  128. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  129. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  130. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  131. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  132. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  133. package/src/client/public/default/sitemap +147 -147
  134. package/src/client/public/default/yandex-browser-manifest.json +8 -8
  135. package/src/client/public/doc/sitemap +147 -147
  136. package/src/client/public/test/sitemap +147 -147
  137. package/src/client/services/core/core.service.js +170 -152
  138. package/src/client/services/crypto/crypto.service.js +70 -70
  139. package/src/client/services/default/default.management.js +345 -345
  140. package/src/client/services/default/default.service.js +89 -89
  141. package/src/client/services/file/file.service.js +70 -70
  142. package/src/client/services/instance/instance.management.js +74 -74
  143. package/src/client/services/instance/instance.service.js +89 -89
  144. package/src/client/services/test/test.service.js +70 -70
  145. package/src/client/services/user/user.management.js +50 -50
  146. package/src/client/services/user/user.service.js +89 -89
  147. package/src/client/ssr/Render.js +16 -16
  148. package/src/client/ssr/body-components/CacheControl.js +114 -113
  149. package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
  150. package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
  151. package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
  152. package/src/client/ssr/head-components/Css.js +241 -241
  153. package/src/client/ssr/head-components/DefaultScripts.js +3 -3
  154. package/src/client/ssr/head-components/Microdata.js +11 -11
  155. package/src/client/ssr/head-components/Production.js +1 -1
  156. package/src/client/ssr/head-components/PwaDefault.js +59 -59
  157. package/src/client/ssr/head-components/Seo.js +14 -14
  158. package/src/client/sw/default.sw.js +201 -201
  159. package/src/client/sw/template.sw.js +84 -84
  160. package/src/client.build.js +22 -22
  161. package/src/client.dev.js +21 -21
  162. package/src/cron.js +25 -25
  163. package/src/db/DataBaseProvider.js +34 -34
  164. package/src/db/mariadb/MariaDB.js +33 -33
  165. package/src/db/mongo/MongooseDB.js +137 -46
  166. package/src/dns.js +22 -22
  167. package/src/index.js +42 -29
  168. package/src/mailer/EmailRender.js +69 -69
  169. package/src/mailer/MailerProvider.js +96 -96
  170. package/src/proxy.js +22 -22
  171. package/src/runtime/lampp/Lampp.js +115 -44
  172. package/src/runtime/nginx/Nginx.js +3 -3
  173. package/src/runtime/xampp/Xampp.js +49 -49
  174. package/src/server/auth.js +235 -204
  175. package/src/server/backup.js +101 -94
  176. package/src/server/client-build-live.js +72 -72
  177. package/src/server/client-build.js +699 -699
  178. package/src/server/client-dev-server.js +60 -58
  179. package/src/server/client-formatted.js +48 -48
  180. package/src/server/client-icons.js +149 -150
  181. package/src/server/conf.js +860 -611
  182. package/src/server/dns.js +98 -98
  183. package/src/server/downloader.js +42 -42
  184. package/src/server/logger.js +190 -180
  185. package/src/server/network.js +122 -122
  186. package/src/server/peer.js +33 -33
  187. package/src/server/process.js +66 -66
  188. package/src/server/prompt-optimizer.js +28 -28
  189. package/src/server/proxy.js +118 -118
  190. package/src/server/runtime.js +444 -393
  191. package/src/server/ssl.js +120 -107
  192. package/src/server.js +25 -25
  193. package/src/ws/IoInterface.js +45 -45
  194. package/src/ws/IoServer.js +39 -39
  195. package/src/ws/core/channels/core.ws.chat.js +23 -23
  196. package/src/ws/core/channels/core.ws.mailer.js +35 -35
  197. package/src/ws/core/channels/core.ws.stream.js +31 -31
  198. package/src/ws/core/core.ws.connection.js +28 -28
  199. package/src/ws/core/core.ws.emit.js +14 -14
  200. package/src/ws/core/core.ws.server.js +24 -24
  201. package/src/ws/core/management/core.ws.chat.js +8 -8
  202. package/src/ws/core/management/core.ws.mailer.js +16 -16
  203. package/src/ws/core/management/core.ws.stream.js +8 -8
  204. package/src/ws/default/channels/default.ws.main.js +16 -16
  205. package/src/ws/default/default.ws.connection.js +22 -22
  206. package/src/ws/default/default.ws.emit.js +14 -14
  207. package/src/ws/default/default.ws.server.js +20 -20
  208. package/src/ws/default/management/default.ws.main.js +8 -8
  209. package/startup.js +11 -11
  210. package/supervisord-openssh-server.conf +4 -4
  211. package/test/api.test.js +60 -60
  212. package/bin/dns.js +0 -1
  213. package/bin/install.js +0 -357
  214. package/bin/shortcut.js +0 -44
@@ -1,1596 +1,1612 @@
1
- import { cap, getId, newInstance } from './CommonJs.js';
2
- import { Draggable } from '@neodrag/vanilla';
3
- import {
4
- append,
5
- s,
6
- prepend,
7
- setPath,
8
- getProxyPath,
9
- htmls,
10
- sa,
11
- getAllChildNodes,
12
- getCurrentTrace,
13
- isActiveElement,
14
- } from './VanillaJs.js';
15
- import { BtnIcon } from './BtnIcon.js';
16
- import { Responsive } from './Responsive.js';
17
- import { loggerFactory } from './Logger.js';
18
- import {
19
- Css,
20
- ThemeEvents,
21
- Themes,
22
- ThemesScope,
23
- darkTheme,
24
- renderStyleTag,
25
- renderStatus,
26
- renderCssAttr,
27
- } from './Css.js';
28
- import { setDocTitle } from './Router.js';
29
- import { NotificationManager } from './NotificationManager.js';
30
- import { EventsUI } from './EventsUI.js';
31
- import { Translate } from './Translate.js';
32
- import { Input } from './Input.js';
33
- import { Validator } from './Validator.js';
34
- import { DropDown } from './DropDown.js';
35
- import { Keyboard } from './Keyboard.js';
36
- import { Badge } from './Badge.js';
37
- import { Worker } from './Worker.js';
38
-
39
- const logger = loggerFactory(import.meta);
40
-
41
- const Modal = {
42
- Data: {},
43
- Render: async function (
44
- options = {
45
- id: '',
46
- barConfig: {},
47
- title: '',
48
- html: '',
49
- handleType: 'bar',
50
- mode: '' /* slide-menu */,
51
- RouterInstance: {},
52
- disableTools: [],
53
- },
54
- ) {
55
- if (options.heightBottomBar === undefined) options.heightBottomBar = 50;
56
- if (options.heightTopBar === undefined) options.heightTopBar = 50;
57
- let originHeightBottomBar = options.heightBottomBar ? newInstance(options.heightBottomBar) : 0;
58
- let originHeightTopBar = options.heightTopBar ? newInstance(options.heightTopBar) : 0;
59
- let width = 300;
60
- let height = 400;
61
- let top = 0;
62
- let left = 0;
63
- const topBottomBarEnable = options && options.barMode && options.barMode === 'top-bottom-bar';
64
- if (!topBottomBarEnable) {
65
- options.heightTopBar = options.heightTopBar + options.heightBottomBar;
66
- options.heightBottomBar = 0;
67
- }
68
- const setCenterRestore = () => {
69
- const ResponsiveData = Responsive.getResponsiveData();
70
- top = `${ResponsiveData.height / 2 - height / 2}px`;
71
- left = `${ResponsiveData.width / 2 - width / 2}px`;
72
- };
73
- setCenterRestore();
74
- let transition = `opacity 0.3s, box-shadow 0.3s, bottom 0.3s`;
75
- const originSlideMenuWidth = 320;
76
- const collapseSlideMenuWidth = 50;
77
- let slideMenuWidth = originSlideMenuWidth;
78
- const minWidth = width;
79
- const heightDefaultTopBar = 0;
80
- const heightDefaultBottomBar = 0;
81
- const idModal = options && 'id' in options ? options.id : getId(this.Data, 'modal-');
82
- this.Data[idModal] = {
83
- options,
84
- onCloseListener: {},
85
- onMenuListener: {},
86
- onDragEndListener: {},
87
- onObserverListener: {},
88
- onClickListener: {},
89
- };
90
- if (options && 'mode' in options) {
91
- this.Data[idModal][options.mode] = {};
92
- switch (options.mode) {
93
- case 'view':
94
- if (options && options.slideMenu) s(`.btn-close-${options.slideMenu}`).click();
95
- options.zIndexSync = true;
96
-
97
- options.style = {
98
- ...options.style,
99
- 'min-width': `${minWidth}px`,
100
- };
101
-
102
- if (this.mobileModal()) {
103
- options.barConfig.buttons.restore.disabled = true;
104
- options.barConfig.buttons.minimize.disabled = true;
105
- options.dragDisabled = true;
106
- options.style.resize = 'none';
107
- }
108
-
109
- Responsive.Event[`view-${idModal}`] = () => {
110
- if (!this.Data[idModal]) return delete Responsive.Event[`view-${idModal}`];
111
- if (this.Data[idModal].slideMenu)
112
- s(`.${idModal}`).style.height = `${
113
- window.innerHeight -
114
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
115
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
116
- }px`;
117
- };
118
- Responsive.Event[`view-${idModal}`]();
119
-
120
- // Router
121
- if (options.route)
122
- (() => {
123
- let path = window.location.pathname;
124
- if (path !== '/' && path[path.length - 1] === '/') path = path.slice(0, -1);
125
- const proxyPath = getProxyPath();
126
- const newPath = `${proxyPath}${options.route}`;
127
- if (path !== newPath) {
128
- // console.warn('SET MODAL URI', newPath);
129
- setPath(`${newPath}`); // ${location.search}
130
- setDocTitle({ ...options.RouterInstance, route: options.route });
131
- }
132
- })();
133
-
134
- break;
135
- case 'slide-menu':
136
- case 'slide-menu-right':
137
- case 'slide-menu-left':
138
- (async () => {
139
- const { barConfig } = options;
140
- options.style = {
141
- position: 'absolute',
142
- height: `${
143
- window.innerHeight -
144
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
145
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
146
- }px`,
147
- width: `${slideMenuWidth}px`,
148
- // 'overflow-x': 'hidden',
149
- // overflow: 'visible', // required for tooltip
150
- 'z-index': 6,
151
- resize: 'none',
152
- top: `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`,
153
- };
154
- options.mode === 'slide-menu-right' ? (options.style.right = '0px') : (options.style.left = '0px');
155
- const contentIconClass = 'abs center';
156
-
157
- options.dragDisabled = true;
158
- options.titleClass = 'hide';
159
- top = '0px';
160
- left = 'auto';
161
- width = 'auto';
162
- // barConfig.buttons.maximize.disabled = true;
163
- // barConfig.buttons.minimize.disabled = true;
164
- // barConfig.buttons.restore.disabled = true;
165
- // barConfig.buttons.menu.disabled = true;
166
- // barConfig.buttons.close.disabled = true;
167
- options.btnBarModalClass = 'hide';
168
- Responsive.Event[`slide-menu-${idModal}`] = () => {
169
- for (const _idModal of Object.keys(this.Data)) {
170
- if (this.Data[_idModal].slideMenu && this.Data[_idModal].slideMenu.id === idModal)
171
- this.Data[_idModal].slideMenu.callBack();
172
- }
173
- s(`.${idModal}`).style.height = `${
174
- window.innerHeight -
175
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
176
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
177
- }px`;
178
- if (s(`.main-body-top`)) {
179
- if (Modal.mobileModal()) {
180
- if (s(`.btn-menu-${idModal}`).classList.contains('hide') && collapseSlideMenuWidth !== slideMenuWidth)
181
- s(`.main-body-top`).classList.remove('hide');
182
- if (s(`.btn-close-${idModal}`).classList.contains('hide')) s(`.main-body-top`).classList.add('hide');
183
- } else if (!s(`.main-body-top`).classList.contains('hide')) s(`.main-body-top`).classList.add('hide');
184
- }
185
- };
186
- barConfig.buttons.menu.onClick = () => {
187
- this.Data[idModal][options.mode].width = slideMenuWidth;
188
- s(`.btn-menu-${idModal}`).classList.add('hide');
189
- s(`.btn-close-${idModal}`).classList.remove('hide');
190
- s(`.${idModal}`).style.width = `${this.Data[idModal][options.mode].width}px`;
191
- s(`.html-${idModal}`).style.display = 'block';
192
- // s(`.title-modal-${idModal}`).style.display = 'block';
193
- if (s(`.main-body-top`)) {
194
- s(`.btn-bar-center-icon-close`).classList.remove('hide');
195
- s(`.btn-bar-center-icon-menu`).classList.add('hide');
196
- }
197
-
198
- Responsive.Event[`slide-menu-${idModal}`]();
199
- };
200
- barConfig.buttons.close.onClick = () => {
201
- this.Data[idModal][options.mode].width = 0;
202
- s(`.btn-close-${idModal}`).classList.add('hide');
203
- s(`.btn-menu-${idModal}`).classList.remove('hide');
204
- s(`.${idModal}`).style.width = `${this.Data[idModal][options.mode].width}px`;
205
- s(`.html-${idModal}`).style.display = 'none';
206
- if (s(`.main-body-top`)) {
207
- s(`.btn-bar-center-icon-menu`).classList.remove('hide');
208
- s(`.btn-bar-center-icon-close`).classList.add('hide');
209
- }
210
- // s(`.title-modal-${idModal}`).style.display = 'none';
211
- Responsive.Event[`slide-menu-${idModal}`]();
212
- };
213
- transition += `, width 0.3s`;
214
-
215
- const inputSearchBoxId = `top-bar-search-box`;
216
- append(
217
- 'body',
218
- html` <div class="fix modal slide-menu-top-bar">
219
- <div
220
- class="fl top-bar ${options.barClass ? options.barClass : ''}"
221
- style="height: ${originHeightTopBar}px;"
222
- >
223
- ${await BtnIcon.Render({
224
- style: `height: 100%`,
225
- class: 'in fll main-btn-menu action-bar-box action-btn-close hide',
226
- label: html` <div class="${contentIconClass} action-btn-close-render">
227
- <i class="fa-solid fa-xmark"></i>
228
- </div>`,
229
- })}
230
- ${await BtnIcon.Render({
231
- style: `height: 100%`,
232
- class: `in fll main-btn-menu action-bar-box action-btn-app-icon ${
233
- options?.disableTools?.includes('app-icon') ? 'hide' : ''
234
- }`,
235
- label: html` <div class="${contentIconClass} action-btn-app-icon-render"></div>`,
236
- })}
237
- <form
238
- class="in fll top-bar-search-box-container hover ${options?.disableTools?.includes('text-box')
239
- ? 'hide'
240
- : ''}"
241
- >
242
- ${await Input.Render({
243
- id: inputSearchBoxId,
244
- placeholder: Modal.mobileModal() ? Translate.Render('search', '.top-bar-search-box') : undefined, // html`<i class="fa-solid fa-magnifying-glass"></i> ${Translate.Render('search')}`,
245
- placeholderIcon: html`<div
246
- class="in fll"
247
- style="width: ${originHeightTopBar}px; height: ${originHeightTopBar}px;"
248
- >
249
- <div class="abs center"><i class="fa-solid fa-magnifying-glass"></i></div>
250
- ${!Modal.mobileModal()
251
- ? html` <div
252
- class="inl wfm key-shortcut-container-info"
253
- style="${renderCssAttr({ style: { top: '10px', left: '60px' } })}"
254
- >
255
- ${await Badge.Render({
256
- id: 'shortcut-key-info-search',
257
- text: 'Shift',
258
- classList: 'inl',
259
- style: { 'z-index': 1 },
260
- })}
261
- ${await Badge.Render({
262
- id: 'shortcut-key-info-search',
263
- text: '+',
264
- classList: 'inl',
265
- style: { 'z-index': 1, background: 'none', color: '#5f5f5f' },
266
- })}
267
- ${await Badge.Render({
268
- id: 'shortcut-key-info-search',
269
- text: 'k',
270
- classList: 'inl',
271
- style: { 'z-index': 1 },
272
- })}
273
- </div>`
274
- : ''}
275
- </div>`,
276
- inputClass: 'in fll',
277
- // containerClass: '',
278
- })}
279
- </form>
280
- <div
281
- class="abs top-box-profile-container ${options?.disableTools?.includes('profile') ? 'hide' : ''}"
282
- >
283
- ${await BtnIcon.Render({
284
- style: `height: 100%`,
285
- class: 'in fll session-in-log-in main-btn-menu action-bar-box action-btn-profile-log-in',
286
- label: html` <div class="${contentIconClass} action-btn-profile-log-in-render"></div>`,
287
- })}
288
- ${await BtnIcon.Render({
289
- style: `height: 100%`,
290
- class: 'in fll session-in-log-out main-btn-menu action-bar-box action-btn-profile-log-out',
291
- label: html` <div class="${contentIconClass} action-btn-profile-log-out-render">
292
- <i class="fas fa-user-plus"></i>
293
- </div>`,
294
- })}
295
- </div>
296
- </div>
297
- </div>`,
298
- );
299
- EventsUI.onClick(`.action-btn-profile-log-in`, () => {
300
- s(`.main-btn-account`).click();
301
- });
302
- EventsUI.onClick(`.action-btn-profile-log-out`, () => {
303
- s(`.main-btn-sign-up`).click();
304
- });
305
- s(`.input-info-${inputSearchBoxId}`).style.textAlign = 'left';
306
- htmls(`.input-info-${inputSearchBoxId}`, '');
307
- const inputInfoNode = s(`.input-info-${inputSearchBoxId}`).cloneNode(true);
308
- s(`.input-info-${inputSearchBoxId}`).remove();
309
- {
310
- const id = 'search-box-history';
311
- const searchBoxHistoryId = id;
312
- const formDataInfoNode = [
313
- {
314
- model: 'search-box',
315
- id: inputSearchBoxId,
316
- rules: [] /*{ type: 'isEmpty' }, { type: 'isEmail' }*/,
317
- },
318
- ];
319
- let hoverHistBox = false;
320
- let hoverInputBox = false;
321
- let currentKeyBoardSearchBoxIndex = 0;
322
- let results = [];
323
- let historySearchBox = [];
324
-
325
- const checkHistoryBoxTitleStatus = () => {
326
- if (s(`.search-box-result-title`) && s(`.search-box-result-title`).classList) {
327
- if (!s(`.${inputSearchBoxId}`).value.trim()) {
328
- s(`.search-box-result-title`).classList.add('hide');
329
- s(`.search-box-recent-title`).classList.remove('hide');
330
- } else {
331
- s(`.search-box-recent-title`).classList.add('hide');
332
- s(`.search-box-result-title`).classList.remove('hide');
333
- }
334
- }
335
- };
336
-
337
- const checkShortcutContainerInfoEnabled = () => {
338
- if (Modal.mobileModal() || !s(`.key-shortcut-container-info`)) return;
339
- if (!s(`.${inputSearchBoxId}`).value) {
340
- s(`.key-shortcut-container-info`).classList.remove('hide');
341
- } else s(`.key-shortcut-container-info`).classList.add('hide');
342
- };
343
-
344
- const renderSearchResult = async (results) => {
345
- htmls(`.html-${searchBoxHistoryId}`, '');
346
- if (results.length === 0) {
347
- append(
348
- `.html-${searchBoxHistoryId}`,
349
- await BtnIcon.Render({
350
- label: html`<i class="fas fa-exclamation-circle"></i> ${Translate.Render('no-result-found')}`,
351
- class: `wfa`,
352
- style: renderCssAttr({
353
- style: {
354
- padding: '3px',
355
- margin: '2px',
356
- 'text-align': 'center',
357
- border: 'none',
358
- cursor: 'default',
359
- background: 'none !important',
360
- },
361
- }),
362
- }),
363
- );
364
- }
365
- let indexResult = -1;
366
- for (const result of results) {
367
- indexResult++;
368
- const indexRender = indexResult;
369
- append(
370
- `.html-${searchBoxHistoryId}`,
371
- await BtnIcon.Render({
372
- label: `${
373
- result.fontAwesomeIcon
374
- ? html`<i class="${result.fontAwesomeIcon.classList.toString()}"></i> `
375
- : result.imgElement
376
- ? html`<img
377
- class="inl"
378
- src="${result.imgElement.src}"
379
- style="${renderCssAttr({ style: { width: '25px', height: '25px' } })}"
380
- />`
381
- : ''
382
- } ${Translate.Render(result.routerId)}`,
383
- class: `wfa search-result-btn-${result.routerId} ${
384
- indexResult === currentKeyBoardSearchBoxIndex ? 'main-btn-menu-active' : ''
385
- } search-result-btn-${indexResult}`,
386
- style: renderCssAttr({
387
- style: { padding: '3px', margin: '2px', 'text-align': 'left' },
388
- }),
389
- }),
390
- );
391
- s(`.search-result-btn-${result.routerId}`).onclick = () => {
392
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
393
- `main-btn-menu-active`,
394
- );
395
- currentKeyBoardSearchBoxIndex = indexRender;
396
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
397
- `main-btn-menu-active`,
398
- );
399
- setSearchValue(`.search-result-btn-${result.routerId}`);
400
- };
401
- }
402
- };
403
-
404
- const getResultSearchBox = (validatorData) => {
405
- const { model, id } = validatorData;
406
- switch (model) {
407
- case 'search-box':
408
- {
409
- if (
410
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
411
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList
412
- )
413
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
414
- `main-btn-menu-active`,
415
- );
416
- currentKeyBoardSearchBoxIndex = 0;
417
- if (
418
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
419
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList
420
- )
421
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
422
- `main-btn-menu-active`,
423
- );
424
- results = [];
425
- const routerInstance = Worker.RouterInstance.Routes();
426
- for (const _routerId of Object.keys(routerInstance)) {
427
- const routerId = _routerId.slice(1);
428
- if (routerId) {
429
- if (
430
- s(`.main-btn-${routerId}`) &&
431
- (routerId.toLocaleLowerCase().match(s(`.${id}`).value.toLocaleLowerCase()) ||
432
- (Translate.Data[routerId] &&
433
- Object.keys(Translate.Data[routerId]).filter((keyLang) =>
434
- Translate.Data[routerId][keyLang]
435
- .toLocaleLowerCase()
436
- .match(s(`.${id}`).value.toLocaleLowerCase()),
437
- ).length > 0))
438
- ) {
439
- const fontAwesomeIcon = getAllChildNodes(s(`.main-btn-${routerId}`)).find((e) => {
440
- return (
441
- e.classList &&
442
- Array.from(e.classList).find((e) => e.match('fa-') && !e.match('fa-grip-vertical'))
443
- );
444
- });
445
- const imgElement = getAllChildNodes(s(`.main-btn-${routerId}`)).find((e) => {
446
- return (
447
- typeof e.src === 'string' &&
448
- e.src.match(routerId) &&
449
- e.classList &&
450
- Array.from(e.classList).find((e) => e.match('img-btn-square-menu'))
451
- );
452
- });
453
- if (imgElement || fontAwesomeIcon) {
454
- results.push({
455
- routerId,
456
- fontAwesomeIcon: fontAwesomeIcon,
457
- imgElement,
458
- });
459
- }
460
- }
461
- }
462
- }
463
- }
464
- break;
465
-
466
- default:
467
- break;
468
- }
469
- if (s(`.${inputSearchBoxId}`).value.trim()) renderSearchResult(results);
470
- else renderSearchResult(historySearchBox);
471
- };
472
-
473
- const searchBoxCallBack = async (validatorData) => {
474
- const isSearchBoxActiveElement = isActiveElement(inputSearchBoxId);
475
- checkHistoryBoxTitleStatus();
476
- checkShortcutContainerInfoEnabled();
477
- if (!isSearchBoxActiveElement && !hoverHistBox && !hoverInputBox) {
478
- Modal.removeModal(searchBoxHistoryId);
479
- return;
480
- }
481
- setTimeout(() => getResultSearchBox(validatorData));
482
- };
483
-
484
- const getDefaultSearchBoxSelector = () => `.search-result-btn-${currentKeyBoardSearchBoxIndex}`;
485
-
486
- const updateSearchBoxValue = (selector) => {
487
- if (!selector) selector = getDefaultSearchBoxSelector();
488
- if (s(selector).childNodes) {
489
- if (
490
- s(selector).childNodes[s(selector).childNodes.length - 1] &&
491
- s(selector).childNodes[s(selector).childNodes.length - 1].data &&
492
- s(selector).childNodes[s(selector).childNodes.length - 1].data.trim()
493
- ) {
494
- s(`.${inputSearchBoxId}`).value =
495
- s(selector).childNodes[s(selector).childNodes.length - 1].data.trim();
496
- } else if (
497
- s(selector).childNodes[s(selector).childNodes.length - 2] &&
498
- s(selector).childNodes[s(selector).childNodes.length - 2].outerText &&
499
- s(selector).childNodes[s(selector).childNodes.length - 2].outerText.trim()
500
- ) {
501
- s(`.${inputSearchBoxId}`).value =
502
- s(selector).childNodes[s(selector).childNodes.length - 2].outerText.trim();
503
- }
504
- }
505
- checkHistoryBoxTitleStatus();
506
- checkShortcutContainerInfoEnabled();
507
- };
508
-
509
- const setSearchValue = (selector) => {
510
- if (!selector) selector = getDefaultSearchBoxSelector();
511
- historySearchBox = historySearchBox.filter(
512
- (h) => h.routerId !== results[currentKeyBoardSearchBoxIndex].routerId,
513
- );
514
- historySearchBox.unshift(results[currentKeyBoardSearchBoxIndex]);
515
- updateSearchBoxValue(selector);
516
- s(`.main-btn-${results[currentKeyBoardSearchBoxIndex].routerId}`).click();
517
- Modal.removeModal(searchBoxHistoryId);
518
- };
519
-
520
- const searchBoxHistoryOpen = async () => {
521
- if (!s(`.${id}`)) {
522
- const { barConfig } = await Themes[Css.currentTheme]();
523
- barConfig.buttons.maximize.disabled = true;
524
- barConfig.buttons.minimize.disabled = true;
525
- barConfig.buttons.restore.disabled = true;
526
- barConfig.buttons.menu.disabled = true;
527
- barConfig.buttons.close.disabled = false;
528
- await Modal.Render({
529
- id,
530
- barConfig,
531
- title: html`<div class="search-box-recent-title">
532
- ${renderViewTitle({
533
- icon: html`<i class="fas fa-history mini-title"></i>`,
534
- text: Translate.Render('recent'),
535
- })}
536
- </div>
537
- <div class="search-box-result-title hide">
538
- ${renderViewTitle({
539
- icon: html`<i class="far fa-list-alt mini-title"></i>`,
540
- text: Translate.Render('results'),
541
- })}
542
- </div>`,
543
- html: () => html``,
544
- titleClass: 'mini-title',
545
- style: {
546
- resize: 'none',
547
- 'max-width': '450px',
548
- height:
549
- this.mobileModal() && window.innerWidth < 445
550
- ? `${window.innerHeight - originHeightTopBar}px !important`
551
- : '300px !important',
552
- 'z-index': 7,
553
- },
554
- dragDisabled: true,
555
- maximize: true,
556
- heightBottomBar: 0,
557
- heightTopBar: originHeightTopBar,
558
- barMode: options.barMode,
559
- });
560
-
561
- const titleNode = s(`.title-modal-${id}`).cloneNode(true);
562
- s(`.title-modal-${id}`).remove();
563
- s(`.btn-bar-modal-container-render-${id}`).classList.add('in');
564
- s(`.btn-bar-modal-container-render-${id}`).classList.add('fll');
565
- s(`.btn-bar-modal-container-render-${id}`).appendChild(titleNode);
566
-
567
- prepend(`.btn-bar-modal-container-${id}`, html`<div class="hide">${inputInfoNode.outerHTML}</div>`);
568
-
569
- s(`.top-bar-search-box-container`).onmouseover = () => {
570
- hoverInputBox = true;
571
- };
572
- s(`.top-bar-search-box-container`).onmouseout = () => {
573
- hoverInputBox = false;
574
- };
575
- s(`.${id}`).onmouseover = () => {
576
- hoverHistBox = true;
577
- };
578
- s(`.${id}`).onmouseout = () => {
579
- hoverHistBox = false;
580
- s(`.${inputSearchBoxId}`).focus();
581
- };
582
- }
583
- };
584
-
585
- s('.top-bar-search-box').oninput = () => {
586
- searchBoxHistoryOpen();
587
- searchBoxCallBack(formDataInfoNode[0]);
588
- };
589
- s('.top-bar-search-box').onfocus = () => {
590
- searchBoxHistoryOpen();
591
- searchBoxCallBack(formDataInfoNode[0]);
592
- };
593
- s('.top-bar-search-box').onblur = () => {
594
- if (!hoverHistBox && !hoverInputBox && !isActiveElement(inputSearchBoxId)) {
595
- Modal.removeModal(searchBoxHistoryId);
596
- }
597
- };
598
- EventsUI.onClick(`.top-bar-search-box-container`, () => {
599
- searchBoxHistoryOpen();
600
- searchBoxCallBack(formDataInfoNode[0]);
601
- });
602
-
603
- const timePressDelay = 100;
604
- Keyboard.instanceMultiPressKey({
605
- id: 'input-search-shortcut-ArrowUp',
606
- keys: ['ArrowUp'],
607
- eventCallBack: () => {
608
- if (s(`.${id}`)) {
609
- if (
610
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
611
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex - 1]
612
- ) {
613
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
614
- `main-btn-menu-active`,
615
- );
616
- currentKeyBoardSearchBoxIndex--;
617
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
618
- `main-btn-menu-active`,
619
- );
620
- } else {
621
- if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
622
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
623
- `main-btn-menu-active`,
624
- );
625
- currentKeyBoardSearchBoxIndex = s(`.html-${searchBoxHistoryId}`).childNodes.length - 1;
626
- if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
627
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
628
- `main-btn-menu-active`,
629
- );
630
- }
631
- updateSearchBoxValue();
632
- }
633
- },
634
- timePressDelay,
635
- });
636
-
637
- Keyboard.instanceMultiPressKey({
638
- id: 'input-search-shortcut-ArrowDown',
639
- keys: ['ArrowDown'],
640
- eventCallBack: () => {
641
- if (s(`.${id}`)) {
642
- if (
643
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
644
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex + 1]
645
- ) {
646
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
647
- `main-btn-menu-active`,
648
- );
649
- currentKeyBoardSearchBoxIndex++;
650
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
651
- `main-btn-menu-active`,
652
- );
653
- } else {
654
- if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
655
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
656
- `main-btn-menu-active`,
657
- );
658
- currentKeyBoardSearchBoxIndex = 0;
659
- if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
660
- s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
661
- `main-btn-menu-active`,
662
- );
663
- }
664
- updateSearchBoxValue();
665
- }
666
- },
667
- timePressDelay,
668
- });
669
-
670
- s(`.top-bar-search-box-container`).onsubmit = (e) => {
671
- e.preventDefault();
672
- setSearchValue();
673
- };
674
- }
675
- setTimeout(async () => {
676
- // clone and change position
677
-
678
- // s(`.btn-close-${idModal}`);
679
- // s(`.btn-menu-${idModal}`);
680
- if (originHeightBottomBar === 0) {
681
- const btnCloseNode = s(`.btn-close-${idModal}`).cloneNode(true);
682
- s(`.btn-close-${idModal}`).remove();
683
- s(`.top-bar`).appendChild(btnCloseNode);
684
- s(`.btn-close-${idModal}`).onclick = btnCloseEvent;
685
-
686
- const btnMenuNode = s(`.btn-menu-${idModal}`).cloneNode(true);
687
- s(`.btn-menu-${idModal}`).remove();
688
- s(`.top-bar`).appendChild(btnMenuNode);
689
- s(`.btn-menu-${idModal}`).onclick = btnMenuEvent;
690
- }
691
-
692
- // const titleNode = s(`.title-modal-${idModal}`).cloneNode(true);
693
- // s(`.title-modal-${idModal}`).remove();
694
- // s(`.top-bar`).appendChild(titleNode);
695
-
696
- s(`.slide-menu-top-bar`).style.zIndex = 7;
697
-
698
- // s('body').removeChild(`.${idModal}`);
699
- // while (s(`.top-modal`).firstChild) s(`.top-modal`).removeChild(s(`.top-modal`).firstChild);
700
-
701
- {
702
- const { barConfig } = await Themes[Css.currentTheme]();
703
- barConfig.buttons.maximize.disabled = true;
704
- barConfig.buttons.minimize.disabled = true;
705
- barConfig.buttons.restore.disabled = true;
706
- barConfig.buttons.menu.disabled = true;
707
- barConfig.buttons.close.disabled = true;
708
- const id = 'main-body';
709
- await Modal.Render({
710
- id,
711
- barConfig,
712
- html: options.htmlMainBody ? options.htmlMainBody : () => html``,
713
- titleClass: 'hide',
714
- style: {
715
- // overflow: 'hidden',
716
- background: 'none',
717
- resize: 'none',
718
- 'min-width': `${minWidth}px`,
719
- width: '100%',
720
- // border: '3px solid red',
721
- },
722
- dragDisabled: true,
723
- maximize: true,
724
- slideMenu: 'modal-menu',
725
- heightTopBar: originHeightTopBar,
726
- heightBottomBar: originHeightBottomBar,
727
- barMode: options.barMode,
728
- });
729
- const maxWidthInputSearchBox = 450;
730
- const paddingInputSearchBox = 5;
731
- const paddingRightSearchBox = 50;
732
- Responsive.Event[`view-${id}`] = () => {
733
- if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
734
- const widthInputSearchBox =
735
- window.innerWidth > maxWidthInputSearchBox ? maxWidthInputSearchBox : window.innerWidth;
736
- s(`.top-bar-search-box-container`).style.width = `${
737
- widthInputSearchBox - originHeightTopBar - paddingRightSearchBox - 1
738
- }px`;
739
- s(`.top-bar-search-box`).style.width = `${
740
- widthInputSearchBox -
741
- originHeightTopBar * 2 -
742
- paddingRightSearchBox -
743
- paddingInputSearchBox * 2 /*padding input*/ -
744
- 10 /* right-margin */
745
- }px`;
746
- s(`.top-bar-search-box`).style.top = `${
747
- (originHeightTopBar - s(`.top-bar-search-box`).clientHeight) / 2
748
- }px`;
749
- if (this.Data[id].slideMenu)
750
- s(`.${id}`).style.height = `${
751
- window.innerHeight -
752
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
753
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
754
- }px`;
755
- };
756
- Responsive.Event[`view-${id}`]();
757
- Keyboard.instanceMultiPressKey({
758
- id: 'input-search-shortcut-k',
759
- keys: [
760
- ['Shift', 'k'],
761
- ['Alt', 'k'],
762
- ],
763
- eventCallBack: () => {
764
- if (s(`.top-bar-search-box`)) {
765
- s(`.top-bar-search-box`).blur();
766
- s(`.top-bar-search-box`).focus();
767
- s(`.top-bar-search-box`).select();
768
- }
769
- },
770
- });
771
- }
772
-
773
- {
774
- const { barConfig } = await Themes[Css.currentTheme]();
775
- barConfig.buttons.maximize.disabled = true;
776
- barConfig.buttons.minimize.disabled = true;
777
- barConfig.buttons.restore.disabled = true;
778
- barConfig.buttons.menu.disabled = true;
779
- barConfig.buttons.close.disabled = true;
780
- const id = 'bottom-bar';
781
- if (options && options.homeModals && !options.homeModals.includes(id)) options.homeModals.push(id);
782
- else options.homeModals = [id];
783
- const html = async () => html`
784
- <style>
785
- .top-bar-search-box-container {
786
- height: 100%;
787
- overflow: hidden;
788
- }
789
- .bottom-bar {
790
- overflow: hidden;
791
- }
792
- .action-bar-box {
793
- margin: 0px;
794
- border: none;
795
- width: 50px;
796
- min-height: 50px;
797
- }
798
- </style>
799
- <div
800
- class="fl ${options.barClass ? options.barClass : ''}"
801
- style="height: ${originHeightBottomBar}px;"
802
- >
803
- ${await BtnIcon.Render({
804
- style: `height: 100%`,
805
- class: `in fl${
806
- options.mode === 'slide-menu-right' ? 'r' : 'l'
807
- } main-btn-menu action-bar-box action-btn-center ${
808
- options?.disableTools?.includes('center') ? 'hide' : ''
809
- }`,
810
- label: html`
811
- <div class="${contentIconClass}">
812
- <i class="far fa-square btn-bar-center-icon-square hide"></i>
813
- <span class="btn-bar-center-icon-close hide">${barConfig.buttons.close.label}</span>
814
- <span class="btn-bar-center-icon-menu">${barConfig.buttons.menu.label}</span>
815
- </div>
816
- `,
817
- })}
818
- ${await BtnIcon.Render({
819
- style: `height: 100%`,
820
- class: `in flr main-btn-menu action-bar-box action-btn-lang ${
821
- options?.disableTools?.includes('lang') ? 'hide' : ''
822
- }`,
823
- label: html` <div class="${contentIconClass} action-btn-lang-render"></div>`,
824
- })}
825
- ${await BtnIcon.Render({
826
- style: `height: 100%`,
827
- class: `in flr main-btn-menu action-bar-box action-btn-theme ${
828
- options?.disableTools?.includes('theme') ? 'hide' : ''
829
- }`,
830
- label: html` <div class="${contentIconClass} action-btn-theme-render"></div>`,
831
- })}
832
- ${await BtnIcon.Render({
833
- style: `height: 100%`,
834
- class: `in flr main-btn-menu action-bar-box action-btn-home ${
835
- options?.disableTools?.includes('navigator') ? 'hide' : ''
836
- }`,
837
- label: html` <div class="${contentIconClass}"><i class="fas fa-home"></i></div>`,
838
- })}
839
- ${await BtnIcon.Render({
840
- style: `height: 100%`,
841
- class: `in flr main-btn-menu action-bar-box action-btn-right ${
842
- options?.disableTools?.includes('navigator') ? 'hide' : ''
843
- }`,
844
- label: html` <div class="${contentIconClass}"><i class="fas fa-chevron-right"></i></div>`,
845
- })}
846
- ${await BtnIcon.Render({
847
- style: `height: 100%`,
848
- class: `in flr main-btn-menu action-bar-box action-btn-left ${
849
- options?.disableTools?.includes('navigator') ? 'hide' : ''
850
- }`,
851
- label: html`<div class="${contentIconClass}"><i class="fas fa-chevron-left"></i></div>`,
852
- })}
853
- </div>
854
- `;
855
- if (options.heightBottomBar === 0 && options.heightTopBar > 0) {
856
- append(`.slide-menu-top-bar`, html` <div class="in ${id}">${await html()}</div>`);
857
- } else {
858
- await Modal.Render({
859
- id,
860
- barConfig,
861
- html,
862
- titleClass: 'hide',
863
- style: {
864
- resize: 'none',
865
- height: `${options.heightBottomBar}px`,
866
- 'min-width': `${minWidth}px`,
867
- 'z-index': 7,
868
- },
869
- dragDisabled: true,
870
- maximize: true,
871
- barMode: options.barMode,
872
- });
873
- Responsive.Event[`view-${id}`] = () => {
874
- if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
875
- // <div class="in fll right-offset-menu-bottom-bar" style="height: 100%"></div>
876
- // s(`.right-offset-menu-bottom-bar`).style.width = `${window.innerWidth - slideMenuWidth}px`;
877
- s(`.${id}`).style.top = `${
878
- window.innerHeight - (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
879
- }px`;
880
- };
881
- Responsive.Event[`view-${id}`]();
882
- }
883
- EventsUI.onClick(`.action-btn-left`, (e) => {
884
- e.preventDefault();
885
- window.history.back();
886
- });
887
- EventsUI.onClick(`.action-btn-center`, (e) => {
888
- e.preventDefault();
889
- this.actionBtnCenter();
890
- });
891
- EventsUI.onClick(`.action-btn-right`, (e) => {
892
- e.preventDefault();
893
- window.history.forward();
894
- });
895
- EventsUI.onClick(`.action-btn-home`, () => s(`.main-btn-home`).click());
896
- EventsUI.onClick(`.action-btn-app-icon`, () => s(`.action-btn-home`).click());
897
- Keyboard.instanceMultiPressKey({
898
- id: 'input-shortcut-global-escape',
899
- keys: ['Escape'],
900
- eventCallBack: () => {
901
- // if (s(`.main-btn-home`)) s(`.main-btn-home`).click();
902
-
903
- if (s(`.btn-close-${this.currentTopModalId}`)) s(`.btn-close-${this.currentTopModalId}`).click();
904
- },
905
- });
906
- }
907
-
908
- {
909
- ThemeEvents['action-btn-theme'] = () => {
910
- htmls(
911
- `.action-btn-theme-render`,
912
- html` ${darkTheme ? html` <i class="fas fa-moon"></i>` : html`<i class="far fa-sun"></i>`}`,
913
- );
914
- };
915
- ThemeEvents['action-btn-theme']();
916
-
917
- EventsUI.onClick(`.action-btn-theme`, async () => {
918
- const themePair = ThemesScope.find((t) => t.theme === Css.currentTheme).themePair;
919
- const theme = themePair ? themePair : ThemesScope.find((t) => t.dark === !darkTheme).theme;
920
- if (s(`.dropdown-option-${theme}`))
921
- DropDown.Tokens['settings-theme'].onClickEvents[`dropdown-option-${theme}`]();
922
- else await Themes[theme]();
923
- });
924
- if (!(ThemesScope.find((t) => t.dark) && ThemesScope.find((t) => !t.dark))) {
925
- s(`.action-btn-theme`).classList.add('hide');
926
- }
927
- }
928
-
929
- {
930
- htmls(`.action-btn-lang-render`, html` ${s('html').lang}`);
931
- EventsUI.onClick(`.action-btn-lang`, () => {
932
- let lang = 'en';
933
- if (s('html').lang === 'en') lang = 'es';
934
- if (s(`.dropdown-option-${lang}`))
935
- DropDown.Tokens['settings-lang'].onClickEvents[`dropdown-option-${lang}`]();
936
- else Translate.renderLang(lang);
937
- });
938
- }
939
-
940
- {
941
- const { barConfig } = await Themes[Css.currentTheme]();
942
- barConfig.buttons.maximize.disabled = true;
943
- barConfig.buttons.minimize.disabled = true;
944
- barConfig.buttons.restore.disabled = true;
945
- barConfig.buttons.menu.disabled = true;
946
- barConfig.buttons.close.disabled = true;
947
- const id = 'main-body-top';
948
- await Modal.Render({
949
- id,
950
- barConfig,
951
- html: () => html``,
952
- titleClass: 'hide',
953
- class: 'hide',
954
- style: {
955
- // overflow: 'hidden',
956
- background: 'none',
957
- resize: 'none',
958
- 'min-width': `${minWidth}px`,
959
- 'z-index': 5,
960
- background: `rgba(61, 61, 61, 0.5)`,
961
- // border: '3px solid red',
962
- },
963
- dragDisabled: true,
964
- maximize: true,
965
- heightTopBar: originHeightTopBar,
966
- heightBottomBar: originHeightBottomBar,
967
- barMode: options.barMode,
968
- });
969
-
970
- Responsive.Event[`view-${id}`] = () => {
971
- if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
972
- s(`.${id}`).style.height = `${
973
- window.innerHeight -
974
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
975
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
976
- }px`;
977
- };
978
- Responsive.Event[`view-${id}`]();
979
-
980
- s(`.main-body-top`).onclick = () => s(`.btn-close-modal-menu`).click();
981
- }
982
-
983
- await NotificationManager.RenderBoard(options);
984
- });
985
- })();
986
- break;
987
-
988
- case 'dropNotification':
989
- (() => {
990
- setTimeout(() => {
991
- s(`.${idModal}`).style.top = 'auto';
992
- s(`.${idModal}`).style.left = 'auto';
993
- s(`.${idModal}`).style.height = 'auto';
994
- s(`.${idModal}`).style.position = 'absolute';
995
- let countDrop = 0;
996
- Object.keys(this.Data)
997
- .reverse()
998
- .map((_idModal) => {
999
- if (this.Data[_idModal][options.mode]) {
1000
- s(`.${_idModal}`).style.bottom = `${countDrop * s(`.${_idModal}`).clientHeight * 1.05}px`;
1001
- countDrop++;
1002
- }
1003
- });
1004
- });
1005
- })();
1006
- break;
1007
-
1008
- default:
1009
- break;
1010
- }
1011
- }
1012
- if (options.zIndexSync) this.zIndexSync({ idModal });
1013
- if (s(`.${idModal}`)) {
1014
- s(`.btn-maximize-${idModal}`).click();
1015
- return;
1016
- }
1017
- if (options.slideMenu) {
1018
- if (options.titleClass) options.titleClass = ' title-view-modal ' + options.titleClass;
1019
- options.titleClass = ' title-view-modal ';
1020
- }
1021
-
1022
- const render = html` <style class="style-${idModal}">
1023
- .${idModal} {
1024
- width: ${width}px;
1025
- height: ${height}px;
1026
- top: ${top};
1027
- left: ${left};
1028
- overflow: auto; /* resizable required */
1029
- resize: auto; /* resizable required */
1030
- transition: ${transition};
1031
- opacity: 0;
1032
- z-index: 1;
1033
- }
1034
- .bar-default-modal-${idModal} {
1035
- top: 0px;
1036
- left: 0px;
1037
- z-index: 3;
1038
- }
1039
-
1040
- .modal-html-${idModal} {
1041
- }
1042
-
1043
- .btn-modal-default-${idModal} {
1044
- }
1045
- .modal-handle-${idModal} {
1046
- width: 90%;
1047
- height: 90%;
1048
- top: 5%;
1049
- left: 5%;
1050
- }
1051
- </style>
1052
- ${renderStyleTag(`style-${idModal}`, `.${idModal}`, options)}
1053
- <div class="fix ${options && options.class ? options.class : ''} modal box-shadow ${idModal}">
1054
- <div class="abs modal-handle-${idModal}"></div>
1055
- <div class="in modal-html-${idModal}">
1056
- <div class="stq bar-default-modal bar-default-modal-${idModal}">
1057
- <div
1058
- class="fl btn-bar-modal-container btn-bar-modal-container-${idModal} ${options?.btnBarModalClass
1059
- ? options.btnBarModalClass
1060
- : ''}"
1061
- >
1062
- <div class="btn-bar-modal-container-render-${idModal}"></div>
1063
- <div class="in flr bar-default-modal" style="z-index: 1">
1064
- ${await BtnIcon.Render({
1065
- class: `btn-minimize-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1066
- options?.btnContainerClass ? options.btnContainerClass : ''
1067
- } ${options?.barConfig?.buttons?.minimize?.disabled ? 'hide' : ''}`,
1068
- label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1069
- ${options?.barConfig?.buttons?.minimize?.label ? options.barConfig.buttons.minimize.label : html`_`}
1070
- </div>`,
1071
- })}
1072
- ${await BtnIcon.Render({
1073
- class: `btn-restore-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1074
- options?.btnContainerClass ? options.btnContainerClass : ''
1075
- } ${options?.barConfig?.buttons?.restore?.disabled ? 'hide' : ''}`,
1076
- label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1077
- ${options?.barConfig?.buttons?.restore?.label ? options.barConfig.buttons.restore.label : html`□`}
1078
- </div>`,
1079
- style: 'display: none',
1080
- })}
1081
- ${await BtnIcon.Render({
1082
- class: `btn-maximize-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1083
- options?.btnContainerClass ? options.btnContainerClass : ''
1084
- } ${options?.barConfig?.buttons?.maximize?.disabled ? 'hide' : ''}`,
1085
- label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1086
- ${options?.barConfig?.buttons?.maximize?.label ? options.barConfig.buttons.maximize.label : html`▢`}
1087
- </div>`,
1088
- })}
1089
- ${await BtnIcon.Render({
1090
- class: `btn-close-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1091
- options?.btnContainerClass ? options.btnContainerClass : ''
1092
- } ${options?.barConfig?.buttons?.close?.disabled ? 'hide' : ''}`,
1093
- label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1094
- ${options?.barConfig?.buttons?.close?.label ? options.barConfig.buttons.close.label : html`X`}
1095
- </div>`,
1096
- })}
1097
- ${await BtnIcon.Render({
1098
- class: `btn-menu-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1099
- options?.btnContainerClass ? options.btnContainerClass : ''
1100
- } ${options?.barConfig?.buttons?.menu?.disabled ? 'hide' : ''}`,
1101
- label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1102
- ${options?.barConfig?.buttons?.menu?.label ? options.barConfig.buttons.menu.label : html`≡`}
1103
- </div>`,
1104
- })}
1105
- </div>
1106
- </div>
1107
- ${options && options.status
1108
- ? html` <div class="abs modal-icon-container">${renderStatus(options.status)}</div> `
1109
- : ''}
1110
- <div
1111
- class="inl title-modal-${idModal} ${options && options.titleClass ? options.titleClass : 'title-modal'}"
1112
- >
1113
- ${options && options.titleRender ? options.titleRender() : options.title ? options.title : ''}
1114
- </div>
1115
- </div>
1116
-
1117
- <div class="in html-${idModal}">
1118
- ${options.mode && options.mode.match('slide-menu')
1119
- ? html`<div class="in" style="${renderCssAttr({ style: { height: '50px' } })}">
1120
- ${await BtnIcon.Render({
1121
- style: renderCssAttr({ style: { height: '100%', color: '#5f5f5f' } }),
1122
- class: `in flr main-btn-menu action-bar-box btn-icon-menu-mode`,
1123
- label: html` <div class="abs center">
1124
- <i
1125
- class="fas fa-caret-right btn-icon-menu-mode-right ${options.mode && options.mode.match('right')
1126
- ? ''
1127
- : 'hide'}"
1128
- ></i
1129
- ><i
1130
- class="fas fa-caret-left btn-icon-menu-mode-left ${options.mode && options.mode.match('right')
1131
- ? 'hide'
1132
- : ''}"
1133
- ></i>
1134
- </div>`,
1135
- })}
1136
- </div>`
1137
- : ''}
1138
- ${options && options.html ? (typeof options.html === 'function' ? await options.html() : options.html) : ''}
1139
- </div>
1140
- </div>
1141
- </div>`;
1142
- const selector = options && options.selector ? options.selector : 'body';
1143
- if (options) {
1144
- switch (options.renderType) {
1145
- case 'prepend':
1146
- prepend(selector, render);
1147
- break;
1148
- default:
1149
- append(selector, render);
1150
- break;
1151
- }
1152
- } else append(selector, render);
1153
- let handle = [s(`.bar-default-modal-${idModal}`), s(`.modal-handle-${idModal}`), s(`.modal-html-${idModal}`)];
1154
- if (options && 'handleType' in options) {
1155
- switch (options.handleType) {
1156
- case 'bar':
1157
- handle = [s(`.bar-default-modal-${idModal}`)];
1158
-
1159
- break;
1160
-
1161
- default:
1162
- break;
1163
- }
1164
- }
1165
- switch (options.mode) {
1166
- case 'slide-menu':
1167
- case 'slide-menu-right':
1168
- case 'slide-menu-left':
1169
- s(`.main-btn-home`).onclick = () => {
1170
- for (const keyModal of Object.keys(this.Data)) {
1171
- if (
1172
- ![idModal, 'main-body-top', 'main-body']
1173
- .concat(options?.homeModals ? options.homeModals : [])
1174
- .includes(keyModal)
1175
- )
1176
- s(`.btn-close-${keyModal}`).click();
1177
- }
1178
- s(`.btn-close-modal-menu`).click();
1179
- };
1180
- EventsUI.onClick(`.btn-icon-menu-mode`, () => {
1181
- if (s(`.btn-icon-menu-mode-right`).classList.contains('hide')) {
1182
- s(`.btn-icon-menu-mode-right`).classList.remove('hide');
1183
- s(`.btn-icon-menu-mode-left`).classList.add('hide');
1184
- } else {
1185
- s(`.btn-icon-menu-mode-left`).classList.remove('hide');
1186
- s(`.btn-icon-menu-mode-right`).classList.add('hide');
1187
- }
1188
- if (slideMenuWidth === originSlideMenuWidth) {
1189
- slideMenuWidth = collapseSlideMenuWidth;
1190
- if (!s(`.btn-bar-center-icon-close`).classList.contains('hide')) {
1191
- sa(`.handle-btn-container`).forEach((el) => el.classList.add('hide'));
1192
- sa(`.menu-label-text`).forEach((el) => el.classList.add('hide'));
1193
- if (!Modal.mobileModal()) {
1194
- sa(`.tooltip-menu`).forEach((el) => el.classList.remove('hide'));
1195
- s(`.${idModal}`).style.overflow = 'visible';
1196
- }
1197
- }
1198
- if (options.onCollapseMenu) options.onCollapseMenu();
1199
- } else {
1200
- slideMenuWidth = originSlideMenuWidth;
1201
- sa(`.handle-btn-container`).forEach((el) => el.classList.remove('hide'));
1202
- sa(`.menu-label-text`).forEach((el) => el.classList.remove('hide'));
1203
- if (!Modal.mobileModal()) {
1204
- sa(`.tooltip-menu`).forEach((el) => el.classList.add('hide'));
1205
- s(`.${idModal}`).style.overflow = null;
1206
- }
1207
-
1208
- if (options.onExtendMenu) options.onExtendMenu();
1209
- }
1210
- // btn-bar-center-icon-menu
1211
- this.actionBtnCenter();
1212
- this.actionBtnCenter();
1213
- });
1214
-
1215
- break;
1216
-
1217
- default:
1218
- break;
1219
- }
1220
- let dragOptions = {
1221
- // disabled: true,
1222
- handle,
1223
- onDragStart: (data) => {
1224
- if (!s(`.${idModal}`)) return;
1225
- // logger.info('Dragging started', data);
1226
- s(`.${idModal}`).style.transition = null;
1227
- },
1228
- onDrag: (data) => {
1229
- if (!s(`.${idModal}`)) return;
1230
- // logger.info('Dragging', data);
1231
- },
1232
- onDragEnd: (data) => {
1233
- if (!s(`.${idModal}`)) return;
1234
- // logger.info('Dragging stopped', data);
1235
- s(`.${idModal}`).style.transition = transition;
1236
- Object.keys(this.Data[idModal].onDragEndListener).map((keyListener) =>
1237
- this.Data[idModal].onDragEndListener[keyListener](),
1238
- );
1239
- },
1240
- };
1241
- let dragInstance;
1242
- // new Draggable(s(`.${idModal}`), { disabled: true });
1243
- const setDragInstance = () => (options?.dragDisabled ? null : new Draggable(s(`.${idModal}`), dragOptions));
1244
- this.Data[idModal].setDragInstance = (updateDragOptions) => {
1245
- dragOptions = {
1246
- ...dragOptions,
1247
- ...updateDragOptions,
1248
- };
1249
- dragInstance = setDragInstance();
1250
- this.Data[idModal].dragInstance = dragInstance;
1251
- this.Data[idModal].dragOptions = dragOptions;
1252
- };
1253
- s(`.${idModal}`).style.transition = '0.15s';
1254
- setTimeout(() => (s(`.${idModal}`).style.opacity = '1'));
1255
- setTimeout(() => (s(`.${idModal}`).style.transition = transition), 150);
1256
-
1257
- const btnCloseEvent = () => {
1258
- Object.keys(this.Data[idModal].onCloseListener).map((keyListener) =>
1259
- this.Data[idModal].onCloseListener[keyListener](),
1260
- );
1261
- if (options && 'barConfig' in options && options.barConfig.buttons.close.onClick)
1262
- return options.barConfig.buttons.close.onClick();
1263
- s(`.${idModal}`).style.opacity = '0';
1264
- if (this.Data[idModal].observer) {
1265
- this.Data[idModal].observer.disconnect();
1266
- // this.Data[idModal].observer.unobserve();
1267
- }
1268
- setTimeout(() => {
1269
- if (!s(`.${idModal}`)) return;
1270
- this.removeModal(idModal);
1271
- // Router
1272
- if (options.route)
1273
- (() => {
1274
- let path = window.location.pathname;
1275
- if (path[path.length - 1] !== '/') path = `${path}/`;
1276
- let newPath = `${getProxyPath()}`;
1277
- if (path !== newPath) {
1278
- for (const subIdModal of Object.keys(this.Data).reverse()) {
1279
- if (this.Data[subIdModal].options.route) {
1280
- newPath = `${newPath}${this.Data[subIdModal].options.route}`;
1281
- // console.warn('SET MODAL URI', newPath);
1282
- setPath(newPath);
1283
- this.setTopModalCallback(subIdModal);
1284
- return setDocTitle({ ...options.RouterInstance, route: this.Data[subIdModal].options.route });
1285
- }
1286
- }
1287
- // console.warn('SET MODAL URI', newPath);
1288
- setPath(newPath);
1289
- return setDocTitle({ ...options.RouterInstance, route: '' });
1290
- }
1291
- })();
1292
- }, 300);
1293
- };
1294
- s(`.btn-close-${idModal}`).onclick = btnCloseEvent;
1295
-
1296
- s(`.btn-minimize-${idModal}`).onclick = () => {
1297
- if (options.slideMenu) delete this.Data[idModal].slideMenu;
1298
- s(`.${idModal}`).style.transition = '0.3s';
1299
- s(`.btn-minimize-${idModal}`).style.display = 'none';
1300
- s(`.btn-maximize-${idModal}`).style.display = null;
1301
- s(`.btn-restore-${idModal}`).style.display = null;
1302
- s(`.${idModal}`).style.height = `${s(`.bar-default-modal-${idModal}`).clientHeight}px`;
1303
- setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1304
- };
1305
- s(`.btn-restore-${idModal}`).onclick = () => {
1306
- if (options.slideMenu) delete this.Data[idModal].slideMenu;
1307
- s(`.${idModal}`).style.transition = '0.3s';
1308
- s(`.btn-restore-${idModal}`).style.display = 'none';
1309
- s(`.btn-minimize-${idModal}`).style.display = null;
1310
- s(`.btn-maximize-${idModal}`).style.display = null;
1311
- s(`.${idModal}`).style.transform = null;
1312
- s(`.${idModal}`).style.height = null;
1313
- s(`.${idModal}`).style.width = null;
1314
- setCenterRestore();
1315
- s(`.${idModal}`).style.top = top;
1316
- s(`.${idModal}`).style.left = left;
1317
- dragInstance = setDragInstance();
1318
- setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1319
- };
1320
- s(`.btn-maximize-${idModal}`).onclick = () => {
1321
- s(`.${idModal}`).style.transition = '0.3s';
1322
- setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1323
- s(`.btn-maximize-${idModal}`).style.display = 'none';
1324
- s(`.btn-restore-${idModal}`).style.display = null;
1325
- s(`.btn-minimize-${idModal}`).style.display = null;
1326
- s(`.${idModal}`).style.transform = null;
1327
-
1328
- if (options.slideMenu) {
1329
- const idSlide = this.Data[options.slideMenu]['slide-menu']
1330
- ? 'slide-menu'
1331
- : this.Data[options.slideMenu]['slide-menu-right']
1332
- ? 'slide-menu-right'
1333
- : 'slide-menu-left';
1334
- const callBack = () => {
1335
- s(`.${idModal}`).style.transition = '0.3s';
1336
- s(`.${idModal}`).style.width = `${window.innerWidth - this.Data[options.slideMenu][idSlide].width}px`;
1337
- s(`.${idModal}`).style.left =
1338
- idSlide === 'slide-menu-right' ? `0px` : `${this.Data[options.slideMenu][idSlide].width}px`;
1339
- setTimeout(() => (s(`.${idModal}`) ? (s(`.${idModal}`).style.transition = transition) : null), 300);
1340
- };
1341
-
1342
- callBack();
1343
- this.Data[idModal].slideMenu = {
1344
- callBack,
1345
- id: options.slideMenu,
1346
- };
1347
- s(`.${idModal}`).style.height = `${
1348
- window.innerHeight -
1349
- (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
1350
- (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
1351
- }px`;
1352
- s(`.${idModal}`).style.top = `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`;
1353
- } else {
1354
- s(`.${idModal}`).style.width = '100%';
1355
- s(`.${idModal}`).style.height = '100%';
1356
- s(`.${idModal}`).style.top = `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`;
1357
- s(`.${idModal}`).style.left = `0px`;
1358
- }
1359
- dragInstance = setDragInstance();
1360
- };
1361
-
1362
- const btnMenuEvent = () => {
1363
- Object.keys(this.Data[idModal].onMenuListener).map((keyListener) =>
1364
- this.Data[idModal].onMenuListener[keyListener](),
1365
- );
1366
- if (options && 'barConfig' in options && options.barConfig.buttons.menu.onClick)
1367
- return options.barConfig.buttons.menu.onClick();
1368
- };
1369
- s(`.btn-menu-${idModal}`).onclick = btnMenuEvent;
1370
-
1371
- dragInstance = setDragInstance();
1372
- if (options && options.maximize) s(`.btn-maximize-${idModal}`).click();
1373
- if (options.observer) {
1374
- this.Data[idModal].onObserverListener = {};
1375
- this.Data[idModal].observerCallBack = () => {
1376
- // logger.info('ResizeObserver', `.${idModal}`, s(`.${idModal}`).offsetWidth, s(`.${idModal}`).offsetHeight);
1377
- if (this.Data[idModal] && this.Data[idModal].onObserverListener)
1378
- Object.keys(this.Data[idModal].onObserverListener).map((eventKey) =>
1379
- this.Data[idModal].onObserverListener[eventKey]({
1380
- width: s(`.${idModal}`).offsetWidth,
1381
- height: s(`.${idModal}`).offsetHeight,
1382
- }),
1383
- );
1384
- else console.warn('observer not found', idModal);
1385
- };
1386
- this.Data[idModal].observer = new ResizeObserver(this.Data[idModal].observerCallBack);
1387
- this.Data[idModal].observer.observe(s(`.${idModal}`));
1388
- setTimeout(this.Data[idModal].observerCallBack);
1389
- }
1390
- // cancel: [cancel1, cancel2]
1391
- s(`.${idModal}`).onclick = () => {
1392
- this.Data[idModal]?.onClickListener
1393
- ? Object.keys(this.Data[idModal].onClickListener).map((keyListener) =>
1394
- this.Data[idModal].onClickListener[keyListener](),
1395
- )
1396
- : null;
1397
- };
1398
- return {
1399
- id: idModal,
1400
- ...this.Data[idModal],
1401
- };
1402
- },
1403
- currentTopModalId: '',
1404
- zIndexSync: function ({ idModal }) {
1405
- setTimeout(() => {
1406
- const cleanTopModal = () => {
1407
- Object.keys(this.Data).map((_idModal) => {
1408
- if (this.Data[_idModal].options.zIndexSync && s(`.${_idModal}`)) s(`.${_idModal}`).style.zIndex = '3';
1409
- });
1410
- };
1411
- const setTopModal = () => {
1412
- if (s(`.${idModal}`)) {
1413
- this.setTopModalCallback(idModal);
1414
- } else setTimeout(setTopModal, 100);
1415
- };
1416
- cleanTopModal();
1417
- setTopModal();
1418
- this.Data[idModal].onClickListener[`${idModal}-z-index`] = () => {
1419
- if (s(`.${idModal}`) && s(`.${idModal}`).style.zIndex === '3') {
1420
- if (this.Data[idModal].options.route) setPath(`${getProxyPath()}${this.Data[idModal].options.route}`);
1421
- cleanTopModal();
1422
- setTopModal();
1423
- }
1424
- };
1425
- });
1426
- },
1427
- setTopModalCallback: function (idModal) {
1428
- s(`.${idModal}`).style.zIndex = '4';
1429
- this.currentTopModalId = `${idModal}`;
1430
- },
1431
- mobileModal: () => window.innerWidth < 600 || window.innerHeight < 600,
1432
- writeHTML: ({ idModal, html }) => htmls(`.html-${idModal}`, html),
1433
- viewModalOpen: function () {
1434
- return Object.keys(this.Data).find((idModal) => s(`.${idModal}`) && this.Data[idModal].options.mode === 'view');
1435
- },
1436
- removeModal: function (idModal) {
1437
- if (!s(`.${idModal}`)) return;
1438
- s(`.${idModal}`).remove();
1439
- sa(`.style-${idModal}`).forEach((element) => {
1440
- element.remove();
1441
- });
1442
- delete this.Data[idModal];
1443
- },
1444
- RenderConfirm: async function (options) {
1445
- const { id } = options;
1446
- append(
1447
- 'body',
1448
- html`
1449
- <div
1450
- class="fix background-confirm-modal-${id}"
1451
- style="${renderCssAttr({
1452
- style: {
1453
- 'z-index': '10',
1454
- background: 'rgba(0,0,0,0.5)',
1455
- width: '100%',
1456
- height: '100%',
1457
- top: '0px',
1458
- left: '0px',
1459
- transition: '0.3s',
1460
- opacity: '1',
1461
- },
1462
- })}"
1463
- ></div>
1464
- `,
1465
- );
1466
- const removeBackgroundConfirmModal = () => {
1467
- s(`.background-confirm-modal-${id}`).style.opacity = '0';
1468
- setTimeout(() => {
1469
- s(`.background-confirm-modal-${id}`).remove();
1470
- });
1471
- };
1472
-
1473
- return new Promise(async (resolve, reject) => {
1474
- const { barConfig } = await Themes[Css.currentTheme]();
1475
- barConfig.buttons.maximize.disabled = true;
1476
- barConfig.buttons.minimize.disabled = true;
1477
- barConfig.buttons.restore.disabled = true;
1478
- barConfig.buttons.menu.disabled = true;
1479
- barConfig.buttons.close.disabled = false;
1480
- const htmlRender = html`
1481
- <br />
1482
- <div class="in section-mp" style="font-size: 40px; text-align: center">
1483
- <i class="fas fa-question-circle"></i>
1484
- </div>
1485
- ${await options.html()}
1486
- <div class="in section-mp">
1487
- ${await BtnIcon.Render({
1488
- class: `in section-mp form-button btn-confirm-${id}`,
1489
- label: Translate.Render('confirm'),
1490
- type: 'submit',
1491
- style: `margin: auto`,
1492
- })}
1493
- </div>
1494
- <div class="in section-mp">
1495
- ${await BtnIcon.Render({
1496
- class: `in section-mp form-button btn-cancel-${id}`,
1497
- label: Translate.Render('cancel'),
1498
- type: 'submit',
1499
- style: `margin: auto`,
1500
- })}
1501
- </div>
1502
- `;
1503
- await Modal.Render({
1504
- id,
1505
- barConfig,
1506
- titleClass: 'hide',
1507
- style: {
1508
- width: '300px',
1509
- height: '350px',
1510
- overflow: 'hidden',
1511
- 'z-index': '11',
1512
- resize: 'none',
1513
- },
1514
- dragDisabled: true,
1515
- ...options,
1516
- html: htmlRender,
1517
- });
1518
-
1519
- const end = () => {
1520
- removeBackgroundConfirmModal();
1521
- Modal.removeModal(id);
1522
- };
1523
- barConfig.buttons.close.onClick = () => {
1524
- end();
1525
- resolve({ status: 'cancelled' });
1526
- };
1527
- s(`.background-confirm-modal-${id}`).onclick = () => {
1528
- end();
1529
- resolve({ status: 'cancelled' });
1530
- };
1531
- s(`.btn-cancel-${id}`).onclick = () => {
1532
- end();
1533
- resolve({ status: 'cancelled' });
1534
- };
1535
- s(`.btn-confirm-${id}`).onclick = () => {
1536
- end();
1537
- resolve({ status: 'confirm' });
1538
- };
1539
- });
1540
- },
1541
- headerTitleHeight: 40,
1542
- actionBtnCenter: function () {
1543
- // if (!s(`.btn-close-modal-menu`).classList.contains('hide')) return s(`.main-btn-home`).click();
1544
- if (!s(`.btn-close-modal-menu`).classList.contains('hide')) return s(`.btn-close-modal-menu`).click();
1545
- if (!s(`.btn-menu-modal-menu`).classList.contains('hide')) return s(`.btn-menu-modal-menu`).click();
1546
- },
1547
- };
1548
-
1549
- const renderMenuLabel = ({ img, text, icon }) => {
1550
- if (!img) return html`<span class="menu-btn-icon">${icon}</span> ${text}`;
1551
- return html`<img class="abs center img-btn-square-menu" src="${getProxyPath()}assets/ui-icons/${img}" />
1552
- <div class="abs center main-btn-menu-text">${text}</div>`;
1553
- };
1554
-
1555
- const renderViewTitle = (options = { icon: '', img: '', text: '', assetFolder: '', 'ui-icons': '', dim, top }) => {
1556
- if (options.dim === undefined) options.dim = 60;
1557
- const { img, text, icon, dim, top } = options;
1558
- if (!img && !options['ui-icon']) return html`<span class="view-title-icon">${icon}</span> ${text}`;
1559
- return html`<img
1560
- class="abs img-btn-square-view-title"
1561
- style="${renderCssAttr({
1562
- style: { width: `${dim}px`, height: `${dim}px`, top: top !== undefined ? `${top}px` : `-${dim / 2}px` },
1563
- })}"
1564
- src="${options['ui-icon']
1565
- ? `${getProxyPath()}assets/${options.assetFolder ? options.assetFolder : 'ui-icons'}/${options['ui-icon']}`
1566
- : img}"
1567
- />
1568
- <div class="in text-btn-square-view-title" style="${renderCssAttr({ style: { 'padding-left': `${dim}px` } })}">
1569
- ${text}
1570
- </div>`;
1571
- };
1572
-
1573
- const buildBadgeToolTipMenuOption = (id, sideKey = 'left') => {
1574
- const option = {
1575
- id: `tooltip-content-main-btn-${id}`,
1576
- text: `${Translate.Render(`${id}`)}`,
1577
- classList: 'tooltip-menu hide',
1578
- style: { top: `0px` },
1579
- };
1580
- switch (sideKey) {
1581
- case 'left':
1582
- option.style.left = '40px';
1583
-
1584
- break;
1585
-
1586
- case 'right':
1587
- option.style.right = '80px';
1588
- break;
1589
-
1590
- default:
1591
- break;
1592
- }
1593
- return option;
1594
- };
1595
-
1596
- export { Modal, renderMenuLabel, renderViewTitle, buildBadgeToolTipMenuOption };
1
+ import { cap, getId, newInstance } from './CommonJs.js';
2
+ import { Draggable } from '@neodrag/vanilla';
3
+ import {
4
+ append,
5
+ s,
6
+ prepend,
7
+ setPath,
8
+ getProxyPath,
9
+ htmls,
10
+ sa,
11
+ getAllChildNodes,
12
+ getCurrentTrace,
13
+ isActiveElement,
14
+ } from './VanillaJs.js';
15
+ import { BtnIcon } from './BtnIcon.js';
16
+ import { Responsive } from './Responsive.js';
17
+ import { loggerFactory } from './Logger.js';
18
+ import {
19
+ Css,
20
+ ThemeEvents,
21
+ Themes,
22
+ ThemesScope,
23
+ darkTheme,
24
+ renderStyleTag,
25
+ renderStatus,
26
+ renderCssAttr,
27
+ } from './Css.js';
28
+ import { setDocTitle } from './Router.js';
29
+ import { NotificationManager } from './NotificationManager.js';
30
+ import { EventsUI } from './EventsUI.js';
31
+ import { Translate } from './Translate.js';
32
+ import { Input } from './Input.js';
33
+ import { Validator } from './Validator.js';
34
+ import { DropDown } from './DropDown.js';
35
+ import { Keyboard } from './Keyboard.js';
36
+ import { Badge } from './Badge.js';
37
+ import { Worker } from './Worker.js';
38
+
39
+ const logger = loggerFactory(import.meta);
40
+
41
+ const Modal = {
42
+ Data: {},
43
+ Render: async function (
44
+ options = {
45
+ id: '',
46
+ barConfig: {},
47
+ title: '',
48
+ html: '',
49
+ handleType: 'bar',
50
+ mode: '' /* slide-menu */,
51
+ RouterInstance: {},
52
+ disableTools: [],
53
+ },
54
+ ) {
55
+ if (options.heightBottomBar === undefined) options.heightBottomBar = 50;
56
+ if (options.heightTopBar === undefined) options.heightTopBar = 50;
57
+ let originHeightBottomBar = options.heightBottomBar ? newInstance(options.heightBottomBar) : 0;
58
+ let originHeightTopBar = options.heightTopBar ? newInstance(options.heightTopBar) : 0;
59
+ let width = 300;
60
+ let height = 400;
61
+ let top = 0;
62
+ let left = 0;
63
+ const topBottomBarEnable = options && options.barMode && options.barMode === 'top-bottom-bar';
64
+ if (!topBottomBarEnable) {
65
+ options.heightTopBar = options.heightTopBar + options.heightBottomBar;
66
+ options.heightBottomBar = 0;
67
+ }
68
+ const setCenterRestore = () => {
69
+ const ResponsiveData = Responsive.getResponsiveData();
70
+ top = `${ResponsiveData.height / 2 - height / 2}px`;
71
+ left = `${ResponsiveData.width / 2 - width / 2}px`;
72
+ };
73
+ setCenterRestore();
74
+ let transition = `opacity 0.3s, box-shadow 0.3s, bottom 0.3s`;
75
+ const originSlideMenuWidth = 320;
76
+ const collapseSlideMenuWidth = 50;
77
+ let slideMenuWidth = originSlideMenuWidth;
78
+ const minWidth = width;
79
+ const heightDefaultTopBar = 0;
80
+ const heightDefaultBottomBar = 0;
81
+ const idModal = options && 'id' in options ? options.id : getId(this.Data, 'modal-');
82
+ this.Data[idModal] = {
83
+ options,
84
+ onCloseListener: {},
85
+ onMenuListener: {},
86
+ onDragEndListener: {},
87
+ onObserverListener: {},
88
+ onClickListener: {},
89
+ query: options.query ? `${window.location.search}` : undefined,
90
+ };
91
+ if (options && 'mode' in options) {
92
+ this.Data[idModal][options.mode] = {};
93
+ switch (options.mode) {
94
+ case 'view':
95
+ if (options && options.slideMenu) s(`.btn-close-${options.slideMenu}`).click();
96
+ options.zIndexSync = true;
97
+
98
+ options.style = {
99
+ ...options.style,
100
+ 'min-width': `${minWidth}px`,
101
+ };
102
+
103
+ if (this.mobileModal()) {
104
+ options.barConfig.buttons.restore.disabled = true;
105
+ options.barConfig.buttons.minimize.disabled = true;
106
+ options.dragDisabled = true;
107
+ options.style.resize = 'none';
108
+ }
109
+
110
+ Responsive.Event[`view-${idModal}`] = () => {
111
+ if (!this.Data[idModal]) return delete Responsive.Event[`view-${idModal}`];
112
+ if (this.Data[idModal].slideMenu)
113
+ s(`.${idModal}`).style.height = `${
114
+ window.innerHeight -
115
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
116
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
117
+ }px`;
118
+ };
119
+ Responsive.Event[`view-${idModal}`]();
120
+
121
+ // Router
122
+ if (options.route)
123
+ (() => {
124
+ let path = window.location.pathname;
125
+ if (path !== '/' && path[path.length - 1] === '/') path = path.slice(0, -1);
126
+ const proxyPath = getProxyPath();
127
+ const newPath = `${proxyPath}${options.route}`;
128
+ if (path !== newPath) {
129
+ // console.warn('SET MODAL URI', newPath);
130
+ setPath(`${newPath}`); // ${location.search}
131
+ setDocTitle({ ...options.RouterInstance, route: options.route });
132
+ }
133
+ })();
134
+
135
+ break;
136
+ case 'slide-menu':
137
+ case 'slide-menu-right':
138
+ case 'slide-menu-left':
139
+ (async () => {
140
+ const { barConfig } = options;
141
+ options.style = {
142
+ position: 'absolute',
143
+ height: `${
144
+ window.innerHeight -
145
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
146
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
147
+ }px`,
148
+ width: `${slideMenuWidth}px`,
149
+ // 'overflow-x': 'hidden',
150
+ // overflow: 'visible', // required for tooltip
151
+ 'z-index': 6,
152
+ resize: 'none',
153
+ top: `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`,
154
+ };
155
+ options.mode === 'slide-menu-right' ? (options.style.right = '0px') : (options.style.left = '0px');
156
+ const contentIconClass = 'abs center';
157
+
158
+ options.dragDisabled = true;
159
+ options.titleClass = 'hide';
160
+ top = '0px';
161
+ left = 'auto';
162
+ width = 'auto';
163
+ // barConfig.buttons.maximize.disabled = true;
164
+ // barConfig.buttons.minimize.disabled = true;
165
+ // barConfig.buttons.restore.disabled = true;
166
+ // barConfig.buttons.menu.disabled = true;
167
+ // barConfig.buttons.close.disabled = true;
168
+ options.btnBarModalClass = 'hide';
169
+ Responsive.Event[`slide-menu-${idModal}`] = () => {
170
+ for (const _idModal of Object.keys(this.Data)) {
171
+ if (this.Data[_idModal].slideMenu && this.Data[_idModal].slideMenu.id === idModal)
172
+ this.Data[_idModal].slideMenu.callBack();
173
+ }
174
+ s(`.${idModal}`).style.height = `${
175
+ window.innerHeight -
176
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
177
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
178
+ }px`;
179
+ if (s(`.main-body-top`)) {
180
+ if (Modal.mobileModal()) {
181
+ if (s(`.btn-menu-${idModal}`).classList.contains('hide') && collapseSlideMenuWidth !== slideMenuWidth)
182
+ s(`.main-body-top`).classList.remove('hide');
183
+ if (s(`.btn-close-${idModal}`).classList.contains('hide')) s(`.main-body-top`).classList.add('hide');
184
+ } else if (!s(`.main-body-top`).classList.contains('hide')) s(`.main-body-top`).classList.add('hide');
185
+ }
186
+ };
187
+ barConfig.buttons.menu.onClick = () => {
188
+ this.Data[idModal][options.mode].width = slideMenuWidth;
189
+ s(`.btn-menu-${idModal}`).classList.add('hide');
190
+ s(`.btn-close-${idModal}`).classList.remove('hide');
191
+ s(`.${idModal}`).style.width = `${this.Data[idModal][options.mode].width}px`;
192
+ s(`.html-${idModal}`).style.display = 'block';
193
+ // s(`.title-modal-${idModal}`).style.display = 'block';
194
+ if (s(`.main-body-top`)) {
195
+ s(`.btn-bar-center-icon-close`).classList.remove('hide');
196
+ s(`.btn-bar-center-icon-menu`).classList.add('hide');
197
+ }
198
+
199
+ Responsive.Event[`slide-menu-${idModal}`]();
200
+ };
201
+ barConfig.buttons.close.onClick = () => {
202
+ this.Data[idModal][options.mode].width = 0;
203
+ s(`.btn-close-${idModal}`).classList.add('hide');
204
+ s(`.btn-menu-${idModal}`).classList.remove('hide');
205
+ s(`.${idModal}`).style.width = `${this.Data[idModal][options.mode].width}px`;
206
+ s(`.html-${idModal}`).style.display = 'none';
207
+ if (s(`.main-body-top`)) {
208
+ s(`.btn-bar-center-icon-menu`).classList.remove('hide');
209
+ s(`.btn-bar-center-icon-close`).classList.add('hide');
210
+ }
211
+ // s(`.title-modal-${idModal}`).style.display = 'none';
212
+ Responsive.Event[`slide-menu-${idModal}`]();
213
+ };
214
+ transition += `, width 0.3s`;
215
+
216
+ const inputSearchBoxId = `top-bar-search-box`;
217
+ append(
218
+ 'body',
219
+ html` <div class="fix modal slide-menu-top-bar">
220
+ <div
221
+ class="fl top-bar ${options.barClass ? options.barClass : ''}"
222
+ style="height: ${originHeightTopBar}px;"
223
+ >
224
+ ${await BtnIcon.Render({
225
+ style: `height: 100%`,
226
+ class: 'in fll main-btn-menu action-bar-box action-btn-close hide',
227
+ label: html` <div class="${contentIconClass} action-btn-close-render">
228
+ <i class="fa-solid fa-xmark"></i>
229
+ </div>`,
230
+ })}
231
+ ${await BtnIcon.Render({
232
+ style: `height: 100%`,
233
+ class: `in fll main-btn-menu action-bar-box action-btn-app-icon ${
234
+ options?.disableTools?.includes('app-icon') ? 'hide' : ''
235
+ }`,
236
+ label: html` <div class="${contentIconClass} action-btn-app-icon-render"></div>`,
237
+ })}
238
+ <form
239
+ class="in fll top-bar-search-box-container hover ${options?.disableTools?.includes('text-box')
240
+ ? 'hide'
241
+ : ''}"
242
+ >
243
+ ${await Input.Render({
244
+ id: inputSearchBoxId,
245
+ placeholder: Modal.mobileModal() ? Translate.Render('search', '.top-bar-search-box') : undefined, // html`<i class="fa-solid fa-magnifying-glass"></i> ${Translate.Render('search')}`,
246
+ placeholderIcon: html`<div
247
+ class="in fll"
248
+ style="width: ${originHeightTopBar}px; height: ${originHeightTopBar}px;"
249
+ >
250
+ <div class="abs center"><i class="fa-solid fa-magnifying-glass"></i></div>
251
+ ${!Modal.mobileModal()
252
+ ? html` <div
253
+ class="inl wfm key-shortcut-container-info"
254
+ style="${renderCssAttr({ style: { top: '10px', left: '60px' } })}"
255
+ >
256
+ ${await Badge.Render({
257
+ id: 'shortcut-key-info-search',
258
+ text: 'Shift',
259
+ classList: 'inl',
260
+ style: { 'z-index': 1 },
261
+ })}
262
+ ${await Badge.Render({
263
+ id: 'shortcut-key-info-search',
264
+ text: '+',
265
+ classList: 'inl',
266
+ style: { 'z-index': 1, background: 'none', color: '#5f5f5f' },
267
+ })}
268
+ ${await Badge.Render({
269
+ id: 'shortcut-key-info-search',
270
+ text: 'k',
271
+ classList: 'inl',
272
+ style: { 'z-index': 1 },
273
+ })}
274
+ </div>`
275
+ : ''}
276
+ </div>`,
277
+ inputClass: 'in fll',
278
+ // containerClass: '',
279
+ })}
280
+ </form>
281
+ <div
282
+ class="abs top-box-profile-container ${options?.disableTools?.includes('profile') ? 'hide' : ''}"
283
+ >
284
+ ${await BtnIcon.Render({
285
+ style: `height: 100%`,
286
+ class: 'in fll session-in-log-in main-btn-menu action-bar-box action-btn-profile-log-in',
287
+ label: html` <div class="${contentIconClass} action-btn-profile-log-in-render"></div>`,
288
+ })}
289
+ ${await BtnIcon.Render({
290
+ style: `height: 100%`,
291
+ class: 'in fll session-in-log-out main-btn-menu action-bar-box action-btn-profile-log-out',
292
+ label: html` <div class="${contentIconClass} action-btn-profile-log-out-render">
293
+ <i class="fas fa-user-plus"></i>
294
+ </div>`,
295
+ })}
296
+ </div>
297
+ </div>
298
+ </div>`,
299
+ );
300
+ EventsUI.onClick(`.action-btn-profile-log-in`, () => {
301
+ s(`.main-btn-account`).click();
302
+ });
303
+ EventsUI.onClick(`.action-btn-profile-log-out`, () => {
304
+ s(`.main-btn-sign-up`).click();
305
+ });
306
+ s(`.input-info-${inputSearchBoxId}`).style.textAlign = 'left';
307
+ htmls(`.input-info-${inputSearchBoxId}`, '');
308
+ const inputInfoNode = s(`.input-info-${inputSearchBoxId}`).cloneNode(true);
309
+ s(`.input-info-${inputSearchBoxId}`).remove();
310
+ {
311
+ const id = 'search-box-history';
312
+ const searchBoxHistoryId = id;
313
+ const formDataInfoNode = [
314
+ {
315
+ model: 'search-box',
316
+ id: inputSearchBoxId,
317
+ rules: [] /*{ type: 'isEmpty' }, { type: 'isEmail' }*/,
318
+ },
319
+ ];
320
+ let hoverHistBox = false;
321
+ let hoverInputBox = false;
322
+ let currentKeyBoardSearchBoxIndex = 0;
323
+ let results = [];
324
+ let historySearchBox = [];
325
+
326
+ const checkHistoryBoxTitleStatus = () => {
327
+ if (s(`.search-box-result-title`) && s(`.search-box-result-title`).classList) {
328
+ if (!s(`.${inputSearchBoxId}`).value.trim()) {
329
+ s(`.search-box-result-title`).classList.add('hide');
330
+ s(`.search-box-recent-title`).classList.remove('hide');
331
+ } else {
332
+ s(`.search-box-recent-title`).classList.add('hide');
333
+ s(`.search-box-result-title`).classList.remove('hide');
334
+ }
335
+ }
336
+ };
337
+
338
+ const checkShortcutContainerInfoEnabled = () => {
339
+ if (Modal.mobileModal() || !s(`.key-shortcut-container-info`)) return;
340
+ if (!s(`.${inputSearchBoxId}`).value) {
341
+ s(`.key-shortcut-container-info`).classList.remove('hide');
342
+ } else s(`.key-shortcut-container-info`).classList.add('hide');
343
+ };
344
+
345
+ const renderSearchResult = async (results) => {
346
+ htmls(`.html-${searchBoxHistoryId}`, '');
347
+ if (results.length === 0) {
348
+ append(
349
+ `.html-${searchBoxHistoryId}`,
350
+ await BtnIcon.Render({
351
+ label: html`<i class="fas fa-exclamation-circle"></i> ${Translate.Render('no-result-found')}`,
352
+ class: `wfa`,
353
+ style: renderCssAttr({
354
+ style: {
355
+ padding: '3px',
356
+ margin: '2px',
357
+ 'text-align': 'center',
358
+ border: 'none',
359
+ cursor: 'default',
360
+ background: 'none !important',
361
+ },
362
+ }),
363
+ }),
364
+ );
365
+ }
366
+ let indexResult = -1;
367
+ for (const result of results) {
368
+ indexResult++;
369
+ const indexRender = indexResult;
370
+ append(
371
+ `.html-${searchBoxHistoryId}`,
372
+ await BtnIcon.Render({
373
+ label: `${
374
+ result.fontAwesomeIcon
375
+ ? html`<i class="${result.fontAwesomeIcon.classList.toString()}"></i> `
376
+ : result.imgElement
377
+ ? html`<img
378
+ class="inl"
379
+ src="${result.imgElement.src}"
380
+ style="${renderCssAttr({ style: { width: '25px', height: '25px' } })}"
381
+ />`
382
+ : ''
383
+ } ${Translate.Render(result.routerId)}`,
384
+ class: `wfa search-result-btn-${result.routerId} ${
385
+ indexResult === currentKeyBoardSearchBoxIndex ? 'main-btn-menu-active' : ''
386
+ } search-result-btn-${indexResult}`,
387
+ style: renderCssAttr({
388
+ style: { padding: '3px', margin: '2px', 'text-align': 'left' },
389
+ }),
390
+ }),
391
+ );
392
+ s(`.search-result-btn-${result.routerId}`).onclick = () => {
393
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
394
+ `main-btn-menu-active`,
395
+ );
396
+ currentKeyBoardSearchBoxIndex = indexRender;
397
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
398
+ `main-btn-menu-active`,
399
+ );
400
+ setSearchValue(`.search-result-btn-${result.routerId}`);
401
+ };
402
+ }
403
+ };
404
+
405
+ const getResultSearchBox = (validatorData) => {
406
+ const { model, id } = validatorData;
407
+ switch (model) {
408
+ case 'search-box':
409
+ {
410
+ if (
411
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
412
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList
413
+ )
414
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
415
+ `main-btn-menu-active`,
416
+ );
417
+ currentKeyBoardSearchBoxIndex = 0;
418
+ if (
419
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
420
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList
421
+ )
422
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
423
+ `main-btn-menu-active`,
424
+ );
425
+ results = [];
426
+ const routerInstance = Worker.RouterInstance.Routes();
427
+ for (const _routerId of Object.keys(routerInstance)) {
428
+ const routerId = _routerId.slice(1);
429
+ if (routerId) {
430
+ if (
431
+ s(`.main-btn-${routerId}`) &&
432
+ (routerId.toLocaleLowerCase().match(s(`.${id}`).value.toLocaleLowerCase()) ||
433
+ (Translate.Data[routerId] &&
434
+ Object.keys(Translate.Data[routerId]).filter((keyLang) =>
435
+ Translate.Data[routerId][keyLang]
436
+ .toLocaleLowerCase()
437
+ .match(s(`.${id}`).value.toLocaleLowerCase()),
438
+ ).length > 0))
439
+ ) {
440
+ const fontAwesomeIcon = getAllChildNodes(s(`.main-btn-${routerId}`)).find((e) => {
441
+ return (
442
+ e.classList &&
443
+ Array.from(e.classList).find((e) => e.match('fa-') && !e.match('fa-grip-vertical'))
444
+ );
445
+ });
446
+ const imgElement = getAllChildNodes(s(`.main-btn-${routerId}`)).find((e) => {
447
+ return (
448
+ typeof e.src === 'string' &&
449
+ e.src.match(routerId) &&
450
+ e.classList &&
451
+ Array.from(e.classList).find((e) => e.match('img-btn-square-menu'))
452
+ );
453
+ });
454
+ if (imgElement || fontAwesomeIcon) {
455
+ results.push({
456
+ routerId,
457
+ fontAwesomeIcon: fontAwesomeIcon,
458
+ imgElement,
459
+ });
460
+ }
461
+ }
462
+ }
463
+ }
464
+ }
465
+ break;
466
+
467
+ default:
468
+ break;
469
+ }
470
+ if (s(`.${inputSearchBoxId}`).value.trim()) renderSearchResult(results);
471
+ else renderSearchResult(historySearchBox);
472
+ };
473
+
474
+ const searchBoxCallBack = async (validatorData) => {
475
+ const isSearchBoxActiveElement = isActiveElement(inputSearchBoxId);
476
+ checkHistoryBoxTitleStatus();
477
+ checkShortcutContainerInfoEnabled();
478
+ if (!isSearchBoxActiveElement && !hoverHistBox && !hoverInputBox) {
479
+ Modal.removeModal(searchBoxHistoryId);
480
+ return;
481
+ }
482
+ setTimeout(() => getResultSearchBox(validatorData));
483
+ };
484
+
485
+ const getDefaultSearchBoxSelector = () => `.search-result-btn-${currentKeyBoardSearchBoxIndex}`;
486
+
487
+ const updateSearchBoxValue = (selector) => {
488
+ if (!selector) selector = getDefaultSearchBoxSelector();
489
+ if (s(selector).childNodes) {
490
+ if (
491
+ s(selector).childNodes[s(selector).childNodes.length - 1] &&
492
+ s(selector).childNodes[s(selector).childNodes.length - 1].data &&
493
+ s(selector).childNodes[s(selector).childNodes.length - 1].data.trim()
494
+ ) {
495
+ s(`.${inputSearchBoxId}`).value =
496
+ s(selector).childNodes[s(selector).childNodes.length - 1].data.trim();
497
+ } else if (
498
+ s(selector).childNodes[s(selector).childNodes.length - 2] &&
499
+ s(selector).childNodes[s(selector).childNodes.length - 2].outerText &&
500
+ s(selector).childNodes[s(selector).childNodes.length - 2].outerText.trim()
501
+ ) {
502
+ s(`.${inputSearchBoxId}`).value =
503
+ s(selector).childNodes[s(selector).childNodes.length - 2].outerText.trim();
504
+ }
505
+ }
506
+ checkHistoryBoxTitleStatus();
507
+ checkShortcutContainerInfoEnabled();
508
+ };
509
+
510
+ const setSearchValue = (selector) => {
511
+ if (!selector) selector = getDefaultSearchBoxSelector();
512
+ historySearchBox = historySearchBox.filter(
513
+ (h) => h.routerId !== results[currentKeyBoardSearchBoxIndex].routerId,
514
+ );
515
+ historySearchBox.unshift(results[currentKeyBoardSearchBoxIndex]);
516
+ updateSearchBoxValue(selector);
517
+ s(`.main-btn-${results[currentKeyBoardSearchBoxIndex].routerId}`).click();
518
+ Modal.removeModal(searchBoxHistoryId);
519
+ };
520
+
521
+ const searchBoxHistoryOpen = async () => {
522
+ if (!s(`.${id}`)) {
523
+ const { barConfig } = await Themes[Css.currentTheme]();
524
+ barConfig.buttons.maximize.disabled = true;
525
+ barConfig.buttons.minimize.disabled = true;
526
+ barConfig.buttons.restore.disabled = true;
527
+ barConfig.buttons.menu.disabled = true;
528
+ barConfig.buttons.close.disabled = false;
529
+ await Modal.Render({
530
+ id,
531
+ barConfig,
532
+ title: html`<div class="search-box-recent-title">
533
+ ${renderViewTitle({
534
+ icon: html`<i class="fas fa-history mini-title"></i>`,
535
+ text: Translate.Render('recent'),
536
+ })}
537
+ </div>
538
+ <div class="search-box-result-title hide">
539
+ ${renderViewTitle({
540
+ icon: html`<i class="far fa-list-alt mini-title"></i>`,
541
+ text: Translate.Render('results'),
542
+ })}
543
+ </div>`,
544
+ html: () => html``,
545
+ titleClass: 'mini-title',
546
+ style: {
547
+ resize: 'none',
548
+ 'max-width': '450px',
549
+ height:
550
+ this.mobileModal() && window.innerWidth < 445
551
+ ? `${window.innerHeight - originHeightTopBar}px !important`
552
+ : '300px !important',
553
+ 'z-index': 7,
554
+ },
555
+ dragDisabled: true,
556
+ maximize: true,
557
+ heightBottomBar: 0,
558
+ heightTopBar: originHeightTopBar,
559
+ barMode: options.barMode,
560
+ });
561
+
562
+ const titleNode = s(`.title-modal-${id}`).cloneNode(true);
563
+ s(`.title-modal-${id}`).remove();
564
+ s(`.btn-bar-modal-container-render-${id}`).classList.add('in');
565
+ s(`.btn-bar-modal-container-render-${id}`).classList.add('fll');
566
+ s(`.btn-bar-modal-container-render-${id}`).appendChild(titleNode);
567
+
568
+ prepend(`.btn-bar-modal-container-${id}`, html`<div class="hide">${inputInfoNode.outerHTML}</div>`);
569
+
570
+ s(`.top-bar-search-box-container`).onmouseover = () => {
571
+ hoverInputBox = true;
572
+ };
573
+ s(`.top-bar-search-box-container`).onmouseout = () => {
574
+ hoverInputBox = false;
575
+ };
576
+ s(`.${id}`).onmouseover = () => {
577
+ hoverHistBox = true;
578
+ };
579
+ s(`.${id}`).onmouseout = () => {
580
+ hoverHistBox = false;
581
+ s(`.${inputSearchBoxId}`).focus();
582
+ };
583
+ }
584
+ };
585
+
586
+ s('.top-bar-search-box').oninput = () => {
587
+ searchBoxHistoryOpen();
588
+ searchBoxCallBack(formDataInfoNode[0]);
589
+ };
590
+ s('.top-bar-search-box').onfocus = () => {
591
+ searchBoxHistoryOpen();
592
+ searchBoxCallBack(formDataInfoNode[0]);
593
+ };
594
+ s('.top-bar-search-box').onblur = () => {
595
+ if (!hoverHistBox && !hoverInputBox && !isActiveElement(inputSearchBoxId)) {
596
+ Modal.removeModal(searchBoxHistoryId);
597
+ }
598
+ };
599
+ EventsUI.onClick(`.top-bar-search-box-container`, () => {
600
+ searchBoxHistoryOpen();
601
+ searchBoxCallBack(formDataInfoNode[0]);
602
+ });
603
+
604
+ const timePressDelay = 100;
605
+ Keyboard.instanceMultiPressKey({
606
+ id: 'input-search-shortcut-ArrowUp',
607
+ keys: ['ArrowUp'],
608
+ eventCallBack: () => {
609
+ if (s(`.${id}`)) {
610
+ if (
611
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
612
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex - 1]
613
+ ) {
614
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
615
+ `main-btn-menu-active`,
616
+ );
617
+ currentKeyBoardSearchBoxIndex--;
618
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
619
+ `main-btn-menu-active`,
620
+ );
621
+ } else {
622
+ if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
623
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
624
+ `main-btn-menu-active`,
625
+ );
626
+ currentKeyBoardSearchBoxIndex = s(`.html-${searchBoxHistoryId}`).childNodes.length - 1;
627
+ if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
628
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
629
+ `main-btn-menu-active`,
630
+ );
631
+ }
632
+ updateSearchBoxValue();
633
+ }
634
+ },
635
+ timePressDelay,
636
+ });
637
+
638
+ Keyboard.instanceMultiPressKey({
639
+ id: 'input-search-shortcut-ArrowDown',
640
+ keys: ['ArrowDown'],
641
+ eventCallBack: () => {
642
+ if (s(`.${id}`)) {
643
+ if (
644
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex] &&
645
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex + 1]
646
+ ) {
647
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
648
+ `main-btn-menu-active`,
649
+ );
650
+ currentKeyBoardSearchBoxIndex++;
651
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
652
+ `main-btn-menu-active`,
653
+ );
654
+ } else {
655
+ if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
656
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.remove(
657
+ `main-btn-menu-active`,
658
+ );
659
+ currentKeyBoardSearchBoxIndex = 0;
660
+ if (s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex])
661
+ s(`.html-${searchBoxHistoryId}`).childNodes[currentKeyBoardSearchBoxIndex].classList.add(
662
+ `main-btn-menu-active`,
663
+ );
664
+ }
665
+ updateSearchBoxValue();
666
+ }
667
+ },
668
+ timePressDelay,
669
+ });
670
+
671
+ s(`.top-bar-search-box-container`).onsubmit = (e) => {
672
+ e.preventDefault();
673
+ setSearchValue();
674
+ };
675
+ }
676
+ setTimeout(async () => {
677
+ // clone and change position
678
+
679
+ // s(`.btn-close-${idModal}`);
680
+ // s(`.btn-menu-${idModal}`);
681
+ if (originHeightBottomBar === 0) {
682
+ const btnCloseNode = s(`.btn-close-${idModal}`).cloneNode(true);
683
+ s(`.btn-close-${idModal}`).remove();
684
+ s(`.top-bar`).appendChild(btnCloseNode);
685
+ s(`.btn-close-${idModal}`).onclick = btnCloseEvent;
686
+
687
+ const btnMenuNode = s(`.btn-menu-${idModal}`).cloneNode(true);
688
+ s(`.btn-menu-${idModal}`).remove();
689
+ s(`.top-bar`).appendChild(btnMenuNode);
690
+ s(`.btn-menu-${idModal}`).onclick = btnMenuEvent;
691
+ }
692
+
693
+ // const titleNode = s(`.title-modal-${idModal}`).cloneNode(true);
694
+ // s(`.title-modal-${idModal}`).remove();
695
+ // s(`.top-bar`).appendChild(titleNode);
696
+
697
+ s(`.slide-menu-top-bar`).style.zIndex = 7;
698
+
699
+ // s('body').removeChild(`.${idModal}`);
700
+ // while (s(`.top-modal`).firstChild) s(`.top-modal`).removeChild(s(`.top-modal`).firstChild);
701
+
702
+ {
703
+ const { barConfig } = await Themes[Css.currentTheme]();
704
+ barConfig.buttons.maximize.disabled = true;
705
+ barConfig.buttons.minimize.disabled = true;
706
+ barConfig.buttons.restore.disabled = true;
707
+ barConfig.buttons.menu.disabled = true;
708
+ barConfig.buttons.close.disabled = true;
709
+ const id = 'main-body';
710
+ await Modal.Render({
711
+ id,
712
+ barConfig,
713
+ html: options.htmlMainBody ? options.htmlMainBody : () => html``,
714
+ titleClass: 'hide',
715
+ style: {
716
+ // overflow: 'hidden',
717
+ background: 'none',
718
+ resize: 'none',
719
+ 'min-width': `${minWidth}px`,
720
+ width: '100%',
721
+ // border: '3px solid red',
722
+ },
723
+ dragDisabled: true,
724
+ maximize: true,
725
+ slideMenu: 'modal-menu',
726
+ heightTopBar: originHeightTopBar,
727
+ heightBottomBar: originHeightBottomBar,
728
+ barMode: options.barMode,
729
+ });
730
+ const maxWidthInputSearchBox = 450;
731
+ const paddingInputSearchBox = 5;
732
+ const paddingRightSearchBox = 50;
733
+ Responsive.Event[`view-${id}`] = () => {
734
+ if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
735
+ const widthInputSearchBox =
736
+ window.innerWidth > maxWidthInputSearchBox ? maxWidthInputSearchBox : window.innerWidth;
737
+ s(`.top-bar-search-box-container`).style.width = `${
738
+ widthInputSearchBox - originHeightTopBar - paddingRightSearchBox - 1
739
+ }px`;
740
+ s(`.top-bar-search-box`).style.width = `${
741
+ widthInputSearchBox -
742
+ originHeightTopBar * 2 -
743
+ paddingRightSearchBox -
744
+ paddingInputSearchBox * 2 /*padding input*/ -
745
+ 10 /* right-margin */
746
+ }px`;
747
+ s(`.top-bar-search-box`).style.top = `${
748
+ (originHeightTopBar - s(`.top-bar-search-box`).clientHeight) / 2
749
+ }px`;
750
+ if (this.Data[id].slideMenu)
751
+ s(`.${id}`).style.height = `${
752
+ window.innerHeight -
753
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
754
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
755
+ }px`;
756
+ };
757
+ Responsive.Event[`view-${id}`]();
758
+ Keyboard.instanceMultiPressKey({
759
+ id: 'input-search-shortcut-k',
760
+ keys: [
761
+ ['Shift', 'k'],
762
+ ['Alt', 'k'],
763
+ ],
764
+ eventCallBack: () => {
765
+ if (s(`.top-bar-search-box`)) {
766
+ s(`.top-bar-search-box`).blur();
767
+ s(`.top-bar-search-box`).focus();
768
+ s(`.top-bar-search-box`).select();
769
+ }
770
+ },
771
+ });
772
+ }
773
+
774
+ {
775
+ const { barConfig } = await Themes[Css.currentTheme]();
776
+ barConfig.buttons.maximize.disabled = true;
777
+ barConfig.buttons.minimize.disabled = true;
778
+ barConfig.buttons.restore.disabled = true;
779
+ barConfig.buttons.menu.disabled = true;
780
+ barConfig.buttons.close.disabled = true;
781
+ const id = 'bottom-bar';
782
+ if (options && options.homeModals && !options.homeModals.includes(id)) options.homeModals.push(id);
783
+ else options.homeModals = [id];
784
+ const html = async () => html`
785
+ <style>
786
+ .top-bar-search-box-container {
787
+ height: 100%;
788
+ overflow: hidden;
789
+ }
790
+ .bottom-bar {
791
+ overflow: hidden;
792
+ }
793
+ .action-bar-box {
794
+ margin: 0px;
795
+ border: none;
796
+ width: 50px;
797
+ min-height: 50px;
798
+ }
799
+ </style>
800
+ <div
801
+ class="fl ${options.barClass ? options.barClass : ''}"
802
+ style="height: ${originHeightBottomBar}px;"
803
+ >
804
+ ${await BtnIcon.Render({
805
+ style: `height: 100%`,
806
+ class: `in fl${
807
+ options.mode === 'slide-menu-right' ? 'r' : 'l'
808
+ } main-btn-menu action-bar-box action-btn-center ${
809
+ options?.disableTools?.includes('center') ? 'hide' : ''
810
+ }`,
811
+ label: html`
812
+ <div class="${contentIconClass}">
813
+ <i class="far fa-square btn-bar-center-icon-square hide"></i>
814
+ <span class="btn-bar-center-icon-close hide">${barConfig.buttons.close.label}</span>
815
+ <span class="btn-bar-center-icon-menu">${barConfig.buttons.menu.label}</span>
816
+ </div>
817
+ `,
818
+ })}
819
+ ${await BtnIcon.Render({
820
+ style: `height: 100%`,
821
+ class: `in flr main-btn-menu action-bar-box action-btn-lang ${
822
+ options?.disableTools?.includes('lang') ? 'hide' : ''
823
+ }`,
824
+ label: html` <div class="${contentIconClass} action-btn-lang-render"></div>`,
825
+ })}
826
+ ${await BtnIcon.Render({
827
+ style: `height: 100%`,
828
+ class: `in flr main-btn-menu action-bar-box action-btn-theme ${
829
+ options?.disableTools?.includes('theme') ? 'hide' : ''
830
+ }`,
831
+ label: html` <div class="${contentIconClass} action-btn-theme-render"></div>`,
832
+ })}
833
+ ${await BtnIcon.Render({
834
+ style: `height: 100%`,
835
+ class: `in flr main-btn-menu action-bar-box action-btn-home ${
836
+ options?.disableTools?.includes('navigator') ? 'hide' : ''
837
+ }`,
838
+ label: html` <div class="${contentIconClass}"><i class="fas fa-home"></i></div>`,
839
+ })}
840
+ ${await BtnIcon.Render({
841
+ style: `height: 100%`,
842
+ class: `in flr main-btn-menu action-bar-box action-btn-right ${
843
+ options?.disableTools?.includes('navigator') ? 'hide' : ''
844
+ }`,
845
+ label: html` <div class="${contentIconClass}"><i class="fas fa-chevron-right"></i></div>`,
846
+ })}
847
+ ${await BtnIcon.Render({
848
+ style: `height: 100%`,
849
+ class: `in flr main-btn-menu action-bar-box action-btn-left ${
850
+ options?.disableTools?.includes('navigator') ? 'hide' : ''
851
+ }`,
852
+ label: html`<div class="${contentIconClass}"><i class="fas fa-chevron-left"></i></div>`,
853
+ })}
854
+ </div>
855
+ `;
856
+ if (options.heightBottomBar === 0 && options.heightTopBar > 0) {
857
+ append(`.slide-menu-top-bar`, html` <div class="in ${id}">${await html()}</div>`);
858
+ } else {
859
+ await Modal.Render({
860
+ id,
861
+ barConfig,
862
+ html,
863
+ titleClass: 'hide',
864
+ style: {
865
+ resize: 'none',
866
+ height: `${options.heightBottomBar}px`,
867
+ 'min-width': `${minWidth}px`,
868
+ 'z-index': 7,
869
+ },
870
+ dragDisabled: true,
871
+ maximize: true,
872
+ barMode: options.barMode,
873
+ });
874
+ Responsive.Event[`view-${id}`] = () => {
875
+ if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
876
+ // <div class="in fll right-offset-menu-bottom-bar" style="height: 100%"></div>
877
+ // s(`.right-offset-menu-bottom-bar`).style.width = `${window.innerWidth - slideMenuWidth}px`;
878
+ s(`.${id}`).style.top = `${
879
+ window.innerHeight - (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
880
+ }px`;
881
+ };
882
+ Responsive.Event[`view-${id}`]();
883
+ }
884
+ EventsUI.onClick(`.action-btn-left`, (e) => {
885
+ e.preventDefault();
886
+ window.history.back();
887
+ });
888
+ EventsUI.onClick(`.action-btn-center`, (e) => {
889
+ e.preventDefault();
890
+ this.actionBtnCenter();
891
+ });
892
+ EventsUI.onClick(`.action-btn-right`, (e) => {
893
+ e.preventDefault();
894
+ window.history.forward();
895
+ });
896
+ EventsUI.onClick(`.action-btn-home`, () => s(`.main-btn-home`).click());
897
+ EventsUI.onClick(`.action-btn-app-icon`, () => s(`.action-btn-home`).click());
898
+ Keyboard.instanceMultiPressKey({
899
+ id: 'input-shortcut-global-escape',
900
+ keys: ['Escape'],
901
+ eventCallBack: () => {
902
+ // if (s(`.main-btn-home`)) s(`.main-btn-home`).click();
903
+
904
+ if (s(`.btn-close-${this.currentTopModalId}`)) s(`.btn-close-${this.currentTopModalId}`).click();
905
+ },
906
+ });
907
+ }
908
+
909
+ {
910
+ ThemeEvents['action-btn-theme'] = () => {
911
+ htmls(
912
+ `.action-btn-theme-render`,
913
+ html` ${darkTheme ? html` <i class="fas fa-moon"></i>` : html`<i class="far fa-sun"></i>`}`,
914
+ );
915
+ };
916
+ ThemeEvents['action-btn-theme']();
917
+
918
+ EventsUI.onClick(`.action-btn-theme`, async () => {
919
+ const themePair = ThemesScope.find((t) => t.theme === Css.currentTheme).themePair;
920
+ const theme = themePair ? themePair : ThemesScope.find((t) => t.dark === !darkTheme).theme;
921
+ if (s(`.dropdown-option-${theme}`))
922
+ DropDown.Tokens['settings-theme'].onClickEvents[`dropdown-option-${theme}`]();
923
+ else await Themes[theme]();
924
+ });
925
+ if (!(ThemesScope.find((t) => t.dark) && ThemesScope.find((t) => !t.dark))) {
926
+ s(`.action-btn-theme`).classList.add('hide');
927
+ }
928
+ }
929
+
930
+ {
931
+ htmls(`.action-btn-lang-render`, html` ${s('html').lang}`);
932
+ EventsUI.onClick(`.action-btn-lang`, () => {
933
+ let lang = 'en';
934
+ if (s('html').lang === 'en') lang = 'es';
935
+ if (s(`.dropdown-option-${lang}`))
936
+ DropDown.Tokens['settings-lang'].onClickEvents[`dropdown-option-${lang}`]();
937
+ else Translate.renderLang(lang);
938
+ });
939
+ }
940
+
941
+ {
942
+ const { barConfig } = await Themes[Css.currentTheme]();
943
+ barConfig.buttons.maximize.disabled = true;
944
+ barConfig.buttons.minimize.disabled = true;
945
+ barConfig.buttons.restore.disabled = true;
946
+ barConfig.buttons.menu.disabled = true;
947
+ barConfig.buttons.close.disabled = true;
948
+ const id = 'main-body-top';
949
+ await Modal.Render({
950
+ id,
951
+ barConfig,
952
+ html: () => html``,
953
+ titleClass: 'hide',
954
+ class: 'hide',
955
+ style: {
956
+ // overflow: 'hidden',
957
+ background: 'none',
958
+ resize: 'none',
959
+ 'min-width': `${minWidth}px`,
960
+ 'z-index': 5,
961
+ background: `rgba(61, 61, 61, 0.5)`,
962
+ // border: '3px solid red',
963
+ },
964
+ dragDisabled: true,
965
+ maximize: true,
966
+ heightTopBar: originHeightTopBar,
967
+ heightBottomBar: originHeightBottomBar,
968
+ barMode: options.barMode,
969
+ });
970
+
971
+ Responsive.Event[`view-${id}`] = () => {
972
+ if (!this.Data[id] || !s(`.${id}`)) return delete Responsive.Event[`view-${id}`];
973
+ s(`.${id}`).style.height = `${
974
+ window.innerHeight -
975
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
976
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
977
+ }px`;
978
+ };
979
+ Responsive.Event[`view-${id}`]();
980
+
981
+ s(`.main-body-top`).onclick = () => s(`.btn-close-modal-menu`).click();
982
+ }
983
+
984
+ await NotificationManager.RenderBoard(options);
985
+ });
986
+ })();
987
+ break;
988
+
989
+ case 'dropNotification':
990
+ (() => {
991
+ setTimeout(() => {
992
+ s(`.${idModal}`).style.top = 'auto';
993
+ s(`.${idModal}`).style.left = 'auto';
994
+ s(`.${idModal}`).style.height = 'auto';
995
+ s(`.${idModal}`).style.position = 'absolute';
996
+ let countDrop = 0;
997
+ Object.keys(this.Data)
998
+ .reverse()
999
+ .map((_idModal) => {
1000
+ if (this.Data[_idModal][options.mode]) {
1001
+ s(`.${_idModal}`).style.bottom = `${countDrop * s(`.${_idModal}`).clientHeight * 1.05}px`;
1002
+ countDrop++;
1003
+ }
1004
+ });
1005
+ });
1006
+ })();
1007
+ break;
1008
+
1009
+ default:
1010
+ break;
1011
+ }
1012
+ }
1013
+ if (options.zIndexSync) this.zIndexSync({ idModal });
1014
+ if (s(`.${idModal}`)) {
1015
+ s(`.btn-maximize-${idModal}`).click();
1016
+ return;
1017
+ }
1018
+ if (options.slideMenu) {
1019
+ if (options.titleClass) options.titleClass = ' title-view-modal ' + options.titleClass;
1020
+ options.titleClass = ' title-view-modal ';
1021
+ }
1022
+
1023
+ const render = html` <style class="style-${idModal}">
1024
+ .${idModal} {
1025
+ width: ${width}px;
1026
+ height: ${height}px;
1027
+ top: ${top};
1028
+ left: ${left};
1029
+ overflow: auto; /* resizable required */
1030
+ resize: auto; /* resizable required */
1031
+ transition: ${transition};
1032
+ opacity: 0;
1033
+ z-index: 1;
1034
+ }
1035
+ .bar-default-modal-${idModal} {
1036
+ top: 0px;
1037
+ left: 0px;
1038
+ z-index: 3;
1039
+ }
1040
+
1041
+ .modal-html-${idModal} {
1042
+ }
1043
+
1044
+ .btn-modal-default-${idModal} {
1045
+ }
1046
+ .modal-handle-${idModal} {
1047
+ width: 90%;
1048
+ height: 90%;
1049
+ top: 5%;
1050
+ left: 5%;
1051
+ }
1052
+ </style>
1053
+ ${renderStyleTag(`style-${idModal}`, `.${idModal}`, options)}
1054
+ <div class="fix ${options && options.class ? options.class : ''} modal box-shadow ${idModal}">
1055
+ <div class="abs modal-handle-${idModal}"></div>
1056
+ <div class="in modal-html-${idModal}">
1057
+ <div class="stq bar-default-modal bar-default-modal-${idModal}">
1058
+ <div
1059
+ class="fl btn-bar-modal-container btn-bar-modal-container-${idModal} ${options?.btnBarModalClass
1060
+ ? options.btnBarModalClass
1061
+ : ''}"
1062
+ >
1063
+ <div class="btn-bar-modal-container-render-${idModal}"></div>
1064
+ <div class="in flr bar-default-modal" style="z-index: 1">
1065
+ ${await BtnIcon.Render({
1066
+ class: `btn-minimize-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1067
+ options?.btnContainerClass ? options.btnContainerClass : ''
1068
+ } ${options?.barConfig?.buttons?.minimize?.disabled ? 'hide' : ''}`,
1069
+ label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1070
+ ${options?.barConfig?.buttons?.minimize?.label ? options.barConfig.buttons.minimize.label : html`_`}
1071
+ </div>`,
1072
+ })}
1073
+ ${await BtnIcon.Render({
1074
+ class: `btn-restore-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1075
+ options?.btnContainerClass ? options.btnContainerClass : ''
1076
+ } ${options?.barConfig?.buttons?.restore?.disabled ? 'hide' : ''}`,
1077
+ label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1078
+ ${options?.barConfig?.buttons?.restore?.label ? options.barConfig.buttons.restore.label : html`□`}
1079
+ </div>`,
1080
+ style: 'display: none',
1081
+ })}
1082
+ ${await BtnIcon.Render({
1083
+ class: `btn-maximize-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1084
+ options?.btnContainerClass ? options.btnContainerClass : ''
1085
+ } ${options?.barConfig?.buttons?.maximize?.disabled ? 'hide' : ''}`,
1086
+ label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1087
+ ${options?.barConfig?.buttons?.maximize?.label ? options.barConfig.buttons.maximize.label : html`▢`}
1088
+ </div>`,
1089
+ })}
1090
+ ${await BtnIcon.Render({
1091
+ class: `btn-close-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1092
+ options?.btnContainerClass ? options.btnContainerClass : ''
1093
+ } ${options?.barConfig?.buttons?.close?.disabled ? 'hide' : ''}`,
1094
+ label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1095
+ ${options?.barConfig?.buttons?.close?.label ? options.barConfig.buttons.close.label : html`X`}
1096
+ </div>`,
1097
+ })}
1098
+ ${await BtnIcon.Render({
1099
+ class: `btn-menu-${idModal} btn-modal-default btn-modal-default-${idModal} ${
1100
+ options?.btnContainerClass ? options.btnContainerClass : ''
1101
+ } ${options?.barConfig?.buttons?.menu?.disabled ? 'hide' : ''}`,
1102
+ label: html`<div class="${options?.btnIconContainerClass ? options.btnIconContainerClass : ''}">
1103
+ ${options?.barConfig?.buttons?.menu?.label ? options.barConfig.buttons.menu.label : html`≡`}
1104
+ </div>`,
1105
+ })}
1106
+ </div>
1107
+ </div>
1108
+ ${options && options.status
1109
+ ? html` <div class="abs modal-icon-container">${renderStatus(options.status)}</div> `
1110
+ : ''}
1111
+ <div
1112
+ class="inl title-modal-${idModal} ${options && options.titleClass ? options.titleClass : 'title-modal'}"
1113
+ >
1114
+ ${options && options.titleRender ? options.titleRender() : options.title ? options.title : ''}
1115
+ </div>
1116
+ </div>
1117
+
1118
+ <div class="in html-${idModal}">
1119
+ ${options.mode && options.mode.match('slide-menu')
1120
+ ? html`<div class="in" style="${renderCssAttr({ style: { height: '50px' } })}">
1121
+ ${await BtnIcon.Render({
1122
+ style: renderCssAttr({ style: { height: '100%', color: '#5f5f5f' } }),
1123
+ class: `in flr main-btn-menu action-bar-box btn-icon-menu-mode`,
1124
+ label: html` <div class="abs center">
1125
+ <i
1126
+ class="fas fa-caret-right btn-icon-menu-mode-right ${options.mode && options.mode.match('right')
1127
+ ? ''
1128
+ : 'hide'}"
1129
+ ></i
1130
+ ><i
1131
+ class="fas fa-caret-left btn-icon-menu-mode-left ${options.mode && options.mode.match('right')
1132
+ ? 'hide'
1133
+ : ''}"
1134
+ ></i>
1135
+ </div>`,
1136
+ })}
1137
+ </div>`
1138
+ : ''}
1139
+ ${options && options.html ? (typeof options.html === 'function' ? await options.html() : options.html) : ''}
1140
+ </div>
1141
+ </div>
1142
+ </div>`;
1143
+ const selector = options && options.selector ? options.selector : 'body';
1144
+ if (options) {
1145
+ switch (options.renderType) {
1146
+ case 'prepend':
1147
+ prepend(selector, render);
1148
+ break;
1149
+ default:
1150
+ append(selector, render);
1151
+ break;
1152
+ }
1153
+ } else append(selector, render);
1154
+ let handle = [s(`.bar-default-modal-${idModal}`), s(`.modal-handle-${idModal}`), s(`.modal-html-${idModal}`)];
1155
+ if (options && 'handleType' in options) {
1156
+ switch (options.handleType) {
1157
+ case 'bar':
1158
+ handle = [s(`.bar-default-modal-${idModal}`)];
1159
+
1160
+ break;
1161
+
1162
+ default:
1163
+ break;
1164
+ }
1165
+ }
1166
+ switch (options.mode) {
1167
+ case 'slide-menu':
1168
+ case 'slide-menu-right':
1169
+ case 'slide-menu-left':
1170
+ s(`.main-btn-home`).onclick = () => {
1171
+ for (const keyModal of Object.keys(this.Data)) {
1172
+ if (
1173
+ ![idModal, 'main-body-top', 'main-body']
1174
+ .concat(options?.homeModals ? options.homeModals : [])
1175
+ .includes(keyModal)
1176
+ )
1177
+ s(`.btn-close-${keyModal}`).click();
1178
+ }
1179
+ s(`.btn-close-modal-menu`).click();
1180
+ };
1181
+ EventsUI.onClick(`.btn-icon-menu-mode`, () => {
1182
+ if (s(`.btn-icon-menu-mode-right`).classList.contains('hide')) {
1183
+ s(`.btn-icon-menu-mode-right`).classList.remove('hide');
1184
+ s(`.btn-icon-menu-mode-left`).classList.add('hide');
1185
+ } else {
1186
+ s(`.btn-icon-menu-mode-left`).classList.remove('hide');
1187
+ s(`.btn-icon-menu-mode-right`).classList.add('hide');
1188
+ }
1189
+ if (slideMenuWidth === originSlideMenuWidth) {
1190
+ slideMenuWidth = collapseSlideMenuWidth;
1191
+ if (!s(`.btn-bar-center-icon-close`).classList.contains('hide')) {
1192
+ sa(`.handle-btn-container`).forEach((el) => el.classList.add('hide'));
1193
+ sa(`.menu-label-text`).forEach((el) => el.classList.add('hide'));
1194
+ if (!Modal.mobileModal()) {
1195
+ sa(`.tooltip-menu`).forEach((el) => el.classList.remove('hide'));
1196
+ s(`.${idModal}`).style.overflow = 'visible';
1197
+ }
1198
+ }
1199
+ if (options.onCollapseMenu) options.onCollapseMenu();
1200
+ } else {
1201
+ slideMenuWidth = originSlideMenuWidth;
1202
+ sa(`.handle-btn-container`).forEach((el) => el.classList.remove('hide'));
1203
+ sa(`.menu-label-text`).forEach((el) => el.classList.remove('hide'));
1204
+ if (!Modal.mobileModal()) {
1205
+ sa(`.tooltip-menu`).forEach((el) => el.classList.add('hide'));
1206
+ s(`.${idModal}`).style.overflow = null;
1207
+ }
1208
+
1209
+ if (options.onExtendMenu) options.onExtendMenu();
1210
+ }
1211
+ // btn-bar-center-icon-menu
1212
+ this.actionBtnCenter();
1213
+ this.actionBtnCenter();
1214
+ });
1215
+
1216
+ break;
1217
+
1218
+ default:
1219
+ break;
1220
+ }
1221
+ let dragOptions = {
1222
+ // disabled: true,
1223
+ handle,
1224
+ onDragStart: (data) => {
1225
+ if (!s(`.${idModal}`)) return;
1226
+ // logger.info('Dragging started', data);
1227
+ s(`.${idModal}`).style.transition = null;
1228
+ },
1229
+ onDrag: (data) => {
1230
+ if (!s(`.${idModal}`)) return;
1231
+ // logger.info('Dragging', data);
1232
+ },
1233
+ onDragEnd: (data) => {
1234
+ if (!s(`.${idModal}`)) return;
1235
+ // logger.info('Dragging stopped', data);
1236
+ s(`.${idModal}`).style.transition = transition;
1237
+ Object.keys(this.Data[idModal].onDragEndListener).map((keyListener) =>
1238
+ this.Data[idModal].onDragEndListener[keyListener](),
1239
+ );
1240
+ },
1241
+ };
1242
+ let dragInstance;
1243
+ // new Draggable(s(`.${idModal}`), { disabled: true });
1244
+ const setDragInstance = () => (options?.dragDisabled ? null : new Draggable(s(`.${idModal}`), dragOptions));
1245
+ this.Data[idModal].setDragInstance = (updateDragOptions) => {
1246
+ dragOptions = {
1247
+ ...dragOptions,
1248
+ ...updateDragOptions,
1249
+ };
1250
+ dragInstance = setDragInstance();
1251
+ this.Data[idModal].dragInstance = dragInstance;
1252
+ this.Data[idModal].dragOptions = dragOptions;
1253
+ };
1254
+ s(`.${idModal}`).style.transition = '0.15s';
1255
+ setTimeout(() => (s(`.${idModal}`).style.opacity = '1'));
1256
+ setTimeout(() => (s(`.${idModal}`).style.transition = transition), 150);
1257
+
1258
+ const btnCloseEvent = () => {
1259
+ Object.keys(this.Data[idModal].onCloseListener).map((keyListener) =>
1260
+ this.Data[idModal].onCloseListener[keyListener](),
1261
+ );
1262
+ if (options && 'barConfig' in options && options.barConfig.buttons.close.onClick)
1263
+ return options.barConfig.buttons.close.onClick();
1264
+ s(`.${idModal}`).style.opacity = '0';
1265
+ if (this.Data[idModal].observer) {
1266
+ this.Data[idModal].observer.disconnect();
1267
+ // this.Data[idModal].observer.unobserve();
1268
+ }
1269
+ setTimeout(() => {
1270
+ if (!s(`.${idModal}`)) return;
1271
+ this.removeModal(idModal);
1272
+ // Router
1273
+ if (options.route)
1274
+ (() => {
1275
+ let path = window.location.pathname;
1276
+ if (path[path.length - 1] !== '/') path = `${path}/`;
1277
+ let newPath = `${getProxyPath()}`;
1278
+ if (path !== newPath) {
1279
+ for (const subIdModal of Object.keys(this.Data).reverse()) {
1280
+ if (this.Data[subIdModal].options.route) {
1281
+ newPath = `${newPath}${this.Data[subIdModal].options.route}`;
1282
+ // console.warn('SET MODAL URI', newPath);
1283
+ setPath(newPath);
1284
+ this.setTopModalCallback(subIdModal);
1285
+ return setDocTitle({ ...options.RouterInstance, route: this.Data[subIdModal].options.route });
1286
+ }
1287
+ }
1288
+ // console.warn('SET MODAL URI', newPath);
1289
+ setPath(`${newPath}${Modal.homeCid ? `?cid=${Modal.homeCid}` : ''}`);
1290
+ return setDocTitle({ ...options.RouterInstance, route: '' });
1291
+ }
1292
+ })();
1293
+ }, 300);
1294
+ };
1295
+ s(`.btn-close-${idModal}`).onclick = btnCloseEvent;
1296
+
1297
+ s(`.btn-minimize-${idModal}`).onclick = () => {
1298
+ if (options.slideMenu) delete this.Data[idModal].slideMenu;
1299
+ s(`.${idModal}`).style.transition = '0.3s';
1300
+ s(`.btn-minimize-${idModal}`).style.display = 'none';
1301
+ s(`.btn-maximize-${idModal}`).style.display = null;
1302
+ s(`.btn-restore-${idModal}`).style.display = null;
1303
+ s(`.${idModal}`).style.height = `${s(`.bar-default-modal-${idModal}`).clientHeight}px`;
1304
+ setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1305
+ };
1306
+ s(`.btn-restore-${idModal}`).onclick = () => {
1307
+ if (options.slideMenu) delete this.Data[idModal].slideMenu;
1308
+ s(`.${idModal}`).style.transition = '0.3s';
1309
+ s(`.btn-restore-${idModal}`).style.display = 'none';
1310
+ s(`.btn-minimize-${idModal}`).style.display = null;
1311
+ s(`.btn-maximize-${idModal}`).style.display = null;
1312
+ s(`.${idModal}`).style.transform = null;
1313
+ s(`.${idModal}`).style.height = null;
1314
+ s(`.${idModal}`).style.width = null;
1315
+ setCenterRestore();
1316
+ s(`.${idModal}`).style.top = top;
1317
+ s(`.${idModal}`).style.left = left;
1318
+ dragInstance = setDragInstance();
1319
+ setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1320
+ };
1321
+ s(`.btn-maximize-${idModal}`).onclick = () => {
1322
+ s(`.${idModal}`).style.transition = '0.3s';
1323
+ setTimeout(() => (s(`.${idModal}`).style.transition = transition), 300);
1324
+ s(`.btn-maximize-${idModal}`).style.display = 'none';
1325
+ s(`.btn-restore-${idModal}`).style.display = null;
1326
+ s(`.btn-minimize-${idModal}`).style.display = null;
1327
+ s(`.${idModal}`).style.transform = null;
1328
+
1329
+ if (options.slideMenu) {
1330
+ const idSlide = this.Data[options.slideMenu]['slide-menu']
1331
+ ? 'slide-menu'
1332
+ : this.Data[options.slideMenu]['slide-menu-right']
1333
+ ? 'slide-menu-right'
1334
+ : 'slide-menu-left';
1335
+ const callBack = () => {
1336
+ s(`.${idModal}`).style.transition = '0.3s';
1337
+ s(`.${idModal}`).style.width = `${window.innerWidth - this.Data[options.slideMenu][idSlide].width}px`;
1338
+ s(`.${idModal}`).style.left =
1339
+ idSlide === 'slide-menu-right' ? `0px` : `${this.Data[options.slideMenu][idSlide].width}px`;
1340
+ setTimeout(() => (s(`.${idModal}`) ? (s(`.${idModal}`).style.transition = transition) : null), 300);
1341
+ };
1342
+
1343
+ callBack();
1344
+ this.Data[idModal].slideMenu = {
1345
+ callBack,
1346
+ id: options.slideMenu,
1347
+ };
1348
+ s(`.${idModal}`).style.height = `${
1349
+ window.innerHeight -
1350
+ (options.heightTopBar ? options.heightTopBar : heightDefaultTopBar) -
1351
+ (options.heightBottomBar ? options.heightBottomBar : heightDefaultBottomBar)
1352
+ }px`;
1353
+ s(`.${idModal}`).style.top = `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`;
1354
+ } else {
1355
+ s(`.${idModal}`).style.width = '100%';
1356
+ s(`.${idModal}`).style.height = '100%';
1357
+ s(`.${idModal}`).style.top = `${options.heightTopBar ? options.heightTopBar : heightDefaultTopBar}px`;
1358
+ s(`.${idModal}`).style.left = `0px`;
1359
+ }
1360
+ dragInstance = setDragInstance();
1361
+ };
1362
+
1363
+ const btnMenuEvent = () => {
1364
+ Object.keys(this.Data[idModal].onMenuListener).map((keyListener) =>
1365
+ this.Data[idModal].onMenuListener[keyListener](),
1366
+ );
1367
+ if (options && 'barConfig' in options && options.barConfig.buttons.menu.onClick)
1368
+ return options.barConfig.buttons.menu.onClick();
1369
+ };
1370
+ s(`.btn-menu-${idModal}`).onclick = btnMenuEvent;
1371
+
1372
+ dragInstance = setDragInstance();
1373
+ if (options && options.maximize) s(`.btn-maximize-${idModal}`).click();
1374
+ if (options.observer) {
1375
+ this.Data[idModal].onObserverListener = {};
1376
+ this.Data[idModal].observerCallBack = () => {
1377
+ // logger.info('ResizeObserver', `.${idModal}`, s(`.${idModal}`).offsetWidth, s(`.${idModal}`).offsetHeight);
1378
+ if (this.Data[idModal] && this.Data[idModal].onObserverListener)
1379
+ Object.keys(this.Data[idModal].onObserverListener).map((eventKey) =>
1380
+ this.Data[idModal].onObserverListener[eventKey]({
1381
+ width: s(`.${idModal}`).offsetWidth,
1382
+ height: s(`.${idModal}`).offsetHeight,
1383
+ }),
1384
+ );
1385
+ else console.warn('observer not found', idModal);
1386
+ };
1387
+ this.Data[idModal].observer = new ResizeObserver(this.Data[idModal].observerCallBack);
1388
+ this.Data[idModal].observer.observe(s(`.${idModal}`));
1389
+ setTimeout(this.Data[idModal].observerCallBack);
1390
+ }
1391
+ // cancel: [cancel1, cancel2]
1392
+ s(`.${idModal}`).onclick = () => {
1393
+ this.Data[idModal]?.onClickListener
1394
+ ? Object.keys(this.Data[idModal].onClickListener).map((keyListener) =>
1395
+ this.Data[idModal].onClickListener[keyListener](),
1396
+ )
1397
+ : null;
1398
+ };
1399
+ return {
1400
+ id: idModal,
1401
+ ...this.Data[idModal],
1402
+ };
1403
+ },
1404
+ currentTopModalId: '',
1405
+ zIndexSync: function ({ idModal }) {
1406
+ setTimeout(() => {
1407
+ const cleanTopModal = () => {
1408
+ Object.keys(this.Data).map((_idModal) => {
1409
+ if (this.Data[_idModal].options.zIndexSync && s(`.${_idModal}`)) s(`.${_idModal}`).style.zIndex = '3';
1410
+ });
1411
+ };
1412
+ const setTopModal = () => {
1413
+ if (s(`.${idModal}`)) {
1414
+ this.setTopModalCallback(idModal);
1415
+ } else setTimeout(setTopModal, 100);
1416
+ };
1417
+ cleanTopModal();
1418
+ setTopModal();
1419
+ this.Data[idModal].onClickListener[`${idModal}-z-index`] = () => {
1420
+ if (s(`.${idModal}`) && s(`.${idModal}`).style.zIndex === '3') {
1421
+ if (this.Data[idModal].options.route) setPath(`${getProxyPath()}${this.Data[idModal].options.route}`);
1422
+ cleanTopModal();
1423
+ setTopModal();
1424
+ }
1425
+ };
1426
+ });
1427
+ },
1428
+ setTopModalCallback: function (idModal) {
1429
+ s(`.${idModal}`).style.zIndex = '4';
1430
+ this.currentTopModalId = `${idModal}`;
1431
+ if (
1432
+ this.Data[idModal].query &&
1433
+ `${location.pathname}${window.location.search}` !== `${location.pathname}${this.Data[idModal].query}`
1434
+ )
1435
+ setPath(`${location.pathname}${this.Data[idModal].query}`);
1436
+ },
1437
+ mobileModal: () => window.innerWidth < 600 || window.innerHeight < 600,
1438
+ writeHTML: ({ idModal, html }) => htmls(`.html-${idModal}`, html),
1439
+ viewModalOpen: function () {
1440
+ return Object.keys(this.Data).find((idModal) => s(`.${idModal}`) && this.Data[idModal].options.mode === 'view');
1441
+ },
1442
+ removeModal: function (idModal) {
1443
+ if (!s(`.${idModal}`)) return;
1444
+ s(`.${idModal}`).remove();
1445
+ sa(`.style-${idModal}`).forEach((element) => {
1446
+ element.remove();
1447
+ });
1448
+ delete this.Data[idModal];
1449
+ },
1450
+ RenderConfirm: async function (options) {
1451
+ const { id } = options;
1452
+ append(
1453
+ 'body',
1454
+ html`
1455
+ <div
1456
+ class="fix background-confirm-modal-${id}"
1457
+ style="${renderCssAttr({
1458
+ style: {
1459
+ 'z-index': '10',
1460
+ background: 'rgba(0,0,0,0.5)',
1461
+ width: '100%',
1462
+ height: '100%',
1463
+ top: '0px',
1464
+ left: '0px',
1465
+ transition: '0.3s',
1466
+ opacity: '1',
1467
+ },
1468
+ })}"
1469
+ ></div>
1470
+ `,
1471
+ );
1472
+ const removeBackgroundConfirmModal = () => {
1473
+ s(`.background-confirm-modal-${id}`).style.opacity = '0';
1474
+ setTimeout(() => {
1475
+ s(`.background-confirm-modal-${id}`).remove();
1476
+ });
1477
+ };
1478
+
1479
+ return new Promise(async (resolve, reject) => {
1480
+ const { barConfig } = await Themes[Css.currentTheme]();
1481
+ barConfig.buttons.maximize.disabled = true;
1482
+ barConfig.buttons.minimize.disabled = true;
1483
+ barConfig.buttons.restore.disabled = true;
1484
+ barConfig.buttons.menu.disabled = true;
1485
+ barConfig.buttons.close.disabled = false;
1486
+ const htmlRender = html`
1487
+ <br />
1488
+ <div class="in section-mp" style="font-size: 40px; text-align: center">
1489
+ <i class="fas fa-question-circle"></i>
1490
+ </div>
1491
+ ${await options.html()}
1492
+ <div class="in section-mp">
1493
+ ${await BtnIcon.Render({
1494
+ class: `in section-mp form-button btn-confirm-${id}`,
1495
+ label: Translate.Render('confirm'),
1496
+ type: 'submit',
1497
+ style: `margin: auto`,
1498
+ })}
1499
+ </div>
1500
+ <div class="in section-mp">
1501
+ ${await BtnIcon.Render({
1502
+ class: `in section-mp form-button btn-cancel-${id}`,
1503
+ label: Translate.Render('cancel'),
1504
+ type: 'submit',
1505
+ style: `margin: auto`,
1506
+ })}
1507
+ </div>
1508
+ `;
1509
+ await Modal.Render({
1510
+ id,
1511
+ barConfig,
1512
+ titleClass: 'hide',
1513
+ style: {
1514
+ width: '300px',
1515
+ height: '350px',
1516
+ overflow: 'hidden',
1517
+ 'z-index': '11',
1518
+ resize: 'none',
1519
+ },
1520
+ dragDisabled: true,
1521
+ ...options,
1522
+ html: htmlRender,
1523
+ });
1524
+
1525
+ const end = () => {
1526
+ removeBackgroundConfirmModal();
1527
+ Modal.removeModal(id);
1528
+ };
1529
+ barConfig.buttons.close.onClick = () => {
1530
+ end();
1531
+ resolve({ status: 'cancelled' });
1532
+ };
1533
+ s(`.background-confirm-modal-${id}`).onclick = () => {
1534
+ end();
1535
+ resolve({ status: 'cancelled' });
1536
+ };
1537
+ s(`.btn-cancel-${id}`).onclick = () => {
1538
+ end();
1539
+ resolve({ status: 'cancelled' });
1540
+ };
1541
+ s(`.btn-confirm-${id}`).onclick = () => {
1542
+ end();
1543
+ resolve({ status: 'confirm' });
1544
+ };
1545
+ });
1546
+ },
1547
+ headerTitleHeight: 40,
1548
+ actionBtnCenter: function () {
1549
+ // if (!s(`.btn-close-modal-menu`).classList.contains('hide')) return s(`.main-btn-home`).click();
1550
+ if (!s(`.btn-close-modal-menu`).classList.contains('hide')) return s(`.btn-close-modal-menu`).click();
1551
+ if (!s(`.btn-menu-modal-menu`).classList.contains('hide')) return s(`.btn-menu-modal-menu`).click();
1552
+ },
1553
+ cleanUI: function () {
1554
+ s(`.top-bar`).classList.add('hide');
1555
+ s(`.bottom-bar`).classList.add('hide');
1556
+ s(`.modal-menu`).classList.add('hide');
1557
+ },
1558
+ restoreUI: function () {
1559
+ s(`.top-bar`).classList.remove('hide');
1560
+ s(`.bottom-bar`).classList.remove('hide');
1561
+ s(`.modal-menu`).classList.remove('hide');
1562
+ },
1563
+ };
1564
+
1565
+ const renderMenuLabel = ({ img, text, icon }) => {
1566
+ if (!img) return html`<span class="menu-btn-icon">${icon}</span> ${text}`;
1567
+ return html`<img class="abs center img-btn-square-menu" src="${getProxyPath()}assets/ui-icons/${img}" />
1568
+ <div class="abs center main-btn-menu-text">${text}</div>`;
1569
+ };
1570
+
1571
+ const renderViewTitle = (options = { icon: '', img: '', text: '', assetFolder: '', 'ui-icons': '', dim, top }) => {
1572
+ if (options.dim === undefined) options.dim = 60;
1573
+ const { img, text, icon, dim, top } = options;
1574
+ if (!img && !options['ui-icon']) return html`<span class="view-title-icon">${icon}</span> ${text}`;
1575
+ return html`<img
1576
+ class="abs img-btn-square-view-title"
1577
+ style="${renderCssAttr({
1578
+ style: { width: `${dim}px`, height: `${dim}px`, top: top !== undefined ? `${top}px` : `-${dim / 2}px` },
1579
+ })}"
1580
+ src="${options['ui-icon']
1581
+ ? `${getProxyPath()}assets/${options.assetFolder ? options.assetFolder : 'ui-icons'}/${options['ui-icon']}`
1582
+ : img}"
1583
+ />
1584
+ <div class="in text-btn-square-view-title" style="${renderCssAttr({ style: { 'padding-left': `${dim}px` } })}">
1585
+ ${text}
1586
+ </div>`;
1587
+ };
1588
+
1589
+ const buildBadgeToolTipMenuOption = (id, sideKey = 'left') => {
1590
+ const option = {
1591
+ id: `tooltip-content-main-btn-${id}`,
1592
+ text: `${Translate.Render(`${id}`)}`,
1593
+ classList: 'tooltip-menu hide',
1594
+ style: { top: `0px` },
1595
+ };
1596
+ switch (sideKey) {
1597
+ case 'left':
1598
+ option.style.left = '40px';
1599
+
1600
+ break;
1601
+
1602
+ case 'right':
1603
+ option.style.right = '80px';
1604
+ break;
1605
+
1606
+ default:
1607
+ break;
1608
+ }
1609
+ return option;
1610
+ };
1611
+
1612
+ export { Modal, renderMenuLabel, renderViewTitle, buildBadgeToolTipMenuOption };