@synerise/ds-condition 2.0.8 → 2.0.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.
- package/CHANGELOG.md +11 -0
- package/CLAUDE.md +2 -1
- package/README.md +1 -0
- package/dist/Condition.js +66 -30
- package/dist/Condition.types.d.ts +24 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -0
- package/dist/index.d.ts +1 -1
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.9](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@2.0.8...@synerise/ds-condition@2.0.9) (2026-09-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* condition allows hosts to skip auto-opening the next field on a value swap ([c7835e7](https://github.com/Synerise/synerise-design/commit/c7835e7e20691447aeee13b521c860b576d1eef8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.0.8](https://github.com/Synerise/synerise-design/compare/@synerise/ds-condition@2.0.7...@synerise/ds-condition@2.0.8) (2026-09-22)
|
|
7
18
|
|
|
8
19
|
|
package/CLAUDE.md
CHANGED
|
@@ -53,6 +53,7 @@ Primary component. No `forwardRef`.
|
|
|
53
53
|
| `onDeactivate` | `(stepId, conditionId) => void` | — | Fires when active field is blurred/cleared. |
|
|
54
54
|
| `texts` | `Partial<ConditionTexts>` | see `useTranslations` | Override any label. Uses `react-intl` defaults. |
|
|
55
55
|
| `autoClearCondition` | `boolean` | `false` | When `true`, changing subject/context/parameter clears downstream values. |
|
|
56
|
+
| `shouldAutoOpenNextField` | `(change: ConditionFieldChange) => boolean` | — | Return `false` to suppress the active-field advance (and the row clearing that goes with it) for that change; only the matching `onChange*` still fires. |
|
|
56
57
|
| `readOnly` | `boolean` | `false` | Disables all editing; hides add/remove/duplicate controls. |
|
|
57
58
|
| `singleStepCondition` | `boolean` | — | Hides step CRUD and drag handle (single-step mode). |
|
|
58
59
|
| `showActionAttribute` | `boolean` | — | Renders action-attribute selector after subject/context selection. |
|
|
@@ -176,7 +177,7 @@ Merges the `texts` prop with react-intl defaults. Requires `IntlProvider` in the
|
|
|
176
177
|
## Implementation notes
|
|
177
178
|
|
|
178
179
|
- **Controlled-only** — the component holds no data state. All step and condition data lives in the parent. The component only manages UI state: which step/condition/field is currently active (`currentStepId`, `currentConditionId`, `currentField`).
|
|
179
|
-
- **Active-field state machine** — selecting a subject auto-advances focus to `parameter` (or `actionAttribute` if `showActionAttribute`). Selecting a parameter advances to `operator`. Selecting an operator advances to `factor`. This is implemented via `setCurrentField` calls in `selectSubject`, `selectContext`, `selectParameter`, `selectOperator`.
|
|
180
|
+
- **Active-field state machine** — selecting a subject auto-advances focus to `parameter` (or `actionAttribute` if `showActionAttribute`). Selecting a parameter advances to `operator`. Selecting an operator advances to `factor`. This is implemented via `setCurrentField` calls in `selectSubject`, `selectContext`, `selectParameter`, `selectOperator`. Hosts that update a value without a user picking it (an id swap, a migration) pass `shouldAutoOpenNextField` returning `false` so the row is left as it is.
|
|
180
181
|
- **Drag is only enabled** when both `onChangeOrder` is provided AND `steps.length > 1`. The drag handle and `SortableContainer` are always rendered; the handle just has no effect without these.
|
|
181
182
|
- **`autoClearCondition`** — when `true`, changing subject/context also fires `onChangeParameter`, `onChangeOperator`, `onChangeFactorValue` with `undefined` for all existing conditions, and removes all conditions beyond the first. This clears downstream values but the parent must still handle the callbacks to update its state.
|
|
182
183
|
- **`hoverDisabled`** is also set automatically on steps that are not the currently active step (`currentStepId !== step.id`), creating a "focus" effect.
|
package/README.md
CHANGED
|
@@ -117,6 +117,7 @@ import Condition from '@synerise/ds-condition'
|
|
|
117
117
|
| removeStep | Callback called when user clicks on remove step button | (stepId: React.ReactText) => void | - |
|
|
118
118
|
| onChangeOrder | Callback called when user change order of steps | (order: ConditionStep[]) => void | - |
|
|
119
119
|
| autoClearCondition | Automatically fires clearing values of dependent elements | Boolean | false |
|
|
120
|
+
| shouldAutoOpenNextField | Return false to keep the active field where it is after a change, so only the onChange* callback fires | (change: ConditionFieldChange) => boolean | - |
|
|
120
121
|
| minConditionsLength | Minimal length of conditions in step | number | - |
|
|
121
122
|
| maxConditionsLength | Maximal length of conditions in step | number \ undefined | - |
|
|
122
123
|
| onChangeContext | Callback called when user change value of step context | (stepId: React.ReactText, value: ContextItem \ ContextGroup \ undefined) => void | - |
|
package/dist/Condition.js
CHANGED
|
@@ -7,7 +7,7 @@ import { usePrevious } from "@synerise/ds-utils";
|
|
|
7
7
|
import { Condition as Condition$1, StepWrapper, DragLabel, DragLabelPart, AddStepButton } from "./Condition.style.js";
|
|
8
8
|
import { ConditionStep } from "./ConditionStep/ConditionStep.js";
|
|
9
9
|
import { StepName } from "./ConditionStep/StepName/StepName.js";
|
|
10
|
-
import { DEFAULT_FIELD, DEFAULT_CONDITION, DEFAULT_STEP, PARAMETER, OPERATOR, ACTION_ATTRIBUTE,
|
|
10
|
+
import { DEFAULT_FIELD, DEFAULT_CONDITION, DEFAULT_STEP, PARAMETER, OPERATOR, SUBJECT, ACTION_ATTRIBUTE, CONTEXT, FACTOR, DEFAULT_INPUT_PROPS } from "./constants.js";
|
|
11
11
|
import { useTranslations } from "./hooks/useTranslations.js";
|
|
12
12
|
const Condition = (props) => {
|
|
13
13
|
const {
|
|
@@ -23,6 +23,7 @@ const Condition = (props) => {
|
|
|
23
23
|
minConditionsLength = 1,
|
|
24
24
|
maxConditionsLength,
|
|
25
25
|
autoClearCondition,
|
|
26
|
+
shouldAutoOpenNextField,
|
|
26
27
|
onChangeContext,
|
|
27
28
|
onChangeSubject,
|
|
28
29
|
onChangeParameter,
|
|
@@ -81,6 +82,7 @@ const Condition = (props) => {
|
|
|
81
82
|
setCurrentConditionId(newConditionId);
|
|
82
83
|
}
|
|
83
84
|
}, [currentConditionId, currentField, prevSteps, steps]);
|
|
85
|
+
const shouldAdvanceField = useCallback((change) => shouldAutoOpenNextField?.(change) !== false, [shouldAutoOpenNextField]);
|
|
84
86
|
const clearConditionRow = useCallback((stepId) => {
|
|
85
87
|
const step = steps.find((s) => s.id === stepId);
|
|
86
88
|
if (step === void 0 || step.conditions.length === 0) {
|
|
@@ -107,50 +109,84 @@ const Condition = (props) => {
|
|
|
107
109
|
}
|
|
108
110
|
}, [steps, removeCondition, addCondition, autoClearCondition, onChangeFactorValue, onChangeOperator, onChangeParameter]);
|
|
109
111
|
const selectSubject = useCallback((value, stepId) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
112
|
+
if (shouldAdvanceField({
|
|
113
|
+
field: SUBJECT,
|
|
114
|
+
stepId,
|
|
115
|
+
value
|
|
116
|
+
})) {
|
|
117
|
+
clearConditionRow(stepId);
|
|
118
|
+
setCurrentStepId(stepId);
|
|
119
|
+
if (showActionAttribute) {
|
|
120
|
+
setCurrentField(ACTION_ATTRIBUTE);
|
|
121
|
+
} else {
|
|
122
|
+
setCurrentField(PARAMETER);
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
onChangeSubject && onChangeSubject(stepId, value);
|
|
118
|
-
}, [clearConditionRow, onChangeSubject, showActionAttribute]);
|
|
126
|
+
}, [clearConditionRow, onChangeSubject, shouldAdvanceField, showActionAttribute]);
|
|
119
127
|
const selectContext = useCallback((value, stepId) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
128
|
+
if (shouldAdvanceField({
|
|
129
|
+
field: CONTEXT,
|
|
130
|
+
stepId,
|
|
131
|
+
value
|
|
132
|
+
})) {
|
|
133
|
+
clearConditionRow(stepId);
|
|
134
|
+
setCurrentStepId(stepId);
|
|
135
|
+
if (showActionAttribute) {
|
|
136
|
+
setCurrentField(ACTION_ATTRIBUTE);
|
|
137
|
+
} else {
|
|
138
|
+
setCurrentField(PARAMETER);
|
|
139
|
+
}
|
|
126
140
|
}
|
|
127
141
|
onChangeContext && onChangeContext(stepId, value);
|
|
128
|
-
}, [clearConditionRow, onChangeContext, showActionAttribute]);
|
|
142
|
+
}, [clearConditionRow, onChangeContext, shouldAdvanceField, showActionAttribute]);
|
|
129
143
|
const selectActionAttribute = useCallback((value, stepId) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
144
|
+
if (shouldAdvanceField({
|
|
145
|
+
field: ACTION_ATTRIBUTE,
|
|
146
|
+
stepId,
|
|
147
|
+
value
|
|
148
|
+
})) {
|
|
149
|
+
clearConditionRow(stepId);
|
|
150
|
+
setCurrentStepId(stepId);
|
|
151
|
+
setCurrentField(PARAMETER);
|
|
152
|
+
}
|
|
133
153
|
onChangeActionAttribute && onChangeActionAttribute(stepId, value);
|
|
134
|
-
}, [onChangeActionAttribute, clearConditionRow]);
|
|
154
|
+
}, [onChangeActionAttribute, clearConditionRow, shouldAdvanceField]);
|
|
135
155
|
const selectParameter = useCallback((stepId, conditionId, value) => {
|
|
136
156
|
if (conditionId && onChangeParameter) {
|
|
137
|
-
|
|
138
|
-
|
|
157
|
+
const advance = shouldAdvanceField({
|
|
158
|
+
field: PARAMETER,
|
|
159
|
+
stepId,
|
|
160
|
+
conditionId,
|
|
161
|
+
value
|
|
162
|
+
});
|
|
163
|
+
advance && autoClearCondition && onChangeOperator && onChangeOperator(stepId, conditionId, void 0);
|
|
164
|
+
advance && autoClearCondition && onChangeFactorValue && onChangeFactorValue(stepId, conditionId, void 0);
|
|
139
165
|
onChangeParameter(stepId, conditionId, value);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
166
|
+
if (advance) {
|
|
167
|
+
setCurrentConditionId(conditionId);
|
|
168
|
+
setCurrentStepId(stepId);
|
|
169
|
+
setCurrentField(OPERATOR);
|
|
170
|
+
}
|
|
143
171
|
}
|
|
144
|
-
}, [autoClearCondition, onChangeFactorValue, onChangeOperator, onChangeParameter]);
|
|
172
|
+
}, [autoClearCondition, onChangeFactorValue, onChangeOperator, onChangeParameter, shouldAdvanceField]);
|
|
145
173
|
const selectOperator = useCallback((stepId, conditionId, value) => {
|
|
146
174
|
if (conditionId && onChangeOperator && value && "groupId" in value) {
|
|
147
|
-
|
|
175
|
+
const advance = shouldAdvanceField({
|
|
176
|
+
field: OPERATOR,
|
|
177
|
+
stepId,
|
|
178
|
+
conditionId,
|
|
179
|
+
value
|
|
180
|
+
});
|
|
181
|
+
advance && autoClearCondition && onChangeFactorValue && onChangeFactorValue(stepId, conditionId, void 0);
|
|
148
182
|
onChangeOperator(stepId, conditionId, value);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
183
|
+
if (advance) {
|
|
184
|
+
setCurrentConditionId(conditionId);
|
|
185
|
+
setCurrentStepId(stepId);
|
|
186
|
+
setCurrentField(FACTOR);
|
|
187
|
+
}
|
|
152
188
|
}
|
|
153
|
-
}, [autoClearCondition, onChangeFactorValue, onChangeOperator]);
|
|
189
|
+
}, [autoClearCondition, onChangeFactorValue, onChangeOperator, shouldAdvanceField]);
|
|
154
190
|
const setStepConditionFactorType = useCallback((stepId, conditionId, factorType) => {
|
|
155
191
|
setCurrentConditionId(conditionId);
|
|
156
192
|
setCurrentStepId(stepId);
|
|
@@ -46,6 +46,29 @@ export type CustomParameterSelectorProps = Pick<FactorsProps, 'onActivate' | 'on
|
|
|
46
46
|
onSelectItem: FactorsProps['onChangeValue'];
|
|
47
47
|
selectedItem?: ParameterValueType;
|
|
48
48
|
};
|
|
49
|
+
export type ConditionFieldChange = {
|
|
50
|
+
field: 'context';
|
|
51
|
+
stepId: ReactText;
|
|
52
|
+
value: ContextItem | ContextGroup | undefined;
|
|
53
|
+
} | {
|
|
54
|
+
field: 'subject';
|
|
55
|
+
stepId: ReactText;
|
|
56
|
+
value: SubjectItem;
|
|
57
|
+
} | {
|
|
58
|
+
field: 'actionAttribute';
|
|
59
|
+
stepId: ReactText;
|
|
60
|
+
value: FactorValueType;
|
|
61
|
+
} | {
|
|
62
|
+
field: 'parameter';
|
|
63
|
+
stepId: ReactText;
|
|
64
|
+
conditionId: ReactText;
|
|
65
|
+
value: FactorValueType;
|
|
66
|
+
} | {
|
|
67
|
+
field: 'operator';
|
|
68
|
+
stepId: ReactText;
|
|
69
|
+
conditionId: ReactText;
|
|
70
|
+
value: OperatorsItem;
|
|
71
|
+
};
|
|
49
72
|
export type ConditionProps = {
|
|
50
73
|
steps: ConditionStep[];
|
|
51
74
|
getPopupContainerOverride?: (trigger: HTMLElement | null) => HTMLElement;
|
|
@@ -58,6 +81,7 @@ export type ConditionProps = {
|
|
|
58
81
|
minConditionsLength: number;
|
|
59
82
|
maxConditionsLength?: number | undefined;
|
|
60
83
|
autoClearCondition?: boolean;
|
|
84
|
+
shouldAutoOpenNextField?: (change: ConditionFieldChange) => boolean;
|
|
61
85
|
contextSelectorComponent?: ComponentType<CustomContextSelectorProps>;
|
|
62
86
|
parameterSelectorComponent?: ComponentType<FactorValueComponentProps>;
|
|
63
87
|
factorParameterSelectorComponent?: ComponentType<FactorValueComponentProps>;
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const OPERATOR = "operator";
|
|
|
5
5
|
export declare const PARAMETER = "parameter";
|
|
6
6
|
export declare const FACTOR = "factor";
|
|
7
7
|
export declare const SUBJECT = "subject";
|
|
8
|
+
export declare const CONTEXT = "context";
|
|
8
9
|
export declare const ACTION_ATTRIBUTE = "actionAttribute";
|
|
9
10
|
export declare const DEFAULT_INPUT_PROPS: {
|
|
10
11
|
autoResize: {
|
package/dist/constants.js
CHANGED
|
@@ -5,6 +5,7 @@ const OPERATOR = "operator";
|
|
|
5
5
|
const PARAMETER = "parameter";
|
|
6
6
|
const FACTOR = "factor";
|
|
7
7
|
const SUBJECT = "subject";
|
|
8
|
+
const CONTEXT = "context";
|
|
8
9
|
const ACTION_ATTRIBUTE = "actionAttribute";
|
|
9
10
|
const DEFAULT_INPUT_PROPS = {
|
|
10
11
|
autoResize: {
|
|
@@ -14,6 +15,7 @@ const DEFAULT_INPUT_PROPS = {
|
|
|
14
15
|
};
|
|
15
16
|
export {
|
|
16
17
|
ACTION_ATTRIBUTE,
|
|
18
|
+
CONTEXT,
|
|
17
19
|
DEFAULT_CONDITION,
|
|
18
20
|
DEFAULT_FIELD,
|
|
19
21
|
DEFAULT_INPUT_PROPS,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './Condition';
|
|
2
|
-
export type { ConditionProps, ConditionStep, ConditionStepCrudActions, ConditionTexts, StepConditions, } from './Condition.types';
|
|
2
|
+
export type { ConditionFieldChange, ConditionProps, ConditionStep, ConditionStepCrudActions, ConditionTexts, StepConditions, } from './Condition.types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-condition",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "Condition UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -42,18 +42,18 @@
|
|
|
42
42
|
],
|
|
43
43
|
"types": "dist/index.d.ts",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@synerise/ds-button": "^2.1.
|
|
46
|
-
"@synerise/ds-context-selector": "^2.1.
|
|
47
|
-
"@synerise/ds-cruds": "^2.0.
|
|
48
|
-
"@synerise/ds-factors": "^2.2.
|
|
49
|
-
"@synerise/ds-icon": "^2.
|
|
50
|
-
"@synerise/ds-inline-edit": "^2.0.
|
|
51
|
-
"@synerise/ds-input": "^2.0.
|
|
52
|
-
"@synerise/ds-operators": "^2.0.
|
|
45
|
+
"@synerise/ds-button": "^2.1.1",
|
|
46
|
+
"@synerise/ds-context-selector": "^2.1.3",
|
|
47
|
+
"@synerise/ds-cruds": "^2.0.6",
|
|
48
|
+
"@synerise/ds-factors": "^2.2.1",
|
|
49
|
+
"@synerise/ds-icon": "^2.2.0",
|
|
50
|
+
"@synerise/ds-inline-edit": "^2.0.7",
|
|
51
|
+
"@synerise/ds-input": "^2.0.7",
|
|
52
|
+
"@synerise/ds-operators": "^2.0.7",
|
|
53
53
|
"@synerise/ds-sortable": "^2.0.3",
|
|
54
|
-
"@synerise/ds-subject": "^2.0.
|
|
55
|
-
"@synerise/ds-tooltip": "^2.0.
|
|
56
|
-
"@synerise/ds-typography": "^2.0.
|
|
54
|
+
"@synerise/ds-subject": "^2.0.7",
|
|
55
|
+
"@synerise/ds-tooltip": "^2.0.6",
|
|
56
|
+
"@synerise/ds-typography": "^2.0.6",
|
|
57
57
|
"@synerise/ds-utils": "^2.2.0",
|
|
58
58
|
"lodash.debounce": "^4.0.8"
|
|
59
59
|
},
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"react-intl": ">=3.12.0 <= 6.8",
|
|
69
69
|
"styled-components": "^5.3.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "6b725db2b0de1a2dfc6e9a3744f6c2fb2a04cc04"
|
|
72
72
|
}
|