@ramesesinc/platform-core 0.1.0

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 (285) hide show
  1. package/dist/components/action/AlertMessage.d.ts +8 -0
  2. package/dist/components/action/AlertMessage.js +19 -0
  3. package/dist/components/action/AlertMessage.tsx +38 -0
  4. package/dist/components/action/Button.d.ts +21 -0
  5. package/dist/components/action/Button.js +139 -0
  6. package/dist/components/action/Button.tsx +230 -0
  7. package/dist/components/action/CancelEdit.d.ts +9 -0
  8. package/dist/components/action/CancelEdit.js +21 -0
  9. package/dist/components/action/CancelEdit.tsx +40 -0
  10. package/dist/components/action/DeleteData.d.ts +13 -0
  11. package/dist/components/action/DeleteData.js +43 -0
  12. package/dist/components/action/DeleteData.tsx +73 -0
  13. package/dist/components/action/Edit.d.ts +9 -0
  14. package/dist/components/action/Edit.js +21 -0
  15. package/dist/components/action/Edit.tsx +40 -0
  16. package/dist/components/action/LookupPage.d.ts +16 -0
  17. package/dist/components/action/LookupPage.js +62 -0
  18. package/dist/components/action/LookupPage.tsx +113 -0
  19. package/dist/components/action/ProcessRunner.d.ts +62 -0
  20. package/dist/components/action/ProcessRunner.js +156 -0
  21. package/dist/components/action/ProcessRunner.tsx +337 -0
  22. package/dist/components/action/Refresh.d.ts +7 -0
  23. package/dist/components/action/Refresh.js +17 -0
  24. package/dist/components/action/Refresh.tsx +35 -0
  25. package/dist/components/action/SaveData.d.ts +10 -0
  26. package/dist/components/action/SaveData.js +54 -0
  27. package/dist/components/action/SaveData.tsx +74 -0
  28. package/dist/components/action/SelectData.d.ts +8 -0
  29. package/dist/components/action/SelectData.js +29 -0
  30. package/dist/components/action/SelectData.tsx +47 -0
  31. package/dist/components/action/Undo.d.ts +9 -0
  32. package/dist/components/action/Undo.js +31 -0
  33. package/dist/components/action/Undo.tsx +50 -0
  34. package/dist/components/action/UpdateContext.d.ts +9 -0
  35. package/dist/components/action/UpdateContext.js +21 -0
  36. package/dist/components/action/UpdateContext.tsx +40 -0
  37. package/dist/components/action/UpdateData.d.ts +9 -0
  38. package/dist/components/action/UpdateData.js +33 -0
  39. package/dist/components/action/UpdateData.tsx +49 -0
  40. package/dist/components/action/ViewBackPage.d.ts +9 -0
  41. package/dist/components/action/ViewBackPage.js +19 -0
  42. package/dist/components/action/ViewBackPage.tsx +46 -0
  43. package/dist/components/action/ViewPage.d.ts +14 -0
  44. package/dist/components/action/ViewPage.js +88 -0
  45. package/dist/components/action/ViewPage.tsx +141 -0
  46. package/dist/components/common/UIComponent.d.ts +11 -0
  47. package/dist/components/common/UIComponent.js +52 -0
  48. package/dist/components/common/UIComponent.tsx +84 -0
  49. package/dist/components/common/UIInput.d.ts +12 -0
  50. package/dist/components/common/UIInput.js +37 -0
  51. package/dist/components/common/UIInput.tsx +49 -0
  52. package/dist/components/common/UIMenu.d.ts +23 -0
  53. package/dist/components/common/UIMenu.js +61 -0
  54. package/dist/components/common/UIMenu.tsx +91 -0
  55. package/dist/components/index.d.ts +37 -0
  56. package/dist/components/index.js +44 -0
  57. package/dist/components/index.ts +51 -0
  58. package/dist/components/input/CodeEditor.d.ts +12 -0
  59. package/dist/components/input/CodeEditor.js +132 -0
  60. package/dist/components/input/CodeEditor.tsx +188 -0
  61. package/dist/components/input/DateField.d.ts +9 -0
  62. package/dist/components/input/DateField.js +140 -0
  63. package/dist/components/input/DateField.tsx +274 -0
  64. package/dist/components/input/DayPicker.d.ts +2 -0
  65. package/dist/components/input/DayPicker.js +5 -0
  66. package/dist/components/input/DayPicker.tsx +5 -0
  67. package/dist/components/input/HtmlCode.d.ts +8 -0
  68. package/dist/components/input/HtmlCode.js +157 -0
  69. package/dist/components/input/HtmlCode.tsx +203 -0
  70. package/dist/components/input/JsonCode.d.ts +9 -0
  71. package/dist/components/input/JsonCode.js +159 -0
  72. package/dist/components/input/JsonCode.tsx +205 -0
  73. package/dist/components/input/MonthPicker.d.ts +2 -0
  74. package/dist/components/input/MonthPicker.js +5 -0
  75. package/dist/components/input/MonthPicker.tsx +5 -0
  76. package/dist/components/input/ScriptCode.d.ts +8 -0
  77. package/dist/components/input/ScriptCode.js +153 -0
  78. package/dist/components/input/ScriptCode.tsx +195 -0
  79. package/dist/components/input/Select.d.ts +14 -0
  80. package/dist/components/input/Select.js +40 -0
  81. package/dist/components/input/Select.tsx +78 -0
  82. package/dist/components/input/SqlCode.d.ts +8 -0
  83. package/dist/components/input/SqlCode.js +121 -0
  84. package/dist/components/input/SqlCode.tsx +162 -0
  85. package/dist/components/input/StringDecision.d.ts +2 -0
  86. package/dist/components/input/StringDecision.js +34 -0
  87. package/dist/components/input/StringDecision.tsx +64 -0
  88. package/dist/components/input/Text.d.ts +7 -0
  89. package/dist/components/input/Text.js +39 -0
  90. package/dist/components/input/Text.tsx +57 -0
  91. package/dist/components/input/YearPicker.d.ts +8 -0
  92. package/dist/components/input/YearPicker.js +44 -0
  93. package/dist/components/input/YearPicker.tsx +81 -0
  94. package/dist/components/list/IconMenu.d.ts +14 -0
  95. package/dist/components/list/IconMenu.js +72 -0
  96. package/dist/components/list/IconMenu.tsx +115 -0
  97. package/dist/components/list/TabMenu.d.ts +10 -0
  98. package/dist/components/list/TabMenu.js +72 -0
  99. package/dist/components/list/TabMenu.tsx +127 -0
  100. package/dist/components/list/TreeMenu.d.ts +14 -0
  101. package/dist/components/list/TreeMenu.js +207 -0
  102. package/dist/components/list/TreeMenu.tsx +279 -0
  103. package/dist/components/list/TxnTaskList.d.ts +2 -0
  104. package/dist/components/list/TxnTaskList.js +77 -0
  105. package/dist/components/list/TxnTaskList.tsx +198 -0
  106. package/dist/components/output/Label.d.ts +8 -0
  107. package/dist/components/output/Label.js +33 -0
  108. package/dist/components/output/Label.tsx +51 -0
  109. package/dist/components/table/DataList.d.ts +88 -0
  110. package/dist/components/table/DataList.js +361 -0
  111. package/dist/components/table/DataList.tsx +782 -0
  112. package/dist/components/table/DataTable.d.ts +46 -0
  113. package/dist/components/table/DataTable.js +253 -0
  114. package/dist/components/table/DataTable.tsx +572 -0
  115. package/dist/components/table/ListHandler.d.ts +42 -0
  116. package/dist/components/table/ListHandler.js +197 -0
  117. package/dist/components/table/ListHandler.ts +276 -0
  118. package/dist/components/table/TableContext.d.ts +33 -0
  119. package/dist/components/table/TableContext.js +57 -0
  120. package/dist/components/table/TableContext.tsx +122 -0
  121. package/dist/components/view/ComponentView.d.ts +8 -0
  122. package/dist/components/view/ComponentView.js +78 -0
  123. package/dist/components/view/ComponentView.tsx +102 -0
  124. package/dist/components/view/FilterView.d.ts +2 -0
  125. package/dist/components/view/FilterView.js +14 -0
  126. package/dist/components/view/FilterView.tsx +21 -0
  127. package/dist/components/view/HtmlForm.d.ts +7 -0
  128. package/dist/components/view/HtmlForm.js +145 -0
  129. package/dist/components/view/HtmlForm.tsx +186 -0
  130. package/dist/components/view/HtmlView.d.ts +9 -0
  131. package/dist/components/view/HtmlView.js +85 -0
  132. package/dist/components/view/HtmlView.tsx +114 -0
  133. package/dist/components/view/IFrameView.d.ts +2 -0
  134. package/dist/components/view/IFrameView.js +34 -0
  135. package/dist/components/view/IFrameView.tsx +48 -0
  136. package/dist/components/view/Modal.d.ts +14 -0
  137. package/dist/components/view/Modal.js +28 -0
  138. package/dist/components/view/Modal.tsx +72 -0
  139. package/dist/components/view/PageView.d.ts +9 -0
  140. package/dist/components/view/PageView.js +90 -0
  141. package/dist/components/view/PageView.tsx +131 -0
  142. package/dist/components/view/PopupView.d.ts +9 -0
  143. package/dist/components/view/PopupView.js +91 -0
  144. package/dist/components/view/PopupView.tsx +160 -0
  145. package/dist/components/view/RootView.d.ts +8 -0
  146. package/dist/components/view/RootView.js +75 -0
  147. package/dist/components/view/RootView.tsx +109 -0
  148. package/dist/components/view/WizardView.d.ts +6 -0
  149. package/dist/components/view/WizardView.js +34 -0
  150. package/dist/components/view/WizardView.tsx +48 -0
  151. package/dist/core/AppContext.d.ts +25 -0
  152. package/dist/core/AppContext.js +159 -0
  153. package/dist/core/AuthContext.d.ts +13 -0
  154. package/dist/core/AuthContext.js +80 -0
  155. package/dist/core/ComponentCache.d.ts +15 -0
  156. package/dist/core/ComponentCache.js +25 -0
  157. package/dist/core/DataContext.d.ts +20 -0
  158. package/dist/core/DataContext.js +41 -0
  159. package/dist/core/DynamicComponent.d.ts +12 -0
  160. package/dist/core/DynamicComponent.js +30 -0
  161. package/dist/core/DynamicIcon.d.ts +6 -0
  162. package/dist/core/DynamicIcon.js +48 -0
  163. package/dist/core/DynamicTemplate.d.ts +4 -0
  164. package/dist/core/DynamicTemplate.js +17 -0
  165. package/dist/core/ErrorMessage.d.ts +5 -0
  166. package/dist/core/ErrorMessage.js +7 -0
  167. package/dist/core/EventHandler.d.ts +3 -0
  168. package/dist/core/EventHandler.js +1 -0
  169. package/dist/core/HtmlCache.d.ts +6 -0
  170. package/dist/core/HtmlCache.js +17 -0
  171. package/dist/core/Page.d.ts +6 -0
  172. package/dist/core/Page.js +141 -0
  173. package/dist/core/PageCache.d.ts +15 -0
  174. package/dist/core/PageCache.js +26 -0
  175. package/dist/core/PageContext.d.ts +49 -0
  176. package/dist/core/PageContext.js +207 -0
  177. package/dist/core/PageRegistry.d.ts +7 -0
  178. package/dist/core/PageRegistry.js +11 -0
  179. package/dist/core/PageViewContext.d.ts +45 -0
  180. package/dist/core/PageViewContext.js +277 -0
  181. package/dist/core/Panel.d.ts +16 -0
  182. package/dist/core/Panel.js +39 -0
  183. package/dist/core/RowContext.d.ts +11 -0
  184. package/dist/core/RowContext.js +16 -0
  185. package/dist/core/StepHandler.d.ts +9 -0
  186. package/dist/core/StepHandler.js +39 -0
  187. package/dist/core/UIDependHandler.d.ts +6 -0
  188. package/dist/core/UIDependHandler.js +31 -0
  189. package/dist/core/auth/index.d.ts +18 -0
  190. package/dist/core/auth/index.js +187 -0
  191. package/dist/core/auth/session.d.ts +4 -0
  192. package/dist/core/auth/session.js +45 -0
  193. package/dist/core/index.d.ts +3 -0
  194. package/dist/core/index.js +1 -0
  195. package/dist/core/page-helper.d.ts +27 -0
  196. package/dist/core/page-helper.js +47 -0
  197. package/dist/hooks/useUrlParams.d.ts +11 -0
  198. package/dist/hooks/useUrlParams.js +164 -0
  199. package/dist/index.d.ts +65 -0
  200. package/dist/index.js +69 -0
  201. package/dist/layouts/BorderLayout.d.ts +14 -0
  202. package/dist/layouts/BorderLayout.js +8 -0
  203. package/dist/layouts/CardLayout.d.ts +27 -0
  204. package/dist/layouts/CardLayout.js +36 -0
  205. package/dist/layouts/CenterLayout.d.ts +8 -0
  206. package/dist/layouts/CenterLayout.js +6 -0
  207. package/dist/layouts/GridLayout.d.ts +9 -0
  208. package/dist/layouts/GridLayout.js +5 -0
  209. package/dist/layouts/HPanel.d.ts +11 -0
  210. package/dist/layouts/HPanel.js +8 -0
  211. package/dist/layouts/HorizontalLayout.d.ts +11 -0
  212. package/dist/layouts/HorizontalLayout.js +6 -0
  213. package/dist/layouts/MainLayout.d.ts +6 -0
  214. package/dist/layouts/MainLayout.js +5 -0
  215. package/dist/layouts/PageLayout.d.ts +11 -0
  216. package/dist/layouts/PageLayout.js +6 -0
  217. package/dist/layouts/VPanel.d.ts +9 -0
  218. package/dist/layouts/VPanel.js +7 -0
  219. package/dist/layouts/XLayout.d.ts +10 -0
  220. package/dist/layouts/XLayout.js +10 -0
  221. package/dist/layouts/YLayout.d.ts +10 -0
  222. package/dist/layouts/YLayout.js +10 -0
  223. package/dist/lib/PlatformRoute.d.ts +5 -0
  224. package/dist/lib/PlatformRoute.js +288 -0
  225. package/dist/lib/WebPlatform.d.ts +13 -0
  226. package/dist/lib/WebPlatform.js +124 -0
  227. package/dist/lib/components/ActivityBar.d.ts +13 -0
  228. package/dist/lib/components/ActivityBar.js +39 -0
  229. package/dist/lib/components/CopyButton.d.ts +8 -0
  230. package/dist/lib/components/CopyButton.js +50 -0
  231. package/dist/lib/components/Header.d.ts +2 -0
  232. package/dist/lib/components/Header.js +74 -0
  233. package/dist/lib/components/QuickActionMenu.d.ts +18 -0
  234. package/dist/lib/components/QuickActionMenu.js +50 -0
  235. package/dist/lib/components/UserButton.d.ts +11 -0
  236. package/dist/lib/components/UserButton.js +66 -0
  237. package/dist/lib/layouts/BorderLayout.tsx +31 -0
  238. package/dist/lib/layouts/CardLayout.tsx +73 -0
  239. package/dist/lib/layouts/CenterLayout.tsx +20 -0
  240. package/dist/lib/layouts/GridLayout.tsx +20 -0
  241. package/dist/lib/layouts/HPanel.tsx +31 -0
  242. package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
  243. package/dist/lib/layouts/MainLayout.tsx +16 -0
  244. package/dist/lib/layouts/PageLayout.tsx +29 -0
  245. package/dist/lib/layouts/VPanel.tsx +27 -0
  246. package/dist/lib/layouts/XLayout.tsx +29 -0
  247. package/dist/lib/layouts/YLayout.tsx +29 -0
  248. package/dist/lib/utils/BeanUtils.d.ts +3 -0
  249. package/dist/lib/utils/BeanUtils.js +75 -0
  250. package/dist/lib/utils/ComponentLoader.d.ts +13 -0
  251. package/dist/lib/utils/ComponentLoader.js +26 -0
  252. package/dist/lib/utils/ExprUtil.d.ts +7 -0
  253. package/dist/lib/utils/ExprUtil.js +44 -0
  254. package/dist/lib/utils/PageUtils.d.ts +6 -0
  255. package/dist/lib/utils/PageUtils.js +121 -0
  256. package/dist/lib/utils/ResourceLoader.d.ts +11 -0
  257. package/dist/lib/utils/ResourceLoader.js +37 -0
  258. package/dist/lib/utils/SectionProvider.d.ts +5 -0
  259. package/dist/lib/utils/SectionProvider.js +39 -0
  260. package/dist/lib/utils/initResourceLoader.d.ts +0 -0
  261. package/dist/lib/utils/initResourceLoader.js +95 -0
  262. package/dist/styles/index.css +38 -0
  263. package/dist/templates/BasicTemplate.d.ts +2 -0
  264. package/dist/templates/BasicTemplate.js +14 -0
  265. package/dist/templates/CrudFormTemplate.d.ts +2 -0
  266. package/dist/templates/CrudFormTemplate.js +38 -0
  267. package/dist/templates/DataListTemplate.d.ts +2 -0
  268. package/dist/templates/DataListTemplate.js +13 -0
  269. package/dist/templates/ExplorerTemplate.d.ts +10 -0
  270. package/dist/templates/ExplorerTemplate.js +17 -0
  271. package/dist/templates/TxnFormTemplate.d.ts +2 -0
  272. package/dist/templates/TxnFormTemplate.js +66 -0
  273. package/dist/templates/WizardTemplate.d.ts +9 -0
  274. package/dist/templates/WizardTemplate.js +37 -0
  275. package/dist/templates/index.d.ts +5 -0
  276. package/dist/templates/index.js +5 -0
  277. package/dist/types/action.d.ts +8 -0
  278. package/dist/types/action.js +1 -0
  279. package/dist/types/component.d.ts +18 -0
  280. package/dist/types/component.js +1 -0
  281. package/dist/types/list.d.ts +14 -0
  282. package/dist/types/list.js +1 -0
  283. package/dist/types/template.d.ts +6 -0
  284. package/dist/types/template.js +1 -0
  285. package/package.json +56 -0
@@ -0,0 +1,157 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Editor from "@monaco-editor/react";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { usePageContext } from "../../core/PageContext";
5
+ import CopyButton from "../../lib/components/CopyButton";
6
+ import UIComponent from "../common/UIComponent";
7
+ import useUIInput from "../common/UIInput";
8
+ const HtmlCode = (props) => {
9
+ const { height = 300, width = "100%", showCopy = true } = props !== null && props !== void 0 ? props : {};
10
+ const pageContext = usePageContext();
11
+ const editorRef = useRef(null);
12
+ const [fontSize, setFontSize] = useState(14);
13
+ const [error, setError] = useState("");
14
+ const [readOnly, setReadOnly] = useState(true);
15
+ const onRefresh = () => {
16
+ const val = getValue();
17
+ setEditorValue(val !== null && val !== void 0 ? val : "");
18
+ };
19
+ const { initialValue, getValue, setValue } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
20
+ const [editorValue, setEditorValue] = useState(() => initialValue !== null && initialValue !== void 0 ? initialValue : "");
21
+ useEffect(() => {
22
+ const unsubscribe = pageContext === null || pageContext === void 0 ? void 0 : pageContext.dependsTo("editable", (val) => {
23
+ var _a;
24
+ const isEditable = val === true || val === "true";
25
+ setReadOnly(!isEditable);
26
+ if (!isEditable) {
27
+ setEditorValue((_a = getValue()) !== null && _a !== void 0 ? _a : "");
28
+ setError("");
29
+ }
30
+ });
31
+ return unsubscribe;
32
+ }, []);
33
+ useEffect(() => {
34
+ return () => {
35
+ editorRef.current = null;
36
+ };
37
+ }, []);
38
+ const handleKeyDown = useCallback((e) => {
39
+ if (e.ctrlKey && e.key === "=") {
40
+ e.preventDefault();
41
+ setFontSize((prev) => Math.min(prev + 1, 40));
42
+ }
43
+ if (e.ctrlKey && e.key === "-") {
44
+ e.preventDefault();
45
+ setFontSize((prev) => Math.max(prev - 1, 8));
46
+ }
47
+ if (e.ctrlKey && e.key === "0") {
48
+ e.preventDefault();
49
+ setFontSize(14);
50
+ }
51
+ }, []);
52
+ useEffect(() => {
53
+ window.addEventListener("keydown", handleKeyDown);
54
+ return () => window.removeEventListener("keydown", handleKeyDown);
55
+ }, [handleKeyDown]);
56
+ useEffect(() => {
57
+ var _a;
58
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.updateOptions({ fontSize });
59
+ }, [fontSize]);
60
+ useEffect(() => {
61
+ var _a;
62
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.updateOptions({ readOnly, domReadOnly: readOnly });
63
+ }, [readOnly]);
64
+ const validateHtml = (code) => {
65
+ if (!code.trim()) {
66
+ setError("");
67
+ return;
68
+ }
69
+ const errors = [];
70
+ const lines = code.split("\n");
71
+ const tagStack = [];
72
+ const tagRegex = /<\/?([a-zA-Z0-9-]+)(\s[^>]*)?>/g;
73
+ for (let i = 0; i < lines.length; i++) {
74
+ const line = lines[i];
75
+ const matches = [...line.matchAll(tagRegex)];
76
+ for (const match of matches) {
77
+ const tagName = match[1].toLowerCase();
78
+ const isClosing = match[0].startsWith("</");
79
+ const selfClosing = /\/>$/.test(match[0]) || ["br", "hr", "img", "input", "meta", "link"].includes(tagName);
80
+ if (!isClosing && !selfClosing) {
81
+ tagStack.push({ tagName, line: i + 1 });
82
+ }
83
+ else if (isClosing) {
84
+ const lastTag = tagStack.pop();
85
+ if (!lastTag || lastTag.tagName !== tagName) {
86
+ errors.push(`Line ${i + 1}: Unmatched closing tag </${tagName}>`);
87
+ }
88
+ }
89
+ }
90
+ if (i === 0 && !line.toLowerCase().includes("<!doctype")) {
91
+ if (code.includes("<html")) {
92
+ errors.push("Missing <!DOCTYPE html> declaration at the top");
93
+ }
94
+ }
95
+ if (i === lines.length - 1 && code.includes("<html")) {
96
+ if (!code.includes("<head"))
97
+ errors.push("Missing <head> tag");
98
+ if (!code.includes("<body"))
99
+ errors.push("Missing <body> tag");
100
+ }
101
+ }
102
+ if (tagStack.length > 0) {
103
+ const unclosed = tagStack.map((t) => `<${t.tagName}> (opened on line ${t.line})`).join(", ");
104
+ errors.push(`Unclosed tag(s): ${unclosed}`);
105
+ }
106
+ setError(errors.length > 0 ? errors.join("\n• ") : "");
107
+ };
108
+ const handleEditorChange = (value) => {
109
+ if (readOnly)
110
+ return;
111
+ const safeValue = value !== null && value !== void 0 ? value : "";
112
+ setEditorValue(safeValue);
113
+ setValue(safeValue); // write through immediately — HTML is always a string
114
+ validateHtml(safeValue);
115
+ };
116
+ const handleEditorDidMount = (editor, monaco) => {
117
+ editorRef.current = editor;
118
+ editor.updateOptions({
119
+ minimap: { enabled: false },
120
+ fontSize,
121
+ lineNumbers: "on",
122
+ renderWhitespace: "selection",
123
+ folding: true,
124
+ bracketPairColorization: { enabled: true },
125
+ formatOnPaste: true,
126
+ formatOnType: true,
127
+ wordWrap: "on",
128
+ autoClosingBrackets: "always",
129
+ autoClosingQuotes: "always",
130
+ suggestOnTriggerCharacters: true,
131
+ });
132
+ };
133
+ return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsxs("div", { className: "relative w-full bg-white", children: [showCopy && (_jsx("div", { className: "absolute top-2 right-4 z-50", children: _jsx(CopyButton, { item: editorValue, copySize: 15, copiedSize: 10, classNameCopied: "!px-[15px] !py-[10px]" }) })), _jsx(Editor, { height: height, width: width, language: "html", value: editorValue, onChange: handleEditorChange, onMount: handleEditorDidMount, theme: "vs-dark", options: {
134
+ readOnly,
135
+ domReadOnly: readOnly,
136
+ padding: { top: 10 },
137
+ selectOnLineNumbers: true,
138
+ automaticLayout: true,
139
+ minimap: { enabled: false },
140
+ fontSize,
141
+ wordWrap: "on",
142
+ lineNumbers: "on",
143
+ folding: true,
144
+ bracketPairColorization: { enabled: true },
145
+ formatOnPaste: true,
146
+ formatOnType: true,
147
+ scrollBeyondLastLine: false,
148
+ smoothScrolling: true,
149
+ cursorBlinking: "smooth",
150
+ renderLineHighlight: "all",
151
+ autoClosingBrackets: "always",
152
+ autoClosingQuotes: "always",
153
+ suggestOnTriggerCharacters: true,
154
+ scrollbar: { vertical: "visible", horizontal: "visible" },
155
+ } }, "html-code-editor"), error && !readOnly && _jsx("p", { className: "text-red-500 text-xs mt-1 px-1 whitespace-pre-line", children: error })] }) })));
156
+ };
157
+ export default HtmlCode;
@@ -0,0 +1,203 @@
1
+ import Editor from "@monaco-editor/react";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { usePageContext } from "../../core/PageContext";
4
+ import CopyButton from "../../lib/components/CopyButton";
5
+ import UIComponent from "../common/UIComponent";
6
+ import useUIInput, { UIInputProps } from "../common/UIInput";
7
+
8
+ type HtmlCodeProps = UIInputProps & {
9
+ height?: number | string;
10
+ width?: number | string;
11
+ showCopy?: boolean;
12
+ };
13
+
14
+ const HtmlCode = (props: HtmlCodeProps) => {
15
+ const { height = 300, width = "100%", showCopy = true } = props ?? {};
16
+
17
+ const pageContext = usePageContext();
18
+ const editorRef = useRef<any>(null);
19
+ const [fontSize, setFontSize] = useState(14);
20
+ const [error, setError] = useState("");
21
+ const [readOnly, setReadOnly] = useState(true);
22
+
23
+ const onRefresh = () => {
24
+ const val = getValue();
25
+ setEditorValue(val ?? "");
26
+ };
27
+
28
+ const { initialValue, getValue, setValue } = useUIInput({ ...props, onRefresh });
29
+
30
+ const [editorValue, setEditorValue] = useState(() => initialValue ?? "");
31
+
32
+ useEffect(() => {
33
+ const unsubscribe = pageContext?.dependsTo("editable", (val: any) => {
34
+ const isEditable = val === true || val === "true";
35
+ setReadOnly(!isEditable);
36
+
37
+ if (!isEditable) {
38
+ setEditorValue(getValue() ?? "");
39
+ setError("");
40
+ }
41
+ });
42
+ return unsubscribe;
43
+ }, []);
44
+
45
+ useEffect(() => {
46
+ return () => {
47
+ editorRef.current = null;
48
+ };
49
+ }, []);
50
+
51
+ const handleKeyDown = useCallback((e: KeyboardEvent) => {
52
+ if (e.ctrlKey && e.key === "=") {
53
+ e.preventDefault();
54
+ setFontSize((prev) => Math.min(prev + 1, 40));
55
+ }
56
+ if (e.ctrlKey && e.key === "-") {
57
+ e.preventDefault();
58
+ setFontSize((prev) => Math.max(prev - 1, 8));
59
+ }
60
+ if (e.ctrlKey && e.key === "0") {
61
+ e.preventDefault();
62
+ setFontSize(14);
63
+ }
64
+ }, []);
65
+
66
+ useEffect(() => {
67
+ window.addEventListener("keydown", handleKeyDown);
68
+ return () => window.removeEventListener("keydown", handleKeyDown);
69
+ }, [handleKeyDown]);
70
+
71
+ useEffect(() => {
72
+ editorRef.current?.updateOptions({ fontSize });
73
+ }, [fontSize]);
74
+
75
+ useEffect(() => {
76
+ editorRef.current?.updateOptions({ readOnly, domReadOnly: readOnly });
77
+ }, [readOnly]);
78
+
79
+ const validateHtml = (code: string) => {
80
+ if (!code.trim()) {
81
+ setError("");
82
+ return;
83
+ }
84
+
85
+ const errors: string[] = [];
86
+ const lines = code.split("\n");
87
+ const tagStack: { tagName: string; line: number }[] = [];
88
+ const tagRegex = /<\/?([a-zA-Z0-9-]+)(\s[^>]*)?>/g;
89
+
90
+ for (let i = 0; i < lines.length; i++) {
91
+ const line = lines[i];
92
+ const matches = [...line.matchAll(tagRegex)];
93
+
94
+ for (const match of matches) {
95
+ const tagName = match[1].toLowerCase();
96
+ const isClosing = match[0].startsWith("</");
97
+ const selfClosing = /\/>$/.test(match[0]) || ["br", "hr", "img", "input", "meta", "link"].includes(tagName);
98
+
99
+ if (!isClosing && !selfClosing) {
100
+ tagStack.push({ tagName, line: i + 1 });
101
+ } else if (isClosing) {
102
+ const lastTag = tagStack.pop();
103
+ if (!lastTag || lastTag.tagName !== tagName) {
104
+ errors.push(`Line ${i + 1}: Unmatched closing tag </${tagName}>`);
105
+ }
106
+ }
107
+ }
108
+
109
+ if (i === 0 && !line.toLowerCase().includes("<!doctype")) {
110
+ if (code.includes("<html")) {
111
+ errors.push("Missing <!DOCTYPE html> declaration at the top");
112
+ }
113
+ }
114
+
115
+ if (i === lines.length - 1 && code.includes("<html")) {
116
+ if (!code.includes("<head")) errors.push("Missing <head> tag");
117
+ if (!code.includes("<body")) errors.push("Missing <body> tag");
118
+ }
119
+ }
120
+
121
+ if (tagStack.length > 0) {
122
+ const unclosed = tagStack.map((t) => `<${t.tagName}> (opened on line ${t.line})`).join(", ");
123
+ errors.push(`Unclosed tag(s): ${unclosed}`);
124
+ }
125
+
126
+ setError(errors.length > 0 ? errors.join("\n• ") : "");
127
+ };
128
+
129
+ const handleEditorChange = (value?: string) => {
130
+ if (readOnly) return;
131
+ const safeValue = value ?? "";
132
+ setEditorValue(safeValue);
133
+ setValue(safeValue); // write through immediately — HTML is always a string
134
+ validateHtml(safeValue);
135
+ };
136
+
137
+ const handleEditorDidMount = (editor: any, monaco: any) => {
138
+ editorRef.current = editor;
139
+
140
+ editor.updateOptions({
141
+ minimap: { enabled: false },
142
+ fontSize,
143
+ lineNumbers: "on",
144
+ renderWhitespace: "selection",
145
+ folding: true,
146
+ bracketPairColorization: { enabled: true },
147
+ formatOnPaste: true,
148
+ formatOnType: true,
149
+ wordWrap: "on",
150
+ autoClosingBrackets: "always",
151
+ autoClosingQuotes: "always",
152
+ suggestOnTriggerCharacters: true,
153
+ });
154
+ };
155
+
156
+ return (
157
+ <UIComponent {...(props ?? {})}>
158
+ <div className="relative w-full bg-white">
159
+ {showCopy && (
160
+ <div className="absolute top-2 right-4 z-50">
161
+ <CopyButton item={editorValue} copySize={15} copiedSize={10} classNameCopied="!px-[15px] !py-[10px]" />
162
+ </div>
163
+ )}
164
+ <Editor
165
+ key="html-code-editor"
166
+ height={height}
167
+ width={width}
168
+ language="html"
169
+ value={editorValue}
170
+ onChange={handleEditorChange}
171
+ onMount={handleEditorDidMount}
172
+ theme="vs-dark"
173
+ options={{
174
+ readOnly,
175
+ domReadOnly: readOnly,
176
+ padding: { top: 10 },
177
+ selectOnLineNumbers: true,
178
+ automaticLayout: true,
179
+ minimap: { enabled: false },
180
+ fontSize,
181
+ wordWrap: "on",
182
+ lineNumbers: "on",
183
+ folding: true,
184
+ bracketPairColorization: { enabled: true },
185
+ formatOnPaste: true,
186
+ formatOnType: true,
187
+ scrollBeyondLastLine: false,
188
+ smoothScrolling: true,
189
+ cursorBlinking: "smooth",
190
+ renderLineHighlight: "all",
191
+ autoClosingBrackets: "always",
192
+ autoClosingQuotes: "always",
193
+ suggestOnTriggerCharacters: true,
194
+ scrollbar: { vertical: "visible", horizontal: "visible" },
195
+ }}
196
+ />
197
+ {error && !readOnly && <p className="text-red-500 text-xs mt-1 px-1 whitespace-pre-line">{error}</p>}
198
+ </div>
199
+ </UIComponent>
200
+ );
201
+ };
202
+
203
+ export default HtmlCode;
@@ -0,0 +1,9 @@
1
+ import { UIInputProps } from "../common/UIInput";
2
+ type JsonCodeProps = UIInputProps & {
3
+ height?: number | string;
4
+ width?: number | string;
5
+ showCopy?: boolean;
6
+ onParsed?: (value: any) => void;
7
+ };
8
+ declare const JsonCode: (props: JsonCodeProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default JsonCode;
@@ -0,0 +1,159 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Editor from "@monaco-editor/react";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { usePageContext } from "../../core/PageContext";
5
+ import CopyButton from "../../lib/components/CopyButton";
6
+ import UIComponent from "../common/UIComponent";
7
+ import useUIInput from "../common/UIInput";
8
+ const JsonCode = (props) => {
9
+ const { height = 300, width = "100%", showCopy = true, onParsed } = props !== null && props !== void 0 ? props : {};
10
+ const pageContext = usePageContext();
11
+ const editorRef = useRef(null);
12
+ const [fontSize, setFontSize] = useState(14);
13
+ const [error, setError] = useState("");
14
+ const [readOnly, setReadOnly] = useState(true);
15
+ const stringify = (val) => {
16
+ if (val == null)
17
+ return "";
18
+ try {
19
+ return typeof val === "string" ? val : JSON.stringify(val, null, 2);
20
+ }
21
+ catch (error) {
22
+ console.error("Error stringifying value:", error);
23
+ return "";
24
+ }
25
+ };
26
+ const onRefresh = () => {
27
+ const val = getValue();
28
+ updateValue(val);
29
+ };
30
+ // Initialize once from pageContext — no buffering
31
+ const { initialValue, getValue, setValue } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
32
+ const [editorValue, setEditorValue] = useState(stringify(initialValue));
33
+ const updateValue = (value) => {
34
+ if (error != null && error !== "") {
35
+ // no updating of editor value if there's an error
36
+ return;
37
+ }
38
+ const strValue = stringify(value);
39
+ let strEditorValue = "";
40
+ try {
41
+ const parsedEditorValue = JSON.parse(editorValue !== null && editorValue !== void 0 ? editorValue : "");
42
+ strEditorValue = stringify(parsedEditorValue);
43
+ }
44
+ catch (e) { }
45
+ const matched = strValue === strEditorValue;
46
+ // console.log("updateValue ", { value, strValue, strEditorValue, matched });
47
+ if (!matched) {
48
+ setEditorValue(strValue);
49
+ }
50
+ };
51
+ useEffect(() => {
52
+ const unsubscribe = pageContext === null || pageContext === void 0 ? void 0 : pageContext.dependsTo("editable", (val) => {
53
+ const isEditable = val === true || val === "true";
54
+ setReadOnly(!isEditable);
55
+ setError("");
56
+ if (!isEditable) {
57
+ const val = getValue();
58
+ updateValue(val);
59
+ }
60
+ });
61
+ return unsubscribe;
62
+ }, []);
63
+ useEffect(() => {
64
+ return () => {
65
+ // console.log("unmount");
66
+ editorRef.current = null;
67
+ };
68
+ }, []);
69
+ const handleKeyDown = useCallback((e) => {
70
+ if (e.ctrlKey && e.key === "=") {
71
+ e.preventDefault();
72
+ setFontSize((prev) => Math.min(prev + 1, 40));
73
+ }
74
+ if (e.ctrlKey && e.key === "-") {
75
+ e.preventDefault();
76
+ setFontSize((prev) => Math.max(prev - 1, 8));
77
+ }
78
+ if (e.ctrlKey && e.key === "0") {
79
+ e.preventDefault();
80
+ setFontSize(14);
81
+ }
82
+ }, []);
83
+ useEffect(() => {
84
+ window.addEventListener("keydown", handleKeyDown);
85
+ return () => window.removeEventListener("keydown", handleKeyDown);
86
+ }, [handleKeyDown]);
87
+ useEffect(() => {
88
+ var _a;
89
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.updateOptions({ fontSize });
90
+ }, [fontSize]);
91
+ useEffect(() => {
92
+ var _a;
93
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.updateOptions({ readOnly, domReadOnly: readOnly });
94
+ }, [readOnly]);
95
+ const handleEditorChange = (value) => {
96
+ if (readOnly)
97
+ return;
98
+ const safeValue = value !== null && value !== void 0 ? value : "";
99
+ setEditorValue(safeValue);
100
+ try {
101
+ const parsed = JSON.parse(safeValue);
102
+ setValue(parsed); // write through to pageContext immediately
103
+ setError("");
104
+ onParsed === null || onParsed === void 0 ? void 0 : onParsed(parsed);
105
+ }
106
+ catch (e) {
107
+ setError(e.message);
108
+ }
109
+ };
110
+ const handleEditorDidMount = (editor, monaco) => {
111
+ editorRef.current = editor;
112
+ try {
113
+ monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
114
+ validate: true,
115
+ allowComments: false,
116
+ schemas: [],
117
+ enableSchemaRequest: true,
118
+ });
119
+ }
120
+ catch (e) {
121
+ console.warn("Monaco JSON diagnostics setup failed:", e);
122
+ }
123
+ editor.updateOptions({
124
+ minimap: { enabled: false },
125
+ fontSize,
126
+ lineNumbers: "on",
127
+ renderWhitespace: "selection",
128
+ folding: false,
129
+ bracketPairColorization: { enabled: true },
130
+ formatOnPaste: false,
131
+ formatOnType: false,
132
+ });
133
+ };
134
+ // useEffect(() => {
135
+ // console.log("editor value changed", editorValue, getValue());
136
+ // }, [editorValue]);
137
+ return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsxs("div", { className: "relative w-full bg-white", children: [showCopy && (_jsx("div", { className: "absolute top-2 right-4 z-50", children: _jsx(CopyButton, { item: editorValue !== null && editorValue !== void 0 ? editorValue : "", copySize: 15, copiedSize: 10, classNameCopied: "!px-[15px] !py-[10px]" }) })), _jsx(Editor, { height: height, width: width, language: "json", value: editorValue !== null && editorValue !== void 0 ? editorValue : "", onChange: handleEditorChange, onMount: handleEditorDidMount, theme: "vs-dark", options: {
138
+ readOnly,
139
+ domReadOnly: readOnly,
140
+ padding: { top: 10 },
141
+ selectOnLineNumbers: true,
142
+ automaticLayout: true,
143
+ minimap: { enabled: false },
144
+ fontSize,
145
+ wordWrap: "off",
146
+ lineNumbers: "on",
147
+ renderWhitespace: "selection",
148
+ folding: false,
149
+ bracketPairColorization: { enabled: true },
150
+ formatOnType: false,
151
+ formatOnPaste: false,
152
+ scrollBeyondLastLine: false,
153
+ smoothScrolling: true,
154
+ cursorBlinking: "smooth",
155
+ renderLineHighlight: "all",
156
+ scrollbar: { vertical: "visible", horizontal: "visible" },
157
+ } }, "json-code-viewer"), error && !readOnly && _jsx("p", { className: "text-red-500 text-xs mt-1 px-1", children: error })] }) })));
158
+ };
159
+ export default JsonCode;