@kivacore/ui-pro-shared 0.0.9 → 0.0.11

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.
Files changed (145) hide show
  1. package/package.json +167 -1
  2. package/src/.kiva/config.json +27 -0
  3. package/src/components/avatar-group.tsx +222 -0
  4. package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
  5. package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
  6. package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
  7. package/src/components/kiva/calendar/animations.ts +40 -0
  8. package/src/components/kiva/calendar/calendar-body.tsx +106 -0
  9. package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
  10. package/src/components/kiva/calendar/calendar.tsx +243 -0
  11. package/src/components/kiva/calendar/constants.ts +12 -0
  12. package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
  13. package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
  14. package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
  15. package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
  16. package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
  17. package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
  18. package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
  19. package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
  20. package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
  21. package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
  22. package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
  23. package/src/components/kiva/calendar/header/filter.tsx +80 -0
  24. package/src/components/kiva/calendar/header/today-button.tsx +49 -0
  25. package/src/components/kiva/calendar/header/user-select.tsx +111 -0
  26. package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
  27. package/src/components/kiva/calendar/helpers.ts +617 -0
  28. package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
  29. package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
  30. package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
  31. package/src/components/kiva/calendar/hooks.ts +5 -0
  32. package/src/components/kiva/calendar/index.tsx +27 -0
  33. package/src/components/kiva/calendar/interfaces.ts +35 -0
  34. package/src/components/kiva/calendar/schemas.ts +20 -0
  35. package/src/components/kiva/calendar/settings/settings.tsx +116 -0
  36. package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
  37. package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
  38. package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
  39. package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
  40. package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
  41. package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
  42. package/src/components/kiva/calendar/types.ts +25 -0
  43. package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
  44. package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
  45. package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
  46. package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
  47. package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
  48. package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
  49. package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
  50. package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
  51. package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
  52. package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
  53. package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
  54. package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
  55. package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
  56. package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
  57. package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
  58. package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
  59. package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
  60. package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
  61. package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
  62. package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
  63. package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
  64. package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
  65. package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
  66. package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
  67. package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
  68. package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
  69. package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
  70. package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
  71. package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
  72. package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
  73. package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
  74. package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
  75. package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
  76. package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
  77. package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
  78. package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
  79. package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
  80. package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
  81. package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
  82. package/src/components/kiva/date-time-picker.tsx +163 -0
  83. package/src/components/kiva/editable-record-detail.tsx +809 -0
  84. package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
  85. package/src/components/kiva/enum-option-editor/index.tsx +26 -0
  86. package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
  87. package/src/components/kiva/enum-option-editor/types.ts +90 -0
  88. package/src/components/kiva/kanban.tsx +1376 -0
  89. package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
  90. package/src/components/kiva/map.tsx +1631 -0
  91. package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
  92. package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
  93. package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
  94. package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
  95. package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
  96. package/src/components/kiva/pivot-calendar/index.tsx +32 -0
  97. package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
  98. package/src/components/kiva/pivot-calendar/types.ts +154 -0
  99. package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
  100. package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
  101. package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
  102. package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
  103. package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
  104. package/src/components/kiva/pivot-filter/index.tsx +9 -0
  105. package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
  106. package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
  107. package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
  108. package/src/components/kiva/pivot-filter/types.ts +82 -0
  109. package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
  110. package/src/components/kiva/pivot-grid/index.tsx +23 -0
  111. package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
  112. package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
  113. package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
  114. package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
  115. package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
  116. package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
  117. package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
  118. package/src/components/kiva/pivot-grid/types.ts +195 -0
  119. package/src/components/kiva/place-autocomplete.tsx +484 -0
  120. package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
  121. package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
  122. package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
  123. package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
  124. package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
  125. package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
  126. package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
  127. package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
  128. package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
  129. package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
  130. package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
  131. package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
  132. package/src/hooks/kiva/use-data-export.tsx +265 -0
  133. package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
  134. package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
  135. package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
  136. package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
  137. package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
  138. package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
  139. package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
  140. package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
  141. package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
  142. package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
  143. package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
  144. package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
  145. package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
@@ -0,0 +1,367 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import {
4
+ type RuleGroupType, type RuleType
5
+ } from 'react-querybuilder';
6
+
7
+ import { endOfDay, format, startOfDay } from 'date-fns';
8
+
9
+ import {
10
+ type ColumnConfig,
11
+ type ColumnDataType,
12
+ type FilterModel,
13
+ type FiltersState
14
+ } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
15
+
16
+ import { DEFAULT_OPERATORS } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/operators';
17
+ import { isCompleteUuid } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/lib/helpers';
18
+
19
+ import {
20
+ type SideFilterCombinator,
21
+ type SideFilterOperatorMap
22
+ } from './types';
23
+
24
+ /*
25
+ * These map DTF operators to the operator names the Kiva filter engine
26
+ * accepts (docs → Filter Operators Reference). The backend has no camelCase
27
+ * forms — `contains` / `doesNotContain` / `notIn` / `notBetween` / `notNull`
28
+ * are all rejected. Text search is `like` / `not like` over `%value%`.
29
+ */
30
+ export const DEFAULT_OPERATOR_MAP: SideFilterOperatorMap = {
31
+ text: {
32
+ contains: 'like',
33
+ 'does not contain': 'not like'
34
+ },
35
+ number: {
36
+ is: '=',
37
+ 'is not': '!=',
38
+ 'is less than': '<',
39
+ 'is greater than': '>',
40
+ 'is less than or equal to': '<=',
41
+ 'is greater than or equal to': '>=',
42
+ 'is between': 'between',
43
+ 'is not between': 'not between'
44
+ },
45
+ date: {
46
+ is: '=',
47
+ 'is not': '!=',
48
+ 'is before': '<',
49
+ 'is after': '>',
50
+ 'is on or after': '>=',
51
+ 'is on or before': '<=',
52
+ 'is between': 'between',
53
+ 'is not between': 'not between'
54
+ },
55
+ option: {
56
+ is: '=',
57
+ 'is not': '!=',
58
+ 'is any of': 'in',
59
+ 'is none of': 'not in'
60
+ },
61
+ /*
62
+ * Array-backed columns (uuid[] / text[] — e.g. `followers`, multi-select /
63
+ * tag-select). The Kiva backend rejects the scalar `in` / `not in` on
64
+ * array columns with a 500, so multiOption side filters serialize to the
65
+ * array-membership operators (`contains any` / `contains all` / `not
66
+ * contains`) — matching the toolbar filter path (`toServerRule`). Scalar
67
+ * reference columns should be modeled as `option` (which keeps `=` / `in`).
68
+ */
69
+ multiOption: {
70
+ include: 'contains any',
71
+ exclude: 'not contains',
72
+ 'include any of': 'contains any',
73
+ 'include all of': 'contains all',
74
+ 'exclude if any of': 'not contains',
75
+ 'exclude if all': 'not contains'
76
+ },
77
+ boolean: {
78
+ is: '=',
79
+ 'is not': '!=',
80
+ 'is empty': 'null',
81
+ 'is not empty': 'not null'
82
+ },
83
+ /*
84
+ * uuid (identity / PK) columns. Exact equality only — Postgres has no
85
+ * `LIKE` on `uuid`, so the `contains` operators that `text` exposes are
86
+ * absent. A partial value is dropped before serialization (see
87
+ * `filtersStateToRuleGroup`) so it never 500s with `invalid input syntax`.
88
+ */
89
+ uuid: {
90
+ is: '=',
91
+ 'is not': '!=',
92
+ 'is empty': 'null',
93
+ 'is not empty': 'not null'
94
+ }
95
+ };
96
+
97
+ /*
98
+ * QB operators whose right-hand value is an *end* boundary.
99
+ * For `notBetween` the `to` value is the upper bound, same as `between`.
100
+ */
101
+ const END_SIDE_QB_OPERATORS = new Set([
102
+ 'between',
103
+ 'not between',
104
+ '<',
105
+ '<='
106
+ ]);
107
+
108
+ const RANGE_QB_OPERATORS = new Set(['between', 'not between']);
109
+ const ARRAY_QB_OPERATORS = new Set([
110
+ 'in',
111
+ 'not in',
112
+ 'containsAll',
113
+ 'doesNotContainAll',
114
+ /*
115
+ * Kiva array-membership operators emitted for multiOption columns. They
116
+ * must be array-valued even for a single selection — `contains any` with a
117
+ * scalar value 500s on the backend.
118
+ */
119
+ 'contains any',
120
+ 'contains all',
121
+ 'not contains'
122
+ ]);
123
+ const NULLARY_QB_OPERATORS = new Set(['null', 'not null']);
124
+ const LIKE_QB_OPERATORS = new Set(['like', 'not like']);
125
+
126
+ function buildReverseMap(map: SideFilterOperatorMap) {
127
+ const reverse: Record<ColumnDataType, Record<string, string>> = {
128
+ text: {},
129
+ number: {},
130
+ date: {},
131
+ option: {},
132
+ multiOption: {},
133
+ boolean: {},
134
+ uuid: {}
135
+ };
136
+
137
+ for (const type of Object.keys(map) as Array<ColumnDataType>) {
138
+ const sub = map[type] as Record<string, string>;
139
+
140
+ for (const [dtfOp, qbOp] of Object.entries(sub)) {
141
+ if (!qbOp) continue;
142
+ const target = reverse[type] as Record<string, string>;
143
+
144
+ if (target[qbOp] === undefined) target[qbOp] = dtfOp;
145
+ }
146
+ }
147
+
148
+ return reverse;
149
+ }
150
+
151
+ /*
152
+ * Serialize a date value for the side-filter wire payload.
153
+ *
154
+ * Accepts both `Date` instances and date strings (DTF stores date values as
155
+ * strings in some code paths — e.g. `"2026-06-04T00:00:00"` — so we must
156
+ * handle both). Always emits a timezone-naive `yyyy-MM-dd'T'HH:mm:ss` string:
157
+ * - datetime columns (`includeTime=true`): preserve the wall-clock value.
158
+ * - date-only columns: start-side → 00:00:00, end-side → 23:59:59.
159
+ * End-side snapping to 23:59:59 ensures the picked boundary day is fully
160
+ * included — a `<=` against 00:00:00 drops all records created after
161
+ * midnight on that day.
162
+ */
163
+ function isMidnight(date: Date): boolean {
164
+ return date.getHours() === 0 && date.getMinutes() === 0 && date.getSeconds() === 0;
165
+ }
166
+
167
+ function serializeSideFilterDate(
168
+ value: Date | string,
169
+ includeTime: boolean,
170
+ isEnd: boolean
171
+ ): string {
172
+ const date = value instanceof Date ? value : new Date(value);
173
+
174
+ /*
175
+ * For end-side boundaries we snap to 23:59:59 when:
176
+ * - date-only column (includeTime=false): always snap
177
+ * - datetime column (includeTime=true): snap only when time is still
178
+ * the default midnight, meaning the user didn't explicitly pick a time.
179
+ * An explicit pick like 17:00 is preserved as-is.
180
+ */
181
+ if (isEnd && (!includeTime || isMidnight(date))) {
182
+ return format(endOfDay(date), "yyyy-MM-dd'T'HH:mm:ss");
183
+ }
184
+
185
+ if (!includeTime) {
186
+ return format(startOfDay(date), "yyyy-MM-dd'T'HH:mm:ss");
187
+ }
188
+
189
+ return format(date, "yyyy-MM-dd'T'HH:mm:ss");
190
+ }
191
+
192
+ function isDateValue(v: unknown): v is Date | string {
193
+ return v instanceof Date || (typeof v === 'string' && v.length > 0);
194
+ }
195
+
196
+ function ruleValueFromFilter<TType extends ColumnDataType>(
197
+ filter: FilterModel<TType>,
198
+ qbOperator: string,
199
+ includeTime: boolean
200
+ ): unknown {
201
+ if (NULLARY_QB_OPERATORS.has(qbOperator)) return null;
202
+
203
+ const isDateType = filter.type === 'date';
204
+
205
+ if (RANGE_QB_OPERATORS.has(qbOperator)) {
206
+ const [from, to] = filter.values as Array<unknown>;
207
+
208
+ if (isDateType) {
209
+ return [isDateValue(from) ? serializeSideFilterDate(from, includeTime, false) : from, isDateValue(to) ? serializeSideFilterDate(to, includeTime, true) : to];
210
+ }
211
+
212
+ return [from, to];
213
+ }
214
+
215
+ if (ARRAY_QB_OPERATORS.has(qbOperator)) return [...filter.values];
216
+
217
+ const single = filter.values.length <= 1 ? filter.values[0] : filter.values;
218
+ const isEndOp = END_SIDE_QB_OPERATORS.has(qbOperator);
219
+
220
+ if (isDateType && isDateValue(single)) {
221
+ return serializeSideFilterDate(single, includeTime, isEndOp);
222
+ }
223
+
224
+ /* `like` / `not like` match a SQL pattern, so wrap the term in %…% wildcards. */
225
+ if (LIKE_QB_OPERATORS.has(qbOperator) && typeof single === 'string') {
226
+ return `%${single}%`;
227
+ }
228
+
229
+ return single;
230
+ }
231
+
232
+ export function filtersStateToRuleGroup(
233
+ state: FiltersState,
234
+ combinator: SideFilterCombinator = 'and',
235
+ operatorMap: SideFilterOperatorMap = DEFAULT_OPERATOR_MAP,
236
+ columns: ReadonlyArray<ColumnConfig<unknown>> = []
237
+ ): RuleGroupType {
238
+ const colById = new Map(columns.map(c => [c.id, c]));
239
+
240
+ const rules: Array<RuleType> = state
241
+ .filter(f => f.values.length > 0
242
+ || f.operator === 'is empty'
243
+ || f.operator === 'is not empty')
244
+ /*
245
+ * Drop uuid equality filters whose value isn't a complete UUID — a
246
+ * partial value serializes to `id = '<partial>'` and 500s on Postgres
247
+ * (`invalid input syntax for type uuid`). Presence operators carry no
248
+ * value and pass through untouched.
249
+ */
250
+ .filter(f => f.type !== 'uuid'
251
+ || f.operator === 'is empty'
252
+ || f.operator === 'is not empty'
253
+ || isCompleteUuid(f.values[0]))
254
+ .map((filter) => {
255
+ const filterType = filter.type as ColumnDataType;
256
+ const sub = operatorMap[filterType] as Record<string, string> | undefined;
257
+ const qbOperator = sub?.[filter.operator] ?? filter.operator;
258
+ const colConfig = colById.get(filter.columnId);
259
+ const includeTime = filterType === 'date' && colConfig?.includeTime === true;
260
+
261
+ return {
262
+ field: filter.columnId,
263
+ operator: qbOperator,
264
+ value: ruleValueFromFilter(filter, qbOperator, includeTime)
265
+ } satisfies RuleType;
266
+ });
267
+
268
+ return { combinator, rules };
269
+ }
270
+
271
+ function valuesFromRule(
272
+ rule: RuleType,
273
+ type: ColumnDataType
274
+ ): Array<unknown> {
275
+ const value = rule.value as unknown;
276
+
277
+ if (NULLARY_QB_OPERATORS.has(rule.operator)) return [];
278
+ if (Array.isArray(value)) return value;
279
+ /* Undo the %…% wildcards forward serialization wraps a `like` term in. */
280
+ if (typeof value === 'string' && LIKE_QB_OPERATORS.has(rule.operator)) {
281
+ return [value.replace(/^%/, '').replace(/%$/, '')];
282
+ }
283
+ if (typeof value === 'string' && (RANGE_QB_OPERATORS.has(rule.operator) || ARRAY_QB_OPERATORS.has(rule.operator))) {
284
+ return value.split(',').map(v => v.trim()).filter(Boolean);
285
+ }
286
+
287
+ if (value === null || value === undefined || value === '') return [];
288
+
289
+ if (type === 'date' && !(value instanceof Date)) {
290
+ const str = value as string | number;
291
+ let parsed: Date;
292
+
293
+ /*
294
+ * date-only strings (e.g. "2026-06-04") parse as UTC midnight in most
295
+ * runtimes — wrong in UTC− locales. Reconstruct as local midnight instead.
296
+ */
297
+ if (typeof str === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(str)) {
298
+ const [y, m, d] = str.split('-').map(Number) as [number, number, number];
299
+
300
+ parsed = new Date(y, m - 1, d);
301
+ } else {
302
+ parsed = new Date(str);
303
+ }
304
+
305
+ return Number.isNaN(parsed.getTime()) ? [] : [parsed];
306
+ }
307
+
308
+ if (type === 'number' && typeof value !== 'number') {
309
+ const parsed = Number(value);
310
+
311
+ return Number.isNaN(parsed) ? [] : [parsed];
312
+ }
313
+
314
+ return [value];
315
+ }
316
+
317
+ function flattenRules(group: RuleGroupType): Array<RuleType> {
318
+ const out: Array<RuleType> = [];
319
+
320
+ for (const r of group.rules) {
321
+ if (typeof r === 'string') continue;
322
+ if ('rules' in r) {
323
+ out.push(...flattenRules(r));
324
+ } else {
325
+ out.push(r);
326
+ }
327
+ }
328
+
329
+ return out;
330
+ }
331
+
332
+ export function ruleGroupToFiltersState(
333
+ group: RuleGroupType,
334
+ columns: ReadonlyArray<ColumnConfig<unknown>>,
335
+ operatorMap: SideFilterOperatorMap = DEFAULT_OPERATOR_MAP
336
+ ): FiltersState {
337
+ const reverse = buildReverseMap(operatorMap);
338
+ const byId = new Map(columns.map(c => [c.id, c]));
339
+ const out: FiltersState = [];
340
+
341
+ for (const rule of flattenRules(group)) {
342
+ const column = byId.get(rule.field);
343
+
344
+ if (!column) continue;
345
+ const type = column.type as ColumnDataType;
346
+ const reverseSub = reverse[type] as Record<string, string>;
347
+ const dtfOperator = reverseSub[rule.operator]
348
+ ?? (rule.operator in (operatorMap[type] as object) ? rule.operator : undefined)
349
+ ?? DEFAULT_OPERATORS[type].single;
350
+ const values = valuesFromRule(rule, type);
351
+
352
+ if (values.length === 0
353
+ && dtfOperator !== 'is empty'
354
+ && dtfOperator !== 'is not empty') {
355
+ continue;
356
+ }
357
+
358
+ out.push({
359
+ columnId: column.id,
360
+ type,
361
+ operator: dtfOperator,
362
+ values
363
+ } as FilterModel);
364
+ }
365
+
366
+ return out;
367
+ }
@@ -0,0 +1,81 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { type ReactNode } from 'react';
4
+
5
+ import { type RuleGroupType } from 'react-querybuilder';
6
+
7
+ import {
8
+ type ColumnConfig,
9
+ type ColumnDataType,
10
+ type FilterModel,
11
+ type FiltersState
12
+ } from '@kivacore/ui-pro-shared/components/kiva/data-table-filter/core/types';
13
+
14
+ /**
15
+ * How a single column's filter is rendered in the side panel. Resolved per
16
+ * column via `lib/render-mode.ts`. `auto` lets the resolver pick.
17
+ */
18
+ export type SideFilterRenderMode
19
+ = | 'auto'
20
+ | 'text-input'
21
+ | 'inline-checkbox'
22
+ | 'dropdown-chips'
23
+ | 'date'
24
+ | 'date-range'
25
+ | 'numeric-range'
26
+ | 'boolean';
27
+
28
+ export interface SideFilterColumnDefaults {
29
+ mode?: SideFilterRenderMode;
30
+ /** Threshold above which inline-checkbox lists collapse behind a "Show more" button. */
31
+ showMoreThreshold?: number;
32
+ /** Section starts collapsed when true. */
33
+ collapsed?: boolean;
34
+ /** Pin the section above all unpinned sections. */
35
+ sticky?: boolean;
36
+ /** Override the section title. Defaults to `column.displayName`. */
37
+ title?: ReactNode;
38
+ /** Hide this column from the side panel completely. */
39
+ hidden?: boolean;
40
+ }
41
+
42
+ export type SideFilterDefaults = Record<string, SideFilterColumnDefaults>;
43
+
44
+ /**
45
+ * Optional grouping. When supplied, sections are rendered grouped under
46
+ * named headings; columns not listed here fall under an "Other" group at
47
+ * the bottom.
48
+ */
49
+ export interface SideFilterSectionGroup {
50
+ id: string;
51
+ title: ReactNode;
52
+ columnIds: ReadonlyArray<string>;
53
+ /** Render the group with a divider above its title. Default true. */
54
+ withDivider?: boolean;
55
+ }
56
+
57
+ export type SideFilterCombinator = 'and' | 'or';
58
+
59
+ /**
60
+ * Maps DataTableFilter operator strings to whatever operator vocabulary
61
+ * the consumer's QueryBuilder rules speak. The default map produces
62
+ * conventional `react-querybuilder` operators (`=`, `!=`, `<`, `>`,
63
+ * `between`, `in`, etc.); pass a custom one to keep DTF strings verbatim
64
+ * or to align with a back-end-specific dialect.
65
+ */
66
+ export type SideFilterOperatorMap = {
67
+ [T in ColumnDataType]: Partial<Record<FilterModel<T>['operator'], string>>;
68
+ };
69
+
70
+ export interface SideFilterTranslatorContext {
71
+ combinator: SideFilterCombinator;
72
+ operatorMap: SideFilterOperatorMap;
73
+ }
74
+
75
+ export type {
76
+ ColumnConfig,
77
+ ColumnDataType,
78
+ FilterModel,
79
+ FiltersState,
80
+ RuleGroupType
81
+ };