@wavemaker-ai/react-runtime 1.0.0-rc.317 → 1.0.0-rc.319

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 (163) hide show
  1. package/components/advanced/carousel/index.d.ts +2 -0
  2. package/components/advanced/carousel/template.d.ts +2 -0
  3. package/components/advanced/login/index.d.ts +2 -0
  4. package/components/advanced/marquee/index.d.ts +2 -0
  5. package/components/auth/RoleAuthGuard.js +1 -0
  6. package/components/basic/anchor/index.d.ts +2 -0
  7. package/components/basic/anchor/index.js +1 -1
  8. package/components/basic/audio/index.d.ts +2 -0
  9. package/components/basic/html/index.d.ts +2 -0
  10. package/components/basic/icon/index.d.ts +2 -0
  11. package/components/basic/iframe/index.d.ts +2 -0
  12. package/components/basic/label/index.d.ts +2 -0
  13. package/components/basic/label/index.js +17 -3
  14. package/components/basic/picture/index.d.ts +2 -0
  15. package/components/basic/picture/index.js +20 -1
  16. package/components/basic/progress-bar/index.d.ts +2 -0
  17. package/components/basic/progress-circle/index.d.ts +2 -0
  18. package/components/basic/progress-circle/index.js +2 -1
  19. package/components/basic/richtexteditor/index.d.ts +4 -0
  20. package/components/basic/richtexteditor/index.js +16 -15
  21. package/components/basic/search/index.d.ts +4 -0
  22. package/components/basic/spinner/index.d.ts +2 -0
  23. package/components/basic/tile/index.d.ts +2 -0
  24. package/components/basic/tree/index.d.ts +2 -0
  25. package/components/basic/video/index.d.ts +2 -0
  26. package/components/chart/index.d.ts +2 -0
  27. package/components/common/index.d.ts +2 -0
  28. package/components/common/index.js +5 -1
  29. package/components/common/wm-skeleton.d.ts +95 -0
  30. package/components/common/wm-skeleton.js +346 -0
  31. package/components/container/accordion/accordion-pane/index.d.ts +2 -0
  32. package/components/container/accordion/index.d.ts +4 -0
  33. package/components/container/accordion/index.js +23 -1
  34. package/components/container/accordion/props.d.ts +10 -0
  35. package/components/container/index.d.ts +2 -0
  36. package/components/container/index.js +2 -4
  37. package/components/container/layout-grid/grid-column/index.d.ts +2 -0
  38. package/components/container/layout-grid/grid-row/index.d.ts +2 -0
  39. package/components/container/layout-grid/index.d.ts +2 -0
  40. package/components/container/linear-layout/index.d.ts +2 -0
  41. package/components/container/linear-layout/linear-layout-item/index.d.ts +2 -0
  42. package/components/container/panel/index.d.ts +2 -0
  43. package/components/container/repeat-template/index.d.ts +2 -0
  44. package/components/container/tabs/index.d.ts +4 -0
  45. package/components/container/tabs/index.js +23 -1
  46. package/components/container/tabs/props.d.ts +10 -0
  47. package/components/container/tabs/tab-pane/index.d.ts +2 -0
  48. package/components/container/wizard/index.d.ts +8 -0
  49. package/components/container/wizard/index.js +27 -3
  50. package/components/container/wizard/props.d.ts +10 -0
  51. package/components/container/wizard/wizard-step/index.d.ts +2 -0
  52. package/components/data/card/card-actions/index.d.ts +2 -0
  53. package/components/data/card/card-content/index.d.ts +2 -0
  54. package/components/data/card/card-footer/index.d.ts +2 -0
  55. package/components/data/card/index.d.ts +2 -0
  56. package/components/data/card/index.js +12 -6
  57. package/components/data/form/base-form/hooks/useFormOperations.d.ts +1 -1
  58. package/components/data/form/base-form/hooks/useFormOperations.js +3 -3
  59. package/components/data/form/base-form/index.js +30 -25
  60. package/components/data/form/base-form/props.d.ts +1 -1
  61. package/components/data/form/dynamic-fields/index.js +3 -0
  62. package/components/data/form/form-action/index.d.ts +4 -0
  63. package/components/data/form/form-controller/hooks/index.js +2 -1
  64. package/components/data/form/form-controller/withFormController.js +11 -16
  65. package/components/data/form/form-field/base-field.js +0 -5
  66. package/components/data/form/form-field/index.js +99 -13
  67. package/components/data/form/form-field/props.d.ts +8 -0
  68. package/components/data/form/index.js +13 -0
  69. package/components/data/list/index.d.ts +7 -0
  70. package/components/data/list/index.js +18 -0
  71. package/components/data/list/props.d.ts +7 -0
  72. package/components/data/table/components/RowCells.js +4 -1
  73. package/components/data/table/hooks/useDynamicColumns.js +3 -1
  74. package/components/data/table/hooks/useResponsiveColumns.d.ts +2 -0
  75. package/components/data/table/index.d.ts +8 -0
  76. package/components/data/table/index.js +15 -0
  77. package/components/data/table/live-table/index.d.ts +2 -0
  78. package/components/data/table/props.d.ts +10 -0
  79. package/components/data/table/table-action/index.d.ts +2 -0
  80. package/components/data/table/table-column/index.d.ts +2 -0
  81. package/components/data/table/table-row/index.d.ts +2 -0
  82. package/components/data/table/table-row-action/index.d.ts +2 -0
  83. package/components/data/table/utils/index.d.ts +2 -0
  84. package/components/data/table/utils/index.js +17 -3
  85. package/components/dialogs/alert-dialog/index.d.ts +4 -0
  86. package/components/dialogs/confirm-dialog/index.d.ts +4 -0
  87. package/components/dialogs/dialog/index.d.ts +4 -0
  88. package/components/dialogs/dialog-actions/index.d.ts +2 -0
  89. package/components/dialogs/dialog-body/index.d.ts +2 -0
  90. package/components/dialogs/dialog-content/index.d.ts +2 -0
  91. package/components/dialogs/dialog-header/index.d.ts +2 -0
  92. package/components/dialogs/iframe-dialog/index.d.ts +4 -0
  93. package/components/dialogs/login-dialog/index.d.ts +4 -0
  94. package/components/dialogs/page-dialog/index.d.ts +4 -0
  95. package/components/form/button/index.d.ts +2 -0
  96. package/components/form/button/index.js +10 -1
  97. package/components/form/button-group/index.d.ts +2 -0
  98. package/components/input/calendar/index.d.ts +4 -0
  99. package/components/input/calendar/index.js +2 -1
  100. package/components/input/chips/index.d.ts +4 -0
  101. package/components/input/color-picker/index.d.ts +4 -0
  102. package/components/input/color-picker/index.js +18 -7
  103. package/components/input/composite/index.d.ts +2 -0
  104. package/components/input/currency/index.d.ts +4 -0
  105. package/components/input/default/checkbox/index.d.ts +4 -0
  106. package/components/input/default/checkboxset/index.d.ts +4 -0
  107. package/components/input/default/checkboxset/index.js +7 -5
  108. package/components/input/default/radioset/index.d.ts +4 -0
  109. package/components/input/default/radioset/index.js +2 -1
  110. package/components/input/default/switch/index.d.ts +4 -0
  111. package/components/input/default/switch/index.js +17 -13
  112. package/components/input/epoch/date/index.d.ts +2 -0
  113. package/components/input/epoch/date/index.js +30 -14
  114. package/components/input/epoch/datetime/index.d.ts +2 -0
  115. package/components/input/epoch/datetime/index.js +12 -8
  116. package/components/input/epoch/time/index.d.ts +2 -0
  117. package/components/input/epoch/time/index.js +21 -15
  118. package/components/input/fileupload/index.d.ts +2 -0
  119. package/components/input/number/index.d.ts +4 -0
  120. package/components/input/number/index.js +4 -3
  121. package/components/input/rating/index.d.ts +4 -0
  122. package/components/input/select/index.d.ts +4 -0
  123. package/components/input/slider/index.d.ts +4 -0
  124. package/components/input/slider/index.js +4 -2
  125. package/components/input/text/index.d.ts +4 -0
  126. package/components/input/text/index.js +16 -8
  127. package/components/input/textarea/index.d.ts +4 -0
  128. package/components/input/upload/index.d.ts +4 -0
  129. package/components/input/upload/index.js +6 -4
  130. package/components/navbar/index.d.ts +2 -0
  131. package/components/navbar/nav/index.d.ts +2 -0
  132. package/components/navbar/nav-item/index.d.ts +2 -0
  133. package/components/navigation/breadcrumb/index.d.ts +2 -0
  134. package/components/navigation/menu/index.d.ts +2 -0
  135. package/components/navigation/menu/index.js +2 -2
  136. package/components/navigation/popover/index.d.ts +2 -0
  137. package/components/page/partial/index.d.ts +2 -0
  138. package/context/AppContext.d.ts +2 -0
  139. package/context/AppContext.js +20 -1
  140. package/context/WidgetProvider.js +0 -3
  141. package/core/proxy-service.d.ts +2 -0
  142. package/core/proxy-service.js +25 -0
  143. package/higherOrder/BaseApp.js +1 -3
  144. package/higherOrder/BaseAppProps.d.ts +1 -1
  145. package/higherOrder/BasePage.js +4 -2
  146. package/higherOrder/props.d.ts +10 -0
  147. package/higherOrder/withBaseWrapper.js +3 -0
  148. package/hooks/useAuth.js +3 -0
  149. package/hooks/useLayoutSize.d.ts +6 -0
  150. package/hooks/useLayoutSize.js +12 -0
  151. package/package-lock.json +225 -199
  152. package/package.json +3 -3
  153. package/runtime-dynamic/components/use-dynamic-component.js +6 -11
  154. package/runtime-dynamic/main.js +1 -3
  155. package/runtime-dynamic/services/component-ref-provider.d.ts +1 -1
  156. package/runtime-dynamic/services/component-ref-provider.js +14 -11
  157. package/runtime-dynamic/services/resource-manager.js +10 -4
  158. package/runtime-dynamic/services/script-executor.js +4 -1
  159. package/runtime-dynamic/services/variable-registry.js +3 -0
  160. package/utils/attr.js +0 -1
  161. package/utils/format-util.js +2 -3
  162. package/utils/form-state.util.d.ts +0 -62
  163. package/utils/form-state.util.js +0 -109
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavemaker-ai/react-runtime",
3
- "version": "1.0.0-rc.317",
3
+ "version": "1.0.0-rc.319",
4
4
  "description": "React runtime package for Wavemaker",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -57,7 +57,8 @@
57
57
  "@mui/x-date-pickers": "8.5.3",
58
58
  "@reduxjs/toolkit": "2.9.1",
59
59
  "@tanstack/react-table": "8.21.3",
60
- "@wavemaker-ai/react-codegen": "1.0.0-rc.317",
60
+ "@wavemaker-ai/react-codegen": "1.0.0-rc.319",
61
+ "@wavemaker-ai/variables": "1.0.0-rc.319",
61
62
  "@wavemaker/nvd3": "1.8.16",
62
63
  "axios": "1.15.1",
63
64
  "d3": "7.8.5",
@@ -96,7 +97,6 @@
96
97
  "@types/react-dom": "19.2.3",
97
98
  "@vitejs/plugin-react": "5.1.4",
98
99
  "@vitest/coverage-v8": "3.2.4",
99
- "@wavemaker-ai/variables": "1.0.0-rc.317",
100
100
  "axe-core": "4.11.1",
101
101
  "esbuild": "0.27.5",
102
102
  "eslint": "9",
@@ -3,7 +3,6 @@ import { getComponentRef, getPrefabConfig } from "../services/component-ref-prov
3
3
  import { ComponentType } from "../services/fragment-url";
4
4
  import { buildBasePageLikeComponent } from "../factories/build-base-page-like-component";
5
5
  import { buildPrefabComponent } from "../factories/prefab-factory";
6
- import { useAppContext } from "../../context/AppContext";
7
6
  const builders = {
8
7
  [ComponentType.PAGE]: (name, fragment) => buildBasePageLikeComponent("page", name, fragment),
9
8
  [ComponentType.PARTIAL]: (name, fragment) => buildBasePageLikeComponent("partial", name, fragment),
@@ -16,10 +15,8 @@ function useDynamicComponent(componentName, componentType, options) {
16
15
  error: null
17
16
  });
18
17
  const activeRequestRef = useRef(0);
19
- const appContext = useAppContext();
20
18
  const load = useCallback(
21
19
  async (name) => {
22
- var _a, _b;
23
20
  const requestId = ++activeRequestRef.current;
24
21
  setState({ Component: null, isLoading: true, error: null });
25
22
  try {
@@ -29,17 +26,15 @@ function useDynamicComponent(componentName, componentType, options) {
29
26
  prefabOutboundDefaults = await getPrefabConfig(name) || {};
30
27
  }
31
28
  const fragment = await getComponentRef(name, componentType, fetchOptions);
29
+ if (!fragment) {
30
+ if (requestId === activeRequestRef.current) {
31
+ setState({ Component: null, isLoading: false, error: null });
32
+ }
33
+ return;
34
+ }
32
35
  const builder = builders[componentType];
33
36
  if (!builder) throw new Error(`No builder registered for component type: ${componentType}`);
34
37
  const Component = await builder(name, fragment, prefabOutboundDefaults);
35
- if ((fragment == null ? void 0 : fragment.error) && (fragment == null ? void 0 : fragment.error) == "Access Denied") {
36
- setState({ Component, isLoading: false, error: null });
37
- appContext == null ? void 0 : appContext.notifyApp(
38
- ((_b = (_a = appContext == null ? void 0 : appContext.appLocale) == null ? void 0 : _a.LABELS) == null ? void 0 : _b.ACCESS_DENIED) || (fragment == null ? void 0 : fragment.error),
39
- "Error"
40
- );
41
- return;
42
- }
43
38
  if (requestId === activeRequestRef.current) {
44
39
  setState({ Component, isLoading: false, error: null });
45
40
  }
@@ -1,5 +1,4 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import React from "react";
3
2
  import { createRoot } from "react-dom/client";
4
3
  import wmGlobalsCss from "@wavemaker-ai/react-codegen/styles/wm-styles.css";
5
4
  import { App, initPreviewRuntimeRouter } from "./App";
@@ -30,8 +29,7 @@ async function bootstrap() {
30
29
  throw new Error("Root element #app-root not found");
31
30
  }
32
31
  const root = createRoot(container);
33
- const tree = process.env.NODE_ENV === "development" ? /* @__PURE__ */ jsx(React.StrictMode, { children: /* @__PURE__ */ jsx(App, {}) }) : /* @__PURE__ */ jsx(App, {});
34
- root.render(tree);
32
+ root.render(/* @__PURE__ */ jsx(App, {}));
35
33
  console.timeEnd("bootstrap");
36
34
  window.addEventListener("unload", () => {
37
35
  root.unmount();
@@ -18,7 +18,7 @@ export interface DecodedFragment {
18
18
  export interface GetComponentOptions {
19
19
  prefabName?: string;
20
20
  }
21
- export declare function getComponentRef(componentName: string, componentType: ComponentType, options?: GetComponentOptions): Promise<DecodedFragment>;
21
+ export declare function getComponentRef(componentName: string, componentType: ComponentType, options?: GetComponentOptions): Promise<DecodedFragment | undefined>;
22
22
  export declare function getPrefabConfig(prefabName: string): Promise<Record<string, unknown>>;
23
23
  /**
24
24
  * Resets injected prefab assets and transpile/variable caches so the next
@@ -6,17 +6,8 @@ import { decodeURIComponentSafe, parseJsonSafe } from "../utils";
6
6
  import { clearPrefabResourcesLoaded, loadPrefabResourcesFromConfig } from "./prefab-resources";
7
7
  import { clearTranspileCache } from "./markup-transpiler";
8
8
  import { clearVariablesCache } from "./variable-transpiler";
9
+ import { appManager } from "@wavemaker-ai/variables";
9
10
  function decodeFragment(raw) {
10
- if (!raw) {
11
- return {
12
- markup: "",
13
- script: "",
14
- styles: "",
15
- variables: parseJsonSafe("{}"),
16
- config: void 0,
17
- error: "Access Denied"
18
- };
19
- }
20
11
  return {
21
12
  markup: decodeURIComponentSafe(raw.markup || ""),
22
13
  script: decodeURIComponentSafe(raw.script || ""),
@@ -26,8 +17,20 @@ function decodeFragment(raw) {
26
17
  };
27
18
  }
28
19
  async function loadFragment(componentName, componentType, prefabName) {
20
+ var _a, _b, _c;
29
21
  const url = getFragmentUrl(componentName, componentType, prefabName);
30
- return fetchResource(url).then(decodeFragment);
22
+ try {
23
+ const raw = await fetchResource(url);
24
+ return decodeFragment(raw);
25
+ } catch (err) {
26
+ if (((_a = err.response) == null ? void 0 : _a.status) === 401) {
27
+ return void 0;
28
+ }
29
+ const errorMsg = isString(err) ? err : "";
30
+ console.error(`Failed to load ${componentType} component '${componentName}':`, err);
31
+ (_c = (_b = appManager) == null ? void 0 : _b.notifyApp) == null ? void 0 : _c.call(_b, errorMsg, "error");
32
+ return void 0;
33
+ }
31
34
  }
32
35
  async function getComponentRef(componentName, componentType, options) {
33
36
  return loadFragment(componentName, componentType, options == null ? void 0 : options.prefabName);
@@ -1,8 +1,9 @@
1
1
  import axios from "axios";
2
2
  import { resolvePreviewFetchUrl } from "../preview-resource-base";
3
3
  import { handle401 } from "../../core/app.service";
4
+ import { store } from "../../store";
4
5
  async function fetchResource(url, optional = false) {
5
- var _a;
6
+ var _a, _b;
6
7
  const resolvedUrl = resolvePreviewFetchUrl(url);
7
8
  try {
8
9
  const response = await axios.get(resolvedUrl);
@@ -14,10 +15,15 @@ async function fetchResource(url, optional = false) {
14
15
  const status = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status;
15
16
  if (status === 401) {
16
17
  handle401();
17
- } else if (status === 403) {
18
- return null;
18
+ throw error;
19
19
  }
20
- throw error;
20
+ const appLocale = (_b = store.getState().i18n) == null ? void 0 : _b.appLocale;
21
+ const errorMessages = {
22
+ 404: (appLocale == null ? void 0 : appLocale.MESSAGE_PAGE_NOT_FOUND) || "Page not available",
23
+ 403: (appLocale == null ? void 0 : appLocale.LABEL_ACCESS_DENIED) || "Access Denied"
24
+ };
25
+ const errorMessage = errorMessages[status] || "An error occurred";
26
+ throw errorMessage || "Unknown error loading component";
21
27
  }
22
28
  }
23
29
  export {
@@ -45,7 +45,10 @@ function buildAddPageScript(script, scopeKind, componentName) {
45
45
  try {
46
46
  const cleanScript = prepareScript(script);
47
47
  const allNames = [...Object.keys(SCRIPT_GLOBALS), ...DEFERRED_GLOBALS];
48
- const compiledFn = new Function("App", scopeKind, ...allNames, cleanScript);
48
+ const wrappedScript = `{
49
+ ${cleanScript}
50
+ }`;
51
+ const compiledFn = new Function("App", scopeKind, ...allNames, wrappedScript);
49
52
  const staticValues = Object.keys(SCRIPT_GLOBALS).map((k) => SCRIPT_GLOBALS[k]);
50
53
  return (app, page) => {
51
54
  try {
@@ -55,6 +55,9 @@ function createLazyPartial(partialName) {
55
55
  const { getComponentRef } = await import("./component-ref-provider");
56
56
  const { buildBasePageLikeComponent } = await import("../factories/build-base-page-like-component");
57
57
  const fragment = await getComponentRef(partialName, FType.PARTIAL);
58
+ if (!fragment) {
59
+ return { default: () => null };
60
+ }
58
61
  const Built = await buildBasePageLikeComponent("partial", partialName, fragment);
59
62
  return { default: Built };
60
63
  });
package/utils/attr.js CHANGED
@@ -13,7 +13,6 @@ const INTERNAL_ATTRIBUTES = /* @__PURE__ */ new Set([
13
13
  "ref",
14
14
  "showindevice",
15
15
  "styles",
16
- "viewParent",
17
16
  "onLeftPanelAnimationChange"
18
17
  ]);
19
18
  const SAFE_ATTRIBUTES = /* @__PURE__ */ new Set([
@@ -194,11 +194,10 @@ const formatOnBlur = (datavalue, rawInputValue, trailingzero, decimalplaces) =>
194
194
  };
195
195
  const handleValidatedValueUpdate = (value, name, inputElCurrent, onChangeProp, listenerProp, prevDatavalueState, setPrevDatavalueState, widgetProps) => {
196
196
  const stringifiedValue = value === null ? "" : value.toString();
197
- const widgetInfo = name && (listenerProp == null ? void 0 : listenerProp.Widgets) ? listenerProp.Widgets[name] : void 0;
198
197
  if (listenerProp == null ? void 0 : listenerProp.onChange) {
199
- listenerProp.onChange(name, __spreadProps(__spreadValues({}, widgetInfo || widgetProps), {
198
+ listenerProp.onChange(name, {
200
199
  datavalue: stringifiedValue
201
- }));
200
+ });
202
201
  }
203
202
  setPrevDatavalueState(value);
204
203
  const updatedProps = __spreadProps(__spreadValues({}, widgetProps), {
@@ -1,62 +0,0 @@
1
- /**
2
- * Form State Utility
3
- *
4
- * Handles form field registration and management within the widget context.
5
- * This utility provides centralized logic for registering form fields and form widgets
6
- * to their parent form context.
7
- */
8
- /**
9
- * Interface for widget properties related to form field registration
10
- */
11
- interface FormFieldWidget {
12
- name?: string;
13
- formName?: string;
14
- field?: string;
15
- fieldName?: string;
16
- formKey?: string;
17
- parentForm?: string;
18
- [key: string]: any;
19
- }
20
- /**
21
- * Interface for the context structure where form fields are registered
22
- */
23
- interface WidgetsContext {
24
- [formName: string]: {
25
- formfields: Record<string, any>;
26
- formWidgets: Record<string, any>;
27
- [key: string]: any;
28
- };
29
- }
30
- /**
31
- * Checks if a widget should be registered as a form field
32
- * @param widget - The widget object to check
33
- * @returns true if the widget should be registered as a form field
34
- */
35
- export declare const shouldRegisterFormField: (widget: FormFieldWidget) => boolean;
36
- /**
37
- * Registers a form field widget with its parent form in the context
38
- * This creates references in both formfields and formWidgets collections
39
- *
40
- * @param widgetsContext - The Widgets context object where forms are stored
41
- * @param widget - The widget/proxy to register
42
- * @param widgetProps - The widget properties containing form metadata
43
- */
44
- export declare const registerFormField: (widgetsContext: WidgetsContext, widget: any, widgetProps: FormFieldWidget, newContext: any) => void;
45
- /**
46
- * Ensures the form structure exists in the widgets context and registers a form field
47
- * with safe object spreading to merge properties
48
- *
49
- * @param widgetsContext - The Widgets context object where forms are stored
50
- * @param fieldProps - The field properties to register
51
- */
52
- export declare const registerFormFieldSafe: (widgetsContext: WidgetsContext, fieldProps: FormFieldWidget) => void;
53
- /**
54
- * Unregisters a form field from its parent form
55
- *
56
- * @param widgetsContext - The Widgets context object where forms are stored
57
- * @param formName - The name of the parent form
58
- * @param fieldName - The name of the field to unregister
59
- * @param formKey - Optional form key (defaults to fieldName if not provided)
60
- */
61
- export declare const unregisterFormField: (widgetsContext: WidgetsContext, formName: string, fieldName: string, formKey?: string) => void;
62
- export {};
@@ -1,109 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import get from "lodash-es/get";
18
- const isFormField = (widgetName) => {
19
- return !(widgetName == null ? void 0 : widgetName.includes("formWidget"));
20
- };
21
- const shouldRegisterFormField = (widget) => {
22
- const isField = get(widget, "field", "false") === "true";
23
- const hasFormName = Boolean(widget.formName);
24
- const isNotFormWidget = isFormField(widget.name);
25
- return isField && hasFormName && isNotFormWidget;
26
- };
27
- const hasParentForm = (formName) => {
28
- return Boolean();
29
- };
30
- const registerFormField = (widgetsContext, widget, widgetProps, newContext) => {
31
- var _a;
32
- const formName = widgetProps == null ? void 0 : widgetProps.formName;
33
- if (!formName || !shouldRegisterFormField(widgetProps)) {
34
- return;
35
- }
36
- const formKey = widgetProps.formKey || widgetProps.fieldName;
37
- const fieldName = widgetProps.fieldName;
38
- if (!formKey || !fieldName) {
39
- return;
40
- }
41
- if (!widgetsContext[formName]) {
42
- return;
43
- }
44
- widgetsContext[formName].formfields = widgetsContext[formName].formfields || {};
45
- widgetsContext[formName].formWidgets = widgetsContext[formName].formWidgets || {};
46
- widgetsContext[formName].formfields[formKey] = widget;
47
- widgetsContext[formName].formWidgets[fieldName] = widget;
48
- widgetsContext[formName].formfields[`${fieldName}_formWidget`] = widget;
49
- widgetsContext[formName].formWidgets[`${fieldName}_formWidget`] = widget;
50
- const parentFormName = (_a = widgetsContext[formName]) == null ? void 0 : _a.parentForm;
51
- if (parentFormName && widgetsContext[parentFormName]) {
52
- widgetsContext[parentFormName].formfields = widgetsContext[parentFormName].formfields || {};
53
- widgetsContext[parentFormName].formWidgets = widgetsContext[parentFormName].formWidgets || {};
54
- widgetsContext[parentFormName].formfields[formKey] = widget;
55
- widgetsContext[parentFormName].formWidgets[fieldName] = widget;
56
- widgetsContext[parentFormName].formfields[`${formKey}_formWidget`] = widget;
57
- widgetsContext[parentFormName].formWidgets[`${fieldName}_formWidget`] = widget;
58
- }
59
- };
60
- const registerFormFieldSafe = (widgetsContext, fieldProps) => {
61
- var _a;
62
- const formName = fieldProps == null ? void 0 : fieldProps.formName;
63
- if (!formName || !shouldRegisterFormField(fieldProps)) {
64
- return;
65
- }
66
- const formKey = fieldProps.formKey || fieldProps.fieldName;
67
- const fieldName = fieldProps.fieldName;
68
- if (!formKey || !fieldName) {
69
- return;
70
- }
71
- function register(formName2, formKey2, fieldName2, fieldProps2) {
72
- var _a2, _b, _c, _d, _e;
73
- (_a2 = widgetsContext[formName2]) != null ? _a2 : widgetsContext[formName2] = {
74
- formfields: {},
75
- formWidgets: {}
76
- };
77
- (_c = (_b = widgetsContext[formName2]).formfields) != null ? _c : _b.formfields = {};
78
- (_e = (_d = widgetsContext[formName2]).formWidgets) != null ? _e : _d.formWidgets = {};
79
- widgetsContext[formName2].formfields[formKey2] = __spreadValues({}, fieldProps2);
80
- widgetsContext[formName2].formWidgets[fieldName2] = __spreadValues({}, fieldProps2);
81
- widgetsContext[formName2].formfields[`${fieldName2}_formWidget`] = __spreadValues({}, fieldProps2);
82
- widgetsContext[formName2].formWidgets[`${fieldName2}_formWidget`] = __spreadValues({}, fieldProps2);
83
- }
84
- register(formName, formKey, fieldName, fieldProps);
85
- const parentForm = (_a = widgetsContext[formName]) == null ? void 0 : _a.parentForm;
86
- if (parentForm) {
87
- register(parentForm, formKey, fieldName, fieldProps);
88
- }
89
- };
90
- const unregisterFormField = (widgetsContext, formName, fieldName, formKey) => {
91
- if (!widgetsContext[formName]) {
92
- return;
93
- }
94
- const keyToRemove = formKey || fieldName;
95
- if (widgetsContext[formName].formfields) {
96
- delete widgetsContext[formName].formfields[keyToRemove];
97
- delete widgetsContext[formName].formfields[`${fieldName}_formWidget`];
98
- }
99
- if (widgetsContext[formName].formWidgets) {
100
- delete widgetsContext[formName].formWidgets[fieldName];
101
- delete widgetsContext[formName].formWidgets[`${fieldName}_formWidget`];
102
- }
103
- };
104
- export {
105
- registerFormField,
106
- registerFormFieldSafe,
107
- shouldRegisterFormField,
108
- unregisterFormField
109
- };