@ram_28/kf-ai-sdk 1.0.7 → 1.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/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/components/hooks/index.d.ts +2 -1
- package/dist/components/hooks/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/index.d.ts +3 -3
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/types.d.ts +83 -109
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/useFilter.d.ts +1 -1
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
- package/dist/components/hooks/useForm/apiClient.d.ts +4 -4
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +3 -3
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/index.d.ts +7 -4
- package/dist/components/hooks/useForm/index.d.ts.map +1 -1
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +5 -5
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +7 -6
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts +8 -8
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/types.d.ts +86 -93
- package/dist/components/hooks/useForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/index.d.ts +1 -1
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/types.d.ts +6 -46
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +5 -33
- package/dist/components/hooks/useTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useTable/useTable.d.ts +0 -5
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.mjs +1990 -2234
- package/dist/types/common.d.ts +35 -26
- package/dist/types/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/sdk/api/index.ts +7 -3
- package/sdk/components/hooks/index.ts +24 -4
- package/sdk/components/hooks/useFilter/index.ts +19 -18
- package/sdk/components/hooks/useFilter/types.ts +157 -123
- package/sdk/components/hooks/useFilter/useFilter.ts +259 -393
- package/sdk/components/hooks/useForm/apiClient.ts +5 -5
- package/sdk/components/hooks/useForm/expressionValidator.utils.ts +11 -11
- package/sdk/components/hooks/useForm/index.ts +41 -45
- package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +7 -7
- package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +21 -20
- package/sdk/components/hooks/useForm/schemaParser.utils.ts +36 -41
- package/sdk/components/hooks/useForm/types.ts +107 -113
- package/sdk/components/hooks/useForm/useForm.ts +54 -54
- package/sdk/components/hooks/useKanban/index.ts +0 -1
- package/sdk/components/hooks/useKanban/types.ts +8 -66
- package/sdk/components/hooks/useKanban/useKanban.ts +14 -75
- package/sdk/components/hooks/useTable/types.ts +7 -60
- package/sdk/components/hooks/useTable/useTable.ts +13 -121
- package/sdk/types/common.ts +42 -26
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +0 -33
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +0 -1
- package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +0 -298
package/dist/types/common.d.ts
CHANGED
|
@@ -12,30 +12,27 @@ export type SortOption = Record<string, SortDirection>;
|
|
|
12
12
|
*/
|
|
13
13
|
export type Sort = SortOption[];
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Condition operators for individual conditions (leaf nodes)
|
|
16
|
+
* Used in Condition.Operator
|
|
16
17
|
*/
|
|
17
|
-
export type
|
|
18
|
+
export type ConditionOperator = "EQ" | "NE" | "GT" | "GTE" | "LT" | "LTE" | "Between" | "NotBetween" | "IN" | "NIN" | "Empty" | "NotEmpty" | "Contains" | "NotContains" | "MinLength" | "MaxLength";
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Operators for combining conditions in a group (tree nodes)
|
|
21
|
+
* Used in ConditionGroup.Operator
|
|
20
22
|
*/
|
|
21
|
-
export type
|
|
23
|
+
export type ConditionGroupOperator = "And" | "Or" | "Not";
|
|
22
24
|
/**
|
|
23
25
|
* RHS value type for filter conditions
|
|
24
26
|
*/
|
|
25
27
|
export type FilterRHSType = "Constant" | "BOField" | "AppVariable";
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* Leaf condition (actual field comparison)
|
|
28
30
|
*/
|
|
29
|
-
interface
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Leaf filter condition (actual field comparison)
|
|
35
|
-
*/
|
|
36
|
-
export interface FilterCondition extends FilterNodeBase {
|
|
31
|
+
export interface Condition {
|
|
32
|
+
/** Optional ID for hook state management (omitted in API payload) */
|
|
33
|
+
id?: string;
|
|
37
34
|
/** Condition operator */
|
|
38
|
-
Operator:
|
|
35
|
+
Operator: ConditionOperator;
|
|
39
36
|
/** Left-hand side field name */
|
|
40
37
|
LHSField: string;
|
|
41
38
|
/** Right-hand side value */
|
|
@@ -44,23 +41,36 @@ export interface FilterCondition extends FilterNodeBase {
|
|
|
44
41
|
RHSType?: FilterRHSType;
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
|
-
*
|
|
44
|
+
* Group combining conditions (recursive structure)
|
|
48
45
|
*/
|
|
49
|
-
export interface
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
|
|
46
|
+
export interface ConditionGroup {
|
|
47
|
+
/** Optional ID for hook state management (omitted in API payload) */
|
|
48
|
+
id?: string;
|
|
49
|
+
/** Group operator (And, Or, Not) */
|
|
50
|
+
Operator: ConditionGroupOperator;
|
|
51
|
+
/** Nested conditions (can be Condition or ConditionGroup) */
|
|
52
|
+
Condition: Array<Condition | ConditionGroup>;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
|
-
*
|
|
57
|
-
|
|
55
|
+
* Root filter type (alias for ConditionGroup)
|
|
56
|
+
*/
|
|
57
|
+
export type Filter = ConditionGroup;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Use `Condition` instead
|
|
60
|
+
*/
|
|
61
|
+
export type FilterCondition = Condition;
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Use `ConditionGroup` instead
|
|
64
|
+
*/
|
|
65
|
+
export type FilterLogical = ConditionGroup;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated Use `ConditionGroupOperator` instead
|
|
58
68
|
*/
|
|
59
|
-
export type
|
|
69
|
+
export type FilterOperator = ConditionGroupOperator;
|
|
60
70
|
/**
|
|
61
|
-
*
|
|
71
|
+
* @deprecated Use `Condition | ConditionGroup` instead
|
|
62
72
|
*/
|
|
63
|
-
export type FilterNode =
|
|
73
|
+
export type FilterNode = Condition | ConditionGroup;
|
|
64
74
|
/**
|
|
65
75
|
* DateTime encoding format used by the API
|
|
66
76
|
*/
|
|
@@ -234,5 +244,4 @@ export interface FetchFieldResponse {
|
|
|
234
244
|
/** Array of field options */
|
|
235
245
|
Data: FetchFieldOption[];
|
|
236
246
|
}
|
|
237
|
-
export {};
|
|
238
247
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../sdk/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,E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AClC,IAAI,EAAE,OAAO,CAAC;IACd,2BAA2B;IAC3B,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,8BAA8B;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yBAAyB;IACzB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAMD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC;CAC1B;AAMD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CAC7B;AAMD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,gBAAgB,EAAE,CAAC;CAC1B"}
|
package/package.json
CHANGED
package/sdk/api/index.ts
CHANGED
|
@@ -26,12 +26,16 @@ export type {
|
|
|
26
26
|
SortDirection,
|
|
27
27
|
SortOption,
|
|
28
28
|
Sort,
|
|
29
|
-
// Filter types
|
|
29
|
+
// Filter types (new names)
|
|
30
|
+
Condition,
|
|
31
|
+
ConditionGroup,
|
|
32
|
+
ConditionGroupOperator,
|
|
30
33
|
Filter,
|
|
34
|
+
FilterRHSType,
|
|
35
|
+
ConditionOperator,
|
|
36
|
+
// Filter types (legacy - deprecated)
|
|
31
37
|
FilterCondition,
|
|
32
38
|
FilterOperator,
|
|
33
|
-
FilterRHSType,
|
|
34
|
-
LogicalOperator,
|
|
35
39
|
FilterLogical,
|
|
36
40
|
FilterNode,
|
|
37
41
|
// List types
|
|
@@ -9,15 +9,35 @@ export type {
|
|
|
9
9
|
// Form hook
|
|
10
10
|
export { useForm } from "./useForm";
|
|
11
11
|
export type {
|
|
12
|
+
// Core types
|
|
12
13
|
UseFormOptions,
|
|
13
14
|
UseFormReturn,
|
|
14
|
-
BackendFieldDefinition,
|
|
15
|
-
ProcessedField,
|
|
16
|
-
ProcessedSchema,
|
|
17
15
|
FormOperation,
|
|
18
16
|
FormMode,
|
|
19
|
-
|
|
17
|
+
|
|
18
|
+
// Form field configuration
|
|
19
|
+
FormFieldConfig,
|
|
20
|
+
FormSchemaConfig,
|
|
21
|
+
FormFieldType,
|
|
22
|
+
SelectOption,
|
|
23
|
+
FieldPermission,
|
|
24
|
+
|
|
25
|
+
// Result types
|
|
26
|
+
FieldValidationResult,
|
|
20
27
|
SubmissionResult,
|
|
28
|
+
|
|
29
|
+
// BDO Schema types (advanced)
|
|
30
|
+
BDOSchema,
|
|
31
|
+
BDOFieldDefinition,
|
|
32
|
+
SchemaValidationRule,
|
|
33
|
+
} from "./useForm";
|
|
34
|
+
|
|
35
|
+
// Error utilities
|
|
36
|
+
export {
|
|
37
|
+
parseApiError,
|
|
38
|
+
isNetworkError,
|
|
39
|
+
isValidationError,
|
|
40
|
+
clearFormCache,
|
|
21
41
|
} from "./useForm";
|
|
22
42
|
|
|
23
43
|
// Kanban hook
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
// Main hook export
|
|
2
|
-
export { useFilter } from
|
|
2
|
+
export { useFilter } from "./useFilter";
|
|
3
3
|
|
|
4
|
-
// Type exports
|
|
4
|
+
// Type exports (new names)
|
|
5
5
|
export type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
Condition,
|
|
7
|
+
ConditionGroup,
|
|
8
|
+
ConditionGroupOperator,
|
|
9
|
+
Filter,
|
|
10
|
+
FilterRHSType,
|
|
11
11
|
UseFilterOptions,
|
|
12
|
-
UseFilterReturn
|
|
13
|
-
|
|
12
|
+
UseFilterReturn,
|
|
13
|
+
// Legacy type exports
|
|
14
|
+
FilterCondition,
|
|
15
|
+
FilterOperator,
|
|
16
|
+
} from "./types";
|
|
14
17
|
|
|
15
|
-
//
|
|
18
|
+
// Type guard exports
|
|
16
19
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
areFilterPayloadsEqual
|
|
24
|
-
} from './payloadBuilder.utils';
|
|
20
|
+
isCondition,
|
|
21
|
+
isConditionGroup,
|
|
22
|
+
// Legacy type guard exports
|
|
23
|
+
isFilterCondition,
|
|
24
|
+
isFilterLogical,
|
|
25
|
+
} from "./types";
|
|
@@ -1,143 +1,177 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Condition,
|
|
3
|
+
ConditionGroup,
|
|
4
|
+
ConditionGroupOperator,
|
|
5
|
+
Filter,
|
|
6
|
+
FilterRHSType,
|
|
7
|
+
// Legacy types for backwards compatibility
|
|
8
|
+
FilterCondition,
|
|
9
|
+
FilterOperator,
|
|
10
|
+
} from "../../../types/common";
|
|
11
|
+
|
|
12
|
+
// Re-export from common types for convenience
|
|
13
|
+
export type {
|
|
14
|
+
Condition,
|
|
15
|
+
ConditionGroup,
|
|
16
|
+
ConditionGroupOperator,
|
|
17
|
+
Filter,
|
|
18
|
+
FilterRHSType,
|
|
19
|
+
// Legacy re-exports
|
|
20
|
+
FilterCondition,
|
|
21
|
+
FilterOperator,
|
|
22
|
+
};
|
|
2
23
|
|
|
3
24
|
// ============================================================
|
|
4
|
-
// TYPE
|
|
25
|
+
// TYPE GUARDS
|
|
5
26
|
// ============================================================
|
|
6
27
|
|
|
7
28
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Supports both simple conditions and nested logical groups
|
|
29
|
+
* Type guard to check if an item is a ConditionGroup (has nested Condition array)
|
|
10
30
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Left-hand side field name (required for condition operators) */
|
|
17
|
-
lhsField?: string;
|
|
18
|
-
/** Right-hand side value (required for condition operators) */
|
|
19
|
-
rhsValue?: any;
|
|
20
|
-
/** Right-hand side type (defaults to Constant) */
|
|
21
|
-
rhsType?: FilterRHSType;
|
|
22
|
-
/** Nested conditions (for logical operators: And, Or, Not) */
|
|
23
|
-
children?: FilterConditionWithId[];
|
|
24
|
-
/** Validation state */
|
|
25
|
-
isValid: boolean;
|
|
26
|
-
/** Specific validation errors */
|
|
27
|
-
validationErrors?: string[];
|
|
28
|
-
}
|
|
31
|
+
export const isConditionGroup = (
|
|
32
|
+
item: Condition | ConditionGroup
|
|
33
|
+
): item is ConditionGroup => {
|
|
34
|
+
return "Condition" in item;
|
|
35
|
+
};
|
|
29
36
|
|
|
30
37
|
/**
|
|
31
|
-
* Type
|
|
32
|
-
* Constrains lhsField to keys of T for compile-time type checking
|
|
38
|
+
* Type guard to check if an item is a leaf Condition (has LHSField)
|
|
33
39
|
*/
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/** Right-hand side value */
|
|
40
|
-
rhsValue?: T[keyof T] | T[keyof T][] | any;
|
|
41
|
-
/** Right-hand side type (defaults to Constant) */
|
|
42
|
-
rhsType?: FilterRHSType;
|
|
43
|
-
/** Nested conditions (for logical operators: And, Or, Not) */
|
|
44
|
-
children?: TypedFilterConditionInput<T>[];
|
|
45
|
-
}
|
|
40
|
+
export const isCondition = (
|
|
41
|
+
item: Condition | ConditionGroup
|
|
42
|
+
): item is Condition => {
|
|
43
|
+
return "LHSField" in item;
|
|
44
|
+
};
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
/** Array of filter conditions with IDs */
|
|
51
|
-
conditions: FilterConditionWithId[];
|
|
52
|
-
}
|
|
46
|
+
// ============================================================
|
|
47
|
+
// LEGACY TYPE GUARDS (for backwards compatibility)
|
|
48
|
+
// ============================================================
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
errors: string[];
|
|
59
|
-
}
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use `isConditionGroup` instead
|
|
52
|
+
*/
|
|
53
|
+
export const isFilterLogical = isConditionGroup;
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
field: string;
|
|
66
|
-
/** Error message */
|
|
67
|
-
message: string;
|
|
68
|
-
}
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Use `isCondition` instead
|
|
57
|
+
*/
|
|
58
|
+
export const isFilterCondition = isCondition;
|
|
69
59
|
|
|
60
|
+
// ============================================================
|
|
61
|
+
// HOOK-SPECIFIC TYPE DEFINITIONS
|
|
62
|
+
// ============================================================
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Hook options (minimal configuration)
|
|
66
|
+
*/
|
|
70
67
|
export interface UseFilterOptions {
|
|
71
68
|
/** Initial filter conditions */
|
|
72
|
-
initialConditions?:
|
|
73
|
-
/** Initial
|
|
74
|
-
|
|
75
|
-
/** Whether to validate conditions on change */
|
|
76
|
-
validateOnChange?: boolean;
|
|
77
|
-
/** Callback when condition is added */
|
|
78
|
-
onConditionAdd?: (condition: FilterConditionWithId) => void;
|
|
79
|
-
/** Callback when condition is updated */
|
|
80
|
-
onConditionUpdate?: (condition: FilterConditionWithId) => void;
|
|
81
|
-
/** Callback when condition is removed */
|
|
82
|
-
onConditionRemove?: (conditionId: string) => void;
|
|
83
|
-
/** Callback when validation errors occur */
|
|
84
|
-
onValidationError?: (errors: ValidationError[]) => void;
|
|
69
|
+
initialConditions?: Array<Condition | ConditionGroup>;
|
|
70
|
+
/** Initial operator for combining conditions (defaults to "And") */
|
|
71
|
+
initialOperator?: ConditionGroupOperator;
|
|
85
72
|
}
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
updateCondition: (id: string, updates: Partial<TypedFilterConditionInput<T>>) => boolean;
|
|
105
|
-
/** Remove a condition by ID */
|
|
106
|
-
removeCondition: (id: string) => boolean;
|
|
107
|
-
/** Clear all conditions */
|
|
108
|
-
clearConditions: () => void;
|
|
109
|
-
/** Get a specific condition by ID */
|
|
110
|
-
getCondition: (id: string) => FilterConditionWithId | undefined;
|
|
111
|
-
|
|
112
|
-
// Logical operator management
|
|
113
|
-
/** Set the root logical operator */
|
|
114
|
-
setLogicalOperator: (operator: LogicalOperator) => void;
|
|
115
|
-
|
|
116
|
-
// Bulk operations
|
|
117
|
-
/** Replace all conditions */
|
|
118
|
-
setConditions: (conditions: FilterConditionWithId[]) => void;
|
|
119
|
-
/** Replace a specific condition */
|
|
120
|
-
replaceCondition: (id: string, newCondition: TypedFilterConditionInput<T>) => boolean;
|
|
121
|
-
|
|
122
|
-
// Validation
|
|
123
|
-
/** Validate a single condition */
|
|
124
|
-
validateCondition: (condition: Partial<FilterConditionWithId>) => ValidationResult;
|
|
125
|
-
/** Validate all current conditions */
|
|
126
|
-
validateAllConditions: () => ValidationResult;
|
|
127
|
-
|
|
128
|
-
// State management
|
|
129
|
-
/** Export current filter state */
|
|
130
|
-
exportState: () => FilterState;
|
|
131
|
-
/** Import a filter state */
|
|
132
|
-
importState: (state: FilterState) => void;
|
|
133
|
-
/** Reset to initial state */
|
|
134
|
-
resetToInitial: () => void;
|
|
135
|
-
|
|
136
|
-
// Utilities
|
|
137
|
-
/** Get total number of conditions */
|
|
138
|
-
getConditionCount: () => number;
|
|
74
|
+
/**
|
|
75
|
+
* Hook return interface with nested filter support
|
|
76
|
+
*/
|
|
77
|
+
export interface UseFilterReturn {
|
|
78
|
+
// ============================================================
|
|
79
|
+
// STATE (read-only)
|
|
80
|
+
// ============================================================
|
|
81
|
+
|
|
82
|
+
/** Current operator for combining root-level conditions ("And" | "Or" | "Not") */
|
|
83
|
+
operator: ConditionGroupOperator;
|
|
84
|
+
|
|
85
|
+
/** Current filter items (with id populated) */
|
|
86
|
+
items: Array<Condition | ConditionGroup>;
|
|
87
|
+
|
|
88
|
+
/** Ready-to-use API payload (id stripped, undefined if no conditions) */
|
|
89
|
+
payload: Filter | undefined;
|
|
90
|
+
|
|
139
91
|
/** Whether any conditions exist */
|
|
140
92
|
hasConditions: boolean;
|
|
141
|
-
|
|
142
|
-
|
|
93
|
+
|
|
94
|
+
// ============================================================
|
|
95
|
+
// ADD OPERATIONS (return id of created item)
|
|
96
|
+
// ============================================================
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Add a leaf condition at root level
|
|
100
|
+
* @returns The id of the created condition
|
|
101
|
+
*/
|
|
102
|
+
add: (condition: Omit<Condition, "id">) => string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Add a condition group at root level
|
|
106
|
+
* @returns The id of the created group
|
|
107
|
+
*/
|
|
108
|
+
addGroup: (operator: ConditionGroupOperator) => string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Add a leaf condition to a specific parent group
|
|
112
|
+
* @param parentId - The id of the parent ConditionGroup
|
|
113
|
+
* @returns The id of the created condition
|
|
114
|
+
*/
|
|
115
|
+
addTo: (parentId: string, condition: Omit<Condition, "id">) => string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Add a condition group to a specific parent group
|
|
119
|
+
* @param parentId - The id of the parent ConditionGroup
|
|
120
|
+
* @returns The id of the created group
|
|
121
|
+
*/
|
|
122
|
+
addGroupTo: (parentId: string, operator: ConditionGroupOperator) => string;
|
|
123
|
+
|
|
124
|
+
// ============================================================
|
|
125
|
+
// UPDATE OPERATIONS
|
|
126
|
+
// ============================================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Update a leaf condition by id
|
|
130
|
+
* @param id - The id of the condition to update
|
|
131
|
+
* @param updates - Partial updates to apply
|
|
132
|
+
*/
|
|
133
|
+
update: (id: string, updates: Partial<Omit<Condition, "id">>) => void;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Update a condition group's operator by id
|
|
137
|
+
* @param id - The id of the group to update
|
|
138
|
+
* @param operator - The new operator
|
|
139
|
+
*/
|
|
140
|
+
updateOperator: (id: string, operator: ConditionGroupOperator) => void;
|
|
141
|
+
|
|
142
|
+
// ============================================================
|
|
143
|
+
// REMOVE & ACCESS
|
|
144
|
+
// ============================================================
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Remove a condition or group by id
|
|
148
|
+
* @param id - The id of the item to remove
|
|
149
|
+
*/
|
|
150
|
+
remove: (id: string) => void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get a condition or group by id
|
|
154
|
+
* @param id - The id to look up
|
|
155
|
+
* @returns The item or undefined if not found
|
|
156
|
+
*/
|
|
157
|
+
get: (id: string) => Condition | ConditionGroup | undefined;
|
|
158
|
+
|
|
159
|
+
// ============================================================
|
|
160
|
+
// UTILITY
|
|
161
|
+
// ============================================================
|
|
162
|
+
|
|
163
|
+
/** Clear all conditions */
|
|
164
|
+
clear: () => void;
|
|
165
|
+
|
|
166
|
+
/** Set the root operator for combining conditions */
|
|
167
|
+
setOperator: (op: ConditionGroupOperator) => void;
|
|
168
|
+
|
|
169
|
+
// ============================================================
|
|
170
|
+
// LEGACY API (for backwards compatibility)
|
|
171
|
+
// ============================================================
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated Use `items` instead
|
|
175
|
+
*/
|
|
176
|
+
conditions: Array<Condition | ConditionGroup>;
|
|
143
177
|
}
|