@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.
Files changed (72) hide show
  1. package/.env +1 -0
  2. package/.env.local +8 -0
  3. package/dist/assets-dev.json +25 -0
  4. package/dist/assets.json +25 -0
  5. package/dist/components/MultipleContainers.d.ts +7 -0
  6. package/dist/components/components/Container/Container.d.ts +17 -0
  7. package/dist/components/components/Container/index.d.ts +2 -0
  8. package/dist/components/components/Grid/Grid.d.ts +7 -0
  9. package/dist/components/components/Grid/index.d.ts +1 -0
  10. package/dist/components/components/GridContainer/GridContainer.d.ts +6 -0
  11. package/dist/components/components/GridContainer/index.d.ts +1 -0
  12. package/dist/components/components/Item/Item.d.ts +37 -0
  13. package/dist/components/components/Item/components/Action/Action.d.ts +9 -0
  14. package/dist/components/components/Item/components/Action/index.d.ts +2 -0
  15. package/dist/components/components/Item/components/Handle/Handle.d.ts +3 -0
  16. package/dist/components/components/Item/components/Handle/index.d.ts +1 -0
  17. package/dist/components/components/Item/components/Remove/Remove.d.ts +3 -0
  18. package/dist/components/components/Item/components/Remove/index.d.ts +1 -0
  19. package/dist/components/components/Item/components/index.d.ts +3 -0
  20. package/dist/components/components/Item/index.d.ts +2 -0
  21. package/dist/components/components/index.d.ts +5 -0
  22. package/dist/components/index.d.ts +1 -0
  23. package/dist/components/multipleContainersKeyboardCoordinates.d.ts +2 -0
  24. package/dist/index.d.ts +1 -0
  25. package/dist/meta.d.ts +9 -0
  26. package/dist/meta.js +180 -0
  27. package/dist/metas/MultipleContainers.d.ts +2 -0
  28. package/dist/sortable.cjs.css +335 -0
  29. package/dist/sortable.cjs.js +56525 -0
  30. package/dist/sortable.cjs.js.map +1 -0
  31. package/dist/sortable.esm.css +335 -0
  32. package/dist/sortable.esm.js +56521 -0
  33. package/dist/sortable.esm.js.map +1 -0
  34. package/dist/sortable.umd.css +335 -0
  35. package/dist/sortable.umd.js +22829 -0
  36. package/dist/utilities/createRange.d.ts +1 -0
  37. package/dist/utilities/index.d.ts +1 -0
  38. package/package.json +51 -0
  39. package/rollup.config.ts +109 -0
  40. package/src/assets.json +25 -0
  41. package/src/components/MultipleContainers.tsx +802 -0
  42. package/src/components/components/Container/Container.module.css +103 -0
  43. package/src/components/components/Container/Container.tsx +83 -0
  44. package/src/components/components/Container/index.ts +2 -0
  45. package/src/components/components/Grid/Grid.module.css +30 -0
  46. package/src/components/components/Grid/Grid.tsx +22 -0
  47. package/src/components/components/Grid/index.ts +1 -0
  48. package/src/components/components/GridContainer/GridContainer.module.css +15 -0
  49. package/src/components/components/GridContainer/GridContainer.tsx +23 -0
  50. package/src/components/components/GridContainer/index.ts +1 -0
  51. package/src/components/components/Item/Item.module.css +145 -0
  52. package/src/components/components/Item/Item.tsx +157 -0
  53. package/src/components/components/Item/components/Action/Action.module.css +50 -0
  54. package/src/components/components/Item/components/Action/Action.tsx +33 -0
  55. package/src/components/components/Item/components/Action/index.ts +2 -0
  56. package/src/components/components/Item/components/Handle/Handle.tsx +20 -0
  57. package/src/components/components/Item/components/Handle/index.ts +1 -0
  58. package/src/components/components/Item/components/Remove/Remove.tsx +19 -0
  59. package/src/components/components/Item/components/Remove/index.ts +1 -0
  60. package/src/components/components/Item/components/index.ts +3 -0
  61. package/src/components/components/Item/index.ts +2 -0
  62. package/src/components/components/index.ts +6 -0
  63. package/src/components/index.ts +1 -0
  64. package/src/components/multipleContainersKeyboardCoordinates.ts +116 -0
  65. package/src/index.ts +1 -0
  66. package/src/meta.ts +20 -0
  67. package/src/metas/MultipleContainers.tsx +131 -0
  68. package/src/types/css.d.ts +4 -0
  69. package/src/types/global.d.ts +6 -0
  70. package/src/utilities/createRange.ts +15 -0
  71. package/src/utilities/index.ts +1 -0
  72. 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,3 @@
1
+ export {Action} from './Action';
2
+ export {Handle} from './Handle';
3
+ export {Remove} from './Remove';
@@ -0,0 +1,2 @@
1
+ export {Item} from './Item';
2
+ export {Action, Handle, Remove} from './components';
@@ -0,0 +1,6 @@
1
+
2
+ export {Grid} from './Grid';
3
+ export {GridContainer} from './GridContainer';
4
+ export {Container} from './Container';
5
+ export type {ContainerProps} from './Container';
6
+ export {Item} from './Item';
@@ -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,4 @@
1
+ declare module '*.module.css' {
2
+ const content: {[key: string]: string};
3
+ export default content;
4
+ }
@@ -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';
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "./",
5
+ "declarationDir": "dist/types",
6
+ "declaration": true,
7
+ "outDir": "dist/cjs"
8
+ },
9
+ "include": ["src"],
10
+ "exclude": ["dist"]
11
+ }