sample-ui-component-library 0.0.55-dev → 0.0.56-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.55-dev",
3
+ "version": "0.0.56-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",
@@ -28,7 +28,7 @@ const MODES = {
28
28
  *
29
29
  * @return {JSX}
30
30
  */
31
- export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) => {
31
+ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab, onUpdateContent }, ref) => {
32
32
  const [state, dispatch] = useReducer(editorReducer, initialState);
33
33
  const editorRef = useRef();
34
34
 
@@ -83,12 +83,19 @@ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) =>
83
83
 
84
84
  const setUpdatedContent = useCallback((tab, content) => {
85
85
  dispatch({ type: "SET_UPDATED_CONTENT", payload: {tab, content} });
86
- }, []);
86
+ if (onUpdateContent) {
87
+ onUpdateContent(tab, content);
88
+ }
89
+ }, [onUpdateContent]);
87
90
 
88
91
  const setContent = useCallback((tab, content) => {
89
92
  dispatch({ type: "SET_CONTENT", payload: {tab, content} });
90
93
  }, []);
91
94
 
95
+ const saveAll = useCallback(() => {
96
+ dispatch({ type: "SAVE_ALL", payload: {} });
97
+ }, []);
98
+
92
99
  const api_entries = {
93
100
  state,
94
101
  addTab,
@@ -103,7 +110,8 @@ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab }, ref) =>
103
110
  getTabs,
104
111
  getActiveTab,
105
112
  setUpdatedContent,
106
- setContent
113
+ setContent,
114
+ saveAll
107
115
  }
108
116
 
109
117
  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.setMode(EDITOR_MODES.DESIGN);
150
+ editorRef.current.saveAll();
151
151
  }
152
152
  }, [editorRef]);
153
153
 
@@ -161,6 +161,11 @@ 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, content);
167
+ }, []);
168
+
164
169
  return (
165
170
  <DndContext sensors={sensors} onDragStart={onDragStart} onDragEnd={handleDragEnd}>
166
171
 
@@ -169,7 +174,7 @@ const Template = (args) => {
169
174
  <ToolBarEditor onSelectTool={onSelectTool} />
170
175
  </div>
171
176
  <div className="flow">
172
- <Editor ref={editorRef} onSelectAbstraction={onSelectAbstraction} {...args} />
177
+ <Editor ref={editorRef} onUpdateContent={onUpdateContent} onSelectAbstraction={onSelectAbstraction} {...args} />
173
178
  {dragging && (
174
179
  <div
175
180
  style={{