@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.
- package/package.json +167 -1
- package/src/.kiva/config.json +27 -0
- package/src/components/avatar-group.tsx +222 -0
- package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
- package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
- package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
- package/src/components/kiva/calendar/animations.ts +40 -0
- package/src/components/kiva/calendar/calendar-body.tsx +106 -0
- package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
- package/src/components/kiva/calendar/calendar.tsx +243 -0
- package/src/components/kiva/calendar/constants.ts +12 -0
- package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
- package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
- package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
- package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
- package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
- package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
- package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
- package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
- package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
- package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
- package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
- package/src/components/kiva/calendar/header/filter.tsx +80 -0
- package/src/components/kiva/calendar/header/today-button.tsx +49 -0
- package/src/components/kiva/calendar/header/user-select.tsx +111 -0
- package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
- package/src/components/kiva/calendar/helpers.ts +617 -0
- package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
- package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
- package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
- package/src/components/kiva/calendar/hooks.ts +5 -0
- package/src/components/kiva/calendar/index.tsx +27 -0
- package/src/components/kiva/calendar/interfaces.ts +35 -0
- package/src/components/kiva/calendar/schemas.ts +20 -0
- package/src/components/kiva/calendar/settings/settings.tsx +116 -0
- package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
- package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
- package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
- package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
- package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
- package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
- package/src/components/kiva/calendar/types.ts +25 -0
- package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
- package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
- package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
- package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
- package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
- package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
- package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
- package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
- package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
- package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
- package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
- package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
- package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
- package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
- package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
- package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
- package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
- package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
- package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
- package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
- package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
- package/src/components/kiva/date-time-picker.tsx +163 -0
- package/src/components/kiva/editable-record-detail.tsx +809 -0
- package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
- package/src/components/kiva/enum-option-editor/index.tsx +26 -0
- package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
- package/src/components/kiva/enum-option-editor/types.ts +90 -0
- package/src/components/kiva/kanban.tsx +1376 -0
- package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
- package/src/components/kiva/map.tsx +1631 -0
- package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
- package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
- package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
- package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
- package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
- package/src/components/kiva/pivot-calendar/index.tsx +32 -0
- package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
- package/src/components/kiva/pivot-calendar/types.ts +154 -0
- package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
- package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
- package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
- package/src/components/kiva/pivot-filter/index.tsx +9 -0
- package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
- package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
- package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
- package/src/components/kiva/pivot-filter/types.ts +82 -0
- package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
- package/src/components/kiva/pivot-grid/index.tsx +23 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
- package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
- package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
- package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
- package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
- package/src/components/kiva/pivot-grid/types.ts +195 -0
- package/src/components/kiva/place-autocomplete.tsx +484 -0
- package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
- package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
- package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
- package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
- package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
- package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
- package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
- package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
- package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
- package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
- package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
- package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
- package/src/hooks/kiva/use-data-export.tsx +265 -0
- package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
- package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
- package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
- package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
- package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
- package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
- package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
- package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
- package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
- package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
- package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
- package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
- package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { type RefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type ColumnDef,
|
|
7
|
+
type ColumnPinningState,
|
|
8
|
+
type ColumnSizingState,
|
|
9
|
+
type Table
|
|
10
|
+
} from '@tanstack/react-table';
|
|
11
|
+
import { type VirtualItem } from '@tanstack/react-virtual';
|
|
12
|
+
|
|
13
|
+
export type PivotGridAggregate = 'sum' | 'count' | 'avg' | 'min' | 'max';
|
|
14
|
+
|
|
15
|
+
export type PivotGridColorScope = 'leaf' | 'subtotal' | 'total' | 'grand-total';
|
|
16
|
+
|
|
17
|
+
export type PivotGridPinPosition = 'left' | 'right' | false;
|
|
18
|
+
|
|
19
|
+
export type PivotGridRenderedRowKind
|
|
20
|
+
= | 'group'
|
|
21
|
+
| 'leaf'
|
|
22
|
+
| 'subtotal'
|
|
23
|
+
| 'grand-total';
|
|
24
|
+
|
|
25
|
+
export type PivotGridRenderedColumnKind
|
|
26
|
+
= | 'leaf'
|
|
27
|
+
| 'subtotal'
|
|
28
|
+
| 'grand-total';
|
|
29
|
+
|
|
30
|
+
export interface PivotGridDimension<TData> {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
getValue: (row: TData) => unknown;
|
|
34
|
+
formatValue?: (value: unknown) => string;
|
|
35
|
+
sort?: (a: unknown, b: unknown) => number;
|
|
36
|
+
emptyLabel?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PivotGridMeasure<TData> {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
getValue?: (row: TData) => number | null | undefined;
|
|
43
|
+
aggregate: PivotGridAggregate;
|
|
44
|
+
formatValue?: (value: number) => string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PivotGridCellColorRule {
|
|
48
|
+
formula: string;
|
|
49
|
+
color: string;
|
|
50
|
+
scope?: PivotGridColorScope;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface PivotGridState {
|
|
54
|
+
expandedRowIds: Record<string, boolean>;
|
|
55
|
+
expandedColumnIds: Record<string, boolean>;
|
|
56
|
+
columnPinning: ColumnPinningState;
|
|
57
|
+
columnSizing: ColumnSizingState;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PivotGridDrilldown<TData> {
|
|
61
|
+
columns?: Array<ColumnDef<TData>>;
|
|
62
|
+
getTitle?: (cell: PivotGridRenderedCell<TData>) => string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface UsePivotGridProps<TData> {
|
|
66
|
+
data: Array<TData>;
|
|
67
|
+
rowDimensions: Array<PivotGridDimension<TData>>;
|
|
68
|
+
columnDimensions: Array<PivotGridDimension<TData>>;
|
|
69
|
+
measures: Array<PivotGridMeasure<TData>>;
|
|
70
|
+
getRowId?: (row: TData, index: number) => string;
|
|
71
|
+
initialState?: Partial<PivotGridState>;
|
|
72
|
+
cellColorRules?: Array<PivotGridCellColorRule>;
|
|
73
|
+
drilldown?: PivotGridDrilldown<TData>;
|
|
74
|
+
height?: number | 'auto';
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type PivotGridProps<TData> = UsePivotGridProps<TData>;
|
|
79
|
+
|
|
80
|
+
export interface PivotGridHeaderPathSegment {
|
|
81
|
+
key: string;
|
|
82
|
+
label: string;
|
|
83
|
+
groupNodeId?: string;
|
|
84
|
+
canCollapse?: boolean;
|
|
85
|
+
isExpanded?: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PivotGridLeafColumn<TData> {
|
|
89
|
+
id: string;
|
|
90
|
+
ownerNodeId?: string;
|
|
91
|
+
measure: PivotGridMeasure<TData>;
|
|
92
|
+
kind: PivotGridRenderedColumnKind;
|
|
93
|
+
headerPath: Array<string>;
|
|
94
|
+
headerPathSegments: Array<PivotGridHeaderPathSegment | null>;
|
|
95
|
+
pathLabels: Array<string>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface PivotGridRowHeaderCell {
|
|
99
|
+
key: string;
|
|
100
|
+
label: string;
|
|
101
|
+
kind: PivotGridRenderedRowKind | 'blank';
|
|
102
|
+
depth: number;
|
|
103
|
+
isCurrentDepth: boolean;
|
|
104
|
+
canToggle: boolean;
|
|
105
|
+
isExpanded: boolean;
|
|
106
|
+
groupNodeId?: string;
|
|
107
|
+
rawRowCount: number;
|
|
108
|
+
title?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface PivotGridRenderedCell<_TData> {
|
|
112
|
+
id: string;
|
|
113
|
+
rowId: string;
|
|
114
|
+
columnId: string;
|
|
115
|
+
measureId: string;
|
|
116
|
+
value: number;
|
|
117
|
+
formattedValue: string;
|
|
118
|
+
rowPath: Array<string>;
|
|
119
|
+
columnPath: Array<string>;
|
|
120
|
+
rawRowCount: number;
|
|
121
|
+
rawRowIndices: Array<number>;
|
|
122
|
+
rawRowIds: Array<string>;
|
|
123
|
+
kind: PivotGridRenderedColumnKind;
|
|
124
|
+
isSubtotal: boolean;
|
|
125
|
+
isTotal: boolean;
|
|
126
|
+
isGrandTotal: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface PivotGridRenderedRow<TData> {
|
|
130
|
+
id: string;
|
|
131
|
+
kind: PivotGridRenderedRowKind;
|
|
132
|
+
depth: number;
|
|
133
|
+
pathLabels: Array<string>;
|
|
134
|
+
headerCells: Array<PivotGridRowHeaderCell>;
|
|
135
|
+
rawRowIndices: Array<number>;
|
|
136
|
+
rawRowIds: Array<string>;
|
|
137
|
+
rawRowCount: number;
|
|
138
|
+
cellMap: Map<string, PivotGridRenderedCell<TData>>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface PivotGridHeaderCell {
|
|
142
|
+
key: string;
|
|
143
|
+
label: string;
|
|
144
|
+
level: number;
|
|
145
|
+
columnIds: Array<string>;
|
|
146
|
+
colSpan: number;
|
|
147
|
+
pinPosition: PivotGridPinPosition;
|
|
148
|
+
groupNodeId?: string;
|
|
149
|
+
canCollapse: boolean;
|
|
150
|
+
isExpanded: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface PivotGridHeaderRow {
|
|
154
|
+
id: string;
|
|
155
|
+
level: number;
|
|
156
|
+
cells: Array<PivotGridHeaderCell>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface PivotGridDrilldownState<TData> {
|
|
160
|
+
open: boolean;
|
|
161
|
+
cell: PivotGridRenderedCell<TData> | null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface PivotGridController<TData> {
|
|
165
|
+
table: Table<PivotGridRenderedRow<TData>>;
|
|
166
|
+
dataGridRef: RefObject<HTMLDivElement | null>;
|
|
167
|
+
height: number | 'auto';
|
|
168
|
+
className?: string;
|
|
169
|
+
rowHeaderColumnIds: Array<string>;
|
|
170
|
+
valueColumnIds: Array<string>;
|
|
171
|
+
visibleLeafColumns: Array<PivotGridLeafColumn<TData>>;
|
|
172
|
+
headerDepth: number;
|
|
173
|
+
headerRows: Array<PivotGridHeaderRow>;
|
|
174
|
+
visibleRows: Array<PivotGridRenderedRow<TData>>;
|
|
175
|
+
virtualItems: Array<VirtualItem>;
|
|
176
|
+
virtualTotalSize: number;
|
|
177
|
+
cellColorMap: Map<string, string>;
|
|
178
|
+
drilldownColumns?: Array<ColumnDef<TData>>;
|
|
179
|
+
drilldownState: PivotGridDrilldownState<TData>;
|
|
180
|
+
toggleRow: (nodeId: string) => void;
|
|
181
|
+
toggleColumn: (nodeId: string) => void;
|
|
182
|
+
expandAllRows: () => void;
|
|
183
|
+
collapseAllRows: () => void;
|
|
184
|
+
expandAllColumns: () => void;
|
|
185
|
+
collapseAllColumns: () => void;
|
|
186
|
+
pinColumns: (columnIds: Array<string>, position: Exclude<PivotGridPinPosition, false>) => void;
|
|
187
|
+
unpinColumns: (columnIds: Array<string>) => void;
|
|
188
|
+
openDrilldown: (cell: PivotGridRenderedCell<TData>) => void;
|
|
189
|
+
closeDrilldown: () => void;
|
|
190
|
+
getDrilldownRows: (cell: PivotGridRenderedCell<TData>) => Array<TData>;
|
|
191
|
+
getDrilldownTitle: (cell: PivotGridRenderedCell<TData>) => string;
|
|
192
|
+
exportCsv: () => Promise<void>;
|
|
193
|
+
exportExcel: () => Promise<void>;
|
|
194
|
+
exportPdf: () => Promise<void>;
|
|
195
|
+
}
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import {
|
|
6
|
+
useCallback, useEffect, useRef, useState, type InputHTMLAttributes, type Ref
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
10
|
+
|
|
11
|
+
import { MapPin, Search, X } from 'lucide-react';
|
|
12
|
+
|
|
13
|
+
import { cn } from '@kivacore/ui-pro-shared/lib/utils';
|
|
14
|
+
import {
|
|
15
|
+
Command,
|
|
16
|
+
CommandEmpty,
|
|
17
|
+
CommandGroup,
|
|
18
|
+
CommandItem,
|
|
19
|
+
CommandList
|
|
20
|
+
} from '@kivacore/ui-pro-shared/components/command';
|
|
21
|
+
import { Spinner } from '@kivacore/ui-pro-shared/components/spinner';
|
|
22
|
+
|
|
23
|
+
import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
|
|
24
|
+
/* -------------------------------------------------------------------------- */
|
|
25
|
+
/* GeoJSON types (subset for Photon API) */
|
|
26
|
+
/* -------------------------------------------------------------------------- */
|
|
27
|
+
|
|
28
|
+
interface PlaceFeatureProperties {
|
|
29
|
+
osm_id: number;
|
|
30
|
+
osm_type: 'N' | 'W' | 'R';
|
|
31
|
+
osm_key: string;
|
|
32
|
+
osm_value: string;
|
|
33
|
+
type: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
housenumber?: string;
|
|
36
|
+
street?: string;
|
|
37
|
+
locality?: string;
|
|
38
|
+
district?: string;
|
|
39
|
+
postcode?: string;
|
|
40
|
+
city?: string;
|
|
41
|
+
county?: string;
|
|
42
|
+
state?: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
countrycode?: string;
|
|
45
|
+
extent?: [number, number, number, number];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* -------------------------------------------------------------------------- */
|
|
49
|
+
/* Variants */
|
|
50
|
+
/* -------------------------------------------------------------------------- */
|
|
51
|
+
|
|
52
|
+
const placeAutocompleteVariants = cva(
|
|
53
|
+
'flex items-center gap-2 rounded-md border bg-background shadow-xs transition-[color,box-shadow]',
|
|
54
|
+
{
|
|
55
|
+
variants: {
|
|
56
|
+
variant: {
|
|
57
|
+
default: 'border-input focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50',
|
|
58
|
+
outline: 'border-border focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50',
|
|
59
|
+
ghost: 'border-transparent shadow-none focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50'
|
|
60
|
+
},
|
|
61
|
+
size: {
|
|
62
|
+
sm: 'h-8 px-2 text-xs',
|
|
63
|
+
default: 'h-9 px-2.5 text-sm',
|
|
64
|
+
lg: 'h-11 px-3 text-base'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
defaultVariants: {
|
|
68
|
+
variant: 'default',
|
|
69
|
+
size: 'default'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/* -------------------------------------------------------------------------- */
|
|
75
|
+
/* Helpers */
|
|
76
|
+
/* -------------------------------------------------------------------------- */
|
|
77
|
+
|
|
78
|
+
function formatAddress(properties: PlaceFeatureProperties) {
|
|
79
|
+
const parts: string[] = [];
|
|
80
|
+
|
|
81
|
+
if (properties.name) parts.push(properties.name);
|
|
82
|
+
|
|
83
|
+
if (properties.housenumber && properties.street) {
|
|
84
|
+
parts.push(`${properties.housenumber} ${properties.street}`);
|
|
85
|
+
} else if (properties.street) {
|
|
86
|
+
parts.push(properties.street);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (properties.city) {
|
|
90
|
+
parts.push(properties.city);
|
|
91
|
+
} else if (properties.locality) {
|
|
92
|
+
parts.push(properties.locality);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (properties.state && properties.state !== properties.city) {
|
|
96
|
+
parts.push(properties.state);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (properties.country) {
|
|
100
|
+
parts.push(properties.country);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [...new Set(parts)].join(', ');
|
|
104
|
+
}
|
|
105
|
+
/* -------------------------------------------------------------------------- */
|
|
106
|
+
/* GeoJSON types (subset for Photon API) */
|
|
107
|
+
/* -------------------------------------------------------------------------- */
|
|
108
|
+
|
|
109
|
+
interface PlaceFeature {
|
|
110
|
+
type: 'Feature';
|
|
111
|
+
geometry: {
|
|
112
|
+
type: 'Point';
|
|
113
|
+
coordinates: [number, number];
|
|
114
|
+
};
|
|
115
|
+
properties: PlaceFeatureProperties;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface PlaceFeatureCollection {
|
|
119
|
+
type: 'FeatureCollection';
|
|
120
|
+
features: PlaceFeature[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* -------------------------------------------------------------------------- */
|
|
124
|
+
/* Search options */
|
|
125
|
+
/* -------------------------------------------------------------------------- */
|
|
126
|
+
|
|
127
|
+
interface PlaceSearchOptions {
|
|
128
|
+
/** Search text (address, place name, or POI). */
|
|
129
|
+
query: string;
|
|
130
|
+
/** Preferred language for results (e.g., "en", "de", "fr"). */
|
|
131
|
+
lang?: string;
|
|
132
|
+
/** Maximum number of results to return. */
|
|
133
|
+
limit?: number;
|
|
134
|
+
/** Bounding box to restrict results: [minLon, minLat, maxLon, maxLat]. */
|
|
135
|
+
bbox?: [number, number, number, number];
|
|
136
|
+
/** Latitude used to bias results toward a specific location. */
|
|
137
|
+
lat?: number;
|
|
138
|
+
/** Longitude used to bias results toward a specific location. */
|
|
139
|
+
lon?: number;
|
|
140
|
+
/** Zoom level for location biasing (higher = more local). */
|
|
141
|
+
zoom?: number;
|
|
142
|
+
/** Strength of the location bias. */
|
|
143
|
+
locationBiasScale?: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function buildSearchUrl({
|
|
147
|
+
query,
|
|
148
|
+
bbox,
|
|
149
|
+
lang,
|
|
150
|
+
lat,
|
|
151
|
+
limit,
|
|
152
|
+
locationBiasScale,
|
|
153
|
+
lon,
|
|
154
|
+
zoom
|
|
155
|
+
}: PlaceSearchOptions) {
|
|
156
|
+
const url = new URL('https://photon.komoot.io/api');
|
|
157
|
+
|
|
158
|
+
url.searchParams.set('q', query);
|
|
159
|
+
|
|
160
|
+
if (lang) url.searchParams.set('lang', lang);
|
|
161
|
+
if (limit) url.searchParams.set('limit', String(limit));
|
|
162
|
+
if (bbox) url.searchParams.set('bbox', bbox.join(','));
|
|
163
|
+
|
|
164
|
+
if (lat !== undefined && lon !== undefined) {
|
|
165
|
+
url.searchParams.set('lat', String(lat));
|
|
166
|
+
url.searchParams.set('lon', String(lon));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (zoom !== undefined) url.searchParams.set('zoom', String(zoom));
|
|
170
|
+
if (locationBiasScale !== undefined) url.searchParams.set('location_bias_scale', String(locationBiasScale));
|
|
171
|
+
|
|
172
|
+
return String(url);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* -------------------------------------------------------------------------- */
|
|
176
|
+
/* Hooks */
|
|
177
|
+
/* -------------------------------------------------------------------------- */
|
|
178
|
+
|
|
179
|
+
function useDebounce<T>(value: T, delay: number = 300) {
|
|
180
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
|
181
|
+
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
const timer = setTimeout(() => setDebouncedValue(value), delay);
|
|
184
|
+
|
|
185
|
+
return () => clearTimeout(timer);
|
|
186
|
+
}, [value, delay]);
|
|
187
|
+
|
|
188
|
+
return debouncedValue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function usePlaceSearch({
|
|
192
|
+
debounceMs,
|
|
193
|
+
query,
|
|
194
|
+
lang,
|
|
195
|
+
limit,
|
|
196
|
+
bbox,
|
|
197
|
+
lat,
|
|
198
|
+
lon,
|
|
199
|
+
zoom,
|
|
200
|
+
locationBiasScale
|
|
201
|
+
}: { debounceMs: number } & PlaceSearchOptions) {
|
|
202
|
+
const [results, setResults] = useState<PlaceFeature[]>([]);
|
|
203
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
204
|
+
const [error, setError] = useState<Error | null>(null);
|
|
205
|
+
const [hasSearched, setHasSearched] = useState(false);
|
|
206
|
+
|
|
207
|
+
const debouncedQuery = useDebounce(query, debounceMs);
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
if (!debouncedQuery.trim()) {
|
|
211
|
+
queueMicrotask(() => {
|
|
212
|
+
setResults([]);
|
|
213
|
+
setIsLoading(false);
|
|
214
|
+
setHasSearched(false);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const abortController = new AbortController();
|
|
221
|
+
|
|
222
|
+
async function fetchResults() {
|
|
223
|
+
setIsLoading(true);
|
|
224
|
+
setError(null);
|
|
225
|
+
setHasSearched(true);
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const url = buildSearchUrl({
|
|
229
|
+
query: debouncedQuery, lang, limit, bbox, lat, lon, zoom, locationBiasScale
|
|
230
|
+
});
|
|
231
|
+
const response = await fetch(url, { signal: abortController.signal });
|
|
232
|
+
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
throw new Error(`Photon API error: ${response.status} ${response.statusText}`);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const data: PlaceFeatureCollection = await response.json();
|
|
238
|
+
const seen = new Set<number>();
|
|
239
|
+
const dedupedFeatures = data.features.filter((feature) => {
|
|
240
|
+
const id = feature.properties.osm_id;
|
|
241
|
+
|
|
242
|
+
if (seen.has(id)) return false;
|
|
243
|
+
seen.add(id);
|
|
244
|
+
|
|
245
|
+
return true;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
setResults(dedupedFeatures);
|
|
249
|
+
} catch (err) {
|
|
250
|
+
if (err instanceof Error && err.name !== 'AbortError') {
|
|
251
|
+
setError(err);
|
|
252
|
+
setResults([]);
|
|
253
|
+
}
|
|
254
|
+
} finally {
|
|
255
|
+
setIsLoading(false);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
fetchResults();
|
|
260
|
+
|
|
261
|
+
return () => abortController.abort();
|
|
262
|
+
}, [
|
|
263
|
+
debouncedQuery,
|
|
264
|
+
lang,
|
|
265
|
+
limit,
|
|
266
|
+
bbox,
|
|
267
|
+
lat,
|
|
268
|
+
lon,
|
|
269
|
+
zoom,
|
|
270
|
+
locationBiasScale
|
|
271
|
+
]);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
results, isLoading, error, hasSearched
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* -------------------------------------------------------------------------- */
|
|
279
|
+
/* Component */
|
|
280
|
+
/* -------------------------------------------------------------------------- */
|
|
281
|
+
|
|
282
|
+
export interface PlaceAutocompleteProps
|
|
283
|
+
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'size'>,
|
|
284
|
+
Omit<PlaceSearchOptions, 'query'>,
|
|
285
|
+
VariantProps<typeof placeAutocompleteVariants> {
|
|
286
|
+
ref?: Ref<HTMLInputElement>;
|
|
287
|
+
/** Debounce delay in milliseconds before triggering a search. */
|
|
288
|
+
debounceMs?: number;
|
|
289
|
+
/** Current input value (controlled). */
|
|
290
|
+
value?: string;
|
|
291
|
+
/** Initial input value (uncontrolled). */
|
|
292
|
+
defaultValue?: string;
|
|
293
|
+
/** Called when the input value changes. */
|
|
294
|
+
onChange?: (value: string) => void;
|
|
295
|
+
/** Called when a place is selected from the results. */
|
|
296
|
+
onPlaceSelect?: (feature: PlaceFeature) => void;
|
|
297
|
+
/** Called when the search results change. */
|
|
298
|
+
onResultsChange?: (results: PlaceFeature[]) => void;
|
|
299
|
+
/** Locale for i18n translations. */
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function PlaceAutocomplete({
|
|
303
|
+
className,
|
|
304
|
+
variant,
|
|
305
|
+
size,
|
|
306
|
+
debounceMs = 300,
|
|
307
|
+
lang,
|
|
308
|
+
limit = 5,
|
|
309
|
+
bbox,
|
|
310
|
+
lat,
|
|
311
|
+
lon,
|
|
312
|
+
zoom,
|
|
313
|
+
locationBiasScale,
|
|
314
|
+
value: controlledValue,
|
|
315
|
+
defaultValue = '',
|
|
316
|
+
onChange: controlledOnChange,
|
|
317
|
+
onPlaceSelect,
|
|
318
|
+
onResultsChange,
|
|
319
|
+
placeholder,
|
|
320
|
+
disabled = false, ref, ...props
|
|
321
|
+
}: PlaceAutocompleteProps) {
|
|
322
|
+
const { t } = useUiTranslation();
|
|
323
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
324
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
325
|
+
const internalRef = useRef<HTMLInputElement>(null);
|
|
326
|
+
|
|
327
|
+
const isControlled = controlledValue !== undefined;
|
|
328
|
+
const displayValue = isControlled ? controlledValue : internalValue;
|
|
329
|
+
|
|
330
|
+
const setRefs = useCallback(
|
|
331
|
+
(node: HTMLInputElement | null) => {
|
|
332
|
+
internalRef.current = node;
|
|
333
|
+
if (typeof ref === 'function') ref(node);
|
|
334
|
+
else if (ref) ref.current = node;
|
|
335
|
+
},
|
|
336
|
+
[ref]
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const {
|
|
340
|
+
results, isLoading, error, hasSearched
|
|
341
|
+
} = usePlaceSearch({
|
|
342
|
+
query: searchQuery,
|
|
343
|
+
debounceMs,
|
|
344
|
+
lang,
|
|
345
|
+
limit,
|
|
346
|
+
bbox,
|
|
347
|
+
lat,
|
|
348
|
+
lon,
|
|
349
|
+
zoom,
|
|
350
|
+
locationBiasScale
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
onResultsChange?.(results);
|
|
355
|
+
}, [results, onResultsChange]);
|
|
356
|
+
|
|
357
|
+
const handleClear = useCallback(() => {
|
|
358
|
+
if (!isControlled) setInternalValue('');
|
|
359
|
+
setSearchQuery('');
|
|
360
|
+
controlledOnChange?.('');
|
|
361
|
+
internalRef.current?.focus();
|
|
362
|
+
}, [isControlled, controlledOnChange]);
|
|
363
|
+
|
|
364
|
+
const hasNoResults = hasSearched && !isLoading && !error && results.length === 0;
|
|
365
|
+
const showCommandList = error || hasNoResults || results.length > 0;
|
|
366
|
+
|
|
367
|
+
return (
|
|
368
|
+
<Command
|
|
369
|
+
className="h-fit overflow-visible bg-transparent"
|
|
370
|
+
shouldFilter={false}
|
|
371
|
+
loop>
|
|
372
|
+
<div className="relative">
|
|
373
|
+
<div
|
|
374
|
+
className={cn(
|
|
375
|
+
placeAutocompleteVariants({ variant, size }),
|
|
376
|
+
showCommandList && 'rounded-b-none',
|
|
377
|
+
disabled && 'pointer-events-none cursor-not-allowed opacity-50',
|
|
378
|
+
className
|
|
379
|
+
)}>
|
|
380
|
+
<span className="shrink-0 text-muted-foreground">
|
|
381
|
+
<Search className="size-4" />
|
|
382
|
+
</span>
|
|
383
|
+
<input
|
|
384
|
+
ref={setRefs}
|
|
385
|
+
type="text"
|
|
386
|
+
data-slot="input"
|
|
387
|
+
value={displayValue}
|
|
388
|
+
onChange={(event) => {
|
|
389
|
+
const newValue = event.target.value;
|
|
390
|
+
|
|
391
|
+
if (!isControlled) setInternalValue(newValue);
|
|
392
|
+
setSearchQuery(newValue);
|
|
393
|
+
controlledOnChange?.(newValue);
|
|
394
|
+
}}
|
|
395
|
+
placeholder={placeholder ?? t('ui.placeAutocomplete.searchPlaces', 'Search places...')}
|
|
396
|
+
disabled={disabled}
|
|
397
|
+
autoComplete="off"
|
|
398
|
+
autoCorrect="off"
|
|
399
|
+
autoCapitalize="off"
|
|
400
|
+
spellCheck={false}
|
|
401
|
+
className="min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
402
|
+
{...props} />
|
|
403
|
+
{isLoading && (
|
|
404
|
+
<span className="shrink-0 text-muted-foreground">
|
|
405
|
+
<Spinner className="size-4" />
|
|
406
|
+
</span>
|
|
407
|
+
)}
|
|
408
|
+
{!isLoading && displayValue ? (
|
|
409
|
+
<button
|
|
410
|
+
type="button"
|
|
411
|
+
tabIndex={-1}
|
|
412
|
+
aria-label={t('ui.placeAutocomplete.clearSearch', 'Clear search')}
|
|
413
|
+
className="shrink-0 cursor-pointer text-muted-foreground hover:text-foreground"
|
|
414
|
+
onClick={handleClear}
|
|
415
|
+
disabled={disabled}>
|
|
416
|
+
<X className="size-4" />
|
|
417
|
+
</button>
|
|
418
|
+
) : null}
|
|
419
|
+
</div>
|
|
420
|
+
{showCommandList && (
|
|
421
|
+
<CommandList
|
|
422
|
+
data-state={showCommandList ? 'open' : 'closed'}
|
|
423
|
+
className={cn(
|
|
424
|
+
'bg-popover border-input absolute top-full right-0 left-0 z-50 rounded-b-md border border-t-0 shadow-md',
|
|
425
|
+
'data-[state=open]:animate-in data-[state=closed]:animate-out',
|
|
426
|
+
'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
427
|
+
'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
|
428
|
+
'data-[state=open]:slide-in-from-top-2 data-[state=closed]:slide-out-to-top-2'
|
|
429
|
+
)}>
|
|
430
|
+
{error && (
|
|
431
|
+
<CommandEmpty>{t('ui.placeAutocomplete.error', 'Error:')}: {error.message}</CommandEmpty>
|
|
432
|
+
)}
|
|
433
|
+
{hasNoResults && (
|
|
434
|
+
<CommandEmpty>
|
|
435
|
+
{t('ui.placeAutocomplete.noPlacesFound', 'No places found for')} “{displayValue}”.
|
|
436
|
+
</CommandEmpty>
|
|
437
|
+
)}
|
|
438
|
+
{results.length > 0 && (
|
|
439
|
+
<CommandGroup>
|
|
440
|
+
{results.map((feature) => {
|
|
441
|
+
const address = formatAddress(feature.properties);
|
|
442
|
+
|
|
443
|
+
return (
|
|
444
|
+
<CommandItem
|
|
445
|
+
key={feature.properties.osm_id}
|
|
446
|
+
value={String(feature.properties.osm_id)}
|
|
447
|
+
onSelect={() => {
|
|
448
|
+
const selected = formatAddress(feature.properties);
|
|
449
|
+
|
|
450
|
+
if (!isControlled) setInternalValue(selected);
|
|
451
|
+
setSearchQuery('');
|
|
452
|
+
controlledOnChange?.(selected);
|
|
453
|
+
onPlaceSelect?.(feature);
|
|
454
|
+
}}>
|
|
455
|
+
<MapPin className="size-4 shrink-0" />
|
|
456
|
+
<div className="flex flex-col items-start text-start">
|
|
457
|
+
<span className="font-medium">
|
|
458
|
+
{feature.properties.name
|
|
459
|
+
|| feature.properties.street
|
|
460
|
+
|| t('ui.placeAutocomplete.unknown', 'Unknown')}
|
|
461
|
+
</span>
|
|
462
|
+
<span className="text-muted-foreground text-xs">
|
|
463
|
+
{address}
|
|
464
|
+
</span>
|
|
465
|
+
</div>
|
|
466
|
+
</CommandItem>
|
|
467
|
+
);
|
|
468
|
+
})}
|
|
469
|
+
</CommandGroup>
|
|
470
|
+
)}
|
|
471
|
+
</CommandList>
|
|
472
|
+
)}
|
|
473
|
+
</div>
|
|
474
|
+
</Command>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export type { PlaceFeatureProperties };
|
|
479
|
+
|
|
480
|
+
export {
|
|
481
|
+
PlaceAutocomplete,
|
|
482
|
+
type PlaceFeature,
|
|
483
|
+
type PlaceSearchOptions
|
|
484
|
+
};
|