@canvas-components/react-drag-any 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +113 -2
- package/dist/index.cjs +2127 -0
- package/dist/index.css +160 -0
- package/dist/index.d.cts +180 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +2114 -0
- package/package.json +44 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 canvas-components contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-drag-any
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React 声明式 Canvas 拖放画布。根入口在结构 JSX、`document` 和 `store` 中选择一种。
|
|
4
|
+
|
|
5
|
+
## 通用 Canvas UI 结构
|
|
6
|
+
|
|
7
|
+
队列和泳道可直接由 Canvas UI JSX 声明。通过 `getDragRole(key)` 将稳定的 JSX key 映射为拖拽角色、业务 ID 和数据。卡片内容进入视口时才编译,节点可独立响应事件。
|
|
8
|
+
|
|
9
|
+
卡片角色支持 `{ kind: "card", id, data, disabled: true }`,对应文档卡片的 `disabled`。如需锁定拖拽但允许点击详情等卡片操作,可传 `canDrag={({ card }) => !lockedIds.has(card.id)}`。
|
|
10
|
+
|
|
11
|
+
使用 `canDrop` 按目标容器和插入锚点限制位置。例如,`canDrop={({ target }) => target.beforeCardId === "locked" ? { allowed: false, reason: "不能插到锁定工单前" } : { allowed: true }}`。锚点为 `null` 时表示追加到容器末尾,也涵盖空容器。可在泳道角色上设置 `dropDisabled: true` 拒绝整条泳道的落点。
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { UI } from "@canvas-components/react-canvas-ui";
|
|
15
|
+
import {
|
|
16
|
+
ReactDragAny,
|
|
17
|
+
type DragJSXRole,
|
|
18
|
+
} from "@canvas-components/react-drag-any";
|
|
19
|
+
import "@canvas-components/react-drag-any/style.css";
|
|
20
|
+
|
|
21
|
+
const roles = new Map<string, DragJSXRole<{ order: string }>>([
|
|
22
|
+
["device", { kind: "region", id: "device-a" }],
|
|
23
|
+
["title", { kind: "header" }],
|
|
24
|
+
["jobs", { kind: "items" }],
|
|
25
|
+
["order", { kind: "card", id: "job-1", data: { order: "WO-001" } }],
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
<ReactDragAny
|
|
29
|
+
id="schedule"
|
|
30
|
+
dragLayout="lanes"
|
|
31
|
+
getDragRole={(key) => roles.get(key)}
|
|
32
|
+
annotations={{
|
|
33
|
+
topHeight: 32,
|
|
34
|
+
renderCorner: () => [
|
|
35
|
+
{
|
|
36
|
+
kind: "content",
|
|
37
|
+
rect: { x: 8, y: 4, width: 96, height: 24 },
|
|
38
|
+
content: "设备",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
renderTop: ({ top, viewport }) => [
|
|
42
|
+
{
|
|
43
|
+
kind: "content",
|
|
44
|
+
rect: { x: 8, y: 4, width: top.width - 8, height: 24 },
|
|
45
|
+
content: `时间轴 · 偏移 ${viewport.scrollLeft}px`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
renderOverlay: ({ body, pointer }) =>
|
|
49
|
+
pointer &&
|
|
50
|
+
pointer.x >= body.x &&
|
|
51
|
+
pointer.x < body.x + body.width &&
|
|
52
|
+
pointer.y >= body.y &&
|
|
53
|
+
pointer.y < body.y + body.height
|
|
54
|
+
? [
|
|
55
|
+
{
|
|
56
|
+
kind: "line",
|
|
57
|
+
props: {
|
|
58
|
+
x1: pointer.x - body.x,
|
|
59
|
+
x2: pointer.x - body.x,
|
|
60
|
+
y1: 0,
|
|
61
|
+
y2: body.height,
|
|
62
|
+
stroke: "#2963ae",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
: [],
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<UI.Col>
|
|
70
|
+
<UI.Row key="device" style={{ height: 96 }}>
|
|
71
|
+
<UI.Col key="title" style={{ width: 112 }}>
|
|
72
|
+
<UI.Text>设备 A</UI.Text>
|
|
73
|
+
</UI.Col>
|
|
74
|
+
<UI.Row key="jobs" gap={8} style={{ flex: 1 }}>
|
|
75
|
+
<UI.Col key="order" style={{ width: 220, padding: 8 }}>
|
|
76
|
+
<UI.Text>工单 A</UI.Text>
|
|
77
|
+
</UI.Col>
|
|
78
|
+
</UI.Row>
|
|
79
|
+
</UI.Row>
|
|
80
|
+
</UI.Col>
|
|
81
|
+
</ReactDragAny>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
队列使用纵向布局根和 `card` 子节点,卡片高度及间距映射到画布布局。泳道使用纵向根、横向 `region`、可选 `header` 和横向 `items`。泳道高度、标题宽度、卡片间距和卡片组内边距在画布内共享,卡片可分别设置宽度。结构尺寸使用数字或 `px`,内容内部仍可使用 Canvas UI 支持的布局样式。稀疏网格继续使用下文的 `SparseGrid` 或文档入口。
|
|
85
|
+
|
|
86
|
+
`annotations` 的回调以同一视口读取固定顶部、角头和正文。返回项的坐标相对所处分区,指针坐标相对宿主。正文覆盖项只参与绘制。可用 `refreshIntervalMs` 刷新当前时间线等依赖时钟的内容,覆盖帧复用上一帧正文及命中数据。
|
|
87
|
+
|
|
88
|
+
## 专用结构、文档与 store
|
|
89
|
+
|
|
90
|
+
支持 `Lanes > Lane > Card`、`SparseGrid > GridSlot > Card`、`Queue > Card` 和 `Flow > Card`。每层也可用 `lanes`、`slots`、`cards` 提供批量记录。记录属性与同层结构 children 互斥。卡片可声明 `size`、`data`、`disabled` 和内容。内容写在 Card 子树或 `content` 属性中。字段 `header` 和 `corner` 可传 `UI.*` JSX 或 `canvas-ui` JSON。Canvas UI 支持布局、文本和 21 类叶节点,排除嵌套表格。独立编译可调用 `compileJSX`,结果统一为 `canvas-ui` 文档。
|
|
91
|
+
|
|
92
|
+
既有的内置 JSX 子集和旧原生内容 JSON 会在输入处转换成 `canvas-ui` 文档。
|
|
93
|
+
|
|
94
|
+
在 `onMoveRequest` 中按提案更新业务数组或调用原生包的 `applyMove`。同一次 React 更新传入新数据及 `acknowledgedTransactionId`。跨画布时,`ReactDragAnyGroup` 直接包含各画布声明。用组的 `onMoveRequest` 和 `acknowledgedTransactionId` 在同一次提交更新源和目标。未配置移动回调的画布可用于只读展示。
|
|
95
|
+
|
|
96
|
+
用 `ref` 调用 `focusCard`、`scrollTo`、`getSnapshot`、`cancelDrag` 或 `rejectMove`。用 `contextMenu` 定制右键菜单。`storageKey` 可保存滚动条设置。`UI.*` 的 `onClick` 接收节点级点击事件,同区域多个节点可独立处理。画布级 `onRegionContentAction` 接收区域归属和局部坐标。大数据可使用结构化文档,Canvas UI JSX 在进入视口时编译。
|
|
97
|
+
|
|
98
|
+
## 卡片内滚动
|
|
99
|
+
|
|
100
|
+
在 `ReactDragAny` 上传入 `contentScroll`,再为需要滚动的 Canvas UI 容器指定 `overflowX: "auto"` 或 `overflowY: "auto"` 及合适的宽度或高度。该属性默认关闭。容器样式设为 `scrollbarVisible: false` 时只隐藏滚动条,卡内滚动仍可用。
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<ReactDragAny
|
|
104
|
+
id="jobs"
|
|
105
|
+
dragLayout="queue"
|
|
106
|
+
getDragRole={(key) => key === "job" ? { kind: "card", id: key } : undefined}
|
|
107
|
+
contentScroll
|
|
108
|
+
>
|
|
109
|
+
<UI.Col key="job" style={{ height: 96, overflowY: "auto" }}>
|
|
110
|
+
<UI.div style={{ height: 72 }}>白班工单</UI.div>
|
|
111
|
+
<UI.div style={{ height: 72 }}>夜班工单</UI.div>
|
|
112
|
+
</UI.Col>
|
|
113
|
+
</ReactDragAny>
|
|
114
|
+
```
|