@ramesesinc/platform-core 0.1.9 → 0.1.11

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 (76) hide show
  1. package/dist/components/action/DeleteData.d.ts +1 -0
  2. package/dist/components/action/DeleteData.js +16 -5
  3. package/dist/components/action/LookupPage.d.ts +2 -1
  4. package/dist/components/action/LookupPage.js +4 -3
  5. package/dist/components/action/Play.d.ts +6 -0
  6. package/dist/components/action/Play.js +40 -0
  7. package/dist/components/action/ProgressBar.d.ts +8 -0
  8. package/dist/components/action/ProgressBar.js +146 -0
  9. package/dist/components/action/ViewPage.d.ts +3 -1
  10. package/dist/components/action/ViewPage.js +22 -10
  11. package/dist/components/common/UIMenu.d.ts +1 -0
  12. package/dist/components/common/UIMenu.js +5 -3
  13. package/dist/components/index.d.ts +4 -1
  14. package/dist/components/index.js +4 -1
  15. package/dist/components/input/Combo.d.ts +21 -0
  16. package/dist/components/input/Combo.js +137 -0
  17. package/dist/components/input/DateField.js +7 -14
  18. package/dist/components/input/Text.d.ts +5 -0
  19. package/dist/components/input/Text.js +42 -7
  20. package/dist/components/input/YearPicker.js +3 -2
  21. package/dist/components/list/EditableMenu.d.ts +2 -0
  22. package/dist/components/list/EditableMenu.js +128 -0
  23. package/dist/components/list/TabMenu.js +2 -2
  24. package/dist/components/list/TreeMenu.js +35 -13
  25. package/dist/components/table/DataList.d.ts +1 -1
  26. package/dist/components/table/DataList.js +56 -29
  27. package/dist/components/table/DataTable.d.ts +2 -0
  28. package/dist/components/table/DataTable.js +31 -22
  29. package/dist/components/view/FilterView.js +1 -1
  30. package/dist/components/view/HtmlForm.js +12 -9
  31. package/dist/components/view/HtmlView.js +1 -1
  32. package/dist/components/view/PageView.d.ts +1 -0
  33. package/dist/components/view/PageView.js +38 -11
  34. package/dist/components/view/PopupView.d.ts +1 -0
  35. package/dist/components/view/PopupView.js +4 -4
  36. package/dist/components/view/RootView.d.ts +1 -0
  37. package/dist/components/view/RootView.js +18 -18
  38. package/dist/components/view/WizardView.d.ts +1 -1
  39. package/dist/components/view/WizardView.js +7 -25
  40. package/dist/core/AuthContext.js +1 -1
  41. package/dist/core/DynamicComponent.d.ts +2 -1
  42. package/dist/core/DynamicComponent.js +24 -2
  43. package/dist/core/Page.d.ts +1 -0
  44. package/dist/core/Page.js +6 -5
  45. package/dist/core/PageCache.d.ts +0 -2
  46. package/dist/core/PageCache.js +3 -8
  47. package/dist/core/PageContext.d.ts +1 -0
  48. package/dist/core/PageContext.js +16 -2
  49. package/dist/core/PageViewContext.d.ts +8 -2
  50. package/dist/core/PageViewContext.js +155 -86
  51. package/dist/core/Panel.js +34 -12
  52. package/dist/core/StepHandler.d.ts +1 -1
  53. package/dist/core/StepHandler.js +58 -21
  54. package/dist/index.css +98 -0
  55. package/dist/layouts/CardLayout.d.ts +2 -2
  56. package/dist/layouts/CardLayout.js +3 -4
  57. package/dist/layouts/HPanel.d.ts +2 -2
  58. package/dist/layouts/HPanel.js +1 -2
  59. package/dist/layouts/VPanel.d.ts +2 -2
  60. package/dist/layouts/VPanel.js +1 -2
  61. package/dist/layouts/index.d.ts +2 -3
  62. package/dist/layouts/index.js +2 -3
  63. package/dist/lib/utils/ExprUtil.js +18 -29
  64. package/dist/lib/utils/ResourceLoader.js +19 -7
  65. package/dist/lib/utils/SectionProvider.js +1 -1
  66. package/dist/lib/utils/initResourceLoader.d.ts +2 -0
  67. package/dist/lib/utils/initResourceLoader.js +64 -95
  68. package/dist/lib/utils/nunjucks.d.ts +2 -0
  69. package/dist/lib/utils/nunjucks.js +8 -0
  70. package/dist/templates/CrudFormTemplate.js +2 -3
  71. package/dist/templates/DataListTemplate.js +1 -1
  72. package/dist/templates/WizardTemplate.d.ts +3 -0
  73. package/dist/templates/WizardTemplate.js +17 -10
  74. package/package.json +1 -1
  75. package/dist/components/input/Select.d.ts +0 -14
  76. package/dist/components/input/Select.js +0 -40
@@ -1,10 +1,10 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { getError } from "@ramesesinc/client";
3
3
  import { forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
4
4
  import Page from "../../core/Page";
5
5
  import { PageViewProvider } from "../../core/PageViewContext";
6
6
  const RootView = (props) => {
7
- const { url, eventHandler, standalone = true } = props !== null && props !== void 0 ? props : {};
7
+ const { url, eventHandler, standalone = true, options = {} } = props !== null && props !== void 0 ? props : {};
8
8
  const [paths, setPaths] = useState([]);
9
9
  const mainPath = useRef("");
10
10
  const [newRootPath, setNewRootPath] = useState(null);
@@ -16,7 +16,8 @@ const RootView = (props) => {
16
16
  try {
17
17
  // console.log("RootView loadPage", path); // main#tasklist
18
18
  const pageUUID = "page-" + Math.random().toString(36).slice(2);
19
- comp = _jsx(Page, { url: path }, pageUUID);
19
+ const newUrl = url.split("#");
20
+ comp = _jsx(Page, { url: path, options: options }, pageUUID);
20
21
  }
21
22
  catch (error) {
22
23
  const e = getError(error);
@@ -29,24 +30,24 @@ const RootView = (props) => {
29
30
  (_a = slotRef.current) === null || _a === void 0 ? void 0 : _a.update(comp);
30
31
  };
31
32
  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);
33
+ const splitPaths = (url == null || url.trim() === "" ? "" : url).split("#");
34
+ const [mainPage] = splitPaths;
35
+ mainPath.current = mainPage;
36
+ setPaths(splitPaths);
37
37
  }, [url]);
38
+ // fires when paths changes — handles both initial load and url change
38
39
  useEffect(() => {
39
- // this routine is for the initial loading
40
- // pass the original url
41
- loadPage(url);
42
- setReInitPage(false);
40
+ if (paths.length === 0)
41
+ return;
42
+ loadPage(paths[0]);
43
43
  }, [paths]);
44
+ // fires when mode=window navigation happens
45
+ // setPaths first, then loadPage is triggered by paths useEffect
44
46
  useEffect(() => {
45
- if (reInitPage) {
46
- // let the initial loading take effect
47
+ if (newRootPath == null)
47
48
  return;
48
- }
49
- loadPage(newRootPath);
49
+ setPaths([newRootPath]); // ← paths updates first
50
+ // loadPage will be called by paths useEffect after setPaths takes effect
50
51
  }, [newRootPath]);
51
52
  const pageViewHandle = {
52
53
  displayName: "RootView#pageViewHandle",
@@ -54,7 +55,6 @@ const RootView = (props) => {
54
55
  providerRef.current = ref;
55
56
  },
56
57
  renderPage: (page) => {
57
- // console.log("RootView renderPage", page);
58
58
  setNewRootPath(page);
59
59
  },
60
60
  isStandalone: () => standalone,
@@ -71,5 +71,5 @@ const ChildrenSlot = memo(forwardRef((_, ref) => {
71
71
  setContent(content);
72
72
  },
73
73
  }), []);
74
- return _jsx(_Fragment, { children: content == null ? null : content });
74
+ return _jsx("div", { className: "px-2", children: content == null ? null : content });
75
75
  }));
@@ -1,5 +1,5 @@
1
1
  type WizardViewProps = {
2
- name: string;
2
+ title?: string;
3
3
  items: Record<string, any>[];
4
4
  };
5
5
  declare const WizardView: (props: WizardViewProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,34 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef } from "react";
2
+ import { useRef, useState } from "react";
3
3
  import { usePageContext } from "../../core/PageContext";
4
4
  import { StepHandler } from "../../core/StepHandler";
5
- import ComponentView from "./ComponentView";
5
+ import WizardTemplate from "../../templates/WizardTemplate";
6
6
  const WizardView = (props) => {
7
- const { name = "wizard", items = [] } = props !== null && props !== void 0 ? props : {};
8
- const pageContext = usePageContext();
7
+ const { title, items = [] } = props !== null && props !== void 0 ? props : {};
8
+ const [currentItem, setCurrentItem] = useState(items[0]);
9
9
  const handlerRef = useRef(null);
10
+ const pageContext = usePageContext();
10
11
  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;
12
+ handlerRef.current = StepHandler(items, (item) => setCurrentItem(item), () => pageContext.getData());
28
13
  }
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 }) }));
14
+ return (_jsx(WizardTemplate, { title: (currentItem === null || currentItem === void 0 ? void 0 : currentItem.title) || title, component: currentItem === null || currentItem === void 0 ? void 0 : currentItem.component, componentid: currentItem === null || currentItem === void 0 ? void 0 : currentItem.componentid, attr: currentItem === null || currentItem === void 0 ? void 0 : currentItem.attr, stepHandler: handlerRef.current }));
33
15
  };
34
16
  export default WizardView;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // lib/context/AuthContext.tsx
3
3
  import { createContext, useContext, useEffect, useState } from "react";
4
- import * as auth from "../core/auth";
5
4
  import { useApp } from "./AppContext";
5
+ import * as auth from "./auth";
6
6
  export const useAuth = () => {
7
7
  const ctx = useContext(AuthContext);
8
8
  if (!ctx)
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  export interface DynamicComponentConfig {
3
- component: string;
3
+ component?: string;
4
+ componentid?: string;
4
5
  attr?: Record<string, any>;
5
6
  }
6
7
  interface DynamicComponentProps {
@@ -11,11 +11,33 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import React, { useEffect, useState } from "react";
14
15
  import { ResourceLoader } from "../lib/utils/ResourceLoader";
15
- import React from "react";
16
+ import { DynamicTemplate } from "./DynamicTemplate";
17
+ import { usePageContext } from "./PageContext";
16
18
  export const DynamicComponent = ({ config, fallback = _jsx("div", { style: { color: "red" }, children: "Component not found" }), onError, }) => {
17
- const { component, attr = {} } = config !== null && config !== void 0 ? config : {};
19
+ const { component, componentid, attr = {} } = config !== null && config !== void 0 ? config : {};
18
20
  const _a = attr !== null && attr !== void 0 ? attr : {}, { key } = _a, restAttr = __rest(_a, ["key"]);
21
+ const pageContext = usePageContext();
22
+ const [resolvedNode, setResolvedNode] = useState(null);
23
+ useEffect(() => {
24
+ if (!componentid)
25
+ return;
26
+ pageContext.getMgmt("components", componentid).then((res) => {
27
+ if (!res)
28
+ return;
29
+ const { template, attr: resAttr } = res;
30
+ const mergedAttr = Object.assign(Object.assign({}, resAttr), restAttr);
31
+ setResolvedNode(_jsx(DynamicTemplate, { template: template, attr: mergedAttr }));
32
+ });
33
+ }, [componentid]);
34
+ // componentid path — wait for async resolution
35
+ if (componentid) {
36
+ return resolvedNode ? _jsx(_Fragment, { children: resolvedNode }) : null;
37
+ }
38
+ // component path — sync resolution via ResourceLoader
39
+ if (!component)
40
+ return _jsx(_Fragment, { children: fallback });
19
41
  let Comp;
20
42
  try {
21
43
  Comp = ResourceLoader.getComponent(component);
@@ -1,6 +1,7 @@
1
1
  type PageProps = {
2
2
  url?: string | null;
3
3
  fallback?: React.ReactNode;
4
+ options?: Record<string, any>;
4
5
  };
5
6
  declare const Page: (props: PageProps) => import("react/jsx-runtime").JSX.Element;
6
7
  export default Page;
package/dist/core/Page.js CHANGED
@@ -11,7 +11,7 @@ import { PageProvider } from "./PageContext";
11
11
  import { usePageViewContext } from "./PageViewContext";
12
12
  import { usePopupContext } from "./PopupContext";
13
13
  const Page = (props) => {
14
- const { url: finalUrl, fallback = _jsx("div", { children: "Loading page..." }) } = props !== null && props !== void 0 ? props : {};
14
+ const { url: finalUrl, fallback = _jsx("div", { children: "Loading page..." }), options = {} } = props !== null && props !== void 0 ? props : {};
15
15
  const [uuid] = useState(() => Math.random().toString(36).slice(2));
16
16
  const [value, setValue] = useState(null);
17
17
  const [cache, setCache] = useState({});
@@ -101,10 +101,8 @@ const Page = (props) => {
101
101
  params = res === null || res === void 0 ? void 0 : res.params;
102
102
  }
103
103
  const resolveParams = replaceValues(req.params, params);
104
- // console.log("Page fetchData params", uuid, value, {params, resolveParams});
105
- const resp = await pageContext.current.execService(req.api, resolveParams);
106
- const { data } = resp !== null && resp !== void 0 ? resp : {};
107
- result = data !== null && data !== void 0 ? data : resp;
104
+ // console.log("page fetchData exec service 1.2", req.api, resolveParams);
105
+ result = await pageContext.current.execService(req.api, resolveParams);
108
106
  }
109
107
  return result;
110
108
  }, [value]);
@@ -124,6 +122,9 @@ const Page = (props) => {
124
122
  getSelectedPath: () => {
125
123
  return originalData.selectedPath;
126
124
  },
125
+ getOptions: () => {
126
+ return options;
127
+ },
127
128
  };
128
129
  return (_jsx(PageProvider, { handle: pageHandle, children: _jsx(ChildrenSlot, { ref: slotRef }) }));
129
130
  };
@@ -6,10 +6,8 @@ interface CacheFallback {
6
6
  export declare const getPage: (name: string, fallback: CacheFallback) => Promise<{
7
7
  template: import("react/jsx-runtime").JSX.Element;
8
8
  pageInfo: null;
9
- hasSelectionHandling?: undefined;
10
9
  } | {
11
10
  template: React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>;
12
11
  pageInfo: any;
13
- hasSelectionHandling: any;
14
12
  }>;
15
13
  export {};
@@ -5,11 +5,6 @@ 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 ?? {};
11
- // return { multi_tenant, tenant_name };
12
- // };
13
8
  export const getPage = async (name, fallback) => {
14
9
  let { getTenant: tenant, getModule: module } = fallback;
15
10
  const key = `${module}/${name}`; // ✅ unique per module
@@ -30,10 +25,10 @@ export const getPage = async (name, fallback) => {
30
25
  delete pageInfo.template;
31
26
  delete pageInfo.attr;
32
27
  const tmpl = _jsx(DynamicTemplate, { template: template, attr: Object.assign(Object.assign({}, attr), { title }) });
33
- const hasSelectionHandling = template === "ExplorerTemplate";
34
- cache[key] = { template: tmpl, pageInfo, hasSelectionHandling };
28
+ // const hasSelectionHandling = template === "ExplorerTemplate";
29
+ cache[key] = { template: tmpl, pageInfo /*, hasSelectionHandling*/ };
35
30
  }
36
31
  const pageCache = cache[key];
37
32
  const newTemplate = React.cloneElement(pageCache.template);
38
- return { template: newTemplate, pageInfo: pageCache.pageInfo, hasSelectionHandling: pageCache.hasSelectionHandling };
33
+ return { template: newTemplate, pageInfo: pageCache.pageInfo /*, hasSelectionHandling: pageCache.hasSelectionHandling*/ };
39
34
  };
@@ -34,6 +34,7 @@ export type PageContextValue = {
34
34
  export type PageHandle = {
35
35
  init: (ref: PageContextValue) => void;
36
36
  getSelectedPath: () => string | null;
37
+ getOptions: () => Record<string, any>;
37
38
  };
38
39
  export type PageProviderRef = {
39
40
  set: (name: string, value: any) => void;
@@ -37,7 +37,20 @@ export const PageProvider = ({ handle, children }) => {
37
37
  // console.log("PageContext paths", uuid, paths);
38
38
  const parentContext = useContext(PageContext);
39
39
  const pageView = usePageViewContext();
40
- const binding = useBinding();
40
+ const { action = "read" } = (handle === null || handle === void 0 ? void 0 : handle.getOptions()) || {};
41
+ const binding = useBinding({}, action);
42
+ useLayoutEffect(() => {
43
+ var _a;
44
+ if (handle == null)
45
+ return;
46
+ handle.init(contextValue);
47
+ // load params from pageChain into binding
48
+ const chainInfo = pageView.getPageChainInfo();
49
+ const viewParams = (_a = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.params) !== null && _a !== void 0 ? _a : {};
50
+ Object.keys(viewParams).forEach((k) => {
51
+ set(k, viewParams[k]);
52
+ });
53
+ }, []);
41
54
  // setup the selectedPath from the handle
42
55
  useMemo(() => {
43
56
  // useLayoutEffect(() => {
@@ -112,7 +125,8 @@ export const PageProvider = ({ handle, children }) => {
112
125
  };
113
126
  const setData = (value, mode) => {
114
127
  if (binding && typeof binding.setData === "function") {
115
- binding.setData(value, mode !== null && mode !== void 0 ? mode : "read");
128
+ const oldMode = binding.getMode();
129
+ binding.setData(value, mode !== null && mode !== void 0 ? mode : oldMode);
116
130
  }
117
131
  else {
118
132
  console.warn("binding.setData is not available, skipping data set");
@@ -22,7 +22,6 @@ export type PageViewContextValue = {
22
22
  getTitle: () => string | null;
23
23
  setTitle: (title: string | null) => void;
24
24
  setPage: (page: string | null, options?: PageOptions) => void;
25
- setSelectedPage: (page: string | null) => void;
26
25
  getSelectedPage: () => string | null;
27
26
  pushPage: (page: string) => void;
28
27
  popPage: () => void;
@@ -32,6 +31,12 @@ export type PageViewContextValue = {
32
31
  setSelectionHandling: (hasHandling: boolean) => void;
33
32
  getOriginalLocationInfo: () => PageChainInfo | null;
34
33
  getEventHandler: () => EventHandler | null;
34
+ isRootView: () => boolean;
35
+ getUrl: () => string;
36
+ getPage: () => string;
37
+ getParams: () => Record<string, string>;
38
+ getSubPaths: () => string[];
39
+ getPageChainInfo: () => PageChainInfo;
35
40
  };
36
41
  export type PageViewHandle = {
37
42
  init: (ref: PageViewContextValue) => void;
@@ -39,11 +44,12 @@ export type PageViewHandle = {
39
44
  isStandalone: () => boolean;
40
45
  };
41
46
  export type PageSelectionHandler = {};
42
- type PageChainInfo = {
47
+ export type PageChainInfo = {
43
48
  path: string;
44
49
  base: string;
45
50
  page: string;
46
51
  options: PageOptions;
52
+ params: Record<string, any>;
47
53
  };
48
54
  type PageViewProviderProps = {
49
55
  paths: string[];