@gripflow/core

中文文档
0.1.1发布于 2026/10/12MITTypeScriptESM + CJS零依赖近 30 天下载 7868

Gripflow core: framework-independent, headless drag and drop engine with pointer, touch and keyboard sensors, collision detection, modifiers, sortable model and auto-scroll.

原始使用文档
文档目录7 节
  1. Install
  2. Pure helpers
  3. The engine
  4. Building blocks
  5. Events
  6. Related packages
  7. Author

@gripflow/core

The framework-independent drag-and-drop engine behind Gripflow. Pointer, touch and keyboard sensors, collision detection, modifiers, sortable math, auto-scroll and accessibility announcements, in plain TypeScript.

npm types license

Building a React or Next.js app? You don't need to install this directly. Start with @gripflow/presets (sortable list, grid, table), @gripflow/kanban or @gripflow/tree. @gripflow/core is installed for you.

Install @gripflow/core when you want to:

  • use the pure helpers (arrayMove, applySortableMove, collision functions) on the server or in tests,
  • write custom sensors, modifiers or collision detection,
  • or build an adapter for another UI framework (Vue, Svelte, Solid, vanilla DOM).

It has no React dependency, no network access and no telemetry.

Install

npm install @gripflow/core

Pure helpers

Reordering without mutating your data:

import { arrayMove, applySortableMove } from "@gripflow/core";

arrayMove(["a", "b", "c"], 0, 2); // ["b", "c", "a"]

// Apply the move reported by a drag-end event, by id, across containers:
const next = applySortableMove({ todo: todoCards, done: doneCards }, event.move, (card) => card.id);

Also exported: arrayInsert, arrayRemove, moveById, moveBetweenContainers, findContainerOf.

The engine

DragEngine is the headless state machine. It owns sensors, the active drag, drop validation and events; you register elements and render the result however your framework does.

import { DragEngine, pointerSensor, keyboardSensor } from "@gripflow/core";

const engine = new DragEngine({
  sensors: [pointerSensor(), keyboardSensor()],
  onDragEnd(event) {
    console.log("dropped", event.active.id, "over", event.over?.id, "move:", event.move);
  },
});

const unmount = engine.mount(); // starts listening; call the returned function to stop

const card = document.querySelector<HTMLElement>("#card-1")!;
const registration = engine.registerDraggable({ id: "card-1", element: card });

// later:
registration.unregister();
unmount();

The React packages (@gripflow/react and friends) are thin bindings around exactly this API.

Building blocks

AreaExports
EngineDragEngine, createStore, SortableCoordinator, GeometryCache
SensorspointerSensor, keyboardSensor, isInteractiveTarget
Collision detectionclosestCenter, closestCorners, pointerWithin, rectIntersection, containerAware, composeDetectors, defaultCollisionDetector
ModifiersrestrictToVerticalAxis, restrictToHorizontalAxis, restrictToWindowEdges, restrictToParentElement, restrictToBounds, snapToGrid
Sorting strategiesverticalListStrategy, horizontalListStrategy, rectSortingStrategy, noSortingStrategy
Sortable dataarrayMove, applySortableMove, moveBetweenContainers, arrayInsert, arrayRemove
Scrolling and motionAutoScroller, resolveAnimation, prefersReducedMotion
AccessibilitycreateDefaultAnnouncements, DEFAULT_INSTRUCTIONS
HelperscreateHistory (undo/redo), createOptimisticController (optimistic updates with rollback), loggerPlugin

Example: constrain dragging to a vertical axis (works through @gripflow/react's modifiers prop too):

import { restrictToVerticalAxis, restrictToWindowEdges } from "@gripflow/core";

new DragEngine({ modifiers: [restrictToVerticalAxis, restrictToWindowEdges()] });

Every export is fully typed, so your editor shows documentation as you type.

Events

dragStart, dragMove, dragOver, dropTargetEnter, dropTargetLeave, dropRequested, dropAccepted, dropRejected, dragEnd, dragCancel, error. Subscribe with engine.on(name, handler) or pass onDragEnd-style handlers in the options.

@gripflow/react · @gripflow/presets · @gripflow/kanban · @gripflow/tree · @gripflow/nestjs-adapter

Author

Created and maintained by salmannizam. Issues and ideas are welcome on GitHub. MIT licensed.

版本与发布记录

@gripflow/core 共发布 3 个版本,首次发布于 2026/10/12;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.1.1latest2026/10/121 个月前
0.1.02026/10/121 个月前
0.0.0-stage2026/10/121 个月前

关于 @gripflow/core 的常见问题

@gripflow/core 是什么?

Gripflow core: framework-independent, headless drag and drop engine with pointer, touch and keyboard sensors, collision detection, modifiers, sortable model and auto-scroll.

如何安装 @gripflow/core?

在项目目录运行 npm install @gripflow/core,或使用 pnpm add / yarn add / bun add。

@gripflow/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gripflow/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gripflow/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gripflow/core 可以商用吗?

@gripflow/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gripflow/core 的下载量有多少?

根据 npm 官方下载统计,@gripflow/core 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,868 次,日均约 262 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gripflow/core 还在维护吗?

最新版本 0.1.1 发布于 2026/10/12(1 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/10/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。