fix(editor): keep html panel identity on upload refresh

This commit is contained in:
plum 2026-04-13 15:04:32 +08:00
parent 5368e52f0d
commit 985c8d39fc

View File

@ -53,7 +53,7 @@ function update(method: string){
if(data.type === 'panel' && object.isHtmlPanel) return; if(data.type === 'panel' && object.isHtmlPanel) return;
if(data.type === 'sprite' && object.isHtmlSprite) return; if(data.type === 'sprite' && object.isHtmlSprite) return;
const _json = object.toJSON(); const _json = object.toJSON() as any;
_json.object.type = data.type === 'panel' ? 'HtmlSprite' : 'HtmlPanel'; _json.object.type = data.type === 'panel' ? 'HtmlSprite' : 'HtmlPanel';
_json.object.options.isSprite = !_json.object.options.isSprite; _json.object.options.isSprite = !_json.object.options.isSprite;
@ -135,19 +135,24 @@ function updateFileList(fList: UploadFileInfo[]) {
isSprite: data.type ==='sprite', isSprite: data.type ==='sprite',
fileName: file.name fileName: file.name
}).then(htmlPlaneObj => { }).then(htmlPlaneObj => {
data.codes = htmlPlaneObj.options.codes; object.options.codes = htmlPlaneObj.options.codes;
object.options.isSingleHtml = htmlPlaneObj.options.isSingleHtml;
const _json = object.toJSON(); data.codes = object.options.codes;
Loader.objectLoader.copyAttrByData(htmlPlaneObj, _json.object)
object.parent?.add(htmlPlaneObj); // Keep object identity (id/uuid) so scene tree and context menu references stay valid.
while (object.element.firstChild) {
object.element.removeChild(object.element.firstChild);
}
object.parent?.remove(object); while (htmlPlaneObj.element.firstChild) {
object.element.appendChild(htmlPlaneObj.element.firstChild);
}
App.selected = htmlPlaneObj; App.selected = object;
Hooks.useDispatchSignal("objectSelected", object);
Hooks.useDispatchSignal("objectSelected", htmlPlaneObj); }).catch((e:Error) => window.$message?.error(e.message))
}).catch((e:Error) => window.$message?.error(e.message)); .finally(() => URL.revokeObjectURL(tempURL));
} }
function getCanEdit(name: string) { function getCanEdit(name: string) {