@openg2p/registry-widgets 0.1.1 → 0.1.2

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 (44) hide show
  1. package/dist/components/PanelRenderer.d.ts +3 -3
  2. package/dist/components/PanelRenderer.d.ts.map +1 -1
  3. package/dist/components/SectionBuilder/JSONEditorPanel.d.ts +2 -0
  4. package/dist/components/SectionBuilder/JSONEditorPanel.d.ts.map +1 -1
  5. package/dist/components/SectionBuilder/PropertyEditor.d.ts.map +1 -1
  6. package/dist/components/SectionBuilder/SectionBuilder.d.ts.map +1 -1
  7. package/dist/components/SectionBuilder/VisualBuilderPanel.d.ts +3 -0
  8. package/dist/components/SectionBuilder/VisualBuilderPanel.d.ts.map +1 -1
  9. package/dist/components/SectionRenderer.d.ts +2 -2
  10. package/dist/components/SectionRenderer.d.ts.map +1 -1
  11. package/dist/components/SectionsContainer.d.ts +3 -3
  12. package/dist/components/SectionsContainer.d.ts.map +1 -1
  13. package/dist/components/WidgetProvider.d.ts +4 -4
  14. package/dist/components/WidgetProvider.d.ts.map +1 -1
  15. package/dist/components/WidgetRenderer.d.ts +1 -1
  16. package/dist/components/WidgetRenderer.d.ts.map +1 -1
  17. package/dist/events/WidgetEventBus.d.ts +43 -0
  18. package/dist/events/WidgetEventBus.d.ts.map +1 -0
  19. package/dist/events/types.d.ts +27 -0
  20. package/dist/events/types.d.ts.map +1 -0
  21. package/dist/hooks/useBaseWidget.d.ts +2 -2
  22. package/dist/hooks/useBaseWidget.d.ts.map +1 -1
  23. package/dist/hooks/useGeoWidgetCascade.d.ts +12 -0
  24. package/dist/hooks/useGeoWidgetCascade.d.ts.map +1 -0
  25. package/dist/hooks/useWidgetCascade.d.ts +12 -0
  26. package/dist/hooks/useWidgetCascade.d.ts.map +1 -0
  27. package/dist/hooks/useWidgetEventBus.d.ts +9 -0
  28. package/dist/hooks/useWidgetEventBus.d.ts.map +1 -0
  29. package/dist/index.d.ts +249 -17
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.esm.js +2601 -168
  32. package/dist/index.esm.js.map +1 -1
  33. package/dist/index.js +2609 -166
  34. package/dist/index.js.map +1 -1
  35. package/dist/store/widgetSlice.d.ts.map +1 -1
  36. package/dist/types/index.d.ts +38 -3
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/utils/dataSource.d.ts +3 -2
  39. package/dist/utils/dataSource.d.ts.map +1 -1
  40. package/dist/utils/geoHierarchy.d.ts +53 -0
  41. package/dist/utils/geoHierarchy.d.ts.map +1 -0
  42. package/dist/widgets/RadioWidget.d.ts.map +1 -1
  43. package/dist/widgets/TableWidget.d.ts.map +1 -1
  44. package/package.json +17 -9
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var React = require('react');
5
5
  var reactRedux = require('react-redux');
6
6
  var zod = require('zod');
7
7
  var reactDom = require('react-dom');
8
+ var jsonEditReact = require('json-edit-react');
8
9
  var i18n = require('i18next');
9
10
  var reactI18next = require('react-i18next');
10
11
 
@@ -15,19 +16,58 @@ const initialState = {
15
16
  loading: {},
16
17
  dataSources: {},
17
18
  };
19
+ // Track recent setValue calls to detect race conditions
20
+ const recentSetValueCalls = new Map();
18
21
  const widgetSlice = toolkit.createSlice({
19
22
  name: 'widget',
20
23
  initialState,
21
24
  reducers: {
22
25
  setValue: (state, action) => {
23
- state.values[action.payload.widgetId] = action.payload.value;
26
+ const { widgetId, value } = action.payload;
27
+ const previousValue = state.values[widgetId];
28
+ const now = Date.now();
29
+ // Check if we recently set a different value (race condition detection)
30
+ const recentCall = recentSetValueCalls.get(widgetId);
31
+ const isRaceCondition = recentCall &&
32
+ recentCall.timestamp > now - 100 && // Within 100ms
33
+ recentCall.value !== value &&
34
+ recentCall.value === previousValue; // Trying to set back to old value
35
+ // Track this call
36
+ recentSetValueCalls.set(widgetId, { value, timestamp: now });
37
+ // Clean up old entries (older than 1 second)
38
+ for (const [key, call] of recentSetValueCalls.entries()) {
39
+ if (now - call.timestamp > 1000) {
40
+ recentSetValueCalls.delete(key);
41
+ }
42
+ }
43
+ // CRITICAL: Prevent race condition - if we just set a new value, don't allow setting the old value back
44
+ if (isRaceCondition) {
45
+ return; // Don't update the value
46
+ }
47
+ state.values[widgetId] = value;
24
48
  // Clear errors when value changes
25
- if (state.errors[action.payload.widgetId]) {
26
- delete state.errors[action.payload.widgetId];
49
+ if (state.errors[widgetId]) {
50
+ delete state.errors[widgetId];
27
51
  }
28
52
  },
29
53
  setValues: (state, action) => {
30
- state.values = { ...state.values, ...action.payload };
54
+ // setWidgetValue returns the complete updated state object with all keys preserved
55
+ // We need to do a deep merge to preserve nested structures that aren't in the payload
56
+ // But since setWidgetValue already includes all existing data, we can merge at top level
57
+ // However, we need to be careful: if payload has nested objects, we need to deep merge them
58
+ const merged = { ...state.values };
59
+ for (const [key, value] of Object.entries(action.payload)) {
60
+ if (value !== null && typeof value === 'object' && !Array.isArray(value) &&
61
+ merged[key] !== null && typeof merged[key] === 'object' && !Array.isArray(merged[key])) {
62
+ // Deep merge nested objects to preserve properties not in the payload
63
+ merged[key] = { ...merged[key], ...value };
64
+ }
65
+ else {
66
+ // Replace primitives, arrays, or null values, or if target is not an object
67
+ merged[key] = value;
68
+ }
69
+ }
70
+ state.values = merged;
31
71
  },
32
72
  setError: (state, action) => {
33
73
  if (action.payload.errors.length > 0) {
@@ -276,7 +316,7 @@ const validateWidget = (value, validation, required = false) => {
276
316
  }
277
317
  catch (error) {
278
318
  if (error instanceof zod.z.ZodError) {
279
- errors.push(...error.errors.map((e) => e.message));
319
+ errors.push(...error.issues.map((e) => e.message));
280
320
  }
281
321
  else {
282
322
  errors.push('Validation failed');
@@ -735,31 +775,97 @@ const getStaticDataSource = (dataSource) => {
735
775
  };
736
776
  /**
737
777
  * Get API data source options
778
+ * Uses dataSourceRequestHandler to make API calls through host application
738
779
  */
739
- const getApiDataSource = async (dataSource, allValues, apiAdapter) => {
740
- if (!apiAdapter) {
741
- console.warn('API adapter not provided for API data source');
780
+ const getApiDataSource = async (dataSource, allValues, dataSourceRequestHandler, levelId // Optional level_id from widget-geo-config.level
781
+ ) => {
782
+ if (!dataSourceRequestHandler) {
783
+ console.error('[getApiDataSource] dataSourceRequestHandler is required for API data sources');
742
784
  return [];
743
785
  }
744
786
  try {
745
787
  // Get dependency value if exists
746
- const params = {};
788
+ // dependsOn can be either a data path (e.g., "person.address") or a widget-id
789
+ let depValue = null;
747
790
  if (dataSource.dependsOn) {
748
- const depValue = getValueByPath(allValues, dataSource.dependsOn);
749
- if (depValue !== null && depValue !== undefined && depValue !== '') {
750
- params[dataSource.dependsOn.split('.').pop() || 'filter'] = depValue;
791
+ // First try as data path
792
+ depValue = getValueByPath(allValues, dataSource.dependsOn);
793
+ // If not found and doesn't contain dots, try as widget-id
794
+ if ((depValue === null || depValue === undefined) && !dataSource.dependsOn.includes('.')) {
795
+ depValue = allValues[dataSource.dependsOn];
751
796
  }
752
- else {
797
+ if (depValue === null || depValue === undefined || depValue === '') {
753
798
  // If dependency is empty, return empty array
754
799
  return [];
755
800
  }
756
801
  }
757
- const response = await apiAdapter(dataSource.url, {
758
- method: dataSource.method || 'GET',
759
- headers: dataSource.headers,
760
- body: dataSource.body,
761
- params,
762
- });
802
+ // Build request parameters
803
+ const method = dataSource.method || 'GET';
804
+ // Extract static params from dataSource
805
+ // Include explicit params object and any additional fields (like level_id)
806
+ const staticParams = { ...dataSource.params };
807
+ // Extract additional fields that aren't part of the standard ApiDataSource interface
808
+ // These are fields like level_id that might be directly on the dataSource
809
+ // BUT: level_id should come from widget-geo-config.level, not from dataSource
810
+ const standardFields = ['type', 'service', 'endpoint', 'url', 'method', 'dependsOn', 'valueKey', 'labelKey', 'headers', 'body', 'params', 'level_id'];
811
+ for (const [key, value] of Object.entries(dataSource)) {
812
+ if (!standardFields.includes(key) && value !== undefined && value !== null) {
813
+ staticParams[key] = value;
814
+ }
815
+ }
816
+ // If levelId is provided (from widget-geo-config.level), use it instead of any level_id in dataSource
817
+ if (levelId) {
818
+ staticParams.level_id = levelId;
819
+ }
820
+ // Build request params object
821
+ const requestParams = { ...staticParams };
822
+ // Add dependency value to params
823
+ if (dataSource.dependsOn && depValue !== null && depValue !== undefined) {
824
+ // Extract the actual value ID if depValue is an object
825
+ const parentValueId = typeof depValue === 'object' && depValue !== null
826
+ ? (depValue.level_value_id || depValue.id || depValue.value || depValue)
827
+ : depValue;
828
+ // For geo APIs, use parent_level_value_id
829
+ if (staticParams.level_id) {
830
+ requestParams.parent_level_value_id = parentValueId;
831
+ }
832
+ else {
833
+ // For other APIs, use the dependency field name as param key
834
+ const paramKey = dataSource.dependsOn.split('.').pop() || 'filter';
835
+ requestParams[paramKey] = parentValueId;
836
+ }
837
+ }
838
+ else if (staticParams.level_id) {
839
+ // First level has no parent
840
+ requestParams.parent_level_value_id = null;
841
+ }
842
+ // Get service mnemonic and endpoint (required)
843
+ const service = dataSource.service;
844
+ const endpoint = dataSource.endpoint;
845
+ if (!service) {
846
+ console.error('[getApiDataSource] API data source missing service mnemonic. Use "service" field instead of "url"');
847
+ return [];
848
+ }
849
+ if (!endpoint) {
850
+ console.error('[getApiDataSource] API data source missing endpoint. Use "endpoint" field to specify the operation (e.g., "get_g2p_geo_level_values")');
851
+ return [];
852
+ }
853
+ let response;
854
+ try {
855
+ response = await dataSourceRequestHandler(service, endpoint, method, requestParams, {
856
+ headers: dataSource.headers,
857
+ });
858
+ }
859
+ catch (error) {
860
+ console.error('[getApiDataSource] Handler error:', error);
861
+ throw error;
862
+ }
863
+ // Handle OpenG2P response format (response_body.response_payload)
864
+ if (response && typeof response === 'object') {
865
+ if (response.response_body?.response_payload && Array.isArray(response.response_body.response_payload)) {
866
+ return response.response_body.response_payload;
867
+ }
868
+ }
763
869
  // Handle array response
764
870
  if (Array.isArray(response)) {
765
871
  return response;
@@ -806,49 +912,134 @@ const transformDataSourceOptions = (data, valueKey, labelKey) => {
806
912
  }));
807
913
  };
808
914
 
915
+ const WidgetEventBusContext = React.createContext(null);
916
+ /**
917
+ * Hook to access the widget event bus from context
918
+ */
919
+ const useWidgetEventBus = () => {
920
+ return React.useContext(WidgetEventBusContext);
921
+ };
922
+
809
923
  // Define stable empty arrays to avoid selector reference issues
810
924
  const EMPTY_ERRORS = [];
811
- const EMPTY_DATA_SOURCE = [];
925
+ const EMPTY_DATA_SOURCE$1 = [];
812
926
  const useBaseWidget = (options) => {
813
- const { config, apiAdapter, schemaData, onValueChange } = options;
927
+ const { config, dataSourceRequestHandler, schemaData, onValueChange } = options;
814
928
  const dispatch = reactRedux.useDispatch();
929
+ const eventBus = useWidgetEventBus();
815
930
  const widgetId = config['widget-id'];
816
931
  // Get state from Redux
817
932
  const values = reactRedux.useSelector((state) => state.widget.values);
818
933
  const errors = reactRedux.useSelector((state) => state.widget.errors[widgetId] ?? EMPTY_ERRORS);
819
934
  const touched = reactRedux.useSelector((state) => state.widget.touched[widgetId] || false);
820
935
  const loading = reactRedux.useSelector((state) => state.widget.loading[widgetId] || false);
821
- const dataSourceOptions = reactRedux.useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE);
936
+ const dataSourceOptions = reactRedux.useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE$1);
822
937
  // Skip value handling for layout widgets (they don't store data values)
823
938
  // Infer layout from widget-type
824
939
  const isLayoutWidget = config['widget-type'] === 'layout';
940
+ // Track if user has explicitly set a value to prevent default from overwriting
941
+ const userHasSetValueRef = React.useRef(false);
942
+ // Use ref for values to avoid stale closures in handleChange
943
+ const valuesRef = React.useRef(values);
944
+ React.useEffect(() => {
945
+ valuesRef.current = values;
946
+ }, [values]);
947
+ // Track last dispatched value to prevent duplicate dispatches
948
+ const lastDispatchedValueRef = React.useRef(null);
825
949
  // Get current value
826
950
  const currentValue = React.useMemo(() => {
827
951
  if (isLayoutWidget) {
828
952
  return undefined; // Layout widgets don't have values
829
953
  }
830
- const value = getWidgetValue(values, config['widget-data-path'], widgetId);
954
+ // Try to get value from widgetId first (this should have the actual selected value)
955
+ // For geo widgets with dataPath, widgetId stores the actual ID, while dataPath stores the hierarchy object
956
+ let value = values[widgetId];
957
+ // If widgetId doesn't have a value, try dataPath
958
+ if (value === undefined && config['widget-data-path']) {
959
+ value = getWidgetValue(values, config['widget-data-path'], widgetId);
960
+ // CRITICAL: For geo widgets with dataPath, the value might be stored as a hierarchy object
961
+ // Extract the actual value (geo_lowest_level_value_id) if it's an object
962
+ const geoConfig = config['widget-geo-config'];
963
+ if (geoConfig?.isLastLevel && value && typeof value === 'object' && !Array.isArray(value)) {
964
+ // If it's a geo hierarchy object, extract the actual value
965
+ if ('geo_lowest_level_value_id' in value) {
966
+ value = value.geo_lowest_level_value_id;
967
+ }
968
+ else if ('value' in value) {
969
+ value = value.value;
970
+ }
971
+ else if ('id' in value) {
972
+ value = value.id;
973
+ }
974
+ }
975
+ }
976
+ // If value is still undefined and user has set a value, try reading from widgetId as backup
977
+ // This handles cases where dataPath lookup might fail temporarily
978
+ if (value === undefined && userHasSetValueRef.current && values[widgetId] !== undefined) {
979
+ value = values[widgetId];
980
+ }
981
+ // If user has explicitly set a value, always return it (even if undefined/null)
982
+ // This prevents the default from overwriting user selections
983
+ if (userHasSetValueRef.current) {
984
+ return value;
985
+ }
986
+ // Only fall back to default if user hasn't set a value yet
987
+ // But check if value is explicitly null (user cleared it) vs undefined (never set)
988
+ if (value === null) {
989
+ return null; // User explicitly cleared it, don't use default
990
+ }
831
991
  return value !== undefined ? value : config['widget-data-default'];
832
992
  }, [values, config, widgetId, isLayoutWidget]);
833
- // Initialize default value (skip for layout widgets)
993
+ // Initialize default value only once on mount (skip for layout widgets)
834
994
  React.useEffect(() => {
835
995
  if (isLayoutWidget) {
836
996
  return;
837
997
  }
838
- if (config['widget-data-default'] !== undefined && currentValue === undefined) {
998
+ // Only initialize default if value is undefined and user hasn't set a value yet
999
+ if (!userHasSetValueRef.current && config['widget-data-default'] !== undefined && currentValue === undefined) {
839
1000
  handleChange(config['widget-data-default'], false);
840
1001
  }
841
1002
  // eslint-disable-next-line react-hooks/exhaustive-deps
842
- }, [isLayoutWidget]); // handleChange and currentValue are stable or handled separately
1003
+ }, [isLayoutWidget]); // Only run once on mount
843
1004
  // Handle value change
1005
+ // CRITICAL: Don't include 'values' in dependency array - it causes the callback to be recreated
1006
+ // every time values change, which can lead to stale closures and double dispatches
844
1007
  const handleChange = React.useCallback((newValue, validate = true) => {
845
- const updatedValues = setWidgetValue(values, config['widget-data-path'], widgetId, newValue);
846
- // Update Redux store
847
- Object.entries(updatedValues).forEach(([key, value]) => {
848
- if (key !== widgetId || value !== values[key]) {
849
- dispatch(setValue({ widgetId: key, value }));
1008
+ // Use valuesRef to get the latest values, not the stale closure value
1009
+ const currentValues = valuesRef.current;
1010
+ const currentValue = currentValues[widgetId] || getWidgetValue(currentValues, config['widget-data-path'], widgetId);
1011
+ // CRITICAL: Prevent setting the same value (avoids unnecessary dispatches and potential loops)
1012
+ if (currentValue === newValue) {
1013
+ return;
1014
+ }
1015
+ // Mark that user has set a value (unless this is the default initialization)
1016
+ if (newValue !== config['widget-data-default'] || userHasSetValueRef.current) {
1017
+ userHasSetValueRef.current = true;
1018
+ }
1019
+ // CRITICAL FIX: If there's no dataPath, just set the value directly
1020
+ // If there's a dataPath, we need to update both the widgetId and the dataPath
1021
+ if (!config['widget-data-path']) {
1022
+ // No dataPath: just set the value directly by widgetId
1023
+ // CRITICAL: Check if we just dispatched this value to prevent duplicate dispatches
1024
+ if (lastDispatchedValueRef.current === newValue) {
1025
+ return;
850
1026
  }
851
- });
1027
+ lastDispatchedValueRef.current = newValue;
1028
+ dispatch(setValue({ widgetId, value: newValue }));
1029
+ }
1030
+ else {
1031
+ // Has dataPath: update both widgetId and dataPath
1032
+ // CRITICAL: Create updated values object with newValue already set
1033
+ // This prevents setWidgetValue from reading stale values
1034
+ const currentValuesWithUpdate = {
1035
+ ...valuesRef.current,
1036
+ [widgetId]: newValue, // Ensure widgetId has the new value
1037
+ };
1038
+ const updatedValues = setWidgetValue(currentValuesWithUpdate, config['widget-data-path'], widgetId, newValue);
1039
+ // setWidgetValue returns the complete updated structure with all existing data preserved
1040
+ // Use setValues to update the entire state with deep merge
1041
+ dispatch(setValues(updatedValues));
1042
+ }
852
1043
  // Validate if needed
853
1044
  if (validate) {
854
1045
  const validationErrors = validateWidget(newValue, config['widget-data-validation'], config['widget-required']);
@@ -858,14 +1049,36 @@ const useBaseWidget = (options) => {
858
1049
  if (onValueChange) {
859
1050
  onValueChange(widgetId, newValue);
860
1051
  }
861
- }, [values, config, widgetId, dispatch, onValueChange]);
1052
+ // Publish widget:change event
1053
+ // Skip publishing for last-level geo widgets (no child widgets waiting)
1054
+ const geoConfig = config['widget-geo-config'];
1055
+ const isLastLevelGeo = geoConfig?.isLastLevel === true;
1056
+ if (eventBus && !isLastLevelGeo) {
1057
+ eventBus.publish({
1058
+ type: 'widget:change',
1059
+ widgetId,
1060
+ value: newValue,
1061
+ timestamp: Date.now(),
1062
+ });
1063
+ }
1064
+ }, [config, widgetId, dispatch, onValueChange, eventBus] // Removed 'values' to prevent stale closures
1065
+ );
862
1066
  // Handle blur
863
1067
  const handleBlur = React.useCallback(() => {
864
1068
  dispatch(setTouched({ widgetId, touched: true }));
865
1069
  // Validate on blur
866
1070
  const validationErrors = validateWidget(currentValue, config['widget-data-validation'], config['widget-required']);
867
1071
  dispatch(setError({ widgetId, errors: validationErrors }));
868
- }, [currentValue, config, widgetId, dispatch]);
1072
+ // Publish widget:blur event
1073
+ if (eventBus) {
1074
+ eventBus.publish({
1075
+ type: 'widget:blur',
1076
+ widgetId,
1077
+ value: currentValue,
1078
+ timestamp: Date.now(),
1079
+ });
1080
+ }
1081
+ }, [currentValue, config, widgetId, dispatch, eventBus]);
869
1082
  // Get field value helper
870
1083
  const getFieldValue = React.useCallback((path) => {
871
1084
  return getWidgetValue(values, path, '');
@@ -895,33 +1108,102 @@ const useBaseWidget = (options) => {
895
1108
  }
896
1109
  return formatValue(currentValue, config['widget-data-format'], config.widget);
897
1110
  }, [currentValue, config]);
1111
+ // Track readonly state explicitly to detect changes
1112
+ // Use JSON.stringify to create a stable reference for the dependency array
1113
+ const isReadonly = config['widget-readonly'] ?? false;
1114
+ const dataSource = config['widget-data-source'];
1115
+ const geoConfig = config['widget-geo-config'];
1116
+ // Use ref to store handler to avoid stale closures
1117
+ const handlerRef = React.useRef(dataSourceRequestHandler);
1118
+ React.useEffect(() => {
1119
+ handlerRef.current = dataSourceRequestHandler;
1120
+ }, [dataSourceRequestHandler]);
1121
+ // Create a stable key for the config to detect changes
1122
+ // This ensures the effect runs when widget-readonly changes
1123
+ const apiService = dataSource?.type === 'api' ? dataSource.service : '';
1124
+ const apiEndpoint = dataSource?.type === 'api' ? dataSource.endpoint : '';
1125
+ const configKey = `${widgetId}-${isReadonly}-${dataSource?.type || 'none'}-${apiService}-${apiEndpoint}`;
898
1126
  // Handle data source loading
899
1127
  React.useEffect(() => {
900
- const dataSource = config['widget-data-source'];
901
1128
  if (!dataSource) {
902
1129
  return;
903
1130
  }
1131
+ // For API data sources, check if widget is readonly
1132
+ // According to PRD: "Level 1 geo widgets load on widget mount or when entering edit mode"
1133
+ // So we should only load API data sources when widget is NOT readonly
1134
+ if (dataSource.type === 'api' && isReadonly) {
1135
+ return;
1136
+ }
1137
+ // For widgets with dependencies, check if dependency value exists
1138
+ if (dataSource.type === 'api' && dataSource.dependsOn) {
1139
+ // Check if dependency value exists
1140
+ let depValue = null;
1141
+ if (dataSource.dependsOn.includes('.')) {
1142
+ depValue = getWidgetValue(values, dataSource.dependsOn, '');
1143
+ }
1144
+ else {
1145
+ depValue = values[dataSource.dependsOn];
1146
+ }
1147
+ // If dependency is empty, don't load (will load when dependency has value)
1148
+ if (depValue === null || depValue === undefined || depValue === '') {
1149
+ return;
1150
+ }
1151
+ }
904
1152
  const loadDataSource = async () => {
1153
+ // Get current handler from ref to avoid stale closures
1154
+ // Also check prop directly as fallback (for initial render or when ref not updated yet)
1155
+ const currentHandler = handlerRef.current || dataSourceRequestHandler;
1156
+ // Only check for handler when we actually need it (inside the async function)
1157
+ // This avoids false errors during React Strict Mode double-invocation
1158
+ // If handler isn't available yet, silently skip - React will retry when it's ready
905
1159
  try {
1160
+ if (dataSource.type === 'api' && !currentHandler) {
1161
+ // Silently skip if handler isn't available yet (common during React Strict Mode double-invocation)
1162
+ // React will call this effect again when the handler is ready
1163
+ return;
1164
+ }
906
1165
  dispatch(setLoading({ widgetId, loading: true }));
907
1166
  let data = [];
908
1167
  if (dataSource.type === 'static') {
909
1168
  data = getStaticDataSource(dataSource);
910
1169
  }
911
1170
  else if (dataSource.type === 'api') {
912
- data = await getApiDataSource(dataSource, values, apiAdapter);
1171
+ if (!currentHandler) {
1172
+ // Silently skip if handler isn't available yet
1173
+ dispatch(setLoading({ widgetId, loading: false }));
1174
+ dispatch(setDataSource({ widgetId, data: [] }));
1175
+ return;
1176
+ }
1177
+ // Extract level_id from widget-geo-config.level if available
1178
+ const levelId = geoConfig?.level;
1179
+ data = await getApiDataSource(dataSource, values, currentHandler, levelId);
913
1180
  }
914
1181
  else if (dataSource.type === 'schema') {
915
1182
  data = getSchemaDataSource(dataSource, schemaData || {});
916
1183
  }
917
1184
  // Transform to { value, label } format
918
- const valueKey = dataSource.type === 'static' ? undefined : dataSource.valueKey;
919
- const labelKey = dataSource.type === 'static' ? undefined : dataSource.labelKey;
1185
+ // For geo widgets, default to level_value_id and level_value_mnemonic
1186
+ let valueKey;
1187
+ let labelKey;
1188
+ if (dataSource.type === 'static') {
1189
+ valueKey = undefined;
1190
+ labelKey = undefined;
1191
+ }
1192
+ else if (geoConfig) {
1193
+ // Geo widgets: default to level_value_id and level_value_mnemonic
1194
+ valueKey = dataSource.valueKey || 'level_value_id';
1195
+ labelKey = dataSource.labelKey || 'level_value_mnemonic';
1196
+ }
1197
+ else {
1198
+ // Non-geo widgets: use specified keys or undefined
1199
+ valueKey = dataSource.valueKey;
1200
+ labelKey = dataSource.labelKey;
1201
+ }
920
1202
  const transformed = transformDataSourceOptions(data, valueKey, labelKey);
921
1203
  dispatch(setDataSource({ widgetId, data: transformed }));
922
1204
  }
923
1205
  catch (error) {
924
- console.error('Error loading data source:', error);
1206
+ console.error(`[useBaseWidget] ERROR loading data source for ${widgetId}:`, error);
925
1207
  dispatch(setDataSource({ widgetId, data: [] }));
926
1208
  }
927
1209
  finally {
@@ -929,7 +1211,9 @@ const useBaseWidget = (options) => {
929
1211
  }
930
1212
  };
931
1213
  loadDataSource();
932
- }, [config['widget-data-source'], values, apiAdapter, schemaData, widgetId, dispatch]);
1214
+ // Use configKey to ensure effect runs when readonly state changes
1215
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1216
+ }, [configKey, values, dataSourceRequestHandler, schemaData, widgetId, dispatch]);
933
1217
  return {
934
1218
  widgetId,
935
1219
  value: currentValue,
@@ -948,6 +1232,357 @@ const useBaseWidget = (options) => {
948
1232
  };
949
1233
  };
950
1234
 
1235
+ /**
1236
+ * Hook for general widget cascade functionality
1237
+ * Handles listening to parent widget changes and reloading data sources
1238
+ */
1239
+ const useWidgetCascade = (options) => {
1240
+ const { config, dataSourceRequestHandler, values } = options;
1241
+ const dispatch = reactRedux.useDispatch();
1242
+ const eventBus = useWidgetEventBus();
1243
+ const widgetId = config['widget-id'];
1244
+ const cascadeConfig = config['widget-cascade'];
1245
+ const dataSource = config['widget-data-source'];
1246
+ const valuesRef = React.useRef(values);
1247
+ const handlerRef = React.useRef(dataSourceRequestHandler);
1248
+ // Keep refs updated
1249
+ React.useEffect(() => {
1250
+ valuesRef.current = values;
1251
+ handlerRef.current = dataSourceRequestHandler;
1252
+ }, [values, dataSourceRequestHandler]);
1253
+ React.useEffect(() => {
1254
+ if (!cascadeConfig || !eventBus || !dataSource || dataSource.type !== 'api') {
1255
+ return;
1256
+ }
1257
+ const { listenTo, onEvent = 'widget:change', clearOnChange = true, reloadOnChange = true, debounce, throttle } = cascadeConfig;
1258
+ if (listenTo.length === 0) {
1259
+ return;
1260
+ }
1261
+ const handleEvent = async (event) => {
1262
+ // Check if this event is from a parent we're listening to
1263
+ if (!listenTo.includes(event.widgetId)) {
1264
+ return;
1265
+ }
1266
+ const currentValues = valuesRef.current;
1267
+ const currentHandler = handlerRef.current;
1268
+ // Clear value if configured
1269
+ if (clearOnChange) {
1270
+ dispatch(setValue({ widgetId, value: undefined }));
1271
+ }
1272
+ // Reload data source if configured
1273
+ if (reloadOnChange && currentHandler) {
1274
+ try {
1275
+ const data = await getApiDataSource(dataSource, currentValues, currentHandler);
1276
+ // Transform to { value, label } format
1277
+ const valueKey = dataSource.valueKey;
1278
+ const labelKey = dataSource.labelKey;
1279
+ const transformed = transformDataSourceOptions(data, valueKey, labelKey);
1280
+ dispatch(setDataSource({ widgetId, data: transformed }));
1281
+ }
1282
+ catch (error) {
1283
+ console.error('Error reloading data source in cascade:', error);
1284
+ dispatch(setDataSource({ widgetId, data: [] }));
1285
+ }
1286
+ }
1287
+ };
1288
+ // Subscribe to events
1289
+ const unsubscribe = eventBus.subscribe(onEvent, handleEvent, { debounce, throttle });
1290
+ return () => {
1291
+ unsubscribe();
1292
+ };
1293
+ }, [cascadeConfig, eventBus, dataSource, widgetId, dispatch]);
1294
+ };
1295
+
1296
+ /**
1297
+ * Geo Hierarchy Builder
1298
+ * Manages geo hierarchy state and builds hierarchy JSON structure
1299
+ */
1300
+ class GeoHierarchyBuilder {
1301
+ constructor() {
1302
+ this.hierarchies = new Map();
1303
+ }
1304
+ /**
1305
+ * Get or create hierarchy state for a group
1306
+ */
1307
+ getHierarchy(groupId = 'default') {
1308
+ if (!this.hierarchies.has(groupId)) {
1309
+ this.hierarchies.set(groupId, {
1310
+ levels: new Map(),
1311
+ order: [],
1312
+ });
1313
+ }
1314
+ return this.hierarchies.get(groupId);
1315
+ }
1316
+ /**
1317
+ * Add a level to the hierarchy
1318
+ */
1319
+ addLevel(level, level_value_id, level_value_mnemonic, groupId = 'default') {
1320
+ const hierarchy = this.getHierarchy(groupId);
1321
+ // If level already exists, remove it and everything after it
1322
+ const existingIndex = hierarchy.order.indexOf(level);
1323
+ if (existingIndex >= 0) {
1324
+ // Remove this level and all subsequent levels
1325
+ const levelsToRemove = hierarchy.order.slice(existingIndex);
1326
+ levelsToRemove.forEach((l) => {
1327
+ hierarchy.levels.delete(l);
1328
+ hierarchy.order = hierarchy.order.filter((o) => o !== l);
1329
+ });
1330
+ }
1331
+ // Add new level
1332
+ hierarchy.levels.set(level, {
1333
+ level,
1334
+ level_value_id,
1335
+ level_value_mnemonic,
1336
+ });
1337
+ hierarchy.order.push(level);
1338
+ }
1339
+ /**
1340
+ * Remove a level and all levels below it
1341
+ */
1342
+ removeLevelAndBelow(level, groupId = 'default') {
1343
+ const hierarchy = this.getHierarchy(groupId);
1344
+ const index = hierarchy.order.indexOf(level);
1345
+ if (index >= 0) {
1346
+ // Remove this level and all subsequent levels
1347
+ const levelsToRemove = hierarchy.order.slice(index);
1348
+ levelsToRemove.forEach((l) => {
1349
+ hierarchy.levels.delete(l);
1350
+ hierarchy.order = hierarchy.order.filter((o) => o !== l);
1351
+ });
1352
+ }
1353
+ }
1354
+ /**
1355
+ * Build hierarchy JSON structure
1356
+ */
1357
+ buildHierarchyJson(groupId = 'default') {
1358
+ const hierarchy = this.getHierarchy(groupId);
1359
+ if (hierarchy.order.length === 0) {
1360
+ return null;
1361
+ }
1362
+ const hierarchyArray = hierarchy.order.map((level) => {
1363
+ const data = hierarchy.levels.get(level);
1364
+ return {
1365
+ level: data.level,
1366
+ level_value_id: data.level_value_id,
1367
+ level_value_mnemonic: data.level_value_mnemonic,
1368
+ };
1369
+ });
1370
+ const lowestLevel = hierarchy.order[hierarchy.order.length - 1];
1371
+ const lowestLevelData = hierarchy.levels.get(lowestLevel);
1372
+ return {
1373
+ geo_lowest_level_value_id: lowestLevelData.level_value_id,
1374
+ geo_code_hierarchy_json: {
1375
+ hierarchy: hierarchyArray,
1376
+ lowest_level_value_id: lowestLevelData.level_value_id,
1377
+ },
1378
+ };
1379
+ }
1380
+ /**
1381
+ * Clear hierarchy for a group
1382
+ */
1383
+ clear(groupId = 'default') {
1384
+ this.hierarchies.delete(groupId);
1385
+ }
1386
+ /**
1387
+ * Clear all hierarchies
1388
+ */
1389
+ clearAll() {
1390
+ this.hierarchies.clear();
1391
+ }
1392
+ /**
1393
+ * Get current levels for a group
1394
+ */
1395
+ getLevels(groupId = 'default') {
1396
+ const hierarchy = this.getHierarchy(groupId);
1397
+ return hierarchy.order.map((level) => hierarchy.levels.get(level));
1398
+ }
1399
+ }
1400
+ // Singleton instance
1401
+ const geoHierarchyBuilder = new GeoHierarchyBuilder();
1402
+
1403
+ // Define stable empty array to avoid selector reference issues
1404
+ const EMPTY_DATA_SOURCE = [];
1405
+ /**
1406
+ * Hook for geo widget cascade functionality
1407
+ * Handles geo hierarchy building and cascade behavior
1408
+ */
1409
+ const useGeoWidgetCascade = (options) => {
1410
+ const { config, dataSourceRequestHandler, values } = options;
1411
+ const dispatch = reactRedux.useDispatch();
1412
+ const eventBus = useWidgetEventBus();
1413
+ const widgetId = config['widget-id'];
1414
+ const geoConfig = config['widget-geo-config'];
1415
+ const dataSource = config['widget-data-source'];
1416
+ const dataPath = config['widget-data-path'];
1417
+ const valuesRef = React.useRef(values);
1418
+ const handlerRef = React.useRef(dataSourceRequestHandler);
1419
+ // Keep refs updated
1420
+ React.useEffect(() => {
1421
+ valuesRef.current = values;
1422
+ handlerRef.current = dataSourceRequestHandler;
1423
+ }, [values, dataSourceRequestHandler]);
1424
+ // Get current value and data source options
1425
+ const currentValue = reactRedux.useSelector((state) => {
1426
+ if (!dataPath) {
1427
+ return state.widget.values[widgetId];
1428
+ }
1429
+ return getWidgetValue(state.widget.values, dataPath, widgetId);
1430
+ });
1431
+ // Memoize selector to avoid returning new array reference
1432
+ const dataSourceOptions = reactRedux.useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE);
1433
+ React.useEffect(() => {
1434
+ if (!geoConfig || !eventBus || !dataSource || dataSource.type !== 'api') {
1435
+ return;
1436
+ }
1437
+ const { level, isLastLevel, parentWidgetId } = geoConfig;
1438
+ // Listen to parent widget changes
1439
+ if (parentWidgetId) {
1440
+ const handleParentChange = async (event) => {
1441
+ if (event.widgetId !== parentWidgetId) {
1442
+ return;
1443
+ }
1444
+ // CRITICAL: Use a small delay to ensure Redux state has been updated
1445
+ // This prevents reading stale values from valuesRef
1446
+ await new Promise(resolve => setTimeout(resolve, 0));
1447
+ const currentValues = valuesRef.current;
1448
+ const currentHandler = handlerRef.current;
1449
+ // CRITICAL: Get the parent value from Redux state, not from the event
1450
+ // The event.value might be stale, but Redux state is always current
1451
+ const parentValue = currentValues[parentWidgetId];
1452
+ // Remove this level and all below from hierarchy
1453
+ geoHierarchyBuilder.removeLevelAndBelow(level);
1454
+ // Clear this widget's value
1455
+ // CRITICAL: Only dispatch setValue for THIS widget, not for parent or other widgets
1456
+ // setWidgetValue returns the entire updated state, but we only want to update this widget
1457
+ if (dataPath) {
1458
+ const updatedValues = setWidgetValue(currentValues, dataPath, widgetId, undefined);
1459
+ // Only dispatch setValue for this widget's widgetId, not for parent or other widgets
1460
+ // This prevents accidentally overwriting the parent widget's value
1461
+ // The setWidgetValue function updates the nested structure, but we only want to
1462
+ // update the top-level widgetId key, not other keys that might be in updatedValues
1463
+ const newWidgetValue = updatedValues[widgetId];
1464
+ if (newWidgetValue !== undefined) {
1465
+ dispatch(setValue({ widgetId, value: newWidgetValue }));
1466
+ }
1467
+ else {
1468
+ // If widgetId is not in updatedValues, the value was set in a nested path
1469
+ // In this case, we need to use setValues to update the entire structure
1470
+ // But we need to be careful not to overwrite the parent widget's value
1471
+ // Only update keys that are related to this widget's dataPath
1472
+ const dataPathStr = typeof dataPath === 'string' ? dataPath : '';
1473
+ if (dataPathStr && !dataPathStr.startsWith(parentWidgetId + '.')) {
1474
+ // Only update if dataPath doesn't start with parentWidgetId
1475
+ // This ensures we don't accidentally overwrite the parent widget's value
1476
+ dispatch(setValue({ widgetId, value: undefined }));
1477
+ }
1478
+ }
1479
+ }
1480
+ else {
1481
+ dispatch(setValue({ widgetId, value: undefined }));
1482
+ }
1483
+ // Reload data source with new parent value
1484
+ // CRITICAL: Use parentValue from Redux, not event.value
1485
+ if (currentHandler && parentValue !== null && parentValue !== undefined) {
1486
+ try {
1487
+ // Merge the new parent value into current values for the API call
1488
+ // This ensures getApiDataSource can find the dependency value
1489
+ const updatedValues = {
1490
+ ...currentValues,
1491
+ [parentWidgetId]: parentValue, // Use Redux value, not event.value
1492
+ };
1493
+ // Extract level_id from widget-geo-config.level
1494
+ const levelId = geoConfig.level;
1495
+ const data = await getApiDataSource(dataSource, updatedValues, currentHandler, levelId);
1496
+ // Transform to { value, label } format
1497
+ const valueKey = dataSource.valueKey || 'level_value_id';
1498
+ const labelKey = dataSource.labelKey || 'level_value_mnemonic';
1499
+ const transformed = transformDataSourceOptions(data, valueKey, labelKey);
1500
+ dispatch(setDataSource({ widgetId, data: transformed }));
1501
+ }
1502
+ catch (error) {
1503
+ console.error('Error reloading geo data source:', error);
1504
+ dispatch(setDataSource({ widgetId, data: [] }));
1505
+ }
1506
+ }
1507
+ else {
1508
+ // If parent value is cleared, clear the data source
1509
+ dispatch(setDataSource({ widgetId, data: [] }));
1510
+ }
1511
+ };
1512
+ const unsubscribe = eventBus.subscribe('widget:change', handleParentChange);
1513
+ return () => {
1514
+ unsubscribe();
1515
+ };
1516
+ }
1517
+ }, [geoConfig, eventBus, dataSource, widgetId, dataPath, dispatch]);
1518
+ // Handle value changes to build hierarchy
1519
+ React.useEffect(() => {
1520
+ if (!geoConfig) {
1521
+ return;
1522
+ }
1523
+ // Skip if value is empty/null (but allow 0 and false)
1524
+ if (currentValue === null || currentValue === undefined || currentValue === '') {
1525
+ // If value was cleared, remove this level and below from hierarchy
1526
+ const { level } = geoConfig;
1527
+ geoHierarchyBuilder.removeLevelAndBelow(level);
1528
+ return;
1529
+ }
1530
+ const { level, isLastLevel } = geoConfig;
1531
+ // For last level, check if hierarchy is already built to prevent endless loops
1532
+ if (isLastLevel && dataPath) {
1533
+ const currentHierarchy = getWidgetValue(valuesRef.current, dataPath, widgetId);
1534
+ // If hierarchy JSON is already set and matches current value, skip rebuilding
1535
+ if (currentHierarchy && typeof currentHierarchy === 'object' && currentHierarchy.geo_code_hierarchy_json) {
1536
+ // Check if the lowest level value matches
1537
+ const currentLevelValue = typeof currentValue === 'object'
1538
+ ? (currentValue.level_value_id || currentValue.id || currentValue.value)
1539
+ : currentValue;
1540
+ if (currentHierarchy.geo_lowest_level_value_id === currentLevelValue) {
1541
+ return; // Hierarchy already built for this value, skip
1542
+ }
1543
+ }
1544
+ }
1545
+ // Extract level_value_id and level_value_mnemonic from current value
1546
+ // The value could be the ID itself or an object with id/name
1547
+ let level_value_id;
1548
+ let level_value_mnemonic;
1549
+ if (typeof currentValue === 'string' || typeof currentValue === 'number') {
1550
+ // Value is just the ID, need to find mnemonic from data source
1551
+ level_value_id = String(currentValue);
1552
+ // Try to get mnemonic from data source options
1553
+ const option = dataSourceOptions.find((opt) => opt.value === currentValue);
1554
+ level_value_mnemonic = option?.label || String(currentValue);
1555
+ }
1556
+ else if (currentValue && typeof currentValue === 'object') {
1557
+ level_value_id = currentValue.level_value_id || currentValue.id || currentValue.value;
1558
+ level_value_mnemonic = currentValue.level_value_mnemonic || currentValue.name || currentValue.label;
1559
+ }
1560
+ else {
1561
+ return;
1562
+ }
1563
+ // When a widget's own value changes, remove this level and all below from hierarchy first
1564
+ // This ensures that when level 1 changes, we clear the hierarchy and rebuild from scratch
1565
+ // The addLevel method already handles removing existing levels, but we explicitly clear to be safe
1566
+ geoHierarchyBuilder.removeLevelAndBelow(level);
1567
+ // Add level to hierarchy
1568
+ geoHierarchyBuilder.addLevel(level, level_value_id, level_value_mnemonic);
1569
+ // If this is the last level, build and store hierarchy JSON
1570
+ if (isLastLevel && dataPath) {
1571
+ const hierarchyJson = geoHierarchyBuilder.buildHierarchyJson();
1572
+ if (hierarchyJson) {
1573
+ // Store both geo_lowest_level_value_id and geo_code_hierarchy_json
1574
+ const updatedValues = setWidgetValue(valuesRef.current, dataPath, widgetId, {
1575
+ geo_lowest_level_value_id: hierarchyJson.geo_lowest_level_value_id,
1576
+ geo_code_hierarchy_json: hierarchyJson.geo_code_hierarchy_json,
1577
+ });
1578
+ Object.entries(updatedValues).forEach(([key, value]) => {
1579
+ dispatch(setValue({ widgetId: key, value }));
1580
+ });
1581
+ }
1582
+ }
1583
+ }, [geoConfig, currentValue, widgetId, dataPath, dispatch, dataSourceOptions]);
1584
+ };
1585
+
951
1586
  var jsxRuntime = {exports: {}};
952
1587
 
953
1588
  var reactJsxRuntime_production = {};
@@ -1450,42 +2085,208 @@ class WidgetRegistry {
1450
2085
  // Singleton instance
1451
2086
  const widgetRegistry = new WidgetRegistry();
1452
2087
 
2088
+ /**
2089
+ * Widget Event Bus
2090
+ * Provides a publish/subscribe mechanism for widget communication
2091
+ * Supports debounce and throttle for performance optimization
2092
+ */
2093
+ class WidgetEventBus {
2094
+ constructor() {
2095
+ this.subscriptions = new Map();
2096
+ this.throttleTimers = new Map();
2097
+ }
2098
+ /**
2099
+ * Subscribe to an event type
2100
+ * @param eventType The type of event to listen to
2101
+ * @param handler The handler function
2102
+ * @param options Debounce/throttle options
2103
+ * @returns Unsubscribe function
2104
+ */
2105
+ subscribe(eventType, handler, options) {
2106
+ if (!this.subscriptions.has(eventType)) {
2107
+ this.subscriptions.set(eventType, new Map());
2108
+ }
2109
+ const eventSubscriptions = this.subscriptions.get(eventType);
2110
+ const subscriptionId = `${Date.now()}-${Math.random()}`;
2111
+ const subscription = {
2112
+ handler,
2113
+ debounce: options?.debounce,
2114
+ throttle: options?.throttle,
2115
+ };
2116
+ if (!eventSubscriptions.has(subscriptionId)) {
2117
+ eventSubscriptions.set(subscriptionId, []);
2118
+ }
2119
+ eventSubscriptions.get(subscriptionId).push(subscription);
2120
+ // Return unsubscribe function
2121
+ return () => {
2122
+ const subs = eventSubscriptions.get(subscriptionId);
2123
+ if (subs) {
2124
+ const index = subs.indexOf(subscription);
2125
+ if (index > -1) {
2126
+ subs.splice(index, 1);
2127
+ if (subs.length === 0) {
2128
+ eventSubscriptions.delete(subscriptionId);
2129
+ }
2130
+ }
2131
+ }
2132
+ };
2133
+ }
2134
+ /**
2135
+ * Publish an event
2136
+ * @param event The event to publish
2137
+ */
2138
+ publish(event) {
2139
+ const eventSubscriptions = this.subscriptions.get(event.type);
2140
+ if (!eventSubscriptions) {
2141
+ return;
2142
+ }
2143
+ eventSubscriptions.forEach((subscriptions) => {
2144
+ subscriptions.forEach((subscription) => {
2145
+ this.executeHandler(subscription, event);
2146
+ });
2147
+ });
2148
+ }
2149
+ /**
2150
+ * Execute handler with debounce/throttle support
2151
+ */
2152
+ executeHandler(subscription, event) {
2153
+ const { handler, debounce, throttle } = subscription;
2154
+ // Clear existing debounce timer if any
2155
+ if (subscription.debounceTimer) {
2156
+ clearTimeout(subscription.debounceTimer);
2157
+ }
2158
+ // Handle throttle
2159
+ if (throttle && throttle > 0) {
2160
+ const throttleKey = `${event.type}-${event.widgetId}`;
2161
+ const now = Date.now();
2162
+ const lastCallTime = subscription.lastCallTime || 0;
2163
+ if (now - lastCallTime < throttle) {
2164
+ // Still in throttle period, schedule for later
2165
+ if (this.throttleTimers.has(throttleKey)) {
2166
+ return; // Already scheduled
2167
+ }
2168
+ const remainingTime = throttle - (now - lastCallTime);
2169
+ const timer = setTimeout(() => {
2170
+ subscription.lastCallTime = Date.now();
2171
+ handler(event);
2172
+ this.throttleTimers.delete(throttleKey);
2173
+ }, remainingTime);
2174
+ this.throttleTimers.set(throttleKey, timer);
2175
+ return;
2176
+ }
2177
+ subscription.lastCallTime = now;
2178
+ }
2179
+ // Handle debounce
2180
+ if (debounce && debounce > 0) {
2181
+ subscription.debounceTimer = setTimeout(() => {
2182
+ handler(event);
2183
+ subscription.debounceTimer = undefined;
2184
+ }, debounce);
2185
+ return;
2186
+ }
2187
+ // Execute immediately if no debounce/throttle
2188
+ handler(event);
2189
+ }
2190
+ /**
2191
+ * Clear all subscriptions
2192
+ */
2193
+ clear() {
2194
+ // Clear all timers
2195
+ this.subscriptions.forEach((eventSubscriptions) => {
2196
+ eventSubscriptions.forEach((subscriptions) => {
2197
+ subscriptions.forEach((sub) => {
2198
+ if (sub.debounceTimer) {
2199
+ clearTimeout(sub.debounceTimer);
2200
+ }
2201
+ });
2202
+ });
2203
+ });
2204
+ this.throttleTimers.forEach((timer) => clearTimeout(timer));
2205
+ this.throttleTimers.clear();
2206
+ this.subscriptions.clear();
2207
+ }
2208
+ }
2209
+
1453
2210
  const WidgetContext = React.createContext({
1454
- apiAdapter: undefined,
2211
+ dataSourceRequestHandler: undefined,
1455
2212
  schemaData: undefined,
1456
2213
  translate: undefined,
1457
2214
  });
1458
2215
  const useWidgetContext = () => {
1459
2216
  return React.useContext(WidgetContext);
1460
2217
  };
1461
- const WidgetProvider = ({ store, apiAdapter, schemaData, translate, children, }) => {
2218
+ const WidgetProvider = ({ store, dataSourceRequestHandler, schemaData, translate, children, }) => {
1462
2219
  const widgetStore = React.useMemo(() => store || createWidgetStore(), [store]);
1463
- // Sync schemaData to Redux store
2220
+ // Create event bus instance (one per provider)
2221
+ const eventBus = React.useMemo(() => new WidgetEventBus(), []);
2222
+ // Memoize context value to prevent unnecessary re-renders
2223
+ const contextValue = React.useMemo(() => ({
2224
+ dataSourceRequestHandler,
2225
+ schemaData,
2226
+ translate,
2227
+ }), [dataSourceRequestHandler, schemaData, translate]);
2228
+ // Warn if dataSourceRequestHandler is missing (will cause issues with API data sources)
2229
+ React.useEffect(() => {
2230
+ if (!dataSourceRequestHandler) {
2231
+ console.warn('[WidgetProvider] dataSourceRequestHandler is not provided. ' +
2232
+ 'Widgets with API data sources will not be able to load data. ' +
2233
+ 'Please provide dataSourceRequestHandler prop to WidgetProvider.');
2234
+ }
2235
+ }, [dataSourceRequestHandler]);
2236
+ // Cleanup event bus on unmount
2237
+ React.useEffect(() => {
2238
+ return () => {
2239
+ eventBus.clear();
2240
+ };
2241
+ }, [eventBus]);
2242
+ // Initialize schemaData to Redux store (only on mount)
2243
+ // This prevents overwriting user changes when schemaData prop changes
1464
2244
  React.useEffect(() => {
1465
2245
  if (schemaData) {
1466
2246
  widgetStore.dispatch(setValues(schemaData));
1467
2247
  }
1468
- }, [schemaData, widgetStore]);
1469
- const content = (jsxRuntimeExports.jsx(reactRedux.Provider, { store: widgetStore, children: jsxRuntimeExports.jsx(WidgetContext.Provider, { value: { apiAdapter, schemaData, translate }, children: children }) }));
2248
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2249
+ }, []); // Only run on mount
2250
+ const content = (jsxRuntimeExports.jsx(reactRedux.Provider, { store: widgetStore, children: jsxRuntimeExports.jsx(WidgetContext.Provider, { value: contextValue, children: jsxRuntimeExports.jsx(WidgetEventBusContext.Provider, { value: eventBus, children: children }) }) }));
1470
2251
  return content;
1471
2252
  };
1472
2253
 
1473
- const WidgetRenderer = ({ config, apiAdapter: propApiAdapter, schemaData: propSchemaData, onValueChange, defaultComponent, }) => {
2254
+ const WidgetRenderer = ({ config, dataSourceRequestHandler: propDataSourceRequestHandler, schemaData: propSchemaData, onValueChange, defaultComponent, }) => {
1474
2255
  // Use context values as fallback
1475
2256
  const context = useWidgetContext();
1476
- const apiAdapter = propApiAdapter || context.apiAdapter;
2257
+ const dataSourceRequestHandler = propDataSourceRequestHandler || context.dataSourceRequestHandler;
1477
2258
  const schemaData = propSchemaData || context.schemaData;
2259
+ if (!dataSourceRequestHandler && config['widget-data-source']?.type === 'api') {
2260
+ console.error(`[WidgetRenderer] dataSourceRequestHandler is required for widget ${config['widget-id']} with API data source`);
2261
+ }
2262
+ // Get values from Redux for cascade hooks
2263
+ const values = reactRedux.useSelector((state) => state.widget.values);
1478
2264
  const widgetContext = useBaseWidget({
1479
2265
  config,
1480
- apiAdapter,
2266
+ dataSourceRequestHandler,
1481
2267
  schemaData,
1482
2268
  onValueChange,
1483
2269
  });
2270
+ // Apply cascade hooks if configured (only if handler is available)
2271
+ if (dataSourceRequestHandler) {
2272
+ useWidgetCascade({
2273
+ config,
2274
+ dataSourceRequestHandler,
2275
+ values,
2276
+ });
2277
+ useGeoWidgetCascade({
2278
+ config,
2279
+ dataSourceRequestHandler,
2280
+ values,
2281
+ });
2282
+ }
1484
2283
  // Don't render if not visible
1485
2284
  if (!widgetContext.isVisible) {
1486
2285
  return null;
1487
2286
  }
1488
2287
  // Render widget using registry
2288
+ // Don't use key based on readonly state - it causes remounting which resets userHasSetValueRef
2289
+ // The readonly state is already handled in the widget components themselves
1489
2290
  return (jsxRuntimeExports.jsx("div", { className: "widget-container", "data-widget-id": widgetContext.widgetId, style: { marginBottom: 0 }, children: widgetRegistry.render(config, widgetContext, defaultComponent) }));
1490
2291
  };
1491
2292
 
@@ -1588,7 +2389,7 @@ const useWidgetTranslation = () => {
1588
2389
  * - Nested panels (for layout composition)
1589
2390
  * - Widgets (for actual form inputs/controls)
1590
2391
  */
1591
- const PanelRenderer = ({ panel, apiAdapter, schemaData, onValueChange, isEditMode = false, }) => {
2392
+ const PanelRenderer = ({ panel, dataSourceRequestHandler, schemaData, onValueChange, isEditMode = false, }) => {
1592
2393
  const { translateConfig } = useWidgetTranslation();
1593
2394
  const orientation = panel['panel-orientation'] || 'vertical';
1594
2395
  const nestedPanels = panel.panels || [];
@@ -1680,7 +2481,7 @@ const PanelRenderer = ({ panel, apiAdapter, schemaData, onValueChange, isEditMod
1680
2481
  }
1681
2482
  };
1682
2483
  const nestedPanelStyle = getNestedPanelStyle();
1683
- return (jsxRuntimeExports.jsx(React.Fragment, { children: jsxRuntimeExports.jsxs("div", { className: orientation === 'horizontal' ? 'min-w-200 relative' : 'w-full', style: nestedPanelStyle, "data-panel-column-span": columnSpan || undefined, children: [jsxRuntimeExports.jsx(PanelRenderer, { panel: nestedPanel, apiAdapter: apiAdapter, schemaData: schemaData, onValueChange: onValueChange, isEditMode: isEditMode }), orientation === 'horizontal' && !isLastPanel && (jsxRuntimeExports.jsx("div", { style: {
2484
+ return (jsxRuntimeExports.jsx(React.Fragment, { children: jsxRuntimeExports.jsxs("div", { className: orientation === 'horizontal' ? 'min-w-200 relative' : 'w-full', style: nestedPanelStyle, "data-panel-column-span": columnSpan || undefined, children: [jsxRuntimeExports.jsx(PanelRenderer, { panel: nestedPanel, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: schemaData, onValueChange: onValueChange, isEditMode: isEditMode }), orientation === 'horizontal' && !isLastPanel && (jsxRuntimeExports.jsx("div", { style: {
1684
2485
  position: 'absolute',
1685
2486
  right: 0,
1686
2487
  top: 0,
@@ -1688,7 +2489,11 @@ const PanelRenderer = ({ panel, apiAdapter, schemaData, onValueChange, isEditMod
1688
2489
  width: '1px',
1689
2490
  backgroundColor: isEditMode ? '#F2BA1A' : '#D1D5DB',
1690
2491
  } }))] }) }, nestedPanel['panel-id'] || `panel-${index}`));
1691
- }), widgets.map((widgetConfig, index) => (jsxRuntimeExports.jsx(WidgetRenderer, { config: widgetConfig, apiAdapter: apiAdapter, schemaData: schemaData, onValueChange: onValueChange }, widgetConfig['widget-id'] || `widget-${index}`)))] }));
2492
+ }), widgets.map((widgetConfig, index) => {
2493
+ // Don't use readonly state in key - it causes remounting which resets userHasSetValueRef
2494
+ // The readonly state is already handled in the widget components themselves
2495
+ return (jsxRuntimeExports.jsx(WidgetRenderer, { config: widgetConfig, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: schemaData, onValueChange: onValueChange }, widgetConfig['widget-id'] || `widget-${index}`));
2496
+ })] }));
1692
2497
  // Render panel without card styling (panel-type removed from schema)
1693
2498
  // Vertical panels will have constrained width via CSS in SectionRenderer
1694
2499
  // Horizontal panels take full width
@@ -2388,11 +3193,13 @@ const namespaceSectionConfig = (section, namespace) => {
2388
3193
  * - Panels wrap when they exceed available width
2389
3194
  * - Sections can sit side-by-side if there's space
2390
3195
  */
2391
- const SectionRenderer = ({ section, apiAdapter, schemaData, onValueChange, gridColumnSpan, onSectionSave, hideEditButton = false, mode = 'RegistryView', namespace, }) => {
3196
+ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequestHandler, schemaData, onValueChange, gridColumnSpan, onSectionSave, hideEditButton = false, mode = 'RegistryView', namespace, }) => {
2392
3197
  const { translateConfig, translate } = useWidgetTranslation();
2393
- const { schemaData: contextSchemaData } = useWidgetContext();
3198
+ const { schemaData: contextSchemaData, dataSourceRequestHandler: contextDataSourceRequestHandler } = useWidgetContext();
2394
3199
  const store = reactRedux.useStore();
2395
3200
  const dispatch = reactRedux.useDispatch();
3201
+ // Use prop handler if provided, otherwise fall back to context
3202
+ const dataSourceRequestHandler = propDataSourceRequestHandler || contextDataSourceRequestHandler;
2396
3203
  // Get CRView data from schemaData (prefer prop over context, then Redux store)
2397
3204
  const currentSchemaData = schemaData || contextSchemaData || {};
2398
3205
  const storeValues = reactRedux.useSelector((state) => state.widget?.values || {});
@@ -2451,10 +3258,6 @@ const SectionRenderer = ({ section, apiAdapter, schemaData, onValueChange, gridC
2451
3258
  approvedBy: getValueByPath(dataSource, 'approvedBy') || getValueByPath(dataSource, 'approved_by'),
2452
3259
  approvedDate: getValueByPath(dataSource, 'approvedDate') || getValueByPath(dataSource, 'approved_date'),
2453
3260
  };
2454
- // Debug logging (can be removed in production)
2455
- if (mode === 'CRView') {
2456
- console.log('CRView Data Source:', { dataSource, result, currentSchemaData, storeValues });
2457
- }
2458
3261
  return result;
2459
3262
  }, [mode, currentSchemaData, storeValues]);
2460
3263
  // Use namespaced section for rendering
@@ -2578,16 +3381,19 @@ const SectionRenderer = ({ section, apiAdapter, schemaData, onValueChange, gridC
2578
3381
  const modifiedPanel = {
2579
3382
  ...panel,
2580
3383
  panels: panel.panels ? makePanelsEditable(panel.panels, editable) : undefined,
2581
- widgets: panel.widgets?.map(widget => ({
2582
- ...widget,
3384
+ widgets: panel.widgets?.map(widget => {
2583
3385
  // When NOT in edit mode (editable = false), set all widgets to readonly
2584
3386
  // When in edit mode (editable = true):
2585
3387
  // - If section-editable is true, force widgets to be editable (override widget-readonly)
2586
3388
  // - Otherwise, respect original readonly setting
2587
- 'widget-readonly': editable
3389
+ const newReadonly = editable
2588
3390
  ? (sectionEditable ? false : (widget['widget-readonly'] || false))
2589
- : true,
2590
- })),
3391
+ : true;
3392
+ return {
3393
+ ...widget,
3394
+ 'widget-readonly': newReadonly,
3395
+ };
3396
+ }),
2591
3397
  };
2592
3398
  return modifiedPanel;
2593
3399
  });
@@ -2668,7 +3474,7 @@ const SectionRenderer = ({ section, apiAdapter, schemaData, onValueChange, gridC
2668
3474
  overflowY: 'auto',
2669
3475
  }, children: [sectionToRender['section-title'] && (jsxRuntimeExports.jsx("h2", { className: "text-xl font-semibold mb-4", style: { fontFamily: 'Roboto, sans-serif', marginTop: '35px' }, children: translateConfig(sectionToRender['section-title']) })), jsxRuntimeExports.jsxs("div", { id: editGridId, className: "section-panels", children: [editableSection.panels.map((panel, index) => {
2670
3476
  const isLastPanel = index === editableSection.panels.length - 1;
2671
- return (jsxRuntimeExports.jsx("div", { className: `panel-wrapper ${isLastPanel ? 'last-panel-wrapper' : ''}`, children: jsxRuntimeExports.jsx(PanelRenderer, { panel: panel, apiAdapter: apiAdapter, schemaData: namespacedSchemaData, onValueChange: onValueChange, isEditMode: true }) }, panel['panel-id'] || `section-panel-${index}`));
3477
+ return (jsxRuntimeExports.jsx("div", { className: `panel-wrapper ${isLastPanel ? 'last-panel-wrapper' : ''}`, children: jsxRuntimeExports.jsx(PanelRenderer, { panel: panel, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: namespacedSchemaData, onValueChange: onValueChange, isEditMode: true }) }, panel['panel-id'] || `section-panel-${index}`));
2672
3478
  }), hasSupportingDocuments && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("hr", { className: "my-4 w-full", style: { height: '1px', backgroundColor: '#F2BA1A', border: 'none' } }), jsxRuntimeExports.jsxs("div", { className: "supporting-documents-container", children: [jsxRuntimeExports.jsxs("button", { type: "button", onClick: () => setIsDocumentsExpanded(!isDocumentsExpanded), className: "supporting-documents-title-button w-full flex items-center text-left", children: [jsxRuntimeExports.jsx("span", { className: "font-semibold", style: { fontFamily: 'Roboto, sans-serif', fontSize: '16px' }, children: translate('common.supportedDocuments') || 'Supported Documents' }), jsxRuntimeExports.jsx("svg", { className: `w-5 h-5 text-[#ED7C22] transition-transform ml-2 ${isDocumentsExpanded ? 'rotate-180' : ''}`, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 9l-7 7-7-7" }) })] }), isDocumentsExpanded && (jsxRuntimeExports.jsx("div", { className: "supporting-documents-grid mt-4", children: supportingDocuments.map((doc, index) => {
2673
3479
  const docConfig = createDocumentWidgetConfig(doc, sectionId, index);
2674
3480
  return (jsxRuntimeExports.jsx("div", { className: "supporting-document-item", children: jsxRuntimeExports.jsx(FileInputWidget, { config: docConfig }) }, `${sectionId}-doc-${index}`));
@@ -3018,7 +3824,7 @@ const SectionRenderer = ({ section, apiAdapter, schemaData, onValueChange, gridC
3018
3824
  minHeight: 'auto',
3019
3825
  height: 'auto'
3020
3826
  }),
3021
- }, children: [sectionToRender['section-title'] && (jsxRuntimeExports.jsx("h2", { className: "text-xl font-semibold mb-4", style: { marginTop: '35px' }, children: translateConfig(sectionToRender['section-title']) })), jsxRuntimeExports.jsxs("div", { id: gridId, className: "section-panels", style: mode === 'RegistryView' && hideEditButton ? { paddingBottom: '40px' } : {}, children: [editableSection.panels.map((panel, index) => (jsxRuntimeExports.jsx("div", { className: "panel-wrapper", children: jsxRuntimeExports.jsx(PanelRenderer, { panel: panel, apiAdapter: apiAdapter, schemaData: namespacedSchemaData, onValueChange: onValueChange }) }, panel['panel-id'] || `section-panel-${index}`))), mode === 'CRView' && crViewData && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("hr", { className: "border-gray-300 w-full", style: { height: '1px', marginTop: '20px', marginBottom: '0px' } }), jsxRuntimeExports.jsxs("div", { className: "cr-view-container", style: {
3827
+ }, children: [sectionToRender['section-title'] && (jsxRuntimeExports.jsx("h2", { className: "text-xl font-semibold mb-4", style: { marginTop: '35px' }, children: translateConfig(sectionToRender['section-title']) })), jsxRuntimeExports.jsxs("div", { id: gridId, className: "section-panels", style: mode === 'RegistryView' && hideEditButton ? { paddingBottom: '40px' } : {}, children: [editableSection.panels.map((panel, index) => (jsxRuntimeExports.jsx("div", { className: "panel-wrapper", children: jsxRuntimeExports.jsx(PanelRenderer, { panel: panel, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: namespacedSchemaData, onValueChange: onValueChange }) }, panel['panel-id'] || `section-panel-${index}`))), mode === 'CRView' && crViewData && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("hr", { className: "border-gray-300 w-full", style: { height: '1px', marginTop: '20px', marginBottom: '0px' } }), jsxRuntimeExports.jsxs("div", { className: "cr-view-container", style: {
3022
3828
  marginTop: '20px',
3023
3829
  paddingBottom: '30px',
3024
3830
  display: 'flex',
@@ -3154,7 +3960,18 @@ const countVerticalPanels = (panels) => {
3154
3960
  * - All sections align to the same grid, ensuring right-side alignment
3155
3961
  * - Handles nested structure: multiple horizontal panels, each with multiple vertical panels
3156
3962
  */
3157
- const SectionsContainer = ({ sections, apiAdapter, schemaData, onValueChange, className = '', onSectionSave, hideEditButton = false, mode = 'RegistryView', namespace, }) => {
3963
+ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceRequestHandler, schemaData, onValueChange, className = '', onSectionSave, hideEditButton = false, mode = 'RegistryView', namespace, }) => {
3964
+ // Get dataSourceRequestHandler from context if not provided as prop
3965
+ const { dataSourceRequestHandler: contextDataSourceRequestHandler } = useWidgetContext();
3966
+ const dataSourceRequestHandler = propDataSourceRequestHandler || contextDataSourceRequestHandler;
3967
+ // Warn if dataSourceRequestHandler is missing
3968
+ React.useEffect(() => {
3969
+ if (!dataSourceRequestHandler) {
3970
+ console.warn('[SectionsContainer] ⚠️ dataSourceRequestHandler is not provided. ' +
3971
+ 'Sections with widgets that have API data sources will not be able to load data. ' +
3972
+ 'Please provide dataSourceRequestHandler prop to SectionsContainer or WidgetProvider.');
3973
+ }
3974
+ }, [dataSourceRequestHandler]);
3158
3975
  // Find the maximum number of vertical panels across all sections
3159
3976
  // This determines the grid size (minimum 3 columns)
3160
3977
  // Also account for table widgets and their explicit column spans
@@ -3203,7 +4020,7 @@ const SectionsContainer = ({ sections, apiAdapter, schemaData, onValueChange, cl
3203
4020
  : undefined;
3204
4021
  // Check if section has explicit column span
3205
4022
  if (section['section-column-span']) {
3206
- return (jsxRuntimeExports.jsx(SectionRenderer, { section: section, apiAdapter: apiAdapter, schemaData: schemaData, onValueChange: onValueChange, gridColumnSpan: section['section-column-span'], onSectionSave: onSectionSave, hideEditButton: hideEditButton, mode: mode, namespace: sectionNamespace }, section['section-id']));
4023
+ return (jsxRuntimeExports.jsx(SectionRenderer, { section: section, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: schemaData, onValueChange: onValueChange, gridColumnSpan: section['section-column-span'], onSectionSave: onSectionSave, hideEditButton: hideEditButton, mode: mode, namespace: sectionNamespace }, section['section-id']));
3207
4024
  }
3208
4025
  const verticalPanelsCount = countVerticalPanels(section.panels);
3209
4026
  const tableWidgetColumnSpan = getTableWidgetColumnSpan(section.panels);
@@ -3214,16 +4031,1676 @@ const SectionsContainer = ({ sections, apiAdapter, schemaData, onValueChange, cl
3214
4031
  const columnSpan = tableWidgetColumnSpan !== null
3215
4032
  ? tableWidgetColumnSpan
3216
4033
  : (containsTable ? Math.max(verticalPanelsCount, 2) : verticalPanelsCount);
3217
- return (jsxRuntimeExports.jsx(SectionRenderer, { section: section, apiAdapter: apiAdapter, schemaData: schemaData, onValueChange: onValueChange, gridColumnSpan: columnSpan, onSectionSave: onSectionSave, hideEditButton: hideEditButton, mode: mode, namespace: sectionNamespace }, section['section-id']));
4034
+ return (jsxRuntimeExports.jsx(SectionRenderer, { section: section, dataSourceRequestHandler: dataSourceRequestHandler, schemaData: schemaData, onValueChange: onValueChange, gridColumnSpan: columnSpan, onSectionSave: onSectionSave, hideEditButton: hideEditButton, mode: mode, namespace: sectionNamespace }, section['section-id']));
3218
4035
  }) })] }));
3219
4036
  };
3220
4037
 
3221
4038
  /**
3222
- * Filter input value based on allowed character type
4039
+ * JSON Schema definitions for Section Builder validation
4040
+ * These schemas are used by json-edit-react to provide validation and constraints
3223
4041
  */
3224
- const filterByCharacterType = (value, characterType = 'any', customCharset) => {
3225
- if (characterType === 'any') {
3226
- return value;
4042
+ const WIDGET_TYPES = [
4043
+ 'text',
4044
+ 'textarea',
4045
+ 'number',
4046
+ 'boolean',
4047
+ 'date',
4048
+ 'datetime',
4049
+ 'select',
4050
+ 'radio',
4051
+ 'checkbox',
4052
+ 'file',
4053
+ 'simple-table',
4054
+ 'table',
4055
+ 'array-widget',
4056
+ 'iterable-accordion',
4057
+ 'phone',
4058
+ 'currency',
4059
+ 'display',
4060
+ 'profile',
4061
+ ];
4062
+ const ORIENTATIONS = ['horizontal', 'vertical'];
4063
+ const CONDITION_OPERATORS = [
4064
+ 'equals',
4065
+ 'notEquals',
4066
+ 'notEmpty',
4067
+ 'empty',
4068
+ 'greaterThan',
4069
+ 'lessThan',
4070
+ 'contains',
4071
+ 'notContains',
4072
+ ];
4073
+ const DATA_SOURCE_TYPES = ['static', 'api', 'schema'];
4074
+ const VALIDATION_TYPES = ['email', 'phone', 'url'];
4075
+ const CHARACTER_TYPES = [
4076
+ 'any',
4077
+ 'alphabetic',
4078
+ 'alphanumeric',
4079
+ 'numeric',
4080
+ 'numeric-decimal',
4081
+ 'custom',
4082
+ ];
4083
+ const CASE_CONTROLS = ['none', 'lowercase', 'uppercase', 'capitalize'];
4084
+ const NUMERIC_TYPES = ['integer', 'decimal'];
4085
+ const BOOLEAN_REPRESENTATIONS = ['true-false', 'yes-no', 'on-off', 'custom'];
4086
+ const BOOLEAN_CONTROL_TYPES = ['checkbox', 'radio', 'toggle'];
4087
+
4088
+ // Inject styles to constrain json-edit-react container
4089
+ if (typeof document !== 'undefined') {
4090
+ const styleId = 'json-editor-constraints';
4091
+ if (!document.getElementById(styleId)) {
4092
+ const style = document.createElement('style');
4093
+ style.id = styleId;
4094
+ style.textContent = `
4095
+ .json-editor-scroll-container {
4096
+ display: flex !important;
4097
+ flex-direction: column !important;
4098
+ height: 100% !important;
4099
+ max-height: 100% !important;
4100
+ overflow: auto !important;
4101
+ }
4102
+ .json-editor-scroll-container .jer-editor-container {
4103
+ max-width: 100% !important;
4104
+ width: 100% !important;
4105
+ height: auto !important;
4106
+ max-height: none !important;
4107
+ flex-shrink: 0 !important;
4108
+ background-color: white !important;
4109
+ }
4110
+ .json-editor-scroll-container .jer-component {
4111
+ width: 100% !important;
4112
+ }
4113
+ `;
4114
+ document.head.appendChild(style);
4115
+ }
4116
+ }
4117
+ /**
4118
+ * JSON Editor Panel - Left side of Section Builder
4119
+ */
4120
+ const JSONEditorPanel = ({ section, onChange, onReset, onSelectNode, context = 'section', }) => {
4121
+ const [jsonData, setJsonData] = React.useState(section);
4122
+ const [validationErrors, setValidationErrors] = React.useState([]);
4123
+ const [rawJsonView, setRawJsonView] = React.useState(false);
4124
+ const [rawJsonText, setRawJsonText] = React.useState('');
4125
+ const [showPreview, setShowPreview] = React.useState(false);
4126
+ const [editorKey, setEditorKey] = React.useState(0); // Key to force JsonEditor re-render on reset
4127
+ // Store the original section when component mounts or section prop changes
4128
+ const originalSectionRef = React.useRef(section);
4129
+ // Get WidgetProvider context for preview modal (optional - may not be available)
4130
+ let widgetContext;
4131
+ try {
4132
+ widgetContext = useWidgetContext();
4133
+ }
4134
+ catch {
4135
+ widgetContext = {
4136
+ dataSourceRequestHandler: undefined,
4137
+ schemaData: undefined,
4138
+ translate: undefined,
4139
+ };
4140
+ }
4141
+ // Create a store for the preview modal if we're not in a Provider
4142
+ // This ensures SectionRenderer has access to Redux
4143
+ const previewStore = React.useMemo(() => createWidgetStore(), []);
4144
+ // Track if this is the initial mount
4145
+ const isInitialMount = React.useRef(true);
4146
+ React.useEffect(() => {
4147
+ // Only update original section on initial mount (when page loads)
4148
+ // This ensures reset works until save is clicked
4149
+ // Don't update original when user makes edits (those come through onChange)
4150
+ if (isInitialMount.current) {
4151
+ originalSectionRef.current = JSON.parse(JSON.stringify(section)); // Deep copy
4152
+ isInitialMount.current = false;
4153
+ }
4154
+ // Always sync the display with the section prop (for external updates like reset from parent)
4155
+ setJsonData(section);
4156
+ setRawJsonText(JSON.stringify(section, null, 2));
4157
+ // Force JsonEditor to update when section prop changes (e.g., from parent reset)
4158
+ setEditorKey(prev => prev + 1);
4159
+ }, [section]);
4160
+ // Reset to original section
4161
+ const handleReset = React.useCallback(() => {
4162
+ // If parent provides onReset, use it (this will reset both JSON editor and visual builder)
4163
+ if (onReset) {
4164
+ onReset();
4165
+ // Also force JsonEditor to remount to ensure it picks up the reset
4166
+ setEditorKey(prev => prev + 1);
4167
+ return;
4168
+ }
4169
+ // Fallback: reset only this panel (for standalone usage)
4170
+ const original = JSON.parse(JSON.stringify(originalSectionRef.current)); // Deep copy to ensure new reference
4171
+ // Update state immediately
4172
+ setJsonData(original);
4173
+ setRawJsonText(JSON.stringify(original, null, 2));
4174
+ // Force JsonEditor to completely remount by changing key
4175
+ // This is critical because json-edit-react maintains internal state that doesn't sync with props
4176
+ setEditorKey(prev => prev + 1);
4177
+ // Notify parent
4178
+ onChange(original);
4179
+ }, [onChange, onReset]);
4180
+ // Handle Escape key to close preview
4181
+ React.useEffect(() => {
4182
+ if (!showPreview)
4183
+ return;
4184
+ const handleEscape = (e) => {
4185
+ if (e.key === 'Escape') {
4186
+ setShowPreview(false);
4187
+ }
4188
+ };
4189
+ window.addEventListener('keydown', handleEscape);
4190
+ return () => window.removeEventListener('keydown', handleEscape);
4191
+ }, [showPreview]);
4192
+ // Handle clicks in JSON editor to select corresponding node in visual builder
4193
+ React.useEffect(() => {
4194
+ if (!onSelectNode || rawJsonView)
4195
+ return; // Only work in tree view, not raw JSON view
4196
+ const handleJsonEditorClick = (e) => {
4197
+ const mouseEvent = e;
4198
+ const target = mouseEvent.target;
4199
+ // Find the key text element (json-edit-react uses .jer-key-text class)
4200
+ const keyElement = target.closest('.jer-key-text') ||
4201
+ target.querySelector('.jer-key-text') ||
4202
+ (target.classList.contains('jer-key-text') ? target : null);
4203
+ if (!keyElement)
4204
+ return;
4205
+ const keyText = keyElement.textContent?.trim();
4206
+ if (!keyText)
4207
+ return;
4208
+ // Remove colon if present
4209
+ const keyName = keyText.replace(':', '').trim();
4210
+ // Map key names to node types and find the corresponding node
4211
+ let nodeId = null;
4212
+ let nodeType = null;
4213
+ if (keyName === 'section-id') {
4214
+ // Find the section-id value
4215
+ const keyRow = keyElement.closest('.jer-collection-header-row, .jer-value-row');
4216
+ if (keyRow) {
4217
+ const valueElement = keyRow.querySelector('.jer-value-text, .jer-string-value');
4218
+ if (valueElement) {
4219
+ nodeId = valueElement.textContent?.replace(/^"|"$/g, '').trim() || section['section-id'];
4220
+ nodeType = 'section';
4221
+ }
4222
+ }
4223
+ }
4224
+ else if (keyName === 'panel-id') {
4225
+ // Find the panel-id value in the current panel object
4226
+ const panelContainer = keyElement.closest('.jer-collection-component');
4227
+ if (panelContainer) {
4228
+ const valueElement = panelContainer.querySelector('.jer-value-text, .jer-string-value');
4229
+ if (valueElement) {
4230
+ // Try to find panel-id value in this panel
4231
+ const allKeys = panelContainer.querySelectorAll('.jer-key-text');
4232
+ for (const key of Array.from(allKeys)) {
4233
+ if (key.textContent?.includes('panel-id')) {
4234
+ const keyRow = key.closest('.jer-collection-header-row, .jer-value-row');
4235
+ if (keyRow) {
4236
+ const valElement = keyRow.querySelector('.jer-value-text, .jer-string-value');
4237
+ if (valElement) {
4238
+ nodeId = valElement.textContent?.replace(/^"|"$/g, '').trim() || null;
4239
+ nodeType = 'panel';
4240
+ break;
4241
+ }
4242
+ }
4243
+ }
4244
+ }
4245
+ }
4246
+ }
4247
+ }
4248
+ else if (keyName === 'widget-id') {
4249
+ // Find the widget-id value in the current widget object
4250
+ const widgetContainer = keyElement.closest('.jer-collection-component');
4251
+ if (widgetContainer) {
4252
+ const allKeys = widgetContainer.querySelectorAll('.jer-key-text');
4253
+ for (const key of Array.from(allKeys)) {
4254
+ if (key.textContent?.includes('widget-id')) {
4255
+ const keyRow = key.closest('.jer-collection-header-row, .jer-value-row');
4256
+ if (keyRow) {
4257
+ const valElement = keyRow.querySelector('.jer-value-text, .jer-string-value');
4258
+ if (valElement) {
4259
+ nodeId = valElement.textContent?.replace(/^"|"$/g, '').trim() || null;
4260
+ nodeType = 'widget';
4261
+ break;
4262
+ }
4263
+ }
4264
+ }
4265
+ }
4266
+ }
4267
+ }
4268
+ // If we found a node, select it in the visual builder
4269
+ if (nodeId && nodeType) {
4270
+ onSelectNode(nodeId, nodeType);
4271
+ }
4272
+ };
4273
+ // Add click listener to the JSON editor container
4274
+ const editorContainer = document.querySelector('.json-editor-scroll-container');
4275
+ if (editorContainer) {
4276
+ editorContainer.addEventListener('click', handleJsonEditorClick);
4277
+ return () => {
4278
+ editorContainer.removeEventListener('click', handleJsonEditorClick);
4279
+ };
4280
+ }
4281
+ }, [onSelectNode, rawJsonView, section]);
4282
+ // Make section editable for preview - remove readonly flags from widgets
4283
+ const makeSectionEditable = React.useCallback((section) => {
4284
+ const processWidget = (widget) => {
4285
+ if (!widget || typeof widget !== 'object')
4286
+ return widget;
4287
+ const editableWidget = {
4288
+ ...widget,
4289
+ 'widget-readonly': false, // Make all widgets editable in preview
4290
+ };
4291
+ // Process nested widgets
4292
+ if (widget.widgets && Array.isArray(widget.widgets)) {
4293
+ editableWidget.widgets = widget.widgets.map(processWidget);
4294
+ }
4295
+ if (widget['widget-item']) {
4296
+ editableWidget['widget-item'] = processWidget(widget['widget-item']);
4297
+ }
4298
+ // Process table columns
4299
+ if (widget['widget-data-columns'] && Array.isArray(widget['widget-data-columns'])) {
4300
+ editableWidget['widget-data-columns'] = widget['widget-data-columns'].map((col) => {
4301
+ if (col && typeof col === 'object' && col.widget) {
4302
+ return processWidget(col);
4303
+ }
4304
+ return col;
4305
+ });
4306
+ }
4307
+ return editableWidget;
4308
+ };
4309
+ const processPanel = (panel) => {
4310
+ if (!panel || typeof panel !== 'object')
4311
+ return panel;
4312
+ const editablePanel = { ...panel };
4313
+ if (panel.widgets && Array.isArray(panel.widgets)) {
4314
+ editablePanel.widgets = panel.widgets.map(processWidget);
4315
+ }
4316
+ if (panel.panels && Array.isArray(panel.panels)) {
4317
+ editablePanel.panels = panel.panels.map(processPanel);
4318
+ }
4319
+ return editablePanel;
4320
+ };
4321
+ return {
4322
+ ...section,
4323
+ 'section-editable': true,
4324
+ panels: section.panels ? section.panels.map(processPanel) : [],
4325
+ };
4326
+ }, []);
4327
+ // Auto-populate widget-type based on widget selection
4328
+ const autoPopulateWidgetType = React.useCallback((data) => {
4329
+ if (!data || typeof data !== 'object')
4330
+ return data;
4331
+ const processWidget = (widget) => {
4332
+ if (!widget || typeof widget !== 'object')
4333
+ return widget;
4334
+ const widgetType = widget.widget;
4335
+ if (widgetType && !widget['widget-type']) {
4336
+ // Auto-determine widget-type based on widget name
4337
+ const widgetTypeMap = {
4338
+ 'text': 'input',
4339
+ 'textarea': 'input',
4340
+ 'number': 'input',
4341
+ 'boolean': 'input',
4342
+ 'date': 'input',
4343
+ 'datetime': 'input',
4344
+ 'select': 'input',
4345
+ 'radio': 'input',
4346
+ 'checkbox': 'input',
4347
+ 'file': 'input',
4348
+ 'phone': 'input',
4349
+ 'currency': 'input',
4350
+ 'display': 'input',
4351
+ 'table': 'table',
4352
+ 'simple-table': 'table',
4353
+ 'array-widget': 'group',
4354
+ 'iterable-accordion': 'group',
4355
+ 'profile': 'layout',
4356
+ };
4357
+ widget = {
4358
+ ...widget,
4359
+ 'widget-type': widgetTypeMap[widgetType] || 'input',
4360
+ };
4361
+ }
4362
+ // Process nested widgets
4363
+ if (widget.widgets && Array.isArray(widget.widgets)) {
4364
+ widget = {
4365
+ ...widget,
4366
+ widgets: widget.widgets.map(processWidget),
4367
+ };
4368
+ }
4369
+ // Process widget-item
4370
+ if (widget['widget-item']) {
4371
+ widget = {
4372
+ ...widget,
4373
+ 'widget-item': processWidget(widget['widget-item']),
4374
+ };
4375
+ }
4376
+ // Process table columns
4377
+ if (widget['widget-data-columns'] && Array.isArray(widget['widget-data-columns'])) {
4378
+ widget = {
4379
+ ...widget,
4380
+ 'widget-data-columns': widget['widget-data-columns'].map((col) => {
4381
+ if (col && typeof col === 'object' && col.widget && !col['widget-type']) {
4382
+ const widgetTypeMap = {
4383
+ 'text': 'input',
4384
+ 'number': 'input',
4385
+ 'date': 'input',
4386
+ 'select': 'input',
4387
+ 'boolean': 'input',
4388
+ };
4389
+ return {
4390
+ ...col,
4391
+ 'widget-type': widgetTypeMap[col.widget] || 'input',
4392
+ };
4393
+ }
4394
+ return col;
4395
+ }),
4396
+ };
4397
+ }
4398
+ return widget;
4399
+ };
4400
+ const processPanel = (panel) => {
4401
+ if (!panel || typeof panel !== 'object')
4402
+ return panel;
4403
+ let processed = { ...panel };
4404
+ // Process widgets in panel
4405
+ if (processed.widgets && Array.isArray(processed.widgets)) {
4406
+ processed.widgets = processed.widgets.map(processWidget);
4407
+ }
4408
+ // Process nested panels
4409
+ if (processed.panels && Array.isArray(processed.panels)) {
4410
+ processed.panels = processed.panels.map(processPanel);
4411
+ }
4412
+ return processed;
4413
+ };
4414
+ // Process section
4415
+ if (data.panels && Array.isArray(data.panels)) {
4416
+ return {
4417
+ ...data,
4418
+ panels: data.panels.map(processPanel),
4419
+ };
4420
+ }
4421
+ return data;
4422
+ }, []);
4423
+ const handleJsonChange = React.useCallback((data) => {
4424
+ // json-edit-react may wrap the data in a "root" key - unwrap it if present
4425
+ let unwrappedData = data?.root ? data.root : data;
4426
+ // Auto-populate widget-type for widgets that don't have it
4427
+ unwrappedData = autoPopulateWidgetType(unwrappedData);
4428
+ setJsonData(unwrappedData);
4429
+ setRawJsonText(JSON.stringify(unwrappedData, null, 2));
4430
+ // Basic validation
4431
+ const errors = [];
4432
+ if (!unwrappedData['section-id']) {
4433
+ errors.push('section-id is required');
4434
+ }
4435
+ if (!unwrappedData.panels || !Array.isArray(unwrappedData.panels)) {
4436
+ errors.push('panels must be an array');
4437
+ }
4438
+ setValidationErrors(errors);
4439
+ // Only update if valid
4440
+ if (errors.length === 0) {
4441
+ onChange(unwrappedData);
4442
+ }
4443
+ }, [onChange, autoPopulateWidgetType]);
4444
+ const handleRawJsonChange = React.useCallback((text) => {
4445
+ setRawJsonText(text);
4446
+ try {
4447
+ const parsed = JSON.parse(text);
4448
+ const errors = [];
4449
+ if (!parsed['section-id']) {
4450
+ errors.push('section-id is required');
4451
+ }
4452
+ if (!parsed.panels || !Array.isArray(parsed.panels)) {
4453
+ errors.push('panels must be an array');
4454
+ }
4455
+ setValidationErrors(errors);
4456
+ // Auto-populate widget-type
4457
+ const processed = autoPopulateWidgetType(parsed);
4458
+ if (errors.length === 0) {
4459
+ setJsonData(processed);
4460
+ onChange(processed);
4461
+ }
4462
+ }
4463
+ catch (error) {
4464
+ setValidationErrors([`Invalid JSON: ${error instanceof Error ? error.message : 'Parse error'}`]);
4465
+ }
4466
+ }, [onChange, autoPopulateWidgetType]);
4467
+ const toggleRawJsonView = React.useCallback(() => {
4468
+ if (!rawJsonView) {
4469
+ // Switching to raw view - update text from current data
4470
+ setRawJsonText(JSON.stringify(jsonData, null, 2));
4471
+ }
4472
+ setRawJsonView(!rawJsonView);
4473
+ }, [rawJsonView, jsonData]);
4474
+ // Create enum configuration for json-edit-react
4475
+ // This maps field paths to their allowed enum values
4476
+ const enumConfig = React.useCallback(() => {
4477
+ return {
4478
+ // Section level
4479
+ 'section-id': undefined, // string, no enum
4480
+ 'section-title': undefined, // string, no enum
4481
+ 'section-editable': undefined, // boolean, no enum
4482
+ 'section-column-span': undefined, // number, no enum
4483
+ // Panel level - can be nested in panels array
4484
+ 'panel-id': undefined, // string, no enum
4485
+ 'panel-orientation': ORIENTATIONS, // enum: ['horizontal', 'vertical']
4486
+ 'panel-column-span': undefined, // number, no enum
4487
+ // Widget level - can be nested in widgets array or widget-item
4488
+ 'widget': WIDGET_TYPES, // enum: all widget types
4489
+ 'widget-type': ['input', 'layout', 'table', 'group'], // enum
4490
+ 'widget-id': undefined, // string, no enum
4491
+ 'widget-label': undefined, // string, no enum
4492
+ 'widget-orientation': ORIENTATIONS, // enum: ['horizontal', 'vertical']
4493
+ 'widget-required': undefined, // boolean, no enum
4494
+ 'widget-readonly': undefined, // boolean, no enum
4495
+ // Widget data source type
4496
+ 'widget-data-source.type': DATA_SOURCE_TYPES, // enum: ['static', 'api', 'schema']
4497
+ 'widget-data-source.method': ['GET', 'POST', 'PUT', 'DELETE'], // HTTP methods
4498
+ // Widget validation
4499
+ 'widget-data-validation.validationType': VALIDATION_TYPES, // enum: ['email', 'phone', 'url']
4500
+ // Widget format options
4501
+ 'widget-data-format.inputType': ['text', 'email', 'password', 'number', 'tel', 'url', 'search', 'file'],
4502
+ 'widget-data-format.characterType': CHARACTER_TYPES,
4503
+ 'widget-data-format.caseControl': CASE_CONTROLS,
4504
+ 'widget-data-format.numericType': NUMERIC_TYPES,
4505
+ 'widget-data-format.roundingMode': ['round', 'truncate'],
4506
+ 'widget-data-format.textAlign': ['left', 'right'],
4507
+ 'widget-data-format.booleanRepresentation': BOOLEAN_REPRESENTATIONS,
4508
+ 'widget-data-format.booleanControlType': BOOLEAN_CONTROL_TYPES,
4509
+ 'widget-data-format.layout': ['vertical', 'horizontal', 'grid'],
4510
+ 'widget-data-format.inputMethod': ['picker', 'manual', 'hybrid'],
4511
+ 'widget-data-format.dateConstraint': ['any', 'past-only', 'future-only'],
4512
+ 'widget-data-format.dateTimeConstraint': ['any', 'past-only', 'future-only'],
4513
+ // Widget options
4514
+ 'widget-data-options.action': ['show', 'hide', 'enable', 'disable'],
4515
+ 'widget-data-options.condition.operator': CONDITION_OPERATORS,
4516
+ };
4517
+ }, []);
4518
+ return (jsxRuntimeExports.jsxs("div", { style: {
4519
+ display: 'flex',
4520
+ flexDirection: 'column',
4521
+ height: '100%',
4522
+ width: '100%',
4523
+ minHeight: 0,
4524
+ borderRight: '0px',
4525
+ }, children: [jsxRuntimeExports.jsxs("div", { style: {
4526
+ padding: '15px 20px',
4527
+ background: '#ffffff',
4528
+ display: 'flex',
4529
+ justifyContent: 'space-between',
4530
+ alignItems: 'center',
4531
+ }, children: [jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: [jsxRuntimeExports.jsx("div", { style: { fontWeight: 600, fontSize: '16px', color: '#2c3e50' }, children: "JSON Editor" }), validationErrors.length === 0 ? (jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '6px', color: '#28a745' }, children: [jsxRuntimeExports.jsx("div", { style: {
4532
+ width: '12px',
4533
+ height: '12px',
4534
+ borderRadius: '50%',
4535
+ background: '#28a745',
4536
+ } }), jsxRuntimeExports.jsx("span", { style: { fontSize: '12px' }, children: "Valid JSON Schema" })] })) : (jsxRuntimeExports.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '6px', color: '#e74c3c' }, children: [jsxRuntimeExports.jsx("div", { style: {
4537
+ width: '12px',
4538
+ height: '12px',
4539
+ borderRadius: '50%',
4540
+ background: '#e74c3c',
4541
+ } }), jsxRuntimeExports.jsx("span", { style: { fontSize: '12px' }, children: "Validation Errors" })] }))] }), jsxRuntimeExports.jsxs("div", { style: {
4542
+ display: 'flex',
4543
+ alignItems: 'center',
4544
+ gap: '8px',
4545
+ }, children: [jsxRuntimeExports.jsxs("button", { onClick: handleReset, style: {
4546
+ padding: '6px 12px',
4547
+ border: '1px solid #ddd',
4548
+ borderRadius: '4px',
4549
+ background: 'white',
4550
+ color: '#666',
4551
+ cursor: 'pointer',
4552
+ display: 'flex',
4553
+ alignItems: 'center',
4554
+ gap: '6px',
4555
+ fontSize: '12px',
4556
+ fontWeight: 500,
4557
+ transition: 'all 0.2s',
4558
+ }, onMouseEnter: (e) => {
4559
+ e.currentTarget.style.background = '#f8f9fa';
4560
+ e.currentTarget.style.borderColor = '#999';
4561
+ }, onMouseLeave: (e) => {
4562
+ e.currentTarget.style.background = 'white';
4563
+ e.currentTarget.style.borderColor = '#ddd';
4564
+ }, title: "Reset to original JSON", children: [jsxRuntimeExports.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntimeExports.jsx("path", { d: "M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" }), jsxRuntimeExports.jsx("path", { d: "M21 3v5h-5" }), jsxRuntimeExports.jsx("path", { d: "M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" }), jsxRuntimeExports.jsx("path", { d: "M3 21v-5h5" })] }), "Reset"] }), jsxRuntimeExports.jsxs("button", { onClick: () => setShowPreview(true), style: {
4565
+ padding: '6px 12px',
4566
+ border: '1px solid #ddd',
4567
+ borderRadius: '4px',
4568
+ background: 'white',
4569
+ color: '#666',
4570
+ cursor: 'pointer',
4571
+ display: 'flex',
4572
+ alignItems: 'center',
4573
+ gap: '6px',
4574
+ fontSize: '12px',
4575
+ fontWeight: 500,
4576
+ }, title: "Preview Section", children: [jsxRuntimeExports.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntimeExports.jsx("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }), jsxRuntimeExports.jsx("circle", { cx: "12", cy: "12", r: "3" })] }), "Preview"] }), jsxRuntimeExports.jsx("span", { style: {
4577
+ fontSize: '12px',
4578
+ color: !rawJsonView ? '#007bff' : '#6c757d',
4579
+ fontWeight: !rawJsonView ? 600 : 400,
4580
+ transition: 'color 0.2s',
4581
+ }, children: "Tree" }), jsxRuntimeExports.jsx("div", { onClick: toggleRawJsonView, style: {
4582
+ position: 'relative',
4583
+ width: '44px',
4584
+ height: '24px',
4585
+ background: rawJsonView ? '#007bff' : '#ccc',
4586
+ borderRadius: '12px',
4587
+ cursor: 'pointer',
4588
+ transition: 'background 0.2s',
4589
+ }, children: jsxRuntimeExports.jsx("div", { style: {
4590
+ position: 'absolute',
4591
+ top: '2px',
4592
+ left: rawJsonView ? '22px' : '2px',
4593
+ width: '20px',
4594
+ height: '20px',
4595
+ background: 'white',
4596
+ borderRadius: '50%',
4597
+ transition: 'left 0.2s',
4598
+ boxShadow: '0 2px 4px rgba(0,0,0,0.2)',
4599
+ } }) }), jsxRuntimeExports.jsx("span", { style: {
4600
+ fontSize: '12px',
4601
+ color: rawJsonView ? '#007bff' : '#6c757d',
4602
+ fontWeight: rawJsonView ? 600 : 400,
4603
+ transition: 'color 0.2s',
4604
+ }, children: "Raw" })] })] }), jsxRuntimeExports.jsx("div", { style: {
4605
+ flex: 1,
4606
+ minHeight: 0,
4607
+ maxHeight: '100%',
4608
+ overflow: 'hidden',
4609
+ background: 'white',
4610
+ border: '1px solid #E1E1E1',
4611
+ borderRadius: '10px',
4612
+ padding: rawJsonView ? '0' : '20px',
4613
+ position: 'relative',
4614
+ display: 'flex',
4615
+ flexDirection: 'column',
4616
+ }, children: rawJsonView ? (jsxRuntimeExports.jsx("textarea", { value: rawJsonText, onChange: (e) => handleRawJsonChange(e.target.value), style: {
4617
+ width: '100%',
4618
+ height: '100%',
4619
+ background: 'white',
4620
+ color: '#333',
4621
+ border: 'none',
4622
+ padding: '20px',
4623
+ fontFamily: 'Monaco, Menlo, "Ubuntu Mono", Consolas, "source-code-pro", monospace',
4624
+ fontSize: '13px',
4625
+ lineHeight: '1.5',
4626
+ resize: 'none',
4627
+ outline: 'none',
4628
+ boxSizing: 'border-box',
4629
+ borderRadius: '10px',
4630
+ }, spellCheck: false })) : (jsxRuntimeExports.jsx("div", { className: "json-editor-scroll-container", style: {
4631
+ width: '100%',
4632
+ height: '100%',
4633
+ minHeight: 0,
4634
+ maxHeight: '100%',
4635
+ overflow: 'auto',
4636
+ position: 'relative',
4637
+ display: 'flex',
4638
+ flexDirection: 'column',
4639
+ flex: '1 1 0',
4640
+ }, children: jsxRuntimeExports.jsx(jsonEditReact.JsonEditor, { data: jsonData, setData: handleJsonChange, ...{ enumOptions: enumConfig() } }, `editor-${editorKey}`) })) }), showPreview && reactDom.createPortal(jsxRuntimeExports.jsx("div", { className: "section-builder-preview-backdrop", style: {
4641
+ position: 'fixed',
4642
+ top: 0,
4643
+ left: 0,
4644
+ right: 0,
4645
+ bottom: 0,
4646
+ background: 'rgba(0, 0, 0, 0.5)',
4647
+ zIndex: 10000,
4648
+ display: 'flex',
4649
+ alignItems: 'center',
4650
+ justifyContent: 'center',
4651
+ padding: '20px',
4652
+ }, onClick: () => setShowPreview(false), children: jsxRuntimeExports.jsxs("div", { className: "section-builder-preview-modal", style: {
4653
+ background: 'white',
4654
+ borderRadius: '8px',
4655
+ width: '100%',
4656
+ minWidth: '700px', // Ensure enough width for 600px content + padding
4657
+ maxWidth: '90vw',
4658
+ height: '90vh',
4659
+ maxHeight: '90vh',
4660
+ display: 'flex',
4661
+ flexDirection: 'column',
4662
+ boxShadow: '0 4px 20px rgba(0, 0, 0, 0.3)',
4663
+ }, onClick: (e) => e.stopPropagation(), children: [jsxRuntimeExports.jsxs("div", { className: "section-builder-preview-header", style: {
4664
+ padding: '15px 20px',
4665
+ borderBottom: '1px solid #ddd',
4666
+ display: 'flex',
4667
+ justifyContent: 'space-between',
4668
+ alignItems: 'center',
4669
+ background: '#f8f9fa',
4670
+ }, children: [jsxRuntimeExports.jsx("h2", { className: "section-builder-preview-title", style: { margin: 0, fontSize: '18px', fontWeight: 600, color: '#2c3e50' }, children: "Section Preview" }), jsxRuntimeExports.jsx("button", { className: "section-builder-preview-close", onClick: () => setShowPreview(false), style: {
4671
+ padding: '6px 12px',
4672
+ border: 'none',
4673
+ borderRadius: '4px',
4674
+ background: '#e74c3c',
4675
+ color: 'white',
4676
+ cursor: 'pointer',
4677
+ fontSize: '14px',
4678
+ fontWeight: 600,
4679
+ }, children: "Close" })] }), jsxRuntimeExports.jsx("div", { className: "section-builder-preview-content", style: {
4680
+ flex: 1,
4681
+ overflow: 'auto',
4682
+ padding: '20px',
4683
+ }, children: jsxRuntimeExports.jsx(reactRedux.Provider, { store: previewStore, children: jsxRuntimeExports.jsx(WidgetProvider, { store: previewStore, dataSourceRequestHandler: widgetContext.dataSourceRequestHandler, schemaData: widgetContext.schemaData, translate: widgetContext.translate, children: jsxRuntimeExports.jsx("div", { style: { position: 'relative', width: '100%', height: '100%' }, children: jsxRuntimeExports.jsx(SectionRenderer, { section: makeSectionEditable(jsonData), hideEditButton: true, onValueChange: (widgetId, value) => {
4684
+ // Handle value changes in preview (optional - for tracking)
4685
+ console.log('Preview value changed:', widgetId, value);
4686
+ } }) }) }) }) })] }) }), document.body)] }));
4687
+ };
4688
+
4689
+ /**
4690
+ * Recursively build tree nodes from panel structure
4691
+ */
4692
+ function buildTreeNodesFromPanels(panels, parent) {
4693
+ const nodes = [];
4694
+ panels.forEach((panel) => {
4695
+ const panelNode = {
4696
+ type: 'panel',
4697
+ id: panel['panel-id'],
4698
+ label: `Panel: ${panel['panel-id']}`,
4699
+ data: panel,
4700
+ parent: parent,
4701
+ children: [],
4702
+ };
4703
+ // Add nested panels recursively
4704
+ if (panel.panels && panel.panels.length > 0) {
4705
+ panelNode.children = panelNode.children || [];
4706
+ panelNode.children.push(...buildTreeNodesFromPanels(panel.panels, panelNode));
4707
+ }
4708
+ // Add widgets
4709
+ if (panel.widgets && panel.widgets.length > 0) {
4710
+ panelNode.children = panelNode.children || [];
4711
+ panel.widgets.forEach((widget) => {
4712
+ panelNode.children.push({
4713
+ type: 'widget',
4714
+ id: widget['widget-id'],
4715
+ label: `Widget: ${widget['widget-id']} (${widget.widget})`,
4716
+ data: widget,
4717
+ parent: panelNode,
4718
+ });
4719
+ });
4720
+ }
4721
+ nodes.push(panelNode);
4722
+ });
4723
+ return nodes;
4724
+ }
4725
+ /**
4726
+ * Tree view component for section structure
4727
+ */
4728
+ const SectionTree = ({ section, selectedNode, onSelectNode, onAddPanel, onAddWidget, onDeleteNode, onDuplicateNode, }) => {
4729
+ const treeNodes = React.useMemo(() => {
4730
+ if (section.panels && section.panels.length > 0) {
4731
+ return buildTreeNodesFromPanels(section.panels);
4732
+ }
4733
+ return [];
4734
+ }, [section]);
4735
+ const renderTreeNode = (node, level = 0) => {
4736
+ const isSelected = selectedNode?.id === node.id && selectedNode?.type === node.type;
4737
+ const indent = level * 20;
4738
+ const getNodeStyles = () => {
4739
+ const baseStyles = {
4740
+ marginLeft: `${indent}px`,
4741
+ marginTop: '4px',
4742
+ padding: '8px 12px',
4743
+ borderRadius: '4px',
4744
+ cursor: 'pointer',
4745
+ position: 'relative',
4746
+ transition: 'background 0.2s',
4747
+ display: 'flex',
4748
+ alignItems: 'center',
4749
+ justifyContent: 'space-between',
4750
+ };
4751
+ if (isSelected) {
4752
+ switch (node.type) {
4753
+ case 'section':
4754
+ return { ...baseStyles, background: '#e3f2fd', border: '1px solid #2196f3' };
4755
+ case 'panel':
4756
+ return { ...baseStyles, background: '#fff3e0', border: '1px solid #ff9800' };
4757
+ case 'widget':
4758
+ return { ...baseStyles, background: '#e8f5e9', border: '1px solid #4caf50' };
4759
+ }
4760
+ }
4761
+ switch (node.type) {
4762
+ case 'section':
4763
+ return { ...baseStyles, background: '#e3f2fd', border: '1px solid #2196f3' };
4764
+ case 'panel':
4765
+ return { ...baseStyles, background: '#fff3e0', border: '1px solid #ff9800' };
4766
+ case 'widget':
4767
+ return { ...baseStyles, background: '#e8f5e9', border: '1px solid #4caf50' };
4768
+ }
4769
+ return baseStyles;
4770
+ };
4771
+ const getIcon = () => {
4772
+ switch (node.type) {
4773
+ case 'section':
4774
+ return '📁';
4775
+ case 'panel':
4776
+ return '📦';
4777
+ case 'widget':
4778
+ return '🔧';
4779
+ }
4780
+ };
4781
+ const getActionButtonColor = () => {
4782
+ switch (node.type) {
4783
+ case 'section':
4784
+ return '#2196f3';
4785
+ case 'panel':
4786
+ return '#ff9800';
4787
+ case 'widget':
4788
+ return '#4caf50';
4789
+ }
4790
+ };
4791
+ return (jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsxs("div", { style: getNodeStyles(), onClick: (e) => {
4792
+ e.stopPropagation();
4793
+ onSelectNode(node);
4794
+ }, onMouseEnter: (e) => {
4795
+ const target = e.currentTarget;
4796
+ const actionBtn = target.querySelector('.tree-action-btn');
4797
+ if (actionBtn)
4798
+ actionBtn.style.opacity = '1';
4799
+ }, onMouseLeave: (e) => {
4800
+ const target = e.currentTarget;
4801
+ const actionBtn = target.querySelector('.tree-action-btn');
4802
+ if (actionBtn)
4803
+ actionBtn.style.opacity = '0';
4804
+ }, children: [jsxRuntimeExports.jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: '8px' }, children: [jsxRuntimeExports.jsx("span", { children: getIcon() }), jsxRuntimeExports.jsx("span", { style: { fontSize: '13px' }, children: node.label })] }), jsxRuntimeExports.jsx("button", { className: "tree-action-btn", onClick: (e) => {
4805
+ e.stopPropagation();
4806
+ onSelectNode(node);
4807
+ }, style: {
4808
+ width: '24px',
4809
+ height: '24px',
4810
+ borderRadius: '50%',
4811
+ border: 'none',
4812
+ background: getActionButtonColor(),
4813
+ color: 'white',
4814
+ cursor: 'pointer',
4815
+ fontSize: '12px',
4816
+ opacity: isSelected ? '1' : '0',
4817
+ transition: 'opacity 0.2s',
4818
+ display: 'flex',
4819
+ alignItems: 'center',
4820
+ justifyContent: 'center',
4821
+ }, children: "\u2699" })] }), node.children && node.children.length > 0 && (jsxRuntimeExports.jsx("div", { style: { marginLeft: `${indent + 20}px` }, children: node.children.map((child) => renderTreeNode(child, level + 1)) }))] }, node.id));
4822
+ };
4823
+ return (jsxRuntimeExports.jsxs("div", { style: {
4824
+ padding: '15px',
4825
+ overflowY: 'auto',
4826
+ background: '#f8f9fa',
4827
+ height: '100%',
4828
+ }, children: [jsxRuntimeExports.jsx("h3", { style: { fontSize: '14px', marginBottom: '15px', color: '#2c3e50' }, children: "Section Structure" }), jsxRuntimeExports.jsxs("div", { style: {
4829
+ padding: '8px 12px',
4830
+ borderRadius: '4px',
4831
+ background: '#e3f2fd',
4832
+ border: '1px solid #2196f3',
4833
+ marginBottom: '10px',
4834
+ cursor: 'pointer',
4835
+ display: 'flex',
4836
+ alignItems: 'center',
4837
+ justifyContent: 'space-between',
4838
+ }, onClick: () => {
4839
+ const sectionNode = {
4840
+ type: 'section',
4841
+ id: section['section-id'],
4842
+ label: `Section: ${section['section-id']}`,
4843
+ data: section,
4844
+ children: treeNodes,
4845
+ };
4846
+ onSelectNode(sectionNode);
4847
+ }, children: [jsxRuntimeExports.jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: '8px' }, children: [jsxRuntimeExports.jsx("span", { children: "\uD83D\uDCC1" }), jsxRuntimeExports.jsxs("span", { style: { fontSize: '13px', fontWeight: 600 }, children: ["Section: ", section['section-id']] })] }), jsxRuntimeExports.jsx("button", { onClick: (e) => {
4848
+ e.stopPropagation();
4849
+ const sectionNode = {
4850
+ type: 'section',
4851
+ id: section['section-id'],
4852
+ label: `Section: ${section['section-id']}`,
4853
+ data: section,
4854
+ children: treeNodes,
4855
+ };
4856
+ onSelectNode(sectionNode);
4857
+ }, style: {
4858
+ width: '24px',
4859
+ height: '24px',
4860
+ borderRadius: '50%',
4861
+ border: 'none',
4862
+ background: '#2196f3',
4863
+ color: 'white',
4864
+ cursor: 'pointer',
4865
+ fontSize: '12px',
4866
+ }, children: "\u2699" })] }), treeNodes.map((node) => renderTreeNode(node, 0))] }));
4867
+ };
4868
+
4869
+ /**
4870
+ * Property editor component for editing selected node properties
4871
+ */
4872
+ const PropertyEditor = ({ node, onChange, onDelete, onDuplicate, }) => {
4873
+ const [localData, setLocalData] = React.useState(null);
4874
+ React.useEffect(() => {
4875
+ if (node) {
4876
+ setLocalData({ ...node.data });
4877
+ }
4878
+ }, [node]);
4879
+ if (!node || !localData) {
4880
+ return (jsxRuntimeExports.jsx("div", { style: {
4881
+ padding: '15px',
4882
+ background: '#f8f9fa',
4883
+ height: '100%',
4884
+ display: 'flex',
4885
+ alignItems: 'center',
4886
+ justifyContent: 'center',
4887
+ color: '#666',
4888
+ }, children: "Select an item to edit properties" }));
4889
+ }
4890
+ const handleChange = (field, value) => {
4891
+ const updated = { ...localData, [field]: value };
4892
+ setLocalData(updated);
4893
+ onChange(node, updated);
4894
+ };
4895
+ const handleNestedChange = (field, nestedField, value) => {
4896
+ const updated = {
4897
+ ...localData,
4898
+ [field]: {
4899
+ ...(localData[field] || {}),
4900
+ [nestedField]: value,
4901
+ },
4902
+ };
4903
+ setLocalData(updated);
4904
+ onChange(node, updated);
4905
+ };
4906
+ const ensureNestedObject = (field) => {
4907
+ if (!localData[field]) {
4908
+ const updated = {
4909
+ ...localData,
4910
+ [field]: {},
4911
+ };
4912
+ setLocalData(updated);
4913
+ onChange(node, updated);
4914
+ }
4915
+ };
4916
+ const renderSectionProperties = () => {
4917
+ const section = localData;
4918
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsxs("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: ["Section ID ", jsxRuntimeExports.jsx("span", { style: { color: '#e74c3c' }, children: "*" })] }), jsxRuntimeExports.jsx("input", { type: "text", value: section['section-id'] || '', onChange: (e) => handleChange('section-id', e.target.value), style: {
4919
+ width: '100%',
4920
+ padding: '8px 12px',
4921
+ border: '1px solid #ccc',
4922
+ borderRadius: '4px',
4923
+ fontSize: '12px',
4924
+ } })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Section Title" }), jsxRuntimeExports.jsx("input", { type: "text", value: section['section-title'] || '', onChange: (e) => handleChange('section-title', e.target.value), style: {
4925
+ width: '100%',
4926
+ padding: '8px 12px',
4927
+ border: '1px solid #ccc',
4928
+ borderRadius: '4px',
4929
+ fontSize: '12px',
4930
+ } })] }), jsxRuntimeExports.jsx("div", { style: { marginBottom: '20px' }, children: jsxRuntimeExports.jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' }, children: [jsxRuntimeExports.jsx("input", { type: "checkbox", checked: section['section-editable'] || false, onChange: (e) => handleChange('section-editable', e.target.checked) }), jsxRuntimeExports.jsx("span", { children: "Editable" })] }) }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Column Span" }), jsxRuntimeExports.jsx("input", { type: "number", value: section['section-column-span'] || 1, onChange: (e) => handleChange('section-column-span', parseInt(e.target.value) || 1), min: "1", style: {
4931
+ width: '100%',
4932
+ padding: '8px 12px',
4933
+ border: '1px solid #ccc',
4934
+ borderRadius: '4px',
4935
+ fontSize: '12px',
4936
+ } })] })] }));
4937
+ };
4938
+ const renderPanelProperties = () => {
4939
+ const panel = localData;
4940
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsxs("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: ["Panel ID ", jsxRuntimeExports.jsx("span", { style: { color: '#e74c3c' }, children: "*" })] }), jsxRuntimeExports.jsx("input", { type: "text", value: panel['panel-id'] || '', onChange: (e) => handleChange('panel-id', e.target.value), style: {
4941
+ width: '100%',
4942
+ padding: '8px 12px',
4943
+ border: '1px solid #ccc',
4944
+ borderRadius: '4px',
4945
+ fontSize: '12px',
4946
+ } })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Orientation" }), jsxRuntimeExports.jsx("select", { value: panel['panel-orientation'] || 'vertical', onChange: (e) => handleChange('panel-orientation', e.target.value), style: {
4947
+ width: '100%',
4948
+ padding: '8px 12px',
4949
+ border: '1px solid #ccc',
4950
+ borderRadius: '4px',
4951
+ fontSize: '12px',
4952
+ background: 'white',
4953
+ }, children: ORIENTATIONS.map((opt) => (jsxRuntimeExports.jsx("option", { value: opt, children: opt }, opt))) })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Column Span" }), jsxRuntimeExports.jsx("input", { type: "number", value: panel['panel-column-span'] || 1, onChange: (e) => handleChange('panel-column-span', parseInt(e.target.value) || 1), min: "1", style: {
4954
+ width: '100%',
4955
+ padding: '8px 12px',
4956
+ border: '1px solid #ccc',
4957
+ borderRadius: '4px',
4958
+ fontSize: '12px',
4959
+ } })] })] }));
4960
+ };
4961
+ const renderWidgetProperties = () => {
4962
+ const widget = localData;
4963
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsxs("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: ["Widget Type ", jsxRuntimeExports.jsx("span", { style: { color: '#e74c3c' }, children: "*" })] }), jsxRuntimeExports.jsx("select", { value: widget.widget || '', onChange: (e) => {
4964
+ const newWidgetType = e.target.value;
4965
+ // When widget type changes, preserve common fields but clear widget-specific ones
4966
+ const updated = {
4967
+ ...widget,
4968
+ widget: newWidgetType,
4969
+ };
4970
+ // Clear widget-specific fields that don't apply to the new type
4971
+ if (!['select', 'radio', 'checkbox'].includes(newWidgetType)) {
4972
+ delete updated['widget-data-source'];
4973
+ }
4974
+ if (newWidgetType !== 'table') {
4975
+ delete updated['widget-data-columns'];
4976
+ }
4977
+ setLocalData(updated);
4978
+ onChange(node, updated);
4979
+ }, style: {
4980
+ width: '100%',
4981
+ padding: '8px 12px',
4982
+ border: '1px solid #ccc',
4983
+ borderRadius: '4px',
4984
+ fontSize: '12px',
4985
+ background: 'white',
4986
+ }, children: WIDGET_TYPES.map((type) => (jsxRuntimeExports.jsx("option", { value: type, children: type }, type))) })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsxs("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: ["Widget ID ", jsxRuntimeExports.jsx("span", { style: { color: '#e74c3c' }, children: "*" })] }), jsxRuntimeExports.jsx("input", { type: "text", value: widget['widget-id'] || '', onChange: (e) => handleChange('widget-id', e.target.value), style: {
4987
+ width: '100%',
4988
+ padding: '8px 12px',
4989
+ border: '1px solid #ccc',
4990
+ borderRadius: '4px',
4991
+ fontSize: '12px',
4992
+ } })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Widget Label" }), jsxRuntimeExports.jsx("input", { type: "text", value: widget['widget-label'] || '', onChange: (e) => handleChange('widget-label', e.target.value), style: {
4993
+ width: '100%',
4994
+ padding: '8px 12px',
4995
+ border: '1px solid #ccc',
4996
+ borderRadius: '4px',
4997
+ fontSize: '12px',
4998
+ }, placeholder: "Enter label..." })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Data Path" }), jsxRuntimeExports.jsx("input", { type: "text", value: typeof widget['widget-data-path'] === 'string' ? widget['widget-data-path'] : '', onChange: (e) => handleChange('widget-data-path', e.target.value), style: {
4999
+ width: '100%',
5000
+ padding: '8px 12px',
5001
+ border: '1px solid #ccc',
5002
+ borderRadius: '4px',
5003
+ fontSize: '12px',
5004
+ }, placeholder: "person.name" })] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '12px', fontWeight: 500 }, children: "Placeholder" }), jsxRuntimeExports.jsx("input", { type: "text", value: widget['widget-data-placeholder'] || '', onChange: (e) => handleChange('widget-data-placeholder', e.target.value), style: {
5005
+ width: '100%',
5006
+ padding: '8px 12px',
5007
+ border: '1px solid #ccc',
5008
+ borderRadius: '4px',
5009
+ fontSize: '12px',
5010
+ }, placeholder: "Enter placeholder..." })] }), jsxRuntimeExports.jsx("div", { style: { marginBottom: '20px' }, children: jsxRuntimeExports.jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' }, children: [jsxRuntimeExports.jsx("input", { type: "checkbox", checked: widget['widget-required'] || false, onChange: (e) => handleChange('widget-required', e.target.checked) }), jsxRuntimeExports.jsx("span", { children: "Required" })] }) }), jsxRuntimeExports.jsx("div", { style: { marginBottom: '20px' }, children: jsxRuntimeExports.jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' }, children: [jsxRuntimeExports.jsx("input", { type: "checkbox", checked: widget['widget-readonly'] || false, onChange: (e) => handleChange('widget-readonly', e.target.checked) }), jsxRuntimeExports.jsx("span", { children: "Readonly" })] }) }), ['select', 'radio', 'checkbox'].includes(widget.widget) && (jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px', padding: '10px', background: '#e3f2fd', borderRadius: '4px' }, children: [jsxRuntimeExports.jsxs("label", { style: { display: 'block', marginBottom: '8px', fontSize: '12px', fontWeight: 600 }, children: ["Data Source (Required for ", widget.widget, ")"] }), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '10px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Source Type" }), jsxRuntimeExports.jsxs("select", { value: widget['widget-data-source']?.type || 'static', onChange: (e) => {
5011
+ ensureNestedObject('widget-data-source');
5012
+ handleNestedChange('widget-data-source', 'type', e.target.value);
5013
+ }, style: {
5014
+ width: '100%',
5015
+ padding: '6px 8px',
5016
+ border: '1px solid #ccc',
5017
+ borderRadius: '4px',
5018
+ fontSize: '11px',
5019
+ background: 'white',
5020
+ }, children: [jsxRuntimeExports.jsx("option", { value: "static", children: "Static" }), jsxRuntimeExports.jsx("option", { value: "api", children: "API" }), jsxRuntimeExports.jsx("option", { value: "schema", children: "Schema" })] })] }), widget['widget-data-source']?.type === 'static' && (jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Options (JSON array format: see placeholder below)" }), jsxRuntimeExports.jsx("textarea", { value: JSON.stringify(widget['widget-data-source']?.options || [], null, 2), onChange: (e) => {
5021
+ try {
5022
+ const parsed = JSON.parse(e.target.value);
5023
+ handleNestedChange('widget-data-source', 'options', parsed);
5024
+ }
5025
+ catch {
5026
+ // Invalid JSON, ignore
5027
+ }
5028
+ }, style: {
5029
+ width: '100%',
5030
+ padding: '6px 8px',
5031
+ border: '1px solid #ccc',
5032
+ borderRadius: '4px',
5033
+ fontSize: '11px',
5034
+ fontFamily: 'monospace',
5035
+ minHeight: '80px',
5036
+ }, placeholder: '[{"value": "opt1", "label": "Option 1"}]' })] })), widget['widget-data-source']?.type === 'api' && (() => {
5037
+ const apiSource = widget['widget-data-source'];
5038
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { style: { marginBottom: '10px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "API URL" }), jsxRuntimeExports.jsx("input", { type: "text", value: apiSource.url || '', onChange: (e) => handleNestedChange('widget-data-source', 'url', e.target.value), style: {
5039
+ width: '100%',
5040
+ padding: '6px 8px',
5041
+ border: '1px solid #ccc',
5042
+ borderRadius: '4px',
5043
+ fontSize: '11px',
5044
+ }, placeholder: "https://api.example.com/options" })] }), jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Value/Label Keys (e.g., \"id\"/\"name\")" }), jsxRuntimeExports.jsxs("div", { style: { display: 'flex', gap: '8px' }, children: [jsxRuntimeExports.jsx("input", { type: "text", value: apiSource.valueKey || '', onChange: (e) => handleNestedChange('widget-data-source', 'valueKey', e.target.value), style: {
5045
+ flex: 1,
5046
+ padding: '6px 8px',
5047
+ border: '1px solid #ccc',
5048
+ borderRadius: '4px',
5049
+ fontSize: '11px',
5050
+ }, placeholder: "value key" }), jsxRuntimeExports.jsx("input", { type: "text", value: apiSource.labelKey || '', onChange: (e) => handleNestedChange('widget-data-source', 'labelKey', e.target.value), style: {
5051
+ flex: 1,
5052
+ padding: '6px 8px',
5053
+ border: '1px solid #ccc',
5054
+ borderRadius: '4px',
5055
+ fontSize: '11px',
5056
+ }, placeholder: "label key" })] })] })] }));
5057
+ })()] })), widget.widget === 'table' && (jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px', padding: '10px', background: '#fff3e0', borderRadius: '4px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '8px', fontSize: '12px', fontWeight: 600 }, children: "Table Columns" }), jsxRuntimeExports.jsx("div", { style: { fontSize: '11px', color: '#666', marginBottom: '10px' }, children: "Configure columns in JSON editor or add via code" }), jsxRuntimeExports.jsx("textarea", { value: JSON.stringify(widget['widget-data-columns'] || [], null, 2), onChange: (e) => {
5058
+ try {
5059
+ const parsed = JSON.parse(e.target.value);
5060
+ handleChange('widget-data-columns', parsed);
5061
+ }
5062
+ catch {
5063
+ // Invalid JSON, ignore
5064
+ }
5065
+ }, style: {
5066
+ width: '100%',
5067
+ padding: '6px 8px',
5068
+ border: '1px solid #ccc',
5069
+ borderRadius: '4px',
5070
+ fontSize: '11px',
5071
+ fontFamily: 'monospace',
5072
+ minHeight: '100px',
5073
+ }, placeholder: '[{"column-key": "col1", "widget-label": "Column 1", "widget": "text"}]' })] })), widget.widget === 'number' && (jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px', padding: '10px', background: '#f3e5f5', borderRadius: '4px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '8px', fontSize: '12px', fontWeight: 600 }, children: "Number Validation" }), jsxRuntimeExports.jsxs("div", { style: { display: 'flex', gap: '10px', marginBottom: '10px' }, children: [jsxRuntimeExports.jsxs("div", { style: { flex: 1 }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Min Value" }), jsxRuntimeExports.jsx("input", { type: "number", value: widget['widget-data-validation']?.min ?? '', onChange: (e) => handleNestedChange('widget-data-validation', 'min', e.target.value ? parseFloat(e.target.value) : undefined), style: {
5074
+ width: '100%',
5075
+ padding: '6px 8px',
5076
+ border: '1px solid #ccc',
5077
+ borderRadius: '4px',
5078
+ fontSize: '11px',
5079
+ } })] }), jsxRuntimeExports.jsxs("div", { style: { flex: 1 }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Max Value" }), jsxRuntimeExports.jsx("input", { type: "number", value: widget['widget-data-validation']?.max ?? '', onChange: (e) => handleNestedChange('widget-data-validation', 'max', e.target.value ? parseFloat(e.target.value) : undefined), style: {
5080
+ width: '100%',
5081
+ padding: '6px 8px',
5082
+ border: '1px solid #ccc',
5083
+ borderRadius: '4px',
5084
+ fontSize: '11px',
5085
+ } })] })] })] })), ['date', 'datetime'].includes(widget.widget) && (jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px', padding: '10px', background: '#e8f5e9', borderRadius: '4px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '8px', fontSize: '12px', fontWeight: 600 }, children: "Date Range Options" }), jsxRuntimeExports.jsxs("div", { style: { display: 'flex', gap: '10px', marginBottom: '10px' }, children: [jsxRuntimeExports.jsxs("div", { style: { flex: 1 }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Min Date" }), jsxRuntimeExports.jsx("input", { type: "date", value: widget['widget-data-options']?.minDate || '', onChange: (e) => handleNestedChange('widget-data-options', 'minDate', e.target.value || undefined), style: {
5086
+ width: '100%',
5087
+ padding: '6px 8px',
5088
+ border: '1px solid #ccc',
5089
+ borderRadius: '4px',
5090
+ fontSize: '11px',
5091
+ } })] }), jsxRuntimeExports.jsxs("div", { style: { flex: 1 }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Max Date" }), jsxRuntimeExports.jsx("input", { type: "date", value: widget['widget-data-options']?.maxDate || '', onChange: (e) => handleNestedChange('widget-data-options', 'maxDate', e.target.value || undefined), style: {
5092
+ width: '100%',
5093
+ padding: '6px 8px',
5094
+ border: '1px solid #ccc',
5095
+ borderRadius: '4px',
5096
+ fontSize: '11px',
5097
+ } })] })] }), jsxRuntimeExports.jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '11px' }, children: [jsxRuntimeExports.jsx("input", { type: "checkbox", checked: widget['widget-data-options']?.showCalendar || false, onChange: (e) => handleNestedChange('widget-data-options', 'showCalendar', e.target.checked) }), jsxRuntimeExports.jsx("span", { children: "Show Calendar" })] })] })), jsxRuntimeExports.jsxs("div", { style: { marginBottom: '20px', padding: '10px', background: '#f0f0f0', borderRadius: '4px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '8px', fontSize: '12px', fontWeight: 600 }, children: "Validation" }), jsxRuntimeExports.jsx("div", { style: { marginBottom: '10px' }, children: jsxRuntimeExports.jsxs("label", { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' }, children: [jsxRuntimeExports.jsx("input", { type: "checkbox", checked: widget['widget-data-validation']?.required || false, onChange: (e) => {
5098
+ if (!widget['widget-data-validation']) {
5099
+ handleChange('widget-data-validation', { required: e.target.checked });
5100
+ }
5101
+ else {
5102
+ handleNestedChange('widget-data-validation', 'required', e.target.checked);
5103
+ }
5104
+ } }), jsxRuntimeExports.jsx("span", { children: "Required" })] }) }), ['text', 'textarea'].includes(widget.widget) && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { style: { marginBottom: '10px' }, children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Min Length" }), jsxRuntimeExports.jsx("input", { type: "number", value: widget['widget-data-validation']?.minLength || '', onChange: (e) => {
5105
+ const validation = widget['widget-data-validation'] || {};
5106
+ handleChange('widget-data-validation', {
5107
+ ...validation,
5108
+ minLength: e.target.value ? parseInt(e.target.value) : undefined,
5109
+ });
5110
+ }, style: {
5111
+ width: '100%',
5112
+ padding: '6px 8px',
5113
+ border: '1px solid #ccc',
5114
+ borderRadius: '4px',
5115
+ fontSize: '11px',
5116
+ } })] }), jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx("label", { style: { display: 'block', marginBottom: '5px', fontSize: '11px' }, children: "Max Length" }), jsxRuntimeExports.jsx("input", { type: "number", value: widget['widget-data-validation']?.maxLength || '', onChange: (e) => {
5117
+ const validation = widget['widget-data-validation'] || {};
5118
+ handleChange('widget-data-validation', {
5119
+ ...validation,
5120
+ maxLength: e.target.value ? parseInt(e.target.value) : undefined,
5121
+ });
5122
+ }, style: {
5123
+ width: '100%',
5124
+ padding: '6px 8px',
5125
+ border: '1px solid #ccc',
5126
+ borderRadius: '4px',
5127
+ fontSize: '11px',
5128
+ } })] })] }))] })] }));
5129
+ };
5130
+ const getHeaderColor = () => {
5131
+ switch (node.type) {
5132
+ case 'section':
5133
+ return '#2196f3';
5134
+ case 'panel':
5135
+ return '#ff9800';
5136
+ case 'widget':
5137
+ return '#4caf50';
5138
+ }
5139
+ };
5140
+ return (jsxRuntimeExports.jsxs("div", { style: {
5141
+ padding: '15px',
5142
+ overflowY: 'auto',
5143
+ background: '#f8f9fa',
5144
+ height: '100%',
5145
+ }, children: [jsxRuntimeExports.jsx("h3", { style: { fontSize: '14px', marginBottom: '15px', color: '#2c3e50' }, children: "Properties" }), jsxRuntimeExports.jsxs("div", { style: {
5146
+ background: getHeaderColor(),
5147
+ color: 'white',
5148
+ padding: '12px',
5149
+ borderRadius: '4px',
5150
+ marginBottom: '20px',
5151
+ fontWeight: 600,
5152
+ fontSize: '13px',
5153
+ }, children: [node.type === 'section' && `Section: ${node.data['section-id']}`, node.type === 'panel' && `Panel: ${node.data['panel-id']}`, node.type === 'widget' && `Widget: ${node.data['widget-id']}`] }), node.type === 'section' && renderSectionProperties(), node.type === 'panel' && renderPanelProperties(), node.type === 'widget' && renderWidgetProperties(), jsxRuntimeExports.jsxs("div", { style: { display: 'flex', gap: '10px', marginTop: '30px' }, children: [jsxRuntimeExports.jsx("button", { onClick: () => onDelete(node), style: {
5154
+ flex: 1,
5155
+ padding: '10px',
5156
+ border: 'none',
5157
+ borderRadius: '4px',
5158
+ background: '#f44336',
5159
+ color: 'white',
5160
+ fontWeight: 600,
5161
+ cursor: 'pointer',
5162
+ fontSize: '12px',
5163
+ }, children: "Delete" }), jsxRuntimeExports.jsx("button", { onClick: () => onDuplicate(node), style: {
5164
+ flex: 1,
5165
+ padding: '10px',
5166
+ border: 'none',
5167
+ borderRadius: '4px',
5168
+ background: '#ff9800',
5169
+ color: 'white',
5170
+ fontWeight: 600,
5171
+ cursor: 'pointer',
5172
+ fontSize: '12px',
5173
+ }, children: "Duplicate" })] })] }));
5174
+ };
5175
+
5176
+ /**
5177
+ * Visual Builder Panel - Right side of Section Builder
5178
+ */
5179
+ const VisualBuilderPanel = ({ section, selectedNode, onSelectNode, onSectionChange, onAddPanel, onAddWidget, onDeleteNode, onDuplicateNode, onSave, isMaximized = false, onToggleMaximize, }) => {
5180
+ // Validate section before saving
5181
+ const validateSection = (sectionToValidate) => {
5182
+ const errors = [];
5183
+ if (!sectionToValidate['section-id']) {
5184
+ errors.push('Section ID is required');
5185
+ }
5186
+ if (!sectionToValidate.panels || sectionToValidate.panels.length === 0) {
5187
+ errors.push('Section must have at least one panel');
5188
+ }
5189
+ // Validate panels
5190
+ const validatePanels = (panels) => {
5191
+ panels.forEach((panel, index) => {
5192
+ if (!panel['panel-id']) {
5193
+ errors.push(`Panel at index ${index} is missing panel-id`);
5194
+ }
5195
+ if (panel.panels) {
5196
+ validatePanels(panel.panels);
5197
+ }
5198
+ if (panel.widgets) {
5199
+ panel.widgets.forEach((widget, widgetIndex) => {
5200
+ if (!widget['widget-id']) {
5201
+ errors.push(`Widget at panel ${panel['panel-id'] || index}, index ${widgetIndex} is missing widget-id`);
5202
+ }
5203
+ if (!widget.widget) {
5204
+ errors.push(`Widget ${widget['widget-id'] || widgetIndex} is missing widget type`);
5205
+ }
5206
+ });
5207
+ }
5208
+ });
5209
+ };
5210
+ if (sectionToValidate.panels) {
5211
+ validatePanels(sectionToValidate.panels);
5212
+ }
5213
+ return {
5214
+ isValid: errors.length === 0,
5215
+ errors,
5216
+ };
5217
+ };
5218
+ const handleSave = () => {
5219
+ const validation = validateSection(section);
5220
+ if (!validation.isValid) {
5221
+ console.error('Section validation failed:', validation.errors);
5222
+ alert(`Cannot save section. Please fix the following errors:\n\n${validation.errors.join('\n')}`);
5223
+ return;
5224
+ }
5225
+ if (onSave) {
5226
+ try {
5227
+ onSave(section);
5228
+ }
5229
+ catch (error) {
5230
+ console.error('Error saving section:', error);
5231
+ alert('An error occurred while saving the section. Please check the console for details.');
5232
+ }
5233
+ }
5234
+ };
5235
+ const handleNodeChange = (node, updates) => {
5236
+ // Create a deep copy of the section
5237
+ const updatedSection = JSON.parse(JSON.stringify(section));
5238
+ // Find and update the node in the section structure
5239
+ const updateInSection = (current, targetId, targetType) => {
5240
+ if (targetType === 'section' && current['section-id'] === targetId) {
5241
+ Object.assign(current, updates);
5242
+ return true;
5243
+ }
5244
+ if (current.panels) {
5245
+ for (const panel of current.panels) {
5246
+ if (targetType === 'panel' && panel['panel-id'] === targetId) {
5247
+ Object.assign(panel, updates);
5248
+ return true;
5249
+ }
5250
+ if (updateInSection(panel, targetId, targetType)) {
5251
+ return true;
5252
+ }
5253
+ if (panel.widgets) {
5254
+ for (const widget of panel.widgets) {
5255
+ if (targetType === 'widget' && widget['widget-id'] === targetId) {
5256
+ Object.assign(widget, updates);
5257
+ return true;
5258
+ }
5259
+ }
5260
+ }
5261
+ }
5262
+ }
5263
+ if (current.widgets) {
5264
+ for (const widget of current.widgets) {
5265
+ if (targetType === 'widget' && widget['widget-id'] === targetId) {
5266
+ Object.assign(widget, updates);
5267
+ return true;
5268
+ }
5269
+ }
5270
+ }
5271
+ return false;
5272
+ };
5273
+ updateInSection(updatedSection, node.id, node.type);
5274
+ onSectionChange(updatedSection);
5275
+ };
5276
+ const handleAddPanel = () => {
5277
+ if (selectedNode) {
5278
+ if (selectedNode.type === 'section' || selectedNode.type === 'panel') {
5279
+ onAddPanel(selectedNode.id, selectedNode.type);
5280
+ }
5281
+ }
5282
+ else {
5283
+ // Add to root section
5284
+ onAddPanel(section['section-id'], 'section');
5285
+ }
5286
+ };
5287
+ const handleAddWidget = () => {
5288
+ if (selectedNode) {
5289
+ if (selectedNode.type === 'panel') {
5290
+ onAddWidget(selectedNode.id);
5291
+ }
5292
+ else if (selectedNode.type === 'section') {
5293
+ // Find first panel or create one
5294
+ if (section.panels && section.panels.length > 0) {
5295
+ onAddWidget(section.panels[0]['panel-id']);
5296
+ }
5297
+ else {
5298
+ // Create a panel first, then add widget
5299
+ const newPanel = {
5300
+ 'panel-id': `panel-${Date.now()}`,
5301
+ 'panel-orientation': 'vertical',
5302
+ widgets: [],
5303
+ };
5304
+ const updatedSection = {
5305
+ ...section,
5306
+ panels: [...(section.panels || []), newPanel],
5307
+ };
5308
+ onSectionChange(updatedSection);
5309
+ onAddWidget(newPanel['panel-id']);
5310
+ }
5311
+ }
5312
+ }
5313
+ else {
5314
+ // Add to first panel or create one
5315
+ if (section.panels && section.panels.length > 0) {
5316
+ onAddWidget(section.panels[0]['panel-id']);
5317
+ }
5318
+ }
5319
+ };
5320
+ return (jsxRuntimeExports.jsxs("div", { style: {
5321
+ display: 'flex',
5322
+ flexDirection: 'column',
5323
+ height: '100%',
5324
+ width: '100%',
5325
+ minHeight: 0,
5326
+ }, children: [jsxRuntimeExports.jsxs("div", { style: {
5327
+ padding: '15px 20px',
5328
+ background: '#ffffff',
5329
+ borderBottom: '1px solid #ddd',
5330
+ display: 'flex',
5331
+ justifyContent: 'space-between',
5332
+ alignItems: 'center',
5333
+ }, children: [jsxRuntimeExports.jsx("div", { style: { fontWeight: 600, fontSize: '16px', color: '#2c3e50' }, children: "Visual Builder" }), jsxRuntimeExports.jsxs("div", { style: { display: 'flex', gap: '10px' }, children: [jsxRuntimeExports.jsx("button", { onClick: handleAddPanel, style: {
5334
+ padding: '8px 16px',
5335
+ border: 'none',
5336
+ borderRadius: '4px',
5337
+ background: '#2196f3',
5338
+ color: 'white',
5339
+ fontWeight: 600,
5340
+ cursor: 'pointer',
5341
+ fontSize: '12px',
5342
+ whiteSpace: 'nowrap',
5343
+ }, children: "+ Add Panel" }), jsxRuntimeExports.jsx("button", { onClick: handleAddWidget, style: {
5344
+ padding: '8px 16px',
5345
+ border: 'none',
5346
+ borderRadius: '4px',
5347
+ background: '#4caf50',
5348
+ color: 'white',
5349
+ fontWeight: 600,
5350
+ cursor: 'pointer',
5351
+ fontSize: '12px',
5352
+ whiteSpace: 'nowrap',
5353
+ }, children: "+ Add Widget" }), onSave && (jsxRuntimeExports.jsx("button", { onClick: handleSave, style: {
5354
+ padding: '8px 16px',
5355
+ border: 'none',
5356
+ borderRadius: '4px',
5357
+ background: '#ff9800',
5358
+ color: 'white',
5359
+ fontWeight: 600,
5360
+ cursor: 'pointer',
5361
+ fontSize: '12px',
5362
+ whiteSpace: 'nowrap',
5363
+ }, children: "Save" })), onToggleMaximize && (jsxRuntimeExports.jsx("button", { onClick: onToggleMaximize, style: {
5364
+ padding: '8px',
5365
+ border: 'none',
5366
+ borderRadius: '4px',
5367
+ background: 'transparent',
5368
+ color: '#666',
5369
+ cursor: 'pointer',
5370
+ display: 'flex',
5371
+ alignItems: 'center',
5372
+ justifyContent: 'center',
5373
+ width: '32px',
5374
+ height: '32px',
5375
+ }, title: isMaximized ? 'Minimize' : 'Maximize', children: isMaximized ? (jsxRuntimeExports.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsxRuntimeExports.jsx("path", { d: "M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3" }) })) : (jsxRuntimeExports.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsxRuntimeExports.jsx("path", { d: "M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" }) })) }))] })] }), jsxRuntimeExports.jsxs("div", { style: {
5376
+ flex: 1,
5377
+ display: 'flex',
5378
+ overflow: 'hidden',
5379
+ minHeight: 0, // Important for flex children to respect overflow
5380
+ }, children: [jsxRuntimeExports.jsx("div", { style: {
5381
+ width: '45%',
5382
+ borderRight: '1px solid #ddd',
5383
+ display: 'flex',
5384
+ flexDirection: 'column',
5385
+ minHeight: 0, // Important for flex children to respect overflow
5386
+ overflow: 'hidden',
5387
+ }, children: jsxRuntimeExports.jsx(SectionTree, { section: section, selectedNode: selectedNode, onSelectNode: onSelectNode, onAddPanel: onAddPanel, onAddWidget: onAddWidget, onDeleteNode: onDeleteNode, onDuplicateNode: onDuplicateNode }) }), jsxRuntimeExports.jsx("div", { style: {
5388
+ width: '55%',
5389
+ display: 'flex',
5390
+ flexDirection: 'column',
5391
+ minHeight: 0, // Important for flex children to respect overflow
5392
+ overflow: 'hidden',
5393
+ }, children: jsxRuntimeExports.jsx(PropertyEditor, { node: selectedNode, onChange: handleNodeChange, onDelete: onDeleteNode, onDuplicate: onDuplicateNode }) })] })] }));
5394
+ };
5395
+
5396
+ /**
5397
+ * Main Section Builder Component
5398
+ * Provides dual-panel interface for editing section JSON
5399
+ */
5400
+ const SectionBuilder = ({ initialSection, onChange, onSave, }) => {
5401
+ const defaultSection = {
5402
+ 'section-id': 'new-section',
5403
+ 'section-title': '',
5404
+ 'section-editable': false,
5405
+ panels: [],
5406
+ };
5407
+ const [section, setSection] = React.useState(initialSection || defaultSection);
5408
+ const [selectedNode, setSelectedNode] = React.useState(null);
5409
+ const [isMaximized, setIsMaximized] = React.useState(false);
5410
+ // Store the original section for reset functionality
5411
+ const originalSectionRef = React.useRef(initialSection ? JSON.parse(JSON.stringify(initialSection)) : defaultSection);
5412
+ const isInitialMount = React.useRef(true);
5413
+ React.useEffect(() => {
5414
+ if (initialSection) {
5415
+ // Only update original on initial mount
5416
+ if (isInitialMount.current) {
5417
+ originalSectionRef.current = JSON.parse(JSON.stringify(initialSection));
5418
+ isInitialMount.current = false;
5419
+ }
5420
+ setSection(initialSection);
5421
+ }
5422
+ }, [initialSection]);
5423
+ const handleSectionChange = React.useCallback((updatedSection) => {
5424
+ setSection(updatedSection);
5425
+ if (onChange) {
5426
+ onChange(updatedSection);
5427
+ }
5428
+ }, [onChange]);
5429
+ // Reset to original section - resets both JSON editor and visual builder
5430
+ const handleReset = React.useCallback(() => {
5431
+ const original = JSON.parse(JSON.stringify(originalSectionRef.current));
5432
+ setSection(original);
5433
+ setSelectedNode(null); // Clear selection on reset
5434
+ if (onChange) {
5435
+ onChange(original);
5436
+ }
5437
+ }, [onChange]);
5438
+ // Handle node selection from JSON editor
5439
+ const handleSelectNodeFromJson = React.useCallback((nodeId, nodeType) => {
5440
+ // Find the corresponding node in the section structure
5441
+ const findNode = () => {
5442
+ if (nodeType === 'section') {
5443
+ return {
5444
+ type: 'section',
5445
+ id: section['section-id'],
5446
+ label: `Section: ${section['section-id']}`,
5447
+ data: section,
5448
+ };
5449
+ }
5450
+ // Recursively search for panel or widget
5451
+ const searchInPanels = (panels, parent) => {
5452
+ for (const panel of panels) {
5453
+ if (nodeType === 'panel' && panel['panel-id'] === nodeId) {
5454
+ return {
5455
+ type: 'panel',
5456
+ id: panel['panel-id'],
5457
+ label: `Panel: ${panel['panel-id']}`,
5458
+ data: panel,
5459
+ parent: parent,
5460
+ };
5461
+ }
5462
+ // Check nested panels
5463
+ if (panel.panels) {
5464
+ const panelNode = {
5465
+ type: 'panel',
5466
+ id: panel['panel-id'],
5467
+ label: `Panel: ${panel['panel-id']}`,
5468
+ data: panel,
5469
+ parent: parent,
5470
+ };
5471
+ const found = searchInPanels(panel.panels, panelNode);
5472
+ if (found)
5473
+ return found;
5474
+ }
5475
+ // Check widgets
5476
+ if (panel.widgets) {
5477
+ const panelNode = {
5478
+ type: 'panel',
5479
+ id: panel['panel-id'],
5480
+ label: `Panel: ${panel['panel-id']}`,
5481
+ data: panel,
5482
+ parent: parent,
5483
+ };
5484
+ for (const widget of panel.widgets) {
5485
+ if (nodeType === 'widget' && widget['widget-id'] === nodeId) {
5486
+ return {
5487
+ type: 'widget',
5488
+ id: widget['widget-id'],
5489
+ label: `Widget: ${widget['widget-id']} (${widget.widget})`,
5490
+ data: widget,
5491
+ parent: panelNode,
5492
+ };
5493
+ }
5494
+ }
5495
+ }
5496
+ }
5497
+ return null;
5498
+ };
5499
+ if (section.panels) {
5500
+ return searchInPanels(section.panels);
5501
+ }
5502
+ return null;
5503
+ };
5504
+ const node = findNode();
5505
+ if (node) {
5506
+ setSelectedNode(node);
5507
+ }
5508
+ }, [section]);
5509
+ const handleAddPanel = React.useCallback((parentId, parentType) => {
5510
+ const updatedSection = JSON.parse(JSON.stringify(section));
5511
+ const newPanel = {
5512
+ 'panel-id': `panel-${Date.now()}`,
5513
+ 'panel-orientation': 'vertical',
5514
+ widgets: [],
5515
+ };
5516
+ if (parentType === 'section') {
5517
+ updatedSection.panels = [...(updatedSection.panels || []), newPanel];
5518
+ }
5519
+ else if (parentType === 'panel') {
5520
+ const addPanelToParent = (panels) => {
5521
+ for (const panel of panels) {
5522
+ if (panel['panel-id'] === parentId) {
5523
+ panel.panels = [...(panel.panels || []), newPanel];
5524
+ return true;
5525
+ }
5526
+ if (panel.panels && addPanelToParent(panel.panels)) {
5527
+ return true;
5528
+ }
5529
+ }
5530
+ return false;
5531
+ };
5532
+ if (updatedSection.panels) {
5533
+ addPanelToParent(updatedSection.panels);
5534
+ }
5535
+ }
5536
+ handleSectionChange(updatedSection);
5537
+ }, [section, handleSectionChange]);
5538
+ const handleAddWidget = React.useCallback((parentId) => {
5539
+ const updatedSection = JSON.parse(JSON.stringify(section));
5540
+ const newWidget = {
5541
+ widget: 'text',
5542
+ 'widget-id': `widget-${Date.now()}`,
5543
+ 'widget-label': 'New Widget',
5544
+ 'widget-data-path': '',
5545
+ };
5546
+ const addWidgetToPanel = (panels) => {
5547
+ for (const panel of panels) {
5548
+ if (panel['panel-id'] === parentId) {
5549
+ panel.widgets = [...(panel.widgets || []), newWidget];
5550
+ return true;
5551
+ }
5552
+ if (panel.panels && addWidgetToPanel(panel.panels)) {
5553
+ return true;
5554
+ }
5555
+ }
5556
+ return false;
5557
+ };
5558
+ if (updatedSection.panels) {
5559
+ addWidgetToPanel(updatedSection.panels);
5560
+ }
5561
+ handleSectionChange(updatedSection);
5562
+ }, [section, handleSectionChange]);
5563
+ const handleDeleteNode = React.useCallback((node) => {
5564
+ const updatedSection = JSON.parse(JSON.stringify(section));
5565
+ if (node.type === 'section') {
5566
+ // Can't delete section, but can reset it
5567
+ return;
5568
+ }
5569
+ const deleteFromSection = (current) => {
5570
+ if (current.panels) {
5571
+ const panelIndex = current.panels.findIndex((p) => p['panel-id'] === node.id);
5572
+ if (panelIndex !== -1 && node.type === 'panel') {
5573
+ current.panels.splice(panelIndex, 1);
5574
+ return true;
5575
+ }
5576
+ for (const panel of current.panels) {
5577
+ if (panel['panel-id'] === node.id && node.type === 'panel') {
5578
+ // This shouldn't happen due to findIndex above, but handle nested case
5579
+ const index = current.panels.indexOf(panel);
5580
+ if (index !== -1) {
5581
+ current.panels.splice(index, 1);
5582
+ return true;
5583
+ }
5584
+ }
5585
+ if (panel.widgets) {
5586
+ const widgetIndex = panel.widgets.findIndex((w) => w['widget-id'] === node.id);
5587
+ if (widgetIndex !== -1 && node.type === 'widget') {
5588
+ panel.widgets.splice(widgetIndex, 1);
5589
+ return true;
5590
+ }
5591
+ }
5592
+ if (panel.panels && deleteFromSection(panel)) {
5593
+ return true;
5594
+ }
5595
+ }
5596
+ }
5597
+ return false;
5598
+ };
5599
+ deleteFromSection(updatedSection);
5600
+ handleSectionChange(updatedSection);
5601
+ setSelectedNode(null);
5602
+ }, [section, handleSectionChange]);
5603
+ const handleDuplicateNode = React.useCallback((node) => {
5604
+ const updatedSection = JSON.parse(JSON.stringify(section));
5605
+ if (node.type === 'section') {
5606
+ return;
5607
+ }
5608
+ const duplicateInSection = (current) => {
5609
+ if (current.panels) {
5610
+ for (const panel of current.panels) {
5611
+ if (panel['panel-id'] === node.id && node.type === 'panel') {
5612
+ const duplicated = {
5613
+ ...panel,
5614
+ 'panel-id': `${panel['panel-id']}-copy-${Date.now()}`,
5615
+ };
5616
+ const index = current.panels.indexOf(panel);
5617
+ current.panels.splice(index + 1, 0, duplicated);
5618
+ return true;
5619
+ }
5620
+ if (panel.widgets) {
5621
+ for (const widget of panel.widgets) {
5622
+ if (widget['widget-id'] === node.id && node.type === 'widget') {
5623
+ const duplicated = {
5624
+ ...widget,
5625
+ 'widget-id': `${widget['widget-id']}-copy-${Date.now()}`,
5626
+ };
5627
+ const index = panel.widgets.indexOf(widget);
5628
+ panel.widgets.splice(index + 1, 0, duplicated);
5629
+ return true;
5630
+ }
5631
+ }
5632
+ }
5633
+ if (panel.panels && duplicateInSection(panel)) {
5634
+ return true;
5635
+ }
5636
+ }
5637
+ }
5638
+ return false;
5639
+ };
5640
+ duplicateInSection(updatedSection);
5641
+ handleSectionChange(updatedSection);
5642
+ }, [section, handleSectionChange]);
5643
+ const toggleMaximize = React.useCallback(() => {
5644
+ setIsMaximized((prev) => !prev);
5645
+ }, []);
5646
+ // Handle Escape key to exit fullscreen
5647
+ React.useEffect(() => {
5648
+ if (!isMaximized)
5649
+ return;
5650
+ const handleEscape = (e) => {
5651
+ if (e.key === 'Escape') {
5652
+ setIsMaximized(false);
5653
+ }
5654
+ };
5655
+ window.addEventListener('keydown', handleEscape);
5656
+ return () => window.removeEventListener('keydown', handleEscape);
5657
+ }, [isMaximized]);
5658
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [isMaximized && (jsxRuntimeExports.jsx("div", { style: {
5659
+ position: 'fixed',
5660
+ top: 0,
5661
+ left: 0,
5662
+ right: 0,
5663
+ bottom: 0,
5664
+ background: 'rgba(0, 0, 0, 0.5)',
5665
+ zIndex: 9998,
5666
+ }, onClick: toggleMaximize })), jsxRuntimeExports.jsxs("div", { style: {
5667
+ display: 'flex',
5668
+ height: isMaximized ? '100vh' : '100%',
5669
+ width: isMaximized ? '100vw' : '100%',
5670
+ minHeight: 0,
5671
+ background: '#FFFFFF',
5672
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
5673
+ overflow: 'hidden',
5674
+ border: 'none',
5675
+ position: isMaximized ? 'fixed' : 'relative',
5676
+ top: isMaximized ? 0 : 'auto',
5677
+ left: isMaximized ? 0 : 'auto',
5678
+ zIndex: isMaximized ? 9999 : 'auto',
5679
+ }, children: [jsxRuntimeExports.jsx("div", { style: {
5680
+ width: '50%',
5681
+ height: '100%',
5682
+ minHeight: 0,
5683
+ overflow: 'hidden',
5684
+ display: 'flex',
5685
+ padding: '10px 10px 10px 10px',
5686
+ flexDirection: 'column',
5687
+ borderRight: '0px',
5688
+ }, children: jsxRuntimeExports.jsx(JSONEditorPanel, { section: section, onChange: handleSectionChange, onReset: handleReset, onSelectNode: handleSelectNodeFromJson }) }), jsxRuntimeExports.jsx("div", { style: {
5689
+ width: '50%',
5690
+ height: '100%',
5691
+ minHeight: 0,
5692
+ overflow: 'hidden',
5693
+ display: 'flex',
5694
+ flexDirection: 'column',
5695
+ }, children: jsxRuntimeExports.jsx(VisualBuilderPanel, { section: section, selectedNode: selectedNode, onSelectNode: setSelectedNode, onSectionChange: handleSectionChange, onAddPanel: handleAddPanel, onAddWidget: handleAddWidget, onDeleteNode: handleDeleteNode, onDuplicateNode: handleDuplicateNode, onSave: onSave, isMaximized: isMaximized, onToggleMaximize: toggleMaximize }) })] })] }));
5696
+ };
5697
+
5698
+ /**
5699
+ * Filter input value based on allowed character type
5700
+ */
5701
+ const filterByCharacterType = (value, characterType = 'any', customCharset) => {
5702
+ if (characterType === 'any') {
5703
+ return value;
3227
5704
  }
3228
5705
  let regex;
3229
5706
  switch (characterType) {
@@ -4681,87 +7158,54 @@ const RadioWidget = ({ config }) => {
4681
7158
  }
4682
7159
  return options;
4683
7160
  }, [dataSourceOptions, sortOptions]);
4684
- // Handle radio button change - simple and direct
4685
- React.useCallback((selectedValue) => {
4686
- onChange(selectedValue);
7161
+ // Handle value change
7162
+ const handleChange = React.useCallback((optionValue) => {
7163
+ onChange(optionValue);
4687
7164
  }, [onChange]);
4688
- // Determine current value
7165
+ // Handle unset (clear selection) - only if optional
7166
+ const handleUnset = React.useCallback(() => {
7167
+ if (allowUnset) {
7168
+ onChange(null);
7169
+ }
7170
+ }, [allowUnset, onChange]);
7171
+ // Determine current value (handle null/undefined for optional fields)
4689
7172
  const currentValue = React.useMemo(() => {
4690
- console.log('[RadioWidget] Value from useBaseWidget:', {
4691
- value,
4692
- type: typeof value,
4693
- widgetId: widgetConfig['widget-id'],
4694
- dataPath: widgetConfig['widget-data-path']
4695
- });
4696
7173
  if (value === null || value === undefined) {
4697
7174
  return null;
4698
7175
  }
4699
7176
  return value;
4700
- }, [value, widgetConfig]);
4701
- // Helper to safely compare values (handles type coercion)
4702
- const isValueSelected = React.useCallback((optionValue) => {
4703
- // Handle null/undefined cases
4704
- if (currentValue === null || currentValue === undefined) {
4705
- return optionValue === null || optionValue === undefined;
4706
- }
4707
- if (optionValue === null || optionValue === undefined) {
4708
- return false;
4709
- }
4710
- // Convert both to strings and compare (handles any type mismatch)
4711
- const currentStr = String(currentValue).trim();
4712
- const optionStr = String(optionValue).trim();
4713
- return currentStr === optionStr;
4714
- }, [currentValue]);
4715
- // Get layout classes
4716
- const getLayoutClass = React.useMemo(() => {
7177
+ }, [value]);
7178
+ // Get layout classes and styles
7179
+ const layoutConfig = React.useMemo(() => {
4717
7180
  switch (layout) {
4718
7181
  case 'horizontal':
4719
- return 'flex flex-row flex-wrap gap-4';
7182
+ return {
7183
+ className: 'flex flex-row flex-wrap gap-4',
7184
+ style: undefined,
7185
+ };
4720
7186
  case 'grid':
4721
- Math.max(2, Math.min(processedOptions.length, 4));
4722
- return 'grid gap-3';
7187
+ // Calculate grid columns based on option count (max 4 columns, min 2)
7188
+ const cols = Math.max(2, Math.min(processedOptions.length, 4));
7189
+ return {
7190
+ className: 'grid gap-3',
7191
+ style: { gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` },
7192
+ };
4723
7193
  case 'vertical':
4724
7194
  default:
4725
- return 'flex flex-col space-y-2';
4726
- }
4727
- }, [layout, processedOptions.length]);
4728
- const getLayoutStyle = React.useMemo(() => {
4729
- if (layout === 'grid') {
4730
- const cols = Math.max(2, Math.min(processedOptions.length, 4));
4731
- return { gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` };
7195
+ return {
7196
+ className: 'flex flex-col space-y-2',
7197
+ style: undefined,
7198
+ };
4732
7199
  }
4733
- return undefined;
4734
7200
  }, [layout, processedOptions.length]);
4735
7201
  // For readonly mode, render as display text
4736
7202
  if (widgetConfig['widget-readonly']) {
4737
7203
  const label = translateConfig(widgetConfig['widget-label']);
4738
- const selectedOption = processedOptions.find(opt => isValueSelected(opt.value));
7204
+ const selectedOption = processedOptions.find(opt => opt.value === currentValue);
4739
7205
  const displayValue = selectedOption ? selectedOption.label : (allowUnset && currentValue === null ? '-' : '');
4740
7206
  return (jsxRuntimeExports.jsxs("div", { className: "mb-[10px] RadioDisplayWidget flex flex-col sm:flex-row sm:items-start", children: [label && (jsxRuntimeExports.jsxs("div", { className: "text-base text-gray-600 font-medium md:min-w-[120px] sm:pr-4 mb-1 sm:mb-0", style: { fontFamily: 'Roboto, sans-serif' }, children: [label, ":"] })), jsxRuntimeExports.jsx("div", { className: "flex-1", children: jsxRuntimeExports.jsx("div", { className: "text-base text-gray-900 font-medium", children: displayValue }) })] }));
4741
7207
  }
4742
- return (jsxRuntimeExports.jsx("div", { className: "mb-[10px]", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col sm:flex-row sm:items-start", children: [jsxRuntimeExports.jsxs("label", { className: "text-base font-medium text-gray-700 md:min-w-[120px] sm:pr-4 sm:pt-1 mb-1 sm:mb-0", style: { fontFamily: 'Roboto, sans-serif' }, children: [translateConfig(widgetConfig['widget-label']), widgetConfig['widget-required'] && (jsxRuntimeExports.jsx("span", { className: "text-red-500 ml-1", children: "*" }))] }), jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [jsxRuntimeExports.jsx("div", { className: getLayoutClass, style: getLayoutStyle, children: loading ? (jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: translate('common.loading') })) : (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [allowUnset && (jsxRuntimeExports.jsxs("label", { className: `flex items-center cursor-pointer ${!isEnabled || widgetConfig['widget-readonly'] ? 'opacity-50 cursor-not-allowed' : ''}`, children: [jsxRuntimeExports.jsx("input", { type: "radio", name: widgetConfig['widget-id'], checked: currentValue === null,
4743
- // onChange={() => handleRadioChange(null)}
4744
- disabled: !isEnabled || widgetConfig['widget-readonly'], className: "mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300" }), jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-700", children: "-" })] })), processedOptions.map((option, index) => {
4745
- const isChecked = isValueSelected(option.value);
4746
- // Debug log (remove after testing)
4747
- if (index === 0) {
4748
- console.log('[RadioWidget] Value check:', {
4749
- currentValue,
4750
- optionValue: option.value,
4751
- currentType: typeof currentValue,
4752
- optionType: typeof option.value,
4753
- isChecked,
4754
- currentStr: String(currentValue),
4755
- optionStr: String(option.value)
4756
- });
4757
- }
4758
- return (jsxRuntimeExports.jsxs("label", { className: `flex items-center cursor-pointer ${!isEnabled || widgetConfig['widget-readonly'] ? 'opacity-50 cursor-not-allowed' : ''}`, children: [jsxRuntimeExports.jsx("input", { type: "radio", name: widgetConfig['widget-id'], value: String(option.value), checked: isChecked,
4759
- // onChange={() => {
4760
- // console.log('[RadioWidget] onChange called:', option.value);
4761
- // handleRadioChange(option.value);
4762
- // }}
4763
- disabled: !isEnabled || widgetConfig['widget-readonly'], className: "mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300" }), jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-700", children: translateConfig(option.label) })] }, `${widgetConfig['widget-id']}-${option.value}-${index}`));
4764
- })] })) }), touched && error.length > 0 && (jsxRuntimeExports.jsx("p", { className: "text-red-500 text-sm mt-1", children: error[0] }))] })] }) }));
7208
+ return (jsxRuntimeExports.jsx("div", { className: "mb-[10px]", children: jsxRuntimeExports.jsxs("div", { className: "flex flex-col sm:flex-row sm:items-start", children: [jsxRuntimeExports.jsxs("label", { className: "text-base font-medium text-gray-700 md:min-w-[120px] sm:pr-4 sm:pt-1 mb-1 sm:mb-0", style: { fontFamily: 'Roboto, sans-serif' }, children: [translateConfig(widgetConfig['widget-label']), widgetConfig['widget-required'] && (jsxRuntimeExports.jsx("span", { className: "text-red-500 ml-1", children: "*" }))] }), jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [jsxRuntimeExports.jsx("div", { className: layoutConfig.className, style: layoutConfig.style, onBlur: onBlur, children: loading ? (jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500", children: translate('common.loading') })) : (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [allowUnset && (jsxRuntimeExports.jsxs("label", { className: `flex items-center cursor-pointer ${!isEnabled || widgetConfig['widget-readonly'] ? 'opacity-50 cursor-not-allowed' : ''}`, children: [jsxRuntimeExports.jsx("input", { type: "radio", name: widgetConfig['widget-id'], checked: currentValue === null, onChange: handleUnset, disabled: !isEnabled || widgetConfig['widget-readonly'], className: "mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300" }), jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-700", children: "-" })] })), processedOptions.map((option) => (jsxRuntimeExports.jsxs("label", { className: `flex items-center cursor-pointer ${!isEnabled || widgetConfig['widget-readonly'] ? 'opacity-50 cursor-not-allowed' : ''}`, children: [jsxRuntimeExports.jsx("input", { type: "radio", name: widgetConfig['widget-id'], value: option.value, checked: currentValue === option.value, onChange: (e) => handleChange(option.value), disabled: !isEnabled || widgetConfig['widget-readonly'], className: "mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300" }), jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-700", children: translateConfig(option.label) })] }, option.value)))] })) }), touched && error.length > 0 && (jsxRuntimeExports.jsx("p", { className: "text-red-500 text-sm mt-1", children: error[0] }))] })] }) }));
4765
7209
  };
4766
7210
 
4767
7211
  const CheckboxWidget = ({ config }) => {
@@ -5134,7 +7578,7 @@ const TableCellNumber = ({ config, value, onValueChange }) => {
5134
7578
  const TableWidget = ({ config }) => {
5135
7579
  const { value, error, touched, isEnabled, onChange, config: widgetConfig, } = useBaseWidget({ config });
5136
7580
  const { translate, translateConfig } = useWidgetTranslation();
5137
- const { apiAdapter } = useWidgetContext();
7581
+ const { dataSourceRequestHandler } = useWidgetContext();
5138
7582
  const dispatch = reactRedux.useDispatch();
5139
7583
  const storeValues = reactRedux.useSelector((state) => state.widget?.values || {});
5140
7584
  const rows = Array.isArray(value) ? value : [];
@@ -5249,18 +7693,12 @@ const TableWidget = ({ config }) => {
5249
7693
  setLoadingRowIndex(rowIndex);
5250
7694
  try {
5251
7695
  // If API config exists, make API call
5252
- if (apiAdapter && apiConfig.edit) {
7696
+ // TODO: Update to use dataSourceRequestHandler pattern
7697
+ if (dataSourceRequestHandler && apiConfig.edit) {
5253
7698
  const editConfig = apiConfig.edit;
5254
- let url = editConfig.url || '';
5255
- // Replace {id} placeholder if present
5256
- if (rowData.id !== undefined) {
5257
- url = url.replace('{id}', rowData.id);
5258
- }
5259
- await apiAdapter(url, {
5260
- method: editConfig.method || 'PUT',
5261
- headers: editConfig.headers || { 'Content-Type': 'application/json' },
5262
- body: rowData,
5263
- });
7699
+ // Extract service and endpoint from URL if possible, or use config
7700
+ // For now, API operations in TableWidget are disabled
7701
+ console.warn('[TableWidget] API edit operations require migration to dataSourceRequestHandler pattern');
5264
7702
  }
5265
7703
  // Update local state
5266
7704
  const newRows = [...rows];
@@ -5321,7 +7759,7 @@ const TableWidget = ({ config }) => {
5321
7759
  finally {
5322
7760
  setLoadingRowIndex(null);
5323
7761
  }
5324
- }, [editingState, rows, onChange, apiAdapter, apiConfig, translate, isSectionEditMode, originalRows, columns, widgetConfig, dispatch]);
7762
+ }, [editingState, rows, onChange, dataSourceRequestHandler, apiConfig, translate, isSectionEditMode, originalRows, columns, widgetConfig, dispatch]);
5325
7763
  // Add new row
5326
7764
  const startAdd = React.useCallback(() => {
5327
7765
  // If there's an unsaved edit, cancel it first (no confirmation needed)
@@ -5343,14 +7781,14 @@ const TableWidget = ({ config }) => {
5343
7781
  try {
5344
7782
  let savedRow = { ...newRowData };
5345
7783
  // If API config exists, make API call
5346
- if (apiAdapter && apiConfig.add) {
7784
+ // TODO: Update to use dataSourceRequestHandler pattern
7785
+ if (dataSourceRequestHandler && apiConfig.add) {
5347
7786
  const addConfig = apiConfig.add;
5348
- const response = await apiAdapter(addConfig.url || '', {
5349
- method: addConfig.method || 'POST',
5350
- headers: addConfig.headers || { 'Content-Type': 'application/json' },
5351
- body: newRowData,
5352
- });
5353
- // Use response data if available (might contain generated ID)
7787
+ // Extract service and endpoint from URL if possible, or use config
7788
+ // For now, API operations in TableWidget are disabled
7789
+ console.warn('[TableWidget] API add operations require migration to dataSourceRequestHandler pattern');
7790
+ // Use newRowData as response for now
7791
+ const response = newRowData;
5354
7792
  if (response && typeof response === 'object') {
5355
7793
  savedRow = { ...savedRow, ...response };
5356
7794
  }
@@ -5369,7 +7807,7 @@ const TableWidget = ({ config }) => {
5369
7807
  finally {
5370
7808
  setLoadingRowIndex(null);
5371
7809
  }
5372
- }, [isAdding, newRowData, rows, onChange, apiAdapter, apiConfig, translate, isSectionEditMode]);
7810
+ }, [isAdding, newRowData, rows, onChange, dataSourceRequestHandler, apiConfig, translate, isSectionEditMode]);
5373
7811
  // Delete row
5374
7812
  const deleteRow = React.useCallback(async (rowIndex) => {
5375
7813
  if (isAnyRowEditing) {
@@ -5385,21 +7823,16 @@ const TableWidget = ({ config }) => {
5385
7823
  }
5386
7824
  }, [isAnyRowEditing, showConfirmation, cancelEdit, translate]);
5387
7825
  const performDelete = React.useCallback(async (rowIndex) => {
5388
- const row = rows[rowIndex];
7826
+ rows[rowIndex];
5389
7827
  setLoadingRowIndex(rowIndex);
5390
7828
  try {
5391
7829
  // If API config exists, make API call
5392
- if (apiAdapter && apiConfig.delete) {
7830
+ // TODO: Update to use dataSourceRequestHandler pattern
7831
+ if (dataSourceRequestHandler && apiConfig.delete) {
5393
7832
  const deleteConfig = apiConfig.delete;
5394
- let url = deleteConfig.url || '';
5395
- // Replace {id} placeholder if present
5396
- if (row.id !== undefined) {
5397
- url = url.replace('{id}', row.id);
5398
- }
5399
- await apiAdapter(url, {
5400
- method: deleteConfig.method || 'DELETE',
5401
- headers: deleteConfig.headers || {},
5402
- });
7833
+ // Extract service and endpoint from URL if possible, or use config
7834
+ // For now, API operations in TableWidget are disabled
7835
+ console.warn('[TableWidget] API delete operations require migration to dataSourceRequestHandler pattern');
5403
7836
  }
5404
7837
  // In section edit mode, mark row as deleted instead of removing it
5405
7838
  if (isSectionEditMode) {
@@ -5423,7 +7856,7 @@ const TableWidget = ({ config }) => {
5423
7856
  finally {
5424
7857
  setLoadingRowIndex(null);
5425
7858
  }
5426
- }, [rows, onChange, apiAdapter, apiConfig, translate, isSectionEditMode]);
7859
+ }, [rows, onChange, dataSourceRequestHandler, apiConfig, translate, isSectionEditMode]);
5427
7860
  // Get cell value (from editing state or row data)
5428
7861
  const getCellValue = React.useCallback((rowIndex, columnKey) => {
5429
7862
  // When a specific row is being edited (either in section edit mode or normal mode)
@@ -6322,18 +8755,24 @@ exports.DateTimeInputWidget = DateTimeInputWidget;
6322
8755
  exports.DisplayWidget = DisplayWidget;
6323
8756
  exports.FileInputWidget = FileInputWidget;
6324
8757
  exports.IterableAccordionWidget = IterableAccordionWidget;
8758
+ exports.JSONEditorPanel = JSONEditorPanel;
6325
8759
  exports.NumberInputWidget = NumberInputWidget;
6326
8760
  exports.PanelRenderer = PanelRenderer;
6327
8761
  exports.PhoneInputWidget = PhoneInputWidget;
6328
8762
  exports.ProfileWidget = ProfileWidget;
8763
+ exports.PropertyEditor = PropertyEditor;
6329
8764
  exports.RadioWidget = RadioWidget;
8765
+ exports.SectionBuilder = SectionBuilder;
6330
8766
  exports.SectionRenderer = SectionRenderer;
8767
+ exports.SectionTree = SectionTree;
6331
8768
  exports.SectionsContainer = SectionsContainer;
6332
8769
  exports.SelectWidget = SelectWidget;
6333
8770
  exports.SimpleTableWidget = SimpleTableWidget;
6334
8771
  exports.TableWidget = TableWidget;
6335
8772
  exports.TextAreaWidget = TextAreaWidget;
6336
8773
  exports.TextInputWidget = TextInputWidget;
8774
+ exports.VisualBuilderPanel = VisualBuilderPanel;
8775
+ exports.WidgetEventBus = WidgetEventBus;
6337
8776
  exports.WidgetProvider = WidgetProvider;
6338
8777
  exports.WidgetRenderer = WidgetRenderer;
6339
8778
  exports.applyCaseControl = applyCaseControl;
@@ -6348,6 +8787,7 @@ exports.formatDate = formatDate;
6348
8787
  exports.formatNumber = formatNumber;
6349
8788
  exports.formatPhone = formatPhone;
6350
8789
  exports.formatValue = formatValue;
8790
+ exports.geoHierarchyBuilder = geoHierarchyBuilder;
6351
8791
  exports.getApiDataSource = getApiDataSource;
6352
8792
  exports.getFormattedNumberLength = getFormattedNumberLength;
6353
8793
  exports.getSchemaDataSource = getSchemaDataSource;
@@ -6377,7 +8817,10 @@ exports.translatePanelConfig = translatePanelConfig;
6377
8817
  exports.translateUISchema = translateUISchema;
6378
8818
  exports.translateWidgetConfig = translateWidgetConfig;
6379
8819
  exports.useBaseWidget = useBaseWidget;
8820
+ exports.useGeoWidgetCascade = useGeoWidgetCascade;
8821
+ exports.useWidgetCascade = useWidgetCascade;
6380
8822
  exports.useWidgetContext = useWidgetContext;
8823
+ exports.useWidgetEventBus = useWidgetEventBus;
6381
8824
  exports.useWidgetTranslation = useWidgetTranslation;
6382
8825
  exports.validateNumericValue = validateNumericValue;
6383
8826
  exports.validateWidget = validateWidget;