Skip to content

Commit 937ee12

Browse files
update canvas to response to selected layer
1 parent 263f3c7 commit 937ee12

1 file changed

Lines changed: 41 additions & 36 deletions

File tree

editor/scaffolds/editor/editor.tsx

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ export function Editor() {
9090
}, [state.design?.key, fat]);
9191

9292
useEffect(() => {
93-
if (targetted && framework_config) {
93+
const __target = targetted;
94+
if (__target && framework_config) {
9495
const _input = {
95-
id: targetted.id,
96-
name: targetted.name,
97-
entry: targetted,
96+
id: __target.id,
97+
name: __target.name,
98+
entry: __target,
9899
repository: root.repository,
99100
};
100101
const build_config = {
@@ -126,41 +127,45 @@ export function Editor() {
126127
}
127128
}, [targetted?.id, framework_config?.framework]);
128129

129-
useEffect(() => {
130-
if (root) {
131-
const { id, name } = root.entry;
132-
const _input = {
133-
id: id,
134-
name: name,
135-
entry: root.entry,
136-
};
137-
const build_config = {
138-
...config.default_build_configuration,
139-
disable_components: true,
140-
};
130+
useEffect(
131+
() => {
132+
const __target = targetted; // root.entry;
133+
if (__target) {
134+
const _input = {
135+
id: __target.id,
136+
name: __target.name,
137+
entry: __target,
138+
};
139+
const build_config = {
140+
...config.default_build_configuration,
141+
disable_components: true,
142+
};
141143

142-
const on_preview_result = (result: Result) => {
143-
if (result.id == targetId) {
144-
setPreview(result);
145-
}
146-
};
144+
const on_preview_result = (result: Result) => {
145+
if (result.id == targetId) {
146+
setPreview(result);
147+
}
148+
};
147149

148-
// ----- for preview -----
149-
designToCode({
150-
input: _input,
151-
build_config: build_config,
152-
framework: vanilla_presets.vanilla_default,
153-
asset_config: { skip_asset_replacement: true },
154-
}).then(on_preview_result);
150+
// ----- for preview -----
151+
designToCode({
152+
input: _input,
153+
build_config: build_config,
154+
framework: vanilla_presets.vanilla_default,
155+
asset_config: { skip_asset_replacement: true },
156+
}).then(on_preview_result);
155157

156-
designToCode({
157-
input: root,
158-
build_config: build_config,
159-
framework: vanilla_presets.vanilla_default,
160-
asset_config: { asset_repository: MainImageRepository.instance },
161-
}).then(on_preview_result);
162-
}
163-
}, [root?.id]);
158+
designToCode({
159+
input: root,
160+
build_config: build_config,
161+
framework: vanilla_presets.vanilla_default,
162+
asset_config: { asset_repository: MainImageRepository.instance },
163+
}).then(on_preview_result);
164+
}
165+
},
166+
[targetted?.id]
167+
// [root?.id]
168+
);
164169

165170
const { code, scaffold, name: componentName } = result ?? {};
166171

0 commit comments

Comments
 (0)