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