@ gripflow/ core (英语)
Gripflow后方的框架独立拖放引擎. 指针,触控和键盘传感器,相撞探测器,调制器,可分拣数学,自动滚动和可访问性公告,以平版TypeScript形式发布.
建立反应还是下一个.js应用程序? 你不需要直接安装这个 开始
@gripflow/presets(各种列表、网格、表格),@gripflow/kanban或者说@gripflow/tree。 。 。 .@gripflow/core为您安装.
安装 @gripflow/core 当您想要:
- 使用该 纯助手 (单位:千美元)
arrayMove, (中文(简体) ),applySortableMove在服务器上或在测试中, - 写入 定制传感器、修改器或碰撞探测器, (中文(简体) ),
- 或构建一个 另一个 UI 框架的适配器 (Vue, Svelte, Solid, 香草DOM).
它没有反应依赖,没有网络接入和遥测.
安装
npm install @gripflow/core
纯助手
在不改变数据的情况下重排顺序 :
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);
也导出 : arrayInsert, (中文(简体) ), arrayRemove, (中文(简体) ), moveById, (中文(简体) ), moveBetweenContainers, (中文(简体) ), findContainerOf。 。 。 .
发动机
DragEngine 是无头状态机器。 拥有传感器、活性拖放验证和事件;
,您会记录元素,并给出结果,而无论您的框架如何.
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();
反应包( R)@gripflow/react 和朋友),就是这个API周围的薄的束缚.
构件
| 区域 | 出口 |
|---|---|
| 发动机 | DragEngine, (中文(简体) ), createStore, (中文(简体) ), SortableCoordinator, (中文(简体) ), GeometryCache |
| 传感器 | pointerSensor, (中文(简体) ), keyboardSensor, (中文(简体) ), isInteractiveTarget |
| 碰撞探测 | closestCenter, (中文(简体) ), closestCorners, (中文(简体) ), pointerWithin, (中文(简体) ), rectIntersection, (中文(简体) ), containerAware, (中文(简体) ), composeDetectors, (中文(简体) ), defaultCollisionDetector |
| 修改器 | restrictToVerticalAxis, (中文(简体) ), restrictToHorizontalAxis, (中文(简体) ), restrictToWindowEdges, (中文(简体) ), restrictToParentElement, (中文(简体) ), restrictToBounds, (中文(简体) ), snapToGrid |
| 排序战略 | verticalListStrategy, (中文(简体) ), horizontalListStrategy, (中文(简体) ), rectSortingStrategy, (中文(简体) ), noSortingStrategy |
| 可排序数据 | arrayMove, (中文(简体) ), applySortableMove, (中文(简体) ), moveBetweenContainers, (中文(简体) ), arrayInsert, (中文(简体) ), arrayRemove |
| 滚动和移动 | AutoScroller, (中文(简体) ), resolveAnimation, (中文(简体) ), prefersReducedMotion |
| 无障碍 | createDefaultAnnouncements, (中文(简体) ), DEFAULT_INSTRUCTIONS |
| 帮助者 | createHistory (未执行/重新执行), createOptimisticController (乐观的更新与回滚), loggerPlugin |
示例: 限制拖曳到垂直轴(工作通过) @gripflow/react是因为 modifiers 还有道具:
import { restrictToVerticalAxis, restrictToWindowEdges } from "@gripflow/core";
new DragEngine({ modifiers: [restrictToVerticalAxis, restrictToWindowEdges()] });
每个导出都完全输入,所以您的编辑器会显示您输入的文档 .
活动
dragStart, (中文(简体) ), dragMove, (中文(简体) ), dragOver, (中文(简体) ), dropTargetEnter, (中文(简体) ), dropTargetLeave, (中文(简体) ), dropRequested, (中文(简体) ),
dropAccepted, (中文(简体) ), dropRejected, (中文(简体) ), dragEnd, (中文(简体) ), dragCancel, (中文(简体) ), error。订阅 engine.on(name, handler) 或者说
通过 onDragEnd- 选项中的处理者.
相关软件包
@gripflow/react • 妇女
@gripflow/presets • 妇女
@gripflow/kanban • 妇女
@gripflow/tree • 妇女
@gripflow/nestjs-adapter