@openg2p/registry-widgets 1.1.2 → 1.1.3-dev.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/dist/index.js CHANGED
@@ -406,9 +406,8 @@ const createZodSchema = (validation, required = false) => {
406
406
  const normalizeBooleanLike = (val) => {
407
407
  if (val === true || val === 1)
408
408
  return true;
409
- if (val === false || val === 0 || val === null || val === undefined || val === '') {
409
+ if (val === false || val === 0)
410
410
  return false;
411
- }
412
411
  if (typeof val === 'string') {
413
412
  const normalized = val.trim().toLowerCase();
414
413
  return normalized === 'true' || normalized === 'yes' || normalized === '1';
@@ -423,8 +422,11 @@ const evaluateCondition = (condition, allValues) => {
423
422
  const { operator, value } = condition;
424
423
  switch (operator) {
425
424
  case 'equals':
426
- if (typeof value === 'boolean' || typeof fieldValue === 'boolean') {
427
- return normalizeBooleanLike(fieldValue) === normalizeBooleanLike(value);
425
+ if (typeof value === 'boolean') {
426
+ return typeof fieldValue === 'boolean' && fieldValue === value;
427
+ }
428
+ if (typeof fieldValue === 'boolean') {
429
+ return fieldValue === normalizeBooleanLike(value);
428
430
  }
429
431
  return fieldValue === value;
430
432
  case 'notEquals':
@@ -10089,6 +10091,40 @@ const TableWidget = ({ config }) => {
10089
10091
  };
10090
10092
 
10091
10093
  const isUnsetRowValue = (value) => value === null || value === undefined || value === '';
10094
+ const buildDialogConditionValues = (row, columns) => {
10095
+ let context = { ...row };
10096
+ columns.forEach((col) => {
10097
+ const columnKey = col['column-key'];
10098
+ if (!columnKey || row[columnKey] === undefined) {
10099
+ return;
10100
+ }
10101
+ const dataPath = col['widget-data-path'];
10102
+ if (typeof dataPath === 'string' && dataPath) {
10103
+ context = setValueByPath(context, dataPath, row[columnKey]);
10104
+ }
10105
+ });
10106
+ return context;
10107
+ };
10108
+ const buildDialogColumnSegments = (columns) => {
10109
+ const segments = [];
10110
+ let index = 0;
10111
+ while (index < columns.length) {
10112
+ const group = columns[index]['column-group'];
10113
+ if (group) {
10114
+ const groupCols = [];
10115
+ while (index < columns.length && columns[index]['column-group'] === group) {
10116
+ groupCols.push(columns[index]);
10117
+ index += 1;
10118
+ }
10119
+ segments.push({ type: 'group', group, cols: groupCols });
10120
+ }
10121
+ else {
10122
+ segments.push({ type: 'single', col: columns[index] });
10123
+ index += 1;
10124
+ }
10125
+ }
10126
+ return segments;
10127
+ };
10092
10128
  /** Match TableWidget cell styling for add / update / delete rows */
10093
10129
  const getRowCellStyle = (editAction) => {
10094
10130
  if (editAction === 'ADD') {
@@ -10116,7 +10152,7 @@ const SelectDisplayValue = ({ config, value }) => {
10116
10152
  return jsxRuntimeExports.jsx("span", { children: selectedOption ? selectedOption.label : String(value) });
10117
10153
  };
10118
10154
  /** Isolated dialog field — avoids re-running data-source effects when sibling fields update. */
10119
- const DialogTableField = React.memo(function DialogTableField({ col, cellWidgetId, dialogRowValues, isReadonly, }) {
10155
+ const DialogTableField = React.memo(function DialogTableField({ col, cellWidgetId, dialogConditionValues, isReadonly, }) {
10120
10156
  const widgetType = col.widget || 'text';
10121
10157
  const fieldConfig = React.useMemo(() => {
10122
10158
  return {
@@ -10129,9 +10165,9 @@ const DialogTableField = React.memo(function DialogTableField({ col, cellWidgetI
10129
10165
  'widget-data-path': undefined,
10130
10166
  'widget-data-default': col['widget-data-default'],
10131
10167
  'widget-data-options': undefined,
10132
- 'widget-required': shouldRequireWidget(col['widget-data-options'], dialogRowValues, col['widget-required']),
10168
+ 'widget-required': shouldRequireWidget(col['widget-data-options'], dialogConditionValues, col['widget-required']),
10133
10169
  };
10134
- }, [col, cellWidgetId, dialogRowValues, isReadonly, widgetType]);
10170
+ }, [col, cellWidgetId, dialogConditionValues, isReadonly, widgetType]);
10135
10171
  return (jsxRuntimeExports.jsx("div", { className: "min-w-0", children: jsxRuntimeExports.jsx(WidgetRenderer, { config: fieldConfig }) }));
10136
10172
  });
10137
10173
  /**
@@ -10268,12 +10304,14 @@ const DialogTableWidget = ({ config }) => {
10268
10304
  return row;
10269
10305
  });
10270
10306
  const dialogRowValues = dialogStoreValues;
10307
+ const dialogConditionValues = React.useMemo(() => buildDialogConditionValues(dialogRowValues, columns), [dialogRowValues, columns]);
10271
10308
  const collectMergedRowPayload = React.useCallback(() => dialogStoreValues, [dialogStoreValues]);
10272
10309
  const finalizeDialogRowPayload = React.useCallback((raw) => {
10310
+ const conditionValues = buildDialogConditionValues(raw, columns);
10273
10311
  const result = {};
10274
10312
  columns.forEach((col) => {
10275
10313
  const key = col['column-key'];
10276
- if (!shouldShowWidget(col['widget-data-options'], raw)) {
10314
+ if (!shouldShowWidget(col['widget-data-options'], conditionValues)) {
10277
10315
  return;
10278
10316
  }
10279
10317
  const val = raw[key];
@@ -10285,6 +10323,7 @@ const DialogTableWidget = ({ config }) => {
10285
10323
  }, [columns]);
10286
10324
  const saveDialog = React.useCallback(() => {
10287
10325
  const payload = collectMergedRowPayload();
10326
+ const conditionValues = buildDialogConditionValues(payload, columns);
10288
10327
  let hasErrors = false;
10289
10328
  columns.forEach((col) => {
10290
10329
  const key = col['column-key'];
@@ -10292,10 +10331,10 @@ const DialogTableWidget = ({ config }) => {
10292
10331
  const isColReadonly = isReadonly || col['widget-readonly'] === true;
10293
10332
  if (isColReadonly)
10294
10333
  return;
10295
- if (!shouldShowWidget(col['widget-data-options'], payload))
10334
+ if (!shouldShowWidget(col['widget-data-options'], conditionValues))
10296
10335
  return;
10297
10336
  const cellValue = payload[key];
10298
- const isRequired = shouldRequireWidget(col['widget-data-options'], payload, col['widget-required']);
10337
+ const isRequired = shouldRequireWidget(col['widget-data-options'], conditionValues, col['widget-required']);
10299
10338
  const validationErrors = validateWidget(cellValue, col['widget-data-validation'], isRequired);
10300
10339
  if (validationErrors && validationErrors.length > 0) {
10301
10340
  hasErrors = true;
@@ -10370,7 +10409,28 @@ const DialogTableWidget = ({ config }) => {
10370
10409
  return formatValue(cellValue, column['widget-data-format'], column.widget);
10371
10410
  return String(cellValue);
10372
10411
  }, [rows]);
10373
- const visibleDialogColumns = React.useMemo(() => columns.filter((col) => shouldShowWidget(col['widget-data-options'], dialogRowValues)), [columns, dialogRowValues]);
10412
+ const dialogColumnSegments = React.useMemo(() => {
10413
+ return buildDialogColumnSegments(columns)
10414
+ .map((segment) => {
10415
+ if (segment.type === 'single') {
10416
+ if (!shouldShowWidget(segment.col['widget-data-options'], dialogConditionValues)) {
10417
+ return null;
10418
+ }
10419
+ return segment;
10420
+ }
10421
+ const visibleCols = segment.cols.filter((col) => shouldShowWidget(col['widget-data-options'], dialogConditionValues));
10422
+ if (visibleCols.length === 0) {
10423
+ return null;
10424
+ }
10425
+ return { type: 'group', group: segment.group, cols: visibleCols };
10426
+ })
10427
+ .filter((segment) => segment !== null);
10428
+ }, [columns, dialogConditionValues]);
10429
+ const renderDialogField = (col) => {
10430
+ const key = col['column-key'];
10431
+ const cellWidgetId = dialogFieldWidgetId(dialogSessionId, key);
10432
+ return (jsxRuntimeExports.jsx(DialogTableField, { col: col, cellWidgetId: cellWidgetId, dialogConditionValues: dialogConditionValues, isReadonly: isReadonly }, `${dialogSessionId}-${key}`));
10433
+ };
10374
10434
  const tableWidgetId = `dialog-table-widget-${widgetConfig['widget-id']}`;
10375
10435
  const columnSpan = widgetConfig['widget-column-span'] || 2;
10376
10436
  const minWidth = columnSpan * 200;
@@ -10442,10 +10502,11 @@ const DialogTableWidget = ({ config }) => {
10442
10502
  cursor: 'pointer',
10443
10503
  fontSize: '20px',
10444
10504
  lineHeight: 1,
10445
- }, "aria-label": "Close", children: "\u00D7" })] }), jsxRuntimeExports.jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", style: { maxHeight: '70vh', overflow: 'auto' }, children: visibleDialogColumns.map((col) => {
10446
- const key = col['column-key'];
10447
- const cellWidgetId = dialogFieldWidgetId(dialogSessionId, key);
10448
- return (jsxRuntimeExports.jsx(DialogTableField, { col: col, cellWidgetId: cellWidgetId, dialogRowValues: dialogRowValues, isReadonly: isReadonly }, `${dialogSessionId}-${key}`));
10505
+ }, "aria-label": "Close", children: "\u00D7" })] }), jsxRuntimeExports.jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", style: { maxHeight: '70vh', overflow: 'auto' }, children: dialogColumnSegments.map((segment) => {
10506
+ if (segment.type === 'single') {
10507
+ return renderDialogField(segment.col);
10508
+ }
10509
+ return (jsxRuntimeExports.jsx("div", { className: "md:col-span-2 grid grid-cols-1 md:grid-cols-2 gap-4", children: segment.cols.map((col) => renderDialogField(col)) }, `${dialogSessionId}-group-${segment.group}`));
10449
10510
  }) }, `dialog-fields-${dialogSessionId}`), jsxRuntimeExports.jsxs("div", { className: "flex justify-end gap-3 mt-6", children: [jsxRuntimeExports.jsx("button", { type: "button", onClick: closeDialog, className: "px-4 py-2 text-sm font-medium", style: {
10450
10511
  borderRadius: 'var(--owt-btn-border-radius, 10px)',
10451
10512
  border: '1px solid var(--owt-btn-secondary-border, #C4C4C4)',