@dxos/react-list 0.1.50 → 0.1.51-main.04d9478
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/dist/lib/browser/index.mjs +26 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +24 -11
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/List.d.ts +28 -19
- package/dist/types/src/List.d.ts.map +1 -1
- package/dist/types/src/ListItem.d.ts +1 -1
- package/dist/types/src/ListItem.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/List.tsx +60 -22
- package/src/ListItem.tsx +6 -5
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// packages/ui/primitives/react-list/src/List.tsx
|
|
2
2
|
import { DndContext } from "@dnd-kit/core";
|
|
3
3
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
4
|
-
import { SortableContext, arrayMove } from "@dnd-kit/sortable";
|
|
4
|
+
import { SortableContext, arrayMove, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
5
5
|
import { createContextScope } from "@radix-ui/react-context";
|
|
6
6
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
7
|
-
import
|
|
8
|
-
import React, { forwardRef } from "react";
|
|
7
|
+
import React, { forwardRef, useCallback, useState } from "react";
|
|
9
8
|
function _extends() {
|
|
10
9
|
_extends = Object.assign || function(target) {
|
|
11
10
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -23,26 +22,39 @@ function _extends() {
|
|
|
23
22
|
var LIST_NAME = "List";
|
|
24
23
|
var [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
25
24
|
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
25
|
+
var isOrderedDraggable = (props) => props.variant === "ordered-draggable";
|
|
26
26
|
var List = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
27
|
-
const { __listScope, variant = "ordered", selectable = false,
|
|
27
|
+
const { __listScope, variant = "ordered", selectable = false, onDragEnd, onDragOver, listItemIds, itemSizes, children, ...rootProps } = props;
|
|
28
28
|
const ListRoot = variant === "ordered" || variant === "ordered-draggable" ? Primitive.ol : Primitive.ul;
|
|
29
|
+
const [draggingId, setDraggingId] = useState(void 0);
|
|
30
|
+
const onDragStart = useCallback((event) => setDraggingId(event.active.id), []);
|
|
31
|
+
const composedOnDragEnd = useCallback((event) => {
|
|
32
|
+
setDraggingId(void 0);
|
|
33
|
+
onDragEnd == null ? void 0 : onDragEnd(event);
|
|
34
|
+
}, [
|
|
35
|
+
onDragEnd
|
|
36
|
+
]);
|
|
29
37
|
return /* @__PURE__ */ React.createElement(ListRoot, _extends({}, selectable && {
|
|
30
38
|
role: "listbox",
|
|
31
39
|
"aria-multiselectable": true
|
|
32
|
-
},
|
|
40
|
+
}, rootProps, {
|
|
33
41
|
ref: forwardedRef
|
|
34
42
|
}), /* @__PURE__ */ React.createElement(ListProvider, _extends({}, {
|
|
35
43
|
scope: __listScope,
|
|
36
44
|
variant,
|
|
37
45
|
selectable,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
draggingId,
|
|
47
|
+
itemSizes
|
|
48
|
+
}), isOrderedDraggable(props) ? /* @__PURE__ */ React.createElement(DndContext, {
|
|
49
|
+
onDragEnd: composedOnDragEnd,
|
|
50
|
+
onDragOver,
|
|
51
|
+
onDragStart,
|
|
41
52
|
modifiers: [
|
|
42
53
|
restrictToVerticalAxis
|
|
43
54
|
]
|
|
44
55
|
}, /* @__PURE__ */ React.createElement(SortableContext, {
|
|
45
|
-
items:
|
|
56
|
+
items: listItemIds,
|
|
57
|
+
strategy: verticalListSortingStrategy
|
|
46
58
|
}, children)) : /* @__PURE__ */ React.createElement(React.Fragment, null, children)));
|
|
47
59
|
});
|
|
48
60
|
List.displayName = LIST_NAME;
|
|
@@ -92,7 +104,7 @@ var ListItemDragHandle = /* @__PURE__ */ forwardRef2(({ __listItemScope, childre
|
|
|
92
104
|
});
|
|
93
105
|
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
94
106
|
var ListItemCollapsibleContent = Collapsible.Content;
|
|
95
|
-
var
|
|
107
|
+
var ListItemImpl = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
96
108
|
const { __listScope, __listItemScope, children, selected: propsSelected, defaultSelected, onSelectedChange, open: propsOpen, defaultOpen, onOpenChange, collapsible, id, draggableAttributes, draggableListeners, ...listItemProps } = props;
|
|
97
109
|
const { selectable } = useListContext(LIST_NAME, __listScope);
|
|
98
110
|
const [selected = false, setSelected] = useControllableState({
|
|
@@ -133,11 +145,12 @@ var DraggableListItem = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
|
133
145
|
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
134
146
|
id: props.id
|
|
135
147
|
});
|
|
148
|
+
const { itemSizes } = useListContext(LIST_NAME, props.__listScope);
|
|
136
149
|
const ref = useComposedRefs(forwardedRef, setNodeRef);
|
|
137
|
-
return /* @__PURE__ */ React2.createElement(
|
|
150
|
+
return /* @__PURE__ */ React2.createElement(ListItemImpl, _extends2({}, props, {
|
|
138
151
|
style: {
|
|
139
152
|
...props.style,
|
|
140
|
-
transform: CSS
|
|
153
|
+
transform: CSS[itemSizes === "one" ? "Transform" : "Translate"].toString(transform),
|
|
141
154
|
transition
|
|
142
155
|
},
|
|
143
156
|
ref
|
|
@@ -155,7 +168,7 @@ var ListItem = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
|
155
168
|
id: listItemId
|
|
156
169
|
}));
|
|
157
170
|
} else {
|
|
158
|
-
return /* @__PURE__ */ React2.createElement(
|
|
171
|
+
return /* @__PURE__ */ React2.createElement(ListItemImpl, _extends2({}, props, {
|
|
159
172
|
ref: forwardedRef,
|
|
160
173
|
id: listItemId
|
|
161
174
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { DndContext, DragEndEvent } from '@dnd-kit/core';\nimport { restrictToVerticalAxis } from '@dnd-kit/modifiers';\nimport { SortableContext, arrayMove } from '@dnd-kit/sortable';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport omit from 'lodash.omit';\nimport React, { ComponentPropsWithRef, forwardRef, ReactHTMLElement } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';\n\ntype SharedListProps = {\n selectable?: boolean;\n variant?: ListVariant;\n onDragEnd?: (event: DragEndEvent) => void;\n listItemIds?: string[];\n toggleOpenLabel?: string | Omit<ReactHTMLElement<HTMLElement>, 'ref'>;\n};\n\ntype DraggableListProps = Omit<SharedListProps, 'slots'> & {\n onDragEnd: Exclude<SharedListProps['onDragEnd'], undefined>;\n listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;\n variant: 'ordered-draggable';\n};\n\ntype ListProps =\n | (Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd'> & SharedListProps)\n | (Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd'> & DraggableListProps);\n\n// LIST\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = Pick<ListProps, 'selectable' | 'variant' | 'toggleOpenLabel'>;\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n toggleOpenLabel = 'Expand/collapse item',\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' || variant === 'ordered-draggable' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot\n {...(selectable && { role: 'listbox', 'aria-multiselectable': true })}\n {...omit(rootProps, 'onDragEnd', 'listItemIds')}\n ref={forwardedRef}\n >\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n toggleOpenLabel,\n }}\n >\n {variant === 'ordered-draggable' ? (\n <DndContext onDragEnd={(props as DraggableListProps).onDragEnd} modifiers={[restrictToVerticalAxis]}>\n <SortableContext items={(props as DraggableListProps).listItemIds}>{children}</SortableContext>\n </DndContext>\n ) : (\n <>{children}</>\n )}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, createListScope, useListContext, LIST_NAME, arrayMove };\n\nexport type { ListProps, ListVariant, ListScopedProps, DragEndEvent };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DraggableAttributes } from '@dnd-kit/core';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.li>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype DraggableListItemContextValue = {\n draggableAttributes: DraggableAttributes;\n draggableListeners: ReturnType<typeof useSortable>['listeners'];\n};\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n} & Partial<DraggableListItemContextValue>;\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\n );\n },\n);\n\ntype ListItemDragHandleProps = ComponentPropsWithRef<typeof Primitive.div>;\n\nconst ListItemDragHandle = forwardRef<HTMLDivElement, ListItemScopedProps<ListItemDragHandleProps>>(\n ({ __listItemScope, children, ...props }, forwardedRef) => {\n const { draggableAttributes, draggableListeners } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n return (\n <div role='button' ref={forwardedRef} {...props} {...draggableAttributes} {...draggableListeners}>\n {children}\n </div>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst PureListItem = forwardRef<\n ListItemElement,\n ListItemProps & { id: string } & Partial<DraggableListItemContextValue>\n>(\n (\n props: ListItemScopedProps<\n ListScopedProps<ListItemProps & { id: string } & Partial<DraggableListItemContextValue>>\n >,\n forwardedRef,\n ) => {\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n id,\n draggableAttributes,\n draggableListeners,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading');\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { role: 'option', 'aria-selected': !!selected })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n {...{ draggableAttributes, draggableListeners }}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nconst DraggableListItem = forwardRef<ListItemElement, ListItemProps & { id: string }>(\n (props: ListItemScopedProps<ListItemProps & { id: string }>, forwardedRef) => {\n const { attributes, listeners, setNodeRef, transform, transition } = useSortable({\n id: props.id,\n });\n const ref = useComposedRefs(forwardedRef, setNodeRef) as ComponentPropsWithRef<typeof Primitive.li>['ref'];\n\n return (\n <PureListItem\n {...props}\n style={{\n ...props.style,\n transform: CSS.Transform.toString(transform),\n transition,\n }}\n ref={ref}\n {...{\n draggableAttributes: attributes,\n draggableListeners: listeners,\n }}\n />\n );\n },\n);\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>((props: ListScopedProps<ListItemProps>, forwardedRef) => {\n const { variant } = useListContext(LIST_NAME, props.__listScope);\n const listItemId = useId('listItem', props.id);\n\n if (variant === 'ordered-draggable') {\n return <DraggableListItem {...props} ref={forwardedRef} id={listItemId} />;\n } else {\n return <PureListItem {...props} ref={forwardedRef} id={listItemId} />;\n }\n});\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemDragHandle,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemDragHandleProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,
|
|
6
|
-
"names": ["DndContext", "restrictToVerticalAxis", "SortableContext", "arrayMove", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { DndContext, DragEndEvent, DragStartEvent, DragOverEvent } from '@dnd-kit/core';\nimport { restrictToVerticalAxis } from '@dnd-kit/modifiers';\nimport { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { ComponentPropsWithRef, forwardRef, useCallback, useState } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';\n\ntype ListItemSizes = 'one' | 'many';\n\ntype SharedListProps = {\n selectable?: boolean;\n variant?: ListVariant;\n listItemIds?: string[];\n onDragEnd?: (event: DragEndEvent) => void;\n onDragOver?: (event: DragOverEvent) => void;\n itemSizes?: ListItemSizes;\n};\n\ntype SharedDraggableListProps = SharedListProps & {\n listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;\n variant: 'ordered-draggable';\n};\n\ntype HeterogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {\n itemSizes?: 'many';\n};\n\ntype HomogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {\n itemSizes: 'one';\n};\n\ntype BaseListProps = Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd' | 'onDragOver'>;\n\ntype ListProps =\n | (BaseListProps & SharedListProps)\n | (BaseListProps & HomogeneousDraggableListProps)\n | (BaseListProps & HeterogeneousDraggableListProps);\n\n// LIST\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = Pick<ListProps, 'selectable' | 'variant'> & {\n draggingId?: string;\n itemSizes?: ListItemSizes;\n};\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst isOrderedDraggable = (props: ListProps): props is SharedDraggableListProps =>\n props.variant === 'ordered-draggable';\nconst _isOrderedDraggableHomogeneous = (props: ListProps): props is HomogeneousDraggableListProps =>\n isOrderedDraggable(props) && props.itemSizes === 'one';\nconst _isOrderedDraggableHeterogeneous = (props: ListProps): props is HeterogeneousDraggableListProps =>\n isOrderedDraggable(props) && props.itemSizes !== 'one';\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n onDragEnd,\n onDragOver,\n listItemIds,\n itemSizes,\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' || variant === 'ordered-draggable' ? Primitive.ol : Primitive.ul;\n const [draggingId, setDraggingId] = useState<string | undefined>(undefined);\n const onDragStart = useCallback((event: DragStartEvent) => setDraggingId(event.active.id as string), []);\n const composedOnDragEnd = useCallback(\n (event: DragEndEvent) => {\n setDraggingId(undefined);\n onDragEnd?.(event);\n },\n [onDragEnd],\n );\n return (\n <ListRoot {...(selectable && { role: 'listbox', 'aria-multiselectable': true })} {...rootProps} ref={forwardedRef}>\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n draggingId,\n itemSizes,\n }}\n >\n {isOrderedDraggable(props) ? (\n <DndContext\n onDragEnd={composedOnDragEnd}\n onDragOver={onDragOver}\n onDragStart={onDragStart}\n modifiers={[restrictToVerticalAxis]}\n >\n <SortableContext items={listItemIds!} strategy={verticalListSortingStrategy}>\n {children}\n </SortableContext>\n </DndContext>\n ) : (\n <>{children}</>\n )}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, createListScope, useListContext, LIST_NAME, arrayMove };\n\nexport type { ListProps, ListVariant, ListScopedProps, DragEndEvent, DragOverEvent };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DraggableAttributes } from '@dnd-kit/core';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.li>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype DraggableListItemContextValue = {\n draggableAttributes: DraggableAttributes;\n draggableListeners: ReturnType<typeof useSortable>['listeners'];\n};\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n} & Partial<DraggableListItemContextValue>;\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\n );\n },\n);\n\ntype ListItemDragHandleProps = ComponentPropsWithRef<typeof Primitive.div>;\n\nconst ListItemDragHandle = forwardRef<HTMLDivElement, ListItemScopedProps<ListItemDragHandleProps>>(\n ({ __listItemScope, children, ...props }, forwardedRef) => {\n const { draggableAttributes, draggableListeners } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n return (\n <div role='button' ref={forwardedRef} {...props} {...draggableAttributes} {...draggableListeners}>\n {children}\n </div>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst ListItemImpl = forwardRef<\n ListItemElement,\n ListItemProps & { id: string } & Partial<DraggableListItemContextValue>\n>(\n (\n props: ListItemScopedProps<\n ListScopedProps<ListItemProps & { id: string } & Partial<DraggableListItemContextValue>>\n >,\n forwardedRef,\n ) => {\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n id,\n draggableAttributes,\n draggableListeners,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading');\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { role: 'option', 'aria-selected': !!selected })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n {...{ draggableAttributes, draggableListeners }}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nconst DraggableListItem = forwardRef<ListItemElement, ListItemProps & { id: string }>(\n (props: ListItemScopedProps<ListScopedProps<ListItemProps & { id: string }>>, forwardedRef) => {\n const { attributes, listeners, setNodeRef, transform, transition } = useSortable({\n id: props.id,\n });\n const { itemSizes } = useListContext(LIST_NAME, props.__listScope);\n const ref = useComposedRefs(forwardedRef, setNodeRef) as ComponentPropsWithRef<typeof Primitive.li>['ref'];\n\n return (\n <ListItemImpl\n {...props}\n style={{\n ...props.style,\n transform: CSS[itemSizes === 'one' ? 'Transform' : 'Translate'].toString(transform),\n transition,\n }}\n ref={ref}\n {...{\n draggableAttributes: attributes,\n draggableListeners: listeners,\n }}\n />\n );\n },\n);\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>((props: ListScopedProps<ListItemProps>, forwardedRef) => {\n const { variant } = useListContext(LIST_NAME, props.__listScope);\n const listItemId = useId('listItem', props.id);\n\n if (variant === 'ordered-draggable') {\n return <DraggableListItem {...props} ref={forwardedRef} id={listItemId} />;\n } else {\n return <ListItemImpl {...props} ref={forwardedRef} id={listItemId} />;\n }\n});\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemDragHandle,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemDragHandleProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,kBAA+D;AACxE,SAASC,8BAA8B;AACvC,SAASC,iBAAiBC,WAAWC,mCAAmC;AACxE,SAASC,0BAAiC;AAC1C,SAASC,iBAAiB;AAC1B,OAAOC,SAAgCC,YAAYC,aAAaC,gBAAgB;AALhF,SAAA,WAAA;;;;;;;;;;;;;;AASA,IAAMC,YAAY;AAuClB,IAAM,CAACC,mBAAmBC,eAAAA,IAAmBR,mBAAmBM,WAAW,CAAA,CAAE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AAGF,IAAMU,WAAW7D,gBAAAA,YAA2C,CAACI,OAAuCC,iBAAiB;AACnH,QAAM,EAAEyD,QAAO,IAAK1B,eAAeC,WAAWjC,MAAMoB,WAAW;AAC/D,QAAMuC,aAAanB,MAAM,YAAYxC,MAAMQ,EAAE;AAE7C,MAAIkD,YAAY,qBAAqB;AACnC,WAAO,gBAAAnD,OAAA,cAACsC,mBAAAA,UAAAA,CAAAA,GAAsB7C,OAAAA;MAAOS,KAAKR;MAAcO,IAAImD;;EAC9D,OAAO;AACL,WAAO,gBAAApD,OAAA,cAACY,cAAAA,UAAAA,CAAAA,GAAiBnB,OAAAA;MAAOS,KAAKR;MAAcO,IAAImD;;EACzD;AACF,CAAA;AAEAF,SAASG,cAAcvE;",
|
|
6
|
+
"names": ["DndContext", "restrictToVerticalAxis", "SortableContext", "arrayMove", "verticalListSortingStrategy", "createContextScope", "Primitive", "React", "forwardRef", "useCallback", "useState", "LIST_NAME", "createListContext", "createListScope", "ListProvider", "useListContext", "isOrderedDraggable", "props", "variant", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "onDragEnd", "onDragOver", "listItemIds", "itemSizes", "children", "rootProps", "ListRoot", "Primitive", "ol", "ul", "draggingId", "setDraggingId", "useState", "undefined", "onDragStart", "useCallback", "event", "active", "id", "composedOnDragEnd", "role", "ref", "ListProvider", "scope", "isOrderedDraggable", "DndContext", "modifiers", "restrictToVerticalAxis", "SortableContext", "items", "strategy", "verticalListSortingStrategy", "displayName", "LIST_NAME", "useSortable", "CSS", "Collapsible", "useComposedRefs", "createContextScope", "Primitive", "Slot", "useControllableState", "React", "forwardRef", "useId", "_extends", "LIST_ITEM_NAME", "createListItemContext", "createListItemScope", "createContextScope", "ListItemProvider", "useListItemContext", "ListItemHeading", "forwardRef", "children", "asChild", "__listItemScope", "props", "forwardedRef", "headingId", "Root", "Slot", "Primitive", "p", "React", "id", "ref", "ListItemDragHandle", "draggableAttributes", "draggableListeners", "div", "role", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItemImpl", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "useId", "listItem", "li", "aria-labelledby", "scope", "DraggableListItem", "attributes", "listeners", "setNodeRef", "transform", "transition", "useSortable", "itemSizes", "useComposedRefs", "style", "CSS", "toString", "ListItem", "variant", "listItemId", "displayName"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":11866,"imports":[{"path":"@dnd-kit/core","kind":"import-statement","external":true},{"path":"@dnd-kit/modifiers","kind":"import-statement","external":true},{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}]},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytes":20114,"imports":[{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@dnd-kit/utilities","kind":"import-statement","external":true},{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"}]},"packages/ui/primitives/react-list/src/index.ts":{"bytes":456,"imports":[{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"},{"path":"packages/ui/primitives/react-list/src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}]}},"outputs":{"packages/ui/primitives/react-list/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17714},"packages/ui/primitives/react-list/dist/lib/browser/index.mjs":{"imports":[{"path":"@dnd-kit/core","kind":"import-statement","external":true},{"path":"@dnd-kit/modifiers","kind":"import-statement","external":true},{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@dnd-kit/utilities","kind":"import-statement","external":true},{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true}],"exports":["LIST_ITEM_NAME","LIST_NAME","List","ListItem","ListItemCollapsibleContent","ListItemDragHandle","ListItemHeading","ListItemOpenTrigger","arrayMove","createListItemScope","createListScope","useListContext","useListItemContext"],"entryPoint":"packages/ui/primitives/react-list/src/index.ts","inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytesInOutput":2401},"packages/ui/primitives/react-list/src/index.ts":{"bytesInOutput":0},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytesInOutput":4645}},"bytes":7437}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -52,7 +52,6 @@ var import_modifiers = require("@dnd-kit/modifiers");
|
|
|
52
52
|
var import_sortable = require("@dnd-kit/sortable");
|
|
53
53
|
var import_react_context = require("@radix-ui/react-context");
|
|
54
54
|
var import_react_primitive = require("@radix-ui/react-primitive");
|
|
55
|
-
var import_lodash = __toESM(require("lodash.omit"));
|
|
56
55
|
var import_react = __toESM(require("react"));
|
|
57
56
|
function _extends() {
|
|
58
57
|
_extends = Object.assign || function(target) {
|
|
@@ -71,26 +70,39 @@ function _extends() {
|
|
|
71
70
|
var LIST_NAME = "List";
|
|
72
71
|
var [createListContext, createListScope] = (0, import_react_context.createContextScope)(LIST_NAME, []);
|
|
73
72
|
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
73
|
+
var isOrderedDraggable = (props) => props.variant === "ordered-draggable";
|
|
74
74
|
var List = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
75
|
-
const { __listScope, variant = "ordered", selectable = false,
|
|
75
|
+
const { __listScope, variant = "ordered", selectable = false, onDragEnd, onDragOver, listItemIds, itemSizes, children, ...rootProps } = props;
|
|
76
76
|
const ListRoot = variant === "ordered" || variant === "ordered-draggable" ? import_react_primitive.Primitive.ol : import_react_primitive.Primitive.ul;
|
|
77
|
+
const [draggingId, setDraggingId] = (0, import_react.useState)(void 0);
|
|
78
|
+
const onDragStart = (0, import_react.useCallback)((event) => setDraggingId(event.active.id), []);
|
|
79
|
+
const composedOnDragEnd = (0, import_react.useCallback)((event) => {
|
|
80
|
+
setDraggingId(void 0);
|
|
81
|
+
onDragEnd == null ? void 0 : onDragEnd(event);
|
|
82
|
+
}, [
|
|
83
|
+
onDragEnd
|
|
84
|
+
]);
|
|
77
85
|
return /* @__PURE__ */ import_react.default.createElement(ListRoot, _extends({}, selectable && {
|
|
78
86
|
role: "listbox",
|
|
79
87
|
"aria-multiselectable": true
|
|
80
|
-
},
|
|
88
|
+
}, rootProps, {
|
|
81
89
|
ref: forwardedRef
|
|
82
90
|
}), /* @__PURE__ */ import_react.default.createElement(ListProvider, _extends({}, {
|
|
83
91
|
scope: __listScope,
|
|
84
92
|
variant,
|
|
85
93
|
selectable,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
draggingId,
|
|
95
|
+
itemSizes
|
|
96
|
+
}), isOrderedDraggable(props) ? /* @__PURE__ */ import_react.default.createElement(import_core.DndContext, {
|
|
97
|
+
onDragEnd: composedOnDragEnd,
|
|
98
|
+
onDragOver,
|
|
99
|
+
onDragStart,
|
|
89
100
|
modifiers: [
|
|
90
101
|
import_modifiers.restrictToVerticalAxis
|
|
91
102
|
]
|
|
92
103
|
}, /* @__PURE__ */ import_react.default.createElement(import_sortable.SortableContext, {
|
|
93
|
-
items:
|
|
104
|
+
items: listItemIds,
|
|
105
|
+
strategy: import_sortable.verticalListSortingStrategy
|
|
94
106
|
}, children)) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children)));
|
|
95
107
|
});
|
|
96
108
|
List.displayName = LIST_NAME;
|
|
@@ -140,7 +152,7 @@ var ListItemDragHandle = /* @__PURE__ */ (0, import_react2.forwardRef)(({ __list
|
|
|
140
152
|
});
|
|
141
153
|
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
142
154
|
var ListItemCollapsibleContent = Collapsible.Content;
|
|
143
|
-
var
|
|
155
|
+
var ListItemImpl = /* @__PURE__ */ (0, import_react2.forwardRef)((props, forwardedRef) => {
|
|
144
156
|
const { __listScope, __listItemScope, children, selected: propsSelected, defaultSelected, onSelectedChange, open: propsOpen, defaultOpen, onOpenChange, collapsible, id, draggableAttributes, draggableListeners, ...listItemProps } = props;
|
|
145
157
|
const { selectable } = useListContext(LIST_NAME, __listScope);
|
|
146
158
|
const [selected = false, setSelected] = (0, import_react_use_controllable_state.useControllableState)({
|
|
@@ -181,11 +193,12 @@ var DraggableListItem = /* @__PURE__ */ (0, import_react2.forwardRef)((props, fo
|
|
|
181
193
|
const { attributes, listeners, setNodeRef, transform, transition } = (0, import_sortable2.useSortable)({
|
|
182
194
|
id: props.id
|
|
183
195
|
});
|
|
196
|
+
const { itemSizes } = useListContext(LIST_NAME, props.__listScope);
|
|
184
197
|
const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, setNodeRef);
|
|
185
|
-
return /* @__PURE__ */ import_react2.default.createElement(
|
|
198
|
+
return /* @__PURE__ */ import_react2.default.createElement(ListItemImpl, _extends2({}, props, {
|
|
186
199
|
style: {
|
|
187
200
|
...props.style,
|
|
188
|
-
transform: import_utilities.CSS
|
|
201
|
+
transform: import_utilities.CSS[itemSizes === "one" ? "Transform" : "Translate"].toString(transform),
|
|
189
202
|
transition
|
|
190
203
|
},
|
|
191
204
|
ref
|
|
@@ -203,7 +216,7 @@ var ListItem = /* @__PURE__ */ (0, import_react2.forwardRef)((props, forwardedRe
|
|
|
203
216
|
id: listItemId
|
|
204
217
|
}));
|
|
205
218
|
} else {
|
|
206
|
-
return /* @__PURE__ */ import_react2.default.createElement(
|
|
219
|
+
return /* @__PURE__ */ import_react2.default.createElement(ListItemImpl, _extends2({}, props, {
|
|
207
220
|
ref: forwardedRef,
|
|
208
221
|
id: listItemId
|
|
209
222
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport * from './List';\nexport * from './ListItem';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DndContext, DragEndEvent } from '@dnd-kit/core';\nimport { restrictToVerticalAxis } from '@dnd-kit/modifiers';\nimport { SortableContext, arrayMove } from '@dnd-kit/sortable';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport omit from 'lodash.omit';\nimport React, { ComponentPropsWithRef, forwardRef, ReactHTMLElement } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';\n\ntype SharedListProps = {\n selectable?: boolean;\n variant?: ListVariant;\n onDragEnd?: (event: DragEndEvent) => void;\n listItemIds?: string[];\n toggleOpenLabel?: string | Omit<ReactHTMLElement<HTMLElement>, 'ref'>;\n};\n\ntype DraggableListProps = Omit<SharedListProps, 'slots'> & {\n onDragEnd: Exclude<SharedListProps['onDragEnd'], undefined>;\n listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;\n variant: 'ordered-draggable';\n};\n\ntype ListProps =\n | (Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd'> & SharedListProps)\n | (Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd'> & DraggableListProps);\n\n// LIST\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = Pick<ListProps, 'selectable' | 'variant' | 'toggleOpenLabel'>;\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n toggleOpenLabel = 'Expand/collapse item',\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' || variant === 'ordered-draggable' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot\n {...(selectable && { role: 'listbox', 'aria-multiselectable': true })}\n {...omit(rootProps, 'onDragEnd', 'listItemIds')}\n ref={forwardedRef}\n >\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n toggleOpenLabel,\n }}\n >\n {variant === 'ordered-draggable' ? (\n <DndContext onDragEnd={(props as DraggableListProps).onDragEnd} modifiers={[restrictToVerticalAxis]}>\n <SortableContext items={(props as DraggableListProps).listItemIds}>{children}</SortableContext>\n </DndContext>\n ) : (\n <>{children}</>\n )}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, createListScope, useListContext, LIST_NAME, arrayMove };\n\nexport type { ListProps, ListVariant, ListScopedProps, DragEndEvent };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DraggableAttributes } from '@dnd-kit/core';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.li>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype DraggableListItemContextValue = {\n draggableAttributes: DraggableAttributes;\n draggableListeners: ReturnType<typeof useSortable>['listeners'];\n};\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n} & Partial<DraggableListItemContextValue>;\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\n );\n },\n);\n\ntype ListItemDragHandleProps = ComponentPropsWithRef<typeof Primitive.div>;\n\nconst ListItemDragHandle = forwardRef<HTMLDivElement, ListItemScopedProps<ListItemDragHandleProps>>(\n ({ __listItemScope, children, ...props }, forwardedRef) => {\n const { draggableAttributes, draggableListeners } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n return (\n <div role='button' ref={forwardedRef} {...props} {...draggableAttributes} {...draggableListeners}>\n {children}\n </div>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst PureListItem = forwardRef<\n ListItemElement,\n ListItemProps & { id: string } & Partial<DraggableListItemContextValue>\n>(\n (\n props: ListItemScopedProps<\n ListScopedProps<ListItemProps & { id: string } & Partial<DraggableListItemContextValue>>\n >,\n forwardedRef,\n ) => {\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n id,\n draggableAttributes,\n draggableListeners,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading');\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { role: 'option', 'aria-selected': !!selected })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n {...{ draggableAttributes, draggableListeners }}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nconst DraggableListItem = forwardRef<ListItemElement, ListItemProps & { id: string }>(\n (props: ListItemScopedProps<ListItemProps & { id: string }>, forwardedRef) => {\n const { attributes, listeners, setNodeRef, transform, transition } = useSortable({\n id: props.id,\n });\n const ref = useComposedRefs(forwardedRef, setNodeRef) as ComponentPropsWithRef<typeof Primitive.li>['ref'];\n\n return (\n <PureListItem\n {...props}\n style={{\n ...props.style,\n transform: CSS.Transform.toString(transform),\n transition,\n }}\n ref={ref}\n {...{\n draggableAttributes: attributes,\n draggableListeners: listeners,\n }}\n />\n );\n },\n);\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>((props: ListScopedProps<ListItemProps>, forwardedRef) => {\n const { variant } = useListContext(LIST_NAME, props.__listScope);\n const listItemId = useId('listItem', props.id);\n\n if (variant === 'ordered-draggable') {\n return <DraggableListItem {...props} ref={forwardedRef} id={listItemId} />;\n } else {\n return <PureListItem {...props} ref={forwardedRef} id={listItemId} />;\n }\n});\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemDragHandle,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemDragHandleProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;ACIA,
|
|
6
|
-
"names": ["LIST_NAME", "createListContext", "createListScope", "createContextScope", "ListProvider", "useListContext", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport * from './List';\nexport * from './ListItem';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DndContext, DragEndEvent, DragStartEvent, DragOverEvent } from '@dnd-kit/core';\nimport { restrictToVerticalAxis } from '@dnd-kit/modifiers';\nimport { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { ComponentPropsWithRef, forwardRef, useCallback, useState } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';\n\ntype ListItemSizes = 'one' | 'many';\n\ntype SharedListProps = {\n selectable?: boolean;\n variant?: ListVariant;\n listItemIds?: string[];\n onDragEnd?: (event: DragEndEvent) => void;\n onDragOver?: (event: DragOverEvent) => void;\n itemSizes?: ListItemSizes;\n};\n\ntype SharedDraggableListProps = SharedListProps & {\n listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;\n variant: 'ordered-draggable';\n};\n\ntype HeterogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {\n itemSizes?: 'many';\n};\n\ntype HomogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {\n itemSizes: 'one';\n};\n\ntype BaseListProps = Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd' | 'onDragOver'>;\n\ntype ListProps =\n | (BaseListProps & SharedListProps)\n | (BaseListProps & HomogeneousDraggableListProps)\n | (BaseListProps & HeterogeneousDraggableListProps);\n\n// LIST\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = Pick<ListProps, 'selectable' | 'variant'> & {\n draggingId?: string;\n itemSizes?: ListItemSizes;\n};\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst isOrderedDraggable = (props: ListProps): props is SharedDraggableListProps =>\n props.variant === 'ordered-draggable';\nconst _isOrderedDraggableHomogeneous = (props: ListProps): props is HomogeneousDraggableListProps =>\n isOrderedDraggable(props) && props.itemSizes === 'one';\nconst _isOrderedDraggableHeterogeneous = (props: ListProps): props is HeterogeneousDraggableListProps =>\n isOrderedDraggable(props) && props.itemSizes !== 'one';\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n onDragEnd,\n onDragOver,\n listItemIds,\n itemSizes,\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' || variant === 'ordered-draggable' ? Primitive.ol : Primitive.ul;\n const [draggingId, setDraggingId] = useState<string | undefined>(undefined);\n const onDragStart = useCallback((event: DragStartEvent) => setDraggingId(event.active.id as string), []);\n const composedOnDragEnd = useCallback(\n (event: DragEndEvent) => {\n setDraggingId(undefined);\n onDragEnd?.(event);\n },\n [onDragEnd],\n );\n return (\n <ListRoot {...(selectable && { role: 'listbox', 'aria-multiselectable': true })} {...rootProps} ref={forwardedRef}>\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n draggingId,\n itemSizes,\n }}\n >\n {isOrderedDraggable(props) ? (\n <DndContext\n onDragEnd={composedOnDragEnd}\n onDragOver={onDragOver}\n onDragStart={onDragStart}\n modifiers={[restrictToVerticalAxis]}\n >\n <SortableContext items={listItemIds!} strategy={verticalListSortingStrategy}>\n {children}\n </SortableContext>\n </DndContext>\n ) : (\n <>{children}</>\n )}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, createListScope, useListContext, LIST_NAME, arrayMove };\n\nexport type { ListProps, ListVariant, ListScopedProps, DragEndEvent, DragOverEvent };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DraggableAttributes } from '@dnd-kit/core';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.li>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype DraggableListItemContextValue = {\n draggableAttributes: DraggableAttributes;\n draggableListeners: ReturnType<typeof useSortable>['listeners'];\n};\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n} & Partial<DraggableListItemContextValue>;\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\n );\n },\n);\n\ntype ListItemDragHandleProps = ComponentPropsWithRef<typeof Primitive.div>;\n\nconst ListItemDragHandle = forwardRef<HTMLDivElement, ListItemScopedProps<ListItemDragHandleProps>>(\n ({ __listItemScope, children, ...props }, forwardedRef) => {\n const { draggableAttributes, draggableListeners } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n return (\n <div role='button' ref={forwardedRef} {...props} {...draggableAttributes} {...draggableListeners}>\n {children}\n </div>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst ListItemImpl = forwardRef<\n ListItemElement,\n ListItemProps & { id: string } & Partial<DraggableListItemContextValue>\n>(\n (\n props: ListItemScopedProps<\n ListScopedProps<ListItemProps & { id: string } & Partial<DraggableListItemContextValue>>\n >,\n forwardedRef,\n ) => {\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n id,\n draggableAttributes,\n draggableListeners,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading');\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { role: 'option', 'aria-selected': !!selected })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n {...{ draggableAttributes, draggableListeners }}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nconst DraggableListItem = forwardRef<ListItemElement, ListItemProps & { id: string }>(\n (props: ListItemScopedProps<ListScopedProps<ListItemProps & { id: string }>>, forwardedRef) => {\n const { attributes, listeners, setNodeRef, transform, transition } = useSortable({\n id: props.id,\n });\n const { itemSizes } = useListContext(LIST_NAME, props.__listScope);\n const ref = useComposedRefs(forwardedRef, setNodeRef) as ComponentPropsWithRef<typeof Primitive.li>['ref'];\n\n return (\n <ListItemImpl\n {...props}\n style={{\n ...props.style,\n transform: CSS[itemSizes === 'one' ? 'Transform' : 'Translate'].toString(transform),\n transition,\n }}\n ref={ref}\n {...{\n draggableAttributes: attributes,\n draggableListeners: listeners,\n }}\n />\n );\n },\n);\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>((props: ListScopedProps<ListItemProps>, forwardedRef) => {\n const { variant } = useListContext(LIST_NAME, props.__listScope);\n const listItemId = useId('listItem', props.id);\n\n if (variant === 'ordered-draggable') {\n return <DraggableListItem {...props} ref={forwardedRef} id={listItemId} />;\n } else {\n return <ListItemImpl {...props} ref={forwardedRef} id={listItemId} />;\n }\n});\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemDragHandle,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemDragHandleProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;ACIA,kBAAwE;AACxE,uBAAuC;AACvC,sBAAwE;AACxE,2BAA0C;AAC1C,6BAA0B;AAC1B,mBAAgF;AALhF,SAAA,WAAA;;;;;;;;;;;;;;AASA,IAAMA,YAAY;AAuClB,IAAM,CAACC,mBAAmBC,eAAAA,QAAmBC,yCAAmBH,WAAW,CAAA,CAAE;AAO7E,IAAM,CAACI,cAAcC,cAAAA,IAAkBJ,kBAAoCD,SAAAA;AAE3E,IAAMM,qBAAqB,CAACC,UAC1BA,MAAMC,YAAY;AAMpB,IAAMC,OAAOC,6CAAwC,CAACC,OAAmCC,iBAAiB;AACxG,QAAM,EACJC,aACAC,UAAU,WACVC,aAAa,OACbC,WACAC,YACAC,aACAC,WACAC,UACA,GAAGC,UAAAA,IACDV;AACJ,QAAMW,WAAWR,YAAY,aAAaA,YAAY,sBAAsBS,iCAAUC,KAAKD,iCAAUE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AA,UAAAA,CAAAA,GAAiBnB,OAAAA;MAAOS,KAAKR;MAAcO,IAAImD;;EACzD;AACF,CAAA;AAEAF,SAASG,cAAcvE;",
|
|
6
|
+
"names": ["LIST_NAME", "createListContext", "createListScope", "createContextScope", "ListProvider", "useListContext", "isOrderedDraggable", "props", "variant", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "onDragEnd", "onDragOver", "listItemIds", "itemSizes", "children", "rootProps", "ListRoot", "Primitive", "ol", "ul", "draggingId", "setDraggingId", "useState", "undefined", "onDragStart", "useCallback", "event", "active", "id", "composedOnDragEnd", "React", "role", "ref", "ListProvider", "scope", "isOrderedDraggable", "DndContext", "modifiers", "restrictToVerticalAxis", "SortableContext", "items", "strategy", "verticalListSortingStrategy", "displayName", "LIST_NAME", "import_sortable", "import_react_context", "import_react_primitive", "import_react", "_extends", "LIST_ITEM_NAME", "createListItemContext", "createListItemScope", "createContextScope", "ListItemProvider", "useListItemContext", "ListItemHeading", "forwardRef", "children", "asChild", "__listItemScope", "props", "forwardedRef", "headingId", "Root", "Slot", "Primitive", "p", "React", "id", "ref", "ListItemDragHandle", "draggableAttributes", "draggableListeners", "div", "role", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItemImpl", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "useId", "listItem", "li", "aria-labelledby", "scope", "DraggableListItem", "attributes", "listeners", "setNodeRef", "transform", "transition", "useSortable", "itemSizes", "useComposedRefs", "style", "CSS", "toString", "ListItem", "variant", "listItemId", "displayName"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":11866,"imports":[{"path":"@dnd-kit/core","kind":"import-statement","external":true},{"path":"@dnd-kit/modifiers","kind":"import-statement","external":true},{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}]},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytes":20114,"imports":[{"path":"@dnd-kit/sortable","kind":"import-statement","external":true},{"path":"@dnd-kit/utilities","kind":"import-statement","external":true},{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"}]},"packages/ui/primitives/react-list/src/index.ts":{"bytes":456,"imports":[{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"},{"path":"packages/ui/primitives/react-list/src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}]}},"outputs":{"packages/ui/primitives/react-list/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17562},"packages/ui/primitives/react-list/dist/lib/node/index.cjs":{"imports":[{"path":"@dnd-kit/core","kind":"require-call","external":true},{"path":"@dnd-kit/modifiers","kind":"require-call","external":true},{"path":"@dnd-kit/sortable","kind":"require-call","external":true},{"path":"@radix-ui/react-context","kind":"require-call","external":true},{"path":"@radix-ui/react-primitive","kind":"require-call","external":true},{"path":"react","kind":"require-call","external":true},{"path":"@dnd-kit/sortable","kind":"require-call","external":true},{"path":"@dnd-kit/utilities","kind":"require-call","external":true},{"path":"@radix-ui/react-collapsible","kind":"require-call","external":true},{"path":"@radix-ui/react-compose-refs","kind":"require-call","external":true},{"path":"@radix-ui/react-context","kind":"require-call","external":true},{"path":"@radix-ui/react-primitive","kind":"require-call","external":true},{"path":"@radix-ui/react-slot","kind":"require-call","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"require-call","external":true},{"path":"react","kind":"require-call","external":true},{"path":"@dxos/react-hooks","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/ui/primitives/react-list/src/index.ts","inputs":{"packages/ui/primitives/react-list/src/index.ts":{"bytesInOutput":641},"packages/ui/primitives/react-list/src/List.tsx":{"bytesInOutput":2641},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytesInOutput":5181}},"bytes":10381}}}
|
package/dist/types/src/List.d.ts
CHANGED
|
@@ -1,42 +1,51 @@
|
|
|
1
|
-
import { DragEndEvent } from '@dnd-kit/core';
|
|
1
|
+
import { DragEndEvent, DragOverEvent } from '@dnd-kit/core';
|
|
2
2
|
import { arrayMove } from '@dnd-kit/sortable';
|
|
3
3
|
import { Scope } from '@radix-ui/react-context';
|
|
4
4
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
5
|
-
import React, { ComponentPropsWithRef
|
|
5
|
+
import React, { ComponentPropsWithRef } from 'react';
|
|
6
6
|
declare const LIST_NAME = "List";
|
|
7
7
|
type ListScopedProps<P> = P & {
|
|
8
8
|
__listScope?: Scope;
|
|
9
9
|
};
|
|
10
10
|
type ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';
|
|
11
|
+
type ListItemSizes = 'one' | 'many';
|
|
11
12
|
type SharedListProps = {
|
|
12
13
|
selectable?: boolean;
|
|
13
14
|
variant?: ListVariant;
|
|
14
|
-
onDragEnd?: (event: DragEndEvent) => void;
|
|
15
15
|
listItemIds?: string[];
|
|
16
|
-
|
|
16
|
+
onDragEnd?: (event: DragEndEvent) => void;
|
|
17
|
+
onDragOver?: (event: DragOverEvent) => void;
|
|
18
|
+
itemSizes?: ListItemSizes;
|
|
17
19
|
};
|
|
18
|
-
type
|
|
19
|
-
onDragEnd: Exclude<SharedListProps['onDragEnd'], undefined>;
|
|
20
|
+
type SharedDraggableListProps = SharedListProps & {
|
|
20
21
|
listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;
|
|
21
22
|
variant: 'ordered-draggable';
|
|
22
23
|
};
|
|
23
|
-
type
|
|
24
|
+
type HeterogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {
|
|
25
|
+
itemSizes?: 'many';
|
|
26
|
+
};
|
|
27
|
+
type HomogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {
|
|
28
|
+
itemSizes: 'one';
|
|
29
|
+
};
|
|
30
|
+
type BaseListProps = Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd' | 'onDragOver'>;
|
|
31
|
+
type ListProps = (BaseListProps & SharedListProps) | (BaseListProps & HomogeneousDraggableListProps) | (BaseListProps & HeterogeneousDraggableListProps);
|
|
24
32
|
declare const createListScope: import("@radix-ui/react-context").CreateScope;
|
|
25
|
-
type ListContextValue = Pick<ListProps, 'selectable' | 'variant'
|
|
33
|
+
type ListContextValue = Pick<ListProps, 'selectable' | 'variant'> & {
|
|
34
|
+
draggingId?: string;
|
|
35
|
+
itemSizes?: ListItemSizes;
|
|
36
|
+
};
|
|
26
37
|
declare const useListContext: (consumerName: string, scope: Scope<ListContextValue | undefined>) => ListContextValue;
|
|
27
|
-
declare const List: React.ForwardRefExoticComponent<(Pick<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
asChild?: boolean | undefined;
|
|
31
|
-
}, "onDragEnd"> & SharedListProps, "type" | "key" | keyof SharedListProps | "slot" | "style" | "title" | "reversed" | "start" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "asChild"> | Pick<Omit<Pick<React.DetailedHTMLProps<React.OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>, "key" | keyof React.OlHTMLAttributes<HTMLOListElement>> & {
|
|
32
|
-
ref?: ((instance: HTMLOListElement | null) => void) | React.RefObject<HTMLOListElement> | null | undefined;
|
|
38
|
+
declare const List: React.ForwardRefExoticComponent<(Pick<BaseListProps & SharedListProps, "slot" | "style" | "title" | "key" | "reversed" | "start" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "asChild" | keyof SharedListProps> | Pick<BaseListProps & SharedListProps & {
|
|
39
|
+
listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;
|
|
40
|
+
variant: 'ordered-draggable';
|
|
33
41
|
} & {
|
|
34
|
-
|
|
35
|
-
}, "
|
|
36
|
-
onDragEnd: Exclude<SharedListProps['onDragEnd'], undefined>;
|
|
42
|
+
itemSizes: 'one';
|
|
43
|
+
}, "slot" | "style" | "title" | "key" | "reversed" | "start" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "asChild" | keyof SharedListProps> | Pick<BaseListProps & SharedListProps & {
|
|
37
44
|
listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;
|
|
38
45
|
variant: 'ordered-draggable';
|
|
39
|
-
}
|
|
46
|
+
} & {
|
|
47
|
+
itemSizes?: "many" | undefined;
|
|
48
|
+
}, "slot" | "style" | "title" | "key" | "reversed" | "start" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "asChild" | keyof SharedListProps>) & React.RefAttributes<HTMLOListElement>>;
|
|
40
49
|
export { List, createListScope, useListContext, LIST_NAME, arrayMove };
|
|
41
|
-
export type { ListProps, ListVariant, ListScopedProps, DragEndEvent };
|
|
50
|
+
export type { ListProps, ListVariant, ListScopedProps, DragEndEvent, DragOverEvent };
|
|
42
51
|
//# sourceMappingURL=List.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../src/List.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,YAAY,EAAE,MA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,KAAK,6BAA6B,GAAG,OAAO,CAAC,wBAAwB,EAAE,WAAW,CAAC,GAAG;IACpF,SAAS,EAAE,KAAK,CAAC;CAClB,CAAC;AAEF,KAAK,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,SAAS,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC;AAElG,KAAK,SAAS,GACV,CAAC,aAAa,GAAG,eAAe,CAAC,GACjC,CAAC,aAAa,GAAG,6BAA6B,CAAC,GAC/C,CAAC,aAAa,GAAG,+BAA+B,CAAC,CAAC;AAItD,QAAA,MAA0B,eAAe,+CAAqC,CAAC;AAE/E,KAAK,gBAAgB,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,SAAS,CAAC,GAAG;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAqB,cAAc,wFAAkD,CAAC;AAStF,QAAA,MAAM,IAAI;iBArCK,QAAQ,eAAe,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;aACtD,mBAAmB;;eAQjB,KAAK;;iBATH,QAAQ,eAAe,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;aACtD,mBAAmB;;;ykJAsF5B,CAAC;AAIH,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAEvE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -39,7 +39,7 @@ declare const useListItemContext: (consumerName: string, scope: Scope<ListItemCo
|
|
|
39
39
|
type ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {
|
|
40
40
|
asChild?: boolean;
|
|
41
41
|
};
|
|
42
|
-
declare const ListItemHeading: React.ForwardRefExoticComponent<Pick<ListItemHeadingProps, "
|
|
42
|
+
declare const ListItemHeading: React.ForwardRefExoticComponent<Pick<ListItemHeadingProps, "slot" | "style" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "asChild" | "__listItemScope"> & React.RefAttributes<HTMLParagraphElement>>;
|
|
43
43
|
type ListItemDragHandleProps = ComponentPropsWithRef<typeof Primitive.div>;
|
|
44
44
|
declare const ListItemDragHandle: React.ForwardRefExoticComponent<Pick<ListItemScopedProps<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
45
45
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItem.d.ts","sourceRoot":"","sources":["../../../src/ListItem.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,KAAK,WAAW,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAsB,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,SAAS,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GAAG,mBAAmB,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG;IACvG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,QAAA,MAAM,eAAe,wnJAUpB,CAAC;AAEF,KAAK,uBAAuB,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AAE3E,QAAA,MAAM,kBAAkB;;;;8HASvB,CAAC;AAEF,KAAK,wBAAwB,GAAG,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;AAE7E,QAAA,MAAM,mBAAmB,mGAAsB,CAAC;AAEhD,KAAK,+BAA+B,GAAG,cAAc,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AAElF,QAAA,MAAM,0BAA0B,EAAE,yBAAyB,CAAC,uBAAuB,CAAuB,CAAC;AAuG3G,QAAA,MAAM,QAAQ,4QASZ,CAAC;AAIH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,CAAC;AAEF,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,GACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-list",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.51-main.04d9478",
|
|
4
4
|
"description": "List primitive components for React.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@radix-ui/react-slot": "^1.0.1",
|
|
28
28
|
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
29
29
|
"lodash.omit": "^4.5.0",
|
|
30
|
-
"@dxos/react-hooks": "0.1.
|
|
30
|
+
"@dxos/react-hooks": "0.1.51-main.04d9478"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@radix-ui/react-checkbox": "^1.0.3",
|
package/src/List.tsx
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { DndContext, DragEndEvent } from '@dnd-kit/core';
|
|
5
|
+
import { DndContext, DragEndEvent, DragStartEvent, DragOverEvent } from '@dnd-kit/core';
|
|
6
6
|
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
7
|
-
import { SortableContext, arrayMove } from '@dnd-kit/sortable';
|
|
7
|
+
import { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
8
8
|
import { createContextScope, Scope } from '@radix-ui/react-context';
|
|
9
9
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
10
|
-
import
|
|
11
|
-
import React, { ComponentPropsWithRef, forwardRef, ReactHTMLElement } from 'react';
|
|
10
|
+
import React, { ComponentPropsWithRef, forwardRef, useCallback, useState } from 'react';
|
|
12
11
|
|
|
13
12
|
// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role
|
|
14
13
|
|
|
@@ -18,59 +17,98 @@ type ListScopedProps<P> = P & { __listScope?: Scope };
|
|
|
18
17
|
|
|
19
18
|
type ListVariant = 'ordered' | 'unordered' | 'ordered-draggable';
|
|
20
19
|
|
|
20
|
+
type ListItemSizes = 'one' | 'many';
|
|
21
|
+
|
|
21
22
|
type SharedListProps = {
|
|
22
23
|
selectable?: boolean;
|
|
23
24
|
variant?: ListVariant;
|
|
24
|
-
onDragEnd?: (event: DragEndEvent) => void;
|
|
25
25
|
listItemIds?: string[];
|
|
26
|
-
|
|
26
|
+
onDragEnd?: (event: DragEndEvent) => void;
|
|
27
|
+
onDragOver?: (event: DragOverEvent) => void;
|
|
28
|
+
itemSizes?: ListItemSizes;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
|
-
type
|
|
30
|
-
onDragEnd: Exclude<SharedListProps['onDragEnd'], undefined>;
|
|
31
|
+
type SharedDraggableListProps = SharedListProps & {
|
|
31
32
|
listItemIds: Exclude<SharedListProps['listItemIds'], undefined>;
|
|
32
33
|
variant: 'ordered-draggable';
|
|
33
34
|
};
|
|
34
35
|
|
|
36
|
+
type HeterogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {
|
|
37
|
+
itemSizes?: 'many';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type HomogeneousDraggableListProps = Exclude<SharedDraggableListProps, 'itemSizes'> & {
|
|
41
|
+
itemSizes: 'one';
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type BaseListProps = Omit<ComponentPropsWithRef<typeof Primitive.ol>, 'onDragEnd' | 'onDragOver'>;
|
|
45
|
+
|
|
35
46
|
type ListProps =
|
|
36
|
-
| (
|
|
37
|
-
| (
|
|
47
|
+
| (BaseListProps & SharedListProps)
|
|
48
|
+
| (BaseListProps & HomogeneousDraggableListProps)
|
|
49
|
+
| (BaseListProps & HeterogeneousDraggableListProps);
|
|
38
50
|
|
|
39
51
|
// LIST
|
|
40
52
|
|
|
41
53
|
const [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
42
54
|
|
|
43
|
-
type ListContextValue = Pick<ListProps, 'selectable' | 'variant'
|
|
55
|
+
type ListContextValue = Pick<ListProps, 'selectable' | 'variant'> & {
|
|
56
|
+
draggingId?: string;
|
|
57
|
+
itemSizes?: ListItemSizes;
|
|
58
|
+
};
|
|
44
59
|
|
|
45
60
|
const [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);
|
|
46
61
|
|
|
62
|
+
const isOrderedDraggable = (props: ListProps): props is SharedDraggableListProps =>
|
|
63
|
+
props.variant === 'ordered-draggable';
|
|
64
|
+
const _isOrderedDraggableHomogeneous = (props: ListProps): props is HomogeneousDraggableListProps =>
|
|
65
|
+
isOrderedDraggable(props) && props.itemSizes === 'one';
|
|
66
|
+
const _isOrderedDraggableHeterogeneous = (props: ListProps): props is HeterogeneousDraggableListProps =>
|
|
67
|
+
isOrderedDraggable(props) && props.itemSizes !== 'one';
|
|
68
|
+
|
|
47
69
|
const List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {
|
|
48
70
|
const {
|
|
49
71
|
__listScope,
|
|
50
72
|
variant = 'ordered',
|
|
51
73
|
selectable = false,
|
|
52
|
-
|
|
74
|
+
onDragEnd,
|
|
75
|
+
onDragOver,
|
|
76
|
+
listItemIds,
|
|
77
|
+
itemSizes,
|
|
53
78
|
children,
|
|
54
79
|
...rootProps
|
|
55
80
|
} = props;
|
|
56
81
|
const ListRoot = variant === 'ordered' || variant === 'ordered-draggable' ? Primitive.ol : Primitive.ul;
|
|
82
|
+
const [draggingId, setDraggingId] = useState<string | undefined>(undefined);
|
|
83
|
+
const onDragStart = useCallback((event: DragStartEvent) => setDraggingId(event.active.id as string), []);
|
|
84
|
+
const composedOnDragEnd = useCallback(
|
|
85
|
+
(event: DragEndEvent) => {
|
|
86
|
+
setDraggingId(undefined);
|
|
87
|
+
onDragEnd?.(event);
|
|
88
|
+
},
|
|
89
|
+
[onDragEnd],
|
|
90
|
+
);
|
|
57
91
|
return (
|
|
58
|
-
<ListRoot
|
|
59
|
-
{...(selectable && { role: 'listbox', 'aria-multiselectable': true })}
|
|
60
|
-
{...omit(rootProps, 'onDragEnd', 'listItemIds')}
|
|
61
|
-
ref={forwardedRef}
|
|
62
|
-
>
|
|
92
|
+
<ListRoot {...(selectable && { role: 'listbox', 'aria-multiselectable': true })} {...rootProps} ref={forwardedRef}>
|
|
63
93
|
<ListProvider
|
|
64
94
|
{...{
|
|
65
95
|
scope: __listScope,
|
|
66
96
|
variant,
|
|
67
97
|
selectable,
|
|
68
|
-
|
|
98
|
+
draggingId,
|
|
99
|
+
itemSizes,
|
|
69
100
|
}}
|
|
70
101
|
>
|
|
71
|
-
{
|
|
72
|
-
<DndContext
|
|
73
|
-
|
|
102
|
+
{isOrderedDraggable(props) ? (
|
|
103
|
+
<DndContext
|
|
104
|
+
onDragEnd={composedOnDragEnd}
|
|
105
|
+
onDragOver={onDragOver}
|
|
106
|
+
onDragStart={onDragStart}
|
|
107
|
+
modifiers={[restrictToVerticalAxis]}
|
|
108
|
+
>
|
|
109
|
+
<SortableContext items={listItemIds!} strategy={verticalListSortingStrategy}>
|
|
110
|
+
{children}
|
|
111
|
+
</SortableContext>
|
|
74
112
|
</DndContext>
|
|
75
113
|
) : (
|
|
76
114
|
<>{children}</>
|
|
@@ -84,4 +122,4 @@ List.displayName = LIST_NAME;
|
|
|
84
122
|
|
|
85
123
|
export { List, createListScope, useListContext, LIST_NAME, arrayMove };
|
|
86
124
|
|
|
87
|
-
export type { ListProps, ListVariant, ListScopedProps, DragEndEvent };
|
|
125
|
+
export type { ListProps, ListVariant, ListScopedProps, DragEndEvent, DragOverEvent };
|
package/src/ListItem.tsx
CHANGED
|
@@ -101,7 +101,7 @@ type ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content
|
|
|
101
101
|
|
|
102
102
|
const ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;
|
|
103
103
|
|
|
104
|
-
const
|
|
104
|
+
const ListItemImpl = forwardRef<
|
|
105
105
|
ListItemElement,
|
|
106
106
|
ListItemProps & { id: string } & Partial<DraggableListItemContextValue>
|
|
107
107
|
>(
|
|
@@ -177,18 +177,19 @@ const PureListItem = forwardRef<
|
|
|
177
177
|
);
|
|
178
178
|
|
|
179
179
|
const DraggableListItem = forwardRef<ListItemElement, ListItemProps & { id: string }>(
|
|
180
|
-
(props: ListItemScopedProps<ListItemProps & { id: string }
|
|
180
|
+
(props: ListItemScopedProps<ListScopedProps<ListItemProps & { id: string }>>, forwardedRef) => {
|
|
181
181
|
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
182
182
|
id: props.id,
|
|
183
183
|
});
|
|
184
|
+
const { itemSizes } = useListContext(LIST_NAME, props.__listScope);
|
|
184
185
|
const ref = useComposedRefs(forwardedRef, setNodeRef) as ComponentPropsWithRef<typeof Primitive.li>['ref'];
|
|
185
186
|
|
|
186
187
|
return (
|
|
187
|
-
<
|
|
188
|
+
<ListItemImpl
|
|
188
189
|
{...props}
|
|
189
190
|
style={{
|
|
190
191
|
...props.style,
|
|
191
|
-
transform: CSS
|
|
192
|
+
transform: CSS[itemSizes === 'one' ? 'Transform' : 'Translate'].toString(transform),
|
|
192
193
|
transition,
|
|
193
194
|
}}
|
|
194
195
|
ref={ref}
|
|
@@ -208,7 +209,7 @@ const ListItem = forwardRef<ListItemElement, ListItemProps>((props: ListScopedPr
|
|
|
208
209
|
if (variant === 'ordered-draggable') {
|
|
209
210
|
return <DraggableListItem {...props} ref={forwardedRef} id={listItemId} />;
|
|
210
211
|
} else {
|
|
211
|
-
return <
|
|
212
|
+
return <ListItemImpl {...props} ref={forwardedRef} id={listItemId} />;
|
|
212
213
|
}
|
|
213
214
|
});
|
|
214
215
|
|