@ramesesinc/platform-core 0.1.9 → 0.1.10

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 (58) hide show
  1. package/dist/components/action/LookupPage.d.ts +2 -1
  2. package/dist/components/action/LookupPage.js +4 -3
  3. package/dist/components/action/Play.d.ts +6 -0
  4. package/dist/components/action/Play.js +40 -0
  5. package/dist/components/action/ProgressBar.d.ts +8 -0
  6. package/dist/components/action/ProgressBar.js +146 -0
  7. package/dist/components/action/ViewPage.d.ts +2 -1
  8. package/dist/components/action/ViewPage.js +19 -9
  9. package/dist/components/common/UIMenu.js +4 -3
  10. package/dist/components/index.d.ts +4 -1
  11. package/dist/components/index.js +4 -1
  12. package/dist/components/input/Combo.d.ts +21 -0
  13. package/dist/components/input/Combo.js +137 -0
  14. package/dist/components/input/DateField.js +7 -14
  15. package/dist/components/input/Text.d.ts +5 -0
  16. package/dist/components/input/Text.js +42 -7
  17. package/dist/components/list/EditableMenu.d.ts +2 -0
  18. package/dist/components/list/EditableMenu.js +128 -0
  19. package/dist/components/list/TabMenu.js +2 -2
  20. package/dist/components/list/TreeMenu.js +17 -12
  21. package/dist/components/table/DataList.d.ts +1 -1
  22. package/dist/components/table/DataList.js +49 -24
  23. package/dist/components/table/DataTable.d.ts +2 -0
  24. package/dist/components/table/DataTable.js +31 -22
  25. package/dist/components/view/FilterView.js +1 -1
  26. package/dist/components/view/HtmlForm.js +12 -9
  27. package/dist/components/view/PageView.js +36 -9
  28. package/dist/components/view/RootView.js +16 -16
  29. package/dist/core/AuthContext.js +1 -1
  30. package/dist/core/Page.js +2 -4
  31. package/dist/core/PageCache.d.ts +0 -2
  32. package/dist/core/PageCache.js +3 -8
  33. package/dist/core/PageContext.js +12 -0
  34. package/dist/core/PageViewContext.d.ts +8 -2
  35. package/dist/core/PageViewContext.js +129 -75
  36. package/dist/core/Panel.js +31 -9
  37. package/dist/index.css +79 -0
  38. package/dist/layouts/CardLayout.d.ts +2 -2
  39. package/dist/layouts/CardLayout.js +3 -4
  40. package/dist/layouts/HPanel.d.ts +2 -2
  41. package/dist/layouts/HPanel.js +1 -2
  42. package/dist/layouts/VPanel.d.ts +2 -2
  43. package/dist/layouts/VPanel.js +1 -2
  44. package/dist/layouts/index.d.ts +2 -3
  45. package/dist/layouts/index.js +2 -3
  46. package/dist/lib/utils/ExprUtil.js +18 -29
  47. package/dist/lib/utils/ResourceLoader.js +19 -7
  48. package/dist/lib/utils/SectionProvider.js +1 -1
  49. package/dist/lib/utils/initResourceLoader.d.ts +2 -0
  50. package/dist/lib/utils/initResourceLoader.js +64 -95
  51. package/dist/lib/utils/nunjucks.d.ts +2 -0
  52. package/dist/lib/utils/nunjucks.js +8 -0
  53. package/dist/templates/CrudFormTemplate.js +2 -3
  54. package/dist/templates/DataListTemplate.js +1 -1
  55. package/dist/templates/WizardTemplate.js +3 -1
  56. package/package.json +1 -1
  57. package/dist/components/input/Select.d.ts +0 -14
  58. package/dist/components/input/Select.js +0 -40
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- const VPanel = ({ children, gap = 0, style, className }) => {
3
+ export const VPanel = ({ children, gap = 0, style, className }) => {
4
4
  const panelStyle = Object.assign({ display: "flex", flexDirection: "column", gap: gap }, style);
5
5
  return (_jsx("div", { style: panelStyle, className: className, children: children }));
6
6
  };
7
- export default VPanel;
@@ -1,12 +1,11 @@
1
1
  export { default as BorderLayout } from "./BorderLayout";
2
2
  export * from "./CardLayout";
3
- export { default as CardLayout } from "./CardLayout";
4
3
  export { default as CenterLayout } from "./CenterLayout";
5
4
  export { default as GridLayout } from "./GridLayout";
6
5
  export { default as HorizontalLayout } from "./HorizontalLayout";
7
- export { default as HPanel } from "./HPanel";
6
+ export * from "./HPanel";
8
7
  export { default as MainLayout } from "./MainLayout";
9
8
  export { default as PageLayout } from "./PageLayout";
10
- export { default as VPanel } from "./VPanel";
9
+ export * from "./VPanel";
11
10
  export { default as XLayout } from "./XLayout";
12
11
  export { default as YLayout } from "./YLayout";
@@ -1,12 +1,11 @@
1
1
  export { default as BorderLayout } from "./BorderLayout";
2
2
  export * from "./CardLayout";
3
- export { default as CardLayout } from "./CardLayout";
4
3
  export { default as CenterLayout } from "./CenterLayout";
5
4
  export { default as GridLayout } from "./GridLayout";
6
5
  export { default as HorizontalLayout } from "./HorizontalLayout";
7
- export { default as HPanel } from "./HPanel";
6
+ export * from "./HPanel";
8
7
  export { default as MainLayout } from "./MainLayout";
9
8
  export { default as PageLayout } from "./PageLayout";
10
- export { default as VPanel } from "./VPanel";
9
+ export * from "./VPanel";
11
10
  export { default as XLayout } from "./XLayout";
12
11
  export { default as YLayout } from "./YLayout";
@@ -1,18 +1,18 @@
1
- // import nunjucks from "nunjucks";
2
- const nunjucks = require("nunjucks");
3
- let _nunjucksEnv = null;
4
- const getNunjucksEnv = () => {
5
- if (!_nunjucksEnv) {
6
- _nunjucksEnv = new nunjucks.Environment(null, {
7
- autoescape: false,
8
- tags: {
9
- variableStart: "{{",
10
- variableEnd: "}}",
11
- },
12
- });
13
- }
14
- return _nunjucksEnv;
15
- };
1
+ import nunjucks from "nunjucks";
2
+ // Configure Nunjucks environment
3
+ // export const nunjucksEnv = new nunjucks.Environment(undefined, {
4
+ // autoescape: false, // IMPORTANT: you already control the source
5
+ // throwOnUndefined: false,
6
+ // trimBlocks: true,
7
+ // lstripBlocks: true,
8
+ // });
9
+ const nunjucksEnv = new nunjucks.Environment(null, {
10
+ autoescape: false,
11
+ tags: {
12
+ variableStart: "{{",
13
+ variableEnd: "}}",
14
+ },
15
+ });
16
16
  /**
17
17
  * Renders an expression template with the provided data
18
18
  * @param expr - The expression template string
@@ -23,22 +23,11 @@ export const render = (expr, data) => {
23
23
  if (!expr)
24
24
  return "";
25
25
  try {
26
- return getNunjucksEnv().renderString(expr, data);
26
+ //process basic nanjucks expression {{val}}
27
+ return nunjucksEnv.renderString(expr, data);
27
28
  }
28
29
  catch (error) {
29
30
  console.error("Expression render error:", error);
30
- return expr;
31
+ return expr; // Return original expression on error
31
32
  }
32
33
  };
33
- // import Mustache from "mustache";
34
- // // Disable HTML escaping since you control the source
35
- // Mustache.escape = (text) => text;
36
- // export const render = (expr: string, data: any): string => {
37
- // if (!expr) return "";
38
- // try {
39
- // return Mustache.render(expr, data);
40
- // } catch (error) {
41
- // console.error("Expression render error:", error);
42
- // return expr;
43
- // }
44
- // };
@@ -10,22 +10,34 @@ export class ResourceLoader {
10
10
  }
11
11
  static getTemplate(name, loaderKey = "default") {
12
12
  const cacheKey = `${loaderKey}:${name}`;
13
- if (this.cache[cacheKey])
13
+ if (this.cache[cacheKey]) {
14
14
  return this.cache[cacheKey];
15
+ }
15
16
  const loader = loaderKey === "default" ? this.defaultLoader : this.loaders[loaderKey];
16
17
  if (!loader) {
18
+ console.error("No loader found for key:", loaderKey);
17
19
  const Fallback = dynamic(() => Promise.resolve({
18
20
  default: () => React.createElement("div", { style: { color: "red" } }, `No loader registered for "${loaderKey}"`),
19
21
  }));
20
22
  this.cache[cacheKey] = Fallback;
21
23
  return Fallback;
22
24
  }
23
- const Comp = loader(name);
24
- // this is temporary it should be cloned
25
- // if (loaderKey != "component") {
26
- // this.cache[cacheKey] = Comp;
27
- // }
28
- return Comp;
25
+ try {
26
+ const Comp = loader(name);
27
+ // this is temporary it should be cloned
28
+ // if (loaderKey != "component") {
29
+ // this.cache[cacheKey] = Comp;
30
+ // }
31
+ return Comp;
32
+ }
33
+ catch (err) {
34
+ console.error("Error in loader:", err);
35
+ const Fallback = dynamic(() => Promise.resolve({
36
+ default: () => React.createElement("div", { style: { color: "red" } }, `Error loading template "${name}": ${err instanceof Error ? err.message : String(err)}`),
37
+ }));
38
+ this.cache[cacheKey] = Fallback;
39
+ return Fallback;
40
+ }
29
41
  }
30
42
  // Convenience helpers
31
43
  static getComponent(name) {
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { DynamicComponent } from "../../core/DynamicComponent";
3
- import HPanel from "../../layouts/HPanel";
3
+ import { HPanel } from "../../layouts/HPanel";
4
4
  export const SectionProvider = (attr = {}) => {
5
5
  const sections = {};
6
6
  return {
@@ -0,0 +1,2 @@
1
+ import { ResourceLoader } from "./ResourceLoader";
2
+ export default ResourceLoader;
@@ -1,95 +1,64 @@
1
- "use strict";
2
- // import dynamic from "next/dynamic";
3
- // import React from "react";
4
- // import { ResourceLoader } from "./ResourceLoader";
5
- // const isDev = process.env.NODE_ENV === "development";
6
- // console.log("dev mode, is", isDev);
7
- // const packageLoaders: Record<string, () => Promise<any>> = {
8
- // "@ramesesinc/platform-core": () => import("@ramesesinc/platform-core"),
9
- // "@ramesesinc/client": () => import("@ramesesinc/client"),
10
- // };
11
- // const templateLoaders: Record<string, () => Promise<any>> = isDev
12
- // ? { "@/templates": () => import("@/templates"), ...packageLoaders }
13
- // : { ...packageLoaders, "@/templates": () => import("@/templates") };
14
- // const componentLoaders: Record<string, () => Promise<any>> = isDev
15
- // ? { "@/components": () => import("@/components"), ...packageLoaders }
16
- // : { ...packageLoaders, "@/components": () => import("@/components") };
17
- // /* ======================== Template Loader ======================== */
18
- // const templateLoader = (name: string) =>
19
- // dynamic(async () => {
20
- // for (const loader of Object.values(templateLoaders)) {
21
- // try {
22
- // const mod = await loader();
23
- // const Temp = (mod as Record<string, any>)[name];
24
- // if (Temp) {
25
- // let hasSelectionHandling = false;
26
- // try {
27
- // hasSelectionHandling = Temp.hasSelectionHandling ?? false;
28
- // } catch (err) {}
29
- // return { default: Temp, hasSelectionHandling };
30
- // }
31
- // } catch (err) {
32
- // console.log("template loader Error", name, err);
33
- // }
34
- // }
35
- // // fallback → template not found in any path
36
- // return {
37
- // default: () =>
38
- // React.createElement(
39
- // "div",
40
- // {
41
- // style: { color: "red", padding: "8px", border: "1px solid red" },
42
- // },
43
- // `Template "${name}" is not registered`,
44
- // ),
45
- // };
46
- // });
47
- // /* ======================== Component Loader ======================== */
48
- // const componentLoader = (name: string) =>
49
- // dynamic(async () => {
50
- // for (const loader of Object.values(componentLoaders)) {
51
- // try {
52
- // const mod = await loader();
53
- // const Comp = (mod as Record<string, any>)[name];
54
- // if (Comp) {
55
- // return { default: Comp };
56
- // }
57
- // } catch (err) {
58
- // console.log("component loader Error", name, err);
59
- // }
60
- // }
61
- // return {
62
- // default: () =>
63
- // React.createElement(
64
- // "div",
65
- // {
66
- // style: { color: "red", padding: "8px", border: "1px solid red" },
67
- // },
68
- // `Component "${name}" is not registered`,
69
- // ),
70
- // };
71
- // });
72
- // // const actionLoader = (name: string) =>
73
- // // dynamic(async () => {
74
- // // try {
75
- // // // 1️⃣ local component
76
- // // const mod = await import(`@/actions`);
77
- // // return { default: mod[name as keyof typeof mod] };
78
- // // } catch {
79
- // // try {
80
- // // // 2️⃣ package component
81
- // // const pkg = await import("@ramesesinc/react-ui");
82
- // // const Comp = (pkg as Record<string, any>)[name];
83
- // // if (!Comp) throw new Error();
84
- // // return { default: Comp };
85
- // // } catch {
86
- // // // 3️⃣ neither found → throw
87
- // // throw new Error(`Component "${name}" not found in local components or "@ramesesinc/react-ui"`);
88
- // // }
89
- // // }
90
- // // });
91
- // /* ---------------- Register loaders ---------------- */
92
- // ResourceLoader.setDefaultLoader(templateLoader);
93
- // ResourceLoader.registerLoader("component", componentLoader);
94
- // // ResourceLoader.registerLoader("action", actionLoader);
95
- // export default ResourceLoader;
1
+ import dynamic from "next/dynamic";
2
+ import React from "react";
3
+ import { ResourceLoader } from "./ResourceLoader";
4
+ /* ======================== Shared ======================== */
5
+ const createLoaderRef = (localKey, localLoader) => {
6
+ const ref = { current: null };
7
+ return () => {
8
+ if (ref.current == null) {
9
+ const res = {};
10
+ if (process.env.NODE_ENV === "development") {
11
+ // console.log("process.env.NODE_ENV", process.env.NODE_ENV);
12
+ res[localKey] = localLoader;
13
+ }
14
+ // console.log("process.env.NODE_ENV", process.env.NODE_ENV);
15
+ res["@ramesesinc/platform-core"] = () => import("@ramesesinc/platform-core");
16
+ res["@ramesesinc/client"] = () => import("@ramesesinc/client");
17
+ ref.current = res;
18
+ }
19
+ return ref.current;
20
+ };
21
+ };
22
+ const getTemplateLoaders = createLoaderRef("@/templates", () => import("@/templates"));
23
+ const getComponentLoaders = createLoaderRef("@/components", () => import("@/components"));
24
+ /* ======================== Template Loader ======================== */
25
+ const templateLoader = (name) => dynamic(async () => {
26
+ var _a;
27
+ for (const loader of Object.values(getTemplateLoaders())) {
28
+ try {
29
+ const mod = await loader();
30
+ const Temp = mod[name];
31
+ if (Temp) {
32
+ return { default: Temp, hasSelectionHandling: (_a = Temp.hasSelectionHandling) !== null && _a !== void 0 ? _a : false };
33
+ }
34
+ }
35
+ catch (err) {
36
+ console.log("template loader Error", name, err);
37
+ }
38
+ }
39
+ return {
40
+ default: () => React.createElement("div", { style: { color: "red", padding: "8px", border: "1px solid red" } }, `Template "${name}" is not registered`),
41
+ };
42
+ });
43
+ /* ======================== Component Loader ======================== */
44
+ const componentLoader = (name) => dynamic(async () => {
45
+ for (const loader of Object.values(getComponentLoaders())) {
46
+ try {
47
+ const mod = await loader();
48
+ const Comp = mod[name];
49
+ if (Comp) {
50
+ return { default: Comp };
51
+ }
52
+ }
53
+ catch (err) {
54
+ console.log("component loader Error", name, err);
55
+ }
56
+ }
57
+ return {
58
+ default: () => React.createElement("div", { style: { color: "red", padding: "8px", border: "1px solid red" } }, `Component "${name}" is not registered`),
59
+ };
60
+ });
61
+ /* ---------------- Register loaders ---------------- */
62
+ ResourceLoader.setDefaultLoader(templateLoader);
63
+ ResourceLoader.registerLoader("component", componentLoader);
64
+ export default ResourceLoader;
@@ -0,0 +1,2 @@
1
+ import nunjucks from "nunjucks";
2
+ export declare const nunjucksEnv: nunjucks.Environment;
@@ -0,0 +1,8 @@
1
+ import nunjucks from "nunjucks";
2
+ // Client-side only environment
3
+ export const nunjucksEnv = new nunjucks.Environment(undefined, {
4
+ autoescape: false, // IMPORTANT: you already control the source
5
+ throwOnUndefined: false,
6
+ trimBlocks: true,
7
+ lstripBlocks: true,
8
+ });
@@ -1,8 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import BorderLayout from "../layouts/BorderLayout";
3
- import HPanel from "../layouts/HPanel";
4
- import VPanel from "../layouts/VPanel";
5
- import { SectionProvider } from "../lib/utils/SectionProvider";
3
+ import { HPanel, VPanel } from "../layouts";
4
+ import { SectionProvider } from "../lib";
6
5
  const CrudFormTemplate = (props) => {
7
6
  const sp = SectionProvider(props !== null && props !== void 0 ? props : {});
8
7
  const getRight = () => {
@@ -9,7 +9,7 @@ const DataListTemplate = (props) => {
9
9
  const getPreferredTitle = () => {
10
10
  return title !== null && title !== void 0 ? title : pageView.getUI().getTitle();
11
11
  };
12
- const attr = { title: getPreferredTitle(), cols, data, rowsPerPage, commonActions, rowActions, toolbarActions, bulkActions, filters };
12
+ const attr = { title: getPreferredTitle(), cols, data, rowsPerPage, commonActions, rowActions, toolbarActions, bulkActions, filters, searchable };
13
13
  const loadPanel = (section) => {
14
14
  return _jsx(Panel, { content: section });
15
15
  };
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
4
4
  import { useApp } from "../core/AppContext";
5
5
  import BorderLayout from "../layouts/BorderLayout";
6
6
  const WizardTemplate = (props) => {
7
+ console.log(props);
7
8
  const { component, attr = {}, stepHandler, children } = props !== null && props !== void 0 ? props : {};
8
9
  const [view, setView] = useState(null);
9
10
  const { getComponentCache } = useApp();
@@ -32,6 +33,7 @@ const WizardTemplate = (props) => {
32
33
  const handleBack = () => {
33
34
  stepHandler === null || stepHandler === void 0 ? void 0 : stepHandler.back();
34
35
  };
35
- return (_jsx("div", { children: _jsx(BorderLayout, { south: _jsxs("div", { className: "flex justify-between gap-2", children: [(stepHandler === null || stepHandler === void 0 ? void 0 : stepHandler.hasPrev()) && _jsx(Button, { onClick: handleBack, children: "Back" }), (stepHandler === null || stepHandler === void 0 ? void 0 : stepHandler.hasNext()) && (_jsx("div", { className: "flex gap-2", children: _jsx(Button, { onClick: handleNext, children: "Next" }) }))] }), children: render() }) }));
36
+ const south = (_jsxs("div", { className: "flex justify-between gap-2 p-4 font-proxima-600", children: [_jsx("div", { className: "flex gap-2", children: (stepHandler === null || stepHandler === void 0 ? void 0 : stepHandler.hasPrev()) && (_jsx(Button, { onClick: handleBack, className: "bg-transparent text-gray-500 border-none shadow-none hover:bg-gray-100", children: "Back" })) }), _jsx("div", { className: "flex gap-2", children: (stepHandler === null || stepHandler === void 0 ? void 0 : stepHandler.hasNext()) && (_jsx(Button, { onClick: handleNext, className: "bg-primary-500 text-white hover:bg-primary-600", children: "Next" })) })] }));
37
+ return _jsx(BorderLayout, { south: south, children: render() });
36
38
  };
37
39
  export default WizardTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramesesinc/platform-core",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Platform Core Library",
5
5
  "author": "Rameses Systems Inc.",
6
6
  "license": "MIT",
@@ -1,14 +0,0 @@
1
- import { UIInputProps } from "../common/UIInput";
2
- type SelectOption = {
3
- label: string;
4
- value: string;
5
- };
6
- type SelectFieldProps = UIInputProps & {
7
- required?: boolean;
8
- immediate?: boolean;
9
- options?: SelectOption[];
10
- placeholder?: string;
11
- onChange?: (value: string) => void;
12
- };
13
- declare const SelectField: (props: SelectFieldProps) => import("react/jsx-runtime").JSX.Element;
14
- export default SelectField;
@@ -1,40 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useRef, useState } from "react";
3
- import UIComponent from "../common/UIComponent";
4
- import useUIInput from "../common/UIInput";
5
- const SelectField = (props) => {
6
- const { immediate = true, options = [], placeholder } = props !== null && props !== void 0 ? props : {};
7
- const [focused, setFocused] = useState(false);
8
- const selectRef = useRef(null);
9
- const valueRef = useRef("");
10
- const className = "border rounded px-2 py-1 w-full";
11
- const handleFocus = () => {
12
- setFocused(true);
13
- };
14
- const handleBlur = () => {
15
- if (!immediate) {
16
- setValue(selectValue);
17
- }
18
- setFocused(false);
19
- };
20
- const onRefresh = () => {
21
- setSelectValue(getValue());
22
- };
23
- const { initialValue, getValue, setValue, binding } = useUIInput(Object.assign(Object.assign({}, props), { onRefresh }));
24
- valueRef.current = initialValue !== null && initialValue !== void 0 ? initialValue : "";
25
- const [selectValue, setSelectValue] = useState(valueRef.current);
26
- const onChange = (e) => {
27
- var _a, _b;
28
- const text = (_a = e.target.value) !== null && _a !== void 0 ? _a : "";
29
- if (text !== selectValue) {
30
- valueRef.current = text;
31
- setSelectValue(valueRef.current);
32
- }
33
- if (immediate) {
34
- setValue(text);
35
- }
36
- (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, text);
37
- };
38
- return (_jsx(UIComponent, Object.assign({}, (props !== null && props !== void 0 ? props : {}), { children: _jsxs("select", { ref: selectRef, onChange: onChange, value: selectValue, onFocus: handleFocus, onBlur: handleBlur, className: className, children: [placeholder && (_jsx("option", { value: "", disabled: true, children: placeholder })), options.map((opt) => (_jsx("option", { value: opt.value, children: opt.label }, opt.value)))] }) })));
39
- };
40
- export default SelectField;