@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,78 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import UIComponent from "../common/UIComponent";
|
|
3
|
+
import useUIInput, { UIInputProps } from "../common/UIInput";
|
|
4
|
+
|
|
5
|
+
type SelectOption = {
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type SelectFieldProps = UIInputProps & {
|
|
11
|
+
required?: boolean;
|
|
12
|
+
immediate?: boolean;
|
|
13
|
+
options?: SelectOption[];
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const SelectField = (props: SelectFieldProps) => {
|
|
19
|
+
const { immediate = true, options = [], placeholder } = props ?? {};
|
|
20
|
+
const [focused, setFocused] = useState(false);
|
|
21
|
+
const selectRef = useRef<HTMLSelectElement | null>(null);
|
|
22
|
+
const valueRef = useRef<string>("");
|
|
23
|
+
|
|
24
|
+
const className = "border rounded px-2 py-1 w-full";
|
|
25
|
+
|
|
26
|
+
const handleFocus = () => {
|
|
27
|
+
setFocused(true);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handleBlur = () => {
|
|
31
|
+
if (!immediate) {
|
|
32
|
+
setValue(selectValue);
|
|
33
|
+
}
|
|
34
|
+
setFocused(false);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const onRefresh = () => {
|
|
38
|
+
setSelectValue(getValue());
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const { initialValue, getValue, setValue, binding } = useUIInput({ ...props, onRefresh });
|
|
42
|
+
valueRef.current = initialValue ?? "";
|
|
43
|
+
const [selectValue, setSelectValue] = useState(valueRef.current);
|
|
44
|
+
|
|
45
|
+
const onChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
46
|
+
const text = e.target.value ?? "";
|
|
47
|
+
|
|
48
|
+
if (text !== selectValue) {
|
|
49
|
+
valueRef.current = text;
|
|
50
|
+
setSelectValue(valueRef.current);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (immediate) {
|
|
54
|
+
setValue(text);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
props.onChange?.(text);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<UIComponent {...(props ?? {})}>
|
|
62
|
+
<select ref={selectRef} onChange={onChange} value={selectValue} onFocus={handleFocus} onBlur={handleBlur} className={className}>
|
|
63
|
+
{placeholder && (
|
|
64
|
+
<option value="" disabled>
|
|
65
|
+
{placeholder}
|
|
66
|
+
</option>
|
|
67
|
+
)}
|
|
68
|
+
{options.map((opt) => (
|
|
69
|
+
<option key={opt.value} value={opt.value}>
|
|
70
|
+
{opt.label}
|
|
71
|
+
</option>
|
|
72
|
+
))}
|
|
73
|
+
</select>
|
|
74
|
+
</UIComponent>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default SelectField;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UIInputProps } from "../common/UIInput";
|
|
2
|
+
type SqlCodeProps = UIInputProps & {
|
|
3
|
+
height?: number | string;
|
|
4
|
+
width?: number | string;
|
|
5
|
+
showCopy?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const SqlCode: (props: SqlCodeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default SqlCode;
|
|
@@ -0,0 +1,121 @@
|
|
|
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 SqlCode = (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 validateSql = (value) => {
|
|
65
|
+
if (!value.trim()) {
|
|
66
|
+
setError("");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const forbidden = /drop\s+table|delete\s+from/gi;
|
|
70
|
+
if (forbidden.test(value)) {
|
|
71
|
+
setError("Dangerous SQL statement detected.");
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
setError("");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const handleEditorChange = (value) => {
|
|
78
|
+
if (readOnly)
|
|
79
|
+
return;
|
|
80
|
+
const safeValue = value !== null && value !== void 0 ? value : "";
|
|
81
|
+
setEditorValue(safeValue);
|
|
82
|
+
setValue(safeValue); // SQL is always a string, write through immediately
|
|
83
|
+
validateSql(safeValue);
|
|
84
|
+
};
|
|
85
|
+
const handleEditorDidMount = (editor, monaco) => {
|
|
86
|
+
editorRef.current = editor;
|
|
87
|
+
monaco.languages.register({ id: "sql" });
|
|
88
|
+
editor.updateOptions({
|
|
89
|
+
minimap: { enabled: false },
|
|
90
|
+
fontSize,
|
|
91
|
+
lineNumbers: "on",
|
|
92
|
+
renderWhitespace: "selection",
|
|
93
|
+
folding: true,
|
|
94
|
+
bracketPairColorization: { enabled: true },
|
|
95
|
+
formatOnPaste: true,
|
|
96
|
+
formatOnType: true,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
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: "sql", value: editorValue, onChange: handleEditorChange, onMount: handleEditorDidMount, theme: "vs-dark", options: {
|
|
100
|
+
readOnly,
|
|
101
|
+
domReadOnly: readOnly,
|
|
102
|
+
padding: { top: 10 },
|
|
103
|
+
selectOnLineNumbers: true,
|
|
104
|
+
automaticLayout: true,
|
|
105
|
+
minimap: { enabled: false },
|
|
106
|
+
fontSize,
|
|
107
|
+
wordWrap: "off",
|
|
108
|
+
lineNumbers: "on",
|
|
109
|
+
renderWhitespace: "selection",
|
|
110
|
+
folding: true,
|
|
111
|
+
bracketPairColorization: { enabled: true },
|
|
112
|
+
formatOnPaste: true,
|
|
113
|
+
formatOnType: true,
|
|
114
|
+
scrollBeyondLastLine: false,
|
|
115
|
+
smoothScrolling: true,
|
|
116
|
+
cursorBlinking: "smooth",
|
|
117
|
+
renderLineHighlight: "all",
|
|
118
|
+
scrollbar: { vertical: "visible", horizontal: "visible" },
|
|
119
|
+
} }, "sql-code-editor"), error && !readOnly && _jsx("p", { className: "text-red-500 text-xs mt-1 px-1", children: error })] }) })));
|
|
120
|
+
};
|
|
121
|
+
export default SqlCode;
|
|
@@ -0,0 +1,162 @@
|
|
|
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 SqlCodeProps = UIInputProps & {
|
|
9
|
+
height?: number | string;
|
|
10
|
+
width?: number | string;
|
|
11
|
+
showCopy?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const SqlCode = (props: SqlCodeProps) => {
|
|
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 validateSql = (value: string) => {
|
|
80
|
+
if (!value.trim()) {
|
|
81
|
+
setError("");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const forbidden = /drop\s+table|delete\s+from/gi;
|
|
85
|
+
if (forbidden.test(value)) {
|
|
86
|
+
setError("Dangerous SQL statement detected.");
|
|
87
|
+
} else {
|
|
88
|
+
setError("");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleEditorChange = (value?: string) => {
|
|
93
|
+
if (readOnly) return;
|
|
94
|
+
const safeValue = value ?? "";
|
|
95
|
+
setEditorValue(safeValue);
|
|
96
|
+
setValue(safeValue); // SQL is always a string, write through immediately
|
|
97
|
+
validateSql(safeValue);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleEditorDidMount = (editor: any, monaco: any) => {
|
|
101
|
+
editorRef.current = editor;
|
|
102
|
+
|
|
103
|
+
monaco.languages.register({ id: "sql" });
|
|
104
|
+
|
|
105
|
+
editor.updateOptions({
|
|
106
|
+
minimap: { enabled: false },
|
|
107
|
+
fontSize,
|
|
108
|
+
lineNumbers: "on",
|
|
109
|
+
renderWhitespace: "selection",
|
|
110
|
+
folding: true,
|
|
111
|
+
bracketPairColorization: { enabled: true },
|
|
112
|
+
formatOnPaste: true,
|
|
113
|
+
formatOnType: true,
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<UIComponent {...(props ?? {})}>
|
|
119
|
+
<div className="relative w-full bg-white">
|
|
120
|
+
{showCopy && (
|
|
121
|
+
<div className="absolute top-2 right-4 z-50">
|
|
122
|
+
<CopyButton item={editorValue} copySize={15} copiedSize={10} classNameCopied="!px-[15px] !py-[10px]" />
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
<Editor
|
|
126
|
+
key="sql-code-editor"
|
|
127
|
+
height={height}
|
|
128
|
+
width={width}
|
|
129
|
+
language="sql"
|
|
130
|
+
value={editorValue}
|
|
131
|
+
onChange={handleEditorChange}
|
|
132
|
+
onMount={handleEditorDidMount}
|
|
133
|
+
theme="vs-dark"
|
|
134
|
+
options={{
|
|
135
|
+
readOnly,
|
|
136
|
+
domReadOnly: readOnly,
|
|
137
|
+
padding: { top: 10 },
|
|
138
|
+
selectOnLineNumbers: true,
|
|
139
|
+
automaticLayout: true,
|
|
140
|
+
minimap: { enabled: false },
|
|
141
|
+
fontSize,
|
|
142
|
+
wordWrap: "off",
|
|
143
|
+
lineNumbers: "on",
|
|
144
|
+
renderWhitespace: "selection",
|
|
145
|
+
folding: true,
|
|
146
|
+
bracketPairColorization: { enabled: true },
|
|
147
|
+
formatOnPaste: true,
|
|
148
|
+
formatOnType: true,
|
|
149
|
+
scrollBeyondLastLine: false,
|
|
150
|
+
smoothScrolling: true,
|
|
151
|
+
cursorBlinking: "smooth",
|
|
152
|
+
renderLineHighlight: "all",
|
|
153
|
+
scrollbar: { vertical: "visible", horizontal: "visible" },
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
{error && !readOnly && <p className="text-red-500 text-xs mt-1 px-1">{error}</p>}
|
|
157
|
+
</div>
|
|
158
|
+
</UIComponent>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default SqlCode;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { usePageContext } from "../../core/PageContext";
|
|
4
|
+
import UIComponent from "../common/UIComponent";
|
|
5
|
+
const operators = [
|
|
6
|
+
{ label: "Matches", value: "matches" },
|
|
7
|
+
{ label: "Equals", value: "equals" },
|
|
8
|
+
{ label: "Not Equals", value: "neq" },
|
|
9
|
+
];
|
|
10
|
+
const StringDecision = (props) => {
|
|
11
|
+
const { name } = props !== null && props !== void 0 ? props : {};
|
|
12
|
+
const [inputOp, setInputOp] = useState("");
|
|
13
|
+
const [inputValue, setInputValue] = useState("");
|
|
14
|
+
const pageContext = usePageContext();
|
|
15
|
+
const binding = pageContext === null || pageContext === void 0 ? void 0 : pageContext.binding;
|
|
16
|
+
const inputClassName = "border rounded px-2 py-1 w-full";
|
|
17
|
+
const selectClassName = "px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed";
|
|
18
|
+
const handleChangeOperator = (e) => {
|
|
19
|
+
setInputOp(e.target.value);
|
|
20
|
+
};
|
|
21
|
+
const handleChangeValue = (e) => {
|
|
22
|
+
setInputValue(e.target.value);
|
|
23
|
+
};
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (name && inputOp && inputValue) {
|
|
26
|
+
pageContext === null || pageContext === void 0 ? void 0 : pageContext.set(name, { [inputOp]: inputValue });
|
|
27
|
+
}
|
|
28
|
+
else if (name && (!inputOp || !inputValue)) {
|
|
29
|
+
pageContext === null || pageContext === void 0 ? void 0 : pageContext.set(name, null);
|
|
30
|
+
}
|
|
31
|
+
}, [name, inputOp, inputValue, pageContext, binding]);
|
|
32
|
+
return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsxs("div", { className: "flex gap-4 items-center justify-center", children: [_jsxs("select", { value: inputOp, onChange: handleChangeOperator, className: selectClassName, children: [_jsx("option", { value: "", children: "Select operator" }), operators.map((op) => (_jsx("option", { value: op.value, children: op.label }, op.value)))] }), _jsx("input", { type: "text", value: inputValue, onChange: handleChangeValue, className: inputClassName, placeholder: "Enter value" })] }) })));
|
|
33
|
+
};
|
|
34
|
+
export default StringDecision;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { usePageContext } from "../../core/PageContext";
|
|
3
|
+
import UIComponent from "../common/UIComponent";
|
|
4
|
+
|
|
5
|
+
const operators = [
|
|
6
|
+
{ label: "Matches", value: "matches" },
|
|
7
|
+
{ label: "Equals", value: "equals" },
|
|
8
|
+
{ label: "Not Equals", value: "neq" },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const StringDecision = (props: Record<string, any>) => {
|
|
12
|
+
const { name } = props ?? {};
|
|
13
|
+
const [inputOp, setInputOp] = useState("");
|
|
14
|
+
const [inputValue, setInputValue] = useState("");
|
|
15
|
+
const pageContext = usePageContext();
|
|
16
|
+
const binding = pageContext?.binding;
|
|
17
|
+
|
|
18
|
+
const inputClassName = "border rounded px-2 py-1 w-full";
|
|
19
|
+
const selectClassName =
|
|
20
|
+
"px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed";
|
|
21
|
+
|
|
22
|
+
const handleChangeOperator = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
23
|
+
setInputOp(e.target.value);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const handleChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
27
|
+
setInputValue(e.target.value);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (name && inputOp && inputValue) {
|
|
32
|
+
pageContext?.set(name, { [inputOp]: inputValue });
|
|
33
|
+
} else if (name && (!inputOp || !inputValue)) {
|
|
34
|
+
pageContext?.set(name, null);
|
|
35
|
+
}
|
|
36
|
+
}, [name, inputOp, inputValue, pageContext, binding]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<UIComponent {...(props ?? {})}>
|
|
40
|
+
<div className="flex gap-4 items-center justify-center">
|
|
41
|
+
<select value={inputOp} onChange={handleChangeOperator} className={selectClassName}>
|
|
42
|
+
<option value="">Select operator</option>
|
|
43
|
+
{operators.map((op) => (
|
|
44
|
+
<option key={op.value} value={op.value}>
|
|
45
|
+
{op.label}
|
|
46
|
+
</option>
|
|
47
|
+
))}
|
|
48
|
+
</select>
|
|
49
|
+
{/* <Select
|
|
50
|
+
options={operators}
|
|
51
|
+
placeholder="Select operator"
|
|
52
|
+
onChange={(value: string) => setInputOp(value)}
|
|
53
|
+
name={""}
|
|
54
|
+
onRefresh={function (): void {
|
|
55
|
+
throw new Error("Function not implemented.");
|
|
56
|
+
}}
|
|
57
|
+
/> */}
|
|
58
|
+
<input type="text" value={inputValue} onChange={handleChangeValue} className={inputClassName} placeholder="Enter value" />
|
|
59
|
+
</div>
|
|
60
|
+
</UIComponent>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default StringDecision;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import UIComponent from "../common/UIComponent";
|
|
4
|
+
import useUIInput from "../common/UIInput";
|
|
5
|
+
const TextField = (props) => {
|
|
6
|
+
const { name, immediate = true } = props !== null && props !== void 0 ? props : {};
|
|
7
|
+
const [focused, setFocused] = useState(false);
|
|
8
|
+
const inputRef = useRef(null);
|
|
9
|
+
const valueRef = useRef("");
|
|
10
|
+
const className = "border rounded px-2 py-1 w-full";
|
|
11
|
+
const handleFocus = () => {
|
|
12
|
+
setFocused(true);
|
|
13
|
+
};
|
|
14
|
+
const handleBlur = () => {
|
|
15
|
+
if (!immediate) {
|
|
16
|
+
setValue(inputValue);
|
|
17
|
+
}
|
|
18
|
+
setFocused(false);
|
|
19
|
+
};
|
|
20
|
+
const onRefresh = () => {
|
|
21
|
+
setInputValue(getValue());
|
|
22
|
+
};
|
|
23
|
+
const { initialValue, getValue, setValue, binding } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
|
|
24
|
+
valueRef.current = initialValue !== null && initialValue !== void 0 ? initialValue : "";
|
|
25
|
+
const [inputValue, setInputValue] = useState(valueRef.current);
|
|
26
|
+
const onChange = (e) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const text = (_a = e.target.value) !== null && _a !== void 0 ? _a : "";
|
|
29
|
+
if (text !== inputValue) {
|
|
30
|
+
valueRef.current = text;
|
|
31
|
+
setInputValue(valueRef.current);
|
|
32
|
+
}
|
|
33
|
+
if (immediate) {
|
|
34
|
+
setValue(text);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsx("input", { type: "text", ref: inputRef, onChange: onChange, value: inputValue, onFocus: handleFocus, onBlur: handleBlur, className: className }) })));
|
|
38
|
+
};
|
|
39
|
+
export default TextField;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import UIComponent from "../common/UIComponent";
|
|
3
|
+
import useUIInput, { UIInputProps } from "../common/UIInput";
|
|
4
|
+
|
|
5
|
+
type TextFieldProps = UIInputProps & {
|
|
6
|
+
required?: boolean;
|
|
7
|
+
immediate?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const TextField = (props: TextFieldProps) => {
|
|
11
|
+
const { name, immediate = true } = props ?? {};
|
|
12
|
+
const [focused, setFocused] = useState(false);
|
|
13
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
14
|
+
const valueRef = useRef<string>("");
|
|
15
|
+
|
|
16
|
+
const className = "border rounded px-2 py-1 w-full";
|
|
17
|
+
|
|
18
|
+
const handleFocus = () => {
|
|
19
|
+
setFocused(true);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const handleBlur = () => {
|
|
23
|
+
if (!immediate) {
|
|
24
|
+
setValue(inputValue);
|
|
25
|
+
}
|
|
26
|
+
setFocused(false);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const onRefresh = () => {
|
|
30
|
+
setInputValue(getValue());
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { initialValue, getValue, setValue, binding } = useUIInput({ ...props, onRefresh });
|
|
34
|
+
valueRef.current = initialValue ?? "";
|
|
35
|
+
const [inputValue, setInputValue] = useState(valueRef.current);
|
|
36
|
+
|
|
37
|
+
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
38
|
+
const text = e.target.value ?? "";
|
|
39
|
+
|
|
40
|
+
if (text !== inputValue) {
|
|
41
|
+
valueRef.current = text;
|
|
42
|
+
setInputValue(valueRef.current);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (immediate) {
|
|
46
|
+
setValue(text);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<UIComponent {...(props ?? {})}>
|
|
52
|
+
<input type="text" ref={inputRef} onChange={onChange} value={inputValue} onFocus={handleFocus} onBlur={handleBlur} className={className} />
|
|
53
|
+
</UIComponent>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default TextField;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UIInputProps } from "../common/UIInput";
|
|
2
|
+
type YearPickerProps = UIInputProps & {
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
immediate?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const YearPicker: (props: YearPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default YearPicker;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import UIComponent from "../common/UIComponent";
|
|
4
|
+
import useUIInput from "../common/UIInput";
|
|
5
|
+
const YearPicker = (props) => {
|
|
6
|
+
const { min = 1900, max, immediate = true } = props !== null && props !== void 0 ? props : {};
|
|
7
|
+
const valueRef = useRef("");
|
|
8
|
+
const [focused, setFocused] = useState(false);
|
|
9
|
+
// Set default max to current year if not provided
|
|
10
|
+
const currentYear = new Date().getFullYear();
|
|
11
|
+
const maxYear = max || currentYear;
|
|
12
|
+
// Generate array of years (descending order)
|
|
13
|
+
const years = Array.from({ length: maxYear - min + 1 }, (_, i) => maxYear - i);
|
|
14
|
+
const onRefresh = () => {
|
|
15
|
+
setInputValue(getValue());
|
|
16
|
+
};
|
|
17
|
+
const { initialValue, getValue, setValue } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
|
|
18
|
+
valueRef.current = initialValue !== null && initialValue !== void 0 ? initialValue : "";
|
|
19
|
+
const [inputValue, setInputValue] = useState(valueRef.current);
|
|
20
|
+
const handleChange = (e) => {
|
|
21
|
+
const year = e.target.value;
|
|
22
|
+
if (year !== inputValue) {
|
|
23
|
+
valueRef.current = year;
|
|
24
|
+
setInputValue(valueRef.current);
|
|
25
|
+
}
|
|
26
|
+
if (immediate) {
|
|
27
|
+
setValue(year);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const handleFocus = () => {
|
|
31
|
+
setFocused(true);
|
|
32
|
+
};
|
|
33
|
+
const handleBlur = () => {
|
|
34
|
+
if (!immediate) {
|
|
35
|
+
setValue(inputValue);
|
|
36
|
+
}
|
|
37
|
+
setFocused(false);
|
|
38
|
+
};
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
// console.log("inputValue", inputValue);
|
|
41
|
+
}, [inputValue]);
|
|
42
|
+
return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsx("div", { className: "flex flex-col gap-1", children: _jsxs("select", { value: inputValue, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, className: "px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed", children: [_jsx("option", { value: "", children: "Select year" }), years.map((year) => (_jsx("option", { value: year, children: year }, year)))] }) }) })));
|
|
43
|
+
};
|
|
44
|
+
export default YearPicker;
|