miqro 6.1.2 → 6.1.4

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 (175) hide show
  1. package/build/editor.bundle.js +16 -0
  2. package/build/esm/editor/auth.d.ts +6 -0
  3. package/build/esm/editor/auth.js +41 -0
  4. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  5. package/build/esm/editor/common/admin-interface.js +44 -0
  6. package/build/esm/editor/common/constants.d.ts +4 -0
  7. package/build/esm/editor/common/constants.js +20 -0
  8. package/build/esm/editor/common/constants.server.d.ts +2 -0
  9. package/build/esm/editor/common/constants.server.js +4 -0
  10. package/build/esm/editor/common/editor-index.d.ts +2 -0
  11. package/build/esm/editor/common/editor-index.js +14 -0
  12. package/build/esm/editor/common/html-encode.d.ts +1 -0
  13. package/build/esm/editor/common/html-encode.js +14 -0
  14. package/build/esm/editor/common/log-socket.d.ts +15 -0
  15. package/build/esm/editor/common/log-socket.js +70 -0
  16. package/build/esm/editor/common/templates.d.ts +11 -0
  17. package/build/esm/editor/common/templates.js +477 -0
  18. package/build/esm/editor/components/api-preview.d.ts +11 -0
  19. package/build/esm/editor/components/api-preview.js +90 -0
  20. package/build/esm/editor/components/editor.d.ts +16 -0
  21. package/build/esm/editor/components/editor.js +357 -0
  22. package/build/esm/editor/components/file-browser.d.ts +37 -0
  23. package/build/esm/editor/components/file-browser.js +126 -0
  24. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  25. package/build/esm/editor/components/file-editor-toolbar.js +93 -0
  26. package/build/esm/editor/components/file-editor.d.ts +32 -0
  27. package/build/esm/editor/components/file-editor.js +59 -0
  28. package/build/esm/editor/components/filter-query.d.ts +1 -0
  29. package/build/esm/editor/components/filter-query.js +22 -0
  30. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  31. package/build/esm/editor/components/highlight-text-area.js +124 -0
  32. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  33. package/build/esm/editor/components/log-viewer.js +69 -0
  34. package/build/esm/editor/components/new-file.d.ts +10 -0
  35. package/build/esm/editor/components/new-file.js +117 -0
  36. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  37. package/build/esm/editor/components/scroll-query.js +21 -0
  38. package/build/esm/editor/components/start-page.d.ts +13 -0
  39. package/build/esm/editor/components/start-page.js +30 -0
  40. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +29 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +49 -0
  44. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +39 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +149 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  49. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +38 -0
  50. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  51. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  52. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  53. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +45 -0
  54. package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
  55. package/build/esm/editor/http/admin/editor/editor.js +7 -0
  56. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  57. package/build/esm/editor/http/admin/editor/index.api.js +21 -0
  58. package/build/esm/editor/server.d.ts +3 -0
  59. package/build/esm/editor/server.js +49 -0
  60. package/build/esm/editor/ws.d.ts +3 -0
  61. package/build/esm/editor/ws.js +11 -0
  62. package/build/esm/src/bin/types.js +8 -0
  63. package/build/esm/src/common/arguments.d.ts +7 -1
  64. package/build/esm/src/common/arguments.js +72 -10
  65. package/build/esm/src/common/help.d.ts +1 -1
  66. package/build/esm/src/common/help.js +33 -29
  67. package/build/esm/src/inflate/setup-ws.d.ts +1 -1
  68. package/build/esm/src/inflate/setup-ws.js +2 -2
  69. package/build/esm/src/main.js +3 -1
  70. package/build/esm/src/services/app.d.ts +2 -0
  71. package/build/esm/src/services/app.js +2 -2
  72. package/build/esm/src/services/utils/log-transport.d.ts +2 -2
  73. package/build/esm/src/services/utils/log-transport.js +8 -3
  74. package/build/esm/src/services/utils/server-interface.d.ts +1 -1
  75. package/build/esm/src/services/utils/server-interface.js +19 -14
  76. package/build/lib.cjs +23 -21
  77. package/editor/auth.ts +51 -0
  78. package/editor/common/admin-interface.ts +84 -0
  79. package/editor/common/constants.server.ts +5 -0
  80. package/editor/common/constants.ts +21 -0
  81. package/editor/common/editor-index.tsx +17 -0
  82. package/editor/common/html-encode.ts +14 -0
  83. package/editor/common/log-socket.tsx +85 -0
  84. package/editor/common/templates.ts +481 -0
  85. package/editor/components/api-preview.tsx +116 -0
  86. package/editor/components/editor.tsx +486 -0
  87. package/editor/components/file-browser.tsx +308 -0
  88. package/editor/components/file-editor-toolbar.tsx +191 -0
  89. package/editor/components/file-editor.tsx +122 -0
  90. package/editor/components/filter-query.tsx +22 -0
  91. package/editor/components/highlight-text-area.tsx +144 -0
  92. package/editor/components/log-viewer.tsx +110 -0
  93. package/editor/components/new-file.tsx +169 -0
  94. package/editor/components/scroll-query.tsx +22 -0
  95. package/editor/components/start-page.tsx +49 -0
  96. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  97. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  98. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  99. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  100. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  101. package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
  102. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  103. package/editor/http/admin/editor/editor.tsx +8 -0
  104. package/editor/http/admin/editor/index.api.tsx +39 -0
  105. package/editor/server.ts +57 -0
  106. package/editor/ws.ts +15 -0
  107. package/package.json +1 -1
  108. package/sea/install-nodejs.sh +1 -1
  109. package/sea/node.version.tag +1 -1
  110. package/src/bin/compile.ts +35 -0
  111. package/src/bin/doc-md.ts +210 -0
  112. package/src/bin/generate-doc.ts +64 -0
  113. package/src/bin/test.ts +92 -0
  114. package/src/bin/types.ts +29 -0
  115. package/src/cluster.ts +27 -0
  116. package/src/common/arguments.ts +576 -0
  117. package/src/common/assets.ts +128 -0
  118. package/src/common/checksum.ts +58 -0
  119. package/src/common/constants.ts +18 -0
  120. package/src/common/content-type.ts +84 -0
  121. package/src/common/esbuild.ts +94 -0
  122. package/src/common/exit.ts +91 -0
  123. package/src/common/fs.ts +17 -0
  124. package/src/common/help.ts +55 -0
  125. package/src/common/jsx.ts +512 -0
  126. package/src/common/paths.ts +158 -0
  127. package/src/common/watch.ts +85 -0
  128. package/src/inflate/inflate-sea.ts +206 -0
  129. package/src/inflate/inflate.ts +99 -0
  130. package/src/inflate/md.ts +25 -0
  131. package/src/inflate/setup-auth.ts +40 -0
  132. package/src/inflate/setup-cors.ts +40 -0
  133. package/src/inflate/setup-db.ts +115 -0
  134. package/src/inflate/setup-error.ts +43 -0
  135. package/src/inflate/setup-http.ts +655 -0
  136. package/src/inflate/setup-log.ts +44 -0
  137. package/src/inflate/setup-middleware.ts +46 -0
  138. package/src/inflate/setup-server-config.ts +47 -0
  139. package/src/inflate/setup-test.ts +23 -0
  140. package/src/inflate/setup-ws.ts +49 -0
  141. package/src/inflate/setup.doc.ts +68 -0
  142. package/src/inflate/utils/sea-utils.ts +14 -0
  143. package/src/lib.ts +19 -0
  144. package/src/main.ts +89 -0
  145. package/src/services/app.ts +660 -0
  146. package/src/services/editor.tsx +101 -0
  147. package/src/services/globals.ts +143 -0
  148. package/src/services/hot-reload.ts +48 -0
  149. package/src/services/migrations.ts +66 -0
  150. package/src/services/utils/admin-interface.ts +37 -0
  151. package/src/services/utils/cache.ts +88 -0
  152. package/src/services/utils/cluster-cache.ts +230 -0
  153. package/src/services/utils/cluster-ws.ts +197 -0
  154. package/src/services/utils/db-manager.ts +92 -0
  155. package/src/services/utils/get-route.ts +70 -0
  156. package/src/services/utils/log-transport.ts +81 -0
  157. package/src/services/utils/log.ts +92 -0
  158. package/src/services/utils/server-interface.ts +179 -0
  159. package/src/services/utils/websocketmanager.ts +149 -0
  160. package/src/types/@esbuild.d.ts +1 -0
  161. package/src/types/@miqro/core.d.ts +2 -0
  162. package/src/types/@miqro/jsx.d.ts +2 -0
  163. package/src/types/@miqro/parser.d.ts +2 -0
  164. package/src/types/@miqro/query.d.ts +2 -0
  165. package/src/types/@miqro/request.d.ts +2 -0
  166. package/src/types/@miqro/test.d.ts +2 -0
  167. package/src/types/@miqro.d.ts +1 -0
  168. package/src/types/@types.d.ts +1 -0
  169. package/src/types/browser.globals.d.ts +9 -0
  170. package/src/types/globals.d.ts +2 -0
  171. package/src/types/jsx.globals.d.ts +37 -0
  172. package/src/types/miqro.d.ts +129 -0
  173. package/src/types/postject.d.ts +1 -0
  174. package/src/types/server.globals.d.ts +72 -0
  175. package/src/types.ts +222 -0
@@ -0,0 +1,144 @@
1
+ //import hljs from "../lib/highlight/core.min.js"
2
+ import hljs from 'highlight.js/lib/core';
3
+ import javascript from 'highlight.js/lib/languages/javascript';
4
+ import xml from "highlight.js/lib/languages/xml";
5
+ import css from "highlight.js/lib/languages/css";
6
+ import scss from "highlight.js/lib/languages/scss";
7
+ import markdown from "highlight.js/lib/languages/markdown";
8
+ import dockerfile from "highlight.js/lib/languages/dockerfile";
9
+ import yaml from "highlight.js/lib/languages/yaml";
10
+ import typescript from "highlight.js/lib/languages/typescript";
11
+ import c from "highlight.js/lib/languages/c";
12
+ import cpp from "highlight.js/lib/languages/cpp";
13
+ import bash from "highlight.js/lib/languages/bash";
14
+ import python from "highlight.js/lib/languages/python";
15
+ import text from "highlight.js/lib/languages/plaintext";
16
+ import json from "highlight.js/lib/languages/json";
17
+
18
+ // Then register the languages you need
19
+ hljs.registerLanguage('text', text);
20
+ hljs.registerLanguage('dockerfile', dockerfile);
21
+ hljs.registerLanguage('yaml', yaml);
22
+ hljs.registerLanguage('javascript', javascript);
23
+ hljs.registerLanguage('xml', xml);
24
+ hljs.registerLanguage('html', xml);
25
+ hljs.registerLanguage('css', css);
26
+ hljs.registerLanguage('scss', scss);
27
+ hljs.registerLanguage('markdown', markdown);
28
+ hljs.registerLanguage('typescript', typescript);
29
+ hljs.registerLanguage('c', c);
30
+ hljs.registerLanguage('cpp', cpp);
31
+ hljs.registerLanguage('bash', bash);
32
+ hljs.registerLanguage('python', python);
33
+ hljs.registerLanguage('json', json);
34
+
35
+ /*!
36
+ Theme: GitHub Dark
37
+ Description: Dark theme as seen on github.com
38
+ Author: github.com
39
+ Maintainer: @Hirse
40
+ Updated: 2021-05-15
41
+
42
+ Outdated base version: https://github.com/primer/github-syntax-dark
43
+ Current colors taken from GitHub's CSS
44
+ */
45
+ const STYLE = `pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}code{outline: 0px solid rgba(0, 0, 0, 0.263);caret-color: red;}.hljs-name{color: #e8910d;}.hljs-tag .hljs-attr, .hljs-tag .hljs-name{color: #e8910d;}`;
46
+ const POSTTYLE = "pre{padding:0; margin:0;} code { background-color: #000000; color: #ffffff; }";
47
+ const TAG_NAME = "HIGHLIGHT-TEXT-AREA";
48
+
49
+ function runHighlight(content: string | null, language: string) {
50
+ const now = Date.now();
51
+ console.log("runHighlight [%s]", language);
52
+ const value = hljs.highlight(String(content), {
53
+ language,
54
+ ignoreIllegals: true
55
+ }).value;
56
+ console.log("runHighlight [%s] took [%s]ms", language, Date.now() - now);
57
+ return value;
58
+ }
59
+
60
+ function emitEvents(elementRef: any, topMost: any, content: string, oncontentchange?: (ev: CustomEvent) => void) {
61
+ if (elementRef.current && topMost.current) {
62
+ const currentContent = elementRef.current.textContent as any;
63
+ const webComponentElement = (topMost.current as HTMLElement).parentNode as HTMLElement;
64
+ const event = new CustomEvent("contentchange", { detail: currentContent });
65
+ if (webComponentElement && webComponentElement instanceof HTMLElement && webComponentElement.tagName === TAG_NAME) {
66
+ try {
67
+ webComponentElement.dispatchEvent(event);
68
+ } catch (e) {
69
+ console.error(e);
70
+ }
71
+ }
72
+ if (typeof oncontentchange === "function") {
73
+ try {
74
+ oncontentchange(event);
75
+ } catch (e) {
76
+ console.error(e);
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ export function HighlightTextArea({ content, language, oncontentchange, tabChar, disabled }:
83
+ { language: string; content: string; disabled?: string; tabChar?: string; oncontentchange?: (ev: CustomEvent) => void }
84
+ ) {
85
+ const elementRef = jsx.useRef();
86
+ const topMost = jsx.useRef();
87
+ const [lastLanguage, setlastLanguage] = jsx.useState(language);
88
+
89
+ // effect to watch changes to language
90
+ jsx.useEffect(() => {
91
+ if (elementRef.current && (lastLanguage !== language || elementRef.current.textContent !== content)) {
92
+ setlastLanguage(language);
93
+ elementRef.current.innerHTML = runHighlight(content, language);
94
+ }
95
+ }, [lastLanguage, language, elementRef.current, content])
96
+
97
+ return <pre ref={topMost}>
98
+ <style innerHTML={STYLE + POSTTYLE} />
99
+ <code
100
+ autocomplete="off"
101
+ autocorrect="off"
102
+ autocapitalize="off"
103
+ spellcheck="false"
104
+ contenteditable={disabled ? "false" : "true"}
105
+ ref={elementRef}
106
+ tabindex="0"
107
+ innerHTML={!elementRef.current ? runHighlight(content, language) : null}
108
+ onfocusout={async (ev) => {
109
+ ev.preventDefault();
110
+ if (elementRef.current) {
111
+ if (content !== elementRef.current.textContent) {
112
+ //setlastContent(String(elementRef.current.textContent));
113
+ elementRef.current.innerHTML = runHighlight(elementRef.current.textContent, language);
114
+ }
115
+ }
116
+ }}
117
+ onkeydown={ev => {
118
+ if (ev.keyCode === 9) {
119
+ ev.preventDefault();
120
+ // now insert four non-breaking spaces for the tab key
121
+ const sel = document.getSelection();
122
+ if (sel && topMost.current) {
123
+ if ((topMost.current as any).contains(sel.anchorNode)) {
124
+ const range = sel.getRangeAt(0);
125
+ const tabNode = document.createTextNode(tabChar ? tabChar : "\t");
126
+ range.insertNode(tabNode);
127
+ range.setStartAfter(tabNode);
128
+ range.setEndAfter(tabNode);
129
+ sel.removeAllRanges();
130
+ sel.addRange(range);
131
+ }
132
+ }
133
+ emitEvents(elementRef, topMost, content, oncontentchange);
134
+ }
135
+ }}
136
+ oninput={ev => {
137
+ ev.preventDefault();
138
+ emitEvents(elementRef, topMost, content, oncontentchange);
139
+ }} />
140
+ </pre>
141
+ }
142
+
143
+ HighlightTextArea.asFragment = true;
144
+ HighlightTextArea.shadowInit = false;
@@ -0,0 +1,110 @@
1
+ import { LogSocket } from "../common/log-socket.js";
2
+
3
+ function getUniqueIdentifiers(lines: {
4
+ out: string;
5
+ identifier: string;
6
+ }[]) {
7
+ const identifiersCache = {};
8
+ return lines.map(l => l.identifier).filter(identifier => {
9
+ const filter = !identifiersCache[identifier];
10
+ identifiersCache[identifier] = true;
11
+ return filter;
12
+ });
13
+ }
14
+
15
+ const LOG_LEVEL_MAP =
16
+ {
17
+ "none": 0,
18
+ "error": 1,
19
+ "warn": 2,
20
+ "info": 3,
21
+ "debug": 4,
22
+ "trace": 5,
23
+ };
24
+
25
+ interface LogViewerProps {
26
+ socket: LogSocket;
27
+ }
28
+
29
+ export function LogViewer(props: LogViewerProps) {
30
+ const { lines, clearLog, getMaxlogsize, setMaxLogSize } = props.socket;
31
+
32
+ const maxLogSize = getMaxlogsize();
33
+
34
+ const refresh = jsx.useRefresh();
35
+
36
+ jsx.useEffect(() => {
37
+ refresh();
38
+ }, [maxLogSize]);
39
+
40
+ const [identifier, setidentifier] = jsx.useState<string>("");
41
+ const [level, setlevel] = jsx.useState<string>("debug");
42
+ const [filter, setfilter] = jsx.useState<string>("");
43
+ const identifiers = getUniqueIdentifiers(lines).sort();
44
+ //console.log(identifiers);
45
+
46
+ return <div class="log-viewer">
47
+ <div class="log-viewer-toolbar">
48
+ <button
49
+ class="btn"
50
+ onclick={e => {
51
+ e.preventDefault();
52
+ clearLog();
53
+ }}>clear log</button>
54
+ <select
55
+ value={maxLogSize}
56
+ oninput={ev => {
57
+ ev.preventDefault();
58
+ if (ev.target.value === "unlimited") {
59
+ setMaxLogSize("unlimited");
60
+ } else {
61
+ setMaxLogSize(parseInt(ev.target.value, 10));
62
+ }
63
+ }}
64
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: 0;">
65
+ {["10", "1000", "5000", "10000", "15000", "20000", "25000", "50000", "100000", "500000", "1000000", "1500000", "5000000"].map(l => <option value={l}>{l}</option>)}
66
+ <option value="unlimited">unlimited</option>
67
+ </select>
68
+ <select
69
+ value={level}
70
+ oninput={ev => {
71
+ ev.preventDefault();
72
+ setlevel(ev.target.value);
73
+ }}
74
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;">
75
+ {["error", "warn", "info", "debug", "trace"].map(l => <option value={l}>{l}</option>)}
76
+ <option value="">all</option>
77
+ </select>
78
+ <select
79
+ value={identifier}
80
+ oninput={ev => {
81
+ ev.preventDefault();
82
+ setidentifier(ev.target.value);
83
+ }}
84
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;">
85
+ {identifiers.map(identifier => <option value={identifier}>{identifier}</option>)}
86
+ <option value=""></option>
87
+ </select>
88
+ <input
89
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;"
90
+ value={filter}
91
+ oninput={ev => {
92
+ ev.preventDefault();
93
+ setfilter(ev.target.value);
94
+ }}
95
+ type="text"
96
+ placeholder="..filter.." />
97
+ </div>
98
+ <div class="log-viewer-log">
99
+ {lines
100
+ .filter(line => identifier === "" || line.identifier === identifier)
101
+ .filter(line => filter === "" || line.out.indexOf(filter) !== -1)
102
+ .filter(line => {
103
+ return (level === "" || LOG_LEVEL_MAP[level] >= LOG_LEVEL_MAP[line.level]);
104
+ })
105
+ .map(line =>
106
+ <p style="margin: 0; padding: 0; border-radius: 0; font-size: 12px;" class={line.level === "error" ? "info-danger" : line.level === "warn" ? "info-warn" : line.level === "trace" ? "info-success" : line.level === "debug" ? "info-info" : ""}>{line.out}</p>
107
+ ).reverse()}
108
+ </div>
109
+ </div>
110
+ }
@@ -0,0 +1,169 @@
1
+ import { BASEEDITOR_PATH } from "../common/constants.js";
2
+ import { TEMPLATES } from "../common/templates.js";
3
+ import { HighlightTextArea } from "./highlight-text-area.js";
4
+
5
+ export function NewFile(props: { migrations: string[]; services: string[]; open: boolean; ondone: (file?: string) => void; }) {
6
+
7
+ const [template, settemplate] = jsx.useState("EMPTY");
8
+
9
+ const refresh = jsx.useRefresh();
10
+
11
+ const [service, setservice] = jsx.useState(props.services[0]);
12
+
13
+ const nameInput = jsx.useRef();
14
+ //const open = dialog ? dialog.open : false;
15
+
16
+ /*jsx.useEffect(() => {
17
+ if (dialog) {
18
+ //console.log((dialogRef.current as any).open);
19
+ if (open !== props.open) {
20
+ if (nameInput.current) {
21
+ nameInput.current.value = "";
22
+ nameInput.current.focus();
23
+ }
24
+ if (props.open) {
25
+ console.log("showModal");
26
+ dialog.showModal();
27
+ //(dialogRef.current as any).show();
28
+ } else {
29
+ console.log("closeModal");
30
+ //dialog.close();
31
+ }
32
+ }
33
+ }
34
+ }, [dialog, open, props.open]);*/
35
+ jsx.useEffect(() => {
36
+
37
+ if (nameInput.current) {
38
+ nameInput.current.value = "";
39
+ nameInput.current.focus();
40
+ }
41
+ }, [nameInput.current]);
42
+
43
+ function close(file?: string) {
44
+ //console.log("closeModal");
45
+ if (props.ondone) {
46
+ props.ondone(file);
47
+ }
48
+ }
49
+
50
+
51
+ let nextMigrationNumber = 1;
52
+ if (props.migrations.length > 0) {
53
+ const lastMigration = props.migrations[props.migrations.length - 1];
54
+ const indexOfDash = lastMigration.indexOf("-");
55
+ if (indexOfDash !== -1) {
56
+ nextMigrationNumber = parseInt(lastMigration.substring(0, indexOfDash), 10) + 1;
57
+ }
58
+ }
59
+
60
+ const httpPath = (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].httpSufix ? TEMPLATES[template].httpSufix : "");
61
+
62
+ const filename = (service ? service + "/" : "") + (service && TEMPLATES[template].prefix ? TEMPLATES[template].prefix + "/" : "") + (template === "MIGRATION" ? nextMigrationNumber + "-" : "") + (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].sufix ? TEMPLATES[template].sufix : "");
63
+
64
+ async function createNewFile() {
65
+ if ((nameInput.current && nameInput.current.value) || TEMPLATES[template].filename) {
66
+ const t = TEMPLATES[template];
67
+ await fetch(BASEEDITOR_PATH + "/api/fs/write", {
68
+ method: "POST",
69
+ headers: {
70
+ ["content-type"]: "application/json"
71
+ },
72
+ body: JSON.stringify({
73
+ path: filename,
74
+ contents: t.template ? t.template(filename, httpPath) : ""
75
+ })
76
+ });
77
+ return filename;
78
+ }
79
+ }
80
+
81
+ return <>
82
+ {props.open ? <dialog
83
+ class="new-dialog"
84
+ open="">
85
+ <div class="dialog-header">
86
+ <h1>Create new File</h1>
87
+ </div>
88
+ <div class="dialog-body">
89
+ <select
90
+ value={service}
91
+ oninput={ev => {
92
+ ev.preventDefault();
93
+ ev.stopPropagation();
94
+ console.log(ev.target.value);
95
+ setservice(ev.target.value);
96
+ }}
97
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation); margin-bottom: var(--file-browser-separation);">
98
+ <option value={""}></option>
99
+ {props.services.map(service => <option value={service}>{service}</option>)}
100
+ </select>
101
+ <p
102
+ style="margin: 0; margin-bottom: var(--file-browser-separation);"
103
+ >{filename}</p>
104
+ {!TEMPLATES[template].filename ? <form
105
+ style="width: 100%;"
106
+ onsubmit={async (ev) => {
107
+ ev.preventDefault();
108
+ ev.stopPropagation();
109
+ const path = await createNewFile();
110
+ close(path);
111
+ }}>
112
+ <input
113
+ style="width: 100%;"
114
+ onkeydown={ev => {
115
+ if (ev.keyCode === 27) {
116
+ // catch esc
117
+ ev.stopPropagation();
118
+ ev.preventDefault();
119
+ close();
120
+ }
121
+ refresh();
122
+ }}
123
+ ref={nameInput}
124
+ type="text"
125
+ placeholder="...filename..." />
126
+ </form> : <></>}
127
+ <select
128
+ value={template}
129
+ oninput={ev => {
130
+ ev.preventDefault();
131
+ ev.stopPropagation();
132
+ console.log(ev.target.value);
133
+ settemplate(ev.target.value);
134
+ }}
135
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation);">
136
+ {Object.keys(TEMPLATES).map(templateName => <option value={templateName}>{TEMPLATES[templateName].displayName}</option>)}
137
+ </select>
138
+ {TEMPLATES[template].template ? <div
139
+ class="new-dialog-preview">
140
+ <HighlightTextArea
141
+ content={TEMPLATES[template].template(filename, httpPath)}
142
+ language={TEMPLATES[template].language}
143
+ disabled="true" />
144
+ </div> : <></>}
145
+ </div>
146
+ <div class="dialog-footer">
147
+ <button
148
+ class="btn danger"
149
+ onclick={ev => {
150
+ ev.preventDefault();
151
+ ev.stopPropagation();
152
+ close();
153
+ }}>cancel</button>
154
+ <button
155
+ style="margin-left: auto;"
156
+ class="btn active"
157
+ onclick={async (ev) => {
158
+ ev.preventDefault();
159
+ ev.stopPropagation();
160
+ const path = await createNewFile();
161
+ close(path);
162
+ }}>create</button>
163
+ </div>
164
+ </dialog> : <></>}
165
+ </>
166
+ }
167
+
168
+ NewFile.asFragment = true;
169
+ NewFile.shadowInit = false;
@@ -0,0 +1,22 @@
1
+ let scrollTimeout2: any = null;
2
+
3
+ export function useScroll(): [{ scrollTop: string; scrollLeft: string }, (newScroll: { scrollTop: number; scrollLeft: number; }, inmediate?: boolean) => void] {
4
+ const [scrollTop, setscrollTop] = jsx.useQuery("scrollTop", "0");
5
+ const [scrollLeft, setscrollLeft] = jsx.useQuery("scrollLeft", "0");
6
+
7
+ return [{
8
+ scrollTop: scrollTop as string,
9
+ scrollLeft: scrollLeft as string
10
+ }, (newScroll: { scrollTop: number; scrollLeft: number; }, inmediate?: boolean) => {
11
+ clearTimeout(scrollTimeout2);
12
+ if (inmediate) {
13
+ setscrollTop(String(newScroll.scrollTop));
14
+ setscrollLeft(String(newScroll.scrollLeft));
15
+ } else {
16
+ scrollTimeout2 = setTimeout(() => {
17
+ setscrollTop(String(newScroll.scrollTop));
18
+ setscrollLeft(String(newScroll.scrollLeft));
19
+ }, 1000);
20
+ }
21
+ }]
22
+ }
@@ -0,0 +1,49 @@
1
+ interface StartPageProps {
2
+ togglePanel: (panel: string) => void;
3
+ isPanelVisible: (panel: string) => boolean;
4
+ disableLog?: boolean; disablePreview?: boolean; disableReload?: boolean;
5
+ }
6
+
7
+ export function StartPage(props: StartPageProps) {
8
+
9
+ jsx.useEffect(() => {
10
+ if (!props.isPanelVisible("left")) {
11
+ props.togglePanel("left");
12
+ }
13
+ }, []);
14
+
15
+ return <div class={`start-page`}>
16
+ <div class="row center">
17
+ <h1>Start Page</h1>
18
+ </div>
19
+ <br />
20
+ <div class="row center">
21
+ <div class="row">
22
+ <div class={`toggle-panel-button left-side-panel-button ${props.isPanelVisible("left") ? "active" : ""}`}
23
+ onclick={ev => {
24
+ ev.preventDefault();
25
+ props.togglePanel("left");
26
+ }}
27
+ ></div>
28
+ <br />
29
+ {props.disableLog ? <></> : <div class={`toggle-panel-button bottom-side-panel-button ${props.isPanelVisible("bottom") ? "active" : ""}`}
30
+ onclick={ev => {
31
+ ev.preventDefault();
32
+ props.togglePanel("bottom");
33
+ }}
34
+ ></div>}
35
+ <br />
36
+ {props.disablePreview ? <></> : <div class={`toggle-panel-button right-side-panel-button ${props.isPanelVisible("right") ? "active" : ""}`}
37
+ onclick={ev => {
38
+ ev.preventDefault();
39
+ props.togglePanel("right");
40
+ }}
41
+ ></div>}
42
+ </div>
43
+ </div>
44
+ <br />
45
+ </div>;
46
+ }
47
+
48
+ StartPage.asFragment = true;
49
+ StartPage.shadowInit = false;
@@ -0,0 +1,32 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { unlinkSync } from "node:fs";
3
+ import { getPath } from "./read.api.js";
4
+
5
+ export default {
6
+ description: "admin editor file deletion endpoint",
7
+ method: "POST",
8
+ path: "/delete",
9
+ middleware: [server.middleware.json()],
10
+ request: {
11
+ body: {
12
+ path: "string"
13
+ }
14
+ },
15
+ response: {
16
+ status: [200, 400],
17
+ body: {
18
+ message: "string"
19
+ }
20
+ },
21
+ handler: async (req, res) => {
22
+ const { path } = req.body;
23
+ await deleteFile(path);
24
+ return res?.json({
25
+ message: "OK"
26
+ });
27
+ }
28
+ } as APIRoute;
29
+
30
+ function deleteFile(path: string) {
31
+ unlinkSync(getPath(path));
32
+ }
@@ -0,0 +1,55 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { readFileSync } from "node:fs";
3
+ import { SUPPORTED_LANGUAGES } from "../../../../../common/constants.js";
4
+ import { relative, resolve } from "node:path";
5
+ import { getLanguage } from "./scan.api.js";
6
+ import { BASE_PATH } from "../../../../../common/constants.server.js";
7
+
8
+ export default {
9
+ method: "POST",
10
+ path: "/read",
11
+ description: "admin editor file read endpoint",
12
+ middleware: [server.middleware.json()],
13
+ request: {
14
+ body: {
15
+ path: "string"
16
+ }
17
+ },
18
+ response: {
19
+ status: [200, 400],
20
+ body: {
21
+ contents: "string",
22
+ path: "string"
23
+ }
24
+ },
25
+ handler: async (req, res) => {
26
+ const { path } = req.body;
27
+ const contents = readFile(path);
28
+ return res?.json({
29
+ contents,
30
+ path
31
+ });
32
+ }
33
+ } as APIRoute;
34
+
35
+ export function readFile(path: string) {
36
+ const filePath = getPath(path);
37
+ const language = getLanguage(filePath);
38
+ if (SUPPORTED_LANGUAGES.includes(language)) {
39
+ const contents = readFileSync(filePath).toString();
40
+ return contents;
41
+ } else {
42
+ throw new Error("unsupported file format");
43
+ }
44
+
45
+ }
46
+
47
+ export function getPath(path: string) {
48
+ const realPath = resolve(BASE_PATH, path);
49
+
50
+ if (relative(BASE_PATH, realPath).startsWith("..")) {
51
+ throw new Error("invalid path! [" + path + "]");
52
+ }
53
+
54
+ return realPath;
55
+ }
@@ -0,0 +1,41 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { existsSync, mkdirSync, renameSync } from "node:fs";
3
+ import { getPath } from "./read.api.js";
4
+ import { dirname } from "node:path";
5
+
6
+ export default {
7
+ middleware: [server.middleware.json()],
8
+ method: "POST",
9
+ description: "admin editor file rename endpoint",
10
+ path: "/rename",
11
+ request: {
12
+ body: {
13
+ path: "string",
14
+ newName: "string"
15
+ }
16
+ },
17
+ response: {
18
+ status: [200, 400],
19
+ body: {
20
+ message: "string"
21
+ }
22
+ },
23
+ handler: async (req, res) => {
24
+ const { path, newName } = req.body;
25
+ await rename(path, newName);
26
+ return res?.json({
27
+ message: "OK"
28
+ });
29
+ }
30
+ } as APIRoute;
31
+
32
+ export async function rename(path: string, newName: string) {
33
+ if (existsSync(path) && !existsSync(newName)) {
34
+ mkdirSync(dirname(getPath(newName)), {
35
+ recursive: true
36
+ });
37
+ renameSync(getPath(path), getPath(newName));
38
+ } else {
39
+ throw new Error("invalid paths");
40
+ }
41
+ }