@openg2p/registry-widgets 0.2.1 → 1.0.1

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.
package/README.md CHANGED
@@ -16,9 +16,14 @@ The Registry UI Widget Library is a layered, extensible system that enables you
16
16
  - ✅ **Data Sources** (static, API, schema reference)
17
17
  - ✅ **Formatting** (dates, currency, phone numbers, numbers)
18
18
  - ✅ **Widget Registry** system for extensible plugin architecture
19
- - ✅ **19+ Pre-built Widgets** ready to use
19
+ - ✅ **20 Pre-built Widgets** ready to use (including HeaderSection)
20
20
  - ✅ **Internationalization** support via i18next
21
21
  - ✅ **Tailwind CSS** ready (unstyled base, you provide styles)
22
+ - ✅ **Multi-mode Section Rendering** (RegistryView, CRView, IntakeForm)
23
+ - ✅ **Geo Hierarchy Cascading Dropdowns** for location-based fields
24
+ - ✅ **Section Builder** with visual and JSON editor for UI schemas
25
+ - ✅ **Form Handle API** for host-driven validation and submission
26
+ - ✅ **Dirty Tracking** with unsaved changes detection per section
22
27
 
23
28
  ## Installation
24
29
 
@@ -77,7 +82,7 @@ The library follows a layered architecture that separates concerns and enables e
77
82
 
78
83
  ┌─────────────────────────────────────────┐
79
84
  │ Widget Components Layer │
80
- │ (19+ Pre-built Widgets)
85
+ │ (20 Pre-built Widgets)
81
86
  └─────────────────────────────────────────┘
82
87
 
83
88
  ┌─────────────────────────────────────────┐
@@ -102,7 +107,7 @@ The library follows a layered architecture that separates concerns and enables e
102
107
 
103
108
  **Widget Registry Layer** - A plugin system that maintains a catalog of available widgets. When a widget is requested by name, the registry looks it up and returns the corresponding React component. This enables dynamic widget loading and easy extensibility - new widgets can be registered without modifying core library code.
104
109
 
105
- **Widget Components Layer** - The actual React components that render UI elements (text inputs, selects, tables, etc.). These are the 19+ pre-built widgets that come with the library. Each widget is a React component that receives configuration and renders the appropriate UI. Custom widgets can be added by registering them in the registry.
110
+ **Widget Components Layer** - The actual React components that render UI elements (text inputs, selects, tables, etc.). These are the 20 pre-built widgets that come with the library. Each widget is a React component that receives configuration and renders the appropriate UI. Custom widgets can be added by registering them in the registry.
106
111
 
107
112
  **Core Hooks Layer** - React hooks that provide all the business logic for widgets. The `useBaseWidget` hook handles state management, validation, conditional logic, data source loading, and formatting. The `useWidgetTranslation` hook provides internationalization support. Widget components use these hooks to get values, errors, visibility states, and change handlers without directly interacting with Redux or utilities.
108
113
 
@@ -224,25 +229,92 @@ Support for multiple validation strategies:
224
229
 
225
230
  ## Available Widgets
226
231
 
227
- The library includes 19+ pre-built widgets:
232
+ The library includes 20 pre-built widgets:
228
233
 
229
234
  - **Input Widgets**: TextInput, TextArea, NumberInput, CurrencyInput, DateInput, DateTimeInput, PhoneInput, FileInput
230
235
  - **Selection Widgets**: Select, Radio, Checkbox, Boolean
231
236
  - **Layout Widgets**: Array, IterableAccordion
232
237
  - **Display Widgets**: Display, Profile
233
238
  - **Table Widgets**: Table, SimpleTable
239
+ - **Section Widgets**: HeaderSection
234
240
 
235
- > 📚 **Widget documentation coming soon!** Detailed guides for each widget will be available in our tutorial pages.
241
+ ### HeaderSection Widget
242
+
243
+ A full-width header card designed for registry record views. Displays a profile image, record name, functional ID, status badge, and audit metadata (created by / approved by) in a responsive two-column layout. Supports editable status and status-reason fields with data source-driven dropdowns, customisable label overrides via i18n, and configurable status-colour mapping.
244
+
245
+ ```json
246
+ {
247
+ "widget": "header-section",
248
+ "widget-type": "group",
249
+ "widget-id": "registry-header",
250
+ "widget-data-path": {
251
+ "image": "record_image_storage_id",
252
+ "name": "record_name",
253
+ "functionalId": "functional_record_id",
254
+ "status": "record_status"
255
+ }
256
+ }
257
+ ```
258
+
259
+ ## Section Modes
260
+
261
+ `SectionsContainer` supports three display modes via the `mode` prop:
262
+
263
+ ### RegistryView (default)
264
+
265
+ Standard registry display. Sections render in a CSS Grid layout with an inline **Edit Details** button. Only one section can be in edit mode at a time; editing a section opens it as a portal-based overlay with save/cancel controls.
266
+
267
+ ### CRView (Change Request View)
268
+
269
+ Read-only comparison view for change requests. Sections display **Created by** / **Approved by** metadata and support `changeRequestType` labels (`"new"` / `"old"`) for side-by-side comparison.
270
+
271
+ ### IntakeForm
272
+
273
+ Accordion-based registration form. Sections expand and collapse, with **Prev** / **Next** navigation buttons. Supports `isDraft` mode (editable vs read-only), per-section validation on save, and status badges (**Saved** / **Modified and not saved**).
274
+
275
+ ## Form Handle API
276
+
277
+ `SectionsContainer` exposes a `SectionsFormHandle` via the `onFormReady` callback, enabling host applications to drive form submission externally:
278
+
279
+ ```tsx
280
+ <SectionsContainer
281
+ sections={sections}
282
+ mode="IntakeForm"
283
+ onFormReady={(handle) => {
284
+ // handle.validate() – validate all sections, returns boolean
285
+ // handle.getFormData() – raw store data (no validation)
286
+ // handle.validateAndGetData() – validate then return SectionChanges[]
287
+ // handle.getStructuredData() – get records and files without validation
288
+ }}
289
+ />
290
+ ```
291
+
292
+ ## Geo Hierarchy Cascading Dropdowns
293
+
294
+ The `useGeoWidgetCascade` hook and `geoHierarchyBuilder` utility provide cascading dropdown functionality for geographic location fields (e.g. Country > State > City). Changes in a parent level automatically reload and reset child dropdowns via the widget event bus.
295
+
296
+ ## Section Builder
297
+
298
+ A visual UI schema editor shipped as `SectionBuilder`, with sub-components:
299
+
300
+ - **JSONEditorPanel** — Live JSON editor (powered by `json-edit-react`) for direct schema manipulation
301
+ - **VisualBuilderPanel** — Drag-and-drop visual layout editor
302
+ - **SectionTree** — Tree view of the section/panel/widget hierarchy
303
+ - **PropertyEditor** — Contextual property panel for the selected node
236
304
 
237
305
  ## Examples
238
306
 
239
307
  See the `examples/` directory for comprehensive examples demonstrating:
240
308
 
241
- - Basic widget usage
242
- - Layout widgets
243
- - Schema internationalization
244
- - Comparison views
245
- - And more...
309
+ - Basic widget usage (`usage-example.tsx`)
310
+ - Layout widgets (`LayoutWidgets.tsx`)
311
+ - Schema internationalization (`schema-i18n-example.tsx`)
312
+ - Comparison views (`comparison-view-example.tsx`)
313
+ - Section rendering modes (`section-renderer-example.tsx`)
314
+ - Intake form flow (`intake-form-example.tsx`)
315
+ - Header section widget (`header-section-example.tsx`)
316
+ - Section builder (`section-builder-example.tsx`)
317
+ - JSON editor standalone (`jsoneditor-standalone-example.tsx`)
246
318
 
247
319
  ## API Reference
248
320
 
@@ -280,10 +352,36 @@ Registry for managing widget components.
280
352
 
281
353
  ### Components
282
354
 
283
- - `SectionsContainer` - Container for rendering sections
284
- - `SectionRenderer` - Renders individual sections
355
+ - `SectionsContainer` - Container for rendering sections with mode support (RegistryView, CRView, IntakeForm)
356
+ - `SectionRenderer` - Renders individual sections with edit mode, dirty tracking, and accordion support
285
357
  - `PanelRenderer` - Renders panels within sections
286
358
  - `FilePreviewModal` - Modal for file preview
359
+ - `SectionBuilder` - Visual UI schema editor
360
+ - `JSONEditorPanel` - JSON editor for UI schemas
361
+ - `VisualBuilderPanel` - Visual layout builder
362
+ - `SectionTree` - Tree view of section hierarchy
363
+ - `PropertyEditor` - Property editor for selected nodes
364
+
365
+ ### Hooks
366
+
367
+ - `useBaseWidget` - Core hook for widget state, validation, conditional logic, and formatting
368
+ - `useWidgetTranslation` - i18n hook for widget labels and messages
369
+ - `useWidgetEventBus` - Pub/sub event bus for inter-widget communication
370
+ - `useWidgetCascade` - Cascading dropdown behaviour between linked widgets
371
+ - `useGeoWidgetCascade` - Geo hierarchy cascading for location-based dropdowns
372
+
373
+ ### Utilities
374
+
375
+ - `pathUtils` - Dot-notation path read/write for nested data structures
376
+ - `validation` - Built-in, regex, and Zod validation
377
+ - `formatting` - Date, currency, phone, number, and text formatting
378
+ - `conditions` - Conditional show/hide and enable/disable evaluation
379
+ - `dataSource` - Static, API, and schema reference data loading
380
+ - `geoHierarchy` - Geo hierarchy builder for location cascades
381
+ - `sectionValidate` - Section-level validation across all widgets
382
+ - `buildSectionChanges` - Build change payloads from section data
383
+ - `schemaNamespace` - Namespace section configs for multi-instance rendering
384
+ - `schemaTranslation` - Translate UI schemas, widget configs, and panel configs
287
385
 
288
386
  ## Contributing
289
387
 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C;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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,wGAAwG;IACxG,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAEpE,wHAAwH;IACxH,oBAAoB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACrE,0JAA0J;IAC1J,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACpD;AA4ED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,yMAa/B,sBAAsB,4CAqSxB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { resolveTheme } from '../theme';
2
+ export type ResolvedTheme = ReturnType<typeof resolveTheme>;
3
+ export declare const ThemeContext: import("react").Context<Required<{
4
+ colors: Required<import("../theme").WidgetThemeColors>;
5
+ section: Required<import("../theme").WidgetThemeSection>;
6
+ panel: Required<import("../theme").WidgetThemePanel>;
7
+ button: Required<import("../theme").WidgetThemeButton>;
8
+ widget: Required<import("../theme").WidgetThemeWidget>;
9
+ }>>;
10
+ /**
11
+ * Access the resolved widget theme from any component inside `<WidgetProvider>`.
12
+ *
13
+ * ```tsx
14
+ * const theme = useWidgetTheme();
15
+ * // theme.colors.primary, theme.section.dividerColor, etc.
16
+ * ```
17
+ */
18
+ export declare function useWidgetTheme(): ResolvedTheme;
19
+ //# sourceMappingURL=useWidgetTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWidgetTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useWidgetTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,YAAY,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAE5D,eAAO,MAAM,YAAY;;;;;;GAA6C,CAAC;AAEvE;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,aAAa,CAE9C"}
package/dist/index.esm.js CHANGED
@@ -3541,41 +3541,22 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
3541
3541
  }
3542
3542
  return section;
3543
3543
  }, [section, namespace]);
3544
- // Create namespaced schemaData if namespace is provided
3545
- // This ensures widgets can read initial values from schemaData at namespaced paths
3544
+ // Create namespaced schemaData if namespace is provided.
3545
+ // Widgets with namespaced data-paths (e.g. "rv-section-0.a1a4d25a.birth_date")
3546
+ // need a nested object at values[namespace] so getValueByPath can traverse it.
3546
3547
  const namespacedSchemaData = useMemo(() => {
3547
3548
  if (!namespace || !currentSchemaData) {
3548
3549
  return schemaData;
3549
3550
  }
3550
- // Create a namespaced version of schemaData by copying values to namespaced paths
3551
- const namespaced = { ...currentSchemaData };
3552
- // Copy all top-level keys to namespaced paths
3553
- Object.keys(currentSchemaData).forEach(key => {
3554
- const namespacedKey = `${namespace}.${key}`;
3555
- if (!(namespacedKey in namespaced)) {
3556
- namespaced[namespacedKey] = currentSchemaData[key];
3557
- }
3558
- });
3559
- // Also handle nested objects - copy nested values to namespaced paths
3560
- const copyNestedValues = (obj, prefix = '') => {
3561
- if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
3562
- Object.keys(obj).forEach(key => {
3563
- const fullPath = prefix ? `${prefix}.${key}` : key;
3564
- const namespacedPath = `${namespace}.${fullPath}`;
3565
- if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
3566
- copyNestedValues(obj[key], fullPath);
3567
- // Also set the nested object at the namespaced path
3568
- setValueByPath(namespaced, namespacedPath, obj[key]);
3569
- }
3570
- else {
3571
- setValueByPath(namespaced, namespacedPath, obj[key]);
3572
- }
3573
- });
3574
- }
3575
- };
3576
- copyNestedValues(currentSchemaData);
3577
- return namespaced;
3551
+ return { ...currentSchemaData, [namespace]: currentSchemaData };
3578
3552
  }, [namespace, schemaData, currentSchemaData]);
3553
+ // Populate the store with namespaced schema data so that namespaced widgets
3554
+ // can read their initial values via getValueByPath on the namespaced paths.
3555
+ useEffect(() => {
3556
+ if (namespace && namespacedSchemaData) {
3557
+ dispatch(setValues(namespacedSchemaData));
3558
+ }
3559
+ }, [namespace, namespacedSchemaData, dispatch]);
3579
3560
  const crViewData = useMemo(() => {
3580
3561
  if (mode !== 'CRView')
3581
3562
  return null;
@@ -3937,6 +3918,8 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
3937
3918
  const baselineSnapshotRef = useRef(null);
3938
3919
  // IntakeForm only: increment when baseline is updated after save - forces badge to update (refs don't trigger re-renders)
3939
3920
  const [intakeFormBaselineTrigger, setIntakeFormBaselineTrigger] = useState(0);
3921
+ // IntakeForm only: tracks whether the user has actually saved this section (prevents "Saved" badge on initial load)
3922
+ const [hasBeenSavedByUser, setHasBeenSavedByUser] = useState(false);
3940
3923
  // IntakeForm: treat as edit mode for dirty tracking when isDraft. RegistryView: use isEditMode.
3941
3924
  const effectiveEditModeForDirty = mode === 'IntakeForm' ? (isDraft !== false) : isEditMode;
3942
3925
  // Compute isDirty: compare current store state to baseline (only when in edit mode)
@@ -3979,18 +3962,68 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
3979
3962
  const intakeFormSectionStatus = useMemo(() => {
3980
3963
  if (mode !== 'IntakeForm' || isDraft === false)
3981
3964
  return null;
3982
- const hasValue = (v) => v !== undefined && v !== null && (typeof v !== 'string' || v.trim().length > 0);
3983
- const currentSnapshot = buildSectionSnapshot(storeValues, namespace);
3984
- const record = currentSnapshot.records?.[0];
3985
- const hasData = record &&
3986
- typeof record === 'object' &&
3987
- Object.values(record).some((v) => hasValue(v));
3988
3965
  if (isDirty)
3989
3966
  return 'modified';
3990
- if (hasData)
3967
+ if (hasBeenSavedByUser)
3991
3968
  return 'saved';
3992
3969
  return null;
3993
- }, [mode, isDirty, storeValues, namespace, buildSectionSnapshot]);
3970
+ }, [mode, isDirty, hasBeenSavedByUser]);
3971
+ // Revert store values to the original schemaData for this section's widgets.
3972
+ // Used by both handleSave (RegistryView raises a CR, so values should not persist)
3973
+ // and handleCancel.
3974
+ const revertToOriginalValues = useCallback(() => {
3975
+ const sectionWidgets = collectWidgets(originalSection.panels);
3976
+ const oldSchemaData = schemaData || contextSchemaData;
3977
+ const currentStoreValues = store.getState().widget.values;
3978
+ let newStoreValues = currentStoreValues;
3979
+ sectionWidgets.forEach(widget => {
3980
+ const originalWidgetId = widget['widget-id'];
3981
+ const namespacedWidgetId = namespace ? `${namespace}__${originalWidgetId}` : originalWidgetId;
3982
+ const widgetId = namespacedWidgetId;
3983
+ const originalDataPath = widget['widget-data-path'];
3984
+ const storeDataPath = namespace && originalDataPath
3985
+ ? (typeof originalDataPath === 'string'
3986
+ ? `${namespace}.${originalDataPath}`
3987
+ : Object.fromEntries(Object.entries(originalDataPath).map(([key, path]) => [key, `${namespace}.${path}`])))
3988
+ : originalDataPath;
3989
+ if (widgetId && originalDataPath) {
3990
+ let oldValue;
3991
+ if (typeof originalDataPath === 'object') {
3992
+ oldValue = {};
3993
+ Object.entries(originalDataPath).forEach(([key, path]) => {
3994
+ if (typeof path === 'string') {
3995
+ oldValue[key] = getValueByPath(oldSchemaData, path);
3996
+ }
3997
+ });
3998
+ }
3999
+ else if (typeof originalDataPath === 'string') {
4000
+ oldValue = getValueByPath(oldSchemaData, originalDataPath);
4001
+ }
4002
+ if (oldValue !== undefined) {
4003
+ newStoreValues = setWidgetValue(newStoreValues, storeDataPath, widgetId, oldValue);
4004
+ // Also revert the widgetId-based entry — useBaseWidget.handleChange
4005
+ // sets values[widgetId] during editing, and useBaseWidget.currentValue
4006
+ // reads values[widgetId] first before falling through to the dataPath.
4007
+ newStoreValues = { ...newStoreValues, [widgetId]: oldValue };
4008
+ }
4009
+ }
4010
+ });
4011
+ if (hasSupportingDocuments) {
4012
+ const originalSupportingDocuments = originalSection['section-supporting-documents'] || [];
4013
+ originalSupportingDocuments.forEach((doc, index) => {
4014
+ const widgetId = `supporting-doc-${sectionId}-${index}`;
4015
+ const originalDataPath = doc['document-data-path'];
4016
+ const storeDataPath = namespace && originalDataPath
4017
+ ? `${namespace}.${originalDataPath}`
4018
+ : originalDataPath;
4019
+ const oldValue = getValueByPath(oldSchemaData, originalDataPath);
4020
+ newStoreValues = setWidgetValue(newStoreValues, storeDataPath, widgetId, oldValue);
4021
+ });
4022
+ }
4023
+ if (newStoreValues !== currentStoreValues) {
4024
+ dispatch(setValues(newStoreValues));
4025
+ }
4026
+ }, [originalSection, schemaData, contextSchemaData, store, namespace, hasSupportingDocuments, sectionId, dispatch]);
3994
4027
  // Handle save button click
3995
4028
  const handleSave = async () => {
3996
4029
  if (!store || !onSectionSave) {
@@ -4040,6 +4073,12 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
4040
4073
  console.error('Section Changes Save failed', error);
4041
4074
  }
4042
4075
  }
4076
+ // In RegistryView, save raises a CR — the actual data update follows a
4077
+ // separate approval workflow, so revert the displayed values to the
4078
+ // originals so the view doesn't show unapproved edits.
4079
+ if (mode === 'RegistryView') {
4080
+ revertToOriginalValues();
4081
+ }
4043
4082
  setIsEditMode(false);
4044
4083
  onEditModeChange?.(originalSectionId, false);
4045
4084
  };
@@ -4085,6 +4124,7 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
4085
4124
  if (mode === 'IntakeForm') {
4086
4125
  baselineSnapshotRef.current = buildSectionSnapshot(currentSchemaData, namespace);
4087
4126
  setIntakeFormBaselineTrigger((prev) => prev + 1);
4127
+ setHasBeenSavedByUser(true);
4088
4128
  }
4089
4129
  onSectionDirtyChange?.(sectionId, false);
4090
4130
  }
@@ -4093,64 +4133,7 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
4093
4133
  }, [store, onSectionSave, onSectionSaveSuccess, sectionIndex, originalSection, schemaData, contextSchemaData, namespace, hasSupportingDocuments, dbSectionId, sectionRegisterId, dispatch, buildSectionSnapshot, sectionId, onSectionDirtyChange, mode, isDraft]);
4094
4134
  // Handle cancel button click
4095
4135
  const handleCancel = () => {
4096
- // Revert values in store to original schema data
4097
- // Use original section (without namespace) for collecting widgets
4098
- const sectionWidgets = collectWidgets(originalSection.panels);
4099
- const oldSchemaData = schemaData || contextSchemaData;
4100
- const currentStoreValues = store.getState().widget.values;
4101
- let newStoreValues = currentStoreValues;
4102
- sectionWidgets.forEach(widget => {
4103
- const originalWidgetId = widget['widget-id'];
4104
- // If namespace was used, we need to use namespaced widget ID and data path
4105
- const namespacedWidgetId = namespace ? `${namespace}__${originalWidgetId}` : originalWidgetId;
4106
- const widgetId = namespacedWidgetId;
4107
- const originalDataPath = widget['widget-data-path'];
4108
- // If namespace was used, data path in store is namespaced, but we read from original schema using original path
4109
- const storeDataPath = namespace && originalDataPath
4110
- ? (typeof originalDataPath === 'string'
4111
- ? `${namespace}.${originalDataPath}`
4112
- : Object.fromEntries(Object.entries(originalDataPath).map(([key, path]) => [key, `${namespace}.${path}`])))
4113
- : originalDataPath;
4114
- if (widgetId && originalDataPath) {
4115
- // Handle multi-path (object) or single path (string)
4116
- // Read from original schema data using original paths
4117
- let oldValue;
4118
- if (typeof originalDataPath === 'object') {
4119
- // Multi-path: get values for each path
4120
- oldValue = {};
4121
- Object.entries(originalDataPath).forEach(([key, path]) => {
4122
- if (typeof path === 'string') {
4123
- oldValue[key] = getValueByPath(oldSchemaData, path);
4124
- }
4125
- });
4126
- }
4127
- else if (typeof originalDataPath === 'string') {
4128
- oldValue = getValueByPath(oldSchemaData, originalDataPath);
4129
- }
4130
- // Set in store using namespaced data path (if namespace was used)
4131
- if (oldValue !== undefined) {
4132
- newStoreValues = setWidgetValue(newStoreValues, storeDataPath, widgetId, oldValue);
4133
- }
4134
- }
4135
- });
4136
- // Also revert supporting documents if any
4137
- if (hasSupportingDocuments) {
4138
- // Use original section's supporting documents to get original data paths
4139
- const originalSupportingDocuments = originalSection['section-supporting-documents'] || [];
4140
- originalSupportingDocuments.forEach((doc, index) => {
4141
- const widgetId = `supporting-doc-${sectionId}-${index}`;
4142
- const originalDataPath = doc['document-data-path'];
4143
- // If namespace was used, data path in store is namespaced
4144
- const storeDataPath = namespace && originalDataPath
4145
- ? `${namespace}.${originalDataPath}`
4146
- : originalDataPath;
4147
- const oldValue = getValueByPath(oldSchemaData, originalDataPath);
4148
- newStoreValues = setWidgetValue(newStoreValues, storeDataPath, widgetId, oldValue);
4149
- });
4150
- }
4151
- if (newStoreValues !== currentStoreValues) {
4152
- dispatch(setValues(newStoreValues));
4153
- }
4136
+ revertToOriginalValues();
4154
4137
  setIsEditMode(false);
4155
4138
  onEditModeChange?.(originalSectionId, false);
4156
4139
  };
@@ -4716,6 +4699,9 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
4716
4699
  }, []);
4717
4700
  const safeSections = sections ?? [];
4718
4701
  const prevSectionsLengthRef = useRef(safeSections.length);
4702
+ // Stable ref for namespace so formHandle useMemo doesn't depend on the (possibly inline) function identity
4703
+ const namespaceRef = useRef(namespace);
4704
+ namespaceRef.current = namespace;
4719
4705
  // Track dirty (unsaved changes) per section for form handle validation
4720
4706
  const sectionDirtyMapRef = useRef({});
4721
4707
  const handleSectionDirtyChange = useCallback((sectionId, isDirty) => {
@@ -4761,11 +4747,14 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
4761
4747
  // Form handle for onFormReady - allows host to validate and get all section data from its own Submit button
4762
4748
  const formHandle = useMemo(() => {
4763
4749
  const getValues = () => store.getState().widget?.values || {};
4764
- const getNamespace = (section, index) => namespace
4765
- ? typeof namespace === 'string'
4766
- ? namespace
4767
- : namespace(section['section-id'], index)
4768
- : undefined;
4750
+ const getNamespace = (section, index) => {
4751
+ const ns = namespaceRef.current;
4752
+ return ns
4753
+ ? typeof ns === 'string'
4754
+ ? ns
4755
+ : ns(section['section-id'], index)
4756
+ : undefined;
4757
+ };
4769
4758
  const checkNoUnsavedChanges = () => {
4770
4759
  const hasDirty = Object.values(sectionDirtyMapRef.current).some(Boolean);
4771
4760
  if (hasDirty) {
@@ -4815,7 +4804,7 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
4815
4804
  return results;
4816
4805
  },
4817
4806
  };
4818
- }, [store, dispatch, safeSections, namespace]);
4807
+ }, [store, dispatch, safeSections]);
4819
4808
  // Call onFormReady when form is ready (sections loaded)
4820
4809
  useEffect(() => {
4821
4810
  if (onFormReady && safeSections.length > 0) {
@@ -9104,16 +9093,6 @@ const HeaderSectionWidget = ({ config }) => {
9104
9093
  const statusColor = statusColors[String(statusValue).toLowerCase()] || '#6B7280';
9105
9094
  // ── Scoped class for CSS isolation ────────────────────────────
9106
9095
  const cls = `header-section-widget-${widgetConfig['widget-id']}`;
9107
- // ── Indicator dot component ───────────────────────────────────
9108
- const Dot = ({ color }) => (jsxRuntimeExports.jsx("span", { style: {
9109
- display: 'inline-block',
9110
- width: 8,
9111
- height: 8,
9112
- borderRadius: '50%',
9113
- backgroundColor: color,
9114
- flexShrink: 0,
9115
- marginTop: 6,
9116
- } }));
9117
9096
  // ── RENDER ────────────────────────────────────────────────────
9118
9097
  return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: `
9119
9098
  .${cls} {
@@ -9282,7 +9261,7 @@ const HeaderSectionWidget = ({ config }) => {
9282
9261
  .parentElement?.querySelector('.hdr-avatar-placeholder');
9283
9262
  if (placeholder)
9284
9263
  placeholder.style.display = 'flex';
9285
- } })) : null, jsxRuntimeExports.jsx("div", { className: "hdr-avatar-placeholder", style: { display: imageUrl ? 'none' : 'flex' }, children: jsxRuntimeExports.jsx("img", { src: img$f, alt: "Profile Placeholder" }) })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-info", children: [displayName && jsxRuntimeExports.jsx("div", { className: "hdr-name", children: displayName }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsx(Dot, { color: "#9CA3AF" }), jsxRuntimeExports.jsxs("span", { className: "hdr-field-label", children: [getLabel('functionalId'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: functionalId || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsx(Dot, { color: isReadonly ? statusColor : '#F59E0B' }), jsxRuntimeExports.jsx("span", { className: "hdr-field-label", children: getLabel('status') }), isReadonly ? (statusLabel ? (jsxRuntimeExports.jsx("span", { className: "hdr-status-badge", style: { backgroundColor: statusColor }, children: statusLabel })) : (jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: "-" }))) : (jsxRuntimeExports.jsxs("select", { className: "hdr-select", value: statusValue, onChange: (e) => updateFieldValue('status', e.target.value), children: [jsxRuntimeExports.jsx("option", { value: "", children: getLabel('select') }), statusOptions.map((opt) => (jsxRuntimeExports.jsx("option", { value: opt.value, children: opt.label }, opt.value)))] }))] }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsx(Dot, { color: isReadonly ? '#9CA3AF' : '#F59E0B' }), jsxRuntimeExports.jsxs("span", { className: "hdr-field-label", children: [getLabel('statusReason'), " :"] }), isReadonly ? (jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: statusReason || '-' })) : (jsxRuntimeExports.jsx("input", { type: "text", className: "hdr-input", value: statusReason, placeholder: getLabel('enterReason'), onChange: (e) => updateFieldValue('statusReason', e.target.value) }))] })] })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-right", children: [jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('createdBy'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: createdBy || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('createdAt'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: createdAt || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('lastApprovedBy'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: lastApprovedBy || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('lastApprovedAt'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: lastApprovedAt || '-' })] })] })] })] }));
9264
+ } })) : null, jsxRuntimeExports.jsx("div", { className: "hdr-avatar-placeholder", style: { display: imageUrl ? 'none' : 'flex' }, children: jsxRuntimeExports.jsx("img", { src: img$f, alt: "Profile Placeholder" }) })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-info", children: [displayName && jsxRuntimeExports.jsx("div", { className: "hdr-name", children: displayName }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-field-label", children: [getLabel('functionalId'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: functionalId || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsx("span", { className: "hdr-field-label", children: getLabel('status') }), isReadonly ? (statusLabel ? (jsxRuntimeExports.jsx("span", { className: "hdr-status-badge", style: { backgroundColor: statusColor }, children: statusLabel })) : (jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: "-" }))) : (jsxRuntimeExports.jsxs("select", { className: "hdr-select", value: statusValue, onChange: (e) => updateFieldValue('status', e.target.value), children: [jsxRuntimeExports.jsx("option", { value: "", children: getLabel('select') }), statusOptions.map((opt) => (jsxRuntimeExports.jsx("option", { value: opt.value, children: opt.label }, opt.value)))] }))] }), jsxRuntimeExports.jsxs("div", { className: "hdr-field-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-field-label", children: [getLabel('statusReason'), " :"] }), isReadonly ? (jsxRuntimeExports.jsx("span", { className: "hdr-field-value", children: statusReason || '-' })) : (jsxRuntimeExports.jsx("input", { type: "text", className: "hdr-input", value: statusReason, placeholder: getLabel('enterReason'), onChange: (e) => updateFieldValue('statusReason', e.target.value) }))] })] })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-right", children: [jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('createdBy'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: createdBy || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('createdAt'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: createdAt || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('lastApprovedBy'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: lastApprovedBy || '-' })] }), jsxRuntimeExports.jsxs("div", { className: "hdr-meta-row", children: [jsxRuntimeExports.jsxs("span", { className: "hdr-meta-label", children: [getLabel('lastApprovedAt'), " :"] }), jsxRuntimeExports.jsx("span", { className: "hdr-meta-value", children: lastApprovedAt || '-' })] })] })] })] }));
9286
9265
  };
9287
9266
 
9288
9267
  /**