@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.
- package/dist/components/action/AlertMessage.d.ts +8 -0
- package/dist/components/action/AlertMessage.js +19 -0
- package/dist/components/action/AlertMessage.tsx +38 -0
- package/dist/components/action/Button.d.ts +21 -0
- package/dist/components/action/Button.js +139 -0
- package/dist/components/action/Button.tsx +230 -0
- package/dist/components/action/CancelEdit.d.ts +9 -0
- package/dist/components/action/CancelEdit.js +21 -0
- package/dist/components/action/CancelEdit.tsx +40 -0
- package/dist/components/action/DeleteData.d.ts +13 -0
- package/dist/components/action/DeleteData.js +43 -0
- package/dist/components/action/DeleteData.tsx +73 -0
- package/dist/components/action/Edit.d.ts +9 -0
- package/dist/components/action/Edit.js +21 -0
- package/dist/components/action/Edit.tsx +40 -0
- package/dist/components/action/LookupPage.d.ts +16 -0
- package/dist/components/action/LookupPage.js +62 -0
- package/dist/components/action/LookupPage.tsx +113 -0
- package/dist/components/action/ProcessRunner.d.ts +62 -0
- package/dist/components/action/ProcessRunner.js +156 -0
- package/dist/components/action/ProcessRunner.tsx +337 -0
- package/dist/components/action/Refresh.d.ts +7 -0
- package/dist/components/action/Refresh.js +17 -0
- package/dist/components/action/Refresh.tsx +35 -0
- package/dist/components/action/SaveData.d.ts +10 -0
- package/dist/components/action/SaveData.js +54 -0
- package/dist/components/action/SaveData.tsx +74 -0
- package/dist/components/action/SelectData.d.ts +8 -0
- package/dist/components/action/SelectData.js +29 -0
- package/dist/components/action/SelectData.tsx +47 -0
- package/dist/components/action/Undo.d.ts +9 -0
- package/dist/components/action/Undo.js +31 -0
- package/dist/components/action/Undo.tsx +50 -0
- package/dist/components/action/UpdateContext.d.ts +9 -0
- package/dist/components/action/UpdateContext.js +21 -0
- package/dist/components/action/UpdateContext.tsx +40 -0
- package/dist/components/action/UpdateData.d.ts +9 -0
- package/dist/components/action/UpdateData.js +33 -0
- package/dist/components/action/UpdateData.tsx +49 -0
- package/dist/components/action/ViewBackPage.d.ts +9 -0
- package/dist/components/action/ViewBackPage.js +19 -0
- package/dist/components/action/ViewBackPage.tsx +46 -0
- package/dist/components/action/ViewPage.d.ts +14 -0
- package/dist/components/action/ViewPage.js +88 -0
- package/dist/components/action/ViewPage.tsx +141 -0
- package/dist/components/common/UIComponent.d.ts +11 -0
- package/dist/components/common/UIComponent.js +52 -0
- package/dist/components/common/UIComponent.tsx +84 -0
- package/dist/components/common/UIInput.d.ts +12 -0
- package/dist/components/common/UIInput.js +37 -0
- package/dist/components/common/UIInput.tsx +49 -0
- package/dist/components/common/UIMenu.d.ts +23 -0
- package/dist/components/common/UIMenu.js +61 -0
- package/dist/components/common/UIMenu.tsx +91 -0
- package/dist/components/index.d.ts +37 -0
- package/dist/components/index.js +44 -0
- package/dist/components/index.ts +51 -0
- package/dist/components/input/CodeEditor.d.ts +12 -0
- package/dist/components/input/CodeEditor.js +132 -0
- package/dist/components/input/CodeEditor.tsx +188 -0
- package/dist/components/input/DateField.d.ts +9 -0
- package/dist/components/input/DateField.js +140 -0
- package/dist/components/input/DateField.tsx +274 -0
- package/dist/components/input/DayPicker.d.ts +2 -0
- package/dist/components/input/DayPicker.js +5 -0
- package/dist/components/input/DayPicker.tsx +5 -0
- package/dist/components/input/HtmlCode.d.ts +8 -0
- package/dist/components/input/HtmlCode.js +157 -0
- package/dist/components/input/HtmlCode.tsx +203 -0
- package/dist/components/input/JsonCode.d.ts +9 -0
- package/dist/components/input/JsonCode.js +159 -0
- package/dist/components/input/JsonCode.tsx +205 -0
- package/dist/components/input/MonthPicker.d.ts +2 -0
- package/dist/components/input/MonthPicker.js +5 -0
- package/dist/components/input/MonthPicker.tsx +5 -0
- package/dist/components/input/ScriptCode.d.ts +8 -0
- package/dist/components/input/ScriptCode.js +153 -0
- package/dist/components/input/ScriptCode.tsx +195 -0
- package/dist/components/input/Select.d.ts +14 -0
- package/dist/components/input/Select.js +40 -0
- package/dist/components/input/Select.tsx +78 -0
- package/dist/components/input/SqlCode.d.ts +8 -0
- package/dist/components/input/SqlCode.js +121 -0
- package/dist/components/input/SqlCode.tsx +162 -0
- package/dist/components/input/StringDecision.d.ts +2 -0
- package/dist/components/input/StringDecision.js +34 -0
- package/dist/components/input/StringDecision.tsx +64 -0
- package/dist/components/input/Text.d.ts +7 -0
- package/dist/components/input/Text.js +39 -0
- package/dist/components/input/Text.tsx +57 -0
- package/dist/components/input/YearPicker.d.ts +8 -0
- package/dist/components/input/YearPicker.js +44 -0
- package/dist/components/input/YearPicker.tsx +81 -0
- package/dist/components/list/IconMenu.d.ts +14 -0
- package/dist/components/list/IconMenu.js +72 -0
- package/dist/components/list/IconMenu.tsx +115 -0
- package/dist/components/list/TabMenu.d.ts +10 -0
- package/dist/components/list/TabMenu.js +72 -0
- package/dist/components/list/TabMenu.tsx +127 -0
- package/dist/components/list/TreeMenu.d.ts +14 -0
- package/dist/components/list/TreeMenu.js +207 -0
- package/dist/components/list/TreeMenu.tsx +279 -0
- package/dist/components/list/TxnTaskList.d.ts +2 -0
- package/dist/components/list/TxnTaskList.js +77 -0
- package/dist/components/list/TxnTaskList.tsx +198 -0
- package/dist/components/output/Label.d.ts +8 -0
- package/dist/components/output/Label.js +33 -0
- package/dist/components/output/Label.tsx +51 -0
- package/dist/components/table/DataList.d.ts +88 -0
- package/dist/components/table/DataList.js +361 -0
- package/dist/components/table/DataList.tsx +782 -0
- package/dist/components/table/DataTable.d.ts +46 -0
- package/dist/components/table/DataTable.js +253 -0
- package/dist/components/table/DataTable.tsx +572 -0
- package/dist/components/table/ListHandler.d.ts +42 -0
- package/dist/components/table/ListHandler.js +197 -0
- package/dist/components/table/ListHandler.ts +276 -0
- package/dist/components/table/TableContext.d.ts +33 -0
- package/dist/components/table/TableContext.js +57 -0
- package/dist/components/table/TableContext.tsx +122 -0
- package/dist/components/view/ComponentView.d.ts +8 -0
- package/dist/components/view/ComponentView.js +78 -0
- package/dist/components/view/ComponentView.tsx +102 -0
- package/dist/components/view/FilterView.d.ts +2 -0
- package/dist/components/view/FilterView.js +14 -0
- package/dist/components/view/FilterView.tsx +21 -0
- package/dist/components/view/HtmlForm.d.ts +7 -0
- package/dist/components/view/HtmlForm.js +145 -0
- package/dist/components/view/HtmlForm.tsx +186 -0
- package/dist/components/view/HtmlView.d.ts +9 -0
- package/dist/components/view/HtmlView.js +85 -0
- package/dist/components/view/HtmlView.tsx +114 -0
- package/dist/components/view/IFrameView.d.ts +2 -0
- package/dist/components/view/IFrameView.js +34 -0
- package/dist/components/view/IFrameView.tsx +48 -0
- package/dist/components/view/Modal.d.ts +14 -0
- package/dist/components/view/Modal.js +28 -0
- package/dist/components/view/Modal.tsx +72 -0
- package/dist/components/view/PageView.d.ts +9 -0
- package/dist/components/view/PageView.js +90 -0
- package/dist/components/view/PageView.tsx +131 -0
- package/dist/components/view/PopupView.d.ts +9 -0
- package/dist/components/view/PopupView.js +91 -0
- package/dist/components/view/PopupView.tsx +160 -0
- package/dist/components/view/RootView.d.ts +8 -0
- package/dist/components/view/RootView.js +75 -0
- package/dist/components/view/RootView.tsx +109 -0
- package/dist/components/view/WizardView.d.ts +6 -0
- package/dist/components/view/WizardView.js +34 -0
- package/dist/components/view/WizardView.tsx +48 -0
- package/dist/core/AppContext.d.ts +25 -0
- package/dist/core/AppContext.js +159 -0
- package/dist/core/AuthContext.d.ts +13 -0
- package/dist/core/AuthContext.js +80 -0
- package/dist/core/ComponentCache.d.ts +15 -0
- package/dist/core/ComponentCache.js +25 -0
- package/dist/core/DataContext.d.ts +20 -0
- package/dist/core/DataContext.js +41 -0
- package/dist/core/DynamicComponent.d.ts +12 -0
- package/dist/core/DynamicComponent.js +30 -0
- package/dist/core/DynamicIcon.d.ts +6 -0
- package/dist/core/DynamicIcon.js +48 -0
- package/dist/core/DynamicTemplate.d.ts +4 -0
- package/dist/core/DynamicTemplate.js +17 -0
- package/dist/core/ErrorMessage.d.ts +5 -0
- package/dist/core/ErrorMessage.js +7 -0
- package/dist/core/EventHandler.d.ts +3 -0
- package/dist/core/EventHandler.js +1 -0
- package/dist/core/HtmlCache.d.ts +6 -0
- package/dist/core/HtmlCache.js +17 -0
- package/dist/core/Page.d.ts +6 -0
- package/dist/core/Page.js +141 -0
- package/dist/core/PageCache.d.ts +15 -0
- package/dist/core/PageCache.js +26 -0
- package/dist/core/PageContext.d.ts +49 -0
- package/dist/core/PageContext.js +207 -0
- package/dist/core/PageRegistry.d.ts +7 -0
- package/dist/core/PageRegistry.js +11 -0
- package/dist/core/PageViewContext.d.ts +45 -0
- package/dist/core/PageViewContext.js +277 -0
- package/dist/core/Panel.d.ts +16 -0
- package/dist/core/Panel.js +39 -0
- package/dist/core/RowContext.d.ts +11 -0
- package/dist/core/RowContext.js +16 -0
- package/dist/core/StepHandler.d.ts +9 -0
- package/dist/core/StepHandler.js +39 -0
- package/dist/core/UIDependHandler.d.ts +6 -0
- package/dist/core/UIDependHandler.js +31 -0
- package/dist/core/auth/index.d.ts +18 -0
- package/dist/core/auth/index.js +187 -0
- package/dist/core/auth/session.d.ts +4 -0
- package/dist/core/auth/session.js +45 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-helper.d.ts +27 -0
- package/dist/core/page-helper.js +47 -0
- package/dist/hooks/useUrlParams.d.ts +11 -0
- package/dist/hooks/useUrlParams.js +164 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +69 -0
- package/dist/layouts/BorderLayout.d.ts +14 -0
- package/dist/layouts/BorderLayout.js +8 -0
- package/dist/layouts/CardLayout.d.ts +27 -0
- package/dist/layouts/CardLayout.js +36 -0
- package/dist/layouts/CenterLayout.d.ts +8 -0
- package/dist/layouts/CenterLayout.js +6 -0
- package/dist/layouts/GridLayout.d.ts +9 -0
- package/dist/layouts/GridLayout.js +5 -0
- package/dist/layouts/HPanel.d.ts +11 -0
- package/dist/layouts/HPanel.js +8 -0
- package/dist/layouts/HorizontalLayout.d.ts +11 -0
- package/dist/layouts/HorizontalLayout.js +6 -0
- package/dist/layouts/MainLayout.d.ts +6 -0
- package/dist/layouts/MainLayout.js +5 -0
- package/dist/layouts/PageLayout.d.ts +11 -0
- package/dist/layouts/PageLayout.js +6 -0
- package/dist/layouts/VPanel.d.ts +9 -0
- package/dist/layouts/VPanel.js +7 -0
- package/dist/layouts/XLayout.d.ts +10 -0
- package/dist/layouts/XLayout.js +10 -0
- package/dist/layouts/YLayout.d.ts +10 -0
- package/dist/layouts/YLayout.js +10 -0
- package/dist/lib/PlatformRoute.d.ts +5 -0
- package/dist/lib/PlatformRoute.js +288 -0
- package/dist/lib/WebPlatform.d.ts +13 -0
- package/dist/lib/WebPlatform.js +124 -0
- package/dist/lib/components/ActivityBar.d.ts +13 -0
- package/dist/lib/components/ActivityBar.js +39 -0
- package/dist/lib/components/CopyButton.d.ts +8 -0
- package/dist/lib/components/CopyButton.js +50 -0
- package/dist/lib/components/Header.d.ts +2 -0
- package/dist/lib/components/Header.js +74 -0
- package/dist/lib/components/QuickActionMenu.d.ts +18 -0
- package/dist/lib/components/QuickActionMenu.js +50 -0
- package/dist/lib/components/UserButton.d.ts +11 -0
- package/dist/lib/components/UserButton.js +66 -0
- package/dist/lib/layouts/BorderLayout.tsx +31 -0
- package/dist/lib/layouts/CardLayout.tsx +73 -0
- package/dist/lib/layouts/CenterLayout.tsx +20 -0
- package/dist/lib/layouts/GridLayout.tsx +20 -0
- package/dist/lib/layouts/HPanel.tsx +31 -0
- package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
- package/dist/lib/layouts/MainLayout.tsx +16 -0
- package/dist/lib/layouts/PageLayout.tsx +29 -0
- package/dist/lib/layouts/VPanel.tsx +27 -0
- package/dist/lib/layouts/XLayout.tsx +29 -0
- package/dist/lib/layouts/YLayout.tsx +29 -0
- package/dist/lib/utils/BeanUtils.d.ts +3 -0
- package/dist/lib/utils/BeanUtils.js +75 -0
- package/dist/lib/utils/ComponentLoader.d.ts +13 -0
- package/dist/lib/utils/ComponentLoader.js +26 -0
- package/dist/lib/utils/ExprUtil.d.ts +7 -0
- package/dist/lib/utils/ExprUtil.js +44 -0
- package/dist/lib/utils/PageUtils.d.ts +6 -0
- package/dist/lib/utils/PageUtils.js +121 -0
- package/dist/lib/utils/ResourceLoader.d.ts +11 -0
- package/dist/lib/utils/ResourceLoader.js +37 -0
- package/dist/lib/utils/SectionProvider.d.ts +5 -0
- package/dist/lib/utils/SectionProvider.js +39 -0
- package/dist/lib/utils/initResourceLoader.d.ts +0 -0
- package/dist/lib/utils/initResourceLoader.js +95 -0
- package/dist/styles/index.css +38 -0
- package/dist/templates/BasicTemplate.d.ts +2 -0
- package/dist/templates/BasicTemplate.js +14 -0
- package/dist/templates/CrudFormTemplate.d.ts +2 -0
- package/dist/templates/CrudFormTemplate.js +38 -0
- package/dist/templates/DataListTemplate.d.ts +2 -0
- package/dist/templates/DataListTemplate.js +13 -0
- package/dist/templates/ExplorerTemplate.d.ts +10 -0
- package/dist/templates/ExplorerTemplate.js +17 -0
- package/dist/templates/TxnFormTemplate.d.ts +2 -0
- package/dist/templates/TxnFormTemplate.js +66 -0
- package/dist/templates/WizardTemplate.d.ts +9 -0
- package/dist/templates/WizardTemplate.js +37 -0
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.js +5 -0
- package/dist/types/action.d.ts +8 -0
- package/dist/types/action.js +1 -0
- package/dist/types/component.d.ts +18 -0
- package/dist/types/component.js +1 -0
- package/dist/types/list.d.ts +14 -0
- package/dist/types/list.js +1 -0
- package/dist/types/template.d.ts +6 -0
- package/dist/types/template.js +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
|
|
4
|
+
export type UIComponentProps = {
|
|
5
|
+
name?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
depends?: string;
|
|
8
|
+
visibleWhen?: string;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
labelPosition?: "top" | "left";
|
|
11
|
+
style?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const UIComponent = (props: UIComponentProps) => {
|
|
15
|
+
const { name, title, depends, children, visibleWhen, labelPosition = "top", style } = props ?? {};
|
|
16
|
+
const pageContext = usePageContext();
|
|
17
|
+
|
|
18
|
+
const evaluateVisible = (): boolean => {
|
|
19
|
+
if (!visibleWhen) return true;
|
|
20
|
+
try {
|
|
21
|
+
const context = pageContext?.getAllData() ?? {};
|
|
22
|
+
const stripped = visibleWhen.replace(/^\s*\{([\s\S]*)\}\s*$/, "$1").trim();
|
|
23
|
+
const jsExpr = stripped.replace(/\{\{([\s\S]+?)\}\}/g, (_, path) => {
|
|
24
|
+
const val = path
|
|
25
|
+
.trim()
|
|
26
|
+
.split(".")
|
|
27
|
+
.reduce((obj: any, key: string) => obj?.[key], context);
|
|
28
|
+
return JSON.stringify(val ?? null);
|
|
29
|
+
});
|
|
30
|
+
// eslint-disable-next-line no-new-func
|
|
31
|
+
return Boolean(new Function(`return (${jsExpr})`)());
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.warn("visibleWhen eval error:", e);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const [visible, setVisible] = useState(() => evaluateVisible());
|
|
39
|
+
|
|
40
|
+
const dependHandler = (val: any) => {
|
|
41
|
+
// for visibleWhen
|
|
42
|
+
setVisible(evaluateVisible());
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const unsubscribe = pageContext?.dependsTo(depends || "", dependHandler);
|
|
47
|
+
return unsubscribe;
|
|
48
|
+
}, [depends]);
|
|
49
|
+
|
|
50
|
+
// Re-evaluate when binding changes (same pattern as Label)
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setVisible(evaluateVisible());
|
|
53
|
+
}, [pageContext?.binding?.raw, visibleWhen]);
|
|
54
|
+
|
|
55
|
+
if (!visible) return null;
|
|
56
|
+
|
|
57
|
+
// Top layout (default)
|
|
58
|
+
if (labelPosition === "top") {
|
|
59
|
+
return (
|
|
60
|
+
<div className="flex flex-col gap-1 mb-4">
|
|
61
|
+
{title && (
|
|
62
|
+
<label htmlFor={name} className="text-sm font-medium text-gray-700">
|
|
63
|
+
{title}
|
|
64
|
+
</label>
|
|
65
|
+
)}
|
|
66
|
+
{children}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Left layout
|
|
72
|
+
return (
|
|
73
|
+
<div className="flex items-center gap-2 mb-4">
|
|
74
|
+
{title && (
|
|
75
|
+
<label htmlFor={name} className="text-sm font-medium text-gray-700 min-w-[50px]">
|
|
76
|
+
{title}
|
|
77
|
+
</label>
|
|
78
|
+
)}
|
|
79
|
+
<div className="flex-1">{children}</div>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default UIComponent;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type UIInputProps = {
|
|
2
|
+
name: string;
|
|
3
|
+
depends?: string;
|
|
4
|
+
onRefresh: () => void;
|
|
5
|
+
};
|
|
6
|
+
declare const useUIInput: (props: UIInputProps) => {
|
|
7
|
+
initialValue: any;
|
|
8
|
+
setValue: (value: any) => void;
|
|
9
|
+
getValue: () => any;
|
|
10
|
+
binding: import("@ramesesinc/client").BindingModel;
|
|
11
|
+
};
|
|
12
|
+
export default useUIInput;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
const useUIInput = (props) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const { name, depends, onRefresh } = props !== null && props !== void 0 ? props : {};
|
|
6
|
+
const pageContext = usePageContext();
|
|
7
|
+
// console.log("useIUInput re-render", name, depends, onRefresh);
|
|
8
|
+
const binding = pageContext === null || pageContext === void 0 ? void 0 : pageContext.binding;
|
|
9
|
+
const getValue = () => {
|
|
10
|
+
var _a;
|
|
11
|
+
const val = (_a = pageContext === null || pageContext === void 0 ? void 0 : pageContext.get(name)) !== null && _a !== void 0 ? _a : "";
|
|
12
|
+
// console.log("ui input, get value", name, val, pageContext.getData());
|
|
13
|
+
return val;
|
|
14
|
+
};
|
|
15
|
+
const setValue = (value) => {
|
|
16
|
+
pageContext === null || pageContext === void 0 ? void 0 : pageContext.set(name, value);
|
|
17
|
+
// console.log("after set value", name, pageContext?.get(name));
|
|
18
|
+
};
|
|
19
|
+
const initialValue = (_a = pageContext === null || pageContext === void 0 ? void 0 : pageContext.get(name)) !== null && _a !== void 0 ? _a : "";
|
|
20
|
+
// console.log("ui input init", name, initialValue);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (onRefresh) {
|
|
23
|
+
onRefresh();
|
|
24
|
+
}
|
|
25
|
+
}, [binding === null || binding === void 0 ? void 0 : binding.raw, initialValue]);
|
|
26
|
+
const dependHandler = (val) => {
|
|
27
|
+
if (onRefresh) {
|
|
28
|
+
onRefresh();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const unsubscribe = pageContext === null || pageContext === void 0 ? void 0 : pageContext.dependsTo(depends || "", dependHandler);
|
|
33
|
+
return unsubscribe;
|
|
34
|
+
}, [depends]);
|
|
35
|
+
return { initialValue, setValue, getValue, binding };
|
|
36
|
+
};
|
|
37
|
+
export default useUIInput;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
|
|
4
|
+
export type UIInputProps = {
|
|
5
|
+
name: string;
|
|
6
|
+
depends?: string;
|
|
7
|
+
onRefresh: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const useUIInput = (props: UIInputProps) => {
|
|
11
|
+
const { name, depends, onRefresh } = props ?? {};
|
|
12
|
+
const pageContext = usePageContext();
|
|
13
|
+
// console.log("useIUInput re-render", name, depends, onRefresh);
|
|
14
|
+
const binding = pageContext?.binding;
|
|
15
|
+
|
|
16
|
+
const getValue = () => {
|
|
17
|
+
const val = pageContext?.get(name) ?? "";
|
|
18
|
+
// console.log("ui input, get value", name, val, pageContext.getData());
|
|
19
|
+
return val;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const setValue = (value: any) => {
|
|
23
|
+
pageContext?.set(name, value);
|
|
24
|
+
// console.log("after set value", name, pageContext?.get(name));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const initialValue = pageContext?.get(name) ?? "";
|
|
28
|
+
// console.log("ui input init", name, initialValue);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (onRefresh) {
|
|
31
|
+
onRefresh();
|
|
32
|
+
}
|
|
33
|
+
}, [binding?.raw, initialValue]);
|
|
34
|
+
|
|
35
|
+
const dependHandler = (val: any) => {
|
|
36
|
+
if (onRefresh) {
|
|
37
|
+
onRefresh();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const unsubscribe = pageContext?.dependsTo(depends || "", dependHandler);
|
|
43
|
+
return unsubscribe;
|
|
44
|
+
}, [depends]);
|
|
45
|
+
|
|
46
|
+
return { initialValue, setValue, getValue, binding };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default useUIInput;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type MenuItem = {
|
|
2
|
+
title: string;
|
|
3
|
+
page?: string;
|
|
4
|
+
icon?: React.ReactNode | string;
|
|
5
|
+
mode?: string;
|
|
6
|
+
};
|
|
7
|
+
export type MenuGroup = {
|
|
8
|
+
title: string;
|
|
9
|
+
icon?: React.ReactNode | string;
|
|
10
|
+
items: MenuItem[];
|
|
11
|
+
};
|
|
12
|
+
export type UIMenuProps = {
|
|
13
|
+
items?: Record<string, any>[];
|
|
14
|
+
data?: Record<string, any>;
|
|
15
|
+
menugroup?: string;
|
|
16
|
+
opt?: Record<string, any>;
|
|
17
|
+
};
|
|
18
|
+
declare const useUIMenu: (props: UIMenuProps) => {
|
|
19
|
+
items: MenuGroup[];
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: string | null;
|
|
22
|
+
};
|
|
23
|
+
export default useUIMenu;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
const useUIMenu = (props) => {
|
|
4
|
+
const { items: itemMenus, data, menugroup, opt = {} } = props !== null && props !== void 0 ? props : {};
|
|
5
|
+
const pageContext = usePageContext();
|
|
6
|
+
const [menus, setMenus] = useState([]);
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
// 1️⃣ Static items
|
|
11
|
+
if (Array.isArray(itemMenus) && itemMenus.length > 0) {
|
|
12
|
+
// Check if already grouped (has items array) or flat
|
|
13
|
+
const isGrouped = itemMenus.every((item) => Array.isArray(item.items));
|
|
14
|
+
if (isGrouped) {
|
|
15
|
+
setMenus(itemMenus);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
setMenus([{ title: "", items: itemMenus }]); // ✅ wrap in single group
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const fetchMenus = async () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
setLoading(true);
|
|
25
|
+
setError(null);
|
|
26
|
+
try {
|
|
27
|
+
// 2️⃣ Custom API
|
|
28
|
+
if (data === null || data === void 0 ? void 0 : data.api) {
|
|
29
|
+
const res = await (pageContext === null || pageContext === void 0 ? void 0 : pageContext.execService(data.api, (_a = data.params) !== null && _a !== void 0 ? _a : {}));
|
|
30
|
+
setMenus(Array.isArray(res) ? res : []);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// 3️⃣ Menugroup — fetch categories + items, map to MenuGroup[]
|
|
34
|
+
if (menugroup != null) {
|
|
35
|
+
const menuGroup = await (pageContext === null || pageContext === void 0 ? void 0 : pageContext.getMgmt("menugroups", menugroup));
|
|
36
|
+
const { categories = [] } = menuGroup || {};
|
|
37
|
+
const menusRes = await (pageContext === null || pageContext === void 0 ? void 0 : pageContext.postMgmt("menus", "list", {
|
|
38
|
+
filter: { menugroup },
|
|
39
|
+
sort: { sortorder: 1 },
|
|
40
|
+
}));
|
|
41
|
+
const sorted = Array.isArray(menusRes) ? [...menusRes].sort((a, b) => { var _a, _b; return ((_a = a.sortorder) !== null && _a !== void 0 ? _a : 0) - ((_b = b.sortorder) !== null && _b !== void 0 ? _b : 0); }) : [];
|
|
42
|
+
const mappedItems = categories.map((cat) => ({
|
|
43
|
+
title: cat.title,
|
|
44
|
+
icon: cat.icon,
|
|
45
|
+
items: sorted.filter((m) => m.category === cat.id),
|
|
46
|
+
}));
|
|
47
|
+
setMenus(mappedItems);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
setError((_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : "Failed to load menus");
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
fetchMenus();
|
|
58
|
+
}, [itemMenus, data, menugroup]);
|
|
59
|
+
return { items: menus, loading, error };
|
|
60
|
+
};
|
|
61
|
+
export default useUIMenu;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
|
|
4
|
+
export type MenuItem = {
|
|
5
|
+
title: string;
|
|
6
|
+
page?: string;
|
|
7
|
+
icon?: React.ReactNode | string;
|
|
8
|
+
mode?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type MenuGroup = {
|
|
12
|
+
title: string;
|
|
13
|
+
icon?: React.ReactNode | string;
|
|
14
|
+
items: MenuItem[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type UIMenuProps = {
|
|
18
|
+
items?: Record<string, any>[];
|
|
19
|
+
data?: Record<string, any>;
|
|
20
|
+
menugroup?: string;
|
|
21
|
+
opt?: Record<string, any>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const useUIMenu = (props: UIMenuProps) => {
|
|
25
|
+
const { items: itemMenus, data, menugroup, opt = {} } = props ?? {};
|
|
26
|
+
|
|
27
|
+
const pageContext = usePageContext();
|
|
28
|
+
|
|
29
|
+
const [menus, setMenus] = useState<MenuGroup[]>([]);
|
|
30
|
+
const [loading, setLoading] = useState(false);
|
|
31
|
+
const [error, setError] = useState<string | null>(null);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
// 1️⃣ Static items
|
|
35
|
+
if (Array.isArray(itemMenus) && itemMenus.length > 0) {
|
|
36
|
+
// Check if already grouped (has items array) or flat
|
|
37
|
+
const isGrouped = itemMenus.every((item) => Array.isArray(item.items));
|
|
38
|
+
if (isGrouped) {
|
|
39
|
+
setMenus(itemMenus as MenuGroup[]);
|
|
40
|
+
} else {
|
|
41
|
+
setMenus([{ title: "", items: itemMenus as MenuItem[] }]); // ✅ wrap in single group
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const fetchMenus = async () => {
|
|
47
|
+
setLoading(true);
|
|
48
|
+
setError(null);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// 2️⃣ Custom API
|
|
52
|
+
if (data?.api) {
|
|
53
|
+
const res = await pageContext?.execService(data.api, data.params ?? {});
|
|
54
|
+
setMenus(Array.isArray(res) ? (res as MenuGroup[]) : []);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 3️⃣ Menugroup — fetch categories + items, map to MenuGroup[]
|
|
59
|
+
if (menugroup != null) {
|
|
60
|
+
const menuGroup = await pageContext?.getMgmt("menugroups", menugroup);
|
|
61
|
+
const { categories = [] } = menuGroup || {};
|
|
62
|
+
|
|
63
|
+
const menusRes = await pageContext?.postMgmt("menus", "list", {
|
|
64
|
+
filter: { menugroup },
|
|
65
|
+
sort: { sortorder: 1 },
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const sorted = Array.isArray(menusRes) ? [...menusRes].sort((a, b) => (a.sortorder ?? 0) - (b.sortorder ?? 0)) : [];
|
|
69
|
+
|
|
70
|
+
const mappedItems: MenuGroup[] = categories.map((cat: any) => ({
|
|
71
|
+
title: cat.title,
|
|
72
|
+
icon: cat.icon,
|
|
73
|
+
items: sorted.filter((m: any) => m.category === cat.id),
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
setMenus(mappedItems);
|
|
77
|
+
}
|
|
78
|
+
} catch (err: any) {
|
|
79
|
+
setError(err?.message ?? "Failed to load menus");
|
|
80
|
+
} finally {
|
|
81
|
+
setLoading(false);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
fetchMenus();
|
|
86
|
+
}, [itemMenus, data, menugroup]);
|
|
87
|
+
|
|
88
|
+
return { items: menus, loading, error };
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default useUIMenu;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { default as Button } from "./action/Button";
|
|
2
|
+
export { default as DateField } from "./input/DateField";
|
|
3
|
+
export { default as DayPicker } from "./input/DayPicker";
|
|
4
|
+
export { default as MonthPicker } from "./input/MonthPicker";
|
|
5
|
+
export { default as Select } from "./input/Select";
|
|
6
|
+
export { default as Text } from "./input/Text";
|
|
7
|
+
export { default as YearPicker } from "./input/YearPicker";
|
|
8
|
+
export { default as HtmlCode } from "./input/HtmlCode";
|
|
9
|
+
export { default as JsonCode } from "./input/JsonCode";
|
|
10
|
+
export { default as ScriptCode } from "./input/ScriptCode";
|
|
11
|
+
export { default as SqlCode } from "./input/SqlCode";
|
|
12
|
+
export { default as StringDecision } from "./input/StringDecision";
|
|
13
|
+
export { default as TabMenu } from "./list/TabMenu";
|
|
14
|
+
export { default as TreeMenu } from "./list/TreeMenu";
|
|
15
|
+
export { default as Label } from "./output/Label";
|
|
16
|
+
export { default as DataList } from "./table/DataList";
|
|
17
|
+
export { default as ComponentView } from "./view/ComponentView";
|
|
18
|
+
export { default as FilterView } from "./view/FilterView";
|
|
19
|
+
export { default as HtmlForm } from "./view/HtmlForm";
|
|
20
|
+
export { default as HtmlView } from "./view/HtmlView";
|
|
21
|
+
export { default as IFrameView } from "./view/IFrameView";
|
|
22
|
+
export { default as RootView } from "./view/RootView";
|
|
23
|
+
export { default as WizardView } from "./view/WizardView";
|
|
24
|
+
export { default as AlertMessage } from "./action/AlertMessage";
|
|
25
|
+
export { default as DeleteData } from "./action/DeleteData";
|
|
26
|
+
export { default as Edit } from "./action/Edit";
|
|
27
|
+
export { default as ProcessRunner } from "./action/ProcessRunner";
|
|
28
|
+
export { default as Refresh } from "./action/Refresh";
|
|
29
|
+
export { default as SaveData } from "./action/SaveData";
|
|
30
|
+
export { default as SelectData } from "./action/SelectData";
|
|
31
|
+
export { default as LookupPage } from "./action/LookupPage";
|
|
32
|
+
export { default as UpdateContext } from "./action/UpdateContext";
|
|
33
|
+
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
34
|
+
export { default as ViewPage } from "./action/ViewPage";
|
|
35
|
+
export { default as PageView } from "./view/PageView";
|
|
36
|
+
export { default as IconMenu } from "./list/IconMenu";
|
|
37
|
+
export { default as TxnTaskList } from "./list/TxnTaskList";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export { default as Button } from "./action/Button";
|
|
2
|
+
//inputs
|
|
3
|
+
export { default as DateField } from "./input/DateField";
|
|
4
|
+
export { default as DayPicker } from "./input/DayPicker";
|
|
5
|
+
export { default as MonthPicker } from "./input/MonthPicker";
|
|
6
|
+
export { default as Select } from "./input/Select";
|
|
7
|
+
export { default as Text } from "./input/Text";
|
|
8
|
+
export { default as YearPicker } from "./input/YearPicker";
|
|
9
|
+
//codes
|
|
10
|
+
export { default as HtmlCode } from "./input/HtmlCode";
|
|
11
|
+
export { default as JsonCode } from "./input/JsonCode";
|
|
12
|
+
export { default as ScriptCode } from "./input/ScriptCode";
|
|
13
|
+
export { default as SqlCode } from "./input/SqlCode";
|
|
14
|
+
//conditions
|
|
15
|
+
export { default as StringDecision } from "./input/StringDecision";
|
|
16
|
+
//export { default as YearPicker } from "./input/YearPicker";
|
|
17
|
+
export { default as TabMenu } from "./list/TabMenu";
|
|
18
|
+
export { default as TreeMenu } from "./list/TreeMenu";
|
|
19
|
+
export { default as Label } from "./output/Label";
|
|
20
|
+
export { default as DataList } from "./table/DataList";
|
|
21
|
+
//views
|
|
22
|
+
export { default as ComponentView } from "./view/ComponentView";
|
|
23
|
+
export { default as FilterView } from "./view/FilterView";
|
|
24
|
+
export { default as HtmlForm } from "./view/HtmlForm";
|
|
25
|
+
export { default as HtmlView } from "./view/HtmlView";
|
|
26
|
+
export { default as IFrameView } from "./view/IFrameView";
|
|
27
|
+
export { default as RootView } from "./view/RootView";
|
|
28
|
+
export { default as WizardView } from "./view/WizardView";
|
|
29
|
+
//actions
|
|
30
|
+
export { default as AlertMessage } from "./action/AlertMessage";
|
|
31
|
+
export { default as DeleteData } from "./action/DeleteData";
|
|
32
|
+
export { default as Edit } from "./action/Edit";
|
|
33
|
+
export { default as ProcessRunner } from "./action/ProcessRunner";
|
|
34
|
+
export { default as Refresh } from "./action/Refresh";
|
|
35
|
+
export { default as SaveData } from "./action/SaveData";
|
|
36
|
+
export { default as SelectData } from "./action/SelectData";
|
|
37
|
+
export { default as LookupPage } from "./action/LookupPage";
|
|
38
|
+
export { default as UpdateContext } from "./action/UpdateContext";
|
|
39
|
+
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
40
|
+
export { default as ViewPage } from "./action/ViewPage";
|
|
41
|
+
export { default as PageView } from "./view/PageView";
|
|
42
|
+
//lists
|
|
43
|
+
export { default as IconMenu } from "./list/IconMenu";
|
|
44
|
+
export { default as TxnTaskList } from "./list/TxnTaskList";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { default as Button } from "./action/Button";
|
|
2
|
+
//inputs
|
|
3
|
+
export { default as DateField } from "./input/DateField";
|
|
4
|
+
export { default as DayPicker } from "./input/DayPicker";
|
|
5
|
+
|
|
6
|
+
export { default as MonthPicker } from "./input/MonthPicker";
|
|
7
|
+
export { default as Select } from "./input/Select";
|
|
8
|
+
export { default as Text } from "./input/Text";
|
|
9
|
+
export { default as YearPicker } from "./input/YearPicker";
|
|
10
|
+
|
|
11
|
+
//codes
|
|
12
|
+
export { default as HtmlCode } from "./input/HtmlCode";
|
|
13
|
+
export { default as JsonCode } from "./input/JsonCode";
|
|
14
|
+
export { default as ScriptCode } from "./input/ScriptCode";
|
|
15
|
+
export { default as SqlCode } from "./input/SqlCode";
|
|
16
|
+
|
|
17
|
+
//conditions
|
|
18
|
+
export { default as StringDecision } from "./input/StringDecision";
|
|
19
|
+
|
|
20
|
+
//export { default as YearPicker } from "./input/YearPicker";
|
|
21
|
+
export { default as TabMenu } from "./list/TabMenu";
|
|
22
|
+
export { default as TreeMenu } from "./list/TreeMenu";
|
|
23
|
+
export { default as Label } from "./output/Label";
|
|
24
|
+
export { default as DataList } from "./table/DataList";
|
|
25
|
+
|
|
26
|
+
//views
|
|
27
|
+
export { default as ComponentView } from "./view/ComponentView";
|
|
28
|
+
export { default as FilterView } from "./view/FilterView";
|
|
29
|
+
export { default as HtmlForm } from "./view/HtmlForm";
|
|
30
|
+
export { default as HtmlView } from "./view/HtmlView";
|
|
31
|
+
export { default as IFrameView } from "./view/IFrameView";
|
|
32
|
+
export { default as RootView } from "./view/RootView";
|
|
33
|
+
export { default as WizardView } from "./view/WizardView";
|
|
34
|
+
//actions
|
|
35
|
+
export { default as AlertMessage } from "./action/AlertMessage";
|
|
36
|
+
export { default as DeleteData } from "./action/DeleteData";
|
|
37
|
+
export { default as Edit } from "./action/Edit";
|
|
38
|
+
export { default as ProcessRunner } from "./action/ProcessRunner";
|
|
39
|
+
export { default as Refresh } from "./action/Refresh";
|
|
40
|
+
export { default as SaveData } from "./action/SaveData";
|
|
41
|
+
export { default as SelectData } from "./action/SelectData";
|
|
42
|
+
|
|
43
|
+
export { default as LookupPage } from "./action/LookupPage";
|
|
44
|
+
export { default as UpdateContext } from "./action/UpdateContext";
|
|
45
|
+
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
46
|
+
export { default as ViewPage } from "./action/ViewPage";
|
|
47
|
+
export { default as PageView } from "./view/PageView";
|
|
48
|
+
|
|
49
|
+
//lists
|
|
50
|
+
export { default as IconMenu } from "./list/IconMenu";
|
|
51
|
+
export { default as TxnTaskList } from "./list/TxnTaskList";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UIInputProps } from "../common/UIInput";
|
|
2
|
+
type CodeEditorType = "sql" | "json" | "java" | "javascript" | "html" | "css" | "typescript" | "xml" | "yaml" | "markdown" | "plaintext";
|
|
3
|
+
type CodeEditorProps = UIInputProps & {
|
|
4
|
+
type?: CodeEditorType;
|
|
5
|
+
height?: number | string;
|
|
6
|
+
width?: number | string;
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
immediate?: boolean;
|
|
9
|
+
showCopy?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const CodeEditor: (props: CodeEditorProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default CodeEditor;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useCallback, useEffect } from "react";
|
|
3
|
+
import Editor from "@monaco-editor/react";
|
|
4
|
+
import UIComponent from "../common/UIComponent";
|
|
5
|
+
import useUIInput from "../common/UIInput";
|
|
6
|
+
const languageMap = {
|
|
7
|
+
sql: "sql",
|
|
8
|
+
json: "json",
|
|
9
|
+
java: "groovy",
|
|
10
|
+
javascript: "javascript",
|
|
11
|
+
html: "html",
|
|
12
|
+
css: "css",
|
|
13
|
+
typescript: "typescript",
|
|
14
|
+
xml: "xml",
|
|
15
|
+
yaml: "yaml",
|
|
16
|
+
markdown: "markdown",
|
|
17
|
+
plaintext: "plaintext",
|
|
18
|
+
};
|
|
19
|
+
const CodeEditor = (props) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const { type = "plaintext", height = 300, width = "100%", readOnly = false, immediate = true, showCopy = true, } = props !== null && props !== void 0 ? props : {};
|
|
22
|
+
const editorRef = useRef(null);
|
|
23
|
+
const valueRef = useRef("");
|
|
24
|
+
const [fontSize, setFontSize] = useState(14);
|
|
25
|
+
const [error, setError] = useState("");
|
|
26
|
+
const language = (_a = languageMap[type]) !== null && _a !== void 0 ? _a : type;
|
|
27
|
+
const onRefresh = () => {
|
|
28
|
+
setEditorValue(getValue());
|
|
29
|
+
};
|
|
30
|
+
const { initialValue, getValue, setValue } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
|
|
31
|
+
valueRef.current = initialValue !== null && initialValue !== void 0 ? initialValue : "";
|
|
32
|
+
const [editorValue, setEditorValue] = useState(valueRef.current);
|
|
33
|
+
// Font size keyboard shortcuts
|
|
34
|
+
const handleKeyDown = useCallback((e) => {
|
|
35
|
+
if (e.ctrlKey && e.key === "=") {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
setFontSize((prev) => Math.min(prev + 1, 40));
|
|
38
|
+
}
|
|
39
|
+
if (e.ctrlKey && e.key === "-") {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
setFontSize((prev) => Math.max(prev - 1, 8));
|
|
42
|
+
}
|
|
43
|
+
if (e.ctrlKey && e.key === "0") {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
setFontSize(14);
|
|
46
|
+
}
|
|
47
|
+
}, []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
50
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
51
|
+
}, [handleKeyDown]);
|
|
52
|
+
// JSON-specific validation
|
|
53
|
+
const validateJson = (value) => {
|
|
54
|
+
if (!value.trim()) {
|
|
55
|
+
setError("");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
JSON.parse(value);
|
|
60
|
+
setError("");
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
setError(e.message);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handleEditorChange = (value) => {
|
|
67
|
+
const safeValue = value !== null && value !== void 0 ? value : "";
|
|
68
|
+
setEditorValue(safeValue);
|
|
69
|
+
if (type === "json") {
|
|
70
|
+
validateJson(safeValue);
|
|
71
|
+
}
|
|
72
|
+
if (immediate) {
|
|
73
|
+
setValue(safeValue);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const handleEditorDidMount = (editor, monaco) => {
|
|
77
|
+
editorRef.current = editor;
|
|
78
|
+
if (type === "json") {
|
|
79
|
+
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
80
|
+
validate: true,
|
|
81
|
+
allowComments: false,
|
|
82
|
+
schemas: [],
|
|
83
|
+
enableSchemaRequest: true,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
editor.updateOptions({
|
|
87
|
+
minimap: { enabled: false },
|
|
88
|
+
fontSize,
|
|
89
|
+
lineNumbers: "on",
|
|
90
|
+
renderWhitespace: "selection",
|
|
91
|
+
folding: true,
|
|
92
|
+
bracketPairColorization: { enabled: true },
|
|
93
|
+
formatOnPaste: true,
|
|
94
|
+
formatOnType: true,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
// Sync font size if editor already mounted
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.updateOptions({ fontSize });
|
|
101
|
+
}, [fontSize]);
|
|
102
|
+
/*
|
|
103
|
+
//<CopyButton
|
|
104
|
+
// item={editorValue}
|
|
105
|
+
// copySize={15}
|
|
106
|
+
// copiedSize={10}
|
|
107
|
+
// classNameCopied="!px-[15px] !py-[10px]"
|
|
108
|
+
///>
|
|
109
|
+
*/
|
|
110
|
+
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" })), _jsx(Editor, { height: height, width: width, language: language, value: editorValue, onChange: handleEditorChange, onMount: handleEditorDidMount, theme: "vs-dark", options: {
|
|
111
|
+
readOnly,
|
|
112
|
+
domReadOnly: readOnly,
|
|
113
|
+
padding: { top: 10 },
|
|
114
|
+
selectOnLineNumbers: true,
|
|
115
|
+
automaticLayout: true,
|
|
116
|
+
minimap: { enabled: false },
|
|
117
|
+
fontSize,
|
|
118
|
+
wordWrap: "off",
|
|
119
|
+
lineNumbers: "on",
|
|
120
|
+
renderWhitespace: "selection",
|
|
121
|
+
folding: true,
|
|
122
|
+
bracketPairColorization: { enabled: true },
|
|
123
|
+
formatOnPaste: true,
|
|
124
|
+
formatOnType: true,
|
|
125
|
+
scrollBeyondLastLine: false,
|
|
126
|
+
smoothScrolling: true,
|
|
127
|
+
cursorBlinking: "smooth",
|
|
128
|
+
renderLineHighlight: "all",
|
|
129
|
+
scrollbar: { vertical: "visible", horizontal: "visible" },
|
|
130
|
+
} }), error && type === "json" && (_jsx("p", { className: "text-red-500 text-xs mt-1 px-1", children: error }))] }) })));
|
|
131
|
+
};
|
|
132
|
+
export default CodeEditor;
|