|
| 1 | +import type { FullField } from '@react-querybuilder/core'; |
| 2 | +import type { Component } from 'solid-js'; |
| 3 | +import type { |
| 4 | + ActionProps, |
| 5 | + CombinatorSelectorProps, |
| 6 | + FieldSelectorProps, |
| 7 | + InlineCombinatorProps, |
| 8 | + MatchModeEditorProps, |
| 9 | + NotToggleProps, |
| 10 | + OperatorSelectorProps, |
| 11 | + RuleGroupProps, |
| 12 | + RuleProps, |
| 13 | + ShiftActionsProps, |
| 14 | + UndoRedoActionsProps, |
| 15 | + ValueEditorProps, |
| 16 | + ValueSelectorProps, |
| 17 | + ValueSourceSelectorProps, |
| 18 | +} from './props.js'; |
| 19 | + |
| 20 | +/** |
| 21 | + * Subcomponents. |
| 22 | + * |
| 23 | + * There is no `dragHandle` entry: drag-and-drop is a non-goal. There are no |
| 24 | + * `ruleGroupHeaderElements`/`ruleGroupBodyElements` entries either; to customize the contents |
| 25 | + * of a group's header or body, use a replacement `ruleGroup` component. |
| 26 | + * |
| 27 | + * @group Props |
| 28 | + */ |
| 29 | +export type ControlElementsProp<F extends FullField, O extends string> = Partial<{ |
| 30 | + /** |
| 31 | + * Default component for all button-type controls. |
| 32 | + * |
| 33 | + * @default ActionElement |
| 34 | + */ |
| 35 | + actionElement: Component<ActionProps>; |
| 36 | + /** |
| 37 | + * Adds a sub-group to the current group. |
| 38 | + * |
| 39 | + * @default ActionElement |
| 40 | + */ |
| 41 | + addGroupAction: Component<ActionProps> | null; |
| 42 | + /** |
| 43 | + * Adds a rule to the current group. |
| 44 | + * |
| 45 | + * @default ActionElement |
| 46 | + */ |
| 47 | + addRuleAction: Component<ActionProps> | null; |
| 48 | + /** |
| 49 | + * Clones the current group. |
| 50 | + * |
| 51 | + * @default ActionElement |
| 52 | + */ |
| 53 | + cloneGroupAction: Component<ActionProps> | null; |
| 54 | + /** |
| 55 | + * Clones the current rule. |
| 56 | + * |
| 57 | + * @default ActionElement |
| 58 | + */ |
| 59 | + cloneRuleAction: Component<ActionProps> | null; |
| 60 | + /** |
| 61 | + * Selects the `combinator` property for the current group, or the current independent |
| 62 | + * combinator value. |
| 63 | + * |
| 64 | + * @default ValueSelector |
| 65 | + */ |
| 66 | + combinatorSelector: Component<CombinatorSelectorProps> | null; |
| 67 | + /** |
| 68 | + * Selects the `field` property for the current rule. |
| 69 | + * |
| 70 | + * @default ValueSelector |
| 71 | + */ |
| 72 | + fieldSelector: Component<FieldSelectorProps<F>> | null; |
| 73 | + /** |
| 74 | + * A small wrapper around the `combinatorSelector` component. |
| 75 | + * |
| 76 | + * @default InlineCombinator |
| 77 | + */ |
| 78 | + inlineCombinator: Component<InlineCombinatorProps> | null; |
| 79 | + /** |
| 80 | + * Locks the current group (sets the `disabled` property to `true`). |
| 81 | + * |
| 82 | + * @default ActionElement |
| 83 | + */ |
| 84 | + lockGroupAction: Component<ActionProps> | null; |
| 85 | + /** |
| 86 | + * Locks the current rule (sets the `disabled` property to `true`). |
| 87 | + * |
| 88 | + * @default ActionElement |
| 89 | + */ |
| 90 | + lockRuleAction: Component<ActionProps> | null; |
| 91 | + /** |
| 92 | + * Mutes the current group (sets the `muted` property to `true`). |
| 93 | + * |
| 94 | + * @default ActionElement |
| 95 | + */ |
| 96 | + muteGroupAction: Component<ActionProps> | null; |
| 97 | + /** |
| 98 | + * Mutes the current rule (sets the `muted` property to `true`). |
| 99 | + * |
| 100 | + * @default ActionElement |
| 101 | + */ |
| 102 | + muteRuleAction: Component<ActionProps> | null; |
| 103 | + /** |
| 104 | + * Selects the `match` property for the current rule. |
| 105 | + * |
| 106 | + * @default MatchModeEditor |
| 107 | + */ |
| 108 | + matchModeEditor: Component<MatchModeEditorProps> | null; |
| 109 | + /** |
| 110 | + * Toggles the `not` property of the current group between `true` and `false`. |
| 111 | + * |
| 112 | + * @default NotToggle |
| 113 | + */ |
| 114 | + notToggle: Component<NotToggleProps> | null; |
| 115 | + /** |
| 116 | + * Selects the `operator` property for the current rule. |
| 117 | + * |
| 118 | + * @default ValueSelector |
| 119 | + */ |
| 120 | + operatorSelector: Component<OperatorSelectorProps> | null; |
| 121 | + /** |
| 122 | + * Removes the current group from its parent group's `rules` array. |
| 123 | + * |
| 124 | + * @default ActionElement |
| 125 | + */ |
| 126 | + removeGroupAction: Component<ActionProps> | null; |
| 127 | + /** |
| 128 | + * Removes the current rule from its parent group's `rules` array. |
| 129 | + * |
| 130 | + * @default ActionElement |
| 131 | + */ |
| 132 | + removeRuleAction: Component<ActionProps> | null; |
| 133 | + /** |
| 134 | + * Rule layout component. |
| 135 | + * |
| 136 | + * @default Rule |
| 137 | + */ |
| 138 | + rule: Component<RuleProps>; |
| 139 | + /** |
| 140 | + * Rule group layout component. |
| 141 | + * |
| 142 | + * @default RuleGroup |
| 143 | + */ |
| 144 | + ruleGroup: Component<RuleGroupProps<F, O>>; |
| 145 | + /** |
| 146 | + * Shifts the current rule/group up or down in the query hierarchy. |
| 147 | + * |
| 148 | + * @default ShiftActions |
| 149 | + */ |
| 150 | + shiftActions: Component<ShiftActionsProps> | null; |
| 151 | + /** |
| 152 | + * Undo/redo buttons for the outermost group, rendered when the `showUndoRedo` prop is |
| 153 | + * `true`. |
| 154 | + * |
| 155 | + * @default UndoRedoActions |
| 156 | + */ |
| 157 | + undoRedoActions: Component<UndoRedoActionsProps> | null; |
| 158 | + /** |
| 159 | + * Updates the `value` property for the current rule. |
| 160 | + * |
| 161 | + * @default ValueEditor |
| 162 | + */ |
| 163 | + valueEditor: Component<ValueEditorProps<F, O>> | null; |
| 164 | + /** |
| 165 | + * Default component for all value selector controls. |
| 166 | + * |
| 167 | + * @default ValueSelector |
| 168 | + */ |
| 169 | + valueSelector: Component<ValueSelectorProps>; |
| 170 | + /** |
| 171 | + * Selects the `valueSource` property for the current rule. |
| 172 | + * |
| 173 | + * @default ValueSelector |
| 174 | + */ |
| 175 | + valueSourceSelector: Component<ValueSourceSelectorProps> | null; |
| 176 | +}>; |
| 177 | + |
| 178 | +/** |
| 179 | + * All subcomponents, finalized: every key is present and non-nullable. `null` entries in |
| 180 | + * {@link ControlElementsProp} are replaced with a component that renders nothing, so no call |
| 181 | + * site needs a null check. |
| 182 | + * |
| 183 | + * Unlike React Query Builder, `undoRedoActions` is non-nullable: `QueryManager` owns the |
| 184 | + * history, so this package always ships a working implementation. |
| 185 | + * |
| 186 | + * @group Props |
| 187 | + */ |
| 188 | +export type Controls<F extends FullField, O extends string> = { |
| 189 | + [K in keyof Required<ControlElementsProp<F, O>>]-?: NonNullable< |
| 190 | + Required<ControlElementsProp<F, O>>[K] |
| 191 | + >; |
| 192 | +}; |
0 commit comments