@kivacore/ui-pro-shared 0.0.9 → 0.0.10

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 +187 -21
  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,190 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import {
6
+ createElement,
7
+ useCallback,
8
+ useRef,
9
+ useState,
10
+ type ReactNode,
11
+ type RefObject
12
+ } from 'react';
13
+
14
+ import { type RestApiClient } from '@kivacore/api-client';
15
+
16
+ import {
17
+ Field,
18
+ FieldContent,
19
+ FieldDescription,
20
+ FieldLabel
21
+ } from '@kivacore/ui-pro-shared/components/field';
22
+ import { cn } from '@kivacore/ui-pro-shared/lib/utils';
23
+
24
+ import { useKivaFieldComponent } from '@kivacore/ui-pro-shared/hooks/kiva/use-kiva-field-component';
25
+
26
+ import { type KivaFormViewField, type LocalFormShape } from '@kivacore/ui-pro-shared/hooks/kiva/_internal/use-form-view-engine';
27
+
28
+ interface MacroFormFieldProps {
29
+ slug: string;
30
+ valuesRef: RefObject<Record<string, unknown>>;
31
+ resetSignal: number;
32
+ onFieldChange: RefObject<(slug: string, value: unknown) => void>;
33
+ validationErrors: RefObject<Map<string, string>>;
34
+ valuesVersion: number;
35
+ children: (field: any) => ReactNode;
36
+ }
37
+
38
+ export function MacroFormField({
39
+ slug,
40
+ valuesRef,
41
+ resetSignal,
42
+ onFieldChange,
43
+ validationErrors,
44
+ valuesVersion,
45
+ children
46
+ }: MacroFormFieldProps) {
47
+ const [localValue, setLocalValue] = useState<unknown>(() => valuesRef.current[slug]);
48
+ const [touched, setTouched] = useState(false);
49
+ const lastResetRef = useRef(resetSignal);
50
+
51
+ if (lastResetRef.current !== resetSignal) {
52
+ lastResetRef.current = resetSignal;
53
+ setLocalValue(valuesRef.current[slug]);
54
+ setTouched(false);
55
+ }
56
+
57
+ const handleChange = useCallback((value: unknown) => {
58
+ setLocalValue(value);
59
+ setTouched(true);
60
+ valuesRef.current[slug] = value;
61
+ onFieldChange.current(slug, value);
62
+ }, [onFieldChange, slug, valuesRef]);
63
+
64
+ const handleBlur = useCallback(() => {
65
+ setTouched(true);
66
+ }, []);
67
+
68
+ void valuesVersion;
69
+ const error = validationErrors.current.get(slug);
70
+ const hasError = error != null;
71
+
72
+ return (
73
+ <>
74
+ {children({
75
+ name: slug,
76
+ state: {
77
+ value: localValue,
78
+ meta: {
79
+ isTouched: touched || hasError,
80
+ isValid: !hasError,
81
+ errors: hasError ? [{ message: error }] : []
82
+ }
83
+ },
84
+ handleChange,
85
+ handleBlur
86
+ })}
87
+ </>
88
+ );
89
+ }
90
+
91
+ interface KivaFormViewMappedFormFieldProps {
92
+ resolvedField: KivaFormViewField;
93
+ form: LocalFormShape;
94
+ appSlug?: string;
95
+ dataSourceSlug?: string;
96
+ className?: string;
97
+ client?: RestApiClient;
98
+ }
99
+
100
+ export function KivaFormViewMappedFormField({
101
+ resolvedField,
102
+ form,
103
+ appSlug,
104
+ dataSourceSlug,
105
+ className,
106
+ client
107
+ }: KivaFormViewMappedFormFieldProps) {
108
+ const Component = useKivaFieldComponent(resolvedField.field.type, 'form-field');
109
+
110
+ if (!Component) {
111
+ return null;
112
+ }
113
+
114
+ /*
115
+ * When computedLabel (or fieldLayout.label) is a plain string, override field.name
116
+ * so every field component (which reads the label from field.name) shows the dynamic value.
117
+ */
118
+ const field = typeof resolvedField.label === 'string' ? { ...resolvedField.field, name: resolvedField.label } : resolvedField.field;
119
+
120
+ const fieldNode = createElement(Component, {
121
+ ...resolvedField.fieldProps,
122
+ field,
123
+ form,
124
+ disabled: resolvedField.disabled,
125
+ required: resolvedField.required,
126
+ enumOptions: resolvedField.enumOptions,
127
+ appSlug,
128
+ dataSourceSlug,
129
+ client,
130
+ className: cn(resolvedField.className, resolvedField.fieldProps?.className, className)
131
+ });
132
+
133
+ if (!resolvedField.description) {
134
+ return fieldNode;
135
+ }
136
+
137
+ return (
138
+ <>
139
+ {fieldNode}
140
+ <FieldDescription>{resolvedField.description}</FieldDescription>
141
+ </>
142
+ );
143
+ }
144
+
145
+ interface KivaFormViewMappedValueFieldProps {
146
+ resolvedField: KivaFormViewField;
147
+ values: Record<string, unknown>;
148
+ wrapperClassName?: string;
149
+ className?: string;
150
+ label?: ReactNode;
151
+ description?: ReactNode;
152
+ client?: RestApiClient;
153
+ }
154
+
155
+ export function KivaFormViewMappedValueField({
156
+ resolvedField,
157
+ values,
158
+ wrapperClassName,
159
+ className,
160
+ label,
161
+ description,
162
+ client
163
+ }: KivaFormViewMappedValueFieldProps) {
164
+ const Component = useKivaFieldComponent(resolvedField.field.type, 'value-renderer');
165
+
166
+ return (
167
+ <Field className={cn(wrapperClassName, resolvedField.className)}>
168
+ <FieldLabel>
169
+ {label ?? resolvedField.label ?? resolvedField.field.name}
170
+ {resolvedField.required && <span className="text-destructive">*</span>}
171
+ </FieldLabel>
172
+ <FieldContent>
173
+ <div className="min-h-9 rounded-md border bg-muted/20 px-3 py-2">
174
+ {createElement(Component, {
175
+ ...resolvedField.valueProps,
176
+ field: resolvedField.field,
177
+ value: values[resolvedField.slug],
178
+ record: values,
179
+ enumOptions: resolvedField.enumOptions,
180
+ client,
181
+ className: cn(resolvedField.valueProps?.className, className)
182
+ })}
183
+ </div>
184
+ {(description ?? resolvedField.description) && (
185
+ <FieldDescription>{description ?? resolvedField.description}</FieldDescription>
186
+ )}
187
+ </FieldContent>
188
+ </Field>
189
+ );
190
+ }
@@ -0,0 +1,311 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import { type ReactNode } from 'react';
6
+
7
+ import {
8
+ type KivaKanbanCardContext,
9
+ type KivaKanbanCardMenuItem,
10
+ type KivaKanbanColumnMeta, readUserMeta
11
+ } from '@kivacore/ui-pro-shared/hooks/kiva/use-kiva-kanban';
12
+
13
+ import { type UniqueIdentifier } from '@dnd-kit/core';
14
+ import { Info, MoreVertical } from 'lucide-react';
15
+
16
+ import { AvatarThumbnail } from '@kivacore/ui-pro-shared/components/kiva/avatar-thumbnail';
17
+ import { KivaIcon } from '@kivacore/ui-pro-shared/components/kiva/kiva-icon';
18
+ import {
19
+ getEnumDotClassName,
20
+ getEnumDotStyle,
21
+ getEnumIconColor
22
+ } from '@kivacore/ui-pro-shared/components/kiva/form-fields/lib/utils';
23
+ import { Kanban as KanbanRoot } from '@kivacore/ui-pro-shared/components/kiva/kanban';
24
+ import { Button } from '@kivacore/ui-pro-shared/components/button';
25
+ import {
26
+ DropdownMenu,
27
+ DropdownMenuContent,
28
+ DropdownMenuItem,
29
+ DropdownMenuSeparator,
30
+ DropdownMenuTrigger
31
+ } from '@kivacore/ui-pro-shared/components/dropdown-menu';
32
+ import {
33
+ Tooltip,
34
+ TooltipContent,
35
+ TooltipTrigger
36
+ } from '@kivacore/ui-pro-shared/components/tooltip';
37
+ import { cn } from '@kivacore/ui-pro-shared/lib/utils';
38
+
39
+ /*
40
+ * Generic-friendly alias for `KanbanRoot`. The exported `Kanban` props use a
41
+ * distributive conditional that TypeScript cannot simplify against an
42
+ * unresolved generic, so we re-type the call signature into a shape the
43
+ * compiler can verify directly. Runtime semantics are identical.
44
+ */
45
+ export type KanbanRootGenericProps<T> = {
46
+ value: Record<UniqueIdentifier, Array<T>>;
47
+ onValueChange?: (next: Record<UniqueIdentifier, Array<T>>) => void;
48
+ onFinalDrop?: (item: T, finalColumnId: UniqueIdentifier) => void;
49
+ onDragStart?: (event: { active: { id: UniqueIdentifier } }) => void;
50
+ onDragEnd?: (event: { active: { id: UniqueIdentifier } }) => void;
51
+ onDragCancel?: () => void;
52
+ finalColumns?: Array<UniqueIdentifier>;
53
+ getItemValue: (item: T) => UniqueIdentifier;
54
+ children?: ReactNode;
55
+ };
56
+
57
+ export const KanbanRootGeneric = KanbanRoot as unknown as <T>(
58
+ props: KanbanRootGenericProps<T>
59
+ ) => ReactNode;
60
+
61
+ export function KanbanEmpty({ children }: { children: ReactNode }) {
62
+ return (
63
+ <div className="flex h-[24rem] items-center justify-center rounded-xl border border-dashed bg-muted/20 px-6 text-center text-sm text-muted-foreground">
64
+ <div className="max-w-md text-balance">{children}</div>
65
+ </div>
66
+ );
67
+ }
68
+
69
+ export function KanbanColumnHeader({ column }: { column: KivaKanbanColumnMeta }) {
70
+ return (
71
+ <div className="flex items-center justify-between rounded-t-xl border-b bg-muted/50 px-4 py-3">
72
+ <div className="flex min-w-0 items-center gap-2.5">
73
+ <KanbanColumnAccent
74
+ color={column.color}
75
+ icon={column.icon}
76
+ imageUrl={column.imageUrl} />
77
+ <span className="truncate text-sm font-semibold">{column.label}</span>
78
+ <span className="flex size-5 items-center justify-center rounded-full bg-muted text-xs font-medium">
79
+ {column.count}
80
+ </span>
81
+ </div>
82
+ </div>
83
+ );
84
+ }
85
+
86
+ export function KanbanColumnAccent({
87
+ color,
88
+ icon,
89
+ imageUrl
90
+ }: {
91
+ color?: string | null;
92
+ icon?: string | null;
93
+ imageUrl?: string | null;
94
+ }) {
95
+ if (imageUrl) {
96
+ return <AvatarThumbnail size={5} image={{ signed_url: imageUrl }} shape="circle" />;
97
+ }
98
+
99
+ if (icon) {
100
+ const iconColor = getEnumIconColor(color ?? undefined);
101
+
102
+ return (
103
+ <span
104
+ className={cn('inline-flex size-5 items-center justify-center', iconColor.className)}
105
+ style={iconColor.style}>
106
+ <KivaIcon icon={icon} className="size-4" />
107
+ </span>
108
+ );
109
+ }
110
+
111
+ const dotClass = getEnumDotClassName(color ?? undefined);
112
+ const dotStyle = getEnumDotStyle(color ?? undefined);
113
+
114
+ return (
115
+ <span
116
+ className={cn('inline-block size-2.5 rounded-full', dotClass || 'bg-muted-foreground/60')}
117
+ style={dotStyle} />
118
+ );
119
+ }
120
+
121
+ interface KanbanCardProps<TData> {
122
+ row: TData;
123
+ column: KivaKanbanColumnMeta;
124
+ avatarColumn?: string;
125
+ titleColumn?: string;
126
+ descriptionColumn?: string;
127
+ userColumn?: string;
128
+ cardContent?: (ctx: KivaKanbanCardContext<TData>) => ReactNode;
129
+ menu: Array<KivaKanbanCardMenuItem<TData>>;
130
+ onClick?: (row: TData) => void;
131
+ }
132
+
133
+ export function KanbanCard<TData>({
134
+ row,
135
+ column,
136
+ avatarColumn,
137
+ titleColumn,
138
+ descriptionColumn,
139
+ userColumn,
140
+ cardContent,
141
+ menu,
142
+ onClick
143
+ }: KanbanCardProps<TData>) {
144
+ const record = row as Record<string, unknown>;
145
+
146
+ const avatarValue = avatarColumn ? deriveAvatar(record[avatarColumn]) : null;
147
+ const title = titleColumn ? stringify(record[titleColumn]) : null;
148
+ const description = descriptionColumn ? stringify(record[descriptionColumn]) : null;
149
+ const user = userColumn ? deriveUser(record[userColumn]) : null;
150
+
151
+ const created = stringify(record.created_on);
152
+ const modified = stringify(record.last_modified_on);
153
+ const createdBy = deriveUser(record.created_by);
154
+ const modifiedBy = deriveUser(record.last_modified_by);
155
+
156
+ const hasAudit = Boolean(created ?? modified ?? createdBy ?? modifiedBy);
157
+
158
+ return (
159
+ <div
160
+ className="rounded-lg border border-border/60 bg-card p-3 shadow-xs transition-shadow hover:shadow-sm"
161
+ onClick={onClick ? () => onClick(row) : undefined}>
162
+ <div className="flex items-start gap-2">
163
+ {avatarValue ? (
164
+ <AvatarThumbnail
165
+ size={9}
166
+ icon={avatarValue.icon}
167
+ color={avatarValue.color}
168
+ image={avatarValue.image} />
169
+ ) : null}
170
+ <div className="min-w-0 flex-1">
171
+ {title ? (
172
+ <div className="truncate text-sm font-medium text-foreground">{title}</div>
173
+ ) : null}
174
+ {description ? (
175
+ <div className="line-clamp-2 text-xs text-muted-foreground">{description}</div>
176
+ ) : null}
177
+ </div>
178
+ {menu.length > 0 ? (
179
+ <DropdownMenu>
180
+ <DropdownMenuTrigger asChild>
181
+ <Button
182
+ variant="ghost"
183
+ size="icon-sm"
184
+ className="-mr-1 -mt-1 size-7 shrink-0 text-muted-foreground"
185
+ aria-label="Card actions"
186
+ onClick={event => event.stopPropagation()}
187
+ onPointerDown={event => event.stopPropagation()}>
188
+ <MoreVertical className="size-4" />
189
+ </Button>
190
+ </DropdownMenuTrigger>
191
+ <DropdownMenuContent align="end">
192
+ {menu.map((item, index) => {
193
+ const isDisabled = typeof item.disabled === 'function' ? item.disabled(row) : item.disabled;
194
+ const wantsSeparator = item.destructive && index > 0 && !menu[index - 1]?.destructive;
195
+
196
+ return (
197
+ <div key={item.key} className="contents">
198
+ {wantsSeparator ? <DropdownMenuSeparator /> : null}
199
+ <DropdownMenuItem
200
+ disabled={isDisabled}
201
+ variant={item.destructive ? 'destructive' : 'default'}
202
+ onClick={() => item.onAction?.(row)}>
203
+ {item.icon}
204
+ {item.label}
205
+ </DropdownMenuItem>
206
+ </div>
207
+ );
208
+ })}
209
+ </DropdownMenuContent>
210
+ </DropdownMenu>
211
+ ) : null}
212
+ </div>
213
+
214
+ {cardContent ? (
215
+ <div className="mt-2 text-sm text-foreground">
216
+ {cardContent({ row, column })}
217
+ </div>
218
+ ) : null}
219
+
220
+ <div className="mt-3 flex items-center gap-2">
221
+ {user ? (
222
+ <Tooltip>
223
+ <TooltipTrigger asChild>
224
+ <span>
225
+ <AvatarThumbnail
226
+ size={6}
227
+ shape="circle"
228
+ image={user.imageUrl ? { signed_url: user.imageUrl } : null}
229
+ icon={user.imageUrl ? null : 'huge user-circle-02'} />
230
+ </span>
231
+ </TooltipTrigger>
232
+ <TooltipContent>{user.label}</TooltipContent>
233
+ </Tooltip>
234
+ ) : null}
235
+ <div className="ml-auto" />
236
+ {hasAudit ? (
237
+ <Tooltip>
238
+ <TooltipTrigger asChild>
239
+ <span className="text-muted-foreground">
240
+ <Info className="size-3.5" />
241
+ </span>
242
+ </TooltipTrigger>
243
+ <TooltipContent className="text-xs">
244
+ <div className="space-y-0.5">
245
+ {created ? <div>Created: {created}{createdBy ? ` · ${createdBy.label}` : ''}</div> : null}
246
+ {modified ? <div>Modified: {modified}{modifiedBy ? ` · ${modifiedBy.label}` : ''}</div> : null}
247
+ </div>
248
+ </TooltipContent>
249
+ </Tooltip>
250
+ ) : null}
251
+ </div>
252
+ </div>
253
+ );
254
+ }
255
+
256
+ /* --------------------------- helpers ---------------------------------- */
257
+
258
+ function deriveAvatar(value: unknown): {
259
+ icon?: string | null;
260
+ color?: string | null;
261
+ image?: { signed_url?: string | null; file_name?: string } | null;
262
+ } | null {
263
+ if (!value) return null;
264
+ if (typeof value === 'string') {
265
+ /*
266
+ * Plain icon identifier or color string — strings with whitespace/dashes
267
+ * are treated as icons, hex strings (`#...`) and bare color names as colors.
268
+ */
269
+ const isIcon = value.includes(' ') || (value.includes('-') && !value.startsWith('#'));
270
+
271
+ return isIcon ? { icon: value } : { color: value };
272
+ }
273
+
274
+ if (typeof value === 'object') {
275
+ const obj = value as Record<string, unknown>;
276
+ const icon = typeof obj.icon === 'string' ? obj.icon : null;
277
+ const color = typeof obj.color === 'string' ? obj.color : null;
278
+ const signedUrl = typeof obj.signed_url === 'string' ? obj.signed_url : typeof obj.url === 'string' ? obj.url : null;
279
+
280
+ if (signedUrl) return { image: { signed_url: signedUrl, file_name: typeof obj.file_name === 'string' ? obj.file_name : undefined } };
281
+
282
+ return { icon, color };
283
+ }
284
+
285
+ return null;
286
+ }
287
+
288
+ function deriveUser(value: unknown): { id: string; label: string; imageUrl?: string | null } | null {
289
+ return readUserMeta(value, 'user');
290
+ }
291
+
292
+ function stringify(value: unknown): string | null {
293
+ if (value == null) return null;
294
+ if (typeof value === 'string') {
295
+ const trimmed = value.trim();
296
+
297
+ return trimmed.length > 0 ? trimmed : null;
298
+ }
299
+
300
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value);
301
+ if (value instanceof Date) return value.toLocaleString();
302
+
303
+ if (typeof value === 'object') {
304
+ const obj = value as Record<string, unknown>;
305
+ const candidate = obj.name ?? obj.label ?? obj.title ?? obj.value ?? obj.description;
306
+
307
+ if (typeof candidate === 'string') return candidate;
308
+ }
309
+
310
+ return null;
311
+ }