@middag-io/react 0.45.0 → 0.45.3

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 (321) hide show
  1. package/README.md +4 -3
  2. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  3. package/docs/public/schemas/blocks.json +445 -0
  4. package/docs/public/schemas/components.json +166 -0
  5. package/docs/public/schemas/connectors.json +97 -0
  6. package/docs/public/schemas/fragment.json +2329 -0
  7. package/docs/public/schemas/manifest.json +119 -0
  8. package/docs/public/schemas/navigation.json +72 -0
  9. package/docs/public/schemas/page-contract.json +2329 -0
  10. package/docs/public/schemas/shared-props.json +118 -0
  11. package/docs/public/schemas/theme-defaults.json +253 -0
  12. package/docs/public/schemas/theme.json +401 -0
  13. package/package.json +109 -3
  14. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  15. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  16. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  17. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  18. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  19. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  20. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  21. package/src/assets/lottie/connection/network-1.json +1 -0
  22. package/src/assets/lottie/connection/network-2.json +1 -0
  23. package/src/assets/lottie/connection/network-3.json +1 -0
  24. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  25. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  26. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  27. package/src/assets/lottie/email/mail-1.json +1 -0
  28. package/src/assets/lottie/email/mail-2.json +1 -0
  29. package/src/assets/lottie/email/mail-3.json +1 -0
  30. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  31. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  32. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  33. package/src/assets/lottie/error/warning-1.json +1 -0
  34. package/src/assets/lottie/error/warning-2.json +1 -0
  35. package/src/assets/lottie/error/warning-3.json +1 -0
  36. package/src/assets/lottie/index.ts +49 -0
  37. package/src/assets/lottie/loading/spinner-1.json +1 -0
  38. package/src/assets/lottie/loading/spinner-2.json +1 -0
  39. package/src/assets/lottie/loading/spinner-3.json +1 -0
  40. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  41. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  42. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  43. package/src/assets/lottie/not-found/404-1.json +1 -0
  44. package/src/assets/lottie/not-found/404-2.json +1 -0
  45. package/src/assets/lottie/not-found/404-3.json +1 -0
  46. package/src/assets/lottie/notification/bell-1.json +1 -0
  47. package/src/assets/lottie/notification/bell-2.json +1 -0
  48. package/src/assets/lottie/notification/bell-3.json +1 -0
  49. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  50. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  51. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  52. package/src/assets/lottie/payment/wallet-1.json +1 -0
  53. package/src/assets/lottie/payment/wallet-2.json +1 -0
  54. package/src/assets/lottie/payment/wallet-3.json +1 -0
  55. package/src/assets/lottie/search/search-1.json +1 -0
  56. package/src/assets/lottie/search/search-2.json +1 -0
  57. package/src/assets/lottie/search/search-3.json +1 -0
  58. package/src/assets/lottie/security/lock-1.json +1 -0
  59. package/src/assets/lottie/security/lock-2.json +1 -0
  60. package/src/assets/lottie/security/lock-3.json +1 -0
  61. package/src/assets/lottie/settings/gear-1.json +1 -0
  62. package/src/assets/lottie/settings/gear-2.json +1 -0
  63. package/src/assets/lottie/settings/gear-3.json +1 -0
  64. package/src/assets/lottie/success/check-1.json +1 -0
  65. package/src/assets/lottie/success/check-2.json +1 -0
  66. package/src/assets/lottie/success/check-3.json +1 -0
  67. package/src/assets/lottie/upload/upload-1.json +1 -0
  68. package/src/assets/lottie/upload/upload-2.json +1 -0
  69. package/src/assets/lottie/upload/upload-3.json +1 -0
  70. package/src/assets/lottie/user/profile-1.json +1 -0
  71. package/src/assets/lottie/user/profile-2.json +1 -0
  72. package/src/assets/lottie/user/profile-3.json +1 -0
  73. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  74. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  75. package/src/base/blocks/CardGridBlock.tsx +384 -0
  76. package/src/base/blocks/ChartBlock.tsx +81 -0
  77. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  78. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  79. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  80. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  81. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  82. package/src/base/blocks/LinkListBlock.tsx +94 -0
  83. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  84. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  85. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  86. package/src/base/blocks/TabsBlock.tsx +94 -0
  87. package/src/base/form/FormField.tsx +607 -0
  88. package/src/base/form/fields/CheckboxField.tsx +56 -0
  89. package/src/base/form/fields/ColorField.tsx +76 -0
  90. package/src/base/form/fields/CurrencyField.tsx +126 -0
  91. package/src/base/form/fields/DateField.tsx +168 -0
  92. package/src/base/form/fields/DateRangeField.tsx +66 -0
  93. package/src/base/form/fields/DocumentField.tsx +222 -0
  94. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  95. package/src/base/form/fields/FileUploadField.tsx +253 -0
  96. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  97. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  98. package/src/base/form/fields/NumberField.tsx +67 -0
  99. package/src/base/form/fields/OtpField.tsx +88 -0
  100. package/src/base/form/fields/PasswordField.tsx +69 -0
  101. package/src/base/form/fields/PhoneField.tsx +64 -0
  102. package/src/base/form/fields/RadioField.tsx +66 -0
  103. package/src/base/form/fields/RatingField.tsx +52 -0
  104. package/src/base/form/fields/SelectField.tsx +76 -0
  105. package/src/base/form/fields/SliderField.tsx +77 -0
  106. package/src/base/form/fields/SlugField.tsx +114 -0
  107. package/src/base/form/fields/StaticField.tsx +25 -0
  108. package/src/base/form/fields/SwitchField.tsx +56 -0
  109. package/src/base/form/fields/TagsField.tsx +128 -0
  110. package/src/base/form/fields/TextField.tsx +55 -0
  111. package/src/base/form/fields/TextareaField.tsx +55 -0
  112. package/src/base/form/fields/document-validation.ts +126 -0
  113. package/src/base/form/fields/field-registry.ts +53 -0
  114. package/src/base/form/fields/register-default-fields.ts +86 -0
  115. package/src/base/form/form-schema-builder.ts +192 -0
  116. package/src/base/form/form-utils.ts +71 -0
  117. package/src/base/hooks/useIsDark.ts +50 -0
  118. package/src/base/hooks/useLazyTabs.ts +98 -0
  119. package/src/base/hooks/usePolling.ts +43 -0
  120. package/src/base/hooks/useRemember.ts +58 -0
  121. package/src/base/hooks/useToast.ts +27 -0
  122. package/src/base/layout/BlockRegion.tsx +39 -0
  123. package/src/base/layout/DashboardLayout.tsx +110 -0
  124. package/src/base/layout/SidebarLayout.tsx +38 -0
  125. package/src/base/layout/StackLayout.tsx +32 -0
  126. package/src/base/layout/WizardLayout.tsx +49 -0
  127. package/src/base/partials/ActionBar/index.tsx +115 -0
  128. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  129. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  130. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  131. package/src/base/partials/DataTable/index.tsx +1282 -0
  132. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  133. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  134. package/src/base/partials/DataTable/types.ts +229 -0
  135. package/src/base/partials/DetailSection/index.tsx +316 -0
  136. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  137. package/src/base/partials/EntityItem/index.tsx +154 -0
  138. package/src/base/partials/FilterBar/index.tsx +256 -0
  139. package/src/base/partials/FormSection/index.tsx +87 -0
  140. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  141. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  142. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  143. package/src/base/partials/LogViewer/index.tsx +110 -0
  144. package/src/base/partials/LogViewer/types.ts +28 -0
  145. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  146. package/src/base/partials/MenuBar/index.tsx +80 -0
  147. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  148. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  149. package/src/base/partials/StatRow/index.tsx +28 -0
  150. package/src/base/partials/StatusBar/index.tsx +126 -0
  151. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  152. package/src/base/partials/StepIndicator/index.tsx +63 -0
  153. package/src/base/partials/TableOfContents/index.tsx +78 -0
  154. package/src/base/partials/TimelineList/index.tsx +273 -0
  155. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  156. package/src/base/partials/TreeView/index.tsx +75 -0
  157. package/src/base/partials/index.ts +23 -0
  158. package/src/base/shell/AuthShell.tsx +54 -0
  159. package/src/base/shell/BasicShell.tsx +286 -0
  160. package/src/base/shell/ImmersiveShell.tsx +85 -0
  161. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  162. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  163. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  164. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  165. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  166. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  167. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  168. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  169. package/src/base/theme/appearance.ts +133 -0
  170. package/src/base/theme/host-layout-detector.ts +119 -0
  171. package/src/base/theme/host-theme-detector.ts +146 -0
  172. package/src/base/theme/sidebar-safelist.txt +20 -0
  173. package/src/base/theme/tailwind-theme.css +136 -0
  174. package/src/base/theme/theme-bridge.css +164 -0
  175. package/src/base/theme/theme-context.tsx +142 -0
  176. package/src/base/theme/themes/classic.css +174 -0
  177. package/src/base/theme/tokens.css +290 -0
  178. package/src/base/theme/useHostTheme.ts +95 -0
  179. package/src/base/utils/clipboard.ts +39 -0
  180. package/src/base/utils/conditions.ts +27 -0
  181. package/src/base/utils/icon-registry.ts +78 -0
  182. package/src/base/utils/icons.ts +31 -0
  183. package/src/base/utils/interpolate.ts +9 -0
  184. package/src/base/utils/register-default-icons.ts +163 -0
  185. package/src/base/utils/storage.ts +65 -0
  186. package/src/base/utils/time.ts +139 -0
  187. package/src/contracts/block-data/actions.ts +73 -0
  188. package/src/contracts/block-data/data-display.ts +343 -0
  189. package/src/contracts/block-data/form.ts +164 -0
  190. package/src/contracts/block-data/index.ts +15 -0
  191. package/src/contracts/block-data/interactive.ts +34 -0
  192. package/src/contracts/block-data/shared.ts +44 -0
  193. package/src/contracts/connectors.ts +60 -0
  194. package/src/contracts/generated/contract-schema.ts +1237 -0
  195. package/src/contracts/generated/contract-types.ts +675 -0
  196. package/src/contracts/generated/index.ts +15 -0
  197. package/src/contracts/navigation.ts +59 -0
  198. package/src/contracts/page-contract-schema.ts +40 -0
  199. package/src/contracts/page-contract.ts +79 -0
  200. package/src/contracts/shared-props.ts +92 -0
  201. package/src/engine/ContractPage.tsx +178 -0
  202. package/src/engine/EntityRoutes.tsx +72 -0
  203. package/src/engine/HostSlot.tsx +126 -0
  204. package/src/engine/LazyBlock.tsx +92 -0
  205. package/src/engine/bootstrap.tsx +20 -0
  206. package/src/engine/providers/auth.tsx +87 -0
  207. package/src/engine/providers/error-reporter.tsx +89 -0
  208. package/src/engine/providers/flash.tsx +44 -0
  209. package/src/engine/providers/index.ts +18 -0
  210. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  211. package/src/engine/providers/progress.tsx +56 -0
  212. package/src/engine/providers/scope.tsx +51 -0
  213. package/src/engine/register-defaults.ts +88 -0
  214. package/src/engine/registries.ts +96 -0
  215. package/src/i18n/I18nProvider.tsx +53 -0
  216. package/src/i18n/MANIFEST.md +101 -0
  217. package/src/i18n/host-resolver.ts +18 -0
  218. package/src/i18n/instance.ts +69 -0
  219. package/src/i18n/locales/en/ui.json +277 -0
  220. package/src/i18n/locales/en/validators.json +13 -0
  221. package/src/i18n/locales/pt-BR/ui.json +277 -0
  222. package/src/i18n/locales/pt-BR/validators.json +13 -0
  223. package/src/i18n/register-strings.ts +10 -0
  224. package/src/i18n/render-label.ts +33 -0
  225. package/src/i18n/resolve-field-error.ts +29 -0
  226. package/src/i18n/useHostString.ts +50 -0
  227. package/src/i18n/useTranslation.ts +83 -0
  228. package/src/lib/actions/resolve-action-target.ts +151 -0
  229. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  230. package/src/lib/hooks/use-file-upload.ts +406 -0
  231. package/src/lib/hooks/use-mobile.ts +21 -0
  232. package/src/lib/host-pending.ts +76 -0
  233. package/src/lib/portal-container.ts +16 -0
  234. package/src/lib/test-ids.ts +40 -0
  235. package/src/lib/utils.ts +6 -0
  236. package/src/primitives/reui/MANIFEST.md +97 -0
  237. package/src/primitives/reui/accordion.tsx +64 -0
  238. package/src/primitives/reui/alert-dialog.tsx +196 -0
  239. package/src/primitives/reui/alert.tsx +92 -0
  240. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  241. package/src/primitives/reui/autocomplete.tsx +343 -0
  242. package/src/primitives/reui/avatar.tsx +109 -0
  243. package/src/primitives/reui/badge.tsx +94 -0
  244. package/src/primitives/reui/breadcrumb.tsx +109 -0
  245. package/src/primitives/reui/button-group.tsx +83 -0
  246. package/src/primitives/reui/button.tsx +64 -0
  247. package/src/primitives/reui/calendar.tsx +220 -0
  248. package/src/primitives/reui/card.tsx +92 -0
  249. package/src/primitives/reui/carousel.tsx +239 -0
  250. package/src/primitives/reui/chart.tsx +388 -0
  251. package/src/primitives/reui/checkbox.tsx +30 -0
  252. package/src/primitives/reui/collapsible.tsx +31 -0
  253. package/src/primitives/reui/combobox.tsx +308 -0
  254. package/src/primitives/reui/command.tsx +182 -0
  255. package/src/primitives/reui/context-menu.tsx +250 -0
  256. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  257. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  258. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  259. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  260. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  261. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  262. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  263. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  264. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  265. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  266. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  267. package/src/primitives/reui/date-selector.tsx +1353 -0
  268. package/src/primitives/reui/dialog.tsx +158 -0
  269. package/src/primitives/reui/drawer.tsx +133 -0
  270. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  271. package/src/primitives/reui/empty.tsx +104 -0
  272. package/src/primitives/reui/field.tsx +246 -0
  273. package/src/primitives/reui/filters.tsx +1891 -0
  274. package/src/primitives/reui/frame.tsx +170 -0
  275. package/src/primitives/reui/hover-card.tsx +42 -0
  276. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  277. package/src/primitives/reui/index.ts +98 -0
  278. package/src/primitives/reui/input-group.tsx +170 -0
  279. package/src/primitives/reui/input-otp.tsx +75 -0
  280. package/src/primitives/reui/input.tsx +21 -0
  281. package/src/primitives/reui/item.tsx +193 -0
  282. package/src/primitives/reui/kanban.tsx +743 -0
  283. package/src/primitives/reui/kbd.tsx +28 -0
  284. package/src/primitives/reui/label.tsx +22 -0
  285. package/src/primitives/reui/menubar.tsx +274 -0
  286. package/src/primitives/reui/native-select.tsx +62 -0
  287. package/src/primitives/reui/navigation-menu.tsx +168 -0
  288. package/src/primitives/reui/number-field.tsx +250 -0
  289. package/src/primitives/reui/pagination.tsx +127 -0
  290. package/src/primitives/reui/phone-input.tsx +231 -0
  291. package/src/primitives/reui/popover.tsx +87 -0
  292. package/src/primitives/reui/progress.tsx +31 -0
  293. package/src/primitives/reui/radio-group.tsx +43 -0
  294. package/src/primitives/reui/rating.tsx +177 -0
  295. package/src/primitives/reui/resizable.tsx +51 -0
  296. package/src/primitives/reui/scroll-area.tsx +58 -0
  297. package/src/primitives/reui/scrollspy.tsx +240 -0
  298. package/src/primitives/reui/select.tsx +188 -0
  299. package/src/primitives/reui/separator.tsx +28 -0
  300. package/src/primitives/reui/sheet.tsx +141 -0
  301. package/src/primitives/reui/sidebar.tsx +732 -0
  302. package/src/primitives/reui/skeleton.tsx +13 -0
  303. package/src/primitives/reui/slider.tsx +61 -0
  304. package/src/primitives/reui/sonner.tsx +47 -0
  305. package/src/primitives/reui/sortable.tsx +414 -0
  306. package/src/primitives/reui/spinner.tsx +16 -0
  307. package/src/primitives/reui/stepper.tsx +484 -0
  308. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  309. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  310. package/src/primitives/reui/svgs/openai.tsx +9 -0
  311. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  312. package/src/primitives/reui/switch.tsx +33 -0
  313. package/src/primitives/reui/table.tsx +114 -0
  314. package/src/primitives/reui/tabs.tsx +91 -0
  315. package/src/primitives/reui/textarea.tsx +18 -0
  316. package/src/primitives/reui/timeline.tsx +219 -0
  317. package/src/primitives/reui/toggle-group.tsx +83 -0
  318. package/src/primitives/reui/toggle.tsx +45 -0
  319. package/src/primitives/reui/tooltip.tsx +55 -0
  320. package/src/primitives/reui/tree.tsx +247 -0
  321. package/src/theme.css +71 -0
@@ -0,0 +1,743 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ createContext,
6
+ CSSProperties,
7
+ HTMLAttributes,
8
+ ReactNode,
9
+ useCallback,
10
+ useContext,
11
+ useLayoutEffect,
12
+ useMemo,
13
+ useState,
14
+ } from "react";
15
+ import {
16
+ defaultDropAnimationSideEffects,
17
+ DndContext,
18
+ DragEndEvent,
19
+ DragOverEvent,
20
+ DragOverlay,
21
+ DragStartEvent,
22
+ DropAnimation,
23
+ KeyboardSensor,
24
+ MeasuringStrategy,
25
+ Modifiers,
26
+ MouseSensor,
27
+ TouchSensor,
28
+ UniqueIdentifier,
29
+ useSensor,
30
+ useSensors,
31
+ type DraggableAttributes,
32
+ type DraggableSyntheticListeners,
33
+ } from "@dnd-kit/core";
34
+ import {
35
+ arrayMove,
36
+ defaultAnimateLayoutChanges,
37
+ rectSortingStrategy,
38
+ SortableContext,
39
+ sortableKeyboardCoordinates,
40
+ useSortable,
41
+ verticalListSortingStrategy,
42
+ type AnimateLayoutChanges,
43
+ } from "@dnd-kit/sortable";
44
+ import { CSS } from "@dnd-kit/utilities";
45
+ import { Slot } from "radix-ui";
46
+ import { createPortal } from "react-dom";
47
+
48
+ import { cn } from "@/lib/utils";
49
+
50
+ interface KanbanContextProps<T> {
51
+ columns: Record<string, T[]>;
52
+ setColumns: (columns: Record<string, T[]>) => void;
53
+ getItemId: (item: T) => string;
54
+ columnIds: string[];
55
+ activeId: UniqueIdentifier | null;
56
+ setActiveId: (id: UniqueIdentifier | null) => void;
57
+ findContainer: (id: UniqueIdentifier) => string | undefined;
58
+ isColumn: (id: UniqueIdentifier) => boolean;
59
+ modifiers?: Modifiers;
60
+ }
61
+
62
+ const KanbanContext = createContext<KanbanContextProps<any>>({
63
+ columns: {},
64
+ setColumns: () => {},
65
+ getItemId: () => "",
66
+ columnIds: [],
67
+ activeId: null,
68
+ setActiveId: () => {},
69
+ findContainer: () => undefined,
70
+ isColumn: () => false,
71
+ modifiers: undefined,
72
+ });
73
+
74
+ const ColumnContext = createContext<{
75
+ attributes: DraggableAttributes;
76
+ listeners: DraggableSyntheticListeners | undefined;
77
+ isDragging?: boolean;
78
+ disabled?: boolean;
79
+ }>({
80
+ attributes: {} as DraggableAttributes,
81
+ listeners: undefined,
82
+ isDragging: false,
83
+ disabled: false,
84
+ });
85
+
86
+ const ItemContext = createContext<{
87
+ listeners: DraggableSyntheticListeners | undefined;
88
+ isDragging?: boolean;
89
+ disabled?: boolean;
90
+ }>({
91
+ listeners: undefined,
92
+ isDragging: false,
93
+ disabled: false,
94
+ });
95
+
96
+ const IsOverlayContext = createContext(false);
97
+
98
+ const animateLayoutChanges: AnimateLayoutChanges = (args) =>
99
+ defaultAnimateLayoutChanges({ ...args, wasDragging: true });
100
+
101
+ const dropAnimationConfig: DropAnimation = {
102
+ sideEffects: defaultDropAnimationSideEffects({
103
+ styles: {
104
+ active: {
105
+ opacity: "0.4",
106
+ },
107
+ },
108
+ }),
109
+ };
110
+
111
+ export interface KanbanMoveEvent {
112
+ event: DragEndEvent;
113
+ activeContainer: string;
114
+ activeIndex: number;
115
+ overContainer: string;
116
+ overIndex: number;
117
+ }
118
+
119
+ export interface KanbanRootProps<T> extends HTMLAttributes<HTMLDivElement> {
120
+ value: Record<string, T[]>;
121
+ onValueChange: (value: Record<string, T[]>) => void;
122
+ getItemValue: (item: T) => string;
123
+ children: ReactNode;
124
+ onMove?: (event: KanbanMoveEvent) => void;
125
+ asChild?: boolean;
126
+ modifiers?: Modifiers;
127
+ }
128
+
129
+ function Kanban<T>({
130
+ value,
131
+ onValueChange,
132
+ getItemValue,
133
+ children,
134
+ className,
135
+ asChild = false,
136
+ onMove,
137
+ modifiers,
138
+ ...props
139
+ }: KanbanRootProps<T>) {
140
+ const columns = value;
141
+ const setColumns = onValueChange;
142
+ const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
143
+
144
+ const sensors = useSensors(
145
+ useSensor(MouseSensor, {
146
+ activationConstraint: {
147
+ distance: 10,
148
+ },
149
+ }),
150
+ useSensor(TouchSensor, {
151
+ activationConstraint: {
152
+ delay: 250,
153
+ tolerance: 5,
154
+ },
155
+ }),
156
+ useSensor(KeyboardSensor, {
157
+ coordinateGetter: sortableKeyboardCoordinates,
158
+ }),
159
+ );
160
+
161
+ const columnIds = useMemo(() => Object.keys(columns), [columns]);
162
+
163
+ const isColumn = useCallback(
164
+ (id: UniqueIdentifier) => columnIds.includes(id as string),
165
+ [columnIds],
166
+ );
167
+
168
+ const findContainer = useCallback(
169
+ (id: UniqueIdentifier) => {
170
+ if (isColumn(id)) return id as string;
171
+ return columnIds.find((key) =>
172
+ columns[key].some((item) => getItemValue(item) === id),
173
+ );
174
+ },
175
+ [columns, columnIds, getItemValue, isColumn],
176
+ );
177
+
178
+ const handleDragStart = useCallback((event: DragStartEvent) => {
179
+ setActiveId(event.active.id);
180
+ }, []);
181
+
182
+ const handleDragOver = useCallback(
183
+ (event: DragOverEvent) => {
184
+ if (onMove) {
185
+ return;
186
+ }
187
+
188
+ const { active, over } = event;
189
+ if (!over) return;
190
+
191
+ if (isColumn(active.id)) return;
192
+
193
+ const activeContainer = findContainer(active.id);
194
+ const overContainer = findContainer(over.id);
195
+
196
+ if (!activeContainer || !overContainer) {
197
+ return;
198
+ }
199
+
200
+ if (activeContainer !== overContainer) {
201
+ const activeItems = columns[activeContainer];
202
+ const overItems = columns[overContainer];
203
+
204
+ const activeIndex = activeItems.findIndex(
205
+ (item: T) => getItemValue(item) === active.id,
206
+ );
207
+ let overIndex = overItems.findIndex(
208
+ (item: T) => getItemValue(item) === over.id,
209
+ );
210
+
211
+ // If dropping on the column itself, not an item
212
+ if (isColumn(over.id)) {
213
+ overIndex = overItems.length;
214
+ }
215
+
216
+ const newActiveItems = [...activeItems];
217
+ const newOverItems = [...overItems];
218
+ const [movedItem] = newActiveItems.splice(activeIndex, 1);
219
+ newOverItems.splice(overIndex, 0, movedItem);
220
+
221
+ setColumns({
222
+ ...columns,
223
+ [activeContainer]: newActiveItems,
224
+ [overContainer]: newOverItems,
225
+ });
226
+ } else {
227
+ const container = activeContainer;
228
+ const activeIndex = columns[container].findIndex(
229
+ (item: T) => getItemValue(item) === active.id,
230
+ );
231
+ const overIndex = columns[container].findIndex(
232
+ (item: T) => getItemValue(item) === over.id,
233
+ );
234
+
235
+ if (activeIndex !== overIndex) {
236
+ setColumns({
237
+ ...columns,
238
+ [container]: arrayMove(columns[container], activeIndex, overIndex),
239
+ });
240
+ }
241
+ }
242
+ },
243
+ [findContainer, getItemValue, isColumn, setColumns, columns, onMove],
244
+ );
245
+
246
+ const handleDragCancel = useCallback(() => {
247
+ setActiveId(null);
248
+ }, []);
249
+
250
+ const handleDragEnd = useCallback(
251
+ (event: DragEndEvent) => {
252
+ const { active, over } = event;
253
+ setActiveId(null);
254
+
255
+ if (!over) return;
256
+
257
+ // Handle item move callback
258
+ if (onMove && !isColumn(active.id)) {
259
+ const activeContainer = findContainer(active.id);
260
+ const overContainer = findContainer(over.id);
261
+
262
+ if (activeContainer && overContainer) {
263
+ const activeIndex = columns[activeContainer].findIndex(
264
+ (item: T) => getItemValue(item) === active.id,
265
+ );
266
+ const overIndex = isColumn(over.id)
267
+ ? columns[overContainer].length
268
+ : columns[overContainer].findIndex(
269
+ (item: T) => getItemValue(item) === over.id,
270
+ );
271
+
272
+ onMove({
273
+ event,
274
+ activeContainer,
275
+ activeIndex,
276
+ overContainer,
277
+ overIndex,
278
+ });
279
+ }
280
+ return;
281
+ }
282
+
283
+ // Handle column reordering
284
+ if (isColumn(active.id) && isColumn(over.id)) {
285
+ const activeIndex = columnIds.indexOf(active.id as string);
286
+ const overIndex = columnIds.indexOf(over.id as string);
287
+ if (activeIndex !== overIndex) {
288
+ const newOrder = arrayMove(
289
+ Object.keys(columns),
290
+ activeIndex,
291
+ overIndex,
292
+ );
293
+ const newColumns: Record<string, T[]> = {};
294
+ newOrder.forEach((key) => {
295
+ newColumns[key] = columns[key];
296
+ });
297
+ setColumns(newColumns);
298
+ }
299
+ return;
300
+ }
301
+
302
+ const activeContainer = findContainer(active.id);
303
+ const overContainer = findContainer(over.id);
304
+
305
+ // Handle item reordering within the same column
306
+ if (
307
+ activeContainer &&
308
+ overContainer &&
309
+ activeContainer === overContainer
310
+ ) {
311
+ const container = activeContainer;
312
+ const activeIndex = columns[container].findIndex(
313
+ (item: T) => getItemValue(item) === active.id,
314
+ );
315
+ const overIndex = columns[container].findIndex(
316
+ (item: T) => getItemValue(item) === over.id,
317
+ );
318
+
319
+ if (activeIndex !== overIndex) {
320
+ setColumns({
321
+ ...columns,
322
+ [container]: arrayMove(columns[container], activeIndex, overIndex),
323
+ });
324
+ }
325
+ }
326
+ },
327
+ [
328
+ columnIds,
329
+ columns,
330
+ findContainer,
331
+ getItemValue,
332
+ isColumn,
333
+ setColumns,
334
+ onMove,
335
+ ],
336
+ );
337
+
338
+ const contextValue = useMemo(
339
+ () => ({
340
+ columns,
341
+ setColumns,
342
+ getItemId: getItemValue,
343
+ columnIds,
344
+ activeId,
345
+ setActiveId,
346
+ findContainer,
347
+ isColumn,
348
+ modifiers,
349
+ }),
350
+ [
351
+ columns,
352
+ setColumns,
353
+ getItemValue,
354
+ columnIds,
355
+ activeId,
356
+ findContainer,
357
+ isColumn,
358
+ modifiers,
359
+ ],
360
+ );
361
+
362
+ const Comp = asChild ? Slot.Root : "div";
363
+
364
+ return (
365
+ <KanbanContext.Provider value={contextValue}>
366
+ <DndContext
367
+ sensors={sensors}
368
+ modifiers={modifiers}
369
+ measuring={{
370
+ droppable: {
371
+ strategy: MeasuringStrategy.Always,
372
+ },
373
+ }}
374
+ onDragStart={handleDragStart}
375
+ onDragOver={handleDragOver}
376
+ onDragEnd={handleDragEnd}
377
+ onDragCancel={handleDragCancel}
378
+ >
379
+ <Comp
380
+ data-slot="kanban"
381
+ data-dragging={activeId !== null}
382
+ className={cn(activeId !== null && "cursor-grabbing!", className)}
383
+ {...props}
384
+ >
385
+ {children}
386
+ </Comp>
387
+ </DndContext>
388
+ </KanbanContext.Provider>
389
+ );
390
+ }
391
+
392
+ export interface KanbanBoardProps extends HTMLAttributes<HTMLDivElement> {
393
+ asChild?: boolean;
394
+ }
395
+
396
+ function KanbanBoard({
397
+ className,
398
+ asChild = false,
399
+ children,
400
+ ...props
401
+ }: KanbanBoardProps) {
402
+ const { columnIds } = useContext(KanbanContext);
403
+ const Comp = asChild ? Slot.Root : "div";
404
+
405
+ return (
406
+ <SortableContext items={columnIds} strategy={rectSortingStrategy}>
407
+ <Comp
408
+ data-slot="kanban-board"
409
+ className={cn("grid auto-rows-fr gap-4 sm:grid-cols-3", className)}
410
+ {...props}
411
+ >
412
+ {children}
413
+ </Comp>
414
+ </SortableContext>
415
+ );
416
+ }
417
+
418
+ export interface KanbanColumnProps extends HTMLAttributes<HTMLDivElement> {
419
+ value: string;
420
+ disabled?: boolean;
421
+ asChild?: boolean;
422
+ }
423
+
424
+ function KanbanColumn({
425
+ value,
426
+ className,
427
+ asChild = false,
428
+ disabled,
429
+ children,
430
+ ...props
431
+ }: KanbanColumnProps) {
432
+ const isOverlay = useContext(IsOverlayContext);
433
+
434
+ const {
435
+ setNodeRef,
436
+ transform,
437
+ transition,
438
+ attributes,
439
+ listeners,
440
+ isDragging: isSortableDragging,
441
+ } = useSortable({
442
+ id: value,
443
+ disabled: disabled || isOverlay,
444
+ animateLayoutChanges,
445
+ });
446
+
447
+ const { activeId, isColumn } = useContext(KanbanContext);
448
+ const isColumnDragging = activeId ? isColumn(activeId) : false;
449
+
450
+ const style = {
451
+ transition,
452
+ transform: CSS.Transform.toString(transform),
453
+ } as CSSProperties;
454
+
455
+ const Comp = asChild ? Slot.Root : "div";
456
+
457
+ if (isOverlay) {
458
+ return (
459
+ <ColumnContext.Provider
460
+ value={{
461
+ attributes: {} as DraggableAttributes,
462
+ listeners: undefined,
463
+ isDragging: true,
464
+ disabled: false,
465
+ }}
466
+ >
467
+ <Comp
468
+ data-slot="kanban-column"
469
+ data-value={value}
470
+ data-dragging={true}
471
+ className={cn("group/kanban-column flex flex-col", className)}
472
+ {...props}
473
+ >
474
+ {children}
475
+ </Comp>
476
+ </ColumnContext.Provider>
477
+ );
478
+ }
479
+
480
+ return (
481
+ <ColumnContext.Provider
482
+ value={{ attributes, listeners, isDragging: isColumnDragging, disabled }}
483
+ >
484
+ <Comp
485
+ data-slot="kanban-column"
486
+ data-value={value}
487
+ data-dragging={isSortableDragging}
488
+ data-disabled={disabled}
489
+ ref={setNodeRef}
490
+ style={style}
491
+ className={cn(
492
+ "group/kanban-column flex flex-col",
493
+ isSortableDragging && "z-50 opacity-50",
494
+ disabled && "opacity-50",
495
+ className,
496
+ )}
497
+ {...props}
498
+ >
499
+ {children}
500
+ </Comp>
501
+ </ColumnContext.Provider>
502
+ );
503
+ }
504
+
505
+ export interface KanbanColumnHandleProps extends HTMLAttributes<HTMLDivElement> {
506
+ cursor?: boolean;
507
+ asChild?: boolean;
508
+ }
509
+
510
+ function KanbanColumnHandle({
511
+ className,
512
+ asChild = false,
513
+ cursor = true,
514
+ children,
515
+ ...props
516
+ }: KanbanColumnHandleProps) {
517
+ const { attributes, listeners, isDragging, disabled } =
518
+ useContext(ColumnContext);
519
+
520
+ const Comp = asChild ? Slot.Root : "div";
521
+
522
+ return (
523
+ <Comp
524
+ data-slot="kanban-column-handle"
525
+ data-dragging={isDragging}
526
+ data-disabled={disabled}
527
+ {...attributes}
528
+ {...listeners}
529
+ className={cn(
530
+ "opacity-0 transition-opacity group-hover/kanban-column:opacity-100",
531
+ cursor && (isDragging ? "cursor-grabbing!" : "cursor-grab!"),
532
+ className,
533
+ )}
534
+ {...props}
535
+ >
536
+ {children}
537
+ </Comp>
538
+ );
539
+ }
540
+
541
+ export interface KanbanItemProps extends HTMLAttributes<HTMLDivElement> {
542
+ value: string;
543
+ disabled?: boolean;
544
+ asChild?: boolean;
545
+ }
546
+
547
+ function KanbanItem({
548
+ value,
549
+ className,
550
+ asChild = false,
551
+ disabled,
552
+ children,
553
+ ...props
554
+ }: KanbanItemProps) {
555
+ const isOverlay = useContext(IsOverlayContext);
556
+
557
+ const {
558
+ setNodeRef,
559
+ transform,
560
+ transition,
561
+ attributes,
562
+ listeners,
563
+ isDragging: isSortableDragging,
564
+ } = useSortable({
565
+ id: value,
566
+ disabled: disabled || isOverlay,
567
+ animateLayoutChanges,
568
+ });
569
+
570
+ const { activeId, isColumn } = useContext(KanbanContext);
571
+ const isItemDragging = activeId ? !isColumn(activeId) : false;
572
+
573
+ const style = {
574
+ transition,
575
+ transform: CSS.Transform.toString(transform),
576
+ } as CSSProperties;
577
+
578
+ const Comp = asChild ? Slot.Root : "div";
579
+
580
+ if (isOverlay) {
581
+ return (
582
+ <ItemContext.Provider
583
+ value={{ listeners: undefined, isDragging: true, disabled: false }}
584
+ >
585
+ <Comp
586
+ data-slot="kanban-item"
587
+ data-value={value}
588
+ data-dragging={true}
589
+ className={cn(className)}
590
+ {...props}
591
+ >
592
+ {children}
593
+ </Comp>
594
+ </ItemContext.Provider>
595
+ );
596
+ }
597
+
598
+ return (
599
+ <ItemContext.Provider
600
+ value={{ listeners, isDragging: isItemDragging, disabled }}
601
+ >
602
+ <Comp
603
+ data-slot="kanban-item"
604
+ data-value={value}
605
+ data-dragging={isSortableDragging}
606
+ data-disabled={disabled}
607
+ ref={setNodeRef}
608
+ style={style}
609
+ {...attributes}
610
+ className={cn(
611
+ isSortableDragging && "z-50 opacity-50",
612
+ disabled && "opacity-50",
613
+ className,
614
+ )}
615
+ {...props}
616
+ >
617
+ {children}
618
+ </Comp>
619
+ </ItemContext.Provider>
620
+ );
621
+ }
622
+
623
+ export interface KanbanItemHandleProps extends HTMLAttributes<HTMLDivElement> {
624
+ cursor?: boolean;
625
+ asChild?: boolean;
626
+ }
627
+
628
+ function KanbanItemHandle({
629
+ className,
630
+ asChild = false,
631
+ cursor = true,
632
+ children,
633
+ ...props
634
+ }: KanbanItemHandleProps) {
635
+ const { listeners, isDragging, disabled } = useContext(ItemContext);
636
+
637
+ const Comp = asChild ? Slot.Root : "div";
638
+
639
+ return (
640
+ <Comp
641
+ data-slot="kanban-item-handle"
642
+ data-dragging={isDragging}
643
+ data-disabled={disabled}
644
+ {...listeners}
645
+ className={cn(
646
+ cursor && (isDragging ? "cursor-grabbing!" : "cursor-grab!"),
647
+ className,
648
+ )}
649
+ {...props}
650
+ >
651
+ {children}
652
+ </Comp>
653
+ );
654
+ }
655
+
656
+ export interface KanbanColumnContentProps extends HTMLAttributes<HTMLDivElement> {
657
+ value: string;
658
+ asChild?: boolean;
659
+ }
660
+
661
+ function KanbanColumnContent({
662
+ value,
663
+ className,
664
+ asChild = false,
665
+ children,
666
+ ...props
667
+ }: KanbanColumnContentProps) {
668
+ const { columns, getItemId } = useContext(KanbanContext);
669
+
670
+ const itemIds = useMemo(
671
+ () => columns[value].map(getItemId),
672
+ [columns, getItemId, value],
673
+ );
674
+
675
+ const Comp = asChild ? Slot.Root : "div";
676
+
677
+ return (
678
+ <SortableContext items={itemIds} strategy={verticalListSortingStrategy}>
679
+ <Comp
680
+ data-slot="kanban-column-content"
681
+ className={cn("flex flex-col gap-2", className)}
682
+ {...props}
683
+ >
684
+ {children}
685
+ </Comp>
686
+ </SortableContext>
687
+ );
688
+ }
689
+
690
+ export interface KanbanOverlayProps extends Omit<
691
+ React.ComponentProps<typeof DragOverlay>,
692
+ "children"
693
+ > {
694
+ children?:
695
+ | ReactNode
696
+ | ((params: {
697
+ value: UniqueIdentifier;
698
+ variant: "column" | "item";
699
+ }) => ReactNode);
700
+ }
701
+
702
+ function KanbanOverlay({ children, className, ...props }: KanbanOverlayProps) {
703
+ const { activeId, isColumn, modifiers } = useContext(KanbanContext);
704
+ const [mounted, setMounted] = useState(false);
705
+
706
+ useLayoutEffect(() => setMounted(true), []);
707
+
708
+ const variant = activeId ? (isColumn(activeId) ? "column" : "item") : "item";
709
+
710
+ const content =
711
+ activeId && children
712
+ ? typeof children === "function"
713
+ ? children({ value: activeId, variant })
714
+ : children
715
+ : null;
716
+
717
+ if (!mounted) return null;
718
+
719
+ return createPortal(
720
+ <DragOverlay
721
+ dropAnimation={dropAnimationConfig}
722
+ modifiers={modifiers}
723
+ className={cn("z-50", activeId && "cursor-grabbing", className)}
724
+ {...props}
725
+ >
726
+ <IsOverlayContext.Provider value={true}>
727
+ {content}
728
+ </IsOverlayContext.Provider>
729
+ </DragOverlay>,
730
+ document.body,
731
+ );
732
+ }
733
+
734
+ export {
735
+ Kanban,
736
+ KanbanBoard,
737
+ KanbanColumn,
738
+ KanbanColumnHandle,
739
+ KanbanItem,
740
+ KanbanItemHandle,
741
+ KanbanColumnContent,
742
+ KanbanOverlay,
743
+ };