@softure-ai/theme-notion 0.3.0 → 0.4.0
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/CHANGELOG.md +28 -0
- package/README.md +32 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/notion/Sortable.d.ts +17 -6
- package/dist/notion/Sortable.d.ts.map +1 -1
- package/dist/notion/Sortable.js +97 -22
- package/dist/notion/Sortable.js.map +1 -1
- package/dist/ui/item.d.ts.map +1 -1
- package/dist/ui/item.js +1 -0
- package/dist/ui/item.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/notion/Sortable.tsx +147 -30
- package/src/ui/item.tsx +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,34 @@ Newest first. Each version lists what changed for an app that uses the theme. Wh
|
|
|
4
4
|
production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
5
|
"Definition of done").
|
|
6
6
|
|
|
7
|
+
## 0.4.0
|
|
8
|
+
|
|
9
|
+
- Server Components (#770): the package root imports from a React Server Component again. 0.3.0's `ui/item.tsx`
|
|
10
|
+
created the `ItemGroup` context at module level without `"use client"`, so `next build` failed with
|
|
11
|
+
`createContext is not a function` on any server page that imported from `@softure-ai/theme-notion`, even for
|
|
12
|
+
server-safe parts such as `PageHeader` or `Empty`. The file is a client module now; `tests/repo/themes.test.ts`
|
|
13
|
+
checks every theme so a file with a context or a component hook cannot ship without the directive. An app on 0.2.0
|
|
14
|
+
moves to this version with no change of its own; an app on 0.3.0 drops any workaround that avoided the root import.
|
|
15
|
+
- `SortableList` covers what kept an app on its own dnd-kit wiring (#771); everything is opt-in, existing lists
|
|
16
|
+
behave as before:
|
|
17
|
+
- `disabled` on the list (read-only: no row lifts by touch, mouse or keyboard, rows stay clickable) and on a
|
|
18
|
+
`SortableItem` (one row; wins over the list's). A disabled row carries `data-disabled` and no drag attributes; a
|
|
19
|
+
disabled row's `SortableHandle` is a disabled button.
|
|
20
|
+
- `group` on a `SortableItem`: a lifted row lands only among rows of its own group, by pointer and keyboard.
|
|
21
|
+
- `onDragStart(id)`, `onDragEnd(id, move | null)` (every drop, `null` when the order stayed) and
|
|
22
|
+
`onDragCancel(id)`; the list carries `data-sorting` while a row is lifted. The list's props no longer take the
|
|
23
|
+
native HTML `onDragStart` / `onDragEnd` (dnd-kit never used native drag events).
|
|
24
|
+
- `dragBy="activator"` with `SortableActivator`: the app's own element inside the row lifts it with the row's
|
|
25
|
+
hold; a press elsewhere in the row does not. The keyboard picks up the focused row, which stays focusable.
|
|
26
|
+
- `as="ol"`; children that are not a `SortableItem` stay in place.
|
|
27
|
+
- Fix: a key pressed on a control inside a row (Enter on a button) no longer picks up the row in `row` mode.
|
|
28
|
+
- Migration for an app with its own `DndContext` / `useSortable`: render `SortableList` (`as="ol"` for a numbered
|
|
29
|
+
list, `disabled` for the read-only mode, `dragBy="activator"` with the row's button in `SortableActivator`),
|
|
30
|
+
a `SortableItem` per row with `group`, and move the lift and drop side effects (hiding secondary content, a
|
|
31
|
+
vibration) to `onDragStart` / `onDragEnd` / `onDragCancel` or to `group-data-[sorting]:…` classes. Drop the
|
|
32
|
+
click grace timer after a drop: the click that ends a mouse drop never reaches the row. Remove the app's
|
|
33
|
+
`accent-strong` / `shadow-menu` lifted classes and its `@dnd-kit/*` dependencies if nothing else uses them.
|
|
34
|
+
|
|
7
35
|
## 0.3.0
|
|
8
36
|
|
|
9
37
|
- Needs `@softure-ai/theme-kit` `^0.1.3` (was `^0.1.2`): the version whose `base.css` carries the border and outline
|
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ and more, a native `<details>`), `PageFrame` (a page outside the app shell, the
|
|
|
117
117
|
and count, the shown tab in the address; `Tabs` keeps it in client state), `MarkPopover` (a counted tag that opens a
|
|
118
118
|
list of what it counts, below), `FilterChip` and `FilterChipAdd` (a list's filter pills, below), `Steps` (numbered
|
|
119
119
|
stages with a state, below), `Code` (inline code) and `CodeBlock` (a mono block for logs and paths, below),
|
|
120
|
-
`SortableList`, `SortableItem` and `
|
|
120
|
+
`SortableList`, `SortableItem`, `SortableHandle` and `SortableActivator` (rows reordered by dragging, below).
|
|
121
121
|
|
|
122
122
|
**`FilterChip`.** The filters above a list or a table, drawn the way a Notion database view draws them: a 24 px pill
|
|
123
123
|
`icon · Label: value ▾` that opens a menu of options in the design system's popover. While the default value is
|
|
@@ -230,8 +230,20 @@ app: `items` are the rows' ids in order, and `onReorder(next, { id, from, to })`
|
|
|
230
230
|
`dragBy="handle"` leaves the row alone and drags only by a `SortableHandle` (a ghost grip button, for a desktop list;
|
|
231
231
|
a mouse starts at once there). A screen reader hears the `instructions` on the row (or handle) and the
|
|
232
232
|
`announcements` while it moves: strings with `{item}`, `{position}` and `{total}`, where `getItemLabel(id)` names the
|
|
233
|
-
row (the id by default). `data-slot="sortable-list"`, `sortable-item` (with `data-id`)
|
|
234
|
-
parts.
|
|
233
|
+
row (the id by default). `data-slot="sortable-list"`, `sortable-item` (with `data-id`), `sortable-handle` and
|
|
234
|
+
`sortable-activator` mark the parts.
|
|
235
|
+
|
|
236
|
+
`dragBy="activator"` lifts a row only from the app's own element wrapped in `SortableActivator` (the row's button,
|
|
237
|
+
not its unfolded details), with the same hold; the element keeps its click and keys. The keyboard still picks up the
|
|
238
|
+
focused row, so the row stays focusable next to the button: Space and Enter on the button keep meaning "open". A key
|
|
239
|
+
pressed on any control inside a row stays with that control in every mode. `disabled` on the list makes it read-only
|
|
240
|
+
(no row lifts by touch, mouse or keyboard, the drag attributes go, the rows keep their own handlers, `data-disabled`
|
|
241
|
+
marks them); `disabled` on a `SortableItem` holds one row and wins over the list's. `group` on a `SortableItem` keeps
|
|
242
|
+
a lifted row among rows of the same group (by pointer and keyboard); rows without a group form one together.
|
|
243
|
+
`onDragStart(id)`, `onDragEnd(id, move | null)` (every drop; `null` when the order stayed) and `onDragCancel(id)`
|
|
244
|
+
follow the drag, and the list carries `data-sorting` while a row is lifted (`group-data-[sorting]:hidden` on a row's
|
|
245
|
+
secondary content with `group` on the list). `as="ol"` renders a numbered list; children that are not a
|
|
246
|
+
`SortableItem` (an empty-state `<li>`) stay in place. The click that ends a mouse drop never reaches the row.
|
|
235
247
|
|
|
236
248
|
```tsx
|
|
237
249
|
<SortableList label="Shopping list" items={ids} onReorder={(next) => setIds(next)}
|
|
@@ -251,6 +263,23 @@ parts.
|
|
|
251
263
|
</SortableItem>
|
|
252
264
|
))}
|
|
253
265
|
</SortableList>
|
|
266
|
+
|
|
267
|
+
<SortableList label="Day" as="ol" items={ids} onReorder={setIds} dragBy="activator" disabled={isReadOnly}
|
|
268
|
+
onDragStart={() => navigator.vibrate?.(10)} className="group">
|
|
269
|
+
{ids.map((id) => (
|
|
270
|
+
<SortableItem key={id} id={id} group={byId[id].isStop ? "stops" : "to-fit"}>
|
|
271
|
+
<SortableActivator>
|
|
272
|
+
<button type="button" onClick={() => toggle(id)}>{byId[id].name}</button>
|
|
273
|
+
</SortableActivator>
|
|
274
|
+
{openId === id ? (
|
|
275
|
+
<div className="group-data-[sorting]:hidden">
|
|
276
|
+
<DetailTable label="Details" rows={byId[id].details} />
|
|
277
|
+
</div>
|
|
278
|
+
) : null}
|
|
279
|
+
</SortableItem>
|
|
280
|
+
))}
|
|
281
|
+
{ids.length === 0 ? <li className="text-muted-foreground">Nothing planned</li> : null}
|
|
282
|
+
</SortableList>
|
|
254
283
|
```
|
|
255
284
|
|
|
256
285
|
Deltas from stock shadcn:
|
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export { PageFrame, type PageFrameProps } from "./notion/PageFrame.js";
|
|
|
50
50
|
export { PageHeader, type PageCrumb, type PageHeaderProps } from "./notion/PageHeader.js";
|
|
51
51
|
export { PropertyList, type Property, type PropertyListProps } from "./notion/PropertyList.js";
|
|
52
52
|
export { SidePanel, type SidePanelLayout, type SidePanelProps } from "./notion/SidePanel.js";
|
|
53
|
-
export { SortableHandle, SortableItem, SortableList, type SortableAnnouncements, type SortableDragBy, type SortableHandleProps, type SortableItemProps, type SortableListProps, type SortableMove, } from "./notion/Sortable.js";
|
|
53
|
+
export { SortableActivator, SortableHandle, SortableItem, SortableList, type SortableActivatorProps, type SortableAnnouncements, type SortableDragBy, type SortableHandleProps, type SortableItemProps, type SortableListProps, type SortableMove, } from "./notion/Sortable.js";
|
|
54
54
|
export { StatCards, StatPills, StatsFold, type StatCard, type StatCardAside, type StatCardsProps, type StatPill, type StatPillsProps, type StatsFoldProps, } from "./notion/Stats.js";
|
|
55
55
|
export { Status, type StatusProps } from "./notion/Status.js";
|
|
56
56
|
export { Steps, type StepItem, type StepState, type StepsLayout, type StepsProps } from "./notion/Steps.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1E,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,C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K,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ export { PageFrame } from "./notion/PageFrame.js";
|
|
|
52
52
|
export { PageHeader } from "./notion/PageHeader.js";
|
|
53
53
|
export { PropertyList } from "./notion/PropertyList.js";
|
|
54
54
|
export { SidePanel } from "./notion/SidePanel.js";
|
|
55
|
-
export { SortableHandle, SortableItem, SortableList, } from "./notion/Sortable.js";
|
|
55
|
+
export { SortableActivator, SortableHandle, SortableItem, SortableList, } from "./notion/Sortable.js";
|
|
56
56
|
export { StatCards, StatPills, StatsFold, } from "./notion/Stats.js";
|
|
57
57
|
export { Status } from "./notion/Status.js";
|
|
58
58
|
export { Steps } from "./notion/Steps.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,oGAAoG;AACpG,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB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KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Slot } from "radix-ui";
|
|
2
|
+
import { type ComponentProps, type ReactNode, type Ref } from "react";
|
|
2
3
|
import { Button } from "../ui/button.js";
|
|
3
4
|
export interface SortableAnnouncements {
|
|
4
5
|
readonly pickedUp: string;
|
|
@@ -11,8 +12,9 @@ export interface SortableMove {
|
|
|
11
12
|
readonly from: number;
|
|
12
13
|
readonly to: number;
|
|
13
14
|
}
|
|
14
|
-
export type SortableDragBy = "row" | "handle";
|
|
15
|
-
export interface SortableListProps extends Omit<ComponentProps<"ul">, "children"> {
|
|
15
|
+
export type SortableDragBy = "row" | "handle" | "activator";
|
|
16
|
+
export interface SortableListProps extends Omit<ComponentProps<"ul">, "children" | "ref" | "onDragStart" | "onDragEnd"> {
|
|
17
|
+
readonly ref?: Ref<HTMLUListElement | HTMLOListElement>;
|
|
16
18
|
readonly label: string;
|
|
17
19
|
readonly items: readonly string[];
|
|
18
20
|
readonly onReorder: (next: string[], move: SortableMove) => void;
|
|
@@ -22,15 +24,24 @@ export interface SortableListProps extends Omit<ComponentProps<"ul">, "children"
|
|
|
22
24
|
readonly instructions?: string;
|
|
23
25
|
readonly announcements?: Partial<SortableAnnouncements>;
|
|
24
26
|
readonly getItemLabel?: (id: string) => string;
|
|
27
|
+
readonly disabled?: boolean;
|
|
28
|
+
readonly as?: "ul" | "ol";
|
|
29
|
+
readonly onDragStart?: (id: string) => void;
|
|
30
|
+
readonly onDragEnd?: (id: string, move: SortableMove | null) => void;
|
|
31
|
+
readonly onDragCancel?: (id: string) => void;
|
|
25
32
|
readonly children: ReactNode;
|
|
26
33
|
}
|
|
27
|
-
export declare function SortableList({ label, items, onReorder, dragBy, holdDelay, tolerance, instructions, announcements, getItemLabel, className, children, ...props }: SortableListProps): import("react").JSX.Element;
|
|
34
|
+
export declare function SortableList({ label, items, onReorder, dragBy, holdDelay, tolerance, instructions, announcements, getItemLabel, disabled, as: List, onDragStart, onDragEnd, onDragCancel, ref, className, children, ...props }: SortableListProps): import("react").JSX.Element;
|
|
28
35
|
export interface SortableItemProps extends ComponentProps<"li"> {
|
|
29
36
|
readonly id: string;
|
|
37
|
+
readonly group?: string;
|
|
38
|
+
readonly disabled?: boolean;
|
|
30
39
|
}
|
|
31
|
-
export declare function SortableItem({ id, className, style, children, ...props }: SortableItemProps): import("react").JSX.Element;
|
|
40
|
+
export declare function SortableItem({ id, group, disabled, className, style, children, ...props }: SortableItemProps): import("react").JSX.Element;
|
|
41
|
+
export type SortableActivatorProps = ComponentProps<typeof Slot.Root>;
|
|
42
|
+
export declare function SortableActivator(props: SortableActivatorProps): import("react").JSX.Element;
|
|
32
43
|
export interface SortableHandleProps extends Omit<ComponentProps<typeof Button>, "children"> {
|
|
33
44
|
readonly label?: string;
|
|
34
45
|
}
|
|
35
|
-
export declare function SortableHandle({ label, className, ...props }: SortableHandleProps): import("react").JSX.Element;
|
|
46
|
+
export declare function SortableHandle({ label, className, disabled, ...props }: SortableHandleProps): import("react").JSX.Element;
|
|
36
47
|
//# sourceMappingURL=Sortable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../../src/notion/Sortable.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../../src/notion/Sortable.tsx"],"names":[],"mappings":"AAyBA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAmE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAIvI,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIzC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QA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AAC,EAAE,MAAM,CAAC;CACzB;AAID,wBAAgB,cAAc,CAAC,EAAE,KAAgC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,+BAoBtH"}
|
package/dist/notion/Sortable.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { closestCenter, DndContext, KeyboardSensor, MouseSensor, TouchSensor, useSensor, useSensors, } from "@dnd-kit/core";
|
|
3
|
+
import { closestCenter, DndContext, KeyboardSensor, MouseSensor, TouchSensor, useDndContext, useSensor, useSensors, } from "@dnd-kit/core";
|
|
4
4
|
import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy, } from "@dnd-kit/sortable";
|
|
5
5
|
import { CSS } from "@dnd-kit/utilities";
|
|
6
6
|
import { GripVertical } from "lucide-react";
|
|
7
|
-
import {
|
|
7
|
+
import { Slot } from "radix-ui";
|
|
8
|
+
import { createContext, useContext, useId, useCallback, useRef, useState } from "react";
|
|
8
9
|
import { en as messages } from "../messages/en.js";
|
|
9
10
|
import { cn } from "../lib/utils.js";
|
|
10
11
|
import { Button } from "../ui/button.js";
|
|
@@ -15,13 +16,35 @@ const restrictToVerticalAxis = ({ transform }) => ({ ...transform, x: 0 });
|
|
|
15
16
|
function fillAnnouncement(template, values) {
|
|
16
17
|
return template.replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
function assignRef(ref, node) {
|
|
20
|
+
if (typeof ref === "function")
|
|
21
|
+
ref(node);
|
|
22
|
+
else if (ref)
|
|
23
|
+
ref.current = node;
|
|
24
|
+
}
|
|
25
|
+
// A row's group travels in the drag data; dnd-kit types that data loosely, so it is read as unknown.
|
|
26
|
+
function readGroup(data) {
|
|
27
|
+
if (typeof data !== "object" || data === null || !("group" in data))
|
|
28
|
+
return undefined;
|
|
29
|
+
return typeof data.group === "string" ? data.group : undefined;
|
|
30
|
+
}
|
|
31
|
+
// The keyboard sensor binds `onKeyDown`; the pointer sensors bind the rest.
|
|
32
|
+
function splitListeners(listeners) {
|
|
33
|
+
const entries = Object.entries(listeners ?? {});
|
|
34
|
+
return {
|
|
35
|
+
keyboard: Object.fromEntries(entries.filter(([name]) => name === "onKeyDown")),
|
|
36
|
+
pointer: Object.fromEntries(entries.filter(([name]) => name !== "onKeyDown")),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const SortableListContext = createContext({ dragBy: "row", isDisabled: false });
|
|
40
|
+
const SortableItemContext = createContext(null);
|
|
20
41
|
// A list whose rows are reordered by dragging: a long press lifts a row on a touch screen (a swipe before the hold
|
|
21
42
|
// still scrolls, a tap still activates the row), a mouse drags it, the keyboard picks it up with Space or Enter and
|
|
22
|
-
// moves it with the arrows. The order stays with the app: `onReorder` gets the new one.
|
|
23
|
-
|
|
43
|
+
// moves it with the arrows. The order stays with the app: `onReorder` gets the new one. While a row is lifted the
|
|
44
|
+
// list carries `data-sorting`.
|
|
45
|
+
export function SortableList({ label, items, onReorder, dragBy = "row", holdDelay = 500, tolerance = 8, instructions = messages.sortable.instructions, announcements, getItemLabel = (id) => id, disabled = false, as: List = "ul", onDragStart, onDragEnd, onDragCancel, ref, className, children, ...props }) {
|
|
24
46
|
const contextId = useId();
|
|
47
|
+
const [isSorting, setIsSorting] = useState(false);
|
|
25
48
|
const hold = { delay: holdDelay, tolerance };
|
|
26
49
|
const sensors = useSensors(useSensor(MouseSensor, {
|
|
27
50
|
activationConstraint: dragBy === "handle" ? { distance: HANDLE_MOUSE_DISTANCE } : hold,
|
|
@@ -48,36 +71,88 @@ export function SortableList({ label, items, onReorder, dragBy = "row", holdDela
|
|
|
48
71
|
onDragEnd: ({ active, over }) => announce(over ? copy.dropped : copy.cancelled, active.id, over?.id),
|
|
49
72
|
onDragCancel: ({ active }) => announce(copy.cancelled, active.id),
|
|
50
73
|
};
|
|
51
|
-
|
|
74
|
+
// The move a drop makes, or null when it keeps the order (no target, the row's own place, another group).
|
|
75
|
+
function getMove({ active, over }) {
|
|
52
76
|
if (!over || active.id === over.id)
|
|
53
|
-
return;
|
|
77
|
+
return null;
|
|
78
|
+
if (readGroup(active.data.current) !== readGroup(over.data.current))
|
|
79
|
+
return null;
|
|
54
80
|
const from = items.indexOf(String(active.id));
|
|
55
81
|
const to = items.indexOf(String(over.id));
|
|
56
82
|
if (from < 0 || to < 0)
|
|
57
|
-
return;
|
|
58
|
-
|
|
83
|
+
return null;
|
|
84
|
+
return { id: String(active.id), from, to };
|
|
85
|
+
}
|
|
86
|
+
function handleDragEnd(event) {
|
|
87
|
+
setIsSorting(false);
|
|
88
|
+
const move = getMove(event);
|
|
89
|
+
if (move)
|
|
90
|
+
onReorder(arrayMove([...items], move.from, move.to), move);
|
|
91
|
+
onDragEnd?.(String(event.active.id), move);
|
|
59
92
|
}
|
|
60
|
-
return (_jsx(DndContext, { id: contextId, sensors: sensors, collisionDetection: closestCenter, modifiers: [restrictToVerticalAxis], accessibility: { announcements: liveAnnouncements, screenReaderInstructions: { draggable: instructions } },
|
|
93
|
+
return (_jsx(DndContext, { id: contextId, sensors: sensors, collisionDetection: closestCenter, modifiers: [restrictToVerticalAxis], accessibility: { announcements: liveAnnouncements, screenReaderInstructions: { draggable: instructions } }, onDragStart: ({ active }) => {
|
|
94
|
+
setIsSorting(true);
|
|
95
|
+
onDragStart?.(String(active.id));
|
|
96
|
+
}, onDragEnd: handleDragEnd, onDragCancel: ({ active }) => {
|
|
97
|
+
setIsSorting(false);
|
|
98
|
+
onDragCancel?.(String(active.id));
|
|
99
|
+
}, children: _jsx(SortableContext, { items: [...items], strategy: verticalListSortingStrategy, children: _jsx(SortableListContext.Provider, { value: { dragBy, isDisabled: disabled }, children: _jsx(List, { ref: (node) => assignRef(ref, node), "aria-label": label, "data-slot": "sortable-list", "data-drag-by": dragBy, "data-disabled": disabled ? "" : undefined, "data-sorting": isSorting ? "" : undefined, className: cn("flex flex-col", className), ...props, children: children }) }) }) }));
|
|
61
100
|
}
|
|
62
101
|
// The lifted row floats on `accent-strong` with `shadow-menu`, above its siblings; `data-dragging` marks it.
|
|
63
102
|
const SORTABLE_ITEM = "rounded-md bg-background outline-none touch-manipulation select-none [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring data-[dragging]:relative data-[dragging]:z-10 data-[dragging]:bg-accent-strong data-[dragging]:shadow-menu";
|
|
103
|
+
// The drag props the row element itself carries.
|
|
104
|
+
function getRowBinding(binding) {
|
|
105
|
+
if (binding.isDisabled || binding.dragBy === "handle")
|
|
106
|
+
return {};
|
|
107
|
+
if (binding.dragBy === "activator")
|
|
108
|
+
return { ...binding.attributes, ...splitListeners(binding.listeners).keyboard };
|
|
109
|
+
return { ...binding.attributes, ...binding.listeners };
|
|
110
|
+
}
|
|
64
111
|
// One row of a `SortableList`. In `row` mode the row itself is the drag target and is focusable; in `handle` mode a
|
|
65
|
-
// `SortableHandle` inside it is
|
|
66
|
-
|
|
67
|
-
|
|
112
|
+
// `SortableHandle` inside it is; in `activator` mode a `SortableActivator` takes the press and the row the keyboard.
|
|
113
|
+
// The drag's own pointer and key handlers win over the same props on the drag target; a key pressed on a control
|
|
114
|
+
// inside the row stays with that control.
|
|
115
|
+
export function SortableItem({ id, group, disabled, className, style, children, ...props }) {
|
|
116
|
+
const list = useContext(SortableListContext);
|
|
117
|
+
const { active } = useDndContext();
|
|
118
|
+
const isDisabled = disabled ?? list.isDisabled;
|
|
119
|
+
const isOtherGroup = active !== null && readGroup(active.data.current) !== group;
|
|
68
120
|
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
|
69
121
|
id,
|
|
122
|
+
data: { group },
|
|
70
123
|
attributes: { role: "listitem" },
|
|
124
|
+
disabled: { draggable: isDisabled, droppable: isOtherGroup },
|
|
71
125
|
});
|
|
72
|
-
const
|
|
73
|
-
|
|
126
|
+
const binding = { attributes, listeners, setActivatorNodeRef, dragBy: list.dragBy, isDisabled };
|
|
127
|
+
const isRowActivator = list.dragBy !== "handle";
|
|
128
|
+
// The row is the keyboard's activator outside `handle` mode, so a key on a control inside the row stays there.
|
|
129
|
+
const setRowRef = useCallback((node) => {
|
|
130
|
+
setNodeRef(node);
|
|
131
|
+
if (isRowActivator)
|
|
132
|
+
setActivatorNodeRef(node);
|
|
133
|
+
}, [setNodeRef, setActivatorNodeRef, isRowActivator]);
|
|
134
|
+
return (_jsx(SortableItemContext.Provider, { value: binding, children: _jsx("li", { ref: setRowRef, "data-slot": "sortable-item", "data-id": id, "data-group": group, "data-disabled": isDisabled ? "" : undefined, "data-dragging": isDragging ? "" : undefined, className: cn(SORTABLE_ITEM, className), style: { ...style, transform: CSS.Translate.toString(transform), transition }, ...props, ...getRowBinding(binding), children: children }) }));
|
|
74
135
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const binding = useContext(SortableHandleContext);
|
|
136
|
+
function useSortableItemBinding(part) {
|
|
137
|
+
const binding = useContext(SortableItemContext);
|
|
78
138
|
if (!binding)
|
|
79
|
-
throw new Error(
|
|
80
|
-
|
|
81
|
-
|
|
139
|
+
throw new Error(`${part} failed: it must be rendered inside a SortableItem`);
|
|
140
|
+
return binding;
|
|
141
|
+
}
|
|
142
|
+
// The app's own element inside a row (a button, a title) that lifts the row on a press, for a list with
|
|
143
|
+
// `dragBy="activator"`; a press elsewhere in the row does nothing. Its own click and keys keep working. In the other
|
|
144
|
+
// modes, or on a disabled row, it renders its child unchanged.
|
|
145
|
+
export function SortableActivator(props) {
|
|
146
|
+
const binding = useSortableItemBinding("SortableActivator");
|
|
147
|
+
const isBound = binding.dragBy === "activator" && !binding.isDisabled;
|
|
148
|
+
const pointer = isBound ? splitListeners(binding.listeners).pointer : {};
|
|
149
|
+
return _jsx(Slot.Root, { "data-slot": "sortable-activator", ...props, ...pointer });
|
|
150
|
+
}
|
|
151
|
+
// A grip button that drags its row, for a list with `dragBy="handle"`.
|
|
152
|
+
// On a disabled row it is a disabled button.
|
|
153
|
+
export function SortableHandle({ label = messages.sortable.handle, className, disabled, ...props }) {
|
|
154
|
+
const { attributes, listeners, setActivatorNodeRef, isDisabled } = useSortableItemBinding("SortableHandle");
|
|
155
|
+
const dragProps = isDisabled ? {} : { ...attributes, ...listeners };
|
|
156
|
+
return (_jsx(Button, { ref: setActivatorNodeRef, type: "button", variant: "ghost", size: "icon-sm", "data-slot": "sortable-handle", className: cn("cursor-grab touch-none text-muted-foreground active:cursor-grabbing", className), disabled: isDisabled || disabled, ...props, ...dragProps, role: "button", "aria-label": label, children: _jsx(GripVertical, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH }) }));
|
|
82
157
|
}
|
|
83
158
|
//# sourceMappingURL=Sortable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sortable.js","sourceRoot":"","sources":["../../src/notion/Sortable.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GAKX,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Sortable.js","sourceRoot":"","sources":["../../src/notion/Sortable.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,UAAU,GAKX,MAAM,eAAe,CAAC;AAC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uB;IACrH,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,UAAU,EAAE,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC5G,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IACpE,OAAO,CACL,KAAC,MAAM,IACL,GAAG,EAAE,mBAAmB,EACxB,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,OAAO,EACf,IAAI,EAAC,SAAS,eACJ,iBAAiB,EAC3B,SAAS,EAAE,EAAE,CAAC,qEAAqE,EAAE,SAAS,CAAC,EAC/F,QAAQ,EAAE,UAAU,IAAI,QAAQ,KAC5B,KAAK,KACL,SAAS,EACb,IAAI,EAAC,QAAQ,gBACD,KAAK,YAEjB,KAAC,YAAY,mBAAa,MAAM,EAAC,WAAW,EAAE,iBAAiB,GAAI,GAC5D,CACV,CAAC;AACJ,CAAC"}
|
package/dist/ui/item.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../../src/ui/item.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../../src/ui/item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAIjE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK1C,iBAAS,SAAS,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,qBAWtE;AAED,iBAAS,aAAa,CAAC,EACrB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,SAAS,CAAC,qBASxC;AAED,QAAA,MAAM,Y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AAU,GACX,CAAA"}
|
package/dist/ui/item.js
CHANGED
package/dist/ui/item.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item.js","sourceRoot":"","sources":["../../src/ui/item.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"item.js","sourceRoot":"","sources":["../../src/ui/item.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,wFAAwF;AACxF,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAEnD,SAAS,SAAS,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAA+B;IACrE,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,YACpC,cACE,IAAI,EAAC,MAAM,eACD,YAAY,EACtB,SAAS,EAAE,EAAE,CAAC,gCAAgC,EAAE,SAAS,CAAC,KACtD,KAAK,GACT,GACwB,CAC7B,CAAA;AACH,CAAC;AAED,SAAS,aAAa,CAAC,EACrB,SAAS,EACT,GAAG,KAAK,EAC+B;IACvC,OAAO,CACL,KAAC,SAAS,iBACE,gBAAgB,EAC1B,WAAW,EAAC,YAAY,EACxB,SAAS,EAAE,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,KAC5B,KAAK,GACT,CACH,CAAA;AACH,CAAC;AAED,MAAM,YAAY,GAAG,GAAG,CACtB,qPAAqP,EACrP;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,eAAe;YACxB,KAAK,EAAE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AAS,EACT,aAAa,EACb,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,GACX,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/theme-notion",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "SOFTURE AI Notion theme: shadcn/ui components (new-york v4, Radix, Tailwind CSS v4, lucide) with the Notion design system's tokens and deltas, ready to import.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -55,9 +55,11 @@ export { PageHeader, type PageCrumb, type PageHeaderProps } from "./notion/PageH
|
|
|
55
55
|
export { PropertyList, type Property, type PropertyListProps } from "./notion/PropertyList.js";
|
|
56
56
|
export { SidePanel, type SidePanelLayout, type SidePanelProps } from "./notion/SidePanel.js";
|
|
57
57
|
export {
|
|
58
|
+
SortableActivator,
|
|
58
59
|
SortableHandle,
|
|
59
60
|
SortableItem,
|
|
60
61
|
SortableList,
|
|
62
|
+
type SortableActivatorProps,
|
|
61
63
|
type SortableAnnouncements,
|
|
62
64
|
type SortableDragBy,
|
|
63
65
|
type SortableHandleProps,
|
package/src/notion/Sortable.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
KeyboardSensor,
|
|
7
7
|
MouseSensor,
|
|
8
8
|
TouchSensor,
|
|
9
|
+
useDndContext,
|
|
9
10
|
useSensor,
|
|
10
11
|
useSensors,
|
|
11
12
|
type Announcements,
|
|
@@ -22,7 +23,8 @@ import {
|
|
|
22
23
|
} from "@dnd-kit/sortable";
|
|
23
24
|
import { CSS } from "@dnd-kit/utilities";
|
|
24
25
|
import { GripVertical } from "lucide-react";
|
|
25
|
-
import {
|
|
26
|
+
import { Slot } from "radix-ui";
|
|
27
|
+
import { createContext, useContext, useId, useCallback, useRef, useState, type ComponentProps, type ReactNode, type Ref } from "react";
|
|
26
28
|
|
|
27
29
|
import { en as messages } from "../messages/en.js";
|
|
28
30
|
import { cn } from "../lib/utils.js";
|
|
@@ -43,10 +45,14 @@ export interface SortableMove {
|
|
|
43
45
|
readonly to: number;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
// `row`: the whole row is dragged (a phone list); `handle`: only `SortableHandle` starts a drag (a desktop list)
|
|
47
|
-
|
|
48
|
+
// `row`: the whole row is dragged (a phone list); `handle`: only `SortableHandle` starts a drag (a desktop list);
|
|
49
|
+
// `activator`: a press on the app's own `SortableActivator` inside the row lifts it, with the row's hold, while the
|
|
50
|
+
// keyboard still picks up the focused row.
|
|
51
|
+
export type SortableDragBy = "row" | "handle" | "activator";
|
|
48
52
|
|
|
49
|
-
export interface SortableListProps
|
|
53
|
+
export interface SortableListProps
|
|
54
|
+
extends Omit<ComponentProps<"ul">, "children" | "ref" | "onDragStart" | "onDragEnd"> {
|
|
55
|
+
readonly ref?: Ref<HTMLUListElement | HTMLOListElement>;
|
|
50
56
|
// The list's accessible name.
|
|
51
57
|
readonly label: string;
|
|
52
58
|
// The rows' ids in their current order; the app owns the order.
|
|
@@ -63,6 +69,16 @@ export interface SortableListProps extends Omit<ComponentProps<"ul">, "children"
|
|
|
63
69
|
readonly announcements?: Partial<SortableAnnouncements>;
|
|
64
70
|
// A row's name in the announcements; defaults to its id.
|
|
65
71
|
readonly getItemLabel?: (id: string) => string;
|
|
72
|
+
// No row lifts by touch, mouse or keyboard; the rows still render and keep their own handlers.
|
|
73
|
+
readonly disabled?: boolean;
|
|
74
|
+
// The list element: `ol` for a numbered list. Children that are not a `SortableItem` stay in place.
|
|
75
|
+
readonly as?: "ul" | "ol";
|
|
76
|
+
// Called when a row lifts.
|
|
77
|
+
readonly onDragStart?: (id: string) => void;
|
|
78
|
+
// Called on every drop, with the move when the order changed and `null` when it did not.
|
|
79
|
+
readonly onDragEnd?: (id: string, move: SortableMove | null) => void;
|
|
80
|
+
// Called when a drag is cancelled (Escape, or the page lost focus).
|
|
81
|
+
readonly onDragCancel?: (id: string) => void;
|
|
66
82
|
readonly children: ReactNode;
|
|
67
83
|
}
|
|
68
84
|
|
|
@@ -75,19 +91,46 @@ function fillAnnouncement(template: string, values: Readonly<Record<string, stri
|
|
|
75
91
|
return template.replace(/\{(\w+)\}/g, (match, key: string) => (key in values ? String(values[key]) : match));
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
function assignRef<T>(ref: Ref<T> | undefined, node: T | null) {
|
|
95
|
+
if (typeof ref === "function") ref(node);
|
|
96
|
+
else if (ref) ref.current = node;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// A row's group travels in the drag data; dnd-kit types that data loosely, so it is read as unknown.
|
|
100
|
+
function readGroup(data: unknown): string | undefined {
|
|
101
|
+
if (typeof data !== "object" || data === null || !("group" in data)) return undefined;
|
|
102
|
+
return typeof data.group === "string" ? data.group : undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type SortableListeners = ReturnType<typeof useSortable>["listeners"];
|
|
106
|
+
|
|
107
|
+
// The keyboard sensor binds `onKeyDown`; the pointer sensors bind the rest.
|
|
108
|
+
function splitListeners(listeners: SortableListeners): { keyboard: SortableListeners; pointer: SortableListeners } {
|
|
109
|
+
const entries = Object.entries(listeners ?? {});
|
|
110
|
+
return {
|
|
111
|
+
keyboard: Object.fromEntries(entries.filter(([name]) => name === "onKeyDown")),
|
|
112
|
+
pointer: Object.fromEntries(entries.filter(([name]) => name !== "onKeyDown")),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface SortableListContextValue {
|
|
79
117
|
readonly dragBy: SortableDragBy;
|
|
118
|
+
readonly isDisabled: boolean;
|
|
80
119
|
}
|
|
81
120
|
|
|
82
|
-
const SortableListContext = createContext<
|
|
121
|
+
const SortableListContext = createContext<SortableListContextValue>({ dragBy: "row", isDisabled: false });
|
|
83
122
|
|
|
84
|
-
|
|
123
|
+
interface SortableItemBinding extends Pick<ReturnType<typeof useSortable>, "attributes" | "listeners" | "setActivatorNodeRef"> {
|
|
124
|
+
readonly dragBy: SortableDragBy;
|
|
125
|
+
readonly isDisabled: boolean;
|
|
126
|
+
}
|
|
85
127
|
|
|
86
|
-
const
|
|
128
|
+
const SortableItemContext = createContext<SortableItemBinding | null>(null);
|
|
87
129
|
|
|
88
130
|
// A list whose rows are reordered by dragging: a long press lifts a row on a touch screen (a swipe before the hold
|
|
89
131
|
// still scrolls, a tap still activates the row), a mouse drags it, the keyboard picks it up with Space or Enter and
|
|
90
|
-
// moves it with the arrows. The order stays with the app: `onReorder` gets the new one.
|
|
132
|
+
// moves it with the arrows. The order stays with the app: `onReorder` gets the new one. While a row is lifted the
|
|
133
|
+
// list carries `data-sorting`.
|
|
91
134
|
export function SortableList({
|
|
92
135
|
label,
|
|
93
136
|
items,
|
|
@@ -98,11 +141,18 @@ export function SortableList({
|
|
|
98
141
|
instructions = messages.sortable.instructions,
|
|
99
142
|
announcements,
|
|
100
143
|
getItemLabel = (id) => id,
|
|
144
|
+
disabled = false,
|
|
145
|
+
as: List = "ul",
|
|
146
|
+
onDragStart,
|
|
147
|
+
onDragEnd,
|
|
148
|
+
onDragCancel,
|
|
149
|
+
ref,
|
|
101
150
|
className,
|
|
102
151
|
children,
|
|
103
152
|
...props
|
|
104
153
|
}: SortableListProps) {
|
|
105
154
|
const contextId = useId();
|
|
155
|
+
const [isSorting, setIsSorting] = useState(false);
|
|
106
156
|
const hold = { delay: holdDelay, tolerance };
|
|
107
157
|
const sensors = useSensors(
|
|
108
158
|
useSensor(MouseSensor, {
|
|
@@ -135,12 +185,21 @@ export function SortableList({
|
|
|
135
185
|
onDragCancel: ({ active }) => announce(copy.cancelled, active.id),
|
|
136
186
|
};
|
|
137
187
|
|
|
138
|
-
|
|
139
|
-
|
|
188
|
+
// The move a drop makes, or null when it keeps the order (no target, the row's own place, another group).
|
|
189
|
+
function getMove({ active, over }: DragEndEvent): SortableMove | null {
|
|
190
|
+
if (!over || active.id === over.id) return null;
|
|
191
|
+
if (readGroup(active.data.current) !== readGroup(over.data.current)) return null;
|
|
140
192
|
const from = items.indexOf(String(active.id));
|
|
141
193
|
const to = items.indexOf(String(over.id));
|
|
142
|
-
if (from < 0 || to < 0) return;
|
|
143
|
-
|
|
194
|
+
if (from < 0 || to < 0) return null;
|
|
195
|
+
return { id: String(active.id), from, to };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function handleDragEnd(event: DragEndEvent) {
|
|
199
|
+
setIsSorting(false);
|
|
200
|
+
const move = getMove(event);
|
|
201
|
+
if (move) onReorder(arrayMove([...items], move.from, move.to), move);
|
|
202
|
+
onDragEnd?.(String(event.active.id), move);
|
|
144
203
|
}
|
|
145
204
|
|
|
146
205
|
return (
|
|
@@ -150,19 +209,30 @@ export function SortableList({
|
|
|
150
209
|
collisionDetection={closestCenter}
|
|
151
210
|
modifiers={[restrictToVerticalAxis]}
|
|
152
211
|
accessibility={{ announcements: liveAnnouncements, screenReaderInstructions: { draggable: instructions } }}
|
|
212
|
+
onDragStart={({ active }) => {
|
|
213
|
+
setIsSorting(true);
|
|
214
|
+
onDragStart?.(String(active.id));
|
|
215
|
+
}}
|
|
153
216
|
onDragEnd={handleDragEnd}
|
|
217
|
+
onDragCancel={({ active }) => {
|
|
218
|
+
setIsSorting(false);
|
|
219
|
+
onDragCancel?.(String(active.id));
|
|
220
|
+
}}
|
|
154
221
|
>
|
|
155
222
|
<SortableContext items={[...items]} strategy={verticalListSortingStrategy}>
|
|
156
|
-
<SortableListContext.Provider value={{ dragBy }}>
|
|
157
|
-
<
|
|
223
|
+
<SortableListContext.Provider value={{ dragBy, isDisabled: disabled }}>
|
|
224
|
+
<List
|
|
225
|
+
ref={(node: HTMLUListElement | HTMLOListElement | null) => assignRef(ref, node)}
|
|
158
226
|
aria-label={label}
|
|
159
227
|
data-slot="sortable-list"
|
|
160
228
|
data-drag-by={dragBy}
|
|
229
|
+
data-disabled={disabled ? "" : undefined}
|
|
230
|
+
data-sorting={isSorting ? "" : undefined}
|
|
161
231
|
className={cn("flex flex-col", className)}
|
|
162
232
|
{...props}
|
|
163
233
|
>
|
|
164
234
|
{children}
|
|
165
|
-
</
|
|
235
|
+
</List>
|
|
166
236
|
</SortableListContext.Provider>
|
|
167
237
|
</SortableContext>
|
|
168
238
|
</DndContext>
|
|
@@ -172,49 +242,96 @@ export function SortableList({
|
|
|
172
242
|
export interface SortableItemProps extends ComponentProps<"li"> {
|
|
173
243
|
// The row's id, one of the list's `items`.
|
|
174
244
|
readonly id: string;
|
|
245
|
+
// A lifted row lands only among rows of its own group; rows without one form a group of their own.
|
|
246
|
+
readonly group?: string;
|
|
247
|
+
// This row does not lift; it wins over the list's `disabled`. Other rows may still move past it.
|
|
248
|
+
readonly disabled?: boolean;
|
|
175
249
|
}
|
|
176
250
|
|
|
177
251
|
// The lifted row floats on `accent-strong` with `shadow-menu`, above its siblings; `data-dragging` marks it.
|
|
178
252
|
const SORTABLE_ITEM =
|
|
179
253
|
"rounded-md bg-background outline-none touch-manipulation select-none [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring data-[dragging]:relative data-[dragging]:z-10 data-[dragging]:bg-accent-strong data-[dragging]:shadow-menu";
|
|
180
254
|
|
|
255
|
+
// The drag props the row element itself carries.
|
|
256
|
+
function getRowBinding(binding: SortableItemBinding) {
|
|
257
|
+
if (binding.isDisabled || binding.dragBy === "handle") return {};
|
|
258
|
+
if (binding.dragBy === "activator") return { ...binding.attributes, ...splitListeners(binding.listeners).keyboard };
|
|
259
|
+
return { ...binding.attributes, ...binding.listeners };
|
|
260
|
+
}
|
|
261
|
+
|
|
181
262
|
// One row of a `SortableList`. In `row` mode the row itself is the drag target and is focusable; in `handle` mode a
|
|
182
|
-
// `SortableHandle` inside it is
|
|
183
|
-
|
|
184
|
-
|
|
263
|
+
// `SortableHandle` inside it is; in `activator` mode a `SortableActivator` takes the press and the row the keyboard.
|
|
264
|
+
// The drag's own pointer and key handlers win over the same props on the drag target; a key pressed on a control
|
|
265
|
+
// inside the row stays with that control.
|
|
266
|
+
export function SortableItem({ id, group, disabled, className, style, children, ...props }: SortableItemProps) {
|
|
267
|
+
const list = useContext(SortableListContext);
|
|
268
|
+
const { active } = useDndContext();
|
|
269
|
+
const isDisabled = disabled ?? list.isDisabled;
|
|
270
|
+
const isOtherGroup = active !== null && readGroup(active.data.current) !== group;
|
|
185
271
|
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
|
186
272
|
id,
|
|
273
|
+
data: { group },
|
|
187
274
|
attributes: { role: "listitem" },
|
|
275
|
+
disabled: { draggable: isDisabled, droppable: isOtherGroup },
|
|
188
276
|
});
|
|
189
|
-
const
|
|
277
|
+
const binding: SortableItemBinding = { attributes, listeners, setActivatorNodeRef, dragBy: list.dragBy, isDisabled };
|
|
278
|
+
const isRowActivator = list.dragBy !== "handle";
|
|
279
|
+
// The row is the keyboard's activator outside `handle` mode, so a key on a control inside the row stays there.
|
|
280
|
+
const setRowRef = useCallback(
|
|
281
|
+
(node: HTMLLIElement | null) => {
|
|
282
|
+
setNodeRef(node);
|
|
283
|
+
if (isRowActivator) setActivatorNodeRef(node);
|
|
284
|
+
},
|
|
285
|
+
[setNodeRef, setActivatorNodeRef, isRowActivator],
|
|
286
|
+
);
|
|
190
287
|
return (
|
|
191
|
-
<
|
|
288
|
+
<SortableItemContext.Provider value={binding}>
|
|
192
289
|
<li
|
|
193
|
-
ref={
|
|
290
|
+
ref={setRowRef}
|
|
194
291
|
data-slot="sortable-item"
|
|
195
292
|
data-id={id}
|
|
293
|
+
data-group={group}
|
|
294
|
+
data-disabled={isDisabled ? "" : undefined}
|
|
196
295
|
data-dragging={isDragging ? "" : undefined}
|
|
197
296
|
className={cn(SORTABLE_ITEM, className)}
|
|
198
297
|
style={{ ...style, transform: CSS.Translate.toString(transform), transition }}
|
|
199
298
|
{...props}
|
|
200
|
-
{...
|
|
299
|
+
{...getRowBinding(binding)}
|
|
201
300
|
>
|
|
202
301
|
{children}
|
|
203
302
|
</li>
|
|
204
|
-
</
|
|
303
|
+
</SortableItemContext.Provider>
|
|
205
304
|
);
|
|
206
305
|
}
|
|
207
306
|
|
|
307
|
+
function useSortableItemBinding(part: string): SortableItemBinding {
|
|
308
|
+
const binding = useContext(SortableItemContext);
|
|
309
|
+
if (!binding) throw new Error(`${part} failed: it must be rendered inside a SortableItem`);
|
|
310
|
+
return binding;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export type SortableActivatorProps = ComponentProps<typeof Slot.Root>;
|
|
314
|
+
|
|
315
|
+
// The app's own element inside a row (a button, a title) that lifts the row on a press, for a list with
|
|
316
|
+
// `dragBy="activator"`; a press elsewhere in the row does nothing. Its own click and keys keep working. In the other
|
|
317
|
+
// modes, or on a disabled row, it renders its child unchanged.
|
|
318
|
+
export function SortableActivator(props: SortableActivatorProps) {
|
|
319
|
+
const binding = useSortableItemBinding("SortableActivator");
|
|
320
|
+
const isBound = binding.dragBy === "activator" && !binding.isDisabled;
|
|
321
|
+
const pointer = isBound ? splitListeners(binding.listeners).pointer : {};
|
|
322
|
+
return <Slot.Root data-slot="sortable-activator" {...props} {...pointer} />;
|
|
323
|
+
}
|
|
324
|
+
|
|
208
325
|
export interface SortableHandleProps extends Omit<ComponentProps<typeof Button>, "children"> {
|
|
209
326
|
// The handle's accessible name.
|
|
210
327
|
readonly label?: string;
|
|
211
328
|
}
|
|
212
329
|
|
|
213
330
|
// A grip button that drags its row, for a list with `dragBy="handle"`.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const { attributes, listeners
|
|
331
|
+
// On a disabled row it is a disabled button.
|
|
332
|
+
export function SortableHandle({ label = messages.sortable.handle, className, disabled, ...props }: SortableHandleProps) {
|
|
333
|
+
const { attributes, listeners, setActivatorNodeRef, isDisabled } = useSortableItemBinding("SortableHandle");
|
|
334
|
+
const dragProps = isDisabled ? {} : { ...attributes, ...listeners };
|
|
218
335
|
return (
|
|
219
336
|
<Button
|
|
220
337
|
ref={setActivatorNodeRef}
|
|
@@ -223,9 +340,9 @@ export function SortableHandle({ label = messages.sortable.handle, className, ..
|
|
|
223
340
|
size="icon-sm"
|
|
224
341
|
data-slot="sortable-handle"
|
|
225
342
|
className={cn("cursor-grab touch-none text-muted-foreground active:cursor-grabbing", className)}
|
|
343
|
+
disabled={isDisabled || disabled}
|
|
226
344
|
{...props}
|
|
227
|
-
{...
|
|
228
|
-
{...listeners}
|
|
345
|
+
{...dragProps}
|
|
229
346
|
role="button"
|
|
230
347
|
aria-label={label}
|
|
231
348
|
>
|