sample-ui-component-library 0.0.50-dev → 0.0.51-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/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Editor/Editor.jsx +9 -4
- package/src/components/Editor/EditorReducer.js +9 -1
- package/src/components/Editor/MonacoInstance/MonacoInstance.jsx +20 -7
- package/src/stories/Editor.stories.js +16 -1
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ const MODES = {
|
|
|
27
27
|
*
|
|
28
28
|
* @return {JSX}
|
|
29
29
|
*/
|
|
30
|
-
export const Editor = forwardRef(({ }, ref) => {
|
|
30
|
+
export const Editor = forwardRef(({ onSelectAbstraction }, ref) => {
|
|
31
31
|
const [state, dispatch] = useReducer(editorReducer, initialState);
|
|
32
32
|
|
|
33
33
|
const selectTab = useCallback((id) => {
|
|
@@ -59,6 +59,10 @@ export const Editor = forwardRef(({ }, ref) => {
|
|
|
59
59
|
dispatch({ type: "SET_MODE", payload: mode });
|
|
60
60
|
}, []);
|
|
61
61
|
|
|
62
|
+
const setMappedIds = useCallback((ids) => {
|
|
63
|
+
dispatch({ type: "SET_MAPPED_IDS", payload: ids });
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
62
66
|
const api = useMemo(() => {
|
|
63
67
|
return {
|
|
64
68
|
state,
|
|
@@ -68,9 +72,10 @@ export const Editor = forwardRef(({ }, ref) => {
|
|
|
68
72
|
closeTab,
|
|
69
73
|
moveTab,
|
|
70
74
|
setMapping,
|
|
71
|
-
setMode
|
|
75
|
+
setMode,
|
|
76
|
+
setMappedIds
|
|
72
77
|
};
|
|
73
|
-
}, [state, addTab, selectTab, closeTab, moveTab, setTabGroupId, setMapping, setMode]);
|
|
78
|
+
}, [state, addTab, selectTab, closeTab, moveTab, setTabGroupId, setMapping, setMode, setMappedIds]);
|
|
74
79
|
|
|
75
80
|
useImperativeHandle(ref, () => api, [api]);
|
|
76
81
|
|
|
@@ -81,7 +86,7 @@ export const Editor = forwardRef(({ }, ref) => {
|
|
|
81
86
|
<Tabs />
|
|
82
87
|
</div>
|
|
83
88
|
<div className="monacoContainer">
|
|
84
|
-
<MonacoInstance />
|
|
89
|
+
<MonacoInstance onSelectAbstraction={onSelectAbstraction}/>
|
|
85
90
|
</div>
|
|
86
91
|
</div>
|
|
87
92
|
</EditorContext.Provider>
|
|
@@ -6,7 +6,8 @@ export const initialState = {
|
|
|
6
6
|
activeTab: null,
|
|
7
7
|
mode: EDITOR_MODES.DESIGN,
|
|
8
8
|
mapping: new Map(),
|
|
9
|
-
parentTabGroupId: null
|
|
9
|
+
parentTabGroupId: null,
|
|
10
|
+
mappedIds: []
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export const editorReducer = (state, action) => {
|
|
@@ -121,6 +122,13 @@ export const editorReducer = (state, action) => {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
case "SET_MAPPED_IDS": {
|
|
126
|
+
return {
|
|
127
|
+
...state,
|
|
128
|
+
mappedIds: action.payload
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
124
132
|
case "RESET_STATE": {
|
|
125
133
|
return initialState;
|
|
126
134
|
}
|
|
@@ -9,7 +9,7 @@ import "./MonacoInstance.scss"
|
|
|
9
9
|
|
|
10
10
|
import { useEditor } from "../Editor";
|
|
11
11
|
|
|
12
|
-
export const MonacoInstance = ({
|
|
12
|
+
export const MonacoInstance = ({onSelectAbstraction}) => {
|
|
13
13
|
const { state } = useEditor();
|
|
14
14
|
const [editorContent, setEditorContent] = useState("Loading content...");
|
|
15
15
|
const [showEditor, setShowEditor] = useState(false);
|
|
@@ -29,7 +29,7 @@ export const MonacoInstance = ({ }) => {
|
|
|
29
29
|
} else {
|
|
30
30
|
setShowEditor(false);
|
|
31
31
|
}
|
|
32
|
-
}, [state
|
|
32
|
+
}, [state, editorRef]);
|
|
33
33
|
|
|
34
34
|
useEffect(() => {
|
|
35
35
|
content.current = editorContent;
|
|
@@ -67,16 +67,29 @@ export const MonacoInstance = ({ }) => {
|
|
|
67
67
|
const divs = [];
|
|
68
68
|
|
|
69
69
|
ranges.forEach((entry) => {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const top = editorRef.current.getTopForLineNumber(entry.start_line) - editorRef.current.getScrollTop();
|
|
71
|
+
let bottom = editorRef.current.getTopForLineNumber(entry.end_line + 1) - editorRef.current.getScrollTop();
|
|
72
72
|
if (entry.end_line >= lineCount) {
|
|
73
73
|
bottom = bottom + lineHeight;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
|
|
76
|
+
const style= {
|
|
77
|
+
top: top + "px",
|
|
78
|
+
height: (bottom - top) + "px"
|
|
79
|
+
}
|
|
80
|
+
if (state.mappedIds.includes(entry.uid)) {
|
|
81
|
+
style["backgroundColor"] = "rgba(255, 0, 0, 0.3)";
|
|
82
|
+
}
|
|
83
|
+
const overlayDiv = <div
|
|
84
|
+
className="line-block-overlay"
|
|
85
|
+
onClick={(e) => onSelectAbstraction(entry)}
|
|
86
|
+
style={style}>
|
|
87
|
+
</div>;
|
|
88
|
+
divs.push(overlayDiv);
|
|
89
|
+
|
|
77
90
|
});
|
|
78
91
|
setOverlayDivs(divs);
|
|
79
|
-
}, [editorRef?.current, state]);
|
|
92
|
+
}, [editorRef?.current, state, onSelectAbstraction]);
|
|
80
93
|
|
|
81
94
|
// Scroll the editor and update overlays on wheel event.
|
|
82
95
|
const handleWheel = useCallback((e) => {
|
|
@@ -46,6 +46,10 @@ const Template = (args) => {
|
|
|
46
46
|
|
|
47
47
|
const [dragPreviewLabel, setDragPreviewLabel] = useState(<></>);
|
|
48
48
|
const [selectTool, setSelectTool] = useState("select");
|
|
49
|
+
const [mappedIds, setMappedIds] = useState([
|
|
50
|
+
"c4f43010-71ef-46e6-bf38-0548d3a34012",
|
|
51
|
+
"8bf2605a-1940-49de-9b2f-0efa22bf658c"
|
|
52
|
+
]);
|
|
49
53
|
|
|
50
54
|
const editorRef = useRef();
|
|
51
55
|
|
|
@@ -63,6 +67,7 @@ const Template = (args) => {
|
|
|
63
67
|
editorRef.current.addTab(result);translator_mapping
|
|
64
68
|
editorRef.current.setMapping("TransactionDB.py", transactiondb_mapping);
|
|
65
69
|
editorRef.current.setMapping("FrenchTranslator.py", translator_mapping);
|
|
70
|
+
editorRef.current.setMappedIds(mappedIds);
|
|
66
71
|
}, []);
|
|
67
72
|
|
|
68
73
|
const [dragging, setDragging] = useState(false);
|
|
@@ -139,6 +144,16 @@ const Template = (args) => {
|
|
|
139
144
|
}
|
|
140
145
|
}, [editorRef]);
|
|
141
146
|
|
|
147
|
+
const onSelectAbstraction = useCallback((entry) => {
|
|
148
|
+
action("Abstraction Selected")(entry);
|
|
149
|
+
const found = mappedIds.find((id) => id === entry.uid);
|
|
150
|
+
const newMap = (found)?
|
|
151
|
+
mappedIds.filter((id) => id !== found):
|
|
152
|
+
[...mappedIds, entry.uid];
|
|
153
|
+
setMappedIds(newMap);
|
|
154
|
+
editorRef.current.setMappedIds(newMap);
|
|
155
|
+
}, [mappedIds, setMappedIds, editorRef]);
|
|
156
|
+
|
|
142
157
|
return (
|
|
143
158
|
<DndContext sensors={sensors} onDragStart={onDragStart} onDragEnd={handleDragEnd}>
|
|
144
159
|
|
|
@@ -147,7 +162,7 @@ const Template = (args) => {
|
|
|
147
162
|
<ToolBarEditor onSelectTool={onSelectTool} />
|
|
148
163
|
</div>
|
|
149
164
|
<div className="flow">
|
|
150
|
-
<Editor ref={editorRef}{...args} />
|
|
165
|
+
<Editor ref={editorRef} onSelectAbstraction={onSelectAbstraction} {...args} />
|
|
151
166
|
{dragging && (
|
|
152
167
|
<div
|
|
153
168
|
style={{
|