@kubohiroya/turbowarp-plus-editor-project-folder 0.13.0 → 0.14.0
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/README.ja.md +17 -2
- package/README.md +17 -2
- package/dist/browser-project-dialog.d.ts +20 -0
- package/dist/browser-projects.d.ts +47 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.js +704 -19
- package/dist/zip.d.ts +9 -0
- package/package.json +1 -1
- package/src/browser-project-dialog.ts +257 -0
- package/src/browser-projects.ts +211 -0
- package/src/index.ts +75 -16
- package/src/zip.ts +103 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as projectFile, C as isObject, D as planExtensionSave, E as parseProject, I as _objectWithoutProperties, L as _objectSpread2, M as readFolderUpdate, N as sameBytes, O as projectAssets, P as unsupported, S as fileVersion, T as paletteFile, _ as collapsePalette, a as projectFolderOverwriteWarning, b as expandPalette, c as parseExplorerState, d as subscribeExplorerState, f as writeExplorerState, g as assetTypeFor, h as assetKey, i as isProjectFolderEmpty, j as readFolder, k as projectChanges, l as readExplorerState, m as assertFolderUnchanged, n as registerFolder, o as editorDirectory, p as FolderError, r as createProjectFolder, t as followProjectFolder, u as screenStateFile, v as encodePalette, w as manifestFile, x as extensionsFile, y as equal } from "./shared-cwwWtggC.js";
|
|
1
|
+
import { A as projectFile, C as isObject, D as planExtensionSave, E as parseProject, F as _asyncIterator, I as _objectWithoutProperties, L as _objectSpread2, M as readFolderUpdate, N as sameBytes, O as projectAssets, P as unsupported, S as fileVersion, T as paletteFile, _ as collapsePalette, a as projectFolderOverwriteWarning, b as expandPalette, c as parseExplorerState, d as subscribeExplorerState, f as writeExplorerState, g as assetTypeFor, h as assetKey, i as isProjectFolderEmpty, j as readFolder, k as projectChanges, l as readExplorerState, m as assertFolderUnchanged, n as registerFolder, o as editorDirectory, p as FolderError, r as createProjectFolder, t as followProjectFolder, u as screenStateFile, v as encodePalette, w as manifestFile, x as extensionsFile, y as equal } from "./shared-cwwWtggC.js";
|
|
2
2
|
// src/block-reload.ts
|
|
3
|
-
var _excluded$
|
|
3
|
+
var _excluded$3 = ["targets"];
|
|
4
4
|
var _excluded2$1 = ["targets"];
|
|
5
5
|
var _excluded3$1 = ["blocks"];
|
|
6
6
|
var _excluded4$1 = ["blocks"];
|
|
@@ -36,7 +36,7 @@ var point = (x, y) => {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
function planBlockReload(before, after) {
|
|
39
|
-
const { targets: oldTargets } = before, oldProject = _objectWithoutProperties(before, _excluded$
|
|
39
|
+
const { targets: oldTargets } = before, oldProject = _objectWithoutProperties(before, _excluded$3);
|
|
40
40
|
const { targets: newTargets } = after, newProject = _objectWithoutProperties(after, _excluded2$1);
|
|
41
41
|
if (oldTargets.length !== newTargets.length || !equal(oldProject, newProject)) return reject$1();
|
|
42
42
|
const edits = [];
|
|
@@ -164,7 +164,7 @@ function applyBlockReload(targets, edits) {
|
|
|
164
164
|
return [...touched];
|
|
165
165
|
}
|
|
166
166
|
// src/script-reload.ts
|
|
167
|
-
var _excluded$
|
|
167
|
+
var _excluded$2 = ["targets"];
|
|
168
168
|
var _excluded2 = ["targets"];
|
|
169
169
|
var _excluded3 = ["blocks"];
|
|
170
170
|
var _excluded4 = ["blocks"];
|
|
@@ -216,7 +216,7 @@ function opcodesOf(blocks, into) {
|
|
|
216
216
|
* project and its targets, including comments, must stay the same; otherwise the whole project is reloaded.
|
|
217
217
|
*/
|
|
218
218
|
function planScriptReload(before, after) {
|
|
219
|
-
const { targets: oldTargets } = before, oldProject = _objectWithoutProperties(before, _excluded$
|
|
219
|
+
const { targets: oldTargets } = before, oldProject = _objectWithoutProperties(before, _excluded$2);
|
|
220
220
|
const { targets: newTargets } = after, newProject = _objectWithoutProperties(after, _excluded2);
|
|
221
221
|
if (oldTargets.length !== newTargets.length || !equal(oldProject, newProject)) return reject();
|
|
222
222
|
const known = new Set(corePrefixes);
|
|
@@ -330,7 +330,7 @@ function applyScriptReload(targets, edits, deserialize) {
|
|
|
330
330
|
return prepared.map(({ target }) => target);
|
|
331
331
|
}
|
|
332
332
|
// src/session.ts
|
|
333
|
-
var _excluded = ["blockPalette"];
|
|
333
|
+
var _excluded$1 = ["blockPalette"];
|
|
334
334
|
var screenStateMaxBytes = 524288;
|
|
335
335
|
var notFound = (error) => error instanceof DOMException && ["NotFoundError", "TypeMismatchError"].includes(error.name);
|
|
336
336
|
/** The screen state the folder was saved with, or nothing. */
|
|
@@ -381,7 +381,7 @@ var readerFor = (storage) => {
|
|
|
381
381
|
};
|
|
382
382
|
var encodeJson = (value) => new TextEncoder().encode(`${JSON.stringify(value, null, 2)}\n`);
|
|
383
383
|
function saveManifest(source, added, removed, palette) {
|
|
384
|
-
const _JSON$parse = JSON.parse(new TextDecoder().decode(source.files.get(manifestFile))), { blockPalette: _ } = _JSON$parse, value = _objectWithoutProperties(_JSON$parse, _excluded);
|
|
384
|
+
const _JSON$parse = JSON.parse(new TextDecoder().decode(source.files.get(manifestFile))), { blockPalette: _ } = _JSON$parse, value = _objectWithoutProperties(_JSON$parse, _excluded$1);
|
|
385
385
|
const entries = value.archiveEntries.filter((name) => !removed.includes(name));
|
|
386
386
|
return encodeJson(_objectSpread2(_objectSpread2({}, value), {}, {
|
|
387
387
|
formatVersion: palette ? 2 : 1,
|
|
@@ -978,11 +978,656 @@ function createFolderSession(vm, host) {
|
|
|
978
978
|
dispose
|
|
979
979
|
};
|
|
980
980
|
}
|
|
981
|
+
// src/browser-projects.ts
|
|
982
|
+
var _excluded = ["id"];
|
|
983
|
+
var base = "turbowarp-plus";
|
|
984
|
+
var projectsDirectory = "projects";
|
|
985
|
+
var infoDirectory = "project-info";
|
|
986
|
+
var idPattern = /^[a-z0-9-]{1,64}$/u;
|
|
987
|
+
var pathPattern = /^(?:[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*)?$/u;
|
|
988
|
+
var maxTitle = 200;
|
|
989
|
+
var infoMaxBytes = 16384;
|
|
990
|
+
var missing = (error) => error instanceof DOMException && ["NotFoundError", "TypeMismatchError"].includes(error.name);
|
|
991
|
+
function cleanTitle(title) {
|
|
992
|
+
return String(title).replace(/[\u0000-\u001f\u007f]/gu, " ").trim().slice(0, maxTitle) || "Untitled";
|
|
993
|
+
}
|
|
994
|
+
function parseInfo(id, text) {
|
|
995
|
+
try {
|
|
996
|
+
const value = JSON.parse(text);
|
|
997
|
+
if (!value || typeof value !== "object" || typeof value.title !== "string" || !Number.isFinite(value.createdAt) || !Number.isFinite(value.updatedAt)) return null;
|
|
998
|
+
const projectPath = typeof value.projectPath === "string" && pathPattern.test(value.projectPath) && !value.projectPath.split("/").some((part) => part === "." || part === "..") ? value.projectPath : "";
|
|
999
|
+
return {
|
|
1000
|
+
id,
|
|
1001
|
+
title: cleanTitle(value.title),
|
|
1002
|
+
projectPath,
|
|
1003
|
+
createdAt: value.createdAt,
|
|
1004
|
+
updatedAt: value.updatedAt
|
|
1005
|
+
};
|
|
1006
|
+
} catch (_unused) {
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
async function writeText(directory, name, text) {
|
|
1011
|
+
const writable = await (await directory.getFileHandle(name, { create: true })).createWritable();
|
|
1012
|
+
try {
|
|
1013
|
+
await writable.write(new TextEncoder().encode(text));
|
|
1014
|
+
await writable.close();
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
await writable.abort().catch(() => {});
|
|
1017
|
+
throw error;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
async function resolvePath(root, path) {
|
|
1021
|
+
let directory = root;
|
|
1022
|
+
for (const part of path ? path.split("/") : []) directory = await directory.getDirectoryHandle(part);
|
|
1023
|
+
return directory;
|
|
1024
|
+
}
|
|
1025
|
+
/** The browser's project folders, or `null` when the browser has no origin private file system. */
|
|
1026
|
+
function openBrowserProjects(view) {
|
|
1027
|
+
var _view$crypto;
|
|
1028
|
+
const navigator = view.navigator;
|
|
1029
|
+
const storage = navigator === null || navigator === void 0 ? void 0 : navigator.storage;
|
|
1030
|
+
if (typeof (storage === null || storage === void 0 ? void 0 : storage.getDirectory) !== "function" || typeof ((_view$crypto = view.crypto) === null || _view$crypto === void 0 ? void 0 : _view$crypto.randomUUID) !== "function") return null;
|
|
1031
|
+
const locks = navigator.locks;
|
|
1032
|
+
let opened;
|
|
1033
|
+
const folders = () => {
|
|
1034
|
+
var _opened;
|
|
1035
|
+
return (_opened = opened) !== null && _opened !== void 0 ? _opened : opened = (async () => {
|
|
1036
|
+
const top = await (await storage.getDirectory()).getDirectoryHandle(base, { create: true });
|
|
1037
|
+
return {
|
|
1038
|
+
projects: await top.getDirectoryHandle(projectsDirectory, { create: true }),
|
|
1039
|
+
info: await top.getDirectoryHandle(infoDirectory, { create: true })
|
|
1040
|
+
};
|
|
1041
|
+
})().catch((error) => {
|
|
1042
|
+
opened = void 0;
|
|
1043
|
+
throw error;
|
|
1044
|
+
});
|
|
1045
|
+
};
|
|
1046
|
+
const checkId = (id) => {
|
|
1047
|
+
if (!idPattern.test(id)) throw new DOMException("Unknown browser project", "NotFoundError");
|
|
1048
|
+
};
|
|
1049
|
+
const readInfo = async (id) => {
|
|
1050
|
+
checkId(id);
|
|
1051
|
+
try {
|
|
1052
|
+
const file = await (await (await folders()).info.getFileHandle(`${id}.json`)).getFile();
|
|
1053
|
+
return file.size > infoMaxBytes ? null : parseInfo(id, await file.text());
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (missing(error)) return null;
|
|
1056
|
+
throw error;
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
const writeInfo = async (project) => {
|
|
1060
|
+
const { id } = project, info = _objectWithoutProperties(project, _excluded);
|
|
1061
|
+
await writeText((await folders()).info, `${id}.json`, `${JSON.stringify(info, null, 2)}\n`);
|
|
1062
|
+
};
|
|
1063
|
+
const root = async (id) => {
|
|
1064
|
+
checkId(id);
|
|
1065
|
+
try {
|
|
1066
|
+
return await (await folders()).projects.getDirectoryHandle(id);
|
|
1067
|
+
} catch (error) {
|
|
1068
|
+
if (missing(error)) return null;
|
|
1069
|
+
throw error;
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
const exclusive = (id, run) => {
|
|
1073
|
+
checkId(id);
|
|
1074
|
+
return locks ? locks.request(`turbowarp-plus-browser-project:${id}`, run) : run();
|
|
1075
|
+
};
|
|
1076
|
+
const projects = {
|
|
1077
|
+
async list() {
|
|
1078
|
+
const { info } = await folders();
|
|
1079
|
+
const found = [];
|
|
1080
|
+
var _iteratorAbruptCompletion = false;
|
|
1081
|
+
var _didIteratorError = false;
|
|
1082
|
+
var _iteratorError;
|
|
1083
|
+
try {
|
|
1084
|
+
for (var _iterator = _asyncIterator(info.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
1085
|
+
const entry = _step.value;
|
|
1086
|
+
{
|
|
1087
|
+
const id = entry.kind === "file" && entry.name.endsWith(".json") ? entry.name.slice(0, -5) : "";
|
|
1088
|
+
if (!idPattern.test(id)) continue;
|
|
1089
|
+
const project = await readInfo(id).catch(() => null);
|
|
1090
|
+
if (project && await root(id).catch(() => null)) found.push(project);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
_didIteratorError = true;
|
|
1095
|
+
_iteratorError = err;
|
|
1096
|
+
} finally {
|
|
1097
|
+
try {
|
|
1098
|
+
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
|
1099
|
+
} finally {
|
|
1100
|
+
if (_didIteratorError) throw _iteratorError;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return found.sort((a, b) => b.updatedAt - a.updatedAt || a.title.localeCompare(b.title));
|
|
1104
|
+
},
|
|
1105
|
+
async create(title, { projectPath = "" } = {}) {
|
|
1106
|
+
if (!pathPattern.test(projectPath) || projectPath.split("/").some((part) => part === "." || part === "..")) throw new TypeError("Invalid project path");
|
|
1107
|
+
const id = view.crypto.randomUUID().toLowerCase();
|
|
1108
|
+
const now = Date.now();
|
|
1109
|
+
const project = {
|
|
1110
|
+
id,
|
|
1111
|
+
title: cleanTitle(title),
|
|
1112
|
+
projectPath,
|
|
1113
|
+
createdAt: now,
|
|
1114
|
+
updatedAt: now
|
|
1115
|
+
};
|
|
1116
|
+
const top = await (await folders()).projects.getDirectoryHandle(id, { create: true });
|
|
1117
|
+
let directory = top;
|
|
1118
|
+
for (const part of projectPath ? projectPath.split("/") : []) directory = await directory.getDirectoryHandle(part, { create: true });
|
|
1119
|
+
await writeInfo(project);
|
|
1120
|
+
projects.persist().catch(() => false);
|
|
1121
|
+
return _objectSpread2(_objectSpread2({}, project), {}, {
|
|
1122
|
+
root: top,
|
|
1123
|
+
directory
|
|
1124
|
+
});
|
|
1125
|
+
},
|
|
1126
|
+
root,
|
|
1127
|
+
async directory(id) {
|
|
1128
|
+
const project = await readInfo(id);
|
|
1129
|
+
const top = project && await root(id);
|
|
1130
|
+
if (!top) return null;
|
|
1131
|
+
try {
|
|
1132
|
+
return await resolvePath(top, project.projectPath);
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
if (missing(error)) return null;
|
|
1135
|
+
throw error;
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
async find(handle) {
|
|
1139
|
+
const path = await (await folders()).projects.resolve(handle).catch(() => null);
|
|
1140
|
+
return (path === null || path === void 0 ? void 0 : path.length) && idPattern.test(path[0]) ? readInfo(path[0]) : null;
|
|
1141
|
+
},
|
|
1142
|
+
async touch(id) {
|
|
1143
|
+
const project = await readInfo(id);
|
|
1144
|
+
if (project) await writeInfo(_objectSpread2(_objectSpread2({}, project), {}, { updatedAt: Math.max(Date.now(), project.updatedAt) }));
|
|
1145
|
+
},
|
|
1146
|
+
async rename(id, title) {
|
|
1147
|
+
const project = await readInfo(id);
|
|
1148
|
+
if (!project) throw new DOMException("Unknown browser project", "NotFoundError");
|
|
1149
|
+
await writeInfo(_objectSpread2(_objectSpread2({}, project), {}, {
|
|
1150
|
+
title: cleanTitle(title),
|
|
1151
|
+
updatedAt: Math.max(Date.now(), project.updatedAt)
|
|
1152
|
+
}));
|
|
1153
|
+
},
|
|
1154
|
+
remove: (id) => exclusive(id, async () => {
|
|
1155
|
+
const { projects: stored, info } = await folders();
|
|
1156
|
+
await stored.removeEntry(id, { recursive: true }).catch((error) => {
|
|
1157
|
+
if (!missing(error)) throw error;
|
|
1158
|
+
});
|
|
1159
|
+
await info.removeEntry(`${id}.json`).catch((error) => {
|
|
1160
|
+
if (!missing(error)) throw error;
|
|
1161
|
+
});
|
|
1162
|
+
}),
|
|
1163
|
+
async storage() {
|
|
1164
|
+
var _storage$estimate, _storage$persisted$ca, _storage$persisted;
|
|
1165
|
+
const [estimate, persisted] = await Promise.all([(_storage$estimate = storage.estimate) === null || _storage$estimate === void 0 ? void 0 : _storage$estimate.call(storage).catch(() => void 0), (_storage$persisted$ca = (_storage$persisted = storage.persisted) === null || _storage$persisted === void 0 ? void 0 : _storage$persisted.call(storage).catch(() => false)) !== null && _storage$persisted$ca !== void 0 ? _storage$persisted$ca : false]);
|
|
1166
|
+
return {
|
|
1167
|
+
usage: estimate === null || estimate === void 0 ? void 0 : estimate.usage,
|
|
1168
|
+
quota: estimate === null || estimate === void 0 ? void 0 : estimate.quota,
|
|
1169
|
+
persisted: Boolean(persisted)
|
|
1170
|
+
};
|
|
1171
|
+
},
|
|
1172
|
+
async persist() {
|
|
1173
|
+
var _storage$persist;
|
|
1174
|
+
return Boolean(await ((_storage$persist = storage.persist) === null || _storage$persist === void 0 ? void 0 : _storage$persist.call(storage)));
|
|
1175
|
+
},
|
|
1176
|
+
exclusive
|
|
1177
|
+
};
|
|
1178
|
+
return projects;
|
|
1179
|
+
}
|
|
1180
|
+
// src/zip.ts
|
|
1181
|
+
var crcTable = (() => {
|
|
1182
|
+
const table = /* @__PURE__ */ new Uint32Array(256);
|
|
1183
|
+
for (let n = 0; n < 256; n++) {
|
|
1184
|
+
let c = n;
|
|
1185
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
1186
|
+
table[n] = c >>> 0;
|
|
1187
|
+
}
|
|
1188
|
+
return table;
|
|
1189
|
+
})();
|
|
1190
|
+
function crc32(bytes) {
|
|
1191
|
+
let crc = 4294967295;
|
|
1192
|
+
for (let i = 0; i < bytes.length; i++) crc = crcTable[(crc ^ bytes[i]) & 255] ^ crc >>> 8;
|
|
1193
|
+
return (crc ^ 4294967295) >>> 0;
|
|
1194
|
+
}
|
|
1195
|
+
function dosTime(time) {
|
|
1196
|
+
const date = new Date(Math.max(time, Date.UTC(1980, 0, 1)));
|
|
1197
|
+
return {
|
|
1198
|
+
time: date.getHours() << 11 | date.getMinutes() << 5 | Math.floor(date.getSeconds() / 2),
|
|
1199
|
+
date: date.getFullYear() - 1980 << 9 | date.getMonth() + 1 << 5 | date.getDate()
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
async function collect(directory, prefix, exclude, out) {
|
|
1203
|
+
const children = [];
|
|
1204
|
+
var _iteratorAbruptCompletion = false;
|
|
1205
|
+
var _didIteratorError = false;
|
|
1206
|
+
var _iteratorError;
|
|
1207
|
+
try {
|
|
1208
|
+
for (var _iterator = _asyncIterator(directory.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
1209
|
+
const child = _step.value;
|
|
1210
|
+
children.push(child);
|
|
1211
|
+
}
|
|
1212
|
+
} catch (err) {
|
|
1213
|
+
_didIteratorError = true;
|
|
1214
|
+
_iteratorError = err;
|
|
1215
|
+
} finally {
|
|
1216
|
+
try {
|
|
1217
|
+
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
|
1218
|
+
} finally {
|
|
1219
|
+
if (_didIteratorError) throw _iteratorError;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
children.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1223
|
+
if (prefix && !children.length) out.push({
|
|
1224
|
+
name: prefix,
|
|
1225
|
+
data: /* @__PURE__ */ new Uint8Array(),
|
|
1226
|
+
modified: Date.now(),
|
|
1227
|
+
directory: true
|
|
1228
|
+
});
|
|
1229
|
+
for (const child of children) {
|
|
1230
|
+
const path = prefix + child.name;
|
|
1231
|
+
if (exclude(path)) continue;
|
|
1232
|
+
if (child.kind === "directory") await collect(child, `${path}/`, exclude, out);
|
|
1233
|
+
else {
|
|
1234
|
+
const file = await child.getFile();
|
|
1235
|
+
out.push({
|
|
1236
|
+
name: path,
|
|
1237
|
+
data: new Uint8Array(await file.arrayBuffer()),
|
|
1238
|
+
modified: file.lastModified,
|
|
1239
|
+
directory: false
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
/** The files under `directory` as a ZIP. `exclude` receives paths relative to `directory`, such as `.git`. */
|
|
1245
|
+
async function zipDirectory(directory, { exclude = () => false } = {}) {
|
|
1246
|
+
const entries = [];
|
|
1247
|
+
await collect(directory, "", exclude, entries);
|
|
1248
|
+
if (entries.length > 65535) throw new RangeError("Too many files for a ZIP archive");
|
|
1249
|
+
const encoder = new TextEncoder();
|
|
1250
|
+
const parts = [];
|
|
1251
|
+
const central = [];
|
|
1252
|
+
let offset = 0;
|
|
1253
|
+
for (const entry of entries) {
|
|
1254
|
+
const name = encoder.encode(entry.name);
|
|
1255
|
+
const crc = crc32(entry.data);
|
|
1256
|
+
const { time, date } = dosTime(entry.modified);
|
|
1257
|
+
const local = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(30));
|
|
1258
|
+
local.setUint32(0, 67324752, true);
|
|
1259
|
+
local.setUint16(4, 20, true);
|
|
1260
|
+
local.setUint16(6, 2048, true);
|
|
1261
|
+
local.setUint16(8, 0, true);
|
|
1262
|
+
local.setUint16(10, time, true);
|
|
1263
|
+
local.setUint16(12, date, true);
|
|
1264
|
+
local.setUint32(14, crc, true);
|
|
1265
|
+
local.setUint32(18, entry.data.length, true);
|
|
1266
|
+
local.setUint32(22, entry.data.length, true);
|
|
1267
|
+
local.setUint16(26, name.length, true);
|
|
1268
|
+
const header = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(46));
|
|
1269
|
+
header.setUint32(0, 33639248, true);
|
|
1270
|
+
header.setUint16(4, 20, true);
|
|
1271
|
+
header.setUint16(6, 20, true);
|
|
1272
|
+
header.setUint16(8, 2048, true);
|
|
1273
|
+
header.setUint16(12, time, true);
|
|
1274
|
+
header.setUint16(14, date, true);
|
|
1275
|
+
header.setUint32(16, crc, true);
|
|
1276
|
+
header.setUint32(20, entry.data.length, true);
|
|
1277
|
+
header.setUint32(24, entry.data.length, true);
|
|
1278
|
+
header.setUint16(28, name.length, true);
|
|
1279
|
+
header.setUint32(38, entry.directory ? 16 : 0, true);
|
|
1280
|
+
header.setUint32(42, offset, true);
|
|
1281
|
+
parts.push(new Uint8Array(local.buffer), name, entry.data);
|
|
1282
|
+
central.push(new Uint8Array(header.buffer), name);
|
|
1283
|
+
offset += 30 + name.length + entry.data.length;
|
|
1284
|
+
if (offset > 4294967295) throw new RangeError("The folder is too large for a ZIP archive");
|
|
1285
|
+
}
|
|
1286
|
+
const size = central.reduce((total, part) => total + part.length, 0);
|
|
1287
|
+
const end = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(22));
|
|
1288
|
+
end.setUint32(0, 101010256, true);
|
|
1289
|
+
end.setUint16(8, entries.length, true);
|
|
1290
|
+
end.setUint16(10, entries.length, true);
|
|
1291
|
+
end.setUint32(12, size, true);
|
|
1292
|
+
end.setUint32(16, offset, true);
|
|
1293
|
+
return new Blob([
|
|
1294
|
+
...parts,
|
|
1295
|
+
...central,
|
|
1296
|
+
new Uint8Array(end.buffer)
|
|
1297
|
+
], { type: "application/zip" });
|
|
1298
|
+
}
|
|
1299
|
+
// src/browser-project-dialog.ts
|
|
1300
|
+
var messages$1 = {
|
|
1301
|
+
en: {
|
|
1302
|
+
openTitle: "Project Folders in This Browser",
|
|
1303
|
+
createTitle: "New Project Folder in This Browser",
|
|
1304
|
+
note: "These folders are stored only in this browser. The browser may delete them when you clear site data or do not use this site for a while. Export a ZIP or push to GitHub to keep a copy.",
|
|
1305
|
+
usage: (used, quota) => `Using ${used} of ${quota}.`,
|
|
1306
|
+
persisted: "The browser keeps this storage until you clear it.",
|
|
1307
|
+
empty: "No project folders are stored in this browser yet.",
|
|
1308
|
+
name: "Name",
|
|
1309
|
+
create: "Create",
|
|
1310
|
+
open: "Open",
|
|
1311
|
+
exportZip: "Export ZIP",
|
|
1312
|
+
remove: "Delete…",
|
|
1313
|
+
close: "Close",
|
|
1314
|
+
updated: (date) => `Updated ${date}`,
|
|
1315
|
+
confirmRemove: (title) => `Delete “${title}” from this browser? This cannot be undone. Export a ZIP first to keep a copy.`,
|
|
1316
|
+
failed: "The browser storage could not be used."
|
|
1317
|
+
},
|
|
1318
|
+
ja: {
|
|
1319
|
+
openTitle: "ブラウザー内の作品フォルダ",
|
|
1320
|
+
createTitle: "新しい作品フォルダをブラウザー内に作る",
|
|
1321
|
+
note: "この作品フォルダは、このブラウザーの中にだけ保存されます。サイトのデータを消したときや、しばらくこのサイトを使わなかったときに、ブラウザーが消すことがあります。ZIP で書き出すか、GitHub に送って残してください。",
|
|
1322
|
+
usage: (used, quota) => `${quota} のうち ${used} を使っています。`,
|
|
1323
|
+
persisted: "このブラウザーは、データを消すまでこの保存領域を残します。",
|
|
1324
|
+
empty: "このブラウザーには、まだ作品フォルダがありません。",
|
|
1325
|
+
name: "名前",
|
|
1326
|
+
create: "作成",
|
|
1327
|
+
open: "開く",
|
|
1328
|
+
exportZip: "ZIP で書き出す",
|
|
1329
|
+
remove: "削除…",
|
|
1330
|
+
close: "閉じる",
|
|
1331
|
+
updated: (date) => `更新: ${date}`,
|
|
1332
|
+
confirmRemove: (title) => `「${title}」をこのブラウザーから削除しますか?元に戻せません。残すには、先に ZIP で書き出してください。`,
|
|
1333
|
+
failed: "ブラウザーの保存領域を使えませんでした。"
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
var closeIcon = "M4 4l8 8M12 4l-8 8";
|
|
1337
|
+
function formatBytes(value, locale) {
|
|
1338
|
+
const units = [
|
|
1339
|
+
"B",
|
|
1340
|
+
"KB",
|
|
1341
|
+
"MB",
|
|
1342
|
+
"GB",
|
|
1343
|
+
"TB"
|
|
1344
|
+
];
|
|
1345
|
+
let size = value;
|
|
1346
|
+
let unit = 0;
|
|
1347
|
+
while (size >= 1024 && unit < units.length - 1) {
|
|
1348
|
+
size /= 1024;
|
|
1349
|
+
unit++;
|
|
1350
|
+
}
|
|
1351
|
+
return `${new Intl.NumberFormat(locale, { maximumFractionDigits: unit ? 1 : 0 }).format(size)} ${units[unit]}`;
|
|
1352
|
+
}
|
|
1353
|
+
/** A file name for the exported ZIP that every OS accepts. */
|
|
1354
|
+
function zipFileName(title) {
|
|
1355
|
+
return `${title.replace(/[\\/:*?"<>|\u0000-\u001f\u007f]/gu, "_").replace(/^[.\s]+|[.\s]+$/gu, "").slice(0, 120) || "project"}.zip`;
|
|
1356
|
+
}
|
|
1357
|
+
/** Saves the stored folder of `project` as a ZIP through the browser's download. */
|
|
1358
|
+
async function exportBrowserProject(document, projects, project) {
|
|
1359
|
+
const root = await projects.root(project.id);
|
|
1360
|
+
if (!root) throw new DOMException("The project folder was deleted", "NotFoundError");
|
|
1361
|
+
const blob = await projects.exclusive(project.id, () => zipDirectory(root));
|
|
1362
|
+
const view = document.defaultView;
|
|
1363
|
+
const url = view.URL.createObjectURL(blob);
|
|
1364
|
+
const link = document.createElement("a");
|
|
1365
|
+
link.href = url;
|
|
1366
|
+
link.download = zipFileName(project.title);
|
|
1367
|
+
link.hidden = true;
|
|
1368
|
+
document.body.append(link);
|
|
1369
|
+
link.click();
|
|
1370
|
+
link.remove();
|
|
1371
|
+
view.setTimeout(() => view.URL.revokeObjectURL(url), 6e4);
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Shows the project folders kept in this browser. With `purpose: 'open'` the user picks one; with `'create'` the user
|
|
1375
|
+
* names a new empty one. Resolves with the chosen folder, or `null` when the dialog closes without one.
|
|
1376
|
+
*/
|
|
1377
|
+
function chooseBrowserProject({ document, projects, locale = "en", purpose, title = "" }) {
|
|
1378
|
+
var _ref, _ref2, _dialog$querySelector;
|
|
1379
|
+
const message = locale.startsWith("ja") ? messages$1.ja : messages$1.en;
|
|
1380
|
+
const view = document.defaultView;
|
|
1381
|
+
const dialog = document.createElement("dialog");
|
|
1382
|
+
dialog.dataset.browserProjects = purpose;
|
|
1383
|
+
dialog.setAttribute("aria-labelledby", "tw-plus-browser-projects-title");
|
|
1384
|
+
Object.assign(dialog.style, {
|
|
1385
|
+
width: "min(34rem, calc(100vw - 2rem))",
|
|
1386
|
+
maxHeight: "calc(100vh - 4rem)",
|
|
1387
|
+
padding: "1rem 1.25rem",
|
|
1388
|
+
background: "Canvas",
|
|
1389
|
+
color: "CanvasText",
|
|
1390
|
+
border: "1px solid GrayText",
|
|
1391
|
+
borderRadius: "0.5rem",
|
|
1392
|
+
fontFamily: "inherit",
|
|
1393
|
+
fontSize: "0.875rem",
|
|
1394
|
+
boxSizing: "border-box"
|
|
1395
|
+
});
|
|
1396
|
+
const header = document.createElement("header");
|
|
1397
|
+
Object.assign(header.style, {
|
|
1398
|
+
display: "flex",
|
|
1399
|
+
alignItems: "center",
|
|
1400
|
+
gap: "0.5rem",
|
|
1401
|
+
marginBlockEnd: "0.5rem"
|
|
1402
|
+
});
|
|
1403
|
+
const heading = document.createElement("h2");
|
|
1404
|
+
heading.id = "tw-plus-browser-projects-title";
|
|
1405
|
+
heading.textContent = purpose === "open" ? message.openTitle : message.createTitle;
|
|
1406
|
+
Object.assign(heading.style, {
|
|
1407
|
+
flex: "1",
|
|
1408
|
+
margin: "0",
|
|
1409
|
+
fontSize: "1rem"
|
|
1410
|
+
});
|
|
1411
|
+
const close = document.createElement("button");
|
|
1412
|
+
close.type = "button";
|
|
1413
|
+
close.dataset.browserProjectsClose = "";
|
|
1414
|
+
close.title = message.close;
|
|
1415
|
+
close.setAttribute("aria-label", message.close);
|
|
1416
|
+
Object.assign(close.style, {
|
|
1417
|
+
display: "grid",
|
|
1418
|
+
placeItems: "center",
|
|
1419
|
+
width: "2rem",
|
|
1420
|
+
height: "2rem",
|
|
1421
|
+
padding: "0",
|
|
1422
|
+
background: "transparent",
|
|
1423
|
+
color: "inherit",
|
|
1424
|
+
border: "0",
|
|
1425
|
+
borderRadius: "0.25rem",
|
|
1426
|
+
cursor: "pointer"
|
|
1427
|
+
});
|
|
1428
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1429
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
1430
|
+
svg.setAttribute("width", "16");
|
|
1431
|
+
svg.setAttribute("height", "16");
|
|
1432
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1433
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1434
|
+
path.setAttribute("d", closeIcon);
|
|
1435
|
+
path.setAttribute("stroke", "currentColor");
|
|
1436
|
+
path.setAttribute("stroke-width", "1.5");
|
|
1437
|
+
path.setAttribute("stroke-linecap", "round");
|
|
1438
|
+
svg.append(path);
|
|
1439
|
+
close.append(svg);
|
|
1440
|
+
header.append(heading, close);
|
|
1441
|
+
const note = document.createElement("p");
|
|
1442
|
+
note.textContent = message.note;
|
|
1443
|
+
Object.assign(note.style, { margin: "0 0 0.25rem" });
|
|
1444
|
+
const usage = document.createElement("p");
|
|
1445
|
+
usage.dataset.browserProjectsUsage = "";
|
|
1446
|
+
Object.assign(usage.style, {
|
|
1447
|
+
margin: "0 0 0.75rem",
|
|
1448
|
+
color: "GrayText"
|
|
1449
|
+
});
|
|
1450
|
+
const status = document.createElement("p");
|
|
1451
|
+
status.setAttribute("role", "alert");
|
|
1452
|
+
status.hidden = true;
|
|
1453
|
+
Object.assign(status.style, { margin: "0 0 0.75rem" });
|
|
1454
|
+
dialog.append(header, note, usage, status);
|
|
1455
|
+
let settled = false;
|
|
1456
|
+
let resolveChoice;
|
|
1457
|
+
const result = new Promise((resolve) => {
|
|
1458
|
+
resolveChoice = resolve;
|
|
1459
|
+
});
|
|
1460
|
+
const finish = (choice) => {
|
|
1461
|
+
if (settled) return;
|
|
1462
|
+
settled = true;
|
|
1463
|
+
if (dialog.open) dialog.close();
|
|
1464
|
+
dialog.remove();
|
|
1465
|
+
resolveChoice(choice);
|
|
1466
|
+
};
|
|
1467
|
+
const fail = (error) => {
|
|
1468
|
+
status.hidden = false;
|
|
1469
|
+
status.textContent = message.failed + (error instanceof Error && error.message ? ` (${error.message})` : "");
|
|
1470
|
+
};
|
|
1471
|
+
let busy = false;
|
|
1472
|
+
const run = async (action) => {
|
|
1473
|
+
if (busy) return;
|
|
1474
|
+
busy = true;
|
|
1475
|
+
dialog.setAttribute("aria-busy", "true");
|
|
1476
|
+
try {
|
|
1477
|
+
await action();
|
|
1478
|
+
} catch (error) {
|
|
1479
|
+
fail(error);
|
|
1480
|
+
} finally {
|
|
1481
|
+
busy = false;
|
|
1482
|
+
dialog.removeAttribute("aria-busy");
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
close.addEventListener("click", () => finish(null));
|
|
1486
|
+
dialog.addEventListener("cancel", (event) => {
|
|
1487
|
+
event.preventDefault();
|
|
1488
|
+
finish(null);
|
|
1489
|
+
});
|
|
1490
|
+
dialog.addEventListener("close", () => finish(null));
|
|
1491
|
+
if (purpose === "create") {
|
|
1492
|
+
const form = document.createElement("form");
|
|
1493
|
+
Object.assign(form.style, {
|
|
1494
|
+
display: "flex",
|
|
1495
|
+
gap: "0.5rem",
|
|
1496
|
+
alignItems: "end"
|
|
1497
|
+
});
|
|
1498
|
+
const label = document.createElement("label");
|
|
1499
|
+
Object.assign(label.style, {
|
|
1500
|
+
display: "grid",
|
|
1501
|
+
gap: "0.25rem",
|
|
1502
|
+
flex: "1"
|
|
1503
|
+
});
|
|
1504
|
+
const caption = document.createElement("span");
|
|
1505
|
+
caption.textContent = message.name;
|
|
1506
|
+
const input = document.createElement("input");
|
|
1507
|
+
input.name = "title";
|
|
1508
|
+
input.required = true;
|
|
1509
|
+
input.maxLength = 200;
|
|
1510
|
+
input.value = title;
|
|
1511
|
+
input.autocomplete = "off";
|
|
1512
|
+
label.append(caption, input);
|
|
1513
|
+
const submit = document.createElement("button");
|
|
1514
|
+
submit.type = "submit";
|
|
1515
|
+
submit.textContent = message.create;
|
|
1516
|
+
form.append(label, submit);
|
|
1517
|
+
form.addEventListener("submit", (event) => {
|
|
1518
|
+
event.preventDefault();
|
|
1519
|
+
const name = input.value.trim();
|
|
1520
|
+
if (!name) return;
|
|
1521
|
+
run(async () => {
|
|
1522
|
+
const created = await projects.create(name);
|
|
1523
|
+
finish({
|
|
1524
|
+
project: {
|
|
1525
|
+
id: created.id,
|
|
1526
|
+
title: created.title,
|
|
1527
|
+
projectPath: created.projectPath,
|
|
1528
|
+
createdAt: created.createdAt,
|
|
1529
|
+
updatedAt: created.updatedAt
|
|
1530
|
+
},
|
|
1531
|
+
directory: created.directory
|
|
1532
|
+
});
|
|
1533
|
+
});
|
|
1534
|
+
});
|
|
1535
|
+
dialog.append(form);
|
|
1536
|
+
} else {
|
|
1537
|
+
const list = document.createElement("ul");
|
|
1538
|
+
list.dataset.browserProjectsList = "";
|
|
1539
|
+
Object.assign(list.style, {
|
|
1540
|
+
listStyle: "none",
|
|
1541
|
+
margin: "0",
|
|
1542
|
+
padding: "0",
|
|
1543
|
+
display: "grid",
|
|
1544
|
+
gap: "0.5rem",
|
|
1545
|
+
overflowY: "auto",
|
|
1546
|
+
maxHeight: "50vh"
|
|
1547
|
+
});
|
|
1548
|
+
const dateFormat = new Intl.DateTimeFormat(locale, {
|
|
1549
|
+
dateStyle: "medium",
|
|
1550
|
+
timeStyle: "short"
|
|
1551
|
+
});
|
|
1552
|
+
const render = async () => {
|
|
1553
|
+
const stored = await projects.list();
|
|
1554
|
+
list.replaceChildren();
|
|
1555
|
+
if (!stored.length) {
|
|
1556
|
+
const empty = document.createElement("li");
|
|
1557
|
+
empty.textContent = message.empty;
|
|
1558
|
+
empty.style.color = "GrayText";
|
|
1559
|
+
list.append(empty);
|
|
1560
|
+
}
|
|
1561
|
+
for (const project of stored) {
|
|
1562
|
+
const item = document.createElement("li");
|
|
1563
|
+
item.dataset.browserProject = project.id;
|
|
1564
|
+
Object.assign(item.style, {
|
|
1565
|
+
display: "flex",
|
|
1566
|
+
alignItems: "center",
|
|
1567
|
+
gap: "0.5rem",
|
|
1568
|
+
flexWrap: "wrap",
|
|
1569
|
+
padding: "0.5rem",
|
|
1570
|
+
border: "1px solid GrayText",
|
|
1571
|
+
borderRadius: "0.375rem"
|
|
1572
|
+
});
|
|
1573
|
+
const text = document.createElement("div");
|
|
1574
|
+
Object.assign(text.style, {
|
|
1575
|
+
flex: "1",
|
|
1576
|
+
minWidth: "10rem"
|
|
1577
|
+
});
|
|
1578
|
+
const name = document.createElement("strong");
|
|
1579
|
+
name.textContent = project.title;
|
|
1580
|
+
const updated = document.createElement("div");
|
|
1581
|
+
updated.textContent = message.updated(dateFormat.format(project.updatedAt));
|
|
1582
|
+
updated.style.color = "GrayText";
|
|
1583
|
+
text.append(name, updated);
|
|
1584
|
+
const button = (label, action) => {
|
|
1585
|
+
const element = document.createElement("button");
|
|
1586
|
+
element.type = "button";
|
|
1587
|
+
element.textContent = label;
|
|
1588
|
+
element.addEventListener("click", () => void run(action));
|
|
1589
|
+
return element;
|
|
1590
|
+
};
|
|
1591
|
+
item.append(text, button(message.open, async () => {
|
|
1592
|
+
const directory = await projects.directory(project.id);
|
|
1593
|
+
if (!directory) return render();
|
|
1594
|
+
finish({
|
|
1595
|
+
project,
|
|
1596
|
+
directory
|
|
1597
|
+
});
|
|
1598
|
+
}), button(message.exportZip, () => exportBrowserProject(document, projects, project)), button(message.remove, async () => {
|
|
1599
|
+
if (!view.confirm(message.confirmRemove(project.title))) return;
|
|
1600
|
+
await projects.remove(project.id);
|
|
1601
|
+
await render();
|
|
1602
|
+
await showUsage();
|
|
1603
|
+
}));
|
|
1604
|
+
list.append(item);
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
dialog.append(list);
|
|
1608
|
+
run(render);
|
|
1609
|
+
}
|
|
1610
|
+
const showUsage = async () => {
|
|
1611
|
+
const state = await projects.storage().catch(() => null);
|
|
1612
|
+
if (!state) return;
|
|
1613
|
+
const parts = [];
|
|
1614
|
+
if (state.usage !== void 0 && state.quota) parts.push(message.usage(formatBytes(state.usage, locale), formatBytes(state.quota, locale)));
|
|
1615
|
+
if (state.persisted) parts.push(message.persisted);
|
|
1616
|
+
usage.textContent = parts.join(" ");
|
|
1617
|
+
usage.hidden = !parts.length;
|
|
1618
|
+
};
|
|
1619
|
+
showUsage();
|
|
1620
|
+
document.body.append(dialog);
|
|
1621
|
+
dialog.showModal();
|
|
1622
|
+
(_ref = (_ref2 = (_dialog$querySelector = dialog.querySelector("input")) !== null && _dialog$querySelector !== void 0 ? _dialog$querySelector : dialog.querySelector("[data-browser-projects-list] button")) !== null && _ref2 !== void 0 ? _ref2 : close) === null || _ref === void 0 || _ref.focus();
|
|
1623
|
+
return result;
|
|
1624
|
+
}
|
|
981
1625
|
// src/index.ts
|
|
982
1626
|
var messages = {
|
|
983
1627
|
en: {
|
|
984
1628
|
open: "Open Project Folder…",
|
|
985
1629
|
save: "Save to Project Folder",
|
|
1630
|
+
openBrowser: "Open Project Folder in This Browser…",
|
|
986
1631
|
replace: "Replace the open project and discard its unsaved changes?",
|
|
987
1632
|
opened: "Project folder opened.",
|
|
988
1633
|
saved: "Project folder saved.",
|
|
@@ -1016,6 +1661,7 @@ var messages = {
|
|
|
1016
1661
|
ja: {
|
|
1017
1662
|
open: "プロジェクトフォルダを開く…",
|
|
1018
1663
|
save: "プロジェクトフォルダに保存",
|
|
1664
|
+
openBrowser: "ブラウザー内のプロジェクトフォルダを開く…",
|
|
1019
1665
|
replace: "未保存の変更を破棄して、別の作品を開きますか?",
|
|
1020
1666
|
opened: "プロジェクトフォルダを開きました。",
|
|
1021
1667
|
saved: "プロジェクトフォルダに保存しました。",
|
|
@@ -1048,15 +1694,40 @@ var messages = {
|
|
|
1048
1694
|
}
|
|
1049
1695
|
};
|
|
1050
1696
|
var menus = /* @__PURE__ */ new WeakMap();
|
|
1697
|
+
var abort = () => new DOMException("The user closed the dialog", "AbortError");
|
|
1051
1698
|
/**
|
|
1052
1699
|
* `autoReload` (default true) applies value and position changes without a click when the Editor has no unsaved
|
|
1053
1700
|
* edits and the project is stopped. Other changes always wait for the reload command.
|
|
1054
1701
|
*/
|
|
1055
|
-
function mountProjectFolder({ vm, document, host, locale = "en", autoReload = true }) {
|
|
1702
|
+
function mountProjectFolder({ vm, document, host, locale = "en", autoReload = true, browserStorage = "fallback" }) {
|
|
1056
1703
|
var _vm$runtime;
|
|
1057
1704
|
const view = document.defaultView;
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1705
|
+
const devicePicker = view === null || view === void 0 ? void 0 : view.showDirectoryPicker;
|
|
1706
|
+
const browserProjects = view && browserStorage !== "off" && (browserStorage === "always" || !devicePicker) ? openBrowserProjects(view) : null;
|
|
1707
|
+
if (!devicePicker && !browserProjects || !((_vm$runtime = vm.runtime) === null || _vm$runtime === void 0 ? void 0 : _vm$runtime.storage)) return null;
|
|
1708
|
+
const chooseBrowser = async (purpose, title) => {
|
|
1709
|
+
const choice = await chooseBrowserProject({
|
|
1710
|
+
document,
|
|
1711
|
+
projects: browserProjects,
|
|
1712
|
+
locale,
|
|
1713
|
+
purpose,
|
|
1714
|
+
title
|
|
1715
|
+
});
|
|
1716
|
+
if (!choice) throw abort();
|
|
1717
|
+
return choice.directory;
|
|
1718
|
+
};
|
|
1719
|
+
const pickDirectory = devicePicker ? (options) => devicePicker.call(view, options) : () => chooseBrowser("open");
|
|
1720
|
+
const pickNewDirectory = (options, title) => devicePicker ? devicePicker.call(view, options) : chooseBrowser("create", title);
|
|
1721
|
+
/** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
|
|
1722
|
+
const withBrowserProject = async (directory, run) => {
|
|
1723
|
+
const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
|
|
1724
|
+
if (!project) return run();
|
|
1725
|
+
return browserProjects.exclusive(project.id, async () => {
|
|
1726
|
+
const result = await run();
|
|
1727
|
+
await browserProjects.touch(project.id).catch(() => {});
|
|
1728
|
+
return result;
|
|
1729
|
+
});
|
|
1730
|
+
};
|
|
1060
1731
|
const session = createFolderSession(vm, host);
|
|
1061
1732
|
const status = document.createElement("output");
|
|
1062
1733
|
status.dataset.projectFolderStatus = "";
|
|
@@ -1236,20 +1907,27 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1236
1907
|
session,
|
|
1237
1908
|
open(locale) {
|
|
1238
1909
|
const message = messageFor(locale);
|
|
1239
|
-
session.open((options) => pickDirectory
|
|
1910
|
+
session.open((options) => pickDirectory(options), () => view.confirm(message.replace)).then((result) => {
|
|
1240
1911
|
if (result === "opened") report(message.opened);
|
|
1241
1912
|
}, (error) => fail(locale, error)).finally(renderReload);
|
|
1242
1913
|
renderReload();
|
|
1243
1914
|
},
|
|
1915
|
+
openBrowser: devicePicker && browserProjects ? (locale) => {
|
|
1916
|
+
const message = messageFor(locale);
|
|
1917
|
+
session.open(() => chooseBrowser("open"), () => view.confirm(message.replace)).then((result) => {
|
|
1918
|
+
if (result === "opened") report(message.opened);
|
|
1919
|
+
}, (error) => fail(locale, error)).finally(renderReload);
|
|
1920
|
+
renderReload();
|
|
1921
|
+
} : void 0,
|
|
1244
1922
|
save(locale) {
|
|
1245
1923
|
if (!session.busy) {
|
|
1246
1924
|
var _host$saveWithLock, _host$saveWithLock2;
|
|
1247
1925
|
const message = messageFor(locale);
|
|
1248
1926
|
const directory = session.directory;
|
|
1249
|
-
const save = () => {
|
|
1927
|
+
const save = () => withBrowserProject(directory, () => {
|
|
1250
1928
|
if (session.directory !== directory) throw new FolderError("conflict");
|
|
1251
1929
|
return session.save();
|
|
1252
|
-
};
|
|
1930
|
+
});
|
|
1253
1931
|
((_host$saveWithLock = (_host$saveWithLock2 = host.saveWithLock) === null || _host$saveWithLock2 === void 0 ? void 0 : _host$saveWithLock2.call(host, save)) !== null && _host$saveWithLock !== void 0 ? _host$saveWithLock : save()).then(({ status, sourceRemoved }) => {
|
|
1254
1932
|
const detail = sourceRemoved.length ? ` ${message.sourceRemoved(sourceRemoved)}` : "";
|
|
1255
1933
|
report(message[status] + detail);
|
|
@@ -1274,15 +1952,21 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1274
1952
|
unsavedPaths: () => session.unsavedPaths(),
|
|
1275
1953
|
readUnsavedFile: (path) => session.readUnsavedFile(path),
|
|
1276
1954
|
subscribeEdits: (listener) => session.subscribeEdits(listener),
|
|
1277
|
-
save: () => session.save().finally(renderReload),
|
|
1278
|
-
|
|
1955
|
+
save: () => withBrowserProject(session.directory, () => session.save()).finally(renderReload),
|
|
1956
|
+
/** The folders kept in this browser, when they are offered, for a host that lists or exports them. */
|
|
1957
|
+
browserProjects,
|
|
1958
|
+
/**
|
|
1959
|
+
* Creates a project folder from a snapshot. `title` names a folder made in the browser, where the user names a
|
|
1960
|
+
* new folder instead of picking one on the device.
|
|
1961
|
+
*/
|
|
1962
|
+
createFromSnapshot({ prepareFiles, collectEdits, directory, current = () => true, title }) {
|
|
1279
1963
|
const message = locale.startsWith("ja") ? "指定されたフォルダは空ではありません。フォルダに保存されている内容が上書きされる場合があります。よろしいですか?" : "The selected folder is not empty. Contents in the folder may be overwritten. Continue?";
|
|
1280
1964
|
return session.createFromSnapshot(async () => {
|
|
1281
1965
|
try {
|
|
1282
|
-
const selected = directory !== null && directory !== void 0 ? directory : await
|
|
1966
|
+
const selected = directory !== null && directory !== void 0 ? directory : await pickNewDirectory({
|
|
1283
1967
|
id: "turbowarp-plus-project-folder",
|
|
1284
1968
|
mode: "readwrite"
|
|
1285
|
-
});
|
|
1969
|
+
}, title);
|
|
1286
1970
|
if (!current()) return null;
|
|
1287
1971
|
const overwrite = !await isProjectFolderEmpty(selected);
|
|
1288
1972
|
if (!current() || overwrite && !view.confirm(message)) return null;
|
|
@@ -1319,6 +2003,7 @@ function projectFolderActions(vm, locale = "en") {
|
|
|
1319
2003
|
if (!entry) return void 0;
|
|
1320
2004
|
return {
|
|
1321
2005
|
open: () => entry.open(locale),
|
|
2006
|
+
openBrowser: entry.openBrowser ? () => entry.openBrowser(locale) : void 0,
|
|
1322
2007
|
save: entry.session.canSave ? () => entry.save(locale) : void 0,
|
|
1323
2008
|
detach: () => entry.session.detach()
|
|
1324
2009
|
};
|
|
@@ -1346,6 +2031,6 @@ function renderProjectFolderMenu(createElement, { vm, locale = "en", MenuItem, M
|
|
|
1346
2031
|
}
|
|
1347
2032
|
}, labels[action]));
|
|
1348
2033
|
};
|
|
1349
|
-
return createElement(MenuSection, null, item("open"), entry.session.canSave ? item("save") : null);
|
|
2034
|
+
return createElement(MenuSection, null, item("open"), entry.openBrowser ? item("openBrowser") : null, entry.session.canSave ? item("save") : null);
|
|
1350
2035
|
}
|
|
1351
|
-
export { createProjectFolder, followProjectFolder, mountProjectFolder, parseExplorerState, projectFolderActions, projectFolderOverwriteWarning, readExplorerState, renderProjectFolderMenu, subscribeExplorerState, writeExplorerState };
|
|
2036
|
+
export { chooseBrowserProject, createProjectFolder, exportBrowserProject, followProjectFolder, mountProjectFolder, openBrowserProjects, parseExplorerState, projectFolderActions, projectFolderOverwriteWarning, readExplorerState, renderProjectFolderMenu, subscribeExplorerState, writeExplorerState, zipDirectory, zipFileName };
|