@kubohiroya/turbowarp-plus-editor-project-folder 0.15.1 → 0.16.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 +7 -5
- package/README.md +7 -5
- package/dist/explorer.js +6 -6
- package/dist/folder-registry.d.ts +8 -4
- package/dist/index.d.ts +8 -1
- package/dist/index.js +72 -21
- package/dist/session.d.ts +17 -2
- package/dist/{shared-CUZGohh-.js → shared-CwQoV7xd.js} +1 -1
- package/dist/{shared-cwwWtggC.js → shared-h5VGx9Jp.js} +46 -6
- package/dist/source.d.ts +8 -0
- package/package.json +1 -1
- package/src/explorer.tsx +2 -2
- package/src/folder-registry.ts +11 -7
- package/src/index.ts +36 -12
- package/src/session.ts +27 -14
- package/src/source.ts +40 -0
package/README.ja.md
CHANGED
|
@@ -8,8 +8,10 @@ TurboWarp Plus Editor で sb3-toolchain の作品フォルダ(展開ソース
|
|
|
8
8
|
|
|
9
9
|
- `mountProjectFolder({vm, document, host})` でワークスペースに接続します。ワークスペースの切り替え時には `dispose()` を呼びます。
|
|
10
10
|
- `renderProjectFolderMenu(createElement, props)` は既存の開く・保存コマンドをホストのファイルメニューに渡します。
|
|
11
|
-
-
|
|
11
|
+
- 選んだフォルダの直下に作品がなく、その中の `project` フォルダが作品フォルダのときは、`project` を作品フォルダとして開きます(Project Starter が作るリポジトリの形)。`project` フォルダの中に `.git` があるときは開きません。どちらも作品でないときは、選んだフォルダのエラーをそのまま出します。
|
|
12
|
+
- 接続後の `openDirectory(handle, confirmReplace, root?)` には、ホストが選択済みのディレクトリハンドルを渡せます。ファイルメニューと同じ作品検証・`project` フォルダへの切り替え・未保存編集の確認を経て開き、保存先にはその作品フォルダを使います。`root` には、ホストが自分で作品の場所を見つけたときに、ユーザーが選んだフォルダを渡します。省略すると `handle` です。
|
|
12
13
|
- 接続後の `directory` は、読み込んだ作品のフォルダーのハンドルです。別の作品を読み込むか、フォルダーとの接続を外すと `null` になります。ホストは作品を見分けるのに使えます。
|
|
14
|
+
- 接続後の `root` は、その作品のためにユーザーが選んだフォルダーです。`directory` そのもの、`directory` を `project` フォルダに持つリポジトリ、またはブラウザーに保存したフォルダでは保存したフォルダー全体を指します。`directory` が `null` のときは `null` です。ブラウザーではフォルダーの親を読めないので、ホストは Git のリポジトリを `root` に結び付けます。
|
|
13
15
|
- `host.screenState` を渡すと、Editor の画面状態をフォルダーに保存します。渡すものは workbench の `installProjectScreenState` が返すものです。作品フォルダーは SB3 ではないので、状態は `.tw-plus/workspace.json` に入れます。フォルダーを開くと、作品を読み込む前にこれを読み、`prepareLoad(text)` で渡します。保存時は、作品が変わっていなくても `serialize()` の結果を書きます。保存時刻だけが違うときは書きません。読み書きに失敗しても、開く操作と保存は失敗にしません。セッションは `projectFolder` スライス(ツリーで開いたフォルダーと選択中の項目)も登録します。SB3 から作品フォルダを作るとき、sb3-toolchain(0.26.0 以降)が展開したスナップショットに `.tw-plus/workspace.json` があれば、そのままフォルダーに書くので、作ったフォルダーは同じ画面で開きます。スナップショットにないときは、上書きするフォルダーの古い `workspace.json` を消します。`.tw-plus` のほかのファイルは残します。
|
|
14
16
|
|
|
15
17
|
ホストは VM、メニューコンポーネント、作品状態を扱うコールバックを渡します。メニューからフォルダを開くには、ブラウザーが File System Access のフォルダ選択に対応しているか、[ブラウザー内の作品フォルダ](#ブラウザー内の作品フォルダ)を使える必要があります。ブロック、変数・リスト、スプライトの位置や大きさなどの項目、モニター、組み込みの拡張機能の編集を作品データ(`project.source.json`)に保存し、作品の実行で変わった状態も含みます。スプライトの追加・削除・名前の変更と、コスチューム・音の追加・削除も保存します。新しいアセットのファイルを先に書き、`sb3-source.json` と作品データを書いてから、参照されなくなったアセットのファイルを消します。 [Editor #305](https://github.com/kubohiroya/turbowarp-plus-editor/issues/305) · [Editor #308](https://github.com/kubohiroya/turbowarp-plus-editor/issues/308)
|
|
@@ -21,8 +23,8 @@ TurboWarp Plus Editor で sb3-toolchain の作品フォルダ(展開ソース
|
|
|
21
23
|
Safari と Firefox にはフォルダ選択(`showDirectoryPicker`)がありません。これらのブラウザーでは、作品フォルダをブラウザーの中の保存領域(OPFS、Origin Private File System)に置きます。読み書きの処理はデバイス上のフォルダと同じです。 [Editor #660](https://github.com/kubohiroya/turbowarp-plus-editor/issues/660)
|
|
22
24
|
|
|
23
25
|
- `mountProjectFolder` の `browserStorage` で使い方を選びます。
|
|
24
|
-
- `fallback
|
|
25
|
-
- `always
|
|
26
|
+
- `fallback`(既定):フォルダ選択がないブラウザー(Safari、Firefox)でだけ使います。ファイルメニューでは **フォルダを開く…** を、このブラウザーでは端末のフォルダを開けない旨を添えて無効にし、ブラウザー内の作品フォルダの一覧を開く **ブラウザーに保存したフォルダを開く…** を出します。`projectFolderActions(vm)` は `deviceFolders: false` を返すので、ホストのメニューでも同じように無効にできます。ホストが `open` を呼んだときは、これまでどおりブラウザー内のフォルダを開きます。`createFromSnapshot` は新しい作品フォルダの名前を尋ねます(`title` で名前の初期値を渡せます)。
|
|
27
|
+
- `always`:フォルダ選択があるブラウザーでも使います。ファイルメニューの **フォルダを開く…** の隣に **ブラウザーに保存したフォルダを開く…** を足し、`projectFolderActions(vm).openBrowser` でも開けます。
|
|
26
28
|
- `off`:使いません。
|
|
27
29
|
- 一覧のダイアログでは、作品フォルダを開く、ZIP で書き出す、削除することができます。保存領域の使用量と、ブラウザーが消さずに残すか(`persisted`)も表示します。閉じるボタンは X のアイコンで、名前は表示の言語に合わせます。
|
|
28
30
|
- 作品フォルダは `turbowarp-plus/projects/<id>/` に置き、表示名と時刻は `turbowarp-plus/project-info/<id>.json` に置きます。作品フォルダの外に置くので、Git の管理対象には入りません。`projectPath` を指定すると、リポジトリのルートの下の作品フォルダ(例:`project`)を開けます。
|
|
@@ -54,7 +56,7 @@ TurboWarp Plus Editor は、ブロックパレットの設定を画面状態(`
|
|
|
54
56
|
`./explorer`(`@kubohiroya/turbowarp-plus-editor-project-folder/explorer`)は、エディターのサイドパネルに置くフォルダのツリーです。[Headless Tree](https://headless-tree.lukasbach.com/) を同梱しています。描画にはホストの React 16.14〜18 を使います(省略可能な peer dependency)。メインの入口は React を使いません。
|
|
55
57
|
|
|
56
58
|
- `ProjectFolderExplorer` は `directory`(作品フォルダまたはリポジトリのルート)を表示します。フォルダは開いたときに読み込み、ファイルより先に並べます。`.git` と `.tw-plus` は表示しません。フォルダーごとの開いたフォルダーと選択中の項目はページの中で保持するので、横のパネルを開き直すと、前と同じツリーに戻ります。矢印キー・Home・End で移動と開閉をします。ファイルで Enter・Space を押すかクリックすると `onOpen({path, name, kind})` を呼びます。props は `directory`、`locale`(`ja…` で日本語、それ以外は英語)、`descriptions` と `marks`(Git の状態: `added`・`modified`・`deleted`・`untracked`、どちらも `directory` からの相対パスがキー)、`onOpen`、`label`(ツリーのアクセシブルな名前)です。読み込めないフォルダは、ツリーの中にメッセージを表示します。
|
|
57
|
-
- `renderProjectFolderExplorer(createElement, {vm, locale, marks})` は、`vm` で開いているプロジェクトフォルダのツリーを Editor の横のパネル向けに描きます。説明はフォルダの `project.source.json` と `sb3-source.json` から作り、保存のたびに読み直します。`marks(directory, update)` はそのフォルダの印を追い、止める関数を返します(Git パッケージの `followChangeMarks` など)。フォルダを開いていないときは
|
|
59
|
+
- `renderProjectFolderExplorer(createElement, {vm, locale, marks})` は、`vm` で開いているプロジェクトフォルダのツリーを Editor の横のパネル向けに描きます。説明はフォルダの `project.source.json` と `sb3-source.json` から作り、保存のたびに読み直します。`marks(directory, update)` はそのフォルダの印を追い、止める関数を返します(Git パッケージの `followChangeMarks` など)。フォルダを開いていないときは **フォルダを開く…** を出し、`vm` にプロジェクトフォルダを組み込んでいないときは何も描きません。`followProjectFolder(vm, listener)` は、組み込んだフォルダ・開いているディレクトリ・ユーザーが選んだフォルダ(上の `root`)が変わるたびに `listener(folder, directory, root)` を呼びます。フォルダを開いていないときの `directory` と `root` は `null` です。
|
|
58
60
|
- 各行には文字色で描いたアイコンが付きます。開いた・閉じたフォルダ、作品データ(`project.source.json`・`sb3-source.json`)、JSON、画像、音、コード(`.js`・`.mjs`・`.ts`)、テキスト(`.md`・`.txt`)、その他のファイルです。画像(`.svg`・`.png`・`.jpg`・`.jpeg`・`.gif`・`.bmp`・`.webp`)は、行が画面に入るとサムネイルを表示します。2 MiB を超えるファイルと読み込めない画像はアイコンのままです。サムネイルは装飾用の `<img>` で、オブジェクト URL は行がなくなると解放します。
|
|
59
61
|
- `describeProjectFolder(project, locale, {manifest, folder})` は `descriptions` を作ります。`project.source.json`・`sb3-source.json`・`embedded-extensions.json`(形式 2 では `block-palette.json` も)の説明と、各アセットのファイルを使うコスチューム・背景・音を返します。`manifest` から `assetsDirectory` を読みます。`folder` はツリーのルートから見た作品フォルダのパスです。
|
|
60
62
|
|
|
@@ -92,7 +94,7 @@ TurboWarp Plus Editor は、ブロックパレットの設定を画面状態(`
|
|
|
92
94
|
|
|
93
95
|
Node.js 26 で `npm ci` と `npm test` を実行します。Vite で JavaScript、TypeScript で型宣言を生成します。ホストとの接続検証には `npm pack` で作る tarball を使います。`npm run test:browser` は、最小 editor runtime(`@kubohiroya/turbowarp-plus-editor-test-runtime`)の上で、フォルダの外部変更と本物の VM・ワークスペースとの結合を Chromium で試します。Editor が固定する VM と Scratch Blocks を使い、Editor のビルドは要りません。フォルダの一覧も、React 16.14 で実際の一時フォルダを表示して試します。`TWPF_EXPLORER_SCREENSHOT` にファイルのパスを入れると、その画面を保存します。ブラウザー内の作品フォルダは、フォルダ選択を外した Chromium と WebKit で、作成・保存・開き直し・ZIP の書き出し・削除を試します。WebKit は `npx playwright install webkit` で入れます。ZIP の単体テストと書き出しの確認には `python3` の `zipfile` を使います。
|
|
94
96
|
|
|
95
|
-
Editor のヘッドレス統合テストは実ディスク上のフォルダを使い、選択画面の操作を差し替えます。OS のフォルダ選択画面を確認するときは、使い捨ての sb3-toolchain v1 作品を **ファイル →
|
|
97
|
+
Editor のヘッドレス統合テストは実ディスク上のフォルダを使い、選択画面の操作を差し替えます。OS のフォルダ選択画面を確認するときは、使い捨ての sb3-toolchain v1 作品を **ファイル → フォルダを開く…** から選び、読み書きを許可します。標準ブロックを変更し、**ファイル → プロジェクトフォルダに保存** を選びます。選んだフォルダの `project.source.json` が更新されたことを確かめ、同じフォルダを開き直して編集が反映されることを確認します。
|
|
96
98
|
|
|
97
99
|
初期実装は MPL-2.0 の [TurboWarp Plus Editor d14d065](https://github.com/kubohiroya/turbowarp-plus-editor/tree/d14d0659f77f37328c855ecfeeae0927d81ae81a/packages/editor-project-folder) から分離しました。
|
|
98
100
|
|
package/README.md
CHANGED
|
@@ -8,8 +8,10 @@ This package opens and saves sb3-toolchain project folders (source formats 1 and
|
|
|
8
8
|
|
|
9
9
|
- `mountProjectFolder({vm, document, host})` attaches the folder session to a workspace. Call `dispose()` when the workspace is replaced.
|
|
10
10
|
- `renderProjectFolderMenu(createElement, props)` supplies the existing open and save commands to the host's file menu.
|
|
11
|
-
-
|
|
11
|
+
- A chosen folder with no project of its own opens its `project` folder instead, as in a repository made by Project Starter, when that folder is a valid project folder and has no `.git` of its own. Otherwise the error for the chosen folder stays.
|
|
12
|
+
- The mounted session's `openDirectory(handle, confirmReplace, root?)` accepts a directory handle already selected by the host. It uses the same project validation, `project` fallback and unsaved-edit confirmation as the file menu. Save still targets the opened project folder. `root` names the folder the user chose, for a host that located the project itself; it defaults to `handle`.
|
|
12
13
|
- The mounted session's `directory` is the folder the loaded project came from. It becomes `null` once another project loads or the folder is detached, so a host can tell projects apart by it.
|
|
14
|
+
- The mounted session's `root` is the folder the user chose for that project: `directory` itself, the repository whose `project` folder is `directory`, or, for a folder kept in the browser, its stored folder. It is `null` whenever `directory` is. The browser cannot read a folder's parent, so a host binds a Git repository to `root`.
|
|
13
15
|
- `host.screenState` keeps the Editor's screen state in the folder, as the workbench's `installProjectScreenState` provides it. A project folder is not an SB3, so the state goes into `.tw-plus/workspace.json`. Opening the folder reads it and passes it with `prepareLoad(text)` before the project loads. Saving writes `serialize()`, even when the project itself is unchanged, and skips the write when only the save time differs. A failure to read or write it never fails the open or the save. The session also registers the `projectFolder` slice: the expanded folders and the selected entry of the explorer. When a folder is created from an SB3, a `.tw-plus/workspace.json` in the snapshot sb3-toolchain (0.26.0 or later) unpacked is written into the folder as it is, so the new folder opens with the same screen. A snapshot without one removes the old `workspace.json` of the folder it overwrites, and keeps the other files in `.tw-plus`.
|
|
14
16
|
|
|
15
17
|
The host supplies the VM, menu components, and project state callbacks. The built-in open command needs the File System Access folder picker or [project folders in the browser](#project-folders-in-the-browser). Save writes block, variable, list, sprite property, monitor and built-in extension edits to the project file, including state that changes while the project runs. Sprites can be added, removed and renamed, and costumes and sounds added or removed: new asset files are written first, then `sb3-source.json` and the project file, and asset files nothing refers to are deleted last. See [Editor issue #305](https://github.com/kubohiroya/turbowarp-plus-editor/issues/305) and [issue #308](https://github.com/kubohiroya/turbowarp-plus-editor/issues/308).
|
|
@@ -23,8 +25,8 @@ Folders can contain embedded extension scripts and custom extension URLs. Openin
|
|
|
23
25
|
Safari and Firefox have no folder picker (`showDirectoryPicker`). In these browsers, project folders live in the browser's own storage, the origin private file system (OPFS). They are read and saved the same way as folders on the device. See [Editor issue #660](https://github.com/kubohiroya/turbowarp-plus-editor/issues/660).
|
|
24
26
|
|
|
25
27
|
- `browserStorage` of `mountProjectFolder` chooses how they are used.
|
|
26
|
-
- `fallback` (default): only in browsers without the folder picker. **Open
|
|
27
|
-
- `always`: also in browsers with the folder picker. The File menu gets **Open
|
|
28
|
+
- `fallback` (default): only in browsers without the folder picker (Safari, Firefox). The File menu shows **Open Folder…** as unavailable, with a note that this browser cannot open folders on the device, and offers **Open Folder Saved in This Browser…**, which lists the folders in the browser. `projectFolderActions(vm)` reports this as `deviceFolders: false`, so a host's own menu can do the same; its `open` still falls back to the browser's folders for hosts that call it. `createFromSnapshot` asks for the name of a new folder (`title` gives the initial name).
|
|
29
|
+
- `always`: also in browsers with the folder picker. The File menu gets **Open Folder Saved in This Browser…** next to **Open Folder…**, and `projectFolderActions(vm).openBrowser` opens it too.
|
|
28
30
|
- `off`: never.
|
|
29
31
|
- The dialog opens, exports as a ZIP, and deletes the folders. It shows how much storage is used and whether the browser keeps it (`persisted`). Its close button is an X icon named in the display language.
|
|
30
32
|
- A folder lives at `turbowarp-plus/projects/<id>/`, and its name and times at `turbowarp-plus/project-info/<id>.json`, outside the folder, so Git never tracks them. With `projectPath`, the project folder can sit below the repository root, such as `project`.
|
|
@@ -48,7 +50,7 @@ A change to `block-palette.json` outside the Editor is a structural change that
|
|
|
48
50
|
The `./explorer` entry (`@kubohiroya/turbowarp-plus-editor-project-folder/explorer`) is a tree of a folder for the Editor's side panel, built on [Headless Tree](https://headless-tree.lukasbach.com/), which is bundled. It renders with the host's React 16.14–18 (an optional peer dependency); the main entry does not use React.
|
|
49
51
|
|
|
50
52
|
- `ProjectFolderExplorer` shows `directory` (a project folder or a repository root). Folders load when expanded and sort before files, and `.git` and `.tw-plus` are hidden. The expanded folders and the selected entry of each folder are kept for the page, so the tree comes back as it was when the side panel shows it again. Arrow keys, Home and End move and expand; Enter, Space or a click on a file calls `onOpen({path, name, kind})`. Props: `directory`, `locale` (`ja…` for Japanese, otherwise English), `descriptions` and `marks` (Git status: `added`, `modified`, `deleted` or `untracked`), both keyed by the path relative to `directory`, `onOpen` and `label` (the tree's accessible name). A folder that cannot be read shows a message in the tree.
|
|
51
|
-
- `renderProjectFolderExplorer(createElement, {vm, locale, marks})` renders that explorer on the project folder open for `vm`, for the Editor's side panel, with descriptions from the folder's `project.source.json` and `sb3-source.json` (read again after each save). `marks(directory, update)` follows marks for the directory and returns the function that stops it, such as the Git package's `followChangeMarks`. With no folder open it offers **Open
|
|
53
|
+
- `renderProjectFolderExplorer(createElement, {vm, locale, marks})` renders that explorer on the project folder open for `vm`, for the Editor's side panel, with descriptions from the folder's `project.source.json` and `sb3-source.json` (read again after each save). `marks(directory, update)` follows marks for the directory and returns the function that stops it, such as the Git package's `followChangeMarks`. With no folder open it offers **Open Folder…**; it renders nothing while no project folder is mounted for `vm`. `followProjectFolder(vm, listener)` calls `listener(folder, directory, root)` with the mounted folder, its open directory and the folder the user chose for it (`root`, as above) as they change; `directory` and `root` are `null` while no folder is open.
|
|
52
54
|
- Each row has an icon drawn in the text color: an open or closed folder, project data (`project.source.json`, `sb3-source.json`), JSON, image, sound, code (`.js`, `.mjs`, `.ts`), text (`.md`, `.txt`) or another file. Images (`.svg`, `.png`, `.jpg`, `.jpeg`, `.gif`, `.bmp`, `.webp`) show a thumbnail once their row is on screen; files over 2 MiB, and images that cannot be read, keep the icon. Thumbnails are decorative `<img>` elements from object URLs, which are revoked when the row goes away.
|
|
53
55
|
- `describeProjectFolder(project, locale, {manifest, folder})` builds `descriptions`: what `project.source.json`, `sb3-source.json` and `embedded-extensions.json` (and `block-palette.json` in format 2) are, and which costumes, backdrops and sounds use each asset file. `manifest` supplies `assetsDirectory`; `folder` is the project folder's path under the tree's root.
|
|
54
56
|
|
|
@@ -72,7 +74,7 @@ Script replacements are checked against the VM before any change, and every targ
|
|
|
72
74
|
|
|
73
75
|
Use Node.js 26, then run `npm ci` and `npm test`. Vite builds the JavaScript library, and TypeScript emits the declarations. `npm pack` creates a tarball for host integration checks. `npm run test:browser` runs the folder's external changes against a real VM and workspace in Chromium on the minimal editor runtime (`@kubohiroya/turbowarp-plus-editor-test-runtime`), with the Editor's pinned VM and Scratch Blocks and without building the Editor. It also renders the explorer with React 16.14 over a real temporary folder; set `TWPF_EXPLORER_SCREENSHOT` to a file path to save a screenshot of it. Project folders in the browser are created, saved, reopened, exported as a ZIP and deleted in Chromium with the folder picker removed and in WebKit; install WebKit with `npx playwright install webkit`. The ZIP unit test and the export check read the archive with Python's `zipfile` (`python3`).
|
|
74
76
|
|
|
75
|
-
The Editor's headless integration test uses an actual disk directory and substitutes the picker interaction. To verify the native picker separately, open a disposable sb3-toolchain v1 project with **File → Open
|
|
77
|
+
The Editor's headless integration test uses an actual disk directory and substitutes the picker interaction. To verify the native picker separately, open a disposable sb3-toolchain v1 project with **File → Open Folder…**, accept read/write access, edit a standard block, and select **File → Save to Project Folder**. Check that `project.source.json` changed in the chosen directory and reopen the same folder to confirm the edit.
|
|
76
78
|
|
|
77
79
|
The initial source was extracted from [TurboWarp Plus Editor at d14d065](https://github.com/kubohiroya/turbowarp-plus-editor/tree/d14d0659f77f37328c855ecfeeae0927d81ae81a/packages/editor-project-folder) under MPL-2.0.
|
|
78
80
|
|
package/dist/explorer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as projectFile, C as isObject, F as _asyncIterator, L as _objectSpread2, a as projectFolderOverwriteWarning, d as subscribeExplorerState, f as writeExplorerState, l as readExplorerState, p as FolderError, s as hiddenEntry, t as followProjectFolder, w as manifestFile } from "./shared-
|
|
1
|
+
import { A as projectFile, C as isObject, F as _asyncIterator, L as _objectSpread2, a as projectFolderOverwriteWarning, d as subscribeExplorerState, f as writeExplorerState, l as readExplorerState, p as FolderError, s as hiddenEntry, t as followProjectFolder, w as manifestFile } from "./shared-h5VGx9Jp.js";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
@@ -1463,7 +1463,7 @@ function createFilePreview(directory, documentId, { name, path }, locale, readBa
|
|
|
1463
1463
|
status.textContent = message.large;
|
|
1464
1464
|
return;
|
|
1465
1465
|
}
|
|
1466
|
-
const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-
|
|
1466
|
+
const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-CwQoV7xd.js")]);
|
|
1467
1467
|
if (disposed) return;
|
|
1468
1468
|
const content = decodeText(bytes);
|
|
1469
1469
|
if (content === null) {
|
|
@@ -1524,8 +1524,8 @@ var messages = {
|
|
|
1524
1524
|
empty: "This folder is empty.",
|
|
1525
1525
|
noMatches: "No matching files.",
|
|
1526
1526
|
results: "Matching files",
|
|
1527
|
-
noFolder: "Open a
|
|
1528
|
-
open: "Open
|
|
1527
|
+
noFolder: "Open a folder to show its files here.",
|
|
1528
|
+
open: "Open Folder…",
|
|
1529
1529
|
create: "Create Project Folder",
|
|
1530
1530
|
creating: "Creating project folder…",
|
|
1531
1531
|
createFailed: "Could not create the project folder.",
|
|
@@ -1563,8 +1563,8 @@ var messages = {
|
|
|
1563
1563
|
empty: "このフォルダは空です。",
|
|
1564
1564
|
noMatches: "該当するファイルはありません。",
|
|
1565
1565
|
results: "検索結果",
|
|
1566
|
-
noFolder: "
|
|
1567
|
-
open: "
|
|
1566
|
+
noFolder: "フォルダを開くと、ここにファイルを表示します。",
|
|
1567
|
+
open: "フォルダを開く…",
|
|
1568
1568
|
create: "プロジェクトフォルダを作成",
|
|
1569
1569
|
creating: "プロジェクトフォルダを作成しています…",
|
|
1570
1570
|
createFailed: "プロジェクトフォルダを作成できませんでした。",
|
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
export type ExplorerMutation = (guard: () => void) => Promise<void>;
|
|
3
3
|
export interface FollowedFolder {
|
|
4
4
|
readonly directory: FileSystemDirectoryHandle | null;
|
|
5
|
+
/** The folder the user chose for `directory`: itself, or the repository whose `project` folder it is. */
|
|
6
|
+
readonly root?: FileSystemDirectoryHandle | null;
|
|
5
7
|
subscribe(listener: () => void): () => void;
|
|
6
8
|
subscribeEdits(listener: () => void): () => void;
|
|
7
9
|
unsavedPaths(): ReadonlySet<string> | null;
|
|
8
|
-
/** Asks for a folder and opens it, as the File menu's Open
|
|
10
|
+
/** Asks for a folder and opens it, as the File menu's Open Folder… does. */
|
|
9
11
|
open(locale: string): void;
|
|
10
12
|
mutate(directory: FileSystemDirectoryHandle, operation: ExplorerMutation): Promise<void>;
|
|
11
13
|
}
|
|
12
14
|
export declare function registerFolder(vm: object, folder: FollowedFolder): () => void;
|
|
13
15
|
/**
|
|
14
|
-
* Calls `listener` with the project folder mounted for `vm
|
|
15
|
-
*
|
|
16
|
+
* Calls `listener` with the project folder mounted for `vm`, the directory open in it and the folder the user chose for
|
|
17
|
+
* it (`root`, the directory itself or the repository that holds it in `project/`), now and whenever a folder is
|
|
18
|
+
* mounted, opened, closed or saved. `directory` and `root` are `null` while no folder is open. Returns the function
|
|
19
|
+
* that stops it.
|
|
16
20
|
*/
|
|
17
|
-
export declare function followProjectFolder(vm: object, listener: (folder: FollowedFolder | undefined, directory: FileSystemDirectoryHandle | null) => void): () => void;
|
|
21
|
+
export declare function followProjectFolder(vm: object, listener: (folder: FollowedFolder | undefined, directory: FileSystemDirectoryHandle | null, root: FileSystemDirectoryHandle | null) => void): () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare function mountProjectFolder({ vm, document, host, locale, autoRel
|
|
|
39
39
|
autoReload?: boolean;
|
|
40
40
|
browserStorage?: BrowserStorageMode;
|
|
41
41
|
}): {
|
|
42
|
-
openDirectory: (directory: FileSystemDirectoryHandle, confirmReplace: () => boolean) => Promise<import("./session.js").OpenResult>;
|
|
42
|
+
openDirectory: (directory: FileSystemDirectoryHandle, confirmReplace: () => boolean, root?: FileSystemDirectoryHandle | undefined) => Promise<import("./session.js").OpenResult>;
|
|
43
43
|
unsavedPaths: () => ReadonlySet<string> | null;
|
|
44
44
|
readUnsavedFile: (path: string) => Uint8Array<ArrayBufferLike> | null | undefined;
|
|
45
45
|
subscribeEdits: (listener: () => void) => () => void;
|
|
@@ -65,11 +65,18 @@ export declare function mountProjectFolder({ vm, document, host, locale, autoRel
|
|
|
65
65
|
* detached. A host can tell projects apart by it, for example to keep the layout of each one.
|
|
66
66
|
*/
|
|
67
67
|
readonly directory: FileSystemDirectoryHandle | null;
|
|
68
|
+
/**
|
|
69
|
+
* The folder the user chose for the loaded project, or `null` like `directory`. It is `directory` itself, or
|
|
70
|
+
* the repository whose `project` folder holds the project, or the stored folder of a folder kept in the browser.
|
|
71
|
+
*/
|
|
72
|
+
readonly root: FileSystemDirectoryHandle | null;
|
|
68
73
|
dispose(): void;
|
|
69
74
|
} | null;
|
|
70
75
|
export declare function projectFolderActions(vm: FolderVM, locale?: string): {
|
|
71
76
|
open: () => void;
|
|
72
77
|
openBrowser: (() => void) | undefined;
|
|
78
|
+
/** Whether Open can pick a folder on the device. Safari and Firefox cannot, so hosts show Open as unavailable. */
|
|
79
|
+
deviceFolders: boolean;
|
|
73
80
|
save: (() => void) | undefined;
|
|
74
81
|
detach: () => void;
|
|
75
82
|
} | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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 readProjectFolder, 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 readFolderUpdate, 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-h5VGx9Jp.js";
|
|
2
2
|
// src/block-reload.ts
|
|
3
3
|
var _excluded$3 = ["targets"];
|
|
4
4
|
var _excluded2$1 = ["targets"];
|
|
@@ -513,16 +513,16 @@ function createFolderSession(vm, host) {
|
|
|
513
513
|
vm.off("PROJECT_CHANGED", changed);
|
|
514
514
|
unregisterTree === null || unregisterTree === void 0 || unregisterTree();
|
|
515
515
|
};
|
|
516
|
-
const openFrom = async (getDirectory, confirmReplace, prepare = (directory) =>
|
|
516
|
+
const openFrom = async (getDirectory, confirmReplace, prepare = (directory) => readProjectFolder(directory, vm.runtime.storage), stillCurrent = () => true) => {
|
|
517
517
|
if (disposed || busy) return "cancelled";
|
|
518
518
|
busy = true;
|
|
519
519
|
const priorStage = vm.runtime.getTargetForStage();
|
|
520
520
|
try {
|
|
521
|
-
var _vm$renderer;
|
|
522
|
-
const
|
|
523
|
-
if (!
|
|
521
|
+
var _chosen$root, _vm$renderer;
|
|
522
|
+
const chosen = await getDirectory();
|
|
523
|
+
if (!chosen || disposed) return "cancelled";
|
|
524
524
|
const storage = vm.runtime.storage;
|
|
525
|
-
const source = await prepare(directory);
|
|
525
|
+
const source = await prepare(chosen.directory);
|
|
526
526
|
if (!source || disposed || !stillCurrent() || vm.runtime.getTargetForStage() !== priorStage) return "cancelled";
|
|
527
527
|
if (host.isProjectDirty() && !confirmReplace()) return "cancelled";
|
|
528
528
|
host.beforeLoad();
|
|
@@ -531,6 +531,7 @@ function createFolderSession(vm, host) {
|
|
|
531
531
|
const assets = source.storageAssets;
|
|
532
532
|
reader.assets = assets;
|
|
533
533
|
let stage;
|
|
534
|
+
const directory = source.directory;
|
|
534
535
|
pendingTree = void 0;
|
|
535
536
|
expectingTree = true;
|
|
536
537
|
try {
|
|
@@ -542,10 +543,11 @@ function createFolderSession(vm, host) {
|
|
|
542
543
|
if (reader.assets === assets) reader.assets = null;
|
|
543
544
|
}
|
|
544
545
|
if (disposed || !stage || vm.runtime.getTargetForStage() !== stage) return "cancelled";
|
|
545
|
-
host.onOpened(directory.name);
|
|
546
|
+
host.onOpened(chosen.directory.name);
|
|
546
547
|
const baseline = snapshot();
|
|
547
548
|
setCurrent({
|
|
548
549
|
source,
|
|
550
|
+
root: (_chosen$root = chosen.root) !== null && _chosen$root !== void 0 ? _chosen$root : chosen.directory,
|
|
549
551
|
stage,
|
|
550
552
|
baseline,
|
|
551
553
|
ids: identify(baseline),
|
|
@@ -703,6 +705,11 @@ function createFolderSession(vm, host) {
|
|
|
703
705
|
var _current$source$direc;
|
|
704
706
|
return (_current$source$direc = current === null || current === void 0 ? void 0 : current.source.directory) !== null && _current$source$direc !== void 0 ? _current$source$direc : null;
|
|
705
707
|
},
|
|
708
|
+
/** The folder the user chose: `directory` itself, or the repository whose `project` folder it is. */
|
|
709
|
+
get root() {
|
|
710
|
+
var _current$root;
|
|
711
|
+
return (_current$root = current === null || current === void 0 ? void 0 : current.root) !== null && _current$root !== void 0 ? _current$root : null;
|
|
712
|
+
},
|
|
706
713
|
async mutate(directory, operation) {
|
|
707
714
|
const session = current;
|
|
708
715
|
if (!session || busy || session.source.directory !== directory) throw new FolderError("conflict");
|
|
@@ -800,8 +807,12 @@ function createFolderSession(vm, host) {
|
|
|
800
807
|
var _host$blockReload4;
|
|
801
808
|
const session = current;
|
|
802
809
|
if (!session || !session.pending || session.pending === "waiting" || ((_host$blockReload4 = host.blockReload) === null || _host$blockReload4 === void 0 ? void 0 : _host$blockReload4.isRunning())) return Promise.resolve("cancelled");
|
|
803
|
-
return openFrom(() => Promise.resolve(current === session ?
|
|
810
|
+
return openFrom(() => Promise.resolve(current === session ? {
|
|
811
|
+
directory: session.source.directory,
|
|
812
|
+
root: session.root
|
|
813
|
+
} : null), confirmReplace);
|
|
804
814
|
},
|
|
815
|
+
/** `pick` gives the folder to open and, when it differs, the folder the user chose as `root`. */
|
|
805
816
|
open(pick, confirmReplace) {
|
|
806
817
|
return openFrom(async () => {
|
|
807
818
|
try {
|
|
@@ -815,8 +826,15 @@ function createFolderSession(vm, host) {
|
|
|
815
826
|
}
|
|
816
827
|
}, confirmReplace);
|
|
817
828
|
},
|
|
818
|
-
|
|
819
|
-
|
|
829
|
+
/**
|
|
830
|
+
* Opens `directory`, or its `project` folder when it has no project of its own. `root` is the folder the user
|
|
831
|
+
* chose, for a host that located the project itself; it defaults to `directory`.
|
|
832
|
+
*/
|
|
833
|
+
openDirectory(directory, confirmReplace, root) {
|
|
834
|
+
return openFrom(() => Promise.resolve({
|
|
835
|
+
directory,
|
|
836
|
+
root
|
|
837
|
+
}), confirmReplace);
|
|
820
838
|
},
|
|
821
839
|
createFromSnapshot(selectDestination, prepareFiles, isCurrent) {
|
|
822
840
|
const stage = vm.runtime.getTargetForStage();
|
|
@@ -824,10 +842,10 @@ function createFolderSession(vm, host) {
|
|
|
824
842
|
const currentProject = () => !disposed && vm.runtime.getTargetForStage() === stage && (savedRevision === void 0 || revision === savedRevision) && isCurrent();
|
|
825
843
|
let overwrite = false;
|
|
826
844
|
return openFrom(async () => {
|
|
827
|
-
var _destination$overwrit
|
|
845
|
+
var _destination$overwrit;
|
|
828
846
|
const destination = await selectDestination();
|
|
829
847
|
overwrite = (_destination$overwrit = destination === null || destination === void 0 ? void 0 : destination.overwrite) !== null && _destination$overwrit !== void 0 ? _destination$overwrit : false;
|
|
830
|
-
return
|
|
848
|
+
return destination ? { directory: destination.directory } : null;
|
|
831
849
|
}, currentProject, async (directory) => {
|
|
832
850
|
if (!currentProject()) return null;
|
|
833
851
|
savedRevision = revision;
|
|
@@ -1625,9 +1643,10 @@ function chooseBrowserProject({ document, projects, locale = "en", purpose, titl
|
|
|
1625
1643
|
// src/index.ts
|
|
1626
1644
|
var messages = {
|
|
1627
1645
|
en: {
|
|
1628
|
-
open: "Open
|
|
1646
|
+
open: "Open Folder…",
|
|
1629
1647
|
save: "Save to Project Folder",
|
|
1630
|
-
openBrowser: "Open
|
|
1648
|
+
openBrowser: "Open Folder Saved in This Browser…",
|
|
1649
|
+
deviceUnavailable: "This browser cannot open folders on your device. Use Chrome or Edge, or open a folder saved in this browser.",
|
|
1631
1650
|
replace: "Replace the open project and discard its unsaved changes?",
|
|
1632
1651
|
opened: "Project folder opened.",
|
|
1633
1652
|
saved: "Project folder saved.",
|
|
@@ -1659,9 +1678,10 @@ var messages = {
|
|
|
1659
1678
|
full: "These changes need the whole project to be reloaded."
|
|
1660
1679
|
},
|
|
1661
1680
|
ja: {
|
|
1662
|
-
open: "
|
|
1681
|
+
open: "フォルダを開く…",
|
|
1663
1682
|
save: "プロジェクトフォルダに保存",
|
|
1664
|
-
openBrowser: "
|
|
1683
|
+
openBrowser: "ブラウザーに保存したフォルダを開く…",
|
|
1684
|
+
deviceUnavailable: "このブラウザーでは端末のフォルダを開けません。Chrome か Edge を使うか、ブラウザーに保存したフォルダを開いてください。",
|
|
1665
1685
|
replace: "未保存の変更を破棄して、別の作品を開きますか?",
|
|
1666
1686
|
opened: "プロジェクトフォルダを開きました。",
|
|
1667
1687
|
saved: "プロジェクトフォルダに保存しました。",
|
|
@@ -1714,10 +1734,18 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1714
1734
|
title
|
|
1715
1735
|
});
|
|
1716
1736
|
if (!choice) throw abort();
|
|
1717
|
-
return choice
|
|
1737
|
+
return choice;
|
|
1718
1738
|
};
|
|
1719
|
-
const
|
|
1720
|
-
|
|
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
|
+
};
|
|
1747
|
+
const pickDirectory = devicePicker ? async (options) => ({ directory: await devicePicker.call(view, options) }) : chooseBrowserFolder;
|
|
1748
|
+
const pickNewDirectory = async (options, title) => devicePicker ? devicePicker.call(view, options) : (await chooseBrowser("create", title)).directory;
|
|
1721
1749
|
/** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
|
|
1722
1750
|
const withBrowserProject = async (directory, run) => {
|
|
1723
1751
|
const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
|
|
@@ -1904,6 +1932,7 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1904
1932
|
};
|
|
1905
1933
|
}
|
|
1906
1934
|
const menu = {
|
|
1935
|
+
deviceFolders: typeof devicePicker === "function",
|
|
1907
1936
|
session,
|
|
1908
1937
|
open(locale) {
|
|
1909
1938
|
const message = messageFor(locale);
|
|
@@ -1912,9 +1941,9 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1912
1941
|
}, (error) => fail(locale, error)).finally(renderReload);
|
|
1913
1942
|
renderReload();
|
|
1914
1943
|
},
|
|
1915
|
-
openBrowser:
|
|
1944
|
+
openBrowser: browserProjects ? (locale) => {
|
|
1916
1945
|
const message = messageFor(locale);
|
|
1917
|
-
session.open(
|
|
1946
|
+
session.open(chooseBrowserFolder, () => view.confirm(message.replace)).then((result) => {
|
|
1918
1947
|
if (result === "opened") report(message.opened);
|
|
1919
1948
|
}, (error) => fail(locale, error)).finally(renderReload);
|
|
1920
1949
|
renderReload();
|
|
@@ -1941,6 +1970,9 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1941
1970
|
get directory() {
|
|
1942
1971
|
return session.directory;
|
|
1943
1972
|
},
|
|
1973
|
+
get root() {
|
|
1974
|
+
return session.root;
|
|
1975
|
+
},
|
|
1944
1976
|
subscribe: (listener) => session.subscribe(listener),
|
|
1945
1977
|
subscribeEdits: (listener) => session.subscribeEdits(listener),
|
|
1946
1978
|
unsavedPaths: () => session.unsavedPaths(),
|
|
@@ -1988,6 +2020,13 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
|
|
|
1988
2020
|
get directory() {
|
|
1989
2021
|
return session.directory;
|
|
1990
2022
|
},
|
|
2023
|
+
/**
|
|
2024
|
+
* The folder the user chose for the loaded project, or `null` like `directory`. It is `directory` itself, or
|
|
2025
|
+
* the repository whose `project` folder holds the project, or the stored folder of a folder kept in the browser.
|
|
2026
|
+
*/
|
|
2027
|
+
get root() {
|
|
2028
|
+
return session.root;
|
|
2029
|
+
},
|
|
1991
2030
|
dispose() {
|
|
1992
2031
|
menus.delete(vm);
|
|
1993
2032
|
unregister();
|
|
@@ -2004,6 +2043,8 @@ function projectFolderActions(vm, locale = "en") {
|
|
|
2004
2043
|
return {
|
|
2005
2044
|
open: () => entry.open(locale),
|
|
2006
2045
|
openBrowser: entry.openBrowser ? () => entry.openBrowser(locale) : void 0,
|
|
2046
|
+
/** Whether Open can pick a folder on the device. Safari and Firefox cannot, so hosts show Open as unavailable. */
|
|
2047
|
+
deviceFolders: entry.deviceFolders,
|
|
2007
2048
|
save: entry.session.canSave ? () => entry.save(locale) : void 0,
|
|
2008
2049
|
detach: () => entry.session.detach()
|
|
2009
2050
|
};
|
|
@@ -2013,6 +2054,16 @@ function renderProjectFolderMenu(createElement, { vm, locale = "en", MenuItem, M
|
|
|
2013
2054
|
if (!entry) return null;
|
|
2014
2055
|
const labels = locale.startsWith("ja") ? messages.ja : messages.en;
|
|
2015
2056
|
const item = (action) => {
|
|
2057
|
+
if (action === "open" && !entry.deviceFolders) return createElement(MenuItem, { command: `project-folder-${action}` }, createElement("span", {
|
|
2058
|
+
role: "button",
|
|
2059
|
+
tabIndex: -1,
|
|
2060
|
+
"aria-disabled": true,
|
|
2061
|
+
title: labels.deviceUnavailable,
|
|
2062
|
+
style: {
|
|
2063
|
+
opacity: .5,
|
|
2064
|
+
cursor: "default"
|
|
2065
|
+
}
|
|
2066
|
+
}, labels[action]));
|
|
2016
2067
|
const run = () => {
|
|
2017
2068
|
onRequestClose();
|
|
2018
2069
|
entry[action](locale);
|
package/dist/session.d.ts
CHANGED
|
@@ -91,6 +91,11 @@ export type Comparison = {
|
|
|
91
91
|
editor: string | null;
|
|
92
92
|
disk: string | null;
|
|
93
93
|
};
|
|
94
|
+
/** The folder to open, and the folder the user chose for it, which defaults to `directory`. */
|
|
95
|
+
export type Chosen = {
|
|
96
|
+
directory: FileSystemDirectoryHandle;
|
|
97
|
+
root?: FileSystemDirectoryHandle;
|
|
98
|
+
};
|
|
94
99
|
/**
|
|
95
100
|
* `ready`: the change can be applied in place: values and positions, or with `deserializeBlocks`, whole scripts. `full`: the change needs the whole project reloaded.
|
|
96
101
|
* `waiting`: an external write looks incomplete and is checked again. `dirty`, `running` and `busy` hold the change.
|
|
@@ -123,6 +128,8 @@ export declare function createFolderSession(vm: FolderVM, host: FolderHost): {
|
|
|
123
128
|
/** Identifies the pending project file version, so a host can attempt an automatic apply only once. */
|
|
124
129
|
readonly pendingVersion: string | null;
|
|
125
130
|
readonly directory: FileSystemDirectoryHandle | null;
|
|
131
|
+
/** The folder the user chose: `directory` itself, or the repository whose `project` folder it is. */
|
|
132
|
+
readonly root: FileSystemDirectoryHandle | null;
|
|
126
133
|
mutate(directory: FileSystemDirectoryHandle, operation: (guard: () => void) => Promise<void>): Promise<void>;
|
|
127
134
|
/**
|
|
128
135
|
* Reads what to compare before unsaved edits are replaced. `editor` is `null` when the edits cannot be
|
|
@@ -136,8 +143,16 @@ export declare function createFolderSession(vm: FolderVM, host: FolderHost): {
|
|
|
136
143
|
* edits are discarded only when `confirmReplace` agrees. The VM is left untouched while a project runs.
|
|
137
144
|
*/
|
|
138
145
|
reloadAll(confirmReplace: () => boolean): Promise<OpenResult>;
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
/** `pick` gives the folder to open and, when it differs, the folder the user chose as `root`. */
|
|
147
|
+
open(pick: (options: {
|
|
148
|
+
id: string;
|
|
149
|
+
mode: "readwrite";
|
|
150
|
+
}) => Promise<Chosen>, confirmReplace: () => boolean): Promise<OpenResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Opens `directory`, or its `project` folder when it has no project of its own. `root` is the folder the user
|
|
153
|
+
* chose, for a host that located the project itself; it defaults to `directory`.
|
|
154
|
+
*/
|
|
155
|
+
openDirectory(directory: FileSystemDirectoryHandle, confirmReplace: () => boolean, root?: FileSystemDirectoryHandle): Promise<OpenResult>;
|
|
141
156
|
createFromSnapshot(selectDestination: () => Promise<{
|
|
142
157
|
directory: FileSystemDirectoryHandle;
|
|
143
158
|
overwrite: boolean;
|
|
@@ -726,6 +726,41 @@ async function readFolder(directory, storage) {
|
|
|
726
726
|
palette: paletteDocument
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
|
+
/** The project folder inside a repository, as Project Starter makes it. */
|
|
730
|
+
var projectSubfolder = "project";
|
|
731
|
+
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
|
+
/**
|
|
743
|
+
* Reads the project in `directory`, or, when the folder has no project of its own, in its `project` folder, as in a
|
|
744
|
+
* repository whose project sits in `project/`. That folder must not be a repository itself. The error is the one
|
|
745
|
+
* for `directory` when neither holds a project.
|
|
746
|
+
*/
|
|
747
|
+
async function readProjectFolder(directory, storage) {
|
|
748
|
+
try {
|
|
749
|
+
return await readFolder(directory, storage);
|
|
750
|
+
} catch (error) {
|
|
751
|
+
const child = await (async () => {
|
|
752
|
+
if (await hasEntry(directory, "project.source.json") || await hasEntry(directory, "sb3-source.json")) return null;
|
|
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
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
729
764
|
var sameBytes = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
|
|
730
765
|
async function readFolderUpdate(source, previous) {
|
|
731
766
|
const { directory, versions } = source;
|
|
@@ -1136,21 +1171,26 @@ function registerFolder(vm, folder) {
|
|
|
1136
1171
|
};
|
|
1137
1172
|
}
|
|
1138
1173
|
/**
|
|
1139
|
-
* Calls `listener` with the project folder mounted for `vm
|
|
1140
|
-
*
|
|
1174
|
+
* 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 or the repository that holds it in `project/`), now and whenever a folder is
|
|
1176
|
+
* mounted, opened, closed or saved. `directory` and `root` are `null` while no folder is open. Returns the function
|
|
1177
|
+
* that stops it.
|
|
1141
1178
|
*/
|
|
1142
1179
|
function followProjectFolder(vm, listener) {
|
|
1143
1180
|
let unsubscribe = () => {};
|
|
1144
1181
|
let followed;
|
|
1145
1182
|
const update = () => {
|
|
1146
|
-
var _folder$directory;
|
|
1183
|
+
var _folder$directory, _folder$root2;
|
|
1147
1184
|
const folder = folders.get(vm);
|
|
1148
1185
|
if (folder !== followed) {
|
|
1149
1186
|
unsubscribe();
|
|
1150
1187
|
followed = folder;
|
|
1151
|
-
unsubscribe = folder ? folder.subscribe(() =>
|
|
1188
|
+
unsubscribe = folder ? folder.subscribe(() => {
|
|
1189
|
+
var _folder$root;
|
|
1190
|
+
return listener(folder, folder.directory, (_folder$root = folder.root) !== null && _folder$root !== void 0 ? _folder$root : null);
|
|
1191
|
+
}) : () => {};
|
|
1152
1192
|
}
|
|
1153
|
-
listener(folder, (_folder$directory = folder === null || folder === void 0 ? void 0 : folder.directory) !== null && _folder$directory !== void 0 ? _folder$directory : null);
|
|
1193
|
+
listener(folder, (_folder$directory = folder === null || folder === void 0 ? void 0 : folder.directory) !== null && _folder$directory !== void 0 ? _folder$directory : null, (_folder$root2 = folder === null || folder === void 0 ? void 0 : folder.root) !== null && _folder$root2 !== void 0 ? _folder$root2 : null);
|
|
1154
1194
|
};
|
|
1155
1195
|
registrations.add(update);
|
|
1156
1196
|
update();
|
|
@@ -1159,4 +1199,4 @@ function followProjectFolder(vm, listener) {
|
|
|
1159
1199
|
unsubscribe();
|
|
1160
1200
|
};
|
|
1161
1201
|
}
|
|
1162
|
-
export { projectFile as A, isObject as C, planExtensionSave as D, parseProject as E, _asyncIterator as F, _objectWithoutProperties as I, _objectSpread2 as L,
|
|
1202
|
+
export { projectFile as A, isObject as C, planExtensionSave as D, parseProject as E, _asyncIterator as F, _objectWithoutProperties as I, _objectSpread2 as L, readProjectFolder as M, sameBytes as N, projectAssets as O, unsupported as P, fileVersion as S, paletteFile 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, readFolderUpdate as j, projectChanges 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, manifestFile as w, extensionsFile as x, equal as y };
|
package/dist/source.d.ts
CHANGED
|
@@ -100,6 +100,14 @@ export declare function planExtensionSave(source: FolderSource, project: Project
|
|
|
100
100
|
removed: string[];
|
|
101
101
|
};
|
|
102
102
|
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
|
+
/**
|
|
106
|
+
* Reads the project in `directory`, or, when the folder has no project of its own, in its `project` folder, as in a
|
|
107
|
+
* repository whose project sits in `project/`. That folder must not be a repository itself. The error is the one
|
|
108
|
+
* for `directory` when neither holds a project.
|
|
109
|
+
*/
|
|
110
|
+
export declare function readProjectFolder(directory: FileSystemDirectoryHandle, storage: Storage): Promise<FolderSource>;
|
|
103
111
|
export declare const sameBytes: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
104
112
|
export type FolderUpdate = {
|
|
105
113
|
version: string;
|
package/package.json
CHANGED
package/src/explorer.tsx
CHANGED
|
@@ -57,7 +57,7 @@ const messages = {
|
|
|
57
57
|
en: {
|
|
58
58
|
label: 'Project folder', loading: 'Loading…', empty: 'This folder is empty.', noMatches: 'No matching files.',
|
|
59
59
|
results: 'Matching files',
|
|
60
|
-
noFolder: 'Open a
|
|
60
|
+
noFolder: 'Open a folder to show its files here.', open: 'Open Folder…',
|
|
61
61
|
create: 'Create Project Folder', creating: 'Creating project folder…',
|
|
62
62
|
createFailed: 'Could not create the project folder.',
|
|
63
63
|
unavailable: 'File tabs are unavailable in this editor layout.',
|
|
@@ -77,7 +77,7 @@ const messages = {
|
|
|
77
77
|
ja: {
|
|
78
78
|
label: '作品フォルダ', loading: '読み込んでいます…', empty: 'このフォルダは空です。', noMatches: '該当するファイルはありません。',
|
|
79
79
|
results: '検索結果',
|
|
80
|
-
noFolder: '
|
|
80
|
+
noFolder: 'フォルダを開くと、ここにファイルを表示します。', open: 'フォルダを開く…',
|
|
81
81
|
create: 'プロジェクトフォルダを作成', creating: 'プロジェクトフォルダを作成しています…',
|
|
82
82
|
createFailed: 'プロジェクトフォルダを作成できませんでした。',
|
|
83
83
|
unavailable: 'このエディターのレイアウトではファイルをタブで開けません。',
|
package/src/folder-registry.ts
CHANGED
|
@@ -3,10 +3,12 @@ export type ExplorerMutation = (guard: () => void) => Promise<void>;
|
|
|
3
3
|
|
|
4
4
|
export interface FollowedFolder {
|
|
5
5
|
readonly directory: FileSystemDirectoryHandle | null;
|
|
6
|
+
/** The folder the user chose for `directory`: itself, or the repository whose `project` folder it is. */
|
|
7
|
+
readonly root?: FileSystemDirectoryHandle | null;
|
|
6
8
|
subscribe(listener: () => void): () => void;
|
|
7
9
|
subscribeEdits(listener: () => void): () => void;
|
|
8
10
|
unsavedPaths(): ReadonlySet<string> | null;
|
|
9
|
-
/** Asks for a folder and opens it, as the File menu's Open
|
|
11
|
+
/** Asks for a folder and opens it, as the File menu's Open Folder… does. */
|
|
10
12
|
open(locale: string): void;
|
|
11
13
|
mutate(directory: FileSystemDirectoryHandle, operation: ExplorerMutation): Promise<void>;
|
|
12
14
|
}
|
|
@@ -25,11 +27,13 @@ export function registerFolder(vm: object, folder: FollowedFolder) {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
|
-
* Calls `listener` with the project folder mounted for `vm
|
|
29
|
-
*
|
|
30
|
+
* Calls `listener` with the project folder mounted for `vm`, the directory open in it and the folder the user chose for
|
|
31
|
+
* it (`root`, the directory itself or the repository that holds it in `project/`), now and whenever a folder is
|
|
32
|
+
* mounted, opened, closed or saved. `directory` and `root` are `null` while no folder is open. Returns the function
|
|
33
|
+
* that stops it.
|
|
30
34
|
*/
|
|
31
|
-
export function followProjectFolder(vm: object,
|
|
32
|
-
|
|
35
|
+
export function followProjectFolder(vm: object, listener: (folder: FollowedFolder | undefined,
|
|
36
|
+
directory: FileSystemDirectoryHandle | null, root: FileSystemDirectoryHandle | null) => void) {
|
|
33
37
|
let unsubscribe = () => {};
|
|
34
38
|
let followed: FollowedFolder | undefined;
|
|
35
39
|
const update = () => {
|
|
@@ -37,9 +41,9 @@ export function followProjectFolder(vm: object,
|
|
|
37
41
|
if (folder !== followed) {
|
|
38
42
|
unsubscribe();
|
|
39
43
|
followed = folder;
|
|
40
|
-
unsubscribe = folder ? folder.subscribe(() => listener(folder, folder.directory)) : () => {};
|
|
44
|
+
unsubscribe = folder ? folder.subscribe(() => listener(folder, folder.directory, folder.root ?? null)) : () => {};
|
|
41
45
|
}
|
|
42
|
-
listener(folder, folder?.directory ?? null);
|
|
46
|
+
listener(folder, folder?.directory ?? null, folder?.root ?? null);
|
|
43
47
|
};
|
|
44
48
|
registrations.add(update);
|
|
45
49
|
update();
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {registerFolder} from './folder-registry.js';
|
|
|
5
5
|
import {openBrowserProjects} from './browser-projects.js';
|
|
6
6
|
import type {BrowserProjects} from './browser-projects.js';
|
|
7
7
|
import {chooseBrowserProject} from './browser-project-dialog.js';
|
|
8
|
-
import type {FolderHost, FolderVM, PickerWindow} from './session.js';
|
|
8
|
+
import type {Chosen, FolderHost, FolderVM, PickerWindow} from './session.js';
|
|
9
9
|
|
|
10
10
|
export type {Comparison, ComparisonRequest, ComparisonSection, FolderHost, FolderScreenState, FolderVM, OpenResult} from './session.js';
|
|
11
11
|
export type {ReloadTarget} from './block-reload.js';
|
|
@@ -21,7 +21,8 @@ export {zipDirectory} from './zip.js';
|
|
|
21
21
|
|
|
22
22
|
const messages = {
|
|
23
23
|
en: {
|
|
24
|
-
open: 'Open
|
|
24
|
+
open: 'Open Folder…', save: 'Save to Project Folder', openBrowser: 'Open Folder Saved in This Browser…',
|
|
25
|
+
deviceUnavailable: 'This browser cannot open folders on your device. Use Chrome or Edge, or open a folder saved in this browser.',
|
|
25
26
|
replace: 'Replace the open project and discard its unsaved changes?',
|
|
26
27
|
opened: 'Project folder opened.', saved: 'Project folder saved.', unchanged: 'No changes to save.',
|
|
27
28
|
sourceRemoved: (ids: string[]) => `Removed source metadata for replaced extensions: ${ids.join(', ')}. Use sb3-toolchain to fetch the managed sources again if you need to keep their provenance.`,
|
|
@@ -42,7 +43,8 @@ const messages = {
|
|
|
42
43
|
full: 'These changes need the whole project to be reloaded.'
|
|
43
44
|
},
|
|
44
45
|
ja: {
|
|
45
|
-
open: '
|
|
46
|
+
open: 'フォルダを開く…', save: 'プロジェクトフォルダに保存', openBrowser: 'ブラウザーに保存したフォルダを開く…',
|
|
47
|
+
deviceUnavailable: 'このブラウザーでは端末のフォルダを開けません。Chrome か Edge を使うか、ブラウザーに保存したフォルダを開いてください。',
|
|
46
48
|
replace: '未保存の変更を破棄して、別の作品を開きますか?',
|
|
47
49
|
opened: 'プロジェクトフォルダを開きました。', saved: 'プロジェクトフォルダに保存しました。', unchanged: '保存する変更はありません。',
|
|
48
50
|
sourceRemoved: (ids: string[]) => `差し替えた拡張機能(${ids.join('、')})の出どころ情報を削除しました。出どころを保つには、sb3-toolchain で拡張機能を取得し直してください。`,
|
|
@@ -73,8 +75,10 @@ interface MenuProps {
|
|
|
73
75
|
onRequestClose(): void;
|
|
74
76
|
}
|
|
75
77
|
type MenuEntry = {session: ReturnType<typeof createFolderSession>; open(locale: string): void; save(locale: string): void;
|
|
76
|
-
/** Opens a folder kept in this browser,
|
|
77
|
-
openBrowser?(locale: string): void
|
|
78
|
+
/** Opens a folder kept in this browser, wherever the browser's folders are available. */
|
|
79
|
+
openBrowser?(locale: string): void;
|
|
80
|
+
/** Whether the browser can pick folders on the device; without it, Open uses the browser's folders. */
|
|
81
|
+
deviceFolders: boolean};
|
|
78
82
|
const menus = new WeakMap<FolderVM, MenuEntry>();
|
|
79
83
|
|
|
80
84
|
type ObserverWindow = PickerWindow & {FileSystemObserver?: new (callback: () => void) => {
|
|
@@ -109,13 +113,18 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
|
|
|
109
113
|
const chooseBrowser = async (purpose: 'open' | 'create', title?: string) => {
|
|
110
114
|
const choice = await chooseBrowserProject({document, projects: browserProjects!, locale, purpose, title});
|
|
111
115
|
if (!choice) throw abort();
|
|
112
|
-
return choice
|
|
116
|
+
return choice;
|
|
117
|
+
};
|
|
118
|
+
// A folder kept in the browser was chosen as a whole, so its stored folder is the root even when the project is inside.
|
|
119
|
+
const chooseBrowserFolder = async (): Promise<Chosen> => {
|
|
120
|
+
const {project, directory} = await chooseBrowser('open');
|
|
121
|
+
return {directory, root: await browserProjects!.root(project.id).catch(() => null) ?? directory};
|
|
113
122
|
};
|
|
114
123
|
const pickDirectory = devicePicker ?
|
|
115
|
-
(options: {id: string; mode: 'readwrite'}) => devicePicker.call(view, options) :
|
|
116
|
-
|
|
117
|
-
const pickNewDirectory = (options: {id: string; mode: 'readwrite'}, title?: string) =>
|
|
118
|
-
devicePicker ? devicePicker.call(view, options) : chooseBrowser('create', title);
|
|
124
|
+
async (options: {id: string; mode: 'readwrite'}): Promise<Chosen> => ({directory: await devicePicker.call(view, options)}) :
|
|
125
|
+
chooseBrowserFolder;
|
|
126
|
+
const pickNewDirectory = async (options: {id: string; mode: 'readwrite'}, title?: string) =>
|
|
127
|
+
devicePicker ? devicePicker.call(view, options) : (await chooseBrowser('create', title)).directory;
|
|
119
128
|
/** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
|
|
120
129
|
const withBrowserProject = async <T>(directory: FileSystemDirectoryHandle | null, run: () => Promise<T>) => {
|
|
121
130
|
const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
|
|
@@ -271,6 +280,7 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
|
|
|
271
280
|
};
|
|
272
281
|
}
|
|
273
282
|
const menu: MenuEntry = {
|
|
283
|
+
deviceFolders: typeof devicePicker === 'function',
|
|
274
284
|
session,
|
|
275
285
|
open(locale) {
|
|
276
286
|
const message = messageFor(locale);
|
|
@@ -278,9 +288,9 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
|
|
|
278
288
|
.then(result => {if (result === 'opened') report(message.opened);}, error => fail(locale, error)).finally(renderReload);
|
|
279
289
|
renderReload();
|
|
280
290
|
},
|
|
281
|
-
openBrowser:
|
|
291
|
+
openBrowser: browserProjects ? locale => {
|
|
282
292
|
const message = messageFor(locale);
|
|
283
|
-
session.open(
|
|
293
|
+
session.open(chooseBrowserFolder, () => view.confirm(message.replace))
|
|
284
294
|
.then(result => {if (result === 'opened') report(message.opened);}, error => fail(locale, error)).finally(renderReload);
|
|
285
295
|
renderReload();
|
|
286
296
|
} : undefined,
|
|
@@ -303,6 +313,7 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
|
|
|
303
313
|
menus.set(vm, menu);
|
|
304
314
|
const unregister = registerFolder(vm, {
|
|
305
315
|
get directory() {return session.directory;},
|
|
316
|
+
get root() {return session.root;},
|
|
306
317
|
subscribe: listener => session.subscribe(listener),
|
|
307
318
|
subscribeEdits: listener => session.subscribeEdits(listener),
|
|
308
319
|
unsavedPaths: () => session.unsavedPaths(),
|
|
@@ -351,6 +362,11 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
|
|
|
351
362
|
* detached. A host can tell projects apart by it, for example to keep the layout of each one.
|
|
352
363
|
*/
|
|
353
364
|
get directory() {return session.directory;},
|
|
365
|
+
/**
|
|
366
|
+
* The folder the user chose for the loaded project, or `null` like `directory`. It is `directory` itself, or
|
|
367
|
+
* the repository whose `project` folder holds the project, or the stored folder of a folder kept in the browser.
|
|
368
|
+
*/
|
|
369
|
+
get root() {return session.root;},
|
|
354
370
|
dispose() {
|
|
355
371
|
menus.delete(vm);
|
|
356
372
|
unregister();
|
|
@@ -368,6 +384,8 @@ export function projectFolderActions(vm: FolderVM, locale = 'en') {
|
|
|
368
384
|
return {
|
|
369
385
|
open: () => entry.open(locale),
|
|
370
386
|
openBrowser: entry.openBrowser ? () => entry.openBrowser!(locale) : undefined,
|
|
387
|
+
/** Whether Open can pick a folder on the device. Safari and Firefox cannot, so hosts show Open as unavailable. */
|
|
388
|
+
deviceFolders: entry.deviceFolders,
|
|
371
389
|
save: entry.session.canSave ? () => entry.save(locale) : undefined,
|
|
372
390
|
detach: () => entry.session.detach()
|
|
373
391
|
};
|
|
@@ -380,6 +398,12 @@ export function renderProjectFolderMenu(createElement: MenuElement, {
|
|
|
380
398
|
if (!entry) return null;
|
|
381
399
|
const labels = locale.startsWith('ja') ? messages.ja : messages.en;
|
|
382
400
|
const item = (action: 'open' | 'openBrowser' | 'save') => {
|
|
401
|
+
// Without the device's folder picker, Open is shown but unavailable; the browser's folders have their own item.
|
|
402
|
+
if (action === 'open' && !entry.deviceFolders) {
|
|
403
|
+
return createElement(MenuItem, {command: `project-folder-${action}`},
|
|
404
|
+
createElement('span', {role: 'button', tabIndex: -1, 'aria-disabled': true, title: labels.deviceUnavailable,
|
|
405
|
+
style: {opacity: 0.5, cursor: 'default'}}, labels[action]));
|
|
406
|
+
}
|
|
383
407
|
const run = () => {onRequestClose(); entry[action]!(locale);};
|
|
384
408
|
return createElement(MenuItem, {command: `project-folder-${action}`, onClick: run},
|
|
385
409
|
createElement('span', {role: 'button', tabIndex: 0, onKeyDown(event: KeyboardEvent) {
|
package/src/session.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {assetKey, assetTypeFor, assertFolderUnchanged, collapsePalette, encodePalette, expandPalette, extensionsFile, fileVersion,
|
|
2
|
-
equal, FolderError, manifestFile, paletteFile, parseProject, planExtensionSave, projectAssets, projectChanges, projectFile,
|
|
2
|
+
equal, FolderError, manifestFile, paletteFile, parseProject, planExtensionSave, projectAssets, projectChanges, projectFile, readProjectFolder,
|
|
3
3
|
readFolderUpdate, sameBytes, unsupported} from './source.js';
|
|
4
4
|
import type {Asset, AssetKind, FolderSource, FolderUpdate, JsonObject, Project, Storage} from './source.js';
|
|
5
5
|
import {applyBlockReload, planBlockReload} from './block-reload.js';
|
|
@@ -131,7 +131,9 @@ type Edits = {kind: 'values'; changes: ReturnType<typeof planBlockReload>} |
|
|
|
131
131
|
{kind: 'scripts'; changes: ReturnType<typeof planScriptReload>};
|
|
132
132
|
type PendingUpdate = {update: FolderUpdate; edits: Edits | null; stable: boolean};
|
|
133
133
|
type Pending = PendingUpdate | 'structure' | 'waiting';
|
|
134
|
-
|
|
134
|
+
/** The folder to open, and the folder the user chose for it, which defaults to `directory`. */
|
|
135
|
+
export type Chosen = {directory: FileSystemDirectoryHandle; root?: FileSystemDirectoryHandle};
|
|
136
|
+
type Session = {source: FolderSource; root: FileSystemDirectoryHandle; baseline: Project; ids: string[] | undefined; stage: object; pending: Pending | null};
|
|
135
137
|
/**
|
|
136
138
|
* `ready`: the change can be applied in place: values and positions, or with `deserializeBlocks`, whole scripts. `full`: the change needs the whole project reloaded.
|
|
137
139
|
* `waiting`: an external write looks incomplete and is checked again. `dirty`, `running` and `busy` hold the change.
|
|
@@ -274,20 +276,20 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
274
276
|
unregisterTree?.();
|
|
275
277
|
};
|
|
276
278
|
const openFrom = async (
|
|
277
|
-
getDirectory: () => Promise<
|
|
279
|
+
getDirectory: () => Promise<Chosen | null>,
|
|
278
280
|
confirmReplace: () => boolean,
|
|
279
281
|
prepare: (directory: FileSystemDirectoryHandle) => Promise<FolderSource | null> =
|
|
280
|
-
directory =>
|
|
282
|
+
directory => readProjectFolder(directory, vm.runtime.storage),
|
|
281
283
|
stillCurrent = () => true
|
|
282
284
|
): Promise<OpenResult> => {
|
|
283
285
|
if (disposed || busy) return 'cancelled';
|
|
284
286
|
busy = true;
|
|
285
287
|
const priorStage = vm.runtime.getTargetForStage();
|
|
286
288
|
try {
|
|
287
|
-
const
|
|
288
|
-
if (!
|
|
289
|
+
const chosen = await getDirectory();
|
|
290
|
+
if (!chosen || disposed) return 'cancelled';
|
|
289
291
|
const storage = vm.runtime.storage;
|
|
290
|
-
const source = await prepare(directory);
|
|
292
|
+
const source = await prepare(chosen.directory);
|
|
291
293
|
if (!source || disposed || !stillCurrent() || vm.runtime.getTargetForStage() !== priorStage) return 'cancelled';
|
|
292
294
|
if (host.isProjectDirty() && !confirmReplace()) return 'cancelled';
|
|
293
295
|
host.beforeLoad();
|
|
@@ -296,6 +298,8 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
296
298
|
const assets = source.storageAssets;
|
|
297
299
|
reader.assets = assets;
|
|
298
300
|
let stage: object | null;
|
|
301
|
+
// The project may be the `project` folder inside the chosen one.
|
|
302
|
+
const directory = source.directory;
|
|
299
303
|
pendingTree = undefined;
|
|
300
304
|
expectingTree = true;
|
|
301
305
|
try {
|
|
@@ -307,9 +311,9 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
307
311
|
if (reader.assets === assets) reader.assets = null;
|
|
308
312
|
}
|
|
309
313
|
if (disposed || !stage || vm.runtime.getTargetForStage() !== stage) return 'cancelled';
|
|
310
|
-
host.onOpened(directory.name);
|
|
314
|
+
host.onOpened(chosen.directory.name);
|
|
311
315
|
const baseline = snapshot();
|
|
312
|
-
setCurrent({source, stage, baseline, ids: identify(baseline), pending: null});
|
|
316
|
+
setCurrent({source, root: chosen.root ?? chosen.directory, stage, baseline, ids: identify(baseline), pending: null});
|
|
313
317
|
// The tree may come with the load or right after it; once the folder is current, it is written there.
|
|
314
318
|
expectingTree = false;
|
|
315
319
|
if (pendingTree) writeExplorerState(directory, pendingTree, true);
|
|
@@ -432,6 +436,8 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
432
436
|
return typeof pending === 'object' && pending !== null ? pending.update.version : null;
|
|
433
437
|
},
|
|
434
438
|
get directory() {return current?.source.directory ?? null;},
|
|
439
|
+
/** The folder the user chose: `directory` itself, or the repository whose `project` folder it is. */
|
|
440
|
+
get root() {return current?.root ?? null;},
|
|
435
441
|
async mutate(directory: FileSystemDirectoryHandle, operation: (guard: () => void) => Promise<void>) {
|
|
436
442
|
const session = current;
|
|
437
443
|
if (!session || busy || session.source.directory !== directory) throw new FolderError('conflict');
|
|
@@ -528,9 +534,11 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
528
534
|
if (!session || !session.pending || session.pending === 'waiting' || host.blockReload?.isRunning()) {
|
|
529
535
|
return Promise.resolve('cancelled');
|
|
530
536
|
}
|
|
531
|
-
return openFrom(() => Promise.resolve(current === session ? session.source.directory : null),
|
|
537
|
+
return openFrom(() => Promise.resolve(current === session ? {directory: session.source.directory, root: session.root} : null),
|
|
538
|
+
confirmReplace);
|
|
532
539
|
},
|
|
533
|
-
|
|
540
|
+
/** `pick` gives the folder to open and, when it differs, the folder the user chose as `root`. */
|
|
541
|
+
open(pick: (options: {id: string; mode: 'readwrite'}) => Promise<Chosen>, confirmReplace: () => boolean): Promise<OpenResult> {
|
|
534
542
|
return openFrom(async () => {
|
|
535
543
|
try {
|
|
536
544
|
return await pick({id: 'turbowarp-plus-project-folder', mode: 'readwrite'});
|
|
@@ -540,8 +548,13 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
540
548
|
}
|
|
541
549
|
}, confirmReplace);
|
|
542
550
|
},
|
|
543
|
-
|
|
544
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Opens `directory`, or its `project` folder when it has no project of its own. `root` is the folder the user
|
|
553
|
+
* chose, for a host that located the project itself; it defaults to `directory`.
|
|
554
|
+
*/
|
|
555
|
+
openDirectory(directory: FileSystemDirectoryHandle, confirmReplace: () => boolean,
|
|
556
|
+
root?: FileSystemDirectoryHandle): Promise<OpenResult> {
|
|
557
|
+
return openFrom(() => Promise.resolve({directory, root}), confirmReplace);
|
|
545
558
|
},
|
|
546
559
|
createFromSnapshot(selectDestination: () => Promise<{directory: FileSystemDirectoryHandle; overwrite: boolean} | null>,
|
|
547
560
|
prepareFiles: () => Promise<ReadonlyMap<string, Uint8Array>>, isCurrent: () => boolean): Promise<OpenResult> {
|
|
@@ -553,7 +566,7 @@ export function createFolderSession(vm: FolderVM, host: FolderHost) {
|
|
|
553
566
|
return openFrom(async () => {
|
|
554
567
|
const destination = await selectDestination();
|
|
555
568
|
overwrite = destination?.overwrite ?? false;
|
|
556
|
-
return destination
|
|
569
|
+
return destination ? {directory: destination.directory} : null;
|
|
557
570
|
}, currentProject, async directory => {
|
|
558
571
|
if (!currentProject()) return null;
|
|
559
572
|
savedRevision = revision;
|
package/src/source.ts
CHANGED
|
@@ -374,6 +374,46 @@ export async function readFolder(directory: FileSystemDirectoryHandle, storage:
|
|
|
374
374
|
palette: paletteDocument};
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
/** The project folder inside a repository, as Project Starter makes it. */
|
|
378
|
+
export const projectSubfolder = 'project';
|
|
379
|
+
|
|
380
|
+
const missingEntry = (error: unknown) => error instanceof DOMException && ['NotFoundError', 'TypeMismatchError'].includes(error.name);
|
|
381
|
+
/** Whether `directory` has an entry called `name`, a file or a folder. */
|
|
382
|
+
async function hasEntry(directory: FileSystemDirectoryHandle, name: string) {
|
|
383
|
+
for (const get of [() => directory.getFileHandle(name), () => directory.getDirectoryHandle(name)]) {
|
|
384
|
+
try {
|
|
385
|
+
await get();
|
|
386
|
+
return true;
|
|
387
|
+
} catch (error) {
|
|
388
|
+
if (!missingEntry(error)) throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Reads the project in `directory`, or, when the folder has no project of its own, in its `project` folder, as in a
|
|
396
|
+
* repository whose project sits in `project/`. That folder must not be a repository itself. The error is the one
|
|
397
|
+
* for `directory` when neither holds a project.
|
|
398
|
+
*/
|
|
399
|
+
export async function readProjectFolder(directory: FileSystemDirectoryHandle, storage: Storage): Promise<FolderSource> {
|
|
400
|
+
try {
|
|
401
|
+
return await readFolder(directory, storage);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
const child = await (async () => {
|
|
404
|
+
if (await hasEntry(directory, projectFile) || await hasEntry(directory, manifestFile)) return null;
|
|
405
|
+
const found = await directory.getDirectoryHandle(projectSubfolder);
|
|
406
|
+
return await hasEntry(found, '.git') ? null : found;
|
|
407
|
+
})().catch(() => null);
|
|
408
|
+
if (!child) throw error;
|
|
409
|
+
try {
|
|
410
|
+
return await readFolder(child, storage);
|
|
411
|
+
} catch {
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
377
417
|
export const sameBytes = (a: Uint8Array, b: Uint8Array) => a.length === b.length && a.every((value, index) => value === b[index]);
|
|
378
418
|
|
|
379
419
|
export type FolderUpdate = {version: string; bytes: Uint8Array; project: Project};
|