@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,114 @@
|
|
|
1
|
+
import { localAPI } from "@ramesesinc/lib/local-api";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useApp } from "../../core/AppContext";
|
|
4
|
+
import { usePageContext } from "../../core/PageContext";
|
|
5
|
+
import useDependHandler from "../../core/UIDependHandler";
|
|
6
|
+
import { render } from "../../lib/utils/ExprUtil";
|
|
7
|
+
import UIComponent from "../common/UIComponent";
|
|
8
|
+
|
|
9
|
+
type HtmlLabelProps = {
|
|
10
|
+
label?: string;
|
|
11
|
+
depends?: string;
|
|
12
|
+
expr?: string;
|
|
13
|
+
templateid?: string;
|
|
14
|
+
data?: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const Html = (props: HtmlLabelProps) => {
|
|
18
|
+
const { depends, expr, templateid } = props ?? {};
|
|
19
|
+
const [htmlTemplate, setHtmlTemplate] = useState(""); // Store the raw template
|
|
20
|
+
const [renderedHtml, setRenderedHtml] = useState(""); // Store the rendered HTML
|
|
21
|
+
const [resData, setResData] = useState<Record<string, any>>({});
|
|
22
|
+
const pageContext = usePageContext();
|
|
23
|
+
const binding = pageContext?.binding;
|
|
24
|
+
const { tenant, module } = useApp();
|
|
25
|
+
|
|
26
|
+
const loadHtmlContent = async (tempid: string) => {
|
|
27
|
+
try {
|
|
28
|
+
const htmlContent = await localAPI.useMgmt(tenant!, module!).get("html_templates", tempid);
|
|
29
|
+
|
|
30
|
+
if (htmlContent != null) {
|
|
31
|
+
// Store the raw template
|
|
32
|
+
setHtmlTemplate(htmlContent.htmlCode);
|
|
33
|
+
|
|
34
|
+
// Fetch data from API
|
|
35
|
+
const data = pageContext?.getAllData() ?? {};
|
|
36
|
+
|
|
37
|
+
// Render the template with the data
|
|
38
|
+
const rendered = render(htmlContent.htmlCode, data);
|
|
39
|
+
setRenderedHtml(rendered);
|
|
40
|
+
} else {
|
|
41
|
+
setHtmlTemplate("");
|
|
42
|
+
setRenderedHtml("");
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Error loading HTML template:", error);
|
|
46
|
+
setHtmlTemplate("");
|
|
47
|
+
setRenderedHtml("");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Render the expression using ExprUtil
|
|
52
|
+
const renderExpression = (expression: string) => {
|
|
53
|
+
if (!expression) return "";
|
|
54
|
+
try {
|
|
55
|
+
const data = pageContext?.getData() ?? {};
|
|
56
|
+
return render(expression, { data });
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error("Expression render error:", error);
|
|
59
|
+
return expression;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const initialValue = renderExpression(expr ?? "");
|
|
64
|
+
const [value, setValue] = useState(initialValue);
|
|
65
|
+
|
|
66
|
+
const onRefresh = () => {
|
|
67
|
+
const newValue = renderExpression(expr ?? "");
|
|
68
|
+
setValue(newValue);
|
|
69
|
+
|
|
70
|
+
// Re-render the HTML template if data changes
|
|
71
|
+
if (htmlTemplate && resData) {
|
|
72
|
+
const rendered = render(htmlTemplate, resData);
|
|
73
|
+
setRenderedHtml(rendered);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
useDependHandler({ name: depends, onRefresh });
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (templateid != null && templateid.trim() !== "") {
|
|
81
|
+
loadHtmlContent(templateid);
|
|
82
|
+
}
|
|
83
|
+
}, [templateid]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const newValue = renderExpression(expr ?? "");
|
|
87
|
+
setValue(newValue);
|
|
88
|
+
}, [binding?.raw, expr]);
|
|
89
|
+
|
|
90
|
+
// Re-render template when data changes
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (htmlTemplate && resData && Object.keys(resData).length > 0) {
|
|
93
|
+
const rendered = render(htmlTemplate, resData);
|
|
94
|
+
setRenderedHtml(rendered);
|
|
95
|
+
}
|
|
96
|
+
}, [resData, htmlTemplate]);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<UIComponent {...(props ?? {})}>
|
|
100
|
+
{/* Debug info - remove in production */}
|
|
101
|
+
{/* <details style={{ marginBottom: "20px" }}>
|
|
102
|
+
<summary>Debug Data</summary>
|
|
103
|
+
<pre style={{ fontSize: "10px", maxHeight: "200px", overflow: "auto" }}>
|
|
104
|
+
{JSON.stringify(resData, null, 2)}
|
|
105
|
+
</pre>
|
|
106
|
+
</details> */}
|
|
107
|
+
|
|
108
|
+
{/* Rendered HTML */}
|
|
109
|
+
<div className="h-[calc(100vh-80px)] overflow-y-auto overflow-x-auto" dangerouslySetInnerHTML={{ __html: renderedHtml }} />
|
|
110
|
+
</UIComponent>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default Html;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { usePageContext } from "../../core/PageContext";
|
|
5
|
+
const Iframe = (props) => {
|
|
6
|
+
// console.log(props);
|
|
7
|
+
const { url = "", name, depends = "page", width = "100%", height = "100%" } = props !== null && props !== void 0 ? props : {};
|
|
8
|
+
const pageContext = usePageContext();
|
|
9
|
+
const lastValueRef = useRef();
|
|
10
|
+
const [iframeUrl, setIframeUrl] = useState(url);
|
|
11
|
+
const dependHandler = (value) => {
|
|
12
|
+
if (lastValueRef.current === value)
|
|
13
|
+
return; // skip if unchanged
|
|
14
|
+
lastValueRef.current = value;
|
|
15
|
+
// value is expected to be a URL (string)
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
setIframeUrl(value);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!depends)
|
|
22
|
+
return;
|
|
23
|
+
const unsubscribe = pageContext === null || pageContext === void 0 ? void 0 : pageContext.dependsTo(depends, dependHandler);
|
|
24
|
+
return unsubscribe;
|
|
25
|
+
}, [depends]);
|
|
26
|
+
if (!iframeUrl)
|
|
27
|
+
return null;
|
|
28
|
+
return (_jsx("div", { className: "h-[calc(100vh-60px)]", children: _jsx("iframe", { src: iframeUrl, name: name, title: name || "iframe", style: {
|
|
29
|
+
width,
|
|
30
|
+
height,
|
|
31
|
+
border: "none",
|
|
32
|
+
}, loading: "lazy" }) }));
|
|
33
|
+
};
|
|
34
|
+
export default Iframe;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { usePageContext } from "../../core/PageContext";
|
|
5
|
+
|
|
6
|
+
const Iframe = (props: Record<string, any>) => {
|
|
7
|
+
// console.log(props);
|
|
8
|
+
const { url = "", name, depends = "page", width = "100%", height = "100%" } = props ?? {};
|
|
9
|
+
const pageContext = usePageContext();
|
|
10
|
+
const lastValueRef = useRef<any>();
|
|
11
|
+
const [iframeUrl, setIframeUrl] = useState(url);
|
|
12
|
+
|
|
13
|
+
const dependHandler = (value: any) => {
|
|
14
|
+
if (lastValueRef.current === value) return; // skip if unchanged
|
|
15
|
+
lastValueRef.current = value;
|
|
16
|
+
|
|
17
|
+
// value is expected to be a URL (string)
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
setIframeUrl(value);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!depends) return;
|
|
25
|
+
const unsubscribe = pageContext?.dependsTo(depends, dependHandler);
|
|
26
|
+
return unsubscribe;
|
|
27
|
+
}, [depends]);
|
|
28
|
+
|
|
29
|
+
if (!iframeUrl) return null;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="h-[calc(100vh-60px)]">
|
|
33
|
+
<iframe
|
|
34
|
+
src={iframeUrl}
|
|
35
|
+
name={name}
|
|
36
|
+
title={name || "iframe"}
|
|
37
|
+
style={{
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
border: "none",
|
|
41
|
+
}}
|
|
42
|
+
loading="lazy"
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default Iframe;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type ModalRenderFn = (close: () => void) => ReactNode;
|
|
3
|
+
export type ModalProps = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
children: ReactNode | ModalRenderFn;
|
|
7
|
+
title?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
width?: string;
|
|
10
|
+
height?: string;
|
|
11
|
+
hideCloseButton?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare const Modal: ({ open, onClose, title, children, className, width, height, hideCloseButton }: ModalProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export default Modal;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
const Modal = ({ open, onClose, title, children, className, width = "600px", height, hideCloseButton = false }) => {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handleKey = (e) => {
|
|
8
|
+
if (e.key === "Escape") {
|
|
9
|
+
onClose();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
if (open) {
|
|
13
|
+
document.addEventListener("keydown", handleKey);
|
|
14
|
+
}
|
|
15
|
+
return () => {
|
|
16
|
+
document.removeEventListener("keydown", handleKey);
|
|
17
|
+
};
|
|
18
|
+
}, [open, onClose]);
|
|
19
|
+
if (!open)
|
|
20
|
+
return null;
|
|
21
|
+
const handleOverlayClick = (e) => {
|
|
22
|
+
// if (e.target === e.currentTarget) {
|
|
23
|
+
// onClose();
|
|
24
|
+
// }
|
|
25
|
+
};
|
|
26
|
+
return (_jsx("div", { className: "fixed inset-0 z-[9999] flex items-center justify-center bg-black/40", onClick: handleOverlayClick, children: _jsxs("div", { className: clsx("relative bg-white rounded-lg shadow-lg p-2 w-full max-w-[90vw] transition-all duration-300 ease-in-out", className), style: { width, height }, role: "dialog", "aria-modal": "true", "aria-labelledby": title ? "modal-title" : undefined, children: [title && (_jsx("h2", { id: "modal-title", className: "text-lg font-semibold mb-4 border-b pb-2 text-gray-800", children: title })), _jsx("div", { className: "overflow-auto", children: typeof children === "function" ? children(onClose) : children }), !hideCloseButton && (_jsx("button", { onClick: onClose, "aria-label": "Close modal", className: "absolute top-2 right-2 text-gray-500 hover:text-gray-800 transition-colors", children: "\u2715" }))] }) }));
|
|
27
|
+
};
|
|
28
|
+
export default Modal;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { MouseEvent, ReactNode, useEffect } from "react";
|
|
5
|
+
|
|
6
|
+
export type ModalRenderFn = (close: () => void) => ReactNode;
|
|
7
|
+
|
|
8
|
+
export type ModalProps = {
|
|
9
|
+
open: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
children: ReactNode | ModalRenderFn;
|
|
12
|
+
title?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
width?: string; // e.g. "500px" or "50%"
|
|
15
|
+
height?: string; // e.g. "400px" or "80%"
|
|
16
|
+
hideCloseButton?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const Modal = ({ open, onClose, title, children, className, width = "600px", height, hideCloseButton = false }: ModalProps) => {
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const handleKey = (e: KeyboardEvent) => {
|
|
22
|
+
if (e.key === "Escape") {
|
|
23
|
+
onClose();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (open) {
|
|
28
|
+
document.addEventListener("keydown", handleKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
document.removeEventListener("keydown", handleKey);
|
|
33
|
+
};
|
|
34
|
+
}, [open, onClose]);
|
|
35
|
+
|
|
36
|
+
if (!open) return null;
|
|
37
|
+
|
|
38
|
+
const handleOverlayClick = (e: MouseEvent<HTMLDivElement>) => {
|
|
39
|
+
// if (e.target === e.currentTarget) {
|
|
40
|
+
// onClose();
|
|
41
|
+
// }
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/40" onClick={handleOverlayClick}>
|
|
46
|
+
<div
|
|
47
|
+
className={clsx("relative bg-white rounded-lg shadow-lg p-2 w-full max-w-[90vw] transition-all duration-300 ease-in-out", className)}
|
|
48
|
+
style={{ width, height }}
|
|
49
|
+
role="dialog"
|
|
50
|
+
aria-modal="true"
|
|
51
|
+
aria-labelledby={title ? "modal-title" : undefined}
|
|
52
|
+
>
|
|
53
|
+
{title && (
|
|
54
|
+
<h2 id="modal-title" className="text-lg font-semibold mb-4 border-b pb-2 text-gray-800">
|
|
55
|
+
{title}
|
|
56
|
+
</h2>
|
|
57
|
+
)}
|
|
58
|
+
|
|
59
|
+
{/* Modal Content */}
|
|
60
|
+
<div className="overflow-auto">{typeof children === "function" ? children(onClose) : children}</div>
|
|
61
|
+
|
|
62
|
+
{!hideCloseButton && (
|
|
63
|
+
<button onClick={onClose} aria-label="Close modal" className="absolute top-2 right-2 text-gray-500 hover:text-gray-800 transition-colors">
|
|
64
|
+
✕
|
|
65
|
+
</button>
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default Modal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { UIComponentProps } from "../common/UIComponent";
|
|
3
|
+
interface PageViewProps extends UIComponentProps {
|
|
4
|
+
depends?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
fallback?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare const PageView: React.MemoExoticComponent<(props: PageViewProps) => import("react/jsx-runtime").JSX.Element>;
|
|
9
|
+
export default PageView;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
5
|
+
import Page from "../../core/Page";
|
|
6
|
+
import { usePageContext } from "../../core/PageContext";
|
|
7
|
+
import { PageViewProvider, usePageViewContext } from "../../core/PageViewContext";
|
|
8
|
+
import useDependHandler from "../../core/UIDependHandler";
|
|
9
|
+
import { useUrlParams } from "../../hooks/useUrlParams";
|
|
10
|
+
import UIComponent from "../common/UIComponent";
|
|
11
|
+
const StableShell = memo((props) => {
|
|
12
|
+
const { uiProps, slotRef, handle, paths } = props !== null && props !== void 0 ? props : {};
|
|
13
|
+
return (_jsx(UIComponent, Object.assign({}, uiProps, { children: _jsx(PageViewProvider, { handle: handle, paths: paths !== null && paths !== void 0 ? paths : [], children: _jsx(PageSlot, { ref: slotRef }) }) })));
|
|
14
|
+
});
|
|
15
|
+
const PageView = memo((props) => {
|
|
16
|
+
const { name = "selectedPage", depends, url } = props !== null && props !== void 0 ? props : {};
|
|
17
|
+
const [forceUpdate, setForceUpdate] = useState({});
|
|
18
|
+
const providerRef = useRef({});
|
|
19
|
+
const { setAnchorPath } = useUrlParams();
|
|
20
|
+
const slotRef = useRef(null);
|
|
21
|
+
const pageContext = usePageContext();
|
|
22
|
+
const [ownPaths, setOwnPaths] = useState([]);
|
|
23
|
+
const isEmpty = (value) => value == null || value.trim() === "";
|
|
24
|
+
const pageView = usePageViewContext();
|
|
25
|
+
let preferredName = isEmpty(name) ? depends : name;
|
|
26
|
+
let preferredDepends = isEmpty(depends) ? preferredName : depends;
|
|
27
|
+
const newProps = Object.assign(Object.assign({}, props), { name: preferredName, depends: preferredDepends });
|
|
28
|
+
const propsRef = useRef(newProps);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
propsRef.current = newProps;
|
|
31
|
+
});
|
|
32
|
+
const getUrl = () => {
|
|
33
|
+
if (url != null && url.trim() !== "")
|
|
34
|
+
return url;
|
|
35
|
+
if (newProps.name)
|
|
36
|
+
return pageContext.get(newProps.name);
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
const getUrlRef = useRef(getUrl);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
getUrlRef.current = getUrl;
|
|
42
|
+
});
|
|
43
|
+
// Stable handle — never recreated
|
|
44
|
+
const pageViewHandleRef = useRef({
|
|
45
|
+
displayName: "PageView#pageViewHandle",
|
|
46
|
+
init: (ref) => {
|
|
47
|
+
providerRef.current = ref;
|
|
48
|
+
setForceUpdate({});
|
|
49
|
+
},
|
|
50
|
+
renderPage: (page) => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
if (page == null || page.trim() === "") {
|
|
53
|
+
(_a = slotRef.current) === null || _a === void 0 ? void 0 : _a.update(null, "null");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setOwnPaths([page]); // ← track own paths
|
|
57
|
+
const key = "page-" + Math.random().toString(36).slice(2);
|
|
58
|
+
const comp = _createElement(Page, Object.assign({}, propsRef.current, { url: page, key: key }));
|
|
59
|
+
(_b = slotRef.current) === null || _b === void 0 ? void 0 : _b.update(comp, page);
|
|
60
|
+
},
|
|
61
|
+
isStandalone: () => {
|
|
62
|
+
return pageView == null ? true : pageView.isStandalone();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const onRefresh = (val) => {
|
|
66
|
+
setForceUpdate({ val }); // ← carry the value
|
|
67
|
+
};
|
|
68
|
+
useDependHandler({ name: newProps.depends, onRefresh });
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const prov = providerRef.current;
|
|
71
|
+
if (prov == null || typeof prov.setPage !== "function")
|
|
72
|
+
return;
|
|
73
|
+
const url = getUrlRef.current();
|
|
74
|
+
// console.log("pageView forceUpdate", url, providerRef.current);
|
|
75
|
+
providerRef.current.setPage(url);
|
|
76
|
+
}, [forceUpdate]);
|
|
77
|
+
return _jsx(StableShell, { uiProps: newProps, handle: pageViewHandleRef.current, slotRef: slotRef, paths: ownPaths });
|
|
78
|
+
});
|
|
79
|
+
const PageSlot = memo(forwardRef((_, ref) => {
|
|
80
|
+
const [content, setContent] = useState(null);
|
|
81
|
+
const [opt, setOpt] = useState(null);
|
|
82
|
+
useImperativeHandle(ref, () => ({
|
|
83
|
+
update: (content, opt) => {
|
|
84
|
+
setContent(content);
|
|
85
|
+
setOpt(opt);
|
|
86
|
+
},
|
|
87
|
+
}), []);
|
|
88
|
+
return _jsx(_Fragment, { children: content == null ? null : content });
|
|
89
|
+
}));
|
|
90
|
+
export default PageView;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
+
import Page from "../../core/Page";
|
|
5
|
+
import { usePageContext } from "../../core/PageContext";
|
|
6
|
+
import { PageViewContextValue, PageViewHandle, PageViewProvider, usePageViewContext } from "../../core/PageViewContext";
|
|
7
|
+
import useDependHandler from "../../core/UIDependHandler";
|
|
8
|
+
import { useUrlParams } from "../../hooks/useUrlParams";
|
|
9
|
+
import UIComponent, { UIComponentProps } from "../common/UIComponent";
|
|
10
|
+
|
|
11
|
+
type StableShellProps = {
|
|
12
|
+
uiProps: Record<string, any>;
|
|
13
|
+
handle: PageViewHandle;
|
|
14
|
+
slotRef: React.RefObject<PageSlotHandle>;
|
|
15
|
+
paths: string[]; // ← new
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const StableShell = memo((props: StableShellProps) => {
|
|
19
|
+
const { uiProps, slotRef, handle, paths } = props ?? {};
|
|
20
|
+
return (
|
|
21
|
+
<UIComponent {...uiProps}>
|
|
22
|
+
<PageViewProvider handle={handle} paths={paths ?? []}>
|
|
23
|
+
<PageSlot ref={slotRef} />
|
|
24
|
+
</PageViewProvider>
|
|
25
|
+
</UIComponent>
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
interface PageViewProps extends UIComponentProps {
|
|
30
|
+
depends?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
fallback?: React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const PageView = memo((props: PageViewProps) => {
|
|
36
|
+
const { name = "selectedPage", depends, url } = props ?? {};
|
|
37
|
+
const [forceUpdate, setForceUpdate] = useState({});
|
|
38
|
+
const providerRef = useRef<PageViewContextValue>({} as PageViewContextValue);
|
|
39
|
+
const { setAnchorPath } = useUrlParams();
|
|
40
|
+
const slotRef = useRef<PageSlotHandle>(null);
|
|
41
|
+
const pageContext = usePageContext();
|
|
42
|
+
const [ownPaths, setOwnPaths] = useState<string[]>([]);
|
|
43
|
+
const isEmpty = (value: string | null | undefined) => value == null || value.trim() === "";
|
|
44
|
+
|
|
45
|
+
const pageView = usePageViewContext();
|
|
46
|
+
|
|
47
|
+
let preferredName = isEmpty(name) ? depends : name;
|
|
48
|
+
let preferredDepends = isEmpty(depends) ? preferredName : depends;
|
|
49
|
+
|
|
50
|
+
const newProps = { ...props, name: preferredName, depends: preferredDepends };
|
|
51
|
+
|
|
52
|
+
const propsRef = useRef(newProps);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
propsRef.current = newProps;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const getUrl = () => {
|
|
58
|
+
if (url != null && url.trim() !== "") return url;
|
|
59
|
+
if (newProps.name) return pageContext.get(newProps.name);
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getUrlRef = useRef(getUrl);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
getUrlRef.current = getUrl;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Stable handle — never recreated
|
|
69
|
+
const pageViewHandleRef = useRef({
|
|
70
|
+
displayName: "PageView#pageViewHandle",
|
|
71
|
+
init: (ref: PageViewContextValue) => {
|
|
72
|
+
providerRef.current = ref;
|
|
73
|
+
setForceUpdate({});
|
|
74
|
+
},
|
|
75
|
+
renderPage: (page: string | null) => {
|
|
76
|
+
if (page == null || page.trim() === "") {
|
|
77
|
+
slotRef.current?.update(null, "null");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
setOwnPaths([page]); // ← track own paths
|
|
81
|
+
const key = "page-" + Math.random().toString(36).slice(2);
|
|
82
|
+
const comp = <Page {...propsRef.current} url={page} key={key} />;
|
|
83
|
+
slotRef.current?.update(comp, page);
|
|
84
|
+
},
|
|
85
|
+
isStandalone: () => {
|
|
86
|
+
return pageView == null ? true : pageView.isStandalone();
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const onRefresh = (val?: any) => {
|
|
91
|
+
setForceUpdate({ val }); // ← carry the value
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
useDependHandler({ name: newProps.depends, onRefresh });
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const prov = providerRef.current;
|
|
98
|
+
if (prov == null || typeof prov.setPage !== "function") return;
|
|
99
|
+
|
|
100
|
+
const url = getUrlRef.current();
|
|
101
|
+
// console.log("pageView forceUpdate", url, providerRef.current);
|
|
102
|
+
providerRef.current.setPage(url);
|
|
103
|
+
}, [forceUpdate]);
|
|
104
|
+
|
|
105
|
+
return <StableShell uiProps={newProps} handle={pageViewHandleRef.current} slotRef={slotRef} paths={ownPaths} />;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
type PageSlotHandle = {
|
|
109
|
+
update: (content: React.ReactNode, opt?: any) => void;
|
|
110
|
+
};
|
|
111
|
+
const PageSlot = memo(
|
|
112
|
+
forwardRef<PageSlotHandle>((_, ref) => {
|
|
113
|
+
const [content, setContent] = useState<React.ReactNode>(null);
|
|
114
|
+
const [opt, setOpt] = useState<any>(null);
|
|
115
|
+
|
|
116
|
+
useImperativeHandle(
|
|
117
|
+
ref,
|
|
118
|
+
() => ({
|
|
119
|
+
update: (content: React.ReactNode, opt?: any) => {
|
|
120
|
+
setContent(content);
|
|
121
|
+
setOpt(opt);
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
[],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return <>{content == null ? null : content}</>;
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
export default PageView;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventHandler } from "../../core";
|
|
2
|
+
type PopupViewProps = {
|
|
3
|
+
url: string;
|
|
4
|
+
popupClassName?: string;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
eventHandler?: EventHandler | null;
|
|
7
|
+
};
|
|
8
|
+
declare const PopupView: (props: PopupViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default PopupView;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { getError } from "@ramesesinc/client";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
5
|
+
import { twMerge } from "tailwind-merge";
|
|
6
|
+
import Page from "../../core/Page";
|
|
7
|
+
import { PageViewProvider } from "../../core/PageViewContext";
|
|
8
|
+
const PopupView = (props) => {
|
|
9
|
+
const { url, popupClassName, onClose = () => { }, eventHandler } = props !== null && props !== void 0 ? props : {};
|
|
10
|
+
const [paths, setPaths] = useState([]);
|
|
11
|
+
const providerRef = useRef({});
|
|
12
|
+
const slotRef = useRef(null);
|
|
13
|
+
const [newRootPath, setNewRootPath] = useState(null);
|
|
14
|
+
const [reInitPage, setReInitPage] = useState(true);
|
|
15
|
+
const mainPath = useRef("");
|
|
16
|
+
const defaultPopupClass = `bg-white rounded-lg shadow-xl w-[90%] h-[90%] flex flex-col`;
|
|
17
|
+
const finalPopupClass = twMerge(clsx(defaultPopupClass, popupClassName));
|
|
18
|
+
const loadPage = (path) => {
|
|
19
|
+
var _a;
|
|
20
|
+
// console.log("popupview load page", path);
|
|
21
|
+
let comp = null;
|
|
22
|
+
try {
|
|
23
|
+
const key = "page-" + Math.random().toString(36).slice(2);
|
|
24
|
+
comp = _jsx(Page, { url: path }, key);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const e = getError(error);
|
|
28
|
+
comp = _jsx("div", { children: e.message });
|
|
29
|
+
}
|
|
30
|
+
// update the child slot
|
|
31
|
+
(_a = slotRef.current) === null || _a === void 0 ? void 0 : _a.update(comp, finalPopupClass, onClose);
|
|
32
|
+
};
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
// console.log("popupview change url", url);
|
|
35
|
+
const paths = (url == null || url.trim() === "" ? "" : url).split("#");
|
|
36
|
+
const [firstPath] = paths;
|
|
37
|
+
mainPath.current = firstPath;
|
|
38
|
+
setPaths(paths);
|
|
39
|
+
}, [url]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
// this routine is for the initial loading
|
|
42
|
+
// console.log("popupview change paths", paths);
|
|
43
|
+
loadPage(mainPath.current);
|
|
44
|
+
setReInitPage(false);
|
|
45
|
+
}, [paths]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (reInitPage) {
|
|
48
|
+
// let the initial loading take effect
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
loadPage(newRootPath);
|
|
52
|
+
}, [newRootPath]);
|
|
53
|
+
const pageViewHandle = {
|
|
54
|
+
displayName: "PopupView#pageViewHandle",
|
|
55
|
+
init: (ref) => {
|
|
56
|
+
providerRef.current = ref;
|
|
57
|
+
},
|
|
58
|
+
renderPage: (page) => {
|
|
59
|
+
setNewRootPath(page);
|
|
60
|
+
},
|
|
61
|
+
isStandalone: () => true,
|
|
62
|
+
};
|
|
63
|
+
return (_jsx(PageViewProvider, { prefix: "popup", paths: paths, handle: pageViewHandle, eventHandler: eventHandler, children: _jsx(ChildrenSlot, { ref: slotRef }) }));
|
|
64
|
+
};
|
|
65
|
+
export default PopupView;
|
|
66
|
+
const ChildrenSlot = memo(forwardRef((_, ref) => {
|
|
67
|
+
const [content, setContent] = useState(null);
|
|
68
|
+
const optionsRef = useRef({});
|
|
69
|
+
useImperativeHandle(ref, () => ({
|
|
70
|
+
update: (content, popupClassName, onClose) => {
|
|
71
|
+
const options = { popupClassName, onClose };
|
|
72
|
+
setContent(wrapContent(content, options));
|
|
73
|
+
optionsRef.current = options;
|
|
74
|
+
},
|
|
75
|
+
}), []);
|
|
76
|
+
const handleClose = () => {
|
|
77
|
+
setContent(null);
|
|
78
|
+
const { onClose } = optionsRef.current;
|
|
79
|
+
if (onClose != null && typeof onClose === "function") {
|
|
80
|
+
onClose();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const wrapContent = (comp, options) => {
|
|
84
|
+
if (comp == null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const { popupClassName } = options;
|
|
88
|
+
return (_jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50", children: _jsxs("div", { className: popupClassName, children: [_jsxs("div", { className: "flex items-center justify-between px-4 py-3 border-b", children: [_jsx("h2", { className: "text-lg font-semibold", children: "Page Viewer" }), _jsx("button", { onClick: handleClose, className: "w-8 h-8 flex items-center justify-center rounded-md hover:bg-gray-100 transition-colors", children: _jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), _jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })] }) })] }), _jsx("div", { className: "flex-1 overflow-hidden", children: comp })] }) }));
|
|
89
|
+
};
|
|
90
|
+
return _jsx(_Fragment, { children: content == null ? null : content });
|
|
91
|
+
}));
|