sample-ui-component-library 0.0.10-dev → 0.0.11-dev

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-ui-component-library",
3
- "version": "0.0.10-dev",
3
+ "version": "0.0.11-dev",
4
4
  "description": "A library which contains sample UI elements that can be used for populating layouts.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -30,7 +30,8 @@ export const Tab = ({ id, parentId, node }) => {
30
30
  data: {
31
31
  type: "EditorTab",
32
32
  parentId: parentId,
33
- node: node
33
+ node: node,
34
+ preview: <TabPreview node={node} />
34
35
  },
35
36
  });
36
37
 
@@ -80,10 +81,12 @@ Tab.propTypes = {
80
81
  }
81
82
 
82
83
 
83
- export const TabPreview = ({info}) => {
84
+ export const TabPreview = ({node}) => {
84
85
  return (
85
86
  <div className="tab" style={{ backgroundColor: ACTIVE_TAB_BG_COLOR, color: ACTIVE_TAB_FG_COLOR, opacity:0.5 }}>
86
- <FileEarmark className="icon" />{info.label}<XLg className="close-icon"/>
87
+ <FileEarmark className="icon" />
88
+ <span className="tab-name">{node.name}</span>
89
+ <XLg className="close-icon"/>
87
90
  </div>
88
91
  );
89
92
  }
@@ -23,7 +23,8 @@ export const TreeNode = ({ id, node }) => {
23
23
  id,
24
24
  data: {
25
25
  type: "FileTreeNode",
26
- node: node
26
+ node: node,
27
+ preview: <TreeNodePreview node={node}/ >
27
28
  }
28
29
  }
29
30
  );
@@ -95,7 +96,7 @@ export const TreeNode = ({ id, node }) => {
95
96
 
96
97
  export const TreeNodePreview = ({node}) => {
97
98
  return (
98
- <div className="file-node-row">
99
+ <div className="file-node-row" >
99
100
  <span className="file-name">{node.name}</span>
100
101
  </div>
101
102
  );
@@ -63,29 +63,53 @@ const Template = (args) => {
63
63
  editorRef.current.addTab(node,2);
64
64
  }, []);
65
65
 
66
- const onDragStart = (event) => {
67
- console.log("");
68
- console.log("Drag Started");
69
- const dragPreview = editorRef.current.getPreviewElement(event.active.data.current.node.uid);
70
- setDragPreviewLabel(dragPreview);
71
- }
72
-
66
+ const [dragging, setDragging] = useState(false);
67
+
68
+ /**
69
+ * Callback for when drag ends.
70
+ */
73
71
  const handleDragEnd = (event) =>{
74
72
  const { active, over } = event;
73
+ console.log("Drag Ended");
74
+ const rect = event.activatorEvent;
75
+
76
+ console.log(active, over);
75
77
 
76
78
  if (over) {
77
- console.log("Dragged item:", active);
78
- console.log("Dropped on:", over);
79
+ console.log("Dragged item:", active.id);
80
+ console.log("Dropped on:", over.id);
79
81
  } else {
80
82
  console.log("Dropped outside any droppable");
81
- return;
82
83
  }
84
+ setDragging(false);
85
+ }
83
86
 
84
- if (active.data.current.type === "EditorTab" && over.data.current.type === "EditorTabGutter") {
85
- editorRef.current.moveTab(active.data.current.node.uid, over.data.current.index);
86
- }
87
+ /**
88
+ * Callback for when drag is started.
89
+ */
90
+ const onDragStart = (event) => {
91
+ console.log("Drag Started");
92
+ console.log(event.active.data);
93
+ setDragPreviewLabel(event.active.data.current.preview);
94
+ setDragging(true);
87
95
  }
88
96
 
97
+ // Manually track the drag position.
98
+ const [pos, setPos] = useState({ x: 0, y: 0 });
99
+ useEffect(() => {
100
+ if (!dragging) return;
101
+
102
+ const handleMove = (e) => {
103
+ setPos({ x: e.clientX, y: e.clientY });
104
+ };
105
+
106
+ window.addEventListener("pointermove", handleMove);
107
+
108
+ return () => {
109
+ window.removeEventListener("pointermove", handleMove);
110
+ };
111
+ }, [dragging]);
112
+
89
113
  const sensors = useSensors(
90
114
  useSensor(PointerSensor, {
91
115
  activationConstraint: {
@@ -99,9 +123,18 @@ const Template = (args) => {
99
123
  <div className="editorStoryWrapper">
100
124
  <Editor ref={editorRef}{...args} />
101
125
  </div>
102
- <DragOverlay modifiers={[offsetOverlay]} dropAnimation={null}>
103
- {dragPreviewLabel}
104
- </DragOverlay>
126
+ {dragging && (
127
+ <div
128
+ style={{
129
+ position: "fixed",
130
+ left: pos.x,
131
+ top: pos.y,
132
+ pointerEvents: "none",
133
+ zIndex: 9999,
134
+ }}>
135
+ {dragPreviewLabel}
136
+ </div>
137
+ )}
105
138
  </DndContext>
106
139
  )
107
140
  }
@@ -54,6 +54,9 @@ const Template = (args) => {
54
54
  }, 3000);
55
55
  }, []);
56
56
 
57
+
58
+ const [dragging, setDragging] = useState(false);
59
+
57
60
  /**
58
61
  * Callback for when drag ends.
59
62
  */
@@ -62,7 +65,7 @@ const Template = (args) => {
62
65
  console.log("Drag Ended");
63
66
  const rect = event.activatorEvent;
64
67
 
65
- console.log(over );
68
+ console.log(active, over);
66
69
 
67
70
  if (over) {
68
71
  console.log("Dragged item:", active.id);
@@ -70,6 +73,7 @@ const Template = (args) => {
70
73
  } else {
71
74
  console.log("Dropped outside any droppable");
72
75
  }
76
+ setDragging(false);
73
77
  }
74
78
 
75
79
  /**
@@ -77,10 +81,28 @@ const Template = (args) => {
77
81
  */
78
82
  const onDragStart = (event) => {
79
83
  console.log("Drag Started");
84
+ console.log(event.active.data);
80
85
  const dragPreview = fileBrowserRef.current.getPreviewElement(event.active.data.current.node.uid);
81
- setDragPreviewLabel(dragPreview);
86
+ setDragPreviewLabel(event.active.data.current.preview);
87
+ setDragging(true);
82
88
  }
83
89
 
90
+ // Manually track the drag position.
91
+ const [pos, setPos] = useState({ x: 0, y: 0 });
92
+ useEffect(() => {
93
+ if (!dragging) return;
94
+
95
+ const handleMove = (e) => {
96
+ setPos({ x: e.clientX, y: e.clientY });
97
+ };
98
+
99
+ window.addEventListener("pointermove", handleMove);
100
+
101
+ return () => {
102
+ window.removeEventListener("pointermove", handleMove);
103
+ };
104
+ }, [dragging]);
105
+
84
106
  const sensors = useSensors(
85
107
  useSensor(PointerSensor, {
86
108
  activationConstraint: {
@@ -96,9 +118,18 @@ const Template = (args) => {
96
118
  <FileBrowser ref={fileBrowserRef} {...args} />
97
119
  </div>
98
120
  </div>
99
- <DragOverlay modifiers={[offsetOverlay]} dropAnimation={null}>
100
- {dragPreviewLabel}
101
- </DragOverlay>
121
+ {dragging && (
122
+ <div
123
+ style={{
124
+ position: "fixed",
125
+ left: pos.x,
126
+ top: pos.y,
127
+ pointerEvents: "none",
128
+ zIndex: 9999,
129
+ }}>
130
+ {dragPreviewLabel}
131
+ </div>
132
+ )}
102
133
  </DndContext>
103
134
  )
104
135
  }