{"version":3,"file":"remix-reorder.mjs","sources":["../../src/remix-reorder.ts"],"sourcesContent":["import {\n    isMotionValue,\n    motionValue,\n    transformValue,\n    visualElementStore,\n    type MotionValue,\n} from \"motion-dom\"\nimport { moveItem, type Box, type Point } from \"motion-utils\"\nimport { createElement, on, ref } from \"remix/component\"\nimport type { Handle, RemixNode } from \"remix/component\"\nimport type { ItemData, ReorderAxis } from \"./components/Reorder/types\"\nimport {\n    autoScrollIfNeeded,\n    resetAutoScrollState,\n} from \"./components/Reorder/utils/auto-scroll\"\nimport {\n    checkReorder,\n    keyTarget,\n} from \"./components/Reorder/utils/check-reorder\"\nimport { detectAxis } from \"./components/Reorder/utils/detect-axis\"\nimport type { MotionComponentProps } from \"./remix\"\n\nexport type ReorderGroupProps<V> = Omit<MotionComponentProps, \"values\"> & {\n    /**\n     * The element to render. Defaults to `\"ul\"`.\n     */\n    as?: string\n\n    /**\n     * The axis to reorder along. By default, this is detected from the item\n     * layout. Use `\"xy\"` to explicitly enable wrapped layout reordering.\n     */\n    axis?: ReorderAxis\n\n    /**\n     * Called with the new order of `values`, and the value of the item\n     * that moved, for each step of a drag.\n     */\n    onReorder: (newOrder: V[], moved: V) => void\n\n    /**\n     * The latest values, in order.\n     */\n    values: V[]\n}\n\nexport type ReorderItemProps<V> = Omit<MotionComponentProps, \"layout\"> & {\n    /**\n     * The element to render. Defaults to `\"li\"`.\n     */\n    as?: string\n\n    /**\n     * The value in the group's `values` that this item represents.\n     */\n    value: V\n\n    /**\n     * Set to `\"position\"` to animate only the position of the item when\n     * the order changes.\n     *\n     * @default true\n     */\n    layout?: true | \"position\"\n}\n\ntype Grab = (element: Element, from?: any[]) => void\n\ninterface ItemHandle {\n    element?: HTMLElement\n    update: () => void\n}\n\nexport interface ReorderContext {\n    axis: ReorderAxis\n    hasReordered: boolean\n    getElement: () => Element | undefined\n    registerItem: (value: any, layout: Box) => void\n    /**\n     * Each rendered item, for arrow keys to focus.\n     */\n    items: Map<any, ItemHandle>\n    /**\n     * Whether an item is in the tab order. Only one in `values` is: the\n     * last focused, or the first rendered.\n     */\n    isTabStop: (value: any) => boolean\n    setActive: (value: any) => void\n    checkTabStop: () => void\n    updateOrder: (value: any, offset: Point, velocity: Point) => void\n    onKeyDown: (\n        event: KeyboardEvent,\n        item: any,\n        from: any[] | undefined,\n        grab: Grab\n    ) => void\n}\n\nconst keys = [\"ArrowUp\", \"ArrowLeft\", \"ArrowDown\", \"ArrowRight\", \"Home\", \"End\"]\n\n/**\n * Creates `Reorder.Group` and `Reorder.Item`, rendering the components of\n * `motion`.\n */\nexport interface ReorderComponents {\n    Group: (\n        handle: Handle<ReorderGroupProps<any>, ReorderContext>\n    ) => () => RemixNode\n    Item: (handle: Handle<ReorderItemProps<any>>) => () => RemixNode\n}\n\nexport function createReorder(motion: any): ReorderComponents {\n    /**\n     * A list of items that can be reordered by drag or keyboard, with the\n     * same props as React's `Reorder.Group`.\n     */\n    function Group(handle: Handle<ReorderGroupProps<any>, ReorderContext>) {\n        const itemLayouts = new Map<any, Box>()\n        const items = new Map<any, ItemHandle>()\n        let active: any\n        let detectedAxis: ReorderAxis = \"y\"\n        let isReordering = false\n        let element: Element | undefined\n        let renderedValues: any[] | undefined\n\n        const getOrder = (): ItemData<any>[] =>\n            handle.props.values.flatMap((value) => {\n                const layout = itemLayouts.get(value)\n                return layout ? [{ value, layout }] : []\n            })\n\n        const isRTL = () =>\n            !!element && getComputedStyle(element).direction === \"rtl\"\n\n        /**\n         * Write the new order of the measured items back into the slots they\n         * hold in `values`, leaving unmeasured values in place.\n         */\n        const commit = (newOrder: ItemData<any>[], moved: any) => {\n            const { values, onReorder } = handle.props\n            let i = 0\n            const newValues = values.map((value) =>\n                itemLayouts.has(value) ? newOrder[i++].value : value\n            )\n            newValues.some((value, j) => value !== values[j]) &&\n                onReorder(newValues, moved)\n        }\n\n        const getTabStop = () => {\n            const { values } = handle.props\n            return values.includes(active) ? active : values[0]\n        }\n\n        const isRendered = (value: any) =>\n            items.get(value)?.element?.isConnected\n\n        /**\n         * If the tab stop isn't rendered (e.g. it's virtualized), the first\n         * rendered item takes its place. Items check again when removed.\n         */\n        const checkTabStop = () => {\n            isRendered(getTabStop()) ||\n                context.setActive(handle.props.values.find(isRendered))\n        }\n\n        const context: ReorderContext = {\n            axis: \"y\",\n            hasReordered: false,\n            getElement: () => element,\n            items,\n            isTabStop: (value) =>\n                value === getTabStop() || !handle.props.values.includes(value),\n            checkTabStop,\n            /**\n             * Only values in `values` can be the tab stop.\n             */\n            setActive: (value) => {\n                const tabStop = getTabStop()\n                if (!handle.props.values.includes(value)) return\n                active = value\n                if (value !== tabStop) {\n                    items.get(tabStop)?.update()\n                    items.get(value)?.update()\n                }\n            },\n            /**\n             * Space grabs and drops the item, arrows along `axis` move the\n             * grabbed item one place, or a row in a grid (see keyTarget), or\n             * move focus that way if it isn't grabbed. Home and End go to\n             * either end. Escape restores the order in `from`, the values\n             * when it was grabbed.\n             */\n            onKeyDown: (event, item, from, grab) => {\n                const { key, currentTarget } = event\n                if (\n                    event.defaultPrevented ||\n                    event.target !== currentTarget ||\n                    event.altKey ||\n                    event.ctrlKey ||\n                    event.metaKey\n                ) {\n                    return\n                }\n\n                const { axis } = context\n                const order = getOrder()\n                const keyIndex = keys.indexOf(key)\n                const isX = keyIndex % 2\n                if (key === \" \") {\n                    event.repeat ||\n                        grab(\n                            currentTarget as Element,\n                            from ? undefined : handle.props.values\n                        )\n                } else if (key === \"Escape\" && from) {\n                    const kept = from.flatMap((value) =>\n                        order.filter((data) => data.value === value)\n                    )\n                    commit(\n                        order.map((data) =>\n                            from.includes(data.value) ? kept.shift()! : data\n                        ),\n                        item\n                    )\n                    grab(currentTarget as Element)\n                } else if (\n                    keyIndex < 0 ||\n                    (keyIndex < 4 &&\n                        axis !== \"xy\" &&\n                        axis !== (isX ? \"x\" : \"y\"))\n                ) {\n                    return\n                } else {\n                    /**\n                     * Focus only moves between rendered items.\n                     */\n                    const list = from\n                        ? order\n                        : order.filter(({ value }) => isRendered(value))\n                    const index = list.findIndex(({ value }) => value === item)\n                    const target = keyTarget(\n                        list,\n                        index,\n                        keyIndex,\n                        axis,\n                        !!isX && isRTL()\n                    )\n                    if (target > -1) {\n                        from\n                            ? commit(moveItem(order, index, target), item)\n                            : items.get(list[target].value)?.element?.focus()\n                    }\n                }\n                event.preventDefault()\n            },\n            registerItem: (value, layout) => {\n                itemLayouts.set(value, layout)\n\n                if (!handle.props.axis) {\n                    const nextAxis = detectAxis(\n                        handle.props.values.flatMap((itemValue) => {\n                            const itemLayout = itemLayouts.get(itemValue)\n                            return itemLayout ? [itemLayout] : []\n                        })\n                    )\n\n                    if (nextAxis !== detectedAxis) {\n                        detectedAxis = nextAxis\n                        handle.update()\n                    }\n                }\n            },\n            updateOrder: (item, offset, velocity) => {\n                if (isReordering) return\n\n                const order = getOrder()\n                const newOrder = checkReorder(\n                    order,\n                    item,\n                    offset,\n                    velocity,\n                    context.axis,\n                    isRTL() ? \"rtl\" : \"ltr\"\n                )\n\n                if (order !== newOrder) {\n                    isReordering = context.hasReordered = true\n                    commit(newOrder, item)\n                }\n            },\n        }\n\n        return () => {\n            const {\n                as = \"ul\",\n                axis,\n                values,\n                onReorder,\n                style,\n                mix,\n                children,\n                ...props\n            } = handle.props\n\n            const valuesSet = new Set(values)\n            for (const map of [itemLayouts, items]) {\n                map.forEach(\n                    (_, value) => valuesSet.has(value) || map.delete(value)\n                )\n            }\n\n            /**\n             * Only allow the next reorder once the new order has rendered.\n             */\n            if (values !== renderedValues) {\n                renderedValues = values\n                handle.queueTask(() => (isReordering = false))\n            }\n\n            handle.queueTask(checkTabStop)\n\n            context.axis = axis || detectedAxis\n            handle.context.set(context)\n\n            return createElement(\n                motion[as],\n                {\n                    ...props,\n                    /**\n                     * Scroll anchoring would move the page while items\n                     * reorder, and with it the dragged item.\n                     */\n                    style: { overflowAnchor: \"none\", ...style },\n                    mix: [\n                        ref((node) => (element = node)),\n                        /**\n                         * The release that ends a reordering drag isn't a\n                         * click. Clicks with no pointer press behind them\n                         * (detail 0, e.g. keyboard) are left alone.\n                         */\n                        on<HTMLElement, \"pointerdown\">(\n                            \"pointerdown\",\n                            () => {\n                                context.hasReordered = false\n                            },\n                            true\n                        ),\n                        on<HTMLElement, \"click\">(\n                            \"click\",\n                            (event) => {\n                                if (context.hasReordered && event.detail) {\n                                    context.hasReordered = false\n                                    event.stopPropagation()\n                                    event.preventDefault()\n                                }\n                            },\n                            true\n                        ),\n                        mix,\n                    ],\n                },\n                children\n            )\n        }\n    }\n\n    /**\n     * An item in a `Reorder.Group`, with the same props as React's\n     * `Reorder.Item`.\n     */\n    function Item(handle: Handle<ReorderItemProps<any>>) {\n        /**\n         * The group's values when this item was grabbed with the keyboard, for\n         * Escape to restore. Set only while grabbed.\n         */\n        let grabbedFrom: any[] | undefined\n        const defaultX = motionValue(0)\n        const defaultY = motionValue(0)\n        let zIndex: { x: MotionValue; y: MotionValue; value: MotionValue }\n        const self: ItemHandle = { update: () => handle.update() }\n\n        const getGroup = () => handle.context.get(Group) as ReorderContext\n\n        /**\n         * A keyboard grab is a drag without a pointer, so it shares whileDrag.\n         */\n        const grab: Grab = (element, from) => {\n            grabbedFrom = from\n            visualElementStore\n                .get(element)\n                ?.animationState?.setActive(\"whileDrag\", !!from)\n        }\n\n        return () => {\n            const {\n                as = \"li\",\n                value,\n                style = {},\n                layout = true,\n                onDrag,\n                onDragEnd,\n                mix,\n                children,\n                ...props\n            } = handle.props\n            const group = getGroup()\n            const { axis } = group\n            group.items.set(value, self)\n\n            const x = isMotionValue(style.x) ? style.x : defaultX\n            const y = isMotionValue(style.y) ? style.y : defaultY\n            if (zIndex?.x !== x || zIndex.y !== y) {\n                zIndex = {\n                    x,\n                    y,\n                    value: transformValue(() =>\n                        x.get() || y.get() ? 1 : \"unset\"\n                    ),\n                }\n            }\n\n            return createElement(\n                motion[as],\n                {\n                    drag: axis === \"xy\" ? true : axis,\n                    tabIndex: group.isTabStop(value) ? 0 : -1,\n                    ...props,\n                    dragSnapToOrigin: true,\n                    style: { ...style, x, y, zIndex: zIndex.value },\n                    layout,\n                    onDrag: (event: PointerEvent, info: any) => {\n                        const { velocity, point } = info\n                        group.updateOrder(\n                            handle.props.value,\n                            { x: x.get(), y: y.get() },\n                            velocity\n                        )\n\n                        const scrollAxis =\n                            group.axis === \"xy\"\n                                ? Math.abs(velocity.x) > Math.abs(velocity.y)\n                                    ? \"x\"\n                                    : \"y\"\n                                : group.axis\n                        autoScrollIfNeeded(\n                            group.getElement() || null,\n                            point[scrollAxis],\n                            scrollAxis,\n                            velocity[scrollAxis]\n                        )\n\n                        onDrag?.(event, info)\n                    },\n                    onDragEnd: (event: PointerEvent, info: any) => {\n                        // Runs a frame after release, so after the release's click\n                        group.hasReordered = false\n                        resetAutoScrollState()\n                        onDragEnd?.(event, info)\n                    },\n                    onLayoutMeasure: (measured: Box) =>\n                        group.registerItem(handle.props.value, measured),\n                    mix: [\n                        mix,\n                        ref<HTMLElement>((node, signal) => {\n                            self.element = node\n                            signal.addEventListener(\"abort\", () =>\n                                queueMicrotask(group.checkTabStop)\n                            )\n                        }),\n                        /**\n                         * The item focused last, or holding focus, is the\n                         * group's tab stop.\n                         */\n                        on<HTMLElement, \"focusin\">(\"focusin\", () =>\n                            group.setActive(handle.props.value)\n                        ),\n                        on<HTMLElement, \"keydown\">(\"keydown\", (event) =>\n                            group.onKeyDown(\n                                event,\n                                handle.props.value,\n                                grabbedFrom,\n                                grab\n                            )\n                        ),\n                        /**\n                         * Remix blurs the item when it moves its node, and\n                         * focuses it again in the same flush. So only drop\n                         * it if focus is elsewhere once that's done.\n                         */\n                        on<HTMLElement, \"blur\">(\"blur\", ({ currentTarget }) =>\n                            queueMicrotask(\n                                () =>\n                                    grabbedFrom &&\n                                    currentTarget.ownerDocument\n                                        .activeElement !== currentTarget &&\n                                    grab(currentTarget)\n                            )\n                        ),\n                    ],\n                },\n                children\n            )\n        }\n    }\n\n    return { Group, Item }\n}\n"],"names":[],"mappings":";;;;;;;AAkGA,M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