@openg2p/registry-widgets 1.1.2-dev.8 → 1.1.2-dev.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SectionRenderer.d.ts","sourceRoot":"","sources":["../../src/components/SectionRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAyC,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQ9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAqDlD,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,wBAAwB,CAAC,EAAE,oBAAoB,CAAC,0BAA0B,CAAC,CAAC;IAC5E,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,aAAa,CAAC,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAClE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAClC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAGjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAA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4F;IAC5F,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,wGAAwG;IACxG,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,0HAA0H;IAC1H,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACjE,iGAAiG;IACjG,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAGD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,saAyB7B,oBAAoB,4CAqlDtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGeoWidgetCascade.d.ts","sourceRoot":"","sources":["../../src/hooks/useGeoWidgetCascade.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAgBtE,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,gBAAgB,CAAC;IACzB,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAKD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,0BAA0B,SAuPtE,CAAC"}
1
+ {"version":3,"file":"useGeoWidgetCascade.d.ts","sourceRoot":"","sources":["../../src/hooks/useGeoWidgetCascade.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAmBtE,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,gBAAgB,CAAC;IACzB,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAGD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,0BAA0B,SAwMtE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1771,8 +1771,41 @@ declare class GeoHierarchyBuilder {
1771
1771
  declare const geoHierarchyBuilder: GeoHierarchyBuilder;
1772
1772
  /** Sentinel written to Redux when a geo level is cleared by cascade (distinct from "never set"). */
1773
1773
  declare const GEO_LEVEL_CLEARED: null;
1774
+ interface GeoWidgetRegistration {
1775
+ widgetId: string;
1776
+ parentWidgetId: string | null;
1777
+ level: string;
1778
+ geoConfig: GeoLevelConfig;
1779
+ dataPath: string;
1780
+ groupId: string;
1781
+ }
1774
1782
  declare function registerGeoWidgetParent(widgetId: string, parentWidgetId: string | null): void;
1775
1783
  declare function unregisterGeoWidgetParent(widgetId: string): void;
1784
+ declare function registerGeoWidget(widgetId: string, geoConfig: GeoLevelConfig & {
1785
+ parentWidgetId?: string | null;
1786
+ }, dataPath: string): void;
1787
+ declare function unregisterGeoWidget(widgetId: string): void;
1788
+ declare function orderGeoWidgetRegistrations(registrations: GeoWidgetRegistration[]): GeoWidgetRegistration[];
1789
+ /** Resolve display mnemonic from cached dropdown options, then stored hierarchy. */
1790
+ declare function createGeoLevelMnemonicResolver(values: Record<string, any>, dataSources: Record<string, Array<{
1791
+ value: any;
1792
+ label: string;
1793
+ }>>): (registration: GeoWidgetRegistration, valueId: string) => string | undefined;
1794
+ /** Rebuild group hierarchy from widget values in parent→child order; stop at first missing level. */
1795
+ declare function rebuildGeoHierarchyFromRegistrations(groupId: string, values: Record<string, any>, registrations: GeoWidgetRegistration[], resolveMnemonic?: (registration: GeoWidgetRegistration, valueId: string) => string | undefined): boolean;
1796
+ declare function collectGeoWidgetRegistrationsFromWidgets(widgets: Array<{
1797
+ 'widget-id': string;
1798
+ 'widget-data-path'?: string | Record<string, string>;
1799
+ 'widget-geo-config'?: GeoLevelConfig & {
1800
+ parentWidgetId?: string | null;
1801
+ };
1802
+ }>, namespace?: string): GeoWidgetRegistration[];
1803
+ /** Reconcile all geo groups in section values before save. */
1804
+ declare function reconcileGeoHierarchiesInValues(values: Record<string, any>, registrations: GeoWidgetRegistration[], dataSources?: Record<string, Array<{
1805
+ value: any;
1806
+ label: string;
1807
+ }>>): Record<string, any>;
1808
+ declare function getGeoWidgetRegistrationsInGroup(groupId: string): GeoWidgetRegistration[];
1776
1809
  /** True when changedWidgetId is any upstream geo parent of widgetId (not only immediate parent). */
1777
1810
  declare function isUpstreamGeoAncestor(changedWidgetId: string, widgetId: string, immediateParentWidgetId: string | null): boolean;
1778
1811
  /** Group id for geo widgets sharing the same register prefix (e.g. `{registerId}`). */
@@ -1857,5 +1890,5 @@ declare const translatePanelConfig: (panel: PanelConfig, translate: (key: string
1857
1890
  */
1858
1891
  declare const translateUISchema: (schema: UISchema, translate: (key: string, options?: any) => string) => UISchema;
1859
1892
 
1860
- export { ArrayWidget, BooleanWidget, CheckboxWidget, CurrencyInputWidget, DateInputWidget, DateTimeInputWidget, DialogTableWidget, DisplayWidget, FileInputWidget, GEO_LEVEL_CLEARED, HeaderSectionWidget, IdAuthenticationWidget, IterableAccordionWidget, JSONEditorPanel, MultiSelectWidget, NumberInputWidget, PanelRenderer, PhoneInputWidget, ProfileWidget, PropertyEditor, RadioWidget, RegisterLookupWidget, ScoresDisplayWidget, SectionBuilder, SectionRenderer, SectionTree, SectionsContainer, SelectWidget, SimpleTableWidget, TableWidget, TextAreaWidget, TextInputWidget, VisualBuilderPanel, WidgetEventBus, WidgetProvider, WidgetRenderer, applyCaseControl, applyDecimalPrecision, applyMask, applySharedGeoHierarchyToValues, createWidgetStore, createZodSchema, defaultTheme, evaluateCondition, evaluateWidgetConditions, filterByCharacterType, formatCurrency, formatDate, formatNumber, formatPhone, formatValue, geoHierarchyBuilder, getApiDataSource, getCachedApiDataSource, getFormattedNumberLength, getGeoDescendantWidgetIds, getGeoGroupId, getSchemaDataSource, getStaticDataSource, getValueByPath, getWidgetValue, hasVisibilityRules, initI18n, isAllowedKey, isUpstreamGeoAncestor, normalizeNumericDefault, normalizeOptionRules, parseDataPath, parseNumber, registerDefaultWidgets, registerGeoWidgetParent, removeMask, resetAll, resetAndSeedGeoHierarchyFromValues, resetWidget, resolveGeoWidgetLevelLabel, resolveGeoWidgetLevelValue, resolveTheme, resolveWidgetIdValue, seedGeoHierarchyFromValues, setDataSource, setError, setLoading, setTouched, setValue, setValueByPath, setValues, setWidgetValue, shouldEnableWidget, shouldRequireWidget, shouldShowWidget, transformDataSourceOptions, translatePanelConfig, translateUISchema, translateWidgetConfig, unregisterGeoWidgetParent, useBaseWidget, useGeoWidgetCascade, useWidgetCascade, useWidgetContext, useWidgetEventBus, useWidgetTheme, useWidgetTranslation, validateNumericValue, validateWidget, widgetRegistry };
1861
- export type { ApiAdapter, ApiDataSource$1 as ApiDataSource, BaseWidgetConfig, BooleanControlType, BooleanRepresentation, CaseControl, CharacterType, ConditionOperator, DataSource, DataSourceRequestHandler, DataSourceType, GeoLevelConfig, GeoLevelData, InputMask, NumericType, PanelConfig, RoundingMode, SchemaDataSource, SectionBuilderProps, SectionChanges, SectionConfig, SectionMode, SectionRendererProps, SectionsContainerProps, SectionsFormHandle, StaticDataSource, SupportingDocumentConfig, TextAlign, TreeNode, TreeNodeType, UISchema, UseBaseWidgetOptions, ValidationType, WidgetCascadeConfig, WidgetCondition, WidgetConditionState, WidgetContextValue, WidgetDataPath, WidgetDispatch, WidgetEvent, WidgetEventType, WidgetFormat, WidgetGeoConfig, WidgetOptionRule, WidgetOptions, WidgetRegistryEntry, WidgetRenderFunction, WidgetRootState, WidgetState, WidgetStore, WidgetTheme, WidgetThemeButton, WidgetThemeColors, WidgetThemePanel, WidgetThemeSection, WidgetThemeWidget, WidgetValidation, WidgetValue };
1893
+ export { ArrayWidget, BooleanWidget, CheckboxWidget, CurrencyInputWidget, DateInputWidget, DateTimeInputWidget, DialogTableWidget, DisplayWidget, FileInputWidget, GEO_LEVEL_CLEARED, HeaderSectionWidget, IdAuthenticationWidget, IterableAccordionWidget, JSONEditorPanel, MultiSelectWidget, NumberInputWidget, PanelRenderer, PhoneInputWidget, ProfileWidget, PropertyEditor, RadioWidget, RegisterLookupWidget, ScoresDisplayWidget, SectionBuilder, SectionRenderer, SectionTree, SectionsContainer, SelectWidget, SimpleTableWidget, TableWidget, TextAreaWidget, TextInputWidget, VisualBuilderPanel, WidgetEventBus, WidgetProvider, WidgetRenderer, applyCaseControl, applyDecimalPrecision, applyMask, applySharedGeoHierarchyToValues, collectGeoWidgetRegistrationsFromWidgets, createGeoLevelMnemonicResolver, createWidgetStore, createZodSchema, defaultTheme, evaluateCondition, evaluateWidgetConditions, filterByCharacterType, formatCurrency, formatDate, formatNumber, formatPhone, formatValue, geoHierarchyBuilder, getApiDataSource, getCachedApiDataSource, getFormattedNumberLength, getGeoDescendantWidgetIds, getGeoGroupId, getGeoWidgetRegistrationsInGroup, getSchemaDataSource, getStaticDataSource, getValueByPath, getWidgetValue, hasVisibilityRules, initI18n, isAllowedKey, isUpstreamGeoAncestor, normalizeNumericDefault, normalizeOptionRules, orderGeoWidgetRegistrations, parseDataPath, parseNumber, rebuildGeoHierarchyFromRegistrations, reconcileGeoHierarchiesInValues, registerDefaultWidgets, registerGeoWidget, registerGeoWidgetParent, removeMask, resetAll, resetAndSeedGeoHierarchyFromValues, resetWidget, resolveGeoWidgetLevelLabel, resolveGeoWidgetLevelValue, resolveTheme, resolveWidgetIdValue, seedGeoHierarchyFromValues, setDataSource, setError, setLoading, setTouched, setValue, setValueByPath, setValues, setWidgetValue, shouldEnableWidget, shouldRequireWidget, shouldShowWidget, transformDataSourceOptions, translatePanelConfig, translateUISchema, translateWidgetConfig, unregisterGeoWidget, unregisterGeoWidgetParent, useBaseWidget, useGeoWidgetCascade, useWidgetCascade, useWidgetContext, useWidgetEventBus, useWidgetTheme, useWidgetTranslation, validateNumericValue, validateWidget, widgetRegistry };
1894
+ export type { ApiAdapter, ApiDataSource$1 as ApiDataSource, BaseWidgetConfig, BooleanControlType, BooleanRepresentation, CaseControl, CharacterType, ConditionOperator, DataSource, DataSourceRequestHandler, DataSourceType, GeoLevelConfig, GeoLevelData, GeoWidgetRegistration, InputMask, NumericType, PanelConfig, RoundingMode, SchemaDataSource, SectionBuilderProps, SectionChanges, SectionConfig, SectionMode, SectionRendererProps, SectionsContainerProps, SectionsFormHandle, StaticDataSource, SupportingDocumentConfig, TextAlign, TreeNode, TreeNodeType, UISchema, UseBaseWidgetOptions, ValidationType, WidgetCascadeConfig, WidgetCondition, WidgetConditionState, WidgetContextValue, WidgetDataPath, WidgetDispatch, WidgetEvent, WidgetEventType, WidgetFormat, WidgetGeoConfig, WidgetOptionRule, WidgetOptions, WidgetRegistryEntry, WidgetRenderFunction, WidgetRootState, WidgetState, WidgetStore, WidgetTheme, WidgetThemeButton, WidgetThemeColors, WidgetThemePanel, WidgetThemeSection, WidgetThemeWidget, WidgetValidation, WidgetValue };
package/dist/index.esm.js CHANGED
@@ -2243,12 +2243,145 @@ const geoHierarchyBuilder = new GeoHierarchyBuilder();
2243
2243
  /** Sentinel written to Redux when a geo level is cleared by cascade (distinct from "never set"). */
2244
2244
  const GEO_LEVEL_CLEARED = null;
2245
2245
  const geoWidgetParentRegistry = new Map();
2246
+ const geoWidgetConfigRegistry = new Map();
2246
2247
  function registerGeoWidgetParent(widgetId, parentWidgetId) {
2247
2248
  geoWidgetParentRegistry.set(widgetId, parentWidgetId || null);
2248
2249
  }
2249
2250
  function unregisterGeoWidgetParent(widgetId) {
2250
2251
  geoWidgetParentRegistry.delete(widgetId);
2251
2252
  }
2253
+ function registerGeoWidget(widgetId, geoConfig, dataPath) {
2254
+ if (typeof dataPath !== 'string') {
2255
+ return;
2256
+ }
2257
+ const parentWidgetId = geoConfig.parentWidgetId?.trim() ? geoConfig.parentWidgetId : null;
2258
+ registerGeoWidgetParent(widgetId, parentWidgetId);
2259
+ geoWidgetConfigRegistry.set(widgetId, {
2260
+ widgetId,
2261
+ parentWidgetId,
2262
+ level: geoConfig.level,
2263
+ geoConfig,
2264
+ dataPath,
2265
+ groupId: getGeoGroupId(dataPath),
2266
+ });
2267
+ }
2268
+ function unregisterGeoWidget(widgetId) {
2269
+ unregisterGeoWidgetParent(widgetId);
2270
+ geoWidgetConfigRegistry.delete(widgetId);
2271
+ }
2272
+ function orderGeoWidgetRegistrations(registrations) {
2273
+ if (registrations.length <= 1) {
2274
+ return registrations;
2275
+ }
2276
+ const roots = registrations.filter((entry) => !entry.parentWidgetId);
2277
+ if (roots.length === 0) {
2278
+ return registrations;
2279
+ }
2280
+ const ordered = [];
2281
+ let current = roots[0];
2282
+ const visited = new Set();
2283
+ while (current && !visited.has(current.widgetId)) {
2284
+ visited.add(current.widgetId);
2285
+ ordered.push(current);
2286
+ current = registrations.find((entry) => entry.parentWidgetId === current.widgetId);
2287
+ }
2288
+ return ordered.length > 0 ? ordered : registrations;
2289
+ }
2290
+ function resolveLevelValueId(rawValue) {
2291
+ if (rawValue === null || rawValue === undefined || rawValue === '') {
2292
+ return null;
2293
+ }
2294
+ if (typeof rawValue === 'string' || typeof rawValue === 'number') {
2295
+ return String(rawValue);
2296
+ }
2297
+ if (typeof rawValue === 'object') {
2298
+ const id = rawValue.level_value_id || rawValue.id || rawValue.value;
2299
+ return id != null && id !== '' ? String(id) : null;
2300
+ }
2301
+ return null;
2302
+ }
2303
+ function resolveStoredMnemonic(values, registration, valueId) {
2304
+ const stored = getWidgetValue(values, registration.dataPath, registration.widgetId);
2305
+ const hierarchy = stored?.hierarchy || stored?.geo_code_hierarchy_json?.hierarchy;
2306
+ if (!Array.isArray(hierarchy)) {
2307
+ return undefined;
2308
+ }
2309
+ const levelData = hierarchy.find((entry) => entry.level === registration.level);
2310
+ if (levelData && String(levelData.level_value_id) === String(valueId)) {
2311
+ return levelData.level_value_mnemonic ? String(levelData.level_value_mnemonic) : undefined;
2312
+ }
2313
+ return undefined;
2314
+ }
2315
+ /** Resolve display mnemonic from cached dropdown options, then stored hierarchy. */
2316
+ function createGeoLevelMnemonicResolver(values, dataSources) {
2317
+ return (registration, valueId) => {
2318
+ const options = dataSources[registration.widgetId];
2319
+ const option = options?.find((entry) => String(entry.value) === String(valueId));
2320
+ if (option?.label) {
2321
+ return option.label;
2322
+ }
2323
+ return resolveStoredMnemonic(values, registration, valueId);
2324
+ };
2325
+ }
2326
+ /** Rebuild group hierarchy from widget values in parent→child order; stop at first missing level. */
2327
+ function rebuildGeoHierarchyFromRegistrations(groupId, values, registrations, resolveMnemonic) {
2328
+ const ordered = orderGeoWidgetRegistrations(registrations.filter((entry) => entry.groupId === groupId));
2329
+ geoHierarchyBuilder.clear(groupId);
2330
+ for (const registration of ordered) {
2331
+ const rawValue = resolveGeoWidgetLevelValue(values, registration.widgetId, registration.dataPath, registration.geoConfig);
2332
+ const valueId = resolveLevelValueId(rawValue);
2333
+ if (!valueId) {
2334
+ break;
2335
+ }
2336
+ const mnemonic = resolveMnemonic?.(registration, valueId) ??
2337
+ resolveStoredMnemonic(values, registration, valueId) ??
2338
+ valueId;
2339
+ geoHierarchyBuilder.addLevel(registration.level, valueId, mnemonic, groupId);
2340
+ }
2341
+ return geoHierarchyBuilder.buildHierarchyJson(groupId) !== null;
2342
+ }
2343
+ function collectGeoWidgetRegistrationsFromWidgets(widgets, namespace) {
2344
+ return widgets
2345
+ .filter((widget) => widget['widget-geo-config'] && typeof widget['widget-data-path'] === 'string')
2346
+ .map((widget) => {
2347
+ const originalWidgetId = widget['widget-id'];
2348
+ const originalDataPath = widget['widget-data-path'];
2349
+ const geoConfig = widget['widget-geo-config'];
2350
+ const widgetId = namespace ? `${namespace}__${originalWidgetId}` : originalWidgetId;
2351
+ const parentWidgetId = geoConfig.parentWidgetId?.trim()
2352
+ ? (namespace ? `${namespace}__${geoConfig.parentWidgetId}` : geoConfig.parentWidgetId)
2353
+ : null;
2354
+ const dataPath = namespace ? `${namespace}.${originalDataPath}` : originalDataPath;
2355
+ return {
2356
+ widgetId,
2357
+ parentWidgetId,
2358
+ level: geoConfig.level,
2359
+ geoConfig,
2360
+ dataPath,
2361
+ groupId: getGeoGroupId(dataPath),
2362
+ };
2363
+ });
2364
+ }
2365
+ /** Reconcile all geo groups in section values before save. */
2366
+ function reconcileGeoHierarchiesInValues(values, registrations, dataSources = {}) {
2367
+ const groupIds = [...new Set(registrations.map((entry) => entry.groupId))];
2368
+ let updatedValues = values;
2369
+ const resolveMnemonic = createGeoLevelMnemonicResolver(updatedValues, dataSources);
2370
+ for (const groupId of groupIds) {
2371
+ const groupRegistrations = registrations.filter((entry) => entry.groupId === groupId);
2372
+ const dataPath = groupRegistrations[0]?.dataPath;
2373
+ const widgetId = groupRegistrations[0]?.widgetId;
2374
+ if (!dataPath || !widgetId) {
2375
+ continue;
2376
+ }
2377
+ rebuildGeoHierarchyFromRegistrations(groupId, updatedValues, groupRegistrations, resolveMnemonic);
2378
+ updatedValues = applySharedGeoHierarchyToValues(updatedValues, groupId, dataPath, widgetId);
2379
+ }
2380
+ return updatedValues;
2381
+ }
2382
+ function getGeoWidgetRegistrationsInGroup(groupId) {
2383
+ return orderGeoWidgetRegistrations([...geoWidgetConfigRegistry.values()].filter((entry) => entry.groupId === groupId));
2384
+ }
2252
2385
  /** True when changedWidgetId is any upstream geo parent of widgetId (not only immediate parent). */
2253
2386
  function isUpstreamGeoAncestor(changedWidgetId, widgetId, immediateParentWidgetId) {
2254
2387
  if (changedWidgetId === widgetId) {
@@ -2343,7 +2476,7 @@ function resetAndSeedGeoHierarchyFromValues(values, dataPath, widgetId, groupId)
2343
2476
 
2344
2477
  // Define stable empty arrays to avoid selector reference issues
2345
2478
  const EMPTY_ERRORS = [];
2346
- const EMPTY_DATA_SOURCE$1 = [];
2479
+ const EMPTY_DATA_SOURCE = [];
2347
2480
  const useBaseWidget = (options) => {
2348
2481
  const { config, dataSourceRequestHandler: propHandler, schemaData, onValueChange } = options;
2349
2482
  const dispatch = useDispatch();
@@ -2358,7 +2491,7 @@ const useBaseWidget = (options) => {
2358
2491
  const errors = useSelector((state) => state.widget.errors[widgetId] ?? EMPTY_ERRORS);
2359
2492
  const touched = useSelector((state) => state.widget.touched[widgetId] || false);
2360
2493
  const loading = useSelector((state) => state.widget.loading[widgetId] || false);
2361
- const dataSourceOptions = useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE$1);
2494
+ const dataSourceOptions = useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE);
2362
2495
  // Skip value handling for layout widgets (they don't store data values)
2363
2496
  // Infer layout from widget-type
2364
2497
  const isLayoutWidget = config['widget-type'] === 'layout';
@@ -2886,8 +3019,6 @@ const useWidgetCascade = (options) => {
2886
3019
  }, [cascadeConfig, eventBus, dataSource, widgetId, dispatch]);
2887
3020
  };
2888
3021
 
2889
- // Define stable empty array to avoid selector reference issues
2890
- const EMPTY_DATA_SOURCE = [];
2891
3022
  /**
2892
3023
  * Hook for geo widget cascade functionality
2893
3024
  * Handles geo hierarchy building and cascade behavior
@@ -2917,15 +3048,15 @@ const useGeoWidgetCascade = (options) => {
2917
3048
  ? resolveGeoWidgetLevelValue(state.widget.values, widgetId, dataPath, geoConfig)
2918
3049
  : state.widget.values[widgetId]);
2919
3050
  // Memoize selector to avoid returning new array reference
2920
- const dataSourceOptions = useSelector((state) => state.widget.dataSources[widgetId] ?? EMPTY_DATA_SOURCE);
3051
+ const allDataSources = useSelector((state) => state.widget.dataSources);
2921
3052
  // Register parent chain for upstream-ancestor detection (grandparent → grandchild reset)
2922
3053
  useEffect(() => {
2923
- if (!geoConfig) {
3054
+ if (!geoConfig || typeof dataPath !== 'string') {
2924
3055
  return;
2925
3056
  }
2926
- registerGeoWidgetParent(widgetId, geoConfig.parentWidgetId);
2927
- return () => unregisterGeoWidgetParent(widgetId);
2928
- }, [widgetId, geoConfig]);
3057
+ registerGeoWidget(widgetId, geoConfig, dataPath);
3058
+ return () => unregisterGeoWidget(widgetId);
3059
+ }, [widgetId, geoConfig, dataPath]);
2929
3060
  // Keep in-memory builder in sync with persisted hierarchy (reload, cancel→re-edit, etc.)
2930
3061
  useEffect(() => {
2931
3062
  if (!geoConfig || typeof dataPath !== 'string') {
@@ -3017,18 +3148,20 @@ const useGeoWidgetCascade = (options) => {
3017
3148
  }, [geoConfig, eventBus, dataSource, widgetId, dataPath, dispatch, groupId]);
3018
3149
  // Handle value changes to build hierarchy
3019
3150
  useEffect(() => {
3020
- if (!geoConfig) {
3151
+ if (!geoConfig || typeof dataPath !== 'string') {
3021
3152
  return;
3022
3153
  }
3023
- // Skip if value is undefined (it might still be loading or rehydrating)
3154
+ const { level, isLastLevel } = geoConfig;
3155
+ const groupRegistrations = getGeoWidgetRegistrationsInGroup(groupId);
3156
+ const applyGroupRebuild = () => {
3157
+ const resolveMnemonic = createGeoLevelMnemonicResolver(valuesRef.current, allDataSources);
3158
+ rebuildGeoHierarchyFromRegistrations(groupId, valuesRef.current, groupRegistrations, resolveMnemonic);
3159
+ dispatch(setValues(applySharedGeoHierarchyToValues(valuesRef.current, groupId, dataPath, widgetId)));
3160
+ };
3024
3161
  // ONLY clear hierarchy if the value is explicitly null or empty string (user action)
3025
3162
  if (currentValue === null || currentValue === '') {
3026
- const { level, isLastLevel } = geoConfig;
3027
3163
  geoHierarchyBuilder.removeLevelAndBelow(level, groupId);
3028
- // If we have a dataPath, we need to update Redux with the cleared hierarchy
3029
- if (dataPath) {
3030
- dispatch(setValues(applySharedGeoHierarchyToValues(valuesRef.current, groupId, dataPath, widgetId)));
3031
- }
3164
+ applyGroupRebuild();
3032
3165
  if (!isLastLevel && eventBus && lastCascadePublishRef.current !== GEO_LEVEL_CLEARED) {
3033
3166
  lastCascadePublishRef.current = GEO_LEVEL_CLEARED;
3034
3167
  eventBus.publish({
@@ -3041,56 +3174,13 @@ const useGeoWidgetCascade = (options) => {
3041
3174
  return;
3042
3175
  }
3043
3176
  if (currentValue === undefined) {
3044
- return; // Skip if undefined (still initializing)
3045
- }
3046
- const { level, isLastLevel } = geoConfig;
3047
- // Check if hierarchy is already built to prevent endless loops
3048
- if (dataPath) {
3049
- const currentHierarchy = getWidgetValue(valuesRef.current, dataPath, widgetId);
3050
- // If hierarchy JSON is already set and matches current value, skip rebuilding
3051
- if (currentHierarchy && typeof currentHierarchy === 'object') {
3052
- // Check if this specific level's value matches the hierarchy
3053
- const hierarchyArray = currentHierarchy.hierarchy || currentHierarchy.geo_code_hierarchy_json?.hierarchy;
3054
- if (Array.isArray(hierarchyArray)) {
3055
- const currentLevelValue = typeof currentValue === 'object'
3056
- ? (currentValue.level_value_id || currentValue.id || currentValue.value)
3057
- : currentValue;
3058
- const levelData = hierarchyArray.find((l) => l.level === geoConfig.level);
3059
- // If this level is already correctly represented in the hierarchy, skip rebuilding
3060
- // String conversion ensures comparison works for mixed types
3061
- if (levelData && String(levelData.level_value_id) === String(currentLevelValue)) {
3062
- return;
3063
- }
3064
- }
3177
+ const hasOwnValue = Object.prototype.hasOwnProperty.call(valuesRef.current, widgetId);
3178
+ if (!hasOwnValue) {
3179
+ return;
3065
3180
  }
3066
3181
  }
3067
- // Extract level_value_id and level_value_mnemonic from current value
3068
- // The value could be the ID itself or an object with id/name
3069
- let level_value_id;
3070
- let level_value_mnemonic;
3071
- if (typeof currentValue === 'string' || typeof currentValue === 'number') {
3072
- // Value is just the ID, need to find mnemonic from data source
3073
- level_value_id = String(currentValue);
3074
- // Try to get mnemonic from data source options
3075
- const option = dataSourceOptions.find((opt) => opt.value === currentValue);
3076
- level_value_mnemonic = option?.label || String(currentValue);
3077
- }
3078
- else if (currentValue && typeof currentValue === 'object') {
3079
- level_value_id = currentValue.level_value_id || currentValue.id || currentValue.value;
3080
- level_value_mnemonic = currentValue.level_value_mnemonic || currentValue.name || currentValue.label;
3081
- }
3082
- else {
3083
- return;
3084
- }
3085
- // When a widget's own value changes, remove this level and all below from hierarchy first
3086
- geoHierarchyBuilder.removeLevelAndBelow(level, groupId);
3087
- // Add level to hierarchy
3088
- geoHierarchyBuilder.addLevel(level, level_value_id, level_value_mnemonic, groupId);
3089
- // Build and store hierarchy JSON on every change
3090
- if (dataPath && geoHierarchyBuilder.buildHierarchyJson(groupId)) {
3091
- dispatch(setValues(applySharedGeoHierarchyToValues(valuesRef.current, groupId, dataPath, widgetId)));
3092
- }
3093
- }, [geoConfig, currentValue, widgetId, dataPath, dispatch, dataSourceOptions, groupId]);
3182
+ applyGroupRebuild();
3183
+ }, [geoConfig, currentValue, widgetId, dataPath, dispatch, allDataSources, groupId, eventBus]);
3094
3184
  };
3095
3185
 
3096
3186
  class WidgetRegistry {
@@ -4992,7 +5082,12 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
4992
5082
  // This ensures we use the original widget IDs and data paths
4993
5083
  const sectionWidgets = collectWidgets(originalSection.panels);
4994
5084
  const currentState = store.getState().widget;
4995
- const currentSchemaData = currentState.values || {};
5085
+ let currentSchemaData = currentState.values || {};
5086
+ const geoRegistrations = collectGeoWidgetRegistrationsFromWidgets(sectionWidgets, namespace);
5087
+ if (geoRegistrations.length > 0) {
5088
+ currentSchemaData = reconcileGeoHierarchiesInValues(currentSchemaData, geoRegistrations, currentState.dataSources || {});
5089
+ dispatch(setValues(currentSchemaData));
5090
+ }
4996
5091
  const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch, true);
4997
5092
  if (!isSectionValid) {
4998
5093
  return;
@@ -5058,7 +5153,12 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
5058
5153
  if (isDraft !== false && store && onSectionSave) {
5059
5154
  const sectionWidgets = collectWidgets(originalSection.panels);
5060
5155
  const currentState = store.getState().widget;
5061
- const currentSchemaData = currentState.values || {};
5156
+ let currentSchemaData = currentState.values || {};
5157
+ const geoRegistrations = collectGeoWidgetRegistrationsFromWidgets(sectionWidgets, namespace);
5158
+ if (geoRegistrations.length > 0) {
5159
+ currentSchemaData = reconcileGeoHierarchiesInValues(currentSchemaData, geoRegistrations, currentState.dataSources || {});
5160
+ dispatch(setValues(currentSchemaData));
5161
+ }
5062
5162
  const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch, true);
5063
5163
  if (!isSectionValid)
5064
5164
  return;
@@ -12946,5 +13046,5 @@ const translateUISchema = (schema, translate) => {
12946
13046
  };
12947
13047
  };
12948
13048
 
12949
- export { ArrayWidget, BooleanWidget, CheckboxWidget, CurrencyInputWidget, DateInputWidget, DateTimeInputWidget, DialogTableWidget, DisplayWidget, FileInputWidget, GEO_LEVEL_CLEARED, HeaderSectionWidget, IdAuthenticationWidget, IterableAccordionWidget, JSONEditorPanel, MultiSelectWidget, NumberInputWidget, PanelRenderer, PhoneInputWidget, ProfileWidget, PropertyEditor, RadioWidget, RegisterLookupWidget, ScoresDisplayWidget, SectionBuilder, SectionRenderer, SectionTree, SectionsContainer, SelectWidget, SimpleTableWidget, TableWidget, TextAreaWidget, TextInputWidget, VisualBuilderPanel, WidgetEventBus, WidgetProvider, WidgetRenderer, applyCaseControl, applyDecimalPrecision, applyMask, applySharedGeoHierarchyToValues, createWidgetStore, createZodSchema, defaultTheme, evaluateCondition, evaluateWidgetConditions, filterByCharacterType, formatCurrency, formatDate, formatNumber, formatPhone, formatValue, geoHierarchyBuilder, getApiDataSource, getCachedApiDataSource, getFormattedNumberLength, getGeoDescendantWidgetIds, getGeoGroupId, getSchemaDataSource, getStaticDataSource, getValueByPath, getWidgetValue, hasVisibilityRules, initI18n, isAllowedKey, isUpstreamGeoAncestor, normalizeNumericDefault, normalizeOptionRules, parseDataPath, parseNumber, registerDefaultWidgets, registerGeoWidgetParent, removeMask, resetAll, resetAndSeedGeoHierarchyFromValues, resetWidget, resolveGeoWidgetLevelLabel, resolveGeoWidgetLevelValue, resolveTheme, resolveWidgetIdValue, seedGeoHierarchyFromValues, setDataSource, setError, setLoading, setTouched, setValue, setValueByPath, setValues, setWidgetValue, shouldEnableWidget, shouldRequireWidget, shouldShowWidget, transformDataSourceOptions, translatePanelConfig, translateUISchema, translateWidgetConfig, unregisterGeoWidgetParent, useBaseWidget, useGeoWidgetCascade, useWidgetCascade, useWidgetContext, useWidgetEventBus, useWidgetTheme, useWidgetTranslation, validateNumericValue, validateWidget, widgetRegistry };
13049
+ export { ArrayWidget, BooleanWidget, CheckboxWidget, CurrencyInputWidget, DateInputWidget, DateTimeInputWidget, DialogTableWidget, DisplayWidget, FileInputWidget, GEO_LEVEL_CLEARED, HeaderSectionWidget, IdAuthenticationWidget, IterableAccordionWidget, JSONEditorPanel, MultiSelectWidget, NumberInputWidget, PanelRenderer, PhoneInputWidget, ProfileWidget, PropertyEditor, RadioWidget, RegisterLookupWidget, ScoresDisplayWidget, SectionBuilder, SectionRenderer, SectionTree, SectionsContainer, SelectWidget, SimpleTableWidget, TableWidget, TextAreaWidget, TextInputWidget, VisualBuilderPanel, WidgetEventBus, WidgetProvider, WidgetRenderer, applyCaseControl, applyDecimalPrecision, applyMask, applySharedGeoHierarchyToValues, collectGeoWidgetRegistrationsFromWidgets, createGeoLevelMnemonicResolver, createWidgetStore, createZodSchema, defaultTheme, evaluateCondition, evaluateWidgetConditions, filterByCharacterType, formatCurrency, formatDate, formatNumber, formatPhone, formatValue, geoHierarchyBuilder, getApiDataSource, getCachedApiDataSource, getFormattedNumberLength, getGeoDescendantWidgetIds, getGeoGroupId, getGeoWidgetRegistrationsInGroup, getSchemaDataSource, getStaticDataSource, getValueByPath, getWidgetValue, hasVisibilityRules, initI18n, isAllowedKey, isUpstreamGeoAncestor, normalizeNumericDefault, normalizeOptionRules, orderGeoWidgetRegistrations, parseDataPath, parseNumber, rebuildGeoHierarchyFromRegistrations, reconcileGeoHierarchiesInValues, registerDefaultWidgets, registerGeoWidget, registerGeoWidgetParent, removeMask, resetAll, resetAndSeedGeoHierarchyFromValues, resetWidget, resolveGeoWidgetLevelLabel, resolveGeoWidgetLevelValue, resolveTheme, resolveWidgetIdValue, seedGeoHierarchyFromValues, setDataSource, setError, setLoading, setTouched, setValue, setValueByPath, setValues, setWidgetValue, shouldEnableWidget, shouldRequireWidget, shouldShowWidget, transformDataSourceOptions, translatePanelConfig, translateUISchema, translateWidgetConfig, unregisterGeoWidget, unregisterGeoWidgetParent, useBaseWidget, useGeoWidgetCascade, useWidgetCascade, useWidgetContext, useWidgetEventBus, useWidgetTheme, useWidgetTranslation, validateNumericValue, validateWidget, widgetRegistry };
12950
13050
  //# sourceMappingURL=index.esm.js.map