lupine.api 1.0.41

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/admin/admin-about.tsx +16 -0
  4. package/admin/admin-config.tsx +44 -0
  5. package/admin/admin-css.tsx +3 -0
  6. package/admin/admin-db.tsx +74 -0
  7. package/admin/admin-frame-props.tsx +9 -0
  8. package/admin/admin-frame.tsx +466 -0
  9. package/admin/admin-index.tsx +66 -0
  10. package/admin/admin-login.tsx +99 -0
  11. package/admin/admin-menu-edit.tsx +637 -0
  12. package/admin/admin-menu-list.tsx +87 -0
  13. package/admin/admin-page-edit.tsx +564 -0
  14. package/admin/admin-page-list.tsx +83 -0
  15. package/admin/admin-performance.tsx +28 -0
  16. package/admin/admin-release.tsx +320 -0
  17. package/admin/admin-resources.tsx +385 -0
  18. package/admin/admin-shell.tsx +89 -0
  19. package/admin/admin-table-data.tsx +146 -0
  20. package/admin/admin-table-list.tsx +231 -0
  21. package/admin/admin-test-animations.tsx +379 -0
  22. package/admin/admin-test-component.tsx +808 -0
  23. package/admin/admin-test-edit.tsx +319 -0
  24. package/admin/admin-test-themes.tsx +56 -0
  25. package/admin/admin-tokens.tsx +338 -0
  26. package/admin/design/admin-design.tsx +174 -0
  27. package/admin/design/block-grid.tsx +36 -0
  28. package/admin/design/block-grid1.tsx +21 -0
  29. package/admin/design/block-paragraph.tsx +19 -0
  30. package/admin/design/block-title.tsx +19 -0
  31. package/admin/design/design-block-box.tsx +140 -0
  32. package/admin/design/drag-data.tsx +24 -0
  33. package/admin/index.ts +6 -0
  34. package/admin/package.json +15 -0
  35. package/admin/tsconfig.json +127 -0
  36. package/dev/copy-folder.js +32 -0
  37. package/dev/cp-index-html.js +69 -0
  38. package/dev/file-utils.js +12 -0
  39. package/dev/index.js +19 -0
  40. package/dev/package.json +12 -0
  41. package/dev/plugin-gen-versions.js +20 -0
  42. package/dev/plugin-ifelse.js +155 -0
  43. package/dev/plugin-ifelse.test.js +37 -0
  44. package/dev/run-cmd.js +14 -0
  45. package/dev/send-request.js +12 -0
  46. package/package.json +55 -0
  47. package/src/admin-api/admin-api.ts +59 -0
  48. package/src/admin-api/admin-auth.ts +87 -0
  49. package/src/admin-api/admin-config.ts +93 -0
  50. package/src/admin-api/admin-csv.ts +81 -0
  51. package/src/admin-api/admin-db.ts +269 -0
  52. package/src/admin-api/admin-helper.ts +111 -0
  53. package/src/admin-api/admin-menu.ts +135 -0
  54. package/src/admin-api/admin-page.ts +135 -0
  55. package/src/admin-api/admin-performance.ts +128 -0
  56. package/src/admin-api/admin-release.ts +498 -0
  57. package/src/admin-api/admin-resources.ts +318 -0
  58. package/src/admin-api/admin-token-helper.ts +79 -0
  59. package/src/admin-api/admin-tokens.ts +90 -0
  60. package/src/admin-api/index.ts +2 -0
  61. package/src/api/api-cache.ts +103 -0
  62. package/src/api/api-helper.ts +44 -0
  63. package/src/api/api-module.ts +60 -0
  64. package/src/api/api-router.ts +177 -0
  65. package/src/api/api-shared-storage.ts +64 -0
  66. package/src/api/async-storage.ts +5 -0
  67. package/src/api/debug-service.ts +56 -0
  68. package/src/api/encode-html.ts +27 -0
  69. package/src/api/handle-status.ts +71 -0
  70. package/src/api/index.ts +16 -0
  71. package/src/api/mini-web-socket.ts +270 -0
  72. package/src/api/server-content-type.ts +82 -0
  73. package/src/api/server-render.ts +216 -0
  74. package/src/api/shell-service.ts +66 -0
  75. package/src/api/simple-storage.ts +80 -0
  76. package/src/api/static-server.ts +125 -0
  77. package/src/api/to-client-delivery.ts +26 -0
  78. package/src/app/app-cache.ts +55 -0
  79. package/src/app/app-loader.ts +62 -0
  80. package/src/app/app-message.ts +60 -0
  81. package/src/app/app-shared-storage.ts +317 -0
  82. package/src/app/app-start.ts +117 -0
  83. package/src/app/cleanup-exit.ts +12 -0
  84. package/src/app/host-to-path.ts +38 -0
  85. package/src/app/index.ts +11 -0
  86. package/src/app/process-dev-requests.ts +90 -0
  87. package/src/app/web-listener.ts +230 -0
  88. package/src/app/web-processor.ts +42 -0
  89. package/src/app/web-server.ts +86 -0
  90. package/src/common-js/web-env.js +104 -0
  91. package/src/index.ts +7 -0
  92. package/src/lang/api-lang-en.ts +27 -0
  93. package/src/lang/api-lang-zh-cn.ts +28 -0
  94. package/src/lang/index.ts +2 -0
  95. package/src/lang/lang-helper.ts +76 -0
  96. package/src/lang/lang-props.ts +6 -0
  97. package/src/lib/db/db-helper.ts +23 -0
  98. package/src/lib/db/db-mysql.ts +250 -0
  99. package/src/lib/db/db-sqlite.ts +101 -0
  100. package/src/lib/db/db.spec.ts +28 -0
  101. package/src/lib/db/db.ts +304 -0
  102. package/src/lib/db/index.ts +5 -0
  103. package/src/lib/index.ts +3 -0
  104. package/src/lib/logger.spec.ts +214 -0
  105. package/src/lib/logger.ts +274 -0
  106. package/src/lib/runtime-require.ts +37 -0
  107. package/src/lib/utils/cookie-util.ts +34 -0
  108. package/src/lib/utils/crypto.ts +58 -0
  109. package/src/lib/utils/date-utils.ts +317 -0
  110. package/src/lib/utils/deep-merge.ts +37 -0
  111. package/src/lib/utils/delay.ts +12 -0
  112. package/src/lib/utils/file-setting.ts +55 -0
  113. package/src/lib/utils/format-bytes.ts +11 -0
  114. package/src/lib/utils/fs-utils.ts +144 -0
  115. package/src/lib/utils/get-env.ts +27 -0
  116. package/src/lib/utils/index.ts +12 -0
  117. package/src/lib/utils/is-type.ts +48 -0
  118. package/src/lib/utils/load-env.ts +14 -0
  119. package/src/lib/utils/pad.ts +6 -0
  120. package/src/models/api-base.ts +5 -0
  121. package/src/models/api-module-props.ts +11 -0
  122. package/src/models/api-router-props.ts +26 -0
  123. package/src/models/app-cache-props.ts +33 -0
  124. package/src/models/app-data-props.ts +10 -0
  125. package/src/models/app-loader-props.ts +6 -0
  126. package/src/models/app-shared-storage-props.ts +37 -0
  127. package/src/models/app-start-props.ts +18 -0
  128. package/src/models/async-storage-props.ts +13 -0
  129. package/src/models/db-config.ts +30 -0
  130. package/src/models/host-to-path-props.ts +12 -0
  131. package/src/models/index.ts +16 -0
  132. package/src/models/json-object.ts +8 -0
  133. package/src/models/locals-props.ts +36 -0
  134. package/src/models/logger-props.ts +84 -0
  135. package/src/models/simple-storage-props.ts +14 -0
  136. package/src/models/to-client-delivery-props.ts +6 -0
  137. package/tsconfig.json +115 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 uuware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # lupine.api
2
+
3
+ lupine.api is a fast, lightweight, and flexible node.js based server, working with [lupine.web](https://github.com/uuware/lupine.web) to provide SSR and modern JavaScript features for web applications and APIs.
@@ -0,0 +1,16 @@
1
+ import { CssProps } from 'lupine.components';
2
+
3
+ export const AdminAboutPage = () => {
4
+ const css: CssProps = {
5
+ };
6
+
7
+ return (
8
+ <div css={css} class='admin-about-top'>
9
+ <div class='row-box'>
10
+ About this application
11
+ </div>
12
+ <div class='row-box'>
13
+ </div>
14
+ </div>
15
+ );
16
+ };
@@ -0,0 +1,44 @@
1
+ import { CssProps, getRenderPageProps, NotificationColor, NotificationMessage, RefProps } from 'lupine.components';
2
+
3
+ export const AdminConfigPage = () => {
4
+ const css: CssProps = {
5
+ '.input-cfg': {
6
+ height: '400px',
7
+ maxHeight: '100%',
8
+ },
9
+ };
10
+ const onSave = async () => {
11
+ try {
12
+ const json = JSON.parse(ref.$('.input-cfg').value);
13
+ const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/config/save', { json });
14
+ if (data.json && data.json.status === 'ok') {
15
+ NotificationMessage.sendMessage('Saved', NotificationColor.Success);
16
+ }
17
+ } catch (e) {
18
+ NotificationMessage.sendMessage('Config is not valid JSON', NotificationColor.Error);
19
+ }
20
+ };
21
+ const ref: RefProps = {
22
+ onLoad: async () => {
23
+ const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/config/load');
24
+ if (data.json && data.json.result) {
25
+ ref.$('.input-cfg').value = JSON.stringify(data.json.result, null, 4);
26
+ ref.$('.cfg-btn').disabled = false;
27
+ } else {
28
+ NotificationMessage.sendMessage('Failed to load config', NotificationColor.Error);
29
+ }
30
+ },
31
+ };
32
+ return (
33
+ <div css={css} class='admin-cfg-top' ref={ref}>
34
+ <div class='row-box pb-m'>
35
+ <button onClick={onSave} class='button-base cfg-btn' disabled={true}>
36
+ Save
37
+ </button>
38
+ </div>
39
+ <div class='row-box'>
40
+ <textarea class='input-base input-cfg w-100p'></textarea>
41
+ </div>
42
+ </div>
43
+ );
44
+ };
@@ -0,0 +1,3 @@
1
+ import { CssProps } from 'lupine.components';
2
+
3
+ export const adminCss: CssProps = {};
@@ -0,0 +1,74 @@
1
+ import { CssProps, getRenderPageProps, RefProps } from 'lupine.components';
2
+
3
+ const fetchCreateTables = async () => {
4
+ const data = await getRenderPageProps().renderPageFunctions.fetchData(`/api/admin/db/install`);
5
+ return data.json;
6
+ };
7
+
8
+ export const CreateTablesPage = () => {
9
+ const onClick = async () => {
10
+ const json = await fetchCreateTables();
11
+ console.log('====homepage', json);
12
+ document.querySelector('.install-result')!.innerHTML = JSON.stringify(json.result, null, 4);
13
+ };
14
+
15
+ const css: CssProps = {
16
+ '.install-result': {
17
+ display: 'block',
18
+ unicodeBidi: 'embed',
19
+ fontFamily: 'monospace',
20
+ whiteSpace: 'pre',
21
+ },
22
+ };
23
+ const ref: RefProps = {};
24
+ return (
25
+ <div ref={ref} css={css}>
26
+ Create Tables:
27
+ <button onClick={onClick} class='button-base'>
28
+ Start
29
+ </button>
30
+ <div class='install-result'></div>
31
+ </div>
32
+ );
33
+ };
34
+
35
+ const fetchRunSql = async (sql: string) => {
36
+ const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/run-sql', { sql });
37
+ return data.json;
38
+ };
39
+
40
+ export const RunSqlPage = () => {
41
+ const onClick = async () => {
42
+ const json = await fetchRunSql((ref.$('.sql') as HTMLFormElement).value);
43
+ console.log('====homepage', json);
44
+ ref.$('.sql-result').innerHTML = JSON.stringify(json.result, null, 4);
45
+ };
46
+
47
+ const css: CssProps = {
48
+ 'textarea.sql': {
49
+ width: '100%',
50
+ height: '200px',
51
+ },
52
+ '.sql-result': {
53
+ display: 'block',
54
+ unicodeBidi: 'embed',
55
+ fontFamily: 'monospace',
56
+ whiteSpace: 'pre',
57
+ },
58
+ };
59
+ const ref: RefProps = {};
60
+ return (
61
+ <div ref={ref} css={css}>
62
+ <div>Run SQL:</div>
63
+ <div>
64
+ <textarea class='input-base sql'>SELECT 'Hello world'</textarea>
65
+ </div>
66
+ <div>
67
+ <button onClick={onClick} class='button-base'>
68
+ Run
69
+ </button>
70
+ </div>
71
+ <div class='sql-result'></div>
72
+ </div>
73
+ );
74
+ };
@@ -0,0 +1,9 @@
1
+ import { TabsHookProps } from 'lupine.components';
2
+
3
+ const adminFrameProps = {
4
+ maxWidthMobileMenu: '800px',
5
+ maxTabsCount: 20,
6
+ tabsHook: {} as TabsHookProps,
7
+ };
8
+
9
+ export { adminFrameProps };
@@ -0,0 +1,466 @@
1
+ import { bindGlobalStyles, CssProps, RefProps, VNode, MenuItemProps, clearCookie } from 'lupine.components';
2
+ import { NestMenuItemProps, MenuSidebar, ThemeSelector, TabsHookProps, TabsPageProps, Tabs } from 'lupine.components';
3
+ import { adminCss } from './admin-css';
4
+ import { CreateTablesPage, RunSqlPage } from './admin-db';
5
+ import { TableListPage } from './admin-table-list';
6
+ import { adminFrameProps } from './admin-frame-props';
7
+ import { AdminMenuPage } from './admin-menu-list';
8
+ import { TestThemesPage } from './admin-test-themes';
9
+ import { AdminPagePage } from './admin-page-list';
10
+ import { AdminPerformancePage } from './admin-performance';
11
+ import { AdminReleasePage } from './admin-release';
12
+ import { AdminTestAnimationsPage } from './admin-test-animations';
13
+ import { AdminTestEditPage } from './admin-test-edit';
14
+ import { AdminResourcesPage } from './admin-resources';
15
+ import { AdminTokensPage } from './admin-tokens';
16
+ import { TestComponentPage } from './admin-test-component';
17
+ import { AdminConfigPage } from './admin-config';
18
+ import { AdminAboutPage } from './admin-about';
19
+ import { AdminShellPage } from './admin-shell';
20
+
21
+ const chineseMenuText: { text: string; zh: string }[] = [
22
+ { text: 'Contents', zh: '内容管理' },
23
+ { text: 'Menu List', zh: '菜单列表' },
24
+ { text: 'Page List', zh: '页面列表' },
25
+ { text: 'Process List', zh: '流程列表' },
26
+
27
+ { text: 'DB', zh: '数据库' },
28
+ { text: 'Table List', zh: '表' },
29
+ { text: 'Create Tables', zh: '创建表' },
30
+ { text: 'Run SQL', zh: '运行 SQL' },
31
+
32
+ { text: 'Test', zh: '测试' },
33
+ { text: 'Test Themes', zh: '测试主题' },
34
+ { text: 'Test Component', zh: '测试组件' },
35
+ { text: 'Test Animations', zh: '测试动画' },
36
+ { text: 'Test Edit', zh: '测试编辑' },
37
+
38
+ { text: 'Access', zh: '管理服务器' },
39
+ { text: 'Release', zh: '发布' },
40
+ { text: 'Tokens', zh: '管理令牌' },
41
+
42
+ { text: 'Server Info', zh: '服务器信息' },
43
+ { text: 'Resources', zh: '管理资源' },
44
+ { text: 'Config', zh: '管理配置' },
45
+ { text: 'Shell', zh: '命令终端' },
46
+ { text: 'Server Info', zh: '服务器信息' },
47
+ { text: 'Performance', zh: '性能' },
48
+
49
+ { text: 'Help', zh: '帮助' },
50
+ { text: 'About', zh: '关于' },
51
+ ];
52
+ const translateMenuToChinese = (text: string) => {
53
+ const menuItem = chineseMenuText.find((item) => item.text === text);
54
+ return menuItem ? menuItem.zh : text;
55
+ };
56
+
57
+ export class AdminFrameHelper {
58
+ consoleTitle = 'Welcome to Admin Panel';
59
+ getConsoleTitle() {
60
+ return this.consoleTitle;
61
+ }
62
+ setConsoleTitle(title: string) {
63
+ this.consoleTitle = title;
64
+ }
65
+
66
+ adminTopMenu: NestMenuItemProps[] = [
67
+ // { text: 'Top', url: '/admin' },
68
+ {
69
+ id: 'contents',
70
+ text: 'Contents',
71
+ url: '',
72
+ // hide: true,
73
+ items: [
74
+ {
75
+ id: 'menu-list',
76
+ text: 'Menu List',
77
+ url: '',
78
+ // hide: true,
79
+ js: () => this.addPanel('Menu', AdminMenuPage()),
80
+ },
81
+ {
82
+ id: 'page-list',
83
+ text: 'Page List',
84
+ url: '',
85
+ js: () => this.addPanel('Page', AdminPagePage()),
86
+ },
87
+ {
88
+ id: 'process-list',
89
+ text: 'Process List',
90
+ url: '',
91
+ js: () => this.addPanel('Process', <div>new Process</div>),
92
+ },
93
+ ],
94
+ },
95
+ // { text: 'menu2', url: '/st_did.l--liangbufan.gunanguanvqingguandeng.html' },
96
+ // {
97
+ // text: 'Admin',
98
+ // url: '',
99
+ // items: [{ text: 'Users', url: '/admin/users' }],
100
+ // },
101
+ {
102
+ id: 'db',
103
+ text: 'DB',
104
+ url: '',
105
+ items: [
106
+ {
107
+ id: 'table-list',
108
+ text: 'Table List',
109
+ url: '',
110
+ js: () => this.addPanel('Table List', TableListPage()),
111
+ },
112
+ {
113
+ id: 'create-tables',
114
+ text: 'Create Tables',
115
+ url: '',
116
+ js: () => this.addPanel('Create Tables', CreateTablesPage()),
117
+ },
118
+ {
119
+ id: 'run-sql',
120
+ text: 'Run SQL',
121
+ url: '',
122
+ js: () => this.addPanel('Run SQL', RunSqlPage()),
123
+ },
124
+ ],
125
+ },
126
+ {
127
+ id: 'test',
128
+ text: 'Test',
129
+ url: '',
130
+ items: [
131
+ {
132
+ id: 'test-themes',
133
+ text: 'Test Themes',
134
+ url: '',
135
+ js: () => this.addPanel('Test Themes', TestThemesPage()),
136
+ },
137
+ {
138
+ id: 'test-component',
139
+ text: 'Test Component',
140
+ url: '',
141
+ js: () => this.addPanel('Test Component', TestComponentPage()),
142
+ },
143
+ {
144
+ id: 'test-animations',
145
+ text: 'Test Animations',
146
+ url: '',
147
+ js: () => this.addPanel('Test Animations', AdminTestAnimationsPage()),
148
+ },
149
+ {
150
+ id: 'test-edit',
151
+ text: 'Test Edit',
152
+ url: '',
153
+ js: () => this.addPanel('Test Edit', AdminTestEditPage()),
154
+ },
155
+ ],
156
+ },
157
+
158
+ {
159
+ id: 'access',
160
+ text: 'Access',
161
+ url: '',
162
+ items: [
163
+ {
164
+ id: 'release',
165
+ text: 'Release',
166
+ url: '',
167
+ js: () => this.addPanel('Release', AdminReleasePage()),
168
+ },
169
+ {
170
+ id: 'tokens',
171
+ text: 'Tokens',
172
+ url: '',
173
+ js: () => this.addPanel('Tokens', AdminTokensPage()),
174
+ },
175
+ ],
176
+ },
177
+
178
+ {
179
+ id: 'server-info',
180
+ text: 'Server Info',
181
+ url: '',
182
+ items: [
183
+ {
184
+ id: 'performance',
185
+ text: 'Performance',
186
+ url: '',
187
+ js: () => this.addPanel('Performance', AdminPerformancePage()),
188
+ },
189
+ {
190
+ id: 'resources',
191
+ text: 'Resources',
192
+ url: '',
193
+ js: () => this.addPanel('Resources', AdminResourcesPage()),
194
+ },
195
+ {
196
+ id: 'config',
197
+ text: 'Config',
198
+ url: '',
199
+ js: () => this.addPanel('Config', AdminConfigPage()),
200
+ },
201
+ {
202
+ id: 'shell',
203
+ text: 'Shell',
204
+ url: '',
205
+ js: () => this.addPanel('Shell', AdminShellPage()),
206
+ },
207
+ ],
208
+ },
209
+ {
210
+ id: 'help',
211
+ text: 'Help',
212
+ url: '',
213
+ items: [
214
+ {
215
+ id: 'about',
216
+ text: 'About',
217
+ url: '',
218
+ js: () => this.addPanel('About', AdminAboutPage()),
219
+ },
220
+ ],
221
+ },
222
+ ];
223
+
224
+ hookBeforeShowMenu?: (adminTopMenu: NestMenuItemProps[]) => NestMenuItemProps[];
225
+ // Set a hook to modify the admin top menu dynamically before it is shown
226
+ setHookBeforeShowMenu(hook: (adminTopMenu: NestMenuItemProps[]) => NestMenuItemProps[]) {
227
+ this.hookBeforeShowMenu = hook;
228
+ }
229
+ getAdminTopMenu() {
230
+ if (this.hookBeforeShowMenu) {
231
+ return this.hookBeforeShowMenu(this.adminTopMenu);
232
+ }
233
+ return this.adminTopMenu;
234
+ }
235
+ setAdminTopMenu(adminTopMenu: NestMenuItemProps[]) {
236
+ this.adminTopMenu = adminTopMenu;
237
+ }
238
+ setChineseAdminTopMenu() {
239
+ this.adminTopMenu.forEach((item) => {
240
+ item.text = translateMenuToChinese(item.text);
241
+ item.items?.forEach((subItem) => {
242
+ subItem.text = translateMenuToChinese(subItem.text);
243
+ });
244
+ });
245
+ }
246
+
247
+ mobileMenuMaxWidth = '700px';
248
+ setMobileMenuMaxWidth(maxWidth: string) {
249
+ this.mobileMenuMaxWidth = maxWidth;
250
+ }
251
+ getMobileMenuMaxWidth() {
252
+ return this.mobileMenuMaxWidth;
253
+ }
254
+
255
+ insertMenuItem(item: NestMenuItemProps[], beforeMenuId?: string) {
256
+ let index = -1;
257
+ if (beforeMenuId) {
258
+ index = this.adminTopMenu.findIndex((m) => m.id === beforeMenuId);
259
+ }
260
+ if (index !== -1) {
261
+ this.adminTopMenu.splice(index, 0, ...item);
262
+ } else {
263
+ this.adminTopMenu.push(...item);
264
+ }
265
+ }
266
+ insertSubMenuItem(item: MenuItemProps[], beforeMenuId: string, beforeSubMenuId?: string) {
267
+ const index = this.adminTopMenu.findIndex((m) => m.id === beforeMenuId);
268
+ if (index !== -1) {
269
+ const subMenu = this.adminTopMenu[index].items || [];
270
+ const subIndex = subMenu.findIndex((s) => s.id === beforeSubMenuId);
271
+ if (subIndex !== -1) {
272
+ subMenu.splice(subIndex, 0, ...item);
273
+ } else {
274
+ subMenu.push(...item);
275
+ }
276
+ // this.adminTopMenu[index].items = subMenu;
277
+ }
278
+ }
279
+ getMenuItem(menuId: string): NestMenuItemProps | null {
280
+ const index = this.adminTopMenu.findIndex((m) => m.id === menuId);
281
+ if (index !== -1) {
282
+ return this.adminTopMenu[index];
283
+ }
284
+ return null;
285
+ }
286
+ getSubMenuItem(menuId: string, subMenuId: string): MenuItemProps | null {
287
+ const index = this.adminTopMenu.findIndex((m) => m.id === menuId);
288
+ if (index !== -1) {
289
+ const subMenu = this.adminTopMenu[index].items || [];
290
+ const subIndex = subMenu.findIndex((s) => s.id === subMenuId);
291
+ if (subIndex !== -1) {
292
+ return subMenu[subIndex];
293
+ }
294
+ }
295
+ return null;
296
+ }
297
+
298
+ refUpdate = adminFrameProps.tabsHook;
299
+ async addPanel(title: string, page: VNode) {
300
+ if (adminFrameProps.tabsHook.getCount!() > adminFrameProps.maxTabsCount) {
301
+ alert('You are opening too many pages');
302
+ return;
303
+ }
304
+ if (adminFrameProps.tabsHook.findAndActivate!(title)) {
305
+ return;
306
+ }
307
+ await adminFrameProps.tabsHook.newPage!(title, page);
308
+ }
309
+ }
310
+ export const adminFrameHelper = /* @__PURE__ */ new AdminFrameHelper();
311
+
312
+ export type AdminFrameProps = {
313
+ title?: string;
314
+ css?: CssProps;
315
+ };
316
+ export const AdminFrame = (props: AdminFrameProps) => {
317
+ const refUpdate = adminFrameProps.tabsHook;
318
+ const maxWidthMobileMenu = adminFrameHelper.getMobileMenuMaxWidth();
319
+ const css: CssProps = {
320
+ backgroundColor: 'var(--primary-bg-color)',
321
+ color: 'var(--primary-color)',
322
+ ...adminCss,
323
+ display: 'flex',
324
+ flexDirection: 'column',
325
+ // padding: '10px',
326
+ width: '100%',
327
+ height: '100%',
328
+ minHeight: '100%',
329
+ overflowY: 'auto',
330
+ '.f-header': {
331
+ display: 'flex',
332
+ alignItems: 'center',
333
+ padding: '4px 16px 4px 0px',
334
+ fontSize: '80%',
335
+ },
336
+ '.top-logo': {
337
+ marginLeft: '16px',
338
+ marginRight: '16px',
339
+ },
340
+ '.top-title': {
341
+ flex: '1',
342
+ fontSize: '160%',
343
+ margin: 'auto',
344
+ },
345
+ '.top-menu': {
346
+ display: 'flex',
347
+ },
348
+ '.top-menu .item': {
349
+ padding: '0px 2px',
350
+ },
351
+ '.f-body': {
352
+ flex: '1',
353
+ display: 'flex',
354
+ borderTop: 'var(--primary-border)',
355
+ minHeight: '0',
356
+ },
357
+ '.body-menu': {
358
+ width: '165px',
359
+ // padding: '8px 16px',
360
+ borderRight: 'var(--primary-border)',
361
+ overflowY: 'auto',
362
+ color: 'var(--sidebar-color)',
363
+ backgroundColor: 'var(--sidebar-bg-color)',
364
+ },
365
+ '.close-menu-icon': {
366
+ position: 'relative',
367
+ },
368
+ '.close-menu-icon.hide + .body-menu': {
369
+ display: 'none',
370
+ },
371
+ '.close-menu-icon::after': {
372
+ content: '""',
373
+ position: 'absolute',
374
+ top: '-13px',
375
+ left: '-1px',
376
+ transform: 'rotate(90deg)',
377
+ width: '0',
378
+ height: '0',
379
+ borderLeft: '7px solid transparent',
380
+ borderRight: '7px solid transparent',
381
+ borderTop: '7px solid var(--primary-color)',
382
+ transition: 'all 300ms ease-in-out',
383
+ zIndex: 'var(--layer-sidebar)',
384
+ },
385
+ ['@media only screen and (max-width: ' + maxWidthMobileMenu + ')']: {
386
+ '.body-menu, .close-menu-icon': {
387
+ display: 'none',
388
+ },
389
+ },
390
+ '.body-content': {
391
+ flex: '1',
392
+ overflowX: 'auto',
393
+ // padding: '8px 16px',
394
+ },
395
+ ...props.css,
396
+ };
397
+ const onLogoutClick = () => {
398
+ clearCookie('_token_dev', '/');
399
+ window.location.href = '/admin';
400
+ };
401
+
402
+ bindGlobalStyles('admin-frame', '.admin-frame-box', css);
403
+
404
+ const refCloseMenu: RefProps = {};
405
+ const adminTopMenu = adminFrameHelper.getAdminTopMenu();
406
+ const onCloseMenuClick = () => {
407
+ refCloseMenu.current.classList.toggle('hide');
408
+ };
409
+ return (
410
+ <div class='admin-frame-box'>
411
+ <div class='f-header'>
412
+ <MenuSidebar
413
+ items={adminTopMenu}
414
+ maxWidthMobileMenu={maxWidthMobileMenu}
415
+ color='var(--sidebar-color)'
416
+ backgroundColor='var(--sidebar-bg-color)'
417
+ mobileMenu={true}
418
+ ></MenuSidebar>
419
+ <div class='top-logo'>Lupine.Dev</div>
420
+ <div class='top-title'>{props.title}</div>
421
+ <div class='top-menu'>
422
+ <ThemeSelector></ThemeSelector>
423
+ <button onClick={() => window.open('/')} class='button-base button-s'>
424
+ Home
425
+ </button>
426
+ <button onClick={onLogoutClick} class='button-base button-s'>
427
+ Logout
428
+ </button>
429
+ </div>
430
+ </div>
431
+ <div class='f-body'>
432
+ <div ref={refCloseMenu} class='close-menu-icon' onClick={onCloseMenuClick} title='Hide / Show Side Menu'></div>
433
+ <div class='body-menu'>
434
+ <MenuSidebar
435
+ items={adminTopMenu}
436
+ maxWidthMobileMenu={maxWidthMobileMenu}
437
+ color='var(--sidebar-color)'
438
+ backgroundColor='var(--sidebar-bg-color)'
439
+ desktopMenu={true}
440
+ ></MenuSidebar>
441
+ </div>
442
+ <div class='body-content'>
443
+ <AdminPanel refUpdate={refUpdate} title='Panel'></AdminPanel>
444
+ </div>
445
+ </div>
446
+ </div>
447
+ );
448
+ };
449
+
450
+ export type AdminPanelProps = {
451
+ title?: string;
452
+ css?: CssProps;
453
+ refUpdate: TabsHookProps;
454
+ };
455
+ export const AdminPanel = (props: AdminPanelProps) => {
456
+ const css: CssProps = {
457
+ height: '100%',
458
+ };
459
+ bindGlobalStyles('admin-panel', '.admin-panel-box', css);
460
+ const pages: TabsPageProps[] = [];
461
+ return (
462
+ <div class='admin-panel-box'>
463
+ <Tabs pages={pages} hook={props.refUpdate} pagePadding='8px'></Tabs>
464
+ </div>
465
+ );
466
+ };