@ramesesinc/platform-core 0.1.5 → 0.1.6
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/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.ts +1 -1
- package/dist/core/PageCache.js +14 -1
- package/dist/core/PageContext.js +82 -20
- package/dist/core/PageViewContext.js +14 -3
- package/package.json +1 -1
- /package/dist/components/action/{UpdateContext.d.ts → UpdateState.d.ts} +0 -0
- /package/dist/components/action/{UpdateContext.js → UpdateState.js} +0 -0
- /package/dist/components/action/{UpdateContext.tsx → UpdateState.tsx} +0 -0
|
@@ -29,7 +29,7 @@ export { default as Refresh } from "./action/Refresh";
|
|
|
29
29
|
export { default as SaveData } from "./action/SaveData";
|
|
30
30
|
export { default as SelectData } from "./action/SelectData";
|
|
31
31
|
export { default as LookupPage } from "./action/LookupPage";
|
|
32
|
-
export { default as
|
|
32
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
33
33
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
34
34
|
export { default as ViewPage } from "./action/ViewPage";
|
|
35
35
|
export { default as PageView } from "./view/PageView";
|
package/dist/components/index.js
CHANGED
|
@@ -35,7 +35,7 @@ export { default as Refresh } from "./action/Refresh";
|
|
|
35
35
|
export { default as SaveData } from "./action/SaveData";
|
|
36
36
|
export { default as SelectData } from "./action/SelectData";
|
|
37
37
|
export { default as LookupPage } from "./action/LookupPage";
|
|
38
|
-
export { default as
|
|
38
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
39
39
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
40
40
|
export { default as ViewPage } from "./action/ViewPage";
|
|
41
41
|
export { default as PageView } from "./view/PageView";
|
package/dist/components/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export { default as SaveData } from "./action/SaveData";
|
|
|
41
41
|
export { default as SelectData } from "./action/SelectData";
|
|
42
42
|
|
|
43
43
|
export { default as LookupPage } from "./action/LookupPage";
|
|
44
|
-
export { default as
|
|
44
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
45
45
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
46
46
|
export { default as ViewPage } from "./action/ViewPage";
|
|
47
47
|
export { default as PageView } from "./view/PageView";
|
package/dist/core/PageCache.js
CHANGED
|
@@ -5,10 +5,23 @@ import React from "react";
|
|
|
5
5
|
import { DynamicTemplate } from "./DynamicTemplate";
|
|
6
6
|
// Simple in-memory cache
|
|
7
7
|
const cache = {};
|
|
8
|
+
const getPlatformInfo = async () => {
|
|
9
|
+
const platform = await localAPI.getPlatform();
|
|
10
|
+
const { multi_tenant, tenant_name } = platform !== null && platform !== void 0 ? platform : {};
|
|
11
|
+
return { multi_tenant, tenant_name };
|
|
12
|
+
};
|
|
8
13
|
export const getPage = async (name, fallback) => {
|
|
9
|
-
|
|
14
|
+
let { getTenant: tenant, getModule: module } = fallback;
|
|
10
15
|
const key = `${module}/${name}`; // ✅ unique per module
|
|
11
16
|
if (!cache[key]) {
|
|
17
|
+
if (tenant == null || tenant.trim() === "") {
|
|
18
|
+
// get tenant from platform/info API
|
|
19
|
+
const platform = await localAPI.getPlatform();
|
|
20
|
+
const { multi_tenant, tenant_name } = platform !== null && platform !== void 0 ? platform : {};
|
|
21
|
+
if (String(multi_tenant) === "false") {
|
|
22
|
+
tenant = tenant_name !== null && tenant_name !== void 0 ? tenant_name : "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
12
25
|
const pageInfo = await localAPI.useMgmt(tenant, module).get("pages", name);
|
|
13
26
|
if (!pageInfo) {
|
|
14
27
|
return { template: _jsxs("div", { className: "text-red-500 p-2 border border-red-500", children: ["Page \"", name, "\" not found."] }), pageInfo: null };
|
package/dist/core/PageContext.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useBinding } from "@ramesesinc/client";
|
|
4
4
|
import { localAPI } from "@ramesesinc/lib/local-api";
|
|
5
|
-
import { createContext, useContext, useEffect, useLayoutEffect,
|
|
5
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
6
|
import { parseHashUrl } from "../lib/utils/PageUtils";
|
|
7
7
|
import { useApp } from "./AppContext";
|
|
8
8
|
import { DataBindingProvider } from "./DataContext";
|
|
@@ -39,18 +39,30 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
39
39
|
const pageView = usePageViewContext();
|
|
40
40
|
const binding = useBinding();
|
|
41
41
|
// setup the selectedPath from the handle
|
|
42
|
-
useMemo(() => {
|
|
42
|
+
// useMemo(() => {
|
|
43
|
+
useLayoutEffect(() => {
|
|
43
44
|
const path = handle === null || handle === void 0 ? void 0 : handle.getSelectedPath();
|
|
44
|
-
binding.set
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (binding && typeof binding.set === "function") {
|
|
46
|
+
binding.set("selectedPage", path);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.warn("binding.set is not available, skipping selectedPage setup");
|
|
50
|
+
}
|
|
51
|
+
// return path;
|
|
52
|
+
}, [handle, binding]);
|
|
47
53
|
// for DEV purposes only
|
|
48
|
-
useMemo(() => {
|
|
54
|
+
// useMemo(() => {
|
|
55
|
+
useLayoutEffect(() => {
|
|
49
56
|
const dependHandler = () => {
|
|
50
57
|
// console.log("selectedPage changed => ", binding.get("selectedPage"));
|
|
51
58
|
};
|
|
52
|
-
binding.dependsTo
|
|
53
|
-
|
|
59
|
+
if (binding && typeof binding.dependsTo === "function") {
|
|
60
|
+
binding.dependsTo("selectedPage", dependHandler);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.warn("binding.dependsTo is not available, skipping dependency setup");
|
|
64
|
+
}
|
|
65
|
+
}, [binding]);
|
|
54
66
|
const dataApiHandler = useRef(null);
|
|
55
67
|
const { tenant, module } = useApp();
|
|
56
68
|
const providerRef = {
|
|
@@ -90,14 +102,31 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
90
102
|
};
|
|
91
103
|
/* ------------------ Data ------------------ */
|
|
92
104
|
const getData = () => {
|
|
93
|
-
|
|
105
|
+
if (binding && typeof binding.getData === "function") {
|
|
106
|
+
return binding.getData();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.warn("binding.getData is not available, returning {}");
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
94
112
|
};
|
|
95
113
|
const setData = (value, mode) => {
|
|
96
|
-
binding
|
|
114
|
+
if (binding && typeof binding.setData === "function") {
|
|
115
|
+
binding.setData(value, mode !== null && mode !== void 0 ? mode : "read");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.warn("binding.setData is not available, skipping data set");
|
|
119
|
+
}
|
|
97
120
|
};
|
|
98
121
|
/* ------------------ Reactive deps ------------------ */
|
|
99
122
|
const dependsTo = (name, callback) => {
|
|
100
|
-
|
|
123
|
+
if (binding && typeof binding.dependsTo === "function") {
|
|
124
|
+
return binding.dependsTo(name, callback);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.warn("binding.dependsTo is not available, returning no-op function");
|
|
128
|
+
return () => { };
|
|
129
|
+
}
|
|
101
130
|
};
|
|
102
131
|
const notifyDepends = (name) => {
|
|
103
132
|
binding.notifyDepends(name);
|
|
@@ -110,19 +139,41 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
110
139
|
/* ------------------ Internal props setter ------------------ */
|
|
111
140
|
const set = (name, value) => {
|
|
112
141
|
if (name === "data") {
|
|
113
|
-
binding.setData
|
|
142
|
+
if (binding && typeof binding.setData === "function") {
|
|
143
|
+
binding.setData(value);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.warn("binding.setData is not available, skipping data set");
|
|
147
|
+
}
|
|
114
148
|
}
|
|
115
149
|
else {
|
|
116
|
-
binding.set
|
|
150
|
+
if (binding && typeof binding.set === "function") {
|
|
151
|
+
binding.set(name, value);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.warn("binding.set is not available, skipping set:", name, value);
|
|
155
|
+
}
|
|
117
156
|
}
|
|
118
157
|
};
|
|
119
158
|
const get = (name) => {
|
|
120
159
|
if (name === "data") {
|
|
121
|
-
|
|
160
|
+
if (binding && typeof binding.getData === "function") {
|
|
161
|
+
return binding.getData();
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
console.warn("binding.getData is not available, returning {}");
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (binding && typeof binding.get === "function") {
|
|
169
|
+
const val = binding.get(name);
|
|
170
|
+
// console.log("page context get", name, val, binding.getData());
|
|
171
|
+
return val;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.warn("binding.get is not available, returning undefined for:", name);
|
|
175
|
+
return undefined;
|
|
122
176
|
}
|
|
123
|
-
const val = binding.get(name);
|
|
124
|
-
// console.log("page context get", name, val, binding.getData());
|
|
125
|
-
return val;
|
|
126
177
|
};
|
|
127
178
|
const buildParams = (inputParams, queryParams) => {
|
|
128
179
|
return inputParams;
|
|
@@ -144,10 +195,21 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
144
195
|
return result;
|
|
145
196
|
};
|
|
146
197
|
const setPageParams = (params) => {
|
|
147
|
-
binding.set
|
|
198
|
+
if (binding && typeof binding.set === "function") {
|
|
199
|
+
binding.set("pageParams", params);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.warn("binding.set is not available, skipping pageParams set");
|
|
203
|
+
}
|
|
148
204
|
};
|
|
149
205
|
const getPageParams = () => {
|
|
150
|
-
|
|
206
|
+
if (binding && typeof binding.get === "function") {
|
|
207
|
+
return binding.get("pageParams");
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.warn("binding.get is not available, returning {} for pageParams");
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
151
213
|
};
|
|
152
214
|
/* ------------------ Context value ------------------ */
|
|
153
215
|
const values = {
|
|
@@ -170,7 +232,7 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
170
232
|
getMgmt,
|
|
171
233
|
postMgmt,
|
|
172
234
|
getAllData: () => {
|
|
173
|
-
const allData = Object.assign(Object.assign({}, binding.getUiData()), { data: binding.getData(), pageParams: getPageParams() });
|
|
235
|
+
const allData = Object.assign(Object.assign({}, (binding && typeof binding.getUiData === "function" ? binding.getUiData() : {})), { data: binding && typeof binding.getData === "function" ? binding.getData() : {}, pageParams: getPageParams() });
|
|
174
236
|
return allData;
|
|
175
237
|
},
|
|
176
238
|
setPageParams,
|
|
@@ -187,7 +187,7 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
187
187
|
};
|
|
188
188
|
const popPage = () => {
|
|
189
189
|
var _a, _b, _c;
|
|
190
|
-
// console.log("popPage (pageChain)", uuid, prefix, pageChain);
|
|
190
|
+
// console.log("popPage (pageChain)", uuid, prefix, JSON.stringify(pageChain));
|
|
191
191
|
const { previous: prevChain } = pageChain;
|
|
192
192
|
if (prevChain == null) {
|
|
193
193
|
return;
|
|
@@ -205,15 +205,25 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
205
205
|
const idx = newPath.lastIndexOf("/");
|
|
206
206
|
if (idx >= 0) {
|
|
207
207
|
newPath = path.substring(idx + 1);
|
|
208
|
+
// newPath = newPath.substring(idx + 1);
|
|
208
209
|
}
|
|
209
210
|
page = newPath;
|
|
210
|
-
// console.log("popPage 1.
|
|
211
|
+
// console.log("popPage 1.3", uuid, page);
|
|
211
212
|
}
|
|
212
213
|
else {
|
|
213
214
|
const [, ...anchors] = path.split("#");
|
|
214
215
|
page = (_b = anchors.at(-1)) !== null && _b !== void 0 ? _b : "";
|
|
216
|
+
// console.log("popPage 1.4", uuid, "page:", page, "path:", path);
|
|
215
217
|
if (page === "") {
|
|
216
|
-
page = path;
|
|
218
|
+
// page = path;
|
|
219
|
+
const withoutHash = path.split("#")[0];
|
|
220
|
+
const idx = withoutHash.lastIndexOf("/");
|
|
221
|
+
if (idx >= 0) {
|
|
222
|
+
page = withoutHash.substring(idx + 1);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
page = path;
|
|
226
|
+
}
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
const newPageChain = Object.assign({}, prevChain);
|
|
@@ -221,6 +231,7 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
221
231
|
if (!standalone) {
|
|
222
232
|
history.pushState(null, "", path);
|
|
223
233
|
}
|
|
234
|
+
// console.log("popPage 2", uuid, page);
|
|
224
235
|
(_c = handleRef.current) === null || _c === void 0 ? void 0 : _c.renderPage(page);
|
|
225
236
|
};
|
|
226
237
|
const hasBackPage = () => {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|