@ramesesinc/platform-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/dist/components/action/AlertMessage.d.ts +8 -0
  2. package/dist/components/action/AlertMessage.js +19 -0
  3. package/dist/components/action/AlertMessage.tsx +38 -0
  4. package/dist/components/action/Button.d.ts +21 -0
  5. package/dist/components/action/Button.js +139 -0
  6. package/dist/components/action/Button.tsx +230 -0
  7. package/dist/components/action/CancelEdit.d.ts +9 -0
  8. package/dist/components/action/CancelEdit.js +21 -0
  9. package/dist/components/action/CancelEdit.tsx +40 -0
  10. package/dist/components/action/DeleteData.d.ts +13 -0
  11. package/dist/components/action/DeleteData.js +43 -0
  12. package/dist/components/action/DeleteData.tsx +73 -0
  13. package/dist/components/action/Edit.d.ts +9 -0
  14. package/dist/components/action/Edit.js +21 -0
  15. package/dist/components/action/Edit.tsx +40 -0
  16. package/dist/components/action/LookupPage.d.ts +16 -0
  17. package/dist/components/action/LookupPage.js +62 -0
  18. package/dist/components/action/LookupPage.tsx +113 -0
  19. package/dist/components/action/ProcessRunner.d.ts +62 -0
  20. package/dist/components/action/ProcessRunner.js +156 -0
  21. package/dist/components/action/ProcessRunner.tsx +337 -0
  22. package/dist/components/action/Refresh.d.ts +7 -0
  23. package/dist/components/action/Refresh.js +17 -0
  24. package/dist/components/action/Refresh.tsx +35 -0
  25. package/dist/components/action/SaveData.d.ts +10 -0
  26. package/dist/components/action/SaveData.js +54 -0
  27. package/dist/components/action/SaveData.tsx +74 -0
  28. package/dist/components/action/SelectData.d.ts +8 -0
  29. package/dist/components/action/SelectData.js +29 -0
  30. package/dist/components/action/SelectData.tsx +47 -0
  31. package/dist/components/action/Undo.d.ts +9 -0
  32. package/dist/components/action/Undo.js +31 -0
  33. package/dist/components/action/Undo.tsx +50 -0
  34. package/dist/components/action/UpdateContext.d.ts +9 -0
  35. package/dist/components/action/UpdateContext.js +21 -0
  36. package/dist/components/action/UpdateContext.tsx +40 -0
  37. package/dist/components/action/UpdateData.d.ts +9 -0
  38. package/dist/components/action/UpdateData.js +33 -0
  39. package/dist/components/action/UpdateData.tsx +49 -0
  40. package/dist/components/action/ViewBackPage.d.ts +9 -0
  41. package/dist/components/action/ViewBackPage.js +19 -0
  42. package/dist/components/action/ViewBackPage.tsx +46 -0
  43. package/dist/components/action/ViewPage.d.ts +14 -0
  44. package/dist/components/action/ViewPage.js +88 -0
  45. package/dist/components/action/ViewPage.tsx +141 -0
  46. package/dist/components/common/UIComponent.d.ts +11 -0
  47. package/dist/components/common/UIComponent.js +52 -0
  48. package/dist/components/common/UIComponent.tsx +84 -0
  49. package/dist/components/common/UIInput.d.ts +12 -0
  50. package/dist/components/common/UIInput.js +37 -0
  51. package/dist/components/common/UIInput.tsx +49 -0
  52. package/dist/components/common/UIMenu.d.ts +23 -0
  53. package/dist/components/common/UIMenu.js +61 -0
  54. package/dist/components/common/UIMenu.tsx +91 -0
  55. package/dist/components/index.d.ts +37 -0
  56. package/dist/components/index.js +44 -0
  57. package/dist/components/index.ts +51 -0
  58. package/dist/components/input/CodeEditor.d.ts +12 -0
  59. package/dist/components/input/CodeEditor.js +132 -0
  60. package/dist/components/input/CodeEditor.tsx +188 -0
  61. package/dist/components/input/DateField.d.ts +9 -0
  62. package/dist/components/input/DateField.js +140 -0
  63. package/dist/components/input/DateField.tsx +274 -0
  64. package/dist/components/input/DayPicker.d.ts +2 -0
  65. package/dist/components/input/DayPicker.js +5 -0
  66. package/dist/components/input/DayPicker.tsx +5 -0
  67. package/dist/components/input/HtmlCode.d.ts +8 -0
  68. package/dist/components/input/HtmlCode.js +157 -0
  69. package/dist/components/input/HtmlCode.tsx +203 -0
  70. package/dist/components/input/JsonCode.d.ts +9 -0
  71. package/dist/components/input/JsonCode.js +159 -0
  72. package/dist/components/input/JsonCode.tsx +205 -0
  73. package/dist/components/input/MonthPicker.d.ts +2 -0
  74. package/dist/components/input/MonthPicker.js +5 -0
  75. package/dist/components/input/MonthPicker.tsx +5 -0
  76. package/dist/components/input/ScriptCode.d.ts +8 -0
  77. package/dist/components/input/ScriptCode.js +153 -0
  78. package/dist/components/input/ScriptCode.tsx +195 -0
  79. package/dist/components/input/Select.d.ts +14 -0
  80. package/dist/components/input/Select.js +40 -0
  81. package/dist/components/input/Select.tsx +78 -0
  82. package/dist/components/input/SqlCode.d.ts +8 -0
  83. package/dist/components/input/SqlCode.js +121 -0
  84. package/dist/components/input/SqlCode.tsx +162 -0
  85. package/dist/components/input/StringDecision.d.ts +2 -0
  86. package/dist/components/input/StringDecision.js +34 -0
  87. package/dist/components/input/StringDecision.tsx +64 -0
  88. package/dist/components/input/Text.d.ts +7 -0
  89. package/dist/components/input/Text.js +39 -0
  90. package/dist/components/input/Text.tsx +57 -0
  91. package/dist/components/input/YearPicker.d.ts +8 -0
  92. package/dist/components/input/YearPicker.js +44 -0
  93. package/dist/components/input/YearPicker.tsx +81 -0
  94. package/dist/components/list/IconMenu.d.ts +14 -0
  95. package/dist/components/list/IconMenu.js +72 -0
  96. package/dist/components/list/IconMenu.tsx +115 -0
  97. package/dist/components/list/TabMenu.d.ts +10 -0
  98. package/dist/components/list/TabMenu.js +72 -0
  99. package/dist/components/list/TabMenu.tsx +127 -0
  100. package/dist/components/list/TreeMenu.d.ts +14 -0
  101. package/dist/components/list/TreeMenu.js +207 -0
  102. package/dist/components/list/TreeMenu.tsx +279 -0
  103. package/dist/components/list/TxnTaskList.d.ts +2 -0
  104. package/dist/components/list/TxnTaskList.js +77 -0
  105. package/dist/components/list/TxnTaskList.tsx +198 -0
  106. package/dist/components/output/Label.d.ts +8 -0
  107. package/dist/components/output/Label.js +33 -0
  108. package/dist/components/output/Label.tsx +51 -0
  109. package/dist/components/table/DataList.d.ts +88 -0
  110. package/dist/components/table/DataList.js +361 -0
  111. package/dist/components/table/DataList.tsx +782 -0
  112. package/dist/components/table/DataTable.d.ts +46 -0
  113. package/dist/components/table/DataTable.js +253 -0
  114. package/dist/components/table/DataTable.tsx +572 -0
  115. package/dist/components/table/ListHandler.d.ts +42 -0
  116. package/dist/components/table/ListHandler.js +197 -0
  117. package/dist/components/table/ListHandler.ts +276 -0
  118. package/dist/components/table/TableContext.d.ts +33 -0
  119. package/dist/components/table/TableContext.js +57 -0
  120. package/dist/components/table/TableContext.tsx +122 -0
  121. package/dist/components/view/ComponentView.d.ts +8 -0
  122. package/dist/components/view/ComponentView.js +78 -0
  123. package/dist/components/view/ComponentView.tsx +102 -0
  124. package/dist/components/view/FilterView.d.ts +2 -0
  125. package/dist/components/view/FilterView.js +14 -0
  126. package/dist/components/view/FilterView.tsx +21 -0
  127. package/dist/components/view/HtmlForm.d.ts +7 -0
  128. package/dist/components/view/HtmlForm.js +145 -0
  129. package/dist/components/view/HtmlForm.tsx +186 -0
  130. package/dist/components/view/HtmlView.d.ts +9 -0
  131. package/dist/components/view/HtmlView.js +85 -0
  132. package/dist/components/view/HtmlView.tsx +114 -0
  133. package/dist/components/view/IFrameView.d.ts +2 -0
  134. package/dist/components/view/IFrameView.js +34 -0
  135. package/dist/components/view/IFrameView.tsx +48 -0
  136. package/dist/components/view/Modal.d.ts +14 -0
  137. package/dist/components/view/Modal.js +28 -0
  138. package/dist/components/view/Modal.tsx +72 -0
  139. package/dist/components/view/PageView.d.ts +9 -0
  140. package/dist/components/view/PageView.js +90 -0
  141. package/dist/components/view/PageView.tsx +131 -0
  142. package/dist/components/view/PopupView.d.ts +9 -0
  143. package/dist/components/view/PopupView.js +91 -0
  144. package/dist/components/view/PopupView.tsx +160 -0
  145. package/dist/components/view/RootView.d.ts +8 -0
  146. package/dist/components/view/RootView.js +75 -0
  147. package/dist/components/view/RootView.tsx +109 -0
  148. package/dist/components/view/WizardView.d.ts +6 -0
  149. package/dist/components/view/WizardView.js +34 -0
  150. package/dist/components/view/WizardView.tsx +48 -0
  151. package/dist/core/AppContext.d.ts +25 -0
  152. package/dist/core/AppContext.js +159 -0
  153. package/dist/core/AuthContext.d.ts +13 -0
  154. package/dist/core/AuthContext.js +80 -0
  155. package/dist/core/ComponentCache.d.ts +15 -0
  156. package/dist/core/ComponentCache.js +25 -0
  157. package/dist/core/DataContext.d.ts +20 -0
  158. package/dist/core/DataContext.js +41 -0
  159. package/dist/core/DynamicComponent.d.ts +12 -0
  160. package/dist/core/DynamicComponent.js +30 -0
  161. package/dist/core/DynamicIcon.d.ts +6 -0
  162. package/dist/core/DynamicIcon.js +48 -0
  163. package/dist/core/DynamicTemplate.d.ts +4 -0
  164. package/dist/core/DynamicTemplate.js +17 -0
  165. package/dist/core/ErrorMessage.d.ts +5 -0
  166. package/dist/core/ErrorMessage.js +7 -0
  167. package/dist/core/EventHandler.d.ts +3 -0
  168. package/dist/core/EventHandler.js +1 -0
  169. package/dist/core/HtmlCache.d.ts +6 -0
  170. package/dist/core/HtmlCache.js +17 -0
  171. package/dist/core/Page.d.ts +6 -0
  172. package/dist/core/Page.js +141 -0
  173. package/dist/core/PageCache.d.ts +15 -0
  174. package/dist/core/PageCache.js +26 -0
  175. package/dist/core/PageContext.d.ts +49 -0
  176. package/dist/core/PageContext.js +207 -0
  177. package/dist/core/PageRegistry.d.ts +7 -0
  178. package/dist/core/PageRegistry.js +11 -0
  179. package/dist/core/PageViewContext.d.ts +45 -0
  180. package/dist/core/PageViewContext.js +277 -0
  181. package/dist/core/Panel.d.ts +16 -0
  182. package/dist/core/Panel.js +39 -0
  183. package/dist/core/RowContext.d.ts +11 -0
  184. package/dist/core/RowContext.js +16 -0
  185. package/dist/core/StepHandler.d.ts +9 -0
  186. package/dist/core/StepHandler.js +39 -0
  187. package/dist/core/UIDependHandler.d.ts +6 -0
  188. package/dist/core/UIDependHandler.js +31 -0
  189. package/dist/core/auth/index.d.ts +18 -0
  190. package/dist/core/auth/index.js +187 -0
  191. package/dist/core/auth/session.d.ts +4 -0
  192. package/dist/core/auth/session.js +45 -0
  193. package/dist/core/index.d.ts +3 -0
  194. package/dist/core/index.js +1 -0
  195. package/dist/core/page-helper.d.ts +27 -0
  196. package/dist/core/page-helper.js +47 -0
  197. package/dist/hooks/useUrlParams.d.ts +11 -0
  198. package/dist/hooks/useUrlParams.js +164 -0
  199. package/dist/index.d.ts +65 -0
  200. package/dist/index.js +69 -0
  201. package/dist/layouts/BorderLayout.d.ts +14 -0
  202. package/dist/layouts/BorderLayout.js +8 -0
  203. package/dist/layouts/CardLayout.d.ts +27 -0
  204. package/dist/layouts/CardLayout.js +36 -0
  205. package/dist/layouts/CenterLayout.d.ts +8 -0
  206. package/dist/layouts/CenterLayout.js +6 -0
  207. package/dist/layouts/GridLayout.d.ts +9 -0
  208. package/dist/layouts/GridLayout.js +5 -0
  209. package/dist/layouts/HPanel.d.ts +11 -0
  210. package/dist/layouts/HPanel.js +8 -0
  211. package/dist/layouts/HorizontalLayout.d.ts +11 -0
  212. package/dist/layouts/HorizontalLayout.js +6 -0
  213. package/dist/layouts/MainLayout.d.ts +6 -0
  214. package/dist/layouts/MainLayout.js +5 -0
  215. package/dist/layouts/PageLayout.d.ts +11 -0
  216. package/dist/layouts/PageLayout.js +6 -0
  217. package/dist/layouts/VPanel.d.ts +9 -0
  218. package/dist/layouts/VPanel.js +7 -0
  219. package/dist/layouts/XLayout.d.ts +10 -0
  220. package/dist/layouts/XLayout.js +10 -0
  221. package/dist/layouts/YLayout.d.ts +10 -0
  222. package/dist/layouts/YLayout.js +10 -0
  223. package/dist/lib/PlatformRoute.d.ts +5 -0
  224. package/dist/lib/PlatformRoute.js +288 -0
  225. package/dist/lib/WebPlatform.d.ts +13 -0
  226. package/dist/lib/WebPlatform.js +124 -0
  227. package/dist/lib/components/ActivityBar.d.ts +13 -0
  228. package/dist/lib/components/ActivityBar.js +39 -0
  229. package/dist/lib/components/CopyButton.d.ts +8 -0
  230. package/dist/lib/components/CopyButton.js +50 -0
  231. package/dist/lib/components/Header.d.ts +2 -0
  232. package/dist/lib/components/Header.js +74 -0
  233. package/dist/lib/components/QuickActionMenu.d.ts +18 -0
  234. package/dist/lib/components/QuickActionMenu.js +50 -0
  235. package/dist/lib/components/UserButton.d.ts +11 -0
  236. package/dist/lib/components/UserButton.js +66 -0
  237. package/dist/lib/layouts/BorderLayout.tsx +31 -0
  238. package/dist/lib/layouts/CardLayout.tsx +73 -0
  239. package/dist/lib/layouts/CenterLayout.tsx +20 -0
  240. package/dist/lib/layouts/GridLayout.tsx +20 -0
  241. package/dist/lib/layouts/HPanel.tsx +31 -0
  242. package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
  243. package/dist/lib/layouts/MainLayout.tsx +16 -0
  244. package/dist/lib/layouts/PageLayout.tsx +29 -0
  245. package/dist/lib/layouts/VPanel.tsx +27 -0
  246. package/dist/lib/layouts/XLayout.tsx +29 -0
  247. package/dist/lib/layouts/YLayout.tsx +29 -0
  248. package/dist/lib/utils/BeanUtils.d.ts +3 -0
  249. package/dist/lib/utils/BeanUtils.js +75 -0
  250. package/dist/lib/utils/ComponentLoader.d.ts +13 -0
  251. package/dist/lib/utils/ComponentLoader.js +26 -0
  252. package/dist/lib/utils/ExprUtil.d.ts +7 -0
  253. package/dist/lib/utils/ExprUtil.js +44 -0
  254. package/dist/lib/utils/PageUtils.d.ts +6 -0
  255. package/dist/lib/utils/PageUtils.js +121 -0
  256. package/dist/lib/utils/ResourceLoader.d.ts +11 -0
  257. package/dist/lib/utils/ResourceLoader.js +37 -0
  258. package/dist/lib/utils/SectionProvider.d.ts +5 -0
  259. package/dist/lib/utils/SectionProvider.js +39 -0
  260. package/dist/lib/utils/initResourceLoader.d.ts +0 -0
  261. package/dist/lib/utils/initResourceLoader.js +95 -0
  262. package/dist/styles/index.css +38 -0
  263. package/dist/templates/BasicTemplate.d.ts +2 -0
  264. package/dist/templates/BasicTemplate.js +14 -0
  265. package/dist/templates/CrudFormTemplate.d.ts +2 -0
  266. package/dist/templates/CrudFormTemplate.js +38 -0
  267. package/dist/templates/DataListTemplate.d.ts +2 -0
  268. package/dist/templates/DataListTemplate.js +13 -0
  269. package/dist/templates/ExplorerTemplate.d.ts +10 -0
  270. package/dist/templates/ExplorerTemplate.js +17 -0
  271. package/dist/templates/TxnFormTemplate.d.ts +2 -0
  272. package/dist/templates/TxnFormTemplate.js +66 -0
  273. package/dist/templates/WizardTemplate.d.ts +9 -0
  274. package/dist/templates/WizardTemplate.js +37 -0
  275. package/dist/templates/index.d.ts +5 -0
  276. package/dist/templates/index.js +5 -0
  277. package/dist/types/action.d.ts +8 -0
  278. package/dist/types/action.js +1 -0
  279. package/dist/types/component.d.ts +18 -0
  280. package/dist/types/component.js +1 -0
  281. package/dist/types/list.d.ts +14 -0
  282. package/dist/types/list.js +1 -0
  283. package/dist/types/template.d.ts +6 -0
  284. package/dist/types/template.js +1 -0
  285. package/package.json +56 -0
@@ -0,0 +1,160 @@
1
+ import { getError } from "@ramesesinc/client";
2
+ import clsx from "clsx";
3
+ import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
4
+ import { twMerge } from "tailwind-merge";
5
+ import { EventHandler } from "../../core";
6
+ import Page from "../../core/Page";
7
+ import { PageViewContextValue, PageViewHandle, PageViewProvider } from "../../core/PageViewContext";
8
+
9
+ type PopupViewProps = {
10
+ url: string;
11
+ popupClassName?: string;
12
+ onClose?: () => void;
13
+ eventHandler?: EventHandler | null;
14
+ };
15
+
16
+ const PopupView = (props: PopupViewProps) => {
17
+ const { url, popupClassName, onClose = () => {}, eventHandler } = props ?? {};
18
+
19
+ const [paths, setPaths] = useState<string[]>([]);
20
+
21
+ const providerRef = useRef<PageViewContextValue>({} as PageViewContextValue);
22
+ const slotRef = useRef<PopupSlotHandle>(null);
23
+
24
+ const [newRootPath, setNewRootPath] = useState<string | null>(null);
25
+ const [reInitPage, setReInitPage] = useState(true);
26
+
27
+ const mainPath = useRef("");
28
+
29
+ const defaultPopupClass = `bg-white rounded-lg shadow-xl w-[90%] h-[90%] flex flex-col`;
30
+ const finalPopupClass = twMerge(clsx(defaultPopupClass, popupClassName));
31
+
32
+ const loadPage = (path: string | null) => {
33
+ // console.log("popupview load page", path);
34
+ let comp = null;
35
+ try {
36
+ const key = "page-" + Math.random().toString(36).slice(2);
37
+ comp = <Page url={path} key={key} />;
38
+ } catch (error: any) {
39
+ const e = getError(error);
40
+ comp = <div>{e.message}</div>;
41
+ }
42
+
43
+ // update the child slot
44
+ slotRef.current?.update(comp, finalPopupClass, onClose);
45
+ };
46
+
47
+ useEffect(() => {
48
+ // console.log("popupview change url", url);
49
+ const paths = (url == null || url.trim() === "" ? "" : url).split("#");
50
+ const [firstPath] = paths;
51
+ mainPath.current = firstPath;
52
+ setPaths(paths);
53
+ }, [url]);
54
+
55
+ useEffect(() => {
56
+ // this routine is for the initial loading
57
+ // console.log("popupview change paths", paths);
58
+ loadPage(mainPath.current);
59
+ setReInitPage(false);
60
+ }, [paths]);
61
+
62
+ useEffect(() => {
63
+ if (reInitPage) {
64
+ // let the initial loading take effect
65
+ return;
66
+ }
67
+
68
+ loadPage(newRootPath);
69
+ }, [newRootPath]);
70
+
71
+ const pageViewHandle = {
72
+ displayName: "PopupView#pageViewHandle",
73
+ init: (ref: PageViewContextValue) => {
74
+ providerRef.current = ref;
75
+ },
76
+ renderPage: (page: string) => {
77
+ setNewRootPath(page);
78
+ },
79
+ isStandalone: () => true,
80
+ } as PageViewHandle;
81
+
82
+ return (
83
+ <PageViewProvider prefix="popup" paths={paths} handle={pageViewHandle} eventHandler={eventHandler}>
84
+ <ChildrenSlot ref={slotRef} />
85
+ </PageViewProvider>
86
+ );
87
+ };
88
+
89
+ export default PopupView;
90
+
91
+ type PopupSlotHandle = {
92
+ update: (content: React.ReactNode, popupClassName: string, onClose: () => void) => void;
93
+ };
94
+
95
+ const ChildrenSlot = memo(
96
+ forwardRef<PopupSlotHandle>((_, ref) => {
97
+ const [content, setContent] = useState<React.ReactNode>(null);
98
+
99
+ const optionsRef = useRef<Record<string, any>>({});
100
+
101
+ useImperativeHandle(
102
+ ref,
103
+ () => ({
104
+ update: (content: React.ReactNode, popupClassName: string, onClose: () => void) => {
105
+ const options = { popupClassName, onClose };
106
+ setContent(wrapContent(content, options));
107
+ optionsRef.current = options;
108
+ },
109
+ }),
110
+ [],
111
+ );
112
+
113
+ const handleClose = () => {
114
+ setContent(null);
115
+
116
+ const { onClose } = optionsRef.current;
117
+ if (onClose != null && typeof onClose === "function") {
118
+ onClose();
119
+ }
120
+ };
121
+
122
+ const wrapContent = (comp: React.ReactNode, options: Record<string, any>): React.ReactNode => {
123
+ if (comp == null) {
124
+ return null;
125
+ }
126
+
127
+ const { popupClassName } = options;
128
+ return (
129
+ <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
130
+ <div className={popupClassName}>
131
+ {/* Header */}
132
+ <div className="flex items-center justify-between px-4 py-3 border-b">
133
+ <h2 className="text-lg font-semibold">Page Viewer</h2>
134
+ <button onClick={handleClose} className="w-8 h-8 flex items-center justify-center rounded-md hover:bg-gray-100 transition-colors">
135
+ <svg
136
+ xmlns="http://www.w3.org/2000/svg"
137
+ width="20"
138
+ height="20"
139
+ viewBox="0 0 24 24"
140
+ fill="none"
141
+ stroke="currentColor"
142
+ strokeWidth="2"
143
+ strokeLinecap="round"
144
+ strokeLinejoin="round"
145
+ >
146
+ <line x1="18" y1="6" x2="6" y2="18"></line>
147
+ <line x1="6" y1="6" x2="18" y2="18"></line>
148
+ </svg>
149
+ </button>
150
+ </div>
151
+ {/* Content */}
152
+ <div className="flex-1 overflow-hidden">{comp}</div>
153
+ </div>
154
+ </div>
155
+ );
156
+ };
157
+
158
+ return <>{content == null ? null : content}</>;
159
+ }),
160
+ );
@@ -0,0 +1,8 @@
1
+ import { EventHandler } from "../../core";
2
+ type RootViewProps = {
3
+ url: string;
4
+ eventHandler?: EventHandler | null;
5
+ standalone?: boolean;
6
+ };
7
+ declare const RootView: (props: RootViewProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default RootView;
@@ -0,0 +1,75 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { getError } from "@ramesesinc/client";
3
+ import { forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
4
+ import Page from "../../core/Page";
5
+ import { PageViewProvider } from "../../core/PageViewContext";
6
+ const RootView = (props) => {
7
+ const { url, eventHandler, standalone = true } = props !== null && props !== void 0 ? props : {};
8
+ const [paths, setPaths] = useState([]);
9
+ const mainPath = useRef("");
10
+ const [newRootPath, setNewRootPath] = useState(null);
11
+ const [reInitPage, setReInitPage] = useState(true);
12
+ const providerRef = useRef({});
13
+ const loadPage = (path) => {
14
+ var _a;
15
+ let comp = null;
16
+ try {
17
+ // console.log("RootView loadPage", path); // main#tasklist
18
+ const pageUUID = "page-" + Math.random().toString(36).slice(2);
19
+ comp = _jsx(Page, { url: path }, pageUUID);
20
+ }
21
+ catch (error) {
22
+ const e = getError(error);
23
+ // console.log("rootview loadpage error", e);
24
+ comp = _jsx("div", { children: e.message });
25
+ }
26
+ // update provider paths but maintain the rootPath
27
+ // providerRef.current?.updatePaths(newPaths);
28
+ // update the child slot
29
+ (_a = slotRef.current) === null || _a === void 0 ? void 0 : _a.update(comp);
30
+ };
31
+ useLayoutEffect(() => {
32
+ const paths = (url == null || url.trim() === "" ? "" : url).split("#");
33
+ // console.log("RootView useLayoutEffect ", url, paths);
34
+ const [firstPath] = paths;
35
+ mainPath.current = firstPath;
36
+ setPaths(paths);
37
+ }, [url]);
38
+ useEffect(() => {
39
+ // this routine is for the initial loading
40
+ // pass the original url
41
+ loadPage(url);
42
+ setReInitPage(false);
43
+ }, [paths]);
44
+ useEffect(() => {
45
+ if (reInitPage) {
46
+ // let the initial loading take effect
47
+ return;
48
+ }
49
+ loadPage(newRootPath);
50
+ }, [newRootPath]);
51
+ const pageViewHandle = {
52
+ displayName: "RootView#pageViewHandle",
53
+ init: (ref) => {
54
+ providerRef.current = ref;
55
+ },
56
+ renderPage: (page) => {
57
+ // console.log("RootView renderPage", page);
58
+ setNewRootPath(page);
59
+ },
60
+ isStandalone: () => standalone,
61
+ };
62
+ const slotRef = useRef(null);
63
+ return (_jsx(PageViewProvider, { prefix: "root", paths: paths, handle: pageViewHandle, eventHandler: eventHandler, children: _jsx(ChildrenSlot, { ref: slotRef }) }));
64
+ };
65
+ export default RootView;
66
+ const ChildrenSlot = memo(forwardRef((_, ref) => {
67
+ const [content, setContent] = useState(null);
68
+ useImperativeHandle(ref, () => ({
69
+ update: (content) => {
70
+ // console.log("childrenslot update", content);
71
+ setContent(content);
72
+ },
73
+ }), []);
74
+ return _jsx(_Fragment, { children: content == null ? null : content });
75
+ }));
@@ -0,0 +1,109 @@
1
+ import { getError } from "@ramesesinc/client";
2
+ import { forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
3
+ import { EventHandler } from "../../core";
4
+ import Page from "../../core/Page";
5
+ import { PageViewContextValue, PageViewHandle, PageViewProvider } from "../../core/PageViewContext";
6
+
7
+ type RootViewProps = {
8
+ url: string;
9
+ eventHandler?: EventHandler | null;
10
+ standalone?: boolean;
11
+ };
12
+
13
+ const RootView = (props: RootViewProps) => {
14
+ const { url, eventHandler, standalone = true } = props ?? {};
15
+
16
+ const [paths, setPaths] = useState<string[]>([]);
17
+
18
+ const mainPath = useRef("");
19
+
20
+ const [newRootPath, setNewRootPath] = useState<string | null>(null);
21
+ const [reInitPage, setReInitPage] = useState(true);
22
+
23
+ const providerRef = useRef<PageViewContextValue>({} as PageViewContextValue);
24
+
25
+ const loadPage = (path: string | null) => {
26
+ let comp = null;
27
+ try {
28
+ // console.log("RootView loadPage", path); // main#tasklist
29
+ const pageUUID = "page-" + Math.random().toString(36).slice(2);
30
+ comp = <Page url={path} key={pageUUID} />;
31
+ } catch (error: any) {
32
+ const e = getError(error);
33
+ // console.log("rootview loadpage error", e);
34
+ comp = <div>{e.message}</div>;
35
+ }
36
+ // update provider paths but maintain the rootPath
37
+ // providerRef.current?.updatePaths(newPaths);
38
+ // update the child slot
39
+ slotRef.current?.update(comp);
40
+ };
41
+
42
+ useLayoutEffect(() => {
43
+ const paths = (url == null || url.trim() === "" ? "" : url).split("#");
44
+ // console.log("RootView useLayoutEffect ", url, paths);
45
+ const [firstPath] = paths;
46
+ mainPath.current = firstPath;
47
+ setPaths(paths);
48
+ }, [url]);
49
+
50
+ useEffect(() => {
51
+ // this routine is for the initial loading
52
+ // pass the original url
53
+ loadPage(url);
54
+ setReInitPage(false);
55
+ }, [paths]);
56
+
57
+ useEffect(() => {
58
+ if (reInitPage) {
59
+ // let the initial loading take effect
60
+ return;
61
+ }
62
+
63
+ loadPage(newRootPath);
64
+ }, [newRootPath]);
65
+
66
+ const pageViewHandle = {
67
+ displayName: "RootView#pageViewHandle",
68
+ init: (ref: PageViewContextValue) => {
69
+ providerRef.current = ref;
70
+ },
71
+ renderPage: (page: string) => {
72
+ // console.log("RootView renderPage", page);
73
+ setNewRootPath(page);
74
+ },
75
+ isStandalone: () => standalone,
76
+ } as PageViewHandle;
77
+
78
+ const slotRef = useRef<ChildrenSlotHandle>(null);
79
+
80
+ return (
81
+ <PageViewProvider prefix="root" paths={paths} handle={pageViewHandle} eventHandler={eventHandler}>
82
+ <ChildrenSlot ref={slotRef} />
83
+ </PageViewProvider>
84
+ );
85
+ };
86
+
87
+ export default RootView;
88
+
89
+ type ChildrenSlotHandle = {
90
+ update: (content: React.ReactNode) => void;
91
+ };
92
+ const ChildrenSlot = memo(
93
+ forwardRef<ChildrenSlotHandle>((_, ref) => {
94
+ const [content, setContent] = useState<React.ReactNode>(null);
95
+
96
+ useImperativeHandle(
97
+ ref,
98
+ () => ({
99
+ update: (content: React.ReactNode) => {
100
+ // console.log("childrenslot update", content);
101
+ setContent(content);
102
+ },
103
+ }),
104
+ [],
105
+ );
106
+
107
+ return <>{content == null ? null : content}</>;
108
+ }),
109
+ );
@@ -0,0 +1,6 @@
1
+ type WizardViewProps = {
2
+ name: string;
3
+ items: Record<string, any>[];
4
+ };
5
+ declare const WizardView: (props: WizardViewProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default WizardView;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { usePageContext } from "../../core/PageContext";
4
+ import { StepHandler } from "../../core/StepHandler";
5
+ import ComponentView from "./ComponentView";
6
+ const WizardView = (props) => {
7
+ const { name = "wizard", items = [] } = props !== null && props !== void 0 ? props : {};
8
+ const pageContext = usePageContext();
9
+ const handlerRef = useRef(null);
10
+ if (handlerRef.current == null) {
11
+ const callback = (item) => {
12
+ var _a;
13
+ const onInit = (_a = item.events) === null || _a === void 0 ? void 0 : _a.onInit;
14
+ if (onInit != null && typeof onInit === "function") {
15
+ onInit();
16
+ }
17
+ pageContext === null || pageContext === void 0 ? void 0 : pageContext.set(name, item);
18
+ };
19
+ const handler = StepHandler(items, callback);
20
+ for (const it of items) {
21
+ const item = it;
22
+ if (item.attr == null)
23
+ item.attr = {};
24
+ item.attr.stepHandler = handler;
25
+ item.attr.events = {};
26
+ }
27
+ handlerRef.current = handler;
28
+ }
29
+ useEffect(() => {
30
+ pageContext === null || pageContext === void 0 ? void 0 : pageContext.set(name, items[0]);
31
+ }, []);
32
+ return (_jsx("div", { children: _jsx(ComponentView, { name: name, depends: name }) }));
33
+ };
34
+ export default WizardView;
@@ -0,0 +1,48 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { usePageContext } from "../../core/PageContext";
3
+ import { StepActionHandler, StepHandler } from "../../core/StepHandler";
4
+ import ComponentView from "./ComponentView";
5
+
6
+ type WizardViewProps = {
7
+ name: string;
8
+ items: Record<string, any>[];
9
+ };
10
+
11
+ const WizardView = (props: WizardViewProps) => {
12
+ const { name = "wizard", items = [] } = props ?? {};
13
+ const pageContext = usePageContext();
14
+ const handlerRef = useRef<StepActionHandler | null>(null);
15
+
16
+ if (handlerRef.current == null) {
17
+ const callback = (item: Record<string, any>) => {
18
+ const onInit = item.events?.onInit;
19
+ if (onInit != null && typeof onInit === "function") {
20
+ onInit();
21
+ }
22
+ pageContext?.set(name, item);
23
+ };
24
+
25
+ const handler = StepHandler(items, callback);
26
+
27
+ for (const it of items) {
28
+ const item = it as Record<string, any>;
29
+ if (item.attr == null) item.attr = {};
30
+ item.attr.stepHandler = handler;
31
+ item.attr.events = {};
32
+ }
33
+
34
+ handlerRef.current = handler;
35
+ }
36
+
37
+ useEffect(() => {
38
+ pageContext?.set(name, items[0]);
39
+ }, []);
40
+
41
+ return (
42
+ <div>
43
+ <ComponentView name={name} depends={name} />
44
+ </div>
45
+ );
46
+ };
47
+
48
+ export default WizardView;
@@ -0,0 +1,25 @@
1
+ import { ReactNode } from "react";
2
+ type AppPathInfo = {
3
+ prefixPath: string;
4
+ pageName: string;
5
+ query: string | null;
6
+ anchors: string[];
7
+ };
8
+ interface AppContextType {
9
+ tenant: string | null;
10
+ module: string | null;
11
+ activityid: string | null;
12
+ loading: boolean;
13
+ pathname: string;
14
+ options: Record<string, any>;
15
+ getPageCache: (name: string) => Promise<any>;
16
+ getComponentCache: (name: string) => Promise<any>;
17
+ buildPathInfo: (path: string | null) => AppPathInfo;
18
+ getPathInfo: () => AppPathInfo;
19
+ getPathLocationInfo: () => AppPathInfo;
20
+ }
21
+ export declare const useApp: () => AppContextType;
22
+ export declare function AppProvider({ children }: {
23
+ children: ReactNode;
24
+ }): import("react/jsx-runtime").JSX.Element | null;
25
+ export {};
@@ -0,0 +1,159 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useRouter } from "next/router";
3
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
4
+ import { getComponent } from "./ComponentCache";
5
+ import { getPage } from "./PageCache";
6
+ const AppContext = createContext({
7
+ tenant: null,
8
+ module: null,
9
+ activityid: null,
10
+ loading: true,
11
+ pathname: "",
12
+ options: {},
13
+ getPageCache: async () => undefined,
14
+ getComponentCache: async () => undefined,
15
+ buildPathInfo: (path) => buildAppPathInfo(path),
16
+ getPathInfo: () => ({ prefixPath: "", pageName: "", query: null, anchors: [] }),
17
+ getPathLocationInfo: () => ({ prefixPath: "", pageName: "", query: null, anchors: [] }),
18
+ });
19
+ export const useApp = () => {
20
+ const context = useContext(AppContext);
21
+ if (!context) {
22
+ throw new Error("useApp must be used within AppProvider");
23
+ }
24
+ return context;
25
+ };
26
+ function buildAppPathInfo(path) {
27
+ var _a;
28
+ const result = {
29
+ pageName: "",
30
+ prefixPath: "",
31
+ query: null,
32
+ anchors: [],
33
+ };
34
+ if (path == null) {
35
+ return result;
36
+ }
37
+ let finalPath = path;
38
+ if (!finalPath.startsWith("/")) {
39
+ finalPath = "/" + finalPath;
40
+ }
41
+ const [mainPath, ...subPaths] = finalPath.split("#");
42
+ const [cleanPath, queryPath = null] = mainPath.split("?");
43
+ const parts = cleanPath.split("/").slice(1);
44
+ result.pageName = (_a = parts.at(-1)) !== null && _a !== void 0 ? _a : "";
45
+ result.prefixPath = "/" + parts.slice(0, -1).join("/");
46
+ result.query = queryPath;
47
+ result.anchors = subPaths !== null && subPaths !== void 0 ? subPaths : [];
48
+ return result;
49
+ }
50
+ export function AppProvider({ children }) {
51
+ var _a, _b;
52
+ const [isClient, setIsClient] = useState(false);
53
+ const [state, setState] = useState({
54
+ tenant: null,
55
+ module: null,
56
+ activityid: null,
57
+ loading: true,
58
+ });
59
+ const router = useRouter();
60
+ const pathInfo = useMemo(() => {
61
+ if (router.isReady) {
62
+ return buildAppPathInfo(router.asPath);
63
+ }
64
+ return buildAppPathInfo(null);
65
+ }, [router.asPath, router.isReady]);
66
+ // Set client-side flag
67
+ useEffect(() => {
68
+ setIsClient(true);
69
+ }, []);
70
+ // Handle route changes and initial load
71
+ useEffect(() => {
72
+ if (!isClient || !router.isReady)
73
+ return;
74
+ const extractRouteParams = () => {
75
+ var _a, _b;
76
+ const { pathname, query } = router;
77
+ const tenant = ((_a = query.tenant) !== null && _a !== void 0 ? _a : "");
78
+ const module = ((_b = query.module) !== null && _b !== void 0 ? _b : "");
79
+ let activityid = null;
80
+ if (tenant && module) {
81
+ const [, , , pageId] = pathname.split("/");
82
+ if (pageId === null || pageId === void 0 ? void 0 : pageId.trim()) {
83
+ activityid = pageId;
84
+ }
85
+ }
86
+ setState({
87
+ tenant: (tenant === null || tenant === void 0 ? void 0 : tenant.trim()) || null,
88
+ module: (module === null || module === void 0 ? void 0 : module.trim()) || null,
89
+ activityid,
90
+ loading: false,
91
+ });
92
+ };
93
+ extractRouteParams();
94
+ const handleRouteChange = () => {
95
+ extractRouteParams();
96
+ };
97
+ router.events.on("routeChangeComplete", handleRouteChange);
98
+ return () => {
99
+ router.events.off("routeChangeComplete", handleRouteChange);
100
+ };
101
+ }, [isClient, router]);
102
+ // Don't render anything until client-side
103
+ if (!isClient) {
104
+ return null;
105
+ }
106
+ const cache_fallback = {
107
+ // getTenant: state.tenant,
108
+ // getModule: state.module,
109
+ getTenant: ((_a = router.query.tenant) !== null && _a !== void 0 ? _a : ""),
110
+ getModule: ((_b = router.query.module) !== null && _b !== void 0 ? _b : ""),
111
+ };
112
+ const getPageCache = (name) => getPage(name, cache_fallback);
113
+ const getComponentCache = (name) => getComponent(name, cache_fallback);
114
+ const buildPathInfo = (path) => {
115
+ return buildAppPathInfo(path);
116
+ };
117
+ const getPathInfo = () => {
118
+ return pathInfo;
119
+ };
120
+ const getPathLocationInfo = () => {
121
+ var _a, _b;
122
+ const result = {
123
+ pageName: "",
124
+ prefixPath: "",
125
+ query: null,
126
+ anchors: [],
127
+ };
128
+ try {
129
+ if (window == null)
130
+ return result;
131
+ const paths = [window.location.pathname];
132
+ const query = (_a = window.location.search) !== null && _a !== void 0 ? _a : "";
133
+ if (query.length > 0) {
134
+ if (!query.startsWith("?")) {
135
+ paths.push("?");
136
+ }
137
+ paths.push(query);
138
+ }
139
+ const hash = (_b = window.location.hash) !== null && _b !== void 0 ? _b : "";
140
+ if (hash.length > 0) {
141
+ if (!hash.startsWith("#")) {
142
+ paths.push("#");
143
+ }
144
+ paths.push(hash);
145
+ }
146
+ return buildAppPathInfo(paths.join(""));
147
+ }
148
+ catch (err) {
149
+ console.log("Error getting path location info:", err);
150
+ return result;
151
+ }
152
+ };
153
+ const contextValue = Object.assign(Object.assign({}, state), { pathname: router.pathname, options: router.query, getPageCache,
154
+ getComponentCache,
155
+ buildPathInfo,
156
+ getPathInfo,
157
+ getPathLocationInfo });
158
+ return _jsx(AppContext.Provider, { value: contextValue, children: children });
159
+ }
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from "react";
2
+ type AuthContextType = {
3
+ sessionId: string | null;
4
+ activityId: string | null;
5
+ getSessionId: () => Promise<string | null>;
6
+ signIn: (email: string, password: string) => Promise<string>;
7
+ signOut: () => Promise<void>;
8
+ };
9
+ export declare const useAuth: () => AuthContextType;
10
+ export declare const AuthProvider: ({ children }: {
11
+ children: ReactNode;
12
+ }) => import("react/jsx-runtime").JSX.Element;
13
+ export {};