@kubohiroya/turbowarp-plus-editor-project-folder 0.16.0 → 0.18.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 -4
- package/README.md +15 -4
- package/dist/browser-project-dialog.d.ts +1 -1
- package/dist/browser-projects.d.ts +6 -3
- package/dist/explorer.d.ts +3 -3
- package/dist/explorer.js +72 -16
- package/dist/folder-registry.d.ts +5 -2
- package/dist/index.d.ts +27 -7
- package/dist/index.js +134 -32
- package/dist/not-project-dialog.d.ts +10 -0
- package/dist/session.d.ts +14 -5
- package/dist/{shared-h5VGx9Jp.js → shared-CLo1e5zK.js} +18 -37
- package/dist/{shared-CwQoV7xd.js → shared-DkIVN2xk.js} +1 -1
- package/dist/source.d.ts +6 -6
- package/package.json +1 -1
- package/src/browser-project-dialog.ts +3 -2
- package/src/browser-projects.ts +6 -3
- package/src/explorer.tsx +64 -11
- package/src/folder-registry.ts +5 -2
- package/src/index.ts +54 -17
- package/src/not-project-dialog.ts +63 -0
- package/src/session.ts +24 -11
- package/src/source.ts +12 -32
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as projectChanges, C as isObject, D as parseProject, E as paletteFile, F as unsupported, I as _asyncIterator, L as _objectWithoutProperties, M as readFolder, N as readFolderUpdate, O as planExtensionSave, P as sameBytes, R as _objectSpread2, S as fileVersion, T as manifestFile, _ 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 projectFile, k as projectAssets, 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 isProjectFolder, x as extensionsFile, y as equal } from "./shared-CLo1e5zK.js";
|
|
2
2
|
// src/block-reload.ts
|
|
3
3
|
var _excluded$3 = ["targets"];
|
|
4
4
|
var _excluded2$1 = ["targets"];
|
|
@@ -513,7 +513,8 @@ function createFolderSession(vm, host) {
|
|
|
513
513
|
vm.off("PROJECT_CHANGED", changed);
|
|
514
514
|
unregisterTree === null || unregisterTree === void 0 || unregisterTree();
|
|
515
515
|
};
|
|
516
|
-
const
|
|
516
|
+
const readProject = async (directory) => await isProjectFolder(directory) ? readFolder(directory, vm.runtime.storage) : "not-project";
|
|
517
|
+
const openFrom = async (getDirectory, confirmReplace, prepare = readProject, stillCurrent = () => true) => {
|
|
517
518
|
if (disposed || busy) return "cancelled";
|
|
518
519
|
busy = true;
|
|
519
520
|
const priorStage = vm.runtime.getTargetForStage();
|
|
@@ -523,6 +524,7 @@ function createFolderSession(vm, host) {
|
|
|
523
524
|
if (!chosen || disposed) return "cancelled";
|
|
524
525
|
const storage = vm.runtime.storage;
|
|
525
526
|
const source = await prepare(chosen.directory);
|
|
527
|
+
if (source === "not-project") return disposed ? "cancelled" : "not-project";
|
|
526
528
|
if (!source || disposed || !stillCurrent() || vm.runtime.getTargetForStage() !== priorStage) return "cancelled";
|
|
527
529
|
if (host.isProjectDirty() && !confirmReplace()) return "cancelled";
|
|
528
530
|
host.beforeLoad();
|
|
@@ -705,7 +707,7 @@ function createFolderSession(vm, host) {
|
|
|
705
707
|
var _current$source$direc;
|
|
706
708
|
return (_current$source$direc = current === null || current === void 0 ? void 0 : current.source.directory) !== null && _current$source$direc !== void 0 ? _current$source$direc : null;
|
|
707
709
|
},
|
|
708
|
-
/** The folder the user chose: `directory` itself,
|
|
710
|
+
/** The folder the user chose: `directory` itself, unless a host gave another one to `openDirectory`. */
|
|
709
711
|
get root() {
|
|
710
712
|
var _current$root;
|
|
711
713
|
return (_current$root = current === null || current === void 0 ? void 0 : current.root) !== null && _current$root !== void 0 ? _current$root : null;
|
|
@@ -810,9 +812,12 @@ function createFolderSession(vm, host) {
|
|
|
810
812
|
return openFrom(() => Promise.resolve(current === session ? {
|
|
811
813
|
directory: session.source.directory,
|
|
812
814
|
root: session.root
|
|
813
|
-
} : null), confirmReplace);
|
|
815
|
+
} : null), confirmReplace, (directory) => readFolder(directory, vm.runtime.storage));
|
|
814
816
|
},
|
|
815
|
-
/**
|
|
817
|
+
/**
|
|
818
|
+
* `pick` gives the folder to open and, when a host located the project in another folder the user chose, that
|
|
819
|
+
* folder as `root`. Resolves with `not-project` when the folder is not a project folder.
|
|
820
|
+
*/
|
|
816
821
|
open(pick, confirmReplace) {
|
|
817
822
|
return openFrom(async () => {
|
|
818
823
|
try {
|
|
@@ -827,8 +832,9 @@ function createFolderSession(vm, host) {
|
|
|
827
832
|
}, confirmReplace);
|
|
828
833
|
},
|
|
829
834
|
/**
|
|
830
|
-
* Opens
|
|
831
|
-
* chose, for a host that located the project
|
|
835
|
+
* Opens the project at the root of `directory`, or resolves with `not-project` and changes nothing when the
|
|
836
|
+
* folder is not a project folder. `root` is the folder the user chose, for a host that located the project in
|
|
837
|
+
* it; it defaults to `directory`.
|
|
832
838
|
*/
|
|
833
839
|
openDirectory(directory, confirmReplace, root) {
|
|
834
840
|
return openFrom(() => Promise.resolve({
|
|
@@ -1315,7 +1321,7 @@ async function zipDirectory(directory, { exclude = () => false } = {}) {
|
|
|
1315
1321
|
], { type: "application/zip" });
|
|
1316
1322
|
}
|
|
1317
1323
|
// src/browser-project-dialog.ts
|
|
1318
|
-
var messages$
|
|
1324
|
+
var messages$2 = {
|
|
1319
1325
|
en: {
|
|
1320
1326
|
openTitle: "Project Folders in This Browser",
|
|
1321
1327
|
createTitle: "New Project Folder in This Browser",
|
|
@@ -1390,11 +1396,11 @@ async function exportBrowserProject(document, projects, project) {
|
|
|
1390
1396
|
}
|
|
1391
1397
|
/**
|
|
1392
1398
|
* Shows the project folders kept in this browser. With `purpose: 'open'` the user picks one; with `'create'` the user
|
|
1393
|
-
* names a new empty one. Resolves with the chosen folder, or `null` when the dialog closes without one.
|
|
1399
|
+
* names a new empty one. Resolves with the chosen stored folder, or `null` when the dialog closes without one.
|
|
1394
1400
|
*/
|
|
1395
1401
|
function chooseBrowserProject({ document, projects, locale = "en", purpose, title = "" }) {
|
|
1396
1402
|
var _ref, _ref2, _dialog$querySelector;
|
|
1397
|
-
const message = locale.startsWith("ja") ? messages$
|
|
1403
|
+
const message = locale.startsWith("ja") ? messages$2.ja : messages$2.en;
|
|
1398
1404
|
const view = document.defaultView;
|
|
1399
1405
|
const dialog = document.createElement("dialog");
|
|
1400
1406
|
dialog.dataset.browserProjects = purpose;
|
|
@@ -1607,7 +1613,7 @@ function chooseBrowserProject({ document, projects, locale = "en", purpose, titl
|
|
|
1607
1613
|
return element;
|
|
1608
1614
|
};
|
|
1609
1615
|
item.append(text, button(message.open, async () => {
|
|
1610
|
-
const directory = await projects.
|
|
1616
|
+
const directory = await projects.root(project.id);
|
|
1611
1617
|
if (!directory) return render();
|
|
1612
1618
|
finish({
|
|
1613
1619
|
project,
|
|
@@ -1640,6 +1646,88 @@ function chooseBrowserProject({ document, projects, locale = "en", purpose, titl
|
|
|
1640
1646
|
(_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();
|
|
1641
1647
|
return result;
|
|
1642
1648
|
}
|
|
1649
|
+
// src/not-project-dialog.ts
|
|
1650
|
+
var messages$1 = {
|
|
1651
|
+
en: {
|
|
1652
|
+
title: "Cannot Open Folder",
|
|
1653
|
+
notProject: "This folder is not a project folder.",
|
|
1654
|
+
ok: "OK"
|
|
1655
|
+
},
|
|
1656
|
+
ja: {
|
|
1657
|
+
title: "フォルダを開けません",
|
|
1658
|
+
notProject: "このフォルダはプロジェクトフォルダではありません。",
|
|
1659
|
+
ok: "OK"
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
var dialogs = 0;
|
|
1663
|
+
/** The message the dialog shows, for a host that tells the user in its own way. */
|
|
1664
|
+
var notProjectFolderMessage = (locale = "en") => (locale.startsWith("ja") ? messages$1.ja : messages$1.en).notProject;
|
|
1665
|
+
/**
|
|
1666
|
+
* Tells the user, in a modal dialog, that the folder they tried to open is not a project folder. Resolves when the
|
|
1667
|
+
* dialog closes, after the focus went back to where it was.
|
|
1668
|
+
*/
|
|
1669
|
+
async function showNotProjectFolderDialog({ document, locale = "en" }) {
|
|
1670
|
+
const message = locale.startsWith("ja") ? messages$1.ja : messages$1.en;
|
|
1671
|
+
const returnFocus = document.activeElement;
|
|
1672
|
+
const id = `tw-plus-project-folder-error-${++dialogs}`;
|
|
1673
|
+
const dialog = document.createElement("dialog");
|
|
1674
|
+
dialog.dataset.projectFolderError = "not-project";
|
|
1675
|
+
dialog.setAttribute("role", "alertdialog");
|
|
1676
|
+
dialog.setAttribute("aria-labelledby", `${id}-title`);
|
|
1677
|
+
dialog.setAttribute("aria-describedby", `${id}-message`);
|
|
1678
|
+
Object.assign(dialog.style, {
|
|
1679
|
+
width: "min(26rem, calc(100vw - 2rem))",
|
|
1680
|
+
padding: "1rem 1.25rem",
|
|
1681
|
+
background: "Canvas",
|
|
1682
|
+
color: "CanvasText",
|
|
1683
|
+
border: "1px solid GrayText",
|
|
1684
|
+
borderRadius: "0.5rem",
|
|
1685
|
+
fontFamily: "inherit",
|
|
1686
|
+
fontSize: "0.875rem",
|
|
1687
|
+
boxSizing: "border-box"
|
|
1688
|
+
});
|
|
1689
|
+
const heading = document.createElement("h2");
|
|
1690
|
+
heading.id = `${id}-title`;
|
|
1691
|
+
heading.textContent = message.title;
|
|
1692
|
+
Object.assign(heading.style, {
|
|
1693
|
+
margin: "0 0 0.5rem",
|
|
1694
|
+
fontSize: "1rem"
|
|
1695
|
+
});
|
|
1696
|
+
const text = document.createElement("p");
|
|
1697
|
+
text.id = `${id}-message`;
|
|
1698
|
+
text.textContent = message.notProject;
|
|
1699
|
+
Object.assign(text.style, { margin: "0 0 1rem" });
|
|
1700
|
+
const footer = document.createElement("div");
|
|
1701
|
+
Object.assign(footer.style, {
|
|
1702
|
+
display: "flex",
|
|
1703
|
+
justifyContent: "flex-end"
|
|
1704
|
+
});
|
|
1705
|
+
const ok = document.createElement("button");
|
|
1706
|
+
ok.type = "button";
|
|
1707
|
+
ok.textContent = message.ok;
|
|
1708
|
+
footer.append(ok);
|
|
1709
|
+
dialog.append(heading, text, footer);
|
|
1710
|
+
await new Promise((resolve) => {
|
|
1711
|
+
let settled = false;
|
|
1712
|
+
const finish = () => {
|
|
1713
|
+
if (settled) return;
|
|
1714
|
+
settled = true;
|
|
1715
|
+
if (dialog.open) dialog.close();
|
|
1716
|
+
dialog.remove();
|
|
1717
|
+
if ((returnFocus === null || returnFocus === void 0 ? void 0 : returnFocus.isConnected) && typeof returnFocus.focus === "function") returnFocus.focus();
|
|
1718
|
+
resolve();
|
|
1719
|
+
};
|
|
1720
|
+
ok.addEventListener("click", finish);
|
|
1721
|
+
dialog.addEventListener("cancel", (event) => {
|
|
1722
|
+
event.preventDefault();
|
|
1723
|
+
finish();
|
|
1724
|
+
});
|
|
1725
|
+
dialog.addEventListener("close", finish);
|
|
1726
|
+
document.body.append(dialog);
|
|
1727
|
+
dialog.showModal();
|
|
1728
|
+
ok.focus();
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1643
1731
|
// src/index.ts
|
|
1644
1732
|
var messages = {
|
|
1645
1733
|
en: {
|
|
@@ -1736,16 +1824,15 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1736
1824
|
if (!choice) throw abort();
|
|
1737
1825
|
return choice;
|
|
1738
1826
|
};
|
|
1739
|
-
const chooseBrowserFolder = async () => {
|
|
1740
|
-
var _await$browserProject;
|
|
1741
|
-
const { project, directory } = await chooseBrowser("open");
|
|
1742
|
-
return {
|
|
1743
|
-
directory,
|
|
1744
|
-
root: (_await$browserProject = await browserProjects.root(project.id).catch(() => null)) !== null && _await$browserProject !== void 0 ? _await$browserProject : directory
|
|
1745
|
-
};
|
|
1746
|
-
};
|
|
1827
|
+
const chooseBrowserFolder = async () => ({ directory: (await chooseBrowser("open")).directory });
|
|
1747
1828
|
const pickDirectory = devicePicker ? async (options) => ({ directory: await devicePicker.call(view, options) }) : chooseBrowserFolder;
|
|
1748
|
-
const
|
|
1829
|
+
const locations = [];
|
|
1830
|
+
if (devicePicker) locations.push("device");
|
|
1831
|
+
if (browserProjects) locations.push("browser");
|
|
1832
|
+
const pickNewDirectory = async (options, title, location = devicePicker ? "device" : "browser") => {
|
|
1833
|
+
if (!locations.includes(location)) throw new FolderError("unsupported");
|
|
1834
|
+
return location === "device" ? devicePicker.call(view, options) : (await chooseBrowser("create", title)).directory;
|
|
1835
|
+
};
|
|
1749
1836
|
/** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
|
|
1750
1837
|
const withBrowserProject = async (directory, run) => {
|
|
1751
1838
|
const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
|
|
@@ -1790,6 +1877,10 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1790
1877
|
const detail = error instanceof FolderError && error.message !== error.code ? ` (${error.message})` : "";
|
|
1791
1878
|
report((error instanceof FolderError ? message[error.code] : message.failed) + detail);
|
|
1792
1879
|
};
|
|
1880
|
+
const notProject = (locale) => showNotProjectFolderDialog({
|
|
1881
|
+
document,
|
|
1882
|
+
locale
|
|
1883
|
+
}).catch(() => report(notProjectFolderMessage(locale)));
|
|
1793
1884
|
let stopWatching;
|
|
1794
1885
|
let renderReload = () => {};
|
|
1795
1886
|
if (host.blockReload) {
|
|
@@ -1931,21 +2022,21 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1931
2022
|
notice.remove();
|
|
1932
2023
|
};
|
|
1933
2024
|
}
|
|
2025
|
+
const opened = (locale, result) => {
|
|
2026
|
+
if (result === "opened") report(messageFor(locale).opened);
|
|
2027
|
+
else if (result === "not-project") notProject(locale);
|
|
2028
|
+
};
|
|
1934
2029
|
const menu = {
|
|
1935
2030
|
deviceFolders: typeof devicePicker === "function",
|
|
1936
2031
|
session,
|
|
1937
2032
|
open(locale) {
|
|
1938
2033
|
const message = messageFor(locale);
|
|
1939
|
-
session.open((options) => pickDirectory(options), () => view.confirm(message.replace)).then((result) =>
|
|
1940
|
-
if (result === "opened") report(message.opened);
|
|
1941
|
-
}, (error) => fail(locale, error)).finally(renderReload);
|
|
2034
|
+
session.open((options) => pickDirectory(options), () => view.confirm(message.replace)).then((result) => opened(locale, result), (error) => fail(locale, error)).finally(renderReload);
|
|
1942
2035
|
renderReload();
|
|
1943
2036
|
},
|
|
1944
2037
|
openBrowser: browserProjects ? (locale) => {
|
|
1945
2038
|
const message = messageFor(locale);
|
|
1946
|
-
session.open(chooseBrowserFolder, () => view.confirm(message.replace)).then((result) =>
|
|
1947
|
-
if (result === "opened") report(message.opened);
|
|
1948
|
-
}, (error) => fail(locale, error)).finally(renderReload);
|
|
2039
|
+
session.open(chooseBrowserFolder, () => view.confirm(message.replace)).then((result) => opened(locale, result), (error) => fail(locale, error)).finally(renderReload);
|
|
1949
2040
|
renderReload();
|
|
1950
2041
|
} : void 0,
|
|
1951
2042
|
save(locale) {
|
|
@@ -1973,6 +2064,7 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1973
2064
|
get root() {
|
|
1974
2065
|
return session.root;
|
|
1975
2066
|
},
|
|
2067
|
+
locations,
|
|
1976
2068
|
subscribe: (listener) => session.subscribe(listener),
|
|
1977
2069
|
subscribeEdits: (listener) => session.subscribeEdits(listener),
|
|
1978
2070
|
unsavedPaths: () => session.unsavedPaths(),
|
|
@@ -1980,7 +2072,17 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1980
2072
|
mutate: (directory, operation) => session.mutate(directory, operation).finally(renderReload)
|
|
1981
2073
|
});
|
|
1982
2074
|
return {
|
|
1983
|
-
|
|
2075
|
+
/**
|
|
2076
|
+
* Opens the project at the root of `directory`, as the user's Open would, and resolves with the result. A folder
|
|
2077
|
+
* that is not a project folder changes nothing, shows the error dialog unless `options.notProjectDialog` is
|
|
2078
|
+
* false, and resolves with `not-project`. `root` is the folder the user chose, for a host that located the
|
|
2079
|
+
* project in it; it defaults to `directory`.
|
|
2080
|
+
*/
|
|
2081
|
+
openDirectory: (directory, confirmReplace, root, options = {}) => session.openDirectory(directory, confirmReplace, root !== null && root !== void 0 ? root : void 0).then((result) => {
|
|
2082
|
+
var _options$locale;
|
|
2083
|
+
if (result === "not-project" && options.notProjectDialog !== false) notProject((_options$locale = options.locale) !== null && _options$locale !== void 0 ? _options$locale : locale);
|
|
2084
|
+
return result;
|
|
2085
|
+
}).finally(renderReload),
|
|
1984
2086
|
unsavedPaths: () => session.unsavedPaths(),
|
|
1985
2087
|
readUnsavedFile: (path) => session.readUnsavedFile(path),
|
|
1986
2088
|
subscribeEdits: (listener) => session.subscribeEdits(listener),
|
|
@@ -1991,14 +2093,14 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1991
2093
|
* Creates a project folder from a snapshot. `title` names a folder made in the browser, where the user names a
|
|
1992
2094
|
* new folder instead of picking one on the device.
|
|
1993
2095
|
*/
|
|
1994
|
-
createFromSnapshot({ prepareFiles, collectEdits, directory, current = () => true, title }) {
|
|
2096
|
+
createFromSnapshot({ prepareFiles, collectEdits, directory, current = () => true, title, location }) {
|
|
1995
2097
|
const message = locale.startsWith("ja") ? "指定されたフォルダは空ではありません。フォルダに保存されている内容が上書きされる場合があります。よろしいですか?" : "The selected folder is not empty. Contents in the folder may be overwritten. Continue?";
|
|
1996
2098
|
return session.createFromSnapshot(async () => {
|
|
1997
2099
|
try {
|
|
1998
2100
|
const selected = directory !== null && directory !== void 0 ? directory : await pickNewDirectory({
|
|
1999
2101
|
id: "turbowarp-plus-project-folder",
|
|
2000
2102
|
mode: "readwrite"
|
|
2001
|
-
}, title);
|
|
2103
|
+
}, title, location);
|
|
2002
2104
|
if (!current()) return null;
|
|
2003
2105
|
const overwrite = !await isProjectFolderEmpty(selected);
|
|
2004
2106
|
if (!current() || overwrite && !view.confirm(message)) return null;
|
|
@@ -2021,8 +2123,8 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
2021
2123
|
return session.directory;
|
|
2022
2124
|
},
|
|
2023
2125
|
/**
|
|
2024
|
-
* The folder the user chose for the loaded project, or `null` like `directory`. It is `directory` itself,
|
|
2025
|
-
*
|
|
2126
|
+
* The folder the user chose for the loaded project, or `null` like `directory`. It is `directory` itself, the
|
|
2127
|
+
* project folder, unless the host gave another folder to `openDirectory`.
|
|
2026
2128
|
*/
|
|
2027
2129
|
get root() {
|
|
2028
2130
|
return session.root;
|
|
@@ -2084,4 +2186,4 @@ function renderProjectFolderMenu(createElement, { vm, locale = "en", MenuItem, M
|
|
|
2084
2186
|
};
|
|
2085
2187
|
return createElement(MenuSection, null, item("open"), entry.openBrowser ? item("openBrowser") : null, entry.session.canSave ? item("save") : null);
|
|
2086
2188
|
}
|
|
2087
|
-
export { chooseBrowserProject, createProjectFolder, exportBrowserProject, followProjectFolder, mountProjectFolder, openBrowserProjects, parseExplorerState, projectFolderActions, projectFolderOverwriteWarning, readExplorerState, renderProjectFolderMenu, subscribeExplorerState, writeExplorerState, zipDirectory, zipFileName };
|
|
2189
|
+
export { chooseBrowserProject, createProjectFolder, exportBrowserProject, followProjectFolder, mountProjectFolder, notProjectFolderMessage, openBrowserProjects, parseExplorerState, projectFolderActions, projectFolderOverwriteWarning, readExplorerState, renderProjectFolderMenu, showNotProjectFolderDialog, subscribeExplorerState, writeExplorerState, zipDirectory, zipFileName };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The message the dialog shows, for a host that tells the user in its own way. */
|
|
2
|
+
export declare const notProjectFolderMessage: (locale?: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Tells the user, in a modal dialog, that the folder they tried to open is not a project folder. Resolves when the
|
|
5
|
+
* dialog closes, after the focus went back to where it was.
|
|
6
|
+
*/
|
|
7
|
+
export declare function showNotProjectFolderDialog({ document, locale }: {
|
|
8
|
+
document: Document;
|
|
9
|
+
locale?: string;
|
|
10
|
+
}): Promise<void>;
|
package/dist/session.d.ts
CHANGED
|
@@ -103,7 +103,12 @@ export type Chosen = {
|
|
|
103
103
|
export type ReloadState = 'ready' | 'full' | 'waiting' | 'dirty' | 'running' | 'busy' | null;
|
|
104
104
|
/** What the reload command does for the pending change, regardless of whether it may run now. */
|
|
105
105
|
export type ReloadKind = 'partial' | 'full' | null;
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* `opened`: the folder's project is loaded. `cancelled`: nothing was opened, as when the user closed the picker or kept
|
|
108
|
+
* unsaved edits. `not-project`: the folder's root lacks `project.source.json`, `sb3-source.json` or
|
|
109
|
+
* `embedded-extensions.json`, so it is not a project folder and nothing was opened either.
|
|
110
|
+
*/
|
|
111
|
+
export type OpenResult = 'opened' | 'cancelled' | 'not-project';
|
|
107
112
|
type SaveResult = {
|
|
108
113
|
status: 'saved' | 'unchanged';
|
|
109
114
|
sourceRemoved: string[];
|
|
@@ -128,7 +133,7 @@ export declare function createFolderSession(vm: FolderVM, host: FolderHost): {
|
|
|
128
133
|
/** Identifies the pending project file version, so a host can attempt an automatic apply only once. */
|
|
129
134
|
readonly pendingVersion: string | null;
|
|
130
135
|
readonly directory: FileSystemDirectoryHandle | null;
|
|
131
|
-
/** The folder the user chose: `directory` itself,
|
|
136
|
+
/** The folder the user chose: `directory` itself, unless a host gave another one to `openDirectory`. */
|
|
132
137
|
readonly root: FileSystemDirectoryHandle | null;
|
|
133
138
|
mutate(directory: FileSystemDirectoryHandle, operation: (guard: () => void) => Promise<void>): Promise<void>;
|
|
134
139
|
/**
|
|
@@ -143,14 +148,18 @@ export declare function createFolderSession(vm: FolderVM, host: FolderHost): {
|
|
|
143
148
|
* edits are discarded only when `confirmReplace` agrees. The VM is left untouched while a project runs.
|
|
144
149
|
*/
|
|
145
150
|
reloadAll(confirmReplace: () => boolean): Promise<OpenResult>;
|
|
146
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* `pick` gives the folder to open and, when a host located the project in another folder the user chose, that
|
|
153
|
+
* folder as `root`. Resolves with `not-project` when the folder is not a project folder.
|
|
154
|
+
*/
|
|
147
155
|
open(pick: (options: {
|
|
148
156
|
id: string;
|
|
149
157
|
mode: "readwrite";
|
|
150
158
|
}) => Promise<Chosen>, confirmReplace: () => boolean): Promise<OpenResult>;
|
|
151
159
|
/**
|
|
152
|
-
* Opens
|
|
153
|
-
* chose, for a host that located the project
|
|
160
|
+
* Opens the project at the root of `directory`, or resolves with `not-project` and changes nothing when the
|
|
161
|
+
* folder is not a project folder. `root` is the folder the user chose, for a host that located the project in
|
|
162
|
+
* it; it defaults to `directory`.
|
|
154
163
|
*/
|
|
155
164
|
openDirectory(directory: FileSystemDirectoryHandle, confirmReplace: () => boolean, root?: FileSystemDirectoryHandle): Promise<OpenResult>;
|
|
156
165
|
createFromSnapshot(selectDestination: () => Promise<{
|
|
@@ -404,6 +404,12 @@ var _excluded3 = ["targets"];
|
|
|
404
404
|
var projectFile = "project.source.json";
|
|
405
405
|
var manifestFile = "sb3-source.json";
|
|
406
406
|
var extensionsFile = "embedded-extensions.json";
|
|
407
|
+
/** The files at the root of every project folder, the ones `readFolder` reads before anything else. */
|
|
408
|
+
var projectFolderFiles = [
|
|
409
|
+
projectFile,
|
|
410
|
+
manifestFile,
|
|
411
|
+
extensionsFile
|
|
412
|
+
];
|
|
407
413
|
/** The ZIP entry of the Editor's screen state, which sb3-toolchain lists in `archiveEntries`. */
|
|
408
414
|
var screenStateEntry = "tw-plus/workspace.json";
|
|
409
415
|
/** Block palette settings of source format 2. Format 1 folders have no such file. */
|
|
@@ -671,12 +677,7 @@ async function readFolder(directory, storage) {
|
|
|
671
677
|
versions.set(prefix + name, fileVersion(file));
|
|
672
678
|
return [name, await fileBytes(file)];
|
|
673
679
|
};
|
|
674
|
-
const
|
|
675
|
-
projectFile,
|
|
676
|
-
manifestFile,
|
|
677
|
-
extensionsFile
|
|
678
|
-
];
|
|
679
|
-
const files = new Map(await Promise.all(filenames.map((name) => readEntry(directory, name))));
|
|
680
|
+
const files = new Map(await Promise.all(projectFolderFiles.map((name) => readEntry(directory, name))));
|
|
680
681
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
681
682
|
const projectText = decoder.decode(files.get(projectFile));
|
|
682
683
|
const project = parseProject(projectText);
|
|
@@ -726,40 +727,20 @@ async function readFolder(directory, storage) {
|
|
|
726
727
|
palette: paletteDocument
|
|
727
728
|
};
|
|
728
729
|
}
|
|
729
|
-
/** The project folder inside a repository, as Project Starter makes it. */
|
|
730
|
-
var projectSubfolder = "project";
|
|
731
730
|
var missingEntry = (error) => error instanceof DOMException && ["NotFoundError", "TypeMismatchError"].includes(error.name);
|
|
732
|
-
/** Whether `directory` has an entry called `name`, a file or a folder. */
|
|
733
|
-
async function hasEntry(directory, name) {
|
|
734
|
-
for (const get of [() => directory.getFileHandle(name), () => directory.getDirectoryHandle(name)]) try {
|
|
735
|
-
await get();
|
|
736
|
-
return true;
|
|
737
|
-
} catch (error) {
|
|
738
|
-
if (!missingEntry(error)) throw error;
|
|
739
|
-
}
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
731
|
/**
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
732
|
+
* Whether `directory` is a project folder: its root has every file in `projectFolderFiles`. The files are not read, so a
|
|
733
|
+
* project folder may still be broken or unsupported, which `readFolder` reports. Other errors, such as a withdrawn
|
|
734
|
+
* permission, are thrown.
|
|
746
735
|
*/
|
|
747
|
-
async function
|
|
748
|
-
try {
|
|
749
|
-
|
|
736
|
+
async function isProjectFolder(directory) {
|
|
737
|
+
for (const name of projectFolderFiles) try {
|
|
738
|
+
await directory.getFileHandle(name);
|
|
750
739
|
} catch (error) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const found = await directory.getDirectoryHandle(projectSubfolder);
|
|
754
|
-
return await hasEntry(found, ".git") ? null : found;
|
|
755
|
-
})().catch(() => null);
|
|
756
|
-
if (!child) throw error;
|
|
757
|
-
try {
|
|
758
|
-
return await readFolder(child, storage);
|
|
759
|
-
} catch (_unused2) {
|
|
760
|
-
throw error;
|
|
761
|
-
}
|
|
740
|
+
if (missingEntry(error)) return false;
|
|
741
|
+
throw error;
|
|
762
742
|
}
|
|
743
|
+
return true;
|
|
763
744
|
}
|
|
764
745
|
var sameBytes = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
|
|
765
746
|
async function readFolderUpdate(source, previous) {
|
|
@@ -1172,7 +1153,7 @@ function registerFolder(vm, folder) {
|
|
|
1172
1153
|
}
|
|
1173
1154
|
/**
|
|
1174
1155
|
* Calls `listener` with the project folder mounted for `vm`, the directory open in it and the folder the user chose for
|
|
1175
|
-
* it (`root`, the directory itself
|
|
1156
|
+
* it (`root`, the directory itself unless a host gave another one), now and whenever a folder is
|
|
1176
1157
|
* mounted, opened, closed or saved. `directory` and `root` are `null` while no folder is open. Returns the function
|
|
1177
1158
|
* that stops it.
|
|
1178
1159
|
*/
|
|
@@ -1199,4 +1180,4 @@ function followProjectFolder(vm, listener) {
|
|
|
1199
1180
|
unsubscribe();
|
|
1200
1181
|
};
|
|
1201
1182
|
}
|
|
1202
|
-
export {
|
|
1183
|
+
export { projectChanges as A, isObject as C, parseProject as D, paletteFile as E, unsupported as F, _asyncIterator as I, _objectWithoutProperties as L, readFolder as M, readFolderUpdate as N, planExtensionSave as O, sameBytes as P, _objectSpread2 as R, fileVersion as S, manifestFile as T, collapsePalette as _, projectFolderOverwriteWarning as a, expandPalette as b, parseExplorerState as c, subscribeExplorerState as d, writeExplorerState as f, assetTypeFor as g, assetKey as h, isProjectFolderEmpty as i, projectFile as j, projectAssets as k, readExplorerState as l, assertFolderUnchanged as m, registerFolder as n, editorDirectory as o, FolderError as p, createProjectFolder as r, hiddenEntry as s, followProjectFolder as t, screenStateFile as u, encodePalette as v, isProjectFolder as w, extensionsFile as x, equal as y };
|
package/dist/source.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ type Target = JsonObject & {
|
|
|
15
15
|
export declare const projectFile = "project.source.json";
|
|
16
16
|
export declare const manifestFile = "sb3-source.json";
|
|
17
17
|
export declare const extensionsFile = "embedded-extensions.json";
|
|
18
|
+
/** The files at the root of every project folder, the ones `readFolder` reads before anything else. */
|
|
19
|
+
export declare const projectFolderFiles: readonly ["project.source.json", "sb3-source.json", "embedded-extensions.json"];
|
|
18
20
|
/** Block palette settings of source format 2. Format 1 folders have no such file. */
|
|
19
21
|
export declare const paletteFile = "block-palette.json";
|
|
20
22
|
export declare class FolderError extends Error {
|
|
@@ -100,14 +102,12 @@ export declare function planExtensionSave(source: FolderSource, project: Project
|
|
|
100
102
|
removed: string[];
|
|
101
103
|
};
|
|
102
104
|
export declare function readFolder(directory: FileSystemDirectoryHandle, storage: Storage): Promise<FolderSource>;
|
|
103
|
-
/** The project folder inside a repository, as Project Starter makes it. */
|
|
104
|
-
export declare const projectSubfolder = "project";
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
106
|
+
* Whether `directory` is a project folder: its root has every file in `projectFolderFiles`. The files are not read, so a
|
|
107
|
+
* project folder may still be broken or unsupported, which `readFolder` reports. Other errors, such as a withdrawn
|
|
108
|
+
* permission, are thrown.
|
|
109
109
|
*/
|
|
110
|
-
export declare function
|
|
110
|
+
export declare function isProjectFolder(directory: FileSystemDirectoryHandle): Promise<boolean>;
|
|
111
111
|
export declare const sameBytes: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
112
112
|
export type FolderUpdate = {
|
|
113
113
|
version: string;
|
package/package.json
CHANGED
|
@@ -69,7 +69,7 @@ export type BrowserProjectChoice = {project: BrowserProject; directory: FileSyst
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Shows the project folders kept in this browser. With `purpose: 'open'` the user picks one; with `'create'` the user
|
|
72
|
-
* names a new empty one. Resolves with the chosen folder, or `null` when the dialog closes without one.
|
|
72
|
+
* names a new empty one. Resolves with the chosen stored folder, or `null` when the dialog closes without one.
|
|
73
73
|
*/
|
|
74
74
|
export function chooseBrowserProject({document, projects, locale = 'en', purpose, title = ''}: {
|
|
75
75
|
document: Document; projects: BrowserProjects; locale?: string; purpose: 'open' | 'create'; title?: string;
|
|
@@ -222,8 +222,9 @@ export function chooseBrowserProject({document, projects, locale = 'en', purpose
|
|
|
222
222
|
return element;
|
|
223
223
|
};
|
|
224
224
|
item.append(text,
|
|
225
|
+
// The project is at the root of the stored folder, as on the device.
|
|
225
226
|
button(message.open, async () => {
|
|
226
|
-
const directory = await projects.
|
|
227
|
+
const directory = await projects.root(project.id);
|
|
227
228
|
if (!directory) return render();
|
|
228
229
|
finish({project, directory});
|
|
229
230
|
}),
|
package/src/browser-projects.ts
CHANGED
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
* browser may delete them; a user keeps a copy by exporting a ZIP or pushing to GitHub.
|
|
5
5
|
*
|
|
6
6
|
* Layout under the OPFS root:
|
|
7
|
-
* turbowarp-plus/projects/<id>/ the folder
|
|
7
|
+
* turbowarp-plus/projects/<id>/ the folder, a project folder with the project at its root
|
|
8
8
|
* turbowarp-plus/project-info/<id>.json its title and times, kept outside the folder so Git never sees them
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export interface BrowserProject {
|
|
12
12
|
id: string;
|
|
13
13
|
title: string;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A folder inside the stored folder, `''` for the stored folder itself. Only for compatibility: the Editor opens the
|
|
16
|
+
* project at the root of the stored folder, so an entry with another path is not a project folder there.
|
|
17
|
+
*/
|
|
15
18
|
projectPath: string;
|
|
16
19
|
createdAt: number;
|
|
17
20
|
updatedAt: number;
|
|
@@ -29,7 +32,7 @@ export interface BrowserProjects {
|
|
|
29
32
|
directory: FileSystemDirectoryHandle}>;
|
|
30
33
|
/** The stored folder, or `null` when it was deleted. */
|
|
31
34
|
root(id: string): Promise<FileSystemDirectoryHandle | null>;
|
|
32
|
-
/** The
|
|
35
|
+
/** The folder `projectPath` inside the entry's stored folder. Opening uses `root` instead. */
|
|
33
36
|
directory(id: string): Promise<FileSystemDirectoryHandle | null>;
|
|
34
37
|
/** The entry that holds `handle`, or `null` when it is not in the browser's storage. */
|
|
35
38
|
find(handle: FileSystemHandle): Promise<BrowserProject | null>;
|