sample-ui-component-library 0.0.55-dev → 0.0.57-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 +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Editor/Editor.jsx +19 -6
- package/src/components/Editor/EditorReducer.js +14 -0
- package/src/stories/Editor.stories.js +11 -2
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import React, {
|
|
|
12
12
|
useReducer,
|
|
13
13
|
useContext,
|
|
14
14
|
useRef,
|
|
15
|
+
useEffect
|
|
15
16
|
} from "react";
|
|
16
17
|
|
|
17
18
|
import { EditorContext } from "./EditorContext";
|
|
@@ -28,15 +29,19 @@ const MODES = {
|
|
|
28
29
|
*
|
|
29
30
|
* @return {JSX}
|
|
30
31
|
*/
|
|
31
|
-
export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) => {
|
|
32
|
+
export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab, onUpdateContent }, ref) => {
|
|
32
33
|
const [state, dispatch] = useReducer(editorReducer, initialState);
|
|
33
34
|
const editorRef = useRef();
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
dispatch({ type: "SELECT_TAB", payload: id });
|
|
36
|
+
useEffect(() => {
|
|
37
37
|
if (onSelectTab) {
|
|
38
|
-
|
|
38
|
+
console.log(state.activeTab);
|
|
39
|
+
onSelectTab(state.activeTab);
|
|
39
40
|
}
|
|
41
|
+
}, [state.activeTab]);
|
|
42
|
+
|
|
43
|
+
const selectTab = useCallback((id) => {
|
|
44
|
+
dispatch({ type: "SELECT_TAB", payload: id });
|
|
40
45
|
}, [onSelectTab]);
|
|
41
46
|
|
|
42
47
|
const closeTab = useCallback((id) => {
|
|
@@ -83,12 +88,19 @@ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) =>
|
|
|
83
88
|
|
|
84
89
|
const setUpdatedContent = useCallback((tab, content) => {
|
|
85
90
|
dispatch({ type: "SET_UPDATED_CONTENT", payload: {tab, content} });
|
|
86
|
-
|
|
91
|
+
if (onUpdateContent) {
|
|
92
|
+
onUpdateContent(tab, content);
|
|
93
|
+
}
|
|
94
|
+
}, [onUpdateContent]);
|
|
87
95
|
|
|
88
96
|
const setContent = useCallback((tab, content) => {
|
|
89
97
|
dispatch({ type: "SET_CONTENT", payload: {tab, content} });
|
|
90
98
|
}, []);
|
|
91
99
|
|
|
100
|
+
const saveAll = useCallback(() => {
|
|
101
|
+
dispatch({ type: "SAVE_ALL", payload: {} });
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
92
104
|
const api_entries = {
|
|
93
105
|
state,
|
|
94
106
|
addTab,
|
|
@@ -103,7 +115,8 @@ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) =>
|
|
|
103
115
|
getTabs,
|
|
104
116
|
getActiveTab,
|
|
105
117
|
setUpdatedContent,
|
|
106
|
-
setContent
|
|
118
|
+
setContent,
|
|
119
|
+
saveAll
|
|
107
120
|
}
|
|
108
121
|
|
|
109
122
|
const api = useMemo(() => {
|
|
@@ -163,6 +163,20 @@ export const editorReducer = (state, action) => {
|
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
case "SAVE_ALL": {
|
|
167
|
+
const newTabs = state.tabs.map(tab => {
|
|
168
|
+
tab.content = tab.updatedContent;
|
|
169
|
+
tab.isDirty = false;
|
|
170
|
+
return tab;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
...state,
|
|
175
|
+
modifiedIndicator: !state.modifiedIndicator,
|
|
176
|
+
tabs: newTabs
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
166
180
|
default: {
|
|
167
181
|
return state;
|
|
168
182
|
}
|
|
@@ -147,7 +147,7 @@ const Template = (args) => {
|
|
|
147
147
|
flattenTree(WorkspaceSampleTree.tree).slice(2,2)
|
|
148
148
|
);
|
|
149
149
|
} else if (tool === "implementation-mode") {
|
|
150
|
-
editorRef.current.
|
|
150
|
+
editorRef.current.saveAll();
|
|
151
151
|
}
|
|
152
152
|
}, [editorRef]);
|
|
153
153
|
|
|
@@ -161,6 +161,15 @@ const Template = (args) => {
|
|
|
161
161
|
editorRef.current.setMappedIds(newMap);
|
|
162
162
|
}, [mappedIds, setMappedIds, editorRef]);
|
|
163
163
|
|
|
164
|
+
|
|
165
|
+
const onUpdateContent = useCallback((tab, content) => {
|
|
166
|
+
action("Content Updated")(tab.name + " was modified.");
|
|
167
|
+
}, []);
|
|
168
|
+
|
|
169
|
+
const onSelectTab = useCallback((tab) => {
|
|
170
|
+
action("Tab Selected")(tab&&tab.name);
|
|
171
|
+
}, []);
|
|
172
|
+
|
|
164
173
|
return (
|
|
165
174
|
<DndContext sensors={sensors} onDragStart={onDragStart} onDragEnd={handleDragEnd}>
|
|
166
175
|
|
|
@@ -169,7 +178,7 @@ const Template = (args) => {
|
|
|
169
178
|
<ToolBarEditor onSelectTool={onSelectTool} />
|
|
170
179
|
</div>
|
|
171
180
|
<div className="flow">
|
|
172
|
-
<Editor ref={editorRef} onSelectAbstraction={onSelectAbstraction} {...args} />
|
|
181
|
+
<Editor ref={editorRef} onSelectTab={onSelectTab} onUpdateContent={onUpdateContent} onSelectAbstraction={onSelectAbstraction} {...args} />
|
|
173
182
|
{dragging && (
|
|
174
183
|
<div
|
|
175
184
|
style={{
|