fix loading from project file
This commit is contained in:
parent
80f2077de3
commit
3c81e53e72
14
src/index.js
14
src/index.js
@ -107,9 +107,15 @@ loadButton.onclick = async () => {
|
|||||||
});
|
});
|
||||||
const code = items.find((x) => x.tag === "code");
|
const code = items.find((x) => x.tag === "code");
|
||||||
delete code.tag;
|
delete code.tag;
|
||||||
|
|
||||||
assetEditor.importAssets(
|
assetEditor.importAssets(
|
||||||
assets.map(({ name, mime, content }) => ({ name, mime, bytes: content })),
|
assets.map(({ name, mime, content }) => {
|
||||||
|
const file = new File([content], name, { type: mime });
|
||||||
|
|
||||||
|
return { name, file };
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
projectName.value = code.name;
|
projectName.value = code.name;
|
||||||
const dec = new TextDecoder();
|
const dec = new TextDecoder();
|
||||||
editor.setValue(dec.decode(code.content));
|
editor.setValue(dec.decode(code.content));
|
||||||
@ -141,13 +147,13 @@ exportButton.onclick = async () => {
|
|||||||
downloadFile(slugify(projectName.value) || "project", html, ".html", "text/html");
|
downloadFile(slugify(projectName.value) || "project", html, ".html", "text/html");
|
||||||
};
|
};
|
||||||
|
|
||||||
function saveKarlKoder() {
|
async function saveKarlKoder() {
|
||||||
downloadFile(
|
downloadFile(
|
||||||
slugify(projectName.value) || "project",
|
slugify(projectName.value) || "project",
|
||||||
KarlkoderCodec.en(
|
await KarlkoderCodec.en(
|
||||||
projectName.value,
|
projectName.value,
|
||||||
editor.getValue(),
|
editor.getValue(),
|
||||||
assetEditor.assets,
|
await assetEditor.getAssets(),
|
||||||
),
|
),
|
||||||
".karlkode",
|
".karlkode",
|
||||||
);
|
);
|
||||||
|
@ -13,19 +13,19 @@ function strToBytes(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class KarlkoderCodec {
|
export class KarlkoderCodec {
|
||||||
static en(name, code, assets) {
|
static async en(name, code, assets) {
|
||||||
const ret = [];
|
const ret = [];
|
||||||
for (const asset of assets) {
|
for (const asset of assets) {
|
||||||
ret.push(...strToBytes("asset"));
|
ret.push(...strToBytes("asset"));
|
||||||
ret.push(...strToBytes(asset.name.length.toString()));
|
ret.push(...strToBytes(asset.name.length.toString()));
|
||||||
ret.push(...strToBytes(";"));
|
ret.push(...strToBytes(";"));
|
||||||
ret.push(...strToBytes(asset.mime.length.toString()));
|
ret.push(...strToBytes(asset.file.type.length.toString()));
|
||||||
ret.push(...strToBytes(";"));
|
ret.push(...strToBytes(";"));
|
||||||
ret.push(...strToBytes(asset.bytes.length.toString()));
|
ret.push(...strToBytes(asset.file.size.toString()));
|
||||||
ret.push(...strToBytes(";"));
|
ret.push(...strToBytes(";"));
|
||||||
ret.push(...strToBytes(asset.name));
|
ret.push(...strToBytes(asset.name));
|
||||||
ret.push(...strToBytes(asset.mime));
|
ret.push(...strToBytes(asset.file.type));
|
||||||
ret.push(...asset.bytes);
|
ret.push(...await asset.file.bytes());
|
||||||
}
|
}
|
||||||
ret.push(...strToBytes("code"));
|
ret.push(...strToBytes("code"));
|
||||||
ret.push(...strToBytes(name.length.toString()));
|
ret.push(...strToBytes(name.length.toString()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user