react-conditional-ui 1.2.0

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.
@@ -0,0 +1,225 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
3
+
4
+ declare class Field {
5
+ readonly raw: string;
6
+ readonly value: string;
7
+ readonly label: string;
8
+ readonly isValid: boolean;
9
+ constructor(raw: string, value: string, label: string);
10
+ static invalid(raw: string): Field;
11
+ }
12
+
13
+ declare class Operator {
14
+ readonly raw: string;
15
+ readonly value: string;
16
+ readonly label: string;
17
+ readonly isValid: boolean;
18
+ constructor(raw: string, value: string, label: string);
19
+ static invalid(raw: string): Operator;
20
+ }
21
+
22
+ declare class Value {
23
+ readonly raw: string;
24
+ readonly value: string;
25
+ readonly label: string;
26
+ readonly isValid: boolean;
27
+ readonly errorMessage: string | null;
28
+ readonly matchedOption: FieldOption | null;
29
+ constructor(raw: string, opts?: {
30
+ isValid: boolean;
31
+ errorMessage?: string | null;
32
+ matchedOption?: FieldOption | null;
33
+ });
34
+ static valid(raw: string, matchedOption?: FieldOption): Value;
35
+ static invalid(raw: string, errorMessage: string): Value;
36
+ static empty(): Value;
37
+ }
38
+
39
+ declare const DEFAULT_OPERATORS: OperatorOption[];
40
+
41
+ type OperatorOption = {
42
+ label: string;
43
+ value: string;
44
+ aliases: string[];
45
+ };
46
+ type FieldType = "text" | "number" | "enum";
47
+ type FieldOption = {
48
+ label: string;
49
+ value: string;
50
+ operators?: OperatorOption[];
51
+ fieldValues?: FieldOption[];
52
+ type?: FieldType;
53
+ /** Return `true` if valid, or an error message string. Takes priority over built-in type checks. */
54
+ validateValue?: (raw: string) => true | string;
55
+ };
56
+ type ParsedCondition = {
57
+ field: Field;
58
+ operator: Operator;
59
+ value: Value;
60
+ score: number;
61
+ };
62
+ type LogicalOperator = "and" | "or";
63
+ type ConditionEntry = {
64
+ id: string;
65
+ condition: ParsedCondition;
66
+ connector: LogicalOperator;
67
+ };
68
+ type GroupConfig = {
69
+ /** Logical connector shown between this group and the previous one. Defaults to "and". */
70
+ connector?: LogicalOperator;
71
+ /** Whether condition chips can be edited via popover. Defaults to true. */
72
+ editable?: boolean;
73
+ /** Whether entries can be removed from this group. Defaults to true. */
74
+ removable?: boolean;
75
+ /** Visual variant of the group card. Defaults to "outlined". */
76
+ variant?: "outlined" | "filled";
77
+ /** Optional label displayed above the group. */
78
+ label?: string;
79
+ };
80
+ type ConditionGroup = {
81
+ id: string;
82
+ entries: ConditionEntry[];
83
+ config?: GroupConfig;
84
+ };
85
+ type Diagnostic = {
86
+ start: number;
87
+ end: number;
88
+ message: string;
89
+ };
90
+ type ConditionalUIProps = {
91
+ fields: FieldOption[];
92
+ operators?: OperatorOption[];
93
+ value?: string;
94
+ onChange?: (raw: string) => void;
95
+ onConditionsChange?: (groups: ConditionGroup[]) => void;
96
+ className?: string;
97
+ style?: React$1.CSSProperties;
98
+ };
99
+
100
+ declare function ConditionalUI({ fields, operators, value, onChange, onConditionsChange, className, style, }: ConditionalUIProps): react_jsx_runtime.JSX.Element;
101
+
102
+ type BaseProps = {
103
+ placeholder?: string;
104
+ className?: string;
105
+ style?: React.CSSProperties;
106
+ };
107
+ type StandaloneProps = BaseProps & {
108
+ fields: FieldOption[];
109
+ operators?: OperatorOption[];
110
+ value?: string;
111
+ onChange?: (value: string) => void;
112
+ onSubmit?: (group: ConditionGroup) => void;
113
+ };
114
+ type ControlledProps = BaseProps & {
115
+ fields?: undefined;
116
+ value: string;
117
+ onChange: (value: string) => void;
118
+ onSubmit: () => void;
119
+ getSuggestion?: (text: string) => {
120
+ completion: string;
121
+ display: string;
122
+ } | null;
123
+ getCompletions?: (text: string, limit?: number) => {
124
+ completion: string;
125
+ display: string;
126
+ }[];
127
+ diagnostics?: Diagnostic[];
128
+ };
129
+ type InputProps = StandaloneProps | ControlledProps;
130
+ declare function Input(props: InputProps): react_jsx_runtime.JSX.Element;
131
+
132
+ type GroupMutations = {
133
+ addGroup: (group: ConditionGroup) => void;
134
+ removeEntry: (groupId: string, entryId: string) => void;
135
+ toggleConnector: (groupId: string, entryId: string) => void;
136
+ updateCondition: (groupId: string, entryId: string, condition: ParsedCondition) => void;
137
+ updateGroupConfig: (groupId: string, config: Partial<GroupConfig>) => void;
138
+ reorderWithinGroup: (groupId: string, activeId: string, overId: string) => void;
139
+ moveBetweenGroups: (sourceGroupId: string, targetGroupId: string, entryId: string, overEntryId: string | null) => void;
140
+ ungroupEntry: (groupId: string, entryId: string) => void;
141
+ setGroups: (groups: ConditionGroup[]) => void;
142
+ };
143
+ type UseConditionalOutputOptions = {
144
+ groups?: ConditionGroup[];
145
+ onGroupsChange?: (groups: ConditionGroup[]) => void;
146
+ };
147
+ declare function useConditionalOutput({ groups: controlledGroups, onGroupsChange, }?: UseConditionalOutputOptions): {
148
+ groups: ConditionGroup[];
149
+ mutations: GroupMutations;
150
+ };
151
+
152
+ type OutputProps = {
153
+ fields: FieldOption[];
154
+ operators: OperatorOption[];
155
+ /** Controlled groups. Omit for uncontrolled (internal state). */
156
+ groups?: ConditionGroup[];
157
+ /** Fires whenever groups change (works in both controlled and uncontrolled mode). */
158
+ onGroupsChange?: (groups: ConditionGroup[]) => void;
159
+ /** Default config applied to every group unless overridden by group.config. */
160
+ defaultGroupConfig?: GroupConfig;
161
+ className?: string;
162
+ style?: React.CSSProperties;
163
+ };
164
+
165
+ declare function Output({ fields, operators, groups: controlledGroups, onGroupsChange, defaultGroupConfig, className, style, }: OutputProps): react_jsx_runtime.JSX.Element;
166
+
167
+ type UseConditionalInputOptions = {
168
+ fields: FieldOption[];
169
+ operators?: OperatorOption[];
170
+ value?: string;
171
+ onChange?: (raw: string) => void;
172
+ onSubmit?: (group: ConditionGroup) => void;
173
+ };
174
+ declare function useConditionalInput({ fields, operators, value, onChange, onSubmit, }: UseConditionalInputOptions): {
175
+ text: string;
176
+ diagnostics: Diagnostic[];
177
+ handleChange: (next: string) => void;
178
+ handleSubmit: () => void;
179
+ getSuggestion: (text: string) => {
180
+ completion: string;
181
+ display: string;
182
+ } | null;
183
+ getCompletions: (text: string, limit?: number) => {
184
+ completion: string;
185
+ display: string;
186
+ }[];
187
+ };
188
+
189
+ declare class ConditionDataProvider {
190
+ private readonly suggestions;
191
+ private readonly diagnostics;
192
+ private readonly segments;
193
+ constructor(fields: FieldOption[], operators: OperatorOption[]);
194
+ parseComplexCondition(text: string): ConditionGroup | null;
195
+ getCompletions(text: string, limit?: number): {
196
+ completion: string;
197
+ display: string;
198
+ }[];
199
+ getSuggestion(text: string): {
200
+ completion: string;
201
+ display: string;
202
+ } | null;
203
+ diagnose(text: string): Diagnostic[];
204
+ }
205
+
206
+ type UseConditionDataProviderOptions = {
207
+ fields: FieldOption[];
208
+ operators?: OperatorOption[];
209
+ };
210
+ type UseConditionDataProviderResult = {
211
+ provider: ConditionDataProvider;
212
+ parseComplexCondition: (text: string) => ConditionGroup | null;
213
+ getCompletions: (text: string, limit?: number) => {
214
+ completion: string;
215
+ display: string;
216
+ }[];
217
+ getSuggestion: (text: string) => {
218
+ completion: string;
219
+ display: string;
220
+ } | null;
221
+ diagnose: (text: string) => Diagnostic[];
222
+ };
223
+ declare function useConditionDataProvider({ fields, operators, }: UseConditionDataProviderOptions): UseConditionDataProviderResult;
224
+
225
+ export { ConditionDataProvider, type ConditionEntry, type ConditionGroup, ConditionDataProvider as ConditionParser, ConditionalUI, type ConditionalUIProps, DEFAULT_OPERATORS, type Diagnostic, type FieldOption, type FieldType, type GroupConfig, type GroupMutations, Input, type InputProps, type LogicalOperator, type OperatorOption, Output, type OutputProps, type ParsedCondition, type UseConditionDataProviderOptions, type UseConditionDataProviderResult, type UseConditionalInputOptions, type UseConditionalOutputOptions, useConditionDataProvider, useConditionalInput, useConditionalOutput };
@@ -0,0 +1,225 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
3
+
4
+ declare class Field {
5
+ readonly raw: string;
6
+ readonly value: string;
7
+ readonly label: string;
8
+ readonly isValid: boolean;
9
+ constructor(raw: string, value: string, label: string);
10
+ static invalid(raw: string): Field;
11
+ }
12
+
13
+ declare class Operator {
14
+ readonly raw: string;
15
+ readonly value: string;
16
+ readonly label: string;
17
+ readonly isValid: boolean;
18
+ constructor(raw: string, value: string, label: string);
19
+ static invalid(raw: string): Operator;
20
+ }
21
+
22
+ declare class Value {
23
+ readonly raw: string;
24
+ readonly value: string;
25
+ readonly label: string;
26
+ readonly isValid: boolean;
27
+ readonly errorMessage: string | null;
28
+ readonly matchedOption: FieldOption | null;
29
+ constructor(raw: string, opts?: {
30
+ isValid: boolean;
31
+ errorMessage?: string | null;
32
+ matchedOption?: FieldOption | null;
33
+ });
34
+ static valid(raw: string, matchedOption?: FieldOption): Value;
35
+ static invalid(raw: string, errorMessage: string): Value;
36
+ static empty(): Value;
37
+ }
38
+
39
+ declare const DEFAULT_OPERATORS: OperatorOption[];
40
+
41
+ type OperatorOption = {
42
+ label: string;
43
+ value: string;
44
+ aliases: string[];
45
+ };
46
+ type FieldType = "text" | "number" | "enum";
47
+ type FieldOption = {
48
+ label: string;
49
+ value: string;
50
+ operators?: OperatorOption[];
51
+ fieldValues?: FieldOption[];
52
+ type?: FieldType;
53
+ /** Return `true` if valid, or an error message string. Takes priority over built-in type checks. */
54
+ validateValue?: (raw: string) => true | string;
55
+ };
56
+ type ParsedCondition = {
57
+ field: Field;
58
+ operator: Operator;
59
+ value: Value;
60
+ score: number;
61
+ };
62
+ type LogicalOperator = "and" | "or";
63
+ type ConditionEntry = {
64
+ id: string;
65
+ condition: ParsedCondition;
66
+ connector: LogicalOperator;
67
+ };
68
+ type GroupConfig = {
69
+ /** Logical connector shown between this group and the previous one. Defaults to "and". */
70
+ connector?: LogicalOperator;
71
+ /** Whether condition chips can be edited via popover. Defaults to true. */
72
+ editable?: boolean;
73
+ /** Whether entries can be removed from this group. Defaults to true. */
74
+ removable?: boolean;
75
+ /** Visual variant of the group card. Defaults to "outlined". */
76
+ variant?: "outlined" | "filled";
77
+ /** Optional label displayed above the group. */
78
+ label?: string;
79
+ };
80
+ type ConditionGroup = {
81
+ id: string;
82
+ entries: ConditionEntry[];
83
+ config?: GroupConfig;
84
+ };
85
+ type Diagnostic = {
86
+ start: number;
87
+ end: number;
88
+ message: string;
89
+ };
90
+ type ConditionalUIProps = {
91
+ fields: FieldOption[];
92
+ operators?: OperatorOption[];
93
+ value?: string;
94
+ onChange?: (raw: string) => void;
95
+ onConditionsChange?: (groups: ConditionGroup[]) => void;
96
+ className?: string;
97
+ style?: React$1.CSSProperties;
98
+ };
99
+
100
+ declare function ConditionalUI({ fields, operators, value, onChange, onConditionsChange, className, style, }: ConditionalUIProps): react_jsx_runtime.JSX.Element;
101
+
102
+ type BaseProps = {
103
+ placeholder?: string;
104
+ className?: string;
105
+ style?: React.CSSProperties;
106
+ };
107
+ type StandaloneProps = BaseProps & {
108
+ fields: FieldOption[];
109
+ operators?: OperatorOption[];
110
+ value?: string;
111
+ onChange?: (value: string) => void;
112
+ onSubmit?: (group: ConditionGroup) => void;
113
+ };
114
+ type ControlledProps = BaseProps & {
115
+ fields?: undefined;
116
+ value: string;
117
+ onChange: (value: string) => void;
118
+ onSubmit: () => void;
119
+ getSuggestion?: (text: string) => {
120
+ completion: string;
121
+ display: string;
122
+ } | null;
123
+ getCompletions?: (text: string, limit?: number) => {
124
+ completion: string;
125
+ display: string;
126
+ }[];
127
+ diagnostics?: Diagnostic[];
128
+ };
129
+ type InputProps = StandaloneProps | ControlledProps;
130
+ declare function Input(props: InputProps): react_jsx_runtime.JSX.Element;
131
+
132
+ type GroupMutations = {
133
+ addGroup: (group: ConditionGroup) => void;
134
+ removeEntry: (groupId: string, entryId: string) => void;
135
+ toggleConnector: (groupId: string, entryId: string) => void;
136
+ updateCondition: (groupId: string, entryId: string, condition: ParsedCondition) => void;
137
+ updateGroupConfig: (groupId: string, config: Partial<GroupConfig>) => void;
138
+ reorderWithinGroup: (groupId: string, activeId: string, overId: string) => void;
139
+ moveBetweenGroups: (sourceGroupId: string, targetGroupId: string, entryId: string, overEntryId: string | null) => void;
140
+ ungroupEntry: (groupId: string, entryId: string) => void;
141
+ setGroups: (groups: ConditionGroup[]) => void;
142
+ };
143
+ type UseConditionalOutputOptions = {
144
+ groups?: ConditionGroup[];
145
+ onGroupsChange?: (groups: ConditionGroup[]) => void;
146
+ };
147
+ declare function useConditionalOutput({ groups: controlledGroups, onGroupsChange, }?: UseConditionalOutputOptions): {
148
+ groups: ConditionGroup[];
149
+ mutations: GroupMutations;
150
+ };
151
+
152
+ type OutputProps = {
153
+ fields: FieldOption[];
154
+ operators: OperatorOption[];
155
+ /** Controlled groups. Omit for uncontrolled (internal state). */
156
+ groups?: ConditionGroup[];
157
+ /** Fires whenever groups change (works in both controlled and uncontrolled mode). */
158
+ onGroupsChange?: (groups: ConditionGroup[]) => void;
159
+ /** Default config applied to every group unless overridden by group.config. */
160
+ defaultGroupConfig?: GroupConfig;
161
+ className?: string;
162
+ style?: React.CSSProperties;
163
+ };
164
+
165
+ declare function Output({ fields, operators, groups: controlledGroups, onGroupsChange, defaultGroupConfig, className, style, }: OutputProps): react_jsx_runtime.JSX.Element;
166
+
167
+ type UseConditionalInputOptions = {
168
+ fields: FieldOption[];
169
+ operators?: OperatorOption[];
170
+ value?: string;
171
+ onChange?: (raw: string) => void;
172
+ onSubmit?: (group: ConditionGroup) => void;
173
+ };
174
+ declare function useConditionalInput({ fields, operators, value, onChange, onSubmit, }: UseConditionalInputOptions): {
175
+ text: string;
176
+ diagnostics: Diagnostic[];
177
+ handleChange: (next: string) => void;
178
+ handleSubmit: () => void;
179
+ getSuggestion: (text: string) => {
180
+ completion: string;
181
+ display: string;
182
+ } | null;
183
+ getCompletions: (text: string, limit?: number) => {
184
+ completion: string;
185
+ display: string;
186
+ }[];
187
+ };
188
+
189
+ declare class ConditionDataProvider {
190
+ private readonly suggestions;
191
+ private readonly diagnostics;
192
+ private readonly segments;
193
+ constructor(fields: FieldOption[], operators: OperatorOption[]);
194
+ parseComplexCondition(text: string): ConditionGroup | null;
195
+ getCompletions(text: string, limit?: number): {
196
+ completion: string;
197
+ display: string;
198
+ }[];
199
+ getSuggestion(text: string): {
200
+ completion: string;
201
+ display: string;
202
+ } | null;
203
+ diagnose(text: string): Diagnostic[];
204
+ }
205
+
206
+ type UseConditionDataProviderOptions = {
207
+ fields: FieldOption[];
208
+ operators?: OperatorOption[];
209
+ };
210
+ type UseConditionDataProviderResult = {
211
+ provider: ConditionDataProvider;
212
+ parseComplexCondition: (text: string) => ConditionGroup | null;
213
+ getCompletions: (text: string, limit?: number) => {
214
+ completion: string;
215
+ display: string;
216
+ }[];
217
+ getSuggestion: (text: string) => {
218
+ completion: string;
219
+ display: string;
220
+ } | null;
221
+ diagnose: (text: string) => Diagnostic[];
222
+ };
223
+ declare function useConditionDataProvider({ fields, operators, }: UseConditionDataProviderOptions): UseConditionDataProviderResult;
224
+
225
+ export { ConditionDataProvider, type ConditionEntry, type ConditionGroup, ConditionDataProvider as ConditionParser, ConditionalUI, type ConditionalUIProps, DEFAULT_OPERATORS, type Diagnostic, type FieldOption, type FieldType, type GroupConfig, type GroupMutations, Input, type InputProps, type LogicalOperator, type OperatorOption, Output, type OutputProps, type ParsedCondition, type UseConditionDataProviderOptions, type UseConditionDataProviderResult, type UseConditionalInputOptions, type UseConditionalOutputOptions, useConditionDataProvider, useConditionalInput, useConditionalOutput };