@steedos-widgets/sortable 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/.env +1 -0
- package/.env.local +8 -0
- package/dist/assets-dev.json +25 -0
- package/dist/assets.json +25 -0
- package/dist/components/MultipleContainers.d.ts +7 -0
- package/dist/components/components/Container/Container.d.ts +17 -0
- package/dist/components/components/Container/index.d.ts +2 -0
- package/dist/components/components/Grid/Grid.d.ts +7 -0
- package/dist/components/components/Grid/index.d.ts +1 -0
- package/dist/components/components/GridContainer/GridContainer.d.ts +6 -0
- package/dist/components/components/GridContainer/index.d.ts +1 -0
- package/dist/components/components/Item/Item.d.ts +37 -0
- package/dist/components/components/Item/components/Action/Action.d.ts +9 -0
- package/dist/components/components/Item/components/Action/index.d.ts +2 -0
- package/dist/components/components/Item/components/Handle/Handle.d.ts +3 -0
- package/dist/components/components/Item/components/Handle/index.d.ts +1 -0
- package/dist/components/components/Item/components/Remove/Remove.d.ts +3 -0
- package/dist/components/components/Item/components/Remove/index.d.ts +1 -0
- package/dist/components/components/Item/components/index.d.ts +3 -0
- package/dist/components/components/Item/index.d.ts +2 -0
- package/dist/components/components/index.d.ts +5 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/multipleContainersKeyboardCoordinates.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/meta.d.ts +9 -0
- package/dist/meta.js +180 -0
- package/dist/metas/MultipleContainers.d.ts +2 -0
- package/dist/sortable.cjs.css +335 -0
- package/dist/sortable.cjs.js +56525 -0
- package/dist/sortable.cjs.js.map +1 -0
- package/dist/sortable.esm.css +335 -0
- package/dist/sortable.esm.js +56521 -0
- package/dist/sortable.esm.js.map +1 -0
- package/dist/sortable.umd.css +335 -0
- package/dist/sortable.umd.js +22829 -0
- package/dist/utilities/createRange.d.ts +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/package.json +51 -0
- package/rollup.config.ts +109 -0
- package/src/assets.json +25 -0
- package/src/components/MultipleContainers.tsx +802 -0
- package/src/components/components/Container/Container.module.css +103 -0
- package/src/components/components/Container/Container.tsx +83 -0
- package/src/components/components/Container/index.ts +2 -0
- package/src/components/components/Grid/Grid.module.css +30 -0
- package/src/components/components/Grid/Grid.tsx +22 -0
- package/src/components/components/Grid/index.ts +1 -0
- package/src/components/components/GridContainer/GridContainer.module.css +15 -0
- package/src/components/components/GridContainer/GridContainer.tsx +23 -0
- package/src/components/components/GridContainer/index.ts +1 -0
- package/src/components/components/Item/Item.module.css +145 -0
- package/src/components/components/Item/Item.tsx +157 -0
- package/src/components/components/Item/components/Action/Action.module.css +50 -0
- package/src/components/components/Item/components/Action/Action.tsx +33 -0
- package/src/components/components/Item/components/Action/index.ts +2 -0
- package/src/components/components/Item/components/Handle/Handle.tsx +20 -0
- package/src/components/components/Item/components/Handle/index.ts +1 -0
- package/src/components/components/Item/components/Remove/Remove.tsx +19 -0
- package/src/components/components/Item/components/Remove/index.ts +1 -0
- package/src/components/components/Item/components/index.ts +3 -0
- package/src/components/components/Item/index.ts +2 -0
- package/src/components/components/index.ts +6 -0
- package/src/components/index.ts +1 -0
- package/src/components/multipleContainersKeyboardCoordinates.ts +116 -0
- package/src/index.ts +1 -0
- package/src/meta.ts +20 -0
- package/src/metas/MultipleContainers.tsx +131 -0
- package/src/types/css.d.ts +4 -0
- package/src/types/global.d.ts +6 -0
- package/src/utilities/createRange.ts +15 -0
- package/src/utilities/index.ts +1 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {Action, ActionProps} from '../Action';
|
|
4
|
+
|
|
5
|
+
export function Remove(props: ActionProps) {
|
|
6
|
+
return (
|
|
7
|
+
<Action
|
|
8
|
+
{...props}
|
|
9
|
+
active={{
|
|
10
|
+
fill: 'rgba(255, 70, 70, 0.95)',
|
|
11
|
+
background: 'rgba(255, 70, 70, 0.1)',
|
|
12
|
+
}}
|
|
13
|
+
>
|
|
14
|
+
<svg width="8" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg">
|
|
15
|
+
<path d="M2.99998 -0.000206962C2.7441 -0.000206962 2.48794 0.0972617 2.29294 0.292762L0.292945 2.29276C-0.0980552 2.68376 -0.0980552 3.31682 0.292945 3.70682L7.58591 10.9998L0.292945 18.2928C-0.0980552 18.6838 -0.0980552 19.3168 0.292945 19.7068L2.29294 21.7068C2.68394 22.0978 3.31701 22.0978 3.70701 21.7068L11 14.4139L18.2929 21.7068C18.6829 22.0978 19.317 22.0978 19.707 21.7068L21.707 19.7068C22.098 19.3158 22.098 18.6828 21.707 18.2928L14.414 10.9998L21.707 3.70682C22.098 3.31682 22.098 2.68276 21.707 2.29276L19.707 0.292762C19.316 -0.0982383 18.6829 -0.0982383 18.2929 0.292762L11 7.58573L3.70701 0.292762C3.51151 0.0972617 3.25585 -0.000206962 2.99998 -0.000206962Z" />
|
|
16
|
+
</svg>
|
|
17
|
+
</Action>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {Remove} from './Remove';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {MultipleContainers} from './MultipleContainers'
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
closestCorners,
|
|
5
|
+
getFirstCollision,
|
|
6
|
+
KeyboardCode,
|
|
7
|
+
DroppableContainer,
|
|
8
|
+
KeyboardCoordinateGetter,
|
|
9
|
+
} from '@dnd-kit/core';
|
|
10
|
+
|
|
11
|
+
const directions: string[] = [
|
|
12
|
+
KeyboardCode.Down,
|
|
13
|
+
KeyboardCode.Right,
|
|
14
|
+
KeyboardCode.Up,
|
|
15
|
+
KeyboardCode.Left,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const coordinateGetter: KeyboardCoordinateGetter = (
|
|
19
|
+
event,
|
|
20
|
+
{context: {active, droppableRects, droppableContainers, collisionRect}}
|
|
21
|
+
) => {
|
|
22
|
+
if (directions.includes(event.code)) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
|
|
25
|
+
if (!active || !collisionRect) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const filteredContainers: DroppableContainer[] = [];
|
|
30
|
+
|
|
31
|
+
droppableContainers.getEnabled().forEach((entry) => {
|
|
32
|
+
if (!entry || entry?.disabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const rect = droppableRects.get(entry.id);
|
|
37
|
+
|
|
38
|
+
if (!rect) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const data = entry.data.current;
|
|
43
|
+
|
|
44
|
+
if (data) {
|
|
45
|
+
const {type, children} = data;
|
|
46
|
+
|
|
47
|
+
if (type === 'container' && children?.length > 0) {
|
|
48
|
+
if (active.data.current?.type !== 'container') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
switch (event.code) {
|
|
55
|
+
case KeyboardCode.Down:
|
|
56
|
+
if (collisionRect.top < rect.top) {
|
|
57
|
+
filteredContainers.push(entry);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case KeyboardCode.Up:
|
|
61
|
+
if (collisionRect.top > rect.top) {
|
|
62
|
+
filteredContainers.push(entry);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case KeyboardCode.Left:
|
|
66
|
+
if (collisionRect.left >= rect.left + rect.width) {
|
|
67
|
+
filteredContainers.push(entry);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case KeyboardCode.Right:
|
|
71
|
+
if (collisionRect.left + collisionRect.width <= rect.left) {
|
|
72
|
+
filteredContainers.push(entry);
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const collisions = closestCorners({
|
|
79
|
+
active,
|
|
80
|
+
collisionRect: collisionRect,
|
|
81
|
+
droppableRects,
|
|
82
|
+
droppableContainers: filteredContainers,
|
|
83
|
+
pointerCoordinates: null,
|
|
84
|
+
});
|
|
85
|
+
const closestId = getFirstCollision(collisions, 'id');
|
|
86
|
+
|
|
87
|
+
if (closestId != null) {
|
|
88
|
+
const newDroppable = droppableContainers.get(closestId);
|
|
89
|
+
const newNode = newDroppable?.node.current;
|
|
90
|
+
const newRect = newDroppable?.rect.current;
|
|
91
|
+
|
|
92
|
+
if (newNode && newRect) {
|
|
93
|
+
if (newDroppable.id === 'placeholder') {
|
|
94
|
+
return {
|
|
95
|
+
x: newRect.left + (newRect.width - collisionRect.width) / 2,
|
|
96
|
+
y: newRect.top + (newRect.height - collisionRect.height) / 2,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (newDroppable.data.current?.type === 'container') {
|
|
101
|
+
return {
|
|
102
|
+
x: newRect.left + 20,
|
|
103
|
+
y: newRect.top + 74,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
x: newRect.left,
|
|
109
|
+
y: newRect.top,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components'
|
package/src/meta.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-08-31 16:32:35
|
|
4
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
+
* @LastEditTime: 2022-09-01 18:46:29
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
8
|
+
import MultipleContainers from "./metas/MultipleContainers";
|
|
9
|
+
const components = [MultipleContainers];
|
|
10
|
+
const componentList = [
|
|
11
|
+
{
|
|
12
|
+
title: "Steedos",
|
|
13
|
+
icon: "",
|
|
14
|
+
children: [MultipleContainers]
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
export default {
|
|
18
|
+
componentList,
|
|
19
|
+
components
|
|
20
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const config: any = {
|
|
2
|
+
group: "华炎魔方",
|
|
3
|
+
componentName: "MultipleContainers",
|
|
4
|
+
title: "容器排序",
|
|
5
|
+
docUrl: "",
|
|
6
|
+
screenshot: "",
|
|
7
|
+
npm: {
|
|
8
|
+
package: "@steedos-widgets/sortable",
|
|
9
|
+
version: "{{version}}",
|
|
10
|
+
exportName: "MultipleContainers",
|
|
11
|
+
main: "",
|
|
12
|
+
destructuring: true,
|
|
13
|
+
subName: ""
|
|
14
|
+
},
|
|
15
|
+
// props: [
|
|
16
|
+
// {
|
|
17
|
+
// name: "title",
|
|
18
|
+
// propType: "string",
|
|
19
|
+
// description: '标题',
|
|
20
|
+
// }
|
|
21
|
+
// ],
|
|
22
|
+
preview: {
|
|
23
|
+
},
|
|
24
|
+
targets: ["steedos__RecordPage", "steedos__AppPage", "steedos__HomePage"],
|
|
25
|
+
engines: ["amis"],
|
|
26
|
+
// settings for amis.
|
|
27
|
+
amis: {
|
|
28
|
+
name: 'sortable-multiple-containers',
|
|
29
|
+
icon: "fa-fw fa fa-list-alt"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
...config,
|
|
35
|
+
snippets: [
|
|
36
|
+
{
|
|
37
|
+
title: config.title,
|
|
38
|
+
screenshot: "",
|
|
39
|
+
schema: {
|
|
40
|
+
componentName: config.componentName,
|
|
41
|
+
props: config.preview
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
amis: {
|
|
46
|
+
render: {
|
|
47
|
+
type: config.amis.name,
|
|
48
|
+
usage: "formitem",
|
|
49
|
+
weight: 1,
|
|
50
|
+
framework: "react"
|
|
51
|
+
},
|
|
52
|
+
plugin: {
|
|
53
|
+
rendererName: config.amis.name,
|
|
54
|
+
$schema: '/schemas/UnkownSchema.json',
|
|
55
|
+
name: config.title,
|
|
56
|
+
description: config.title,
|
|
57
|
+
tags: [config.group],
|
|
58
|
+
order: -9999,
|
|
59
|
+
icon: config.amis.icon,
|
|
60
|
+
scaffold: {
|
|
61
|
+
type: config.amis.name,
|
|
62
|
+
label: config.title,
|
|
63
|
+
name: 'board',
|
|
64
|
+
columns: 1,
|
|
65
|
+
vertical: false,
|
|
66
|
+
"value": {
|
|
67
|
+
"A": [
|
|
68
|
+
"A1",
|
|
69
|
+
"B1"
|
|
70
|
+
],
|
|
71
|
+
"B": [
|
|
72
|
+
"A2",
|
|
73
|
+
"B2"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"containerSource": [
|
|
77
|
+
{
|
|
78
|
+
"id": "A",
|
|
79
|
+
"label": "Board A"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "B",
|
|
83
|
+
"label": "Board B"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"itemSource": [
|
|
87
|
+
{
|
|
88
|
+
"id": "A1",
|
|
89
|
+
"label": "Item A1",
|
|
90
|
+
"columnSpan": 2,
|
|
91
|
+
"color": "red"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "A2",
|
|
95
|
+
"label": "Item A2",
|
|
96
|
+
"columnSpan": 1,
|
|
97
|
+
"color": "blue"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "B1",
|
|
101
|
+
"label": "Item B1",
|
|
102
|
+
"color": "green"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"id": "B2",
|
|
106
|
+
"label": "Item B2",
|
|
107
|
+
"color": "silver"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
previewSchema: {
|
|
112
|
+
type: config.amis.name,
|
|
113
|
+
},
|
|
114
|
+
panelTitle: "设置",
|
|
115
|
+
panelControls: [,
|
|
116
|
+
{
|
|
117
|
+
"name": "columns",
|
|
118
|
+
"type": "input-number",
|
|
119
|
+
"label": "列数",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "vertical",
|
|
123
|
+
"type": "checkbox",
|
|
124
|
+
"label": "布局",
|
|
125
|
+
"option": "纵向"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Declare global variables for TypeScript and VSCode.
|
|
2
|
+
// Do not rename this file or move these types into index.d.ts
|
|
3
|
+
// @see https://code.visualstudio.com/docs/nodejs/working-with-javascript#_global-variables-and-type-checking
|
|
4
|
+
declare const __DEV__: boolean;
|
|
5
|
+
declare const __VERSION__: string;
|
|
6
|
+
declare const $FixMe: any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const defaultInitializer = (index: number) => index;
|
|
2
|
+
|
|
3
|
+
export function createRange<T = number>(
|
|
4
|
+
length: number,
|
|
5
|
+
initializer: (index: number) => any = defaultInitializer
|
|
6
|
+
): T[] {
|
|
7
|
+
let array = [];
|
|
8
|
+
let index = 0;
|
|
9
|
+
|
|
10
|
+
while(index < length){
|
|
11
|
+
array.push(initializer(index));
|
|
12
|
+
index++;
|
|
13
|
+
}
|
|
14
|
+
return array;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {createRange} from './createRange';
|