@middag-io/react 0.45.0 → 0.45.2
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/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- 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
|
+
};
|