@kronor/dtv 10.1.0 → 10.1.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.
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { FilterControl as FrameworkFilterControl, SuggestionFetcher, SuggestionItem } from '../framework/filters';
2
+ import type { CustomOperatorOption, FilterControl as FrameworkFilterControl, SuggestionFetcher, SuggestionItem } from '../framework/filters';
3
3
  import type * as FilterValue from '../framework/filterValue';
4
4
  import type { MutableTuple } from './filterTyping';
5
5
  export type { SuggestionFetcher, SuggestionItem };
@@ -33,10 +33,7 @@ export type DropdownControl<Items extends readonly ItemControlItem[]> = Omit<Con
33
33
  export type MultiselectControl<Items extends readonly ItemControlItem[]> = Omit<ControlOfType<'multiselect'>, 'items'> & {
34
34
  items: MutableTuple<Items>;
35
35
  };
36
- export type CustomOperatorControl<Operators extends readonly {
37
- label: string;
38
- value: string;
39
- }[], ValueControl extends FrameworkFilterControl> = Omit<ControlOfType<'customOperator'>, 'operators' | 'valueControl'> & {
36
+ export type CustomOperatorControl<Operators extends readonly CustomOperatorOption[], ValueControl extends FrameworkFilterControl> = Omit<ControlOfType<'customOperator'>, 'operators' | 'valueControl'> & {
40
37
  operators: MutableTuple<Operators>;
41
38
  valueControl: ValueControl;
42
39
  };
@@ -79,10 +76,7 @@ export declare const FilterControl: {
79
76
  filterable?: boolean;
80
77
  initialValue?: ControlValue<MultiselectControl<Items>>;
81
78
  }) => MultiselectControl<Items>;
82
- customOperator: <const Operators extends readonly {
83
- label: string;
84
- value: string;
85
- }[], const ValueControl extends FrameworkFilterControl>(options: {
79
+ customOperator: <const Operators extends readonly CustomOperatorOption[], const ValueControl extends FrameworkFilterControl>(options: {
86
80
  label?: string;
87
81
  operators: Operators;
88
82
  valueControl: ValueControl;
@@ -65,7 +65,8 @@ export declare function makeFilterFormStateSerializable(node: FilterFormState):
65
65
  /**
66
66
  * Schema-aware emptiness check for a FilterFormState tree.
67
67
  * A leaf is considered empty when its primitive value is '' | null | [] (if array).
68
- * For customOperator controls we look at the nested `value` field inside { operator, value }.
68
+ * For customOperator controls we look at the nested `value` field inside { operator, value },
69
+ * unless the operator takes no value (`is empty`): such a leaf is set.
69
70
  */
70
71
  export declare function isFilterEmpty(state: FilterFormState, schemaExpr: FilterExpr): boolean;
71
72
  /**
@@ -104,6 +104,17 @@ export type FilterValueFormatContext = {
104
104
  export type FilterTransform<Input = unknown, Row = any, Field extends FilterField = any> = {
105
105
  toQuery: (input: Input, context: QueryTransformContext<Row, Field>) => TransformResult;
106
106
  };
107
+ /**
108
+ * An operator of a `customOperator` control. `takesValue: false` marks one
109
+ * that filters without a value (`is empty`): the form hides the value control
110
+ * for it, and the filter counts as set although its value is empty. The
111
+ * filter's own transform builds its condition; `hasuraCustomOperator` does not.
112
+ */
113
+ export type CustomOperatorOption = {
114
+ label: string;
115
+ value: string;
116
+ takesValue?: boolean;
117
+ };
107
118
  export type FilterControl = {
108
119
  type: 'text';
109
120
  label?: string;
@@ -141,10 +152,7 @@ export type FilterControl = {
141
152
  } | {
142
153
  type: 'customOperator';
143
154
  label?: string;
144
- operators: {
145
- label: string;
146
- value: string;
147
- }[];
155
+ operators: CustomOperatorOption[];
148
156
  valueControl: FilterControl;
149
157
  initialValue?: any;
150
158
  } | {
@@ -262,6 +270,8 @@ export declare const SUPPORTED_OPERATORS: {
262
270
  label: string;
263
271
  value: string;
264
272
  }[];
273
+ export declare function customOperatorTakesValue(operators: readonly CustomOperatorOption[], operator: unknown): boolean;
274
+ export declare function defaultCustomOperator(operators: readonly CustomOperatorOption[]): string | undefined;
265
275
  export type SuggestionItem = {
266
276
  label: string;
267
277
  };
@@ -50,6 +50,7 @@ export type FilterControlJson = {
50
50
  operators: {
51
51
  label: string;
52
52
  value: string;
53
+ takesValue?: boolean;
53
54
  }[];
54
55
  valueControl: FilterControlJson;
55
56
  initialValue?: any;
@@ -16,7 +16,7 @@ export type { Runtime } from '../framework/runtime';
16
16
  export type { ColumnDefinition } from '../framework/column-definition';
17
17
  export type { FieldQuery } from '../framework/column-definition';
18
18
  export type { FilterState } from '../framework/state';
19
- export type { FilterSchema, FilterField, FilterValueFormatter, FilterValueFormatContext, QueryTransformContext, SuggestionFetcher, TransformConditionResult } from '../framework/filters';
19
+ export type { CustomOperatorOption, FilterSchema, FilterField, FilterValueFormatter, FilterValueFormatContext, QueryTransformContext, SuggestionFetcher, TransformConditionResult } from '../framework/filters';
20
20
  export { TransformResult } from '../framework/filters';
21
21
  export * as FilterValue from '../framework/filterValue';
22
22
  export { FilterExpr } from '../dsl/filterExpr';
@@ -367,6 +367,23 @@ Annotate a hand-written one `ConditionOnlyTransform` — a transform typed
367
367
  `FilterTransform` may return either, which is not enough. A transform object
368
368
  with no `toQuery` at all is rejected too; it would do nothing at query time.
369
369
 
370
+ An operator marked `takesValue: false` filters without a value, as `is empty`
371
+ does. The form hides the value control while it is chosen, the filter counts as
372
+ set with an empty value, and the pill reads `Comment is empty`. A new filter
373
+ starts with the first operator that takes a value. The filter's own transform
374
+ gets `{ operator, value }` with an empty `value` and builds the condition;
375
+ `hasuraCustomOperator` has no condition for an empty value.
376
+
377
+ ```ts
378
+ FilterControl.customOperator({
379
+ operators: [
380
+ { label: 'contains', value: 'contains' },
381
+ { label: 'is empty', value: 'isEmpty', takesValue: false }
382
+ ],
383
+ valueControl: FilterControl.text()
384
+ });
385
+ ```
386
+
370
387
  ### Row-scoped builders
371
388
 
372
389
  `FilterExpr` accepts any field name and is checked when the expression reaches
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronor/dtv",
3
- "version": "10.1.0",
3
+ "version": "10.1.1",
4
4
  "description": "Schema-driven, declarative table views with advanced filtering, data fetching and AI-assisted filter generation.",
5
5
  "repository": {
6
6
  "type": "git",