@kubohiroya/turbowarp-plus-editor-project-folder 0.16.0 → 0.17.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 CHANGED
@@ -26,6 +26,8 @@ Safari と Firefox にはフォルダ選択(`showDirectoryPicker`)があり
26
26
  - `fallback`(既定):フォルダ選択がないブラウザー(Safari、Firefox)でだけ使います。ファイルメニューでは **フォルダを開く…** を、このブラウザーでは端末のフォルダを開けない旨を添えて無効にし、ブラウザー内の作品フォルダの一覧を開く **ブラウザーに保存したフォルダを開く…** を出します。`projectFolderActions(vm)` は `deviceFolders: false` を返すので、ホストのメニューでも同じように無効にできます。ホストが `open` を呼んだときは、これまでどおりブラウザー内のフォルダを開きます。`createFromSnapshot` は新しい作品フォルダの名前を尋ねます(`title` で名前の初期値を渡せます)。
27
27
  - `always`:フォルダ選択があるブラウザーでも使います。ファイルメニューの **フォルダを開く…** の隣に **ブラウザーに保存したフォルダを開く…** を足し、`projectFolderActions(vm).openBrowser` でも開けます。
28
28
  - `off`:使いません。
29
+ - 作品フォルダをまだ開いていないパネルには、利用できる保存方式の説明と作成ボタンを出します。`always` でフォルダ選択と OPFS の両方が使える場合は2方式、Safari・Firefox ではブラウザー内保存の説明を出します。説明には、ボタンを押した後の操作、外部アプリからの見え方、ブラウザー内の作品を残すための書き出し方法を含めます。
30
+ - `renderProjectFolderExplorer` の `createFolder(location)` には、選んだ保存先(`device` または `browser`)が渡ります。ホストはこれを `createFromSnapshot({location, ...})` に渡します。`location` を省略した場合は従来どおりフォルダ選択を優先し、利用できない保存先を明示した場合は別の保存先に切り替えずエラーにします。
29
31
  - 一覧のダイアログでは、作品フォルダを開く、ZIP で書き出す、削除することができます。保存領域の使用量と、ブラウザーが消さずに残すか(`persisted`)も表示します。閉じるボタンは X のアイコンで、名前は表示の言語に合わせます。
30
32
  - 作品フォルダは `turbowarp-plus/projects/<id>/` に置き、表示名と時刻は `turbowarp-plus/project-info/<id>.json` に置きます。作品フォルダの外に置くので、Git の管理対象には入りません。`projectPath` を指定すると、リポジトリのルートの下の作品フォルダ(例:`project`)を開けます。
31
33
  - 同じ作品フォルダへの保存は、`navigator.locks` で作品ごとに排他します。WebKit は `createWritable({mode: 'exclusive'})` を重ねても拒否しないので、タブ間の排他はロックで行います。保存すると一覧の更新時刻が変わります。
@@ -33,6 +35,8 @@ Safari と Firefox にはフォルダ選択(`showDirectoryPicker`)があり
33
35
 
34
36
  ブラウザーの中の作品フォルダは、サイトのデータを消したときや、しばらくサイトを使わなかったときに、ブラウザーが消すことがあります(Safari では 7 日間)。最初の作品フォルダを作るときに `navigator.storage.persist()` を求めますが、保証にはなりません。ZIP で書き出すか、Git で GitHub に送って残すようにダイアログで案内します。
35
37
 
38
+ 保存先選択の導入は、このパッケージを先に公開し、Editor の依存をその版へ固定してからホストの結線を反映します。切り戻すときは Editor の結線と依存の固定を一緒に戻します。OPFS に作成済みの作品は削除せず、ブラウザー内の一覧から開く・ZIP で書き出す経路を維持します。
39
+
36
40
  ## ブロックパレットの設定
37
41
 
38
42
  TurboWarp Plus Editor は、ブロックパレットの設定を画面状態(`.tw-plus/workspace.json`)に保存するようになりました。この節の形式 2 の読み書きは、それ以前に作られた作品フォルダのために残しています。
package/README.md CHANGED
@@ -28,6 +28,8 @@ Safari and Firefox have no folder picker (`showDirectoryPicker`). In these brows
28
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
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.
30
30
  - `off`: never.
31
+ - Before a folder is open, the explorer explains each available destination and offers its creation button. With `always`, browsers supporting both the picker and OPFS show both choices; Safari and Firefox explain browser storage. The text describes the next step, access from other apps, and how to keep an exported copy.
32
+ - The explorer calls its host's `createFolder(location)` with `device` or `browser`. Forward this to `createFromSnapshot({location, ...})`. Omitting `location` preserves the existing picker-first behavior. An explicitly unavailable destination fails instead of silently switching storage.
31
33
  - 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.
32
34
  - 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`.
33
35
  - Saves to the same folder are serialized per folder with `navigator.locks`. WebKit does not refuse a second `createWritable({mode: 'exclusive'})`, so the lock is what keeps tabs apart. A save updates the folder's time in the list.
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { ExplorerMutation } from './folder-registry.js';
2
+ import type { ExplorerMutation, ProjectFolderLocation } from './folder-registry.js';
3
3
  import type { Json, Project } from './source.js';
4
4
  import type { FilePreviewRequest, ReadFileBaseline } from './file-preview.js';
5
5
  export type ExplorerMark = 'added' | 'modified' | 'deleted' | 'untracked';
@@ -66,8 +66,8 @@ export type FollowFileStatuses = (directory: FileSystemDirectoryHandle, update:
66
66
  type FolderViewProps = {
67
67
  vm: object;
68
68
  locale?: string;
69
- /** Saves the current project to a local folder. */
70
- createFolder?(): Promise<unknown>;
69
+ /** Saves the current project to the selected storage location. */
70
+ createFolder?(location?: ProjectFolderLocation): Promise<unknown>;
71
71
  marks?: FollowMarks;
72
72
  fileStatuses?: FollowFileStatuses;
73
73
  /** Reports unsaved text edits in open file tabs for the given folder. */
package/dist/explorer.js CHANGED
@@ -1526,8 +1526,17 @@ var messages = {
1526
1526
  results: "Matching files",
1527
1527
  noFolder: "Open a folder to show its files here.",
1528
1528
  open: "Open Folder…",
1529
- create: "Create Project Folder",
1530
1529
  creating: "Creating project folder…",
1530
+ storageIntro: "Save the current project as a folder containing its project data, costumes, sounds and other files.",
1531
+ deviceTitle: "Save to a folder on this device",
1532
+ deviceDescription: "Choose a folder on your computer. You can view its files in Finder or File Explorer and work with them in VS Code or other apps.",
1533
+ deviceNext: "The button opens a folder picker. Choose an empty folder or create a new one there.",
1534
+ deviceCreate: "Choose a Folder and Save…",
1535
+ browserTitle: "Save in this browser",
1536
+ browserDescription: "Enter a name to create a project folder in this site’s storage, without choosing a folder on your computer. Its files are not directly visible in Finder, File Explorer or other apps.",
1537
+ browserRetention: "The project stays in this browser profile on this device. Clearing site data or automatic browser cleanup may delete it. Keep a copy by exporting an SB3 or ZIP, or saving it to GitHub.",
1538
+ browserReopen: "To continue later, use Open Folder Saved in This Browser… in the File menu.",
1539
+ browserCreate: "Name and Save in This Browser…",
1531
1540
  createFailed: "Could not create the project folder.",
1532
1541
  unavailable: "File tabs are unavailable in this editor layout.",
1533
1542
  failed: "This folder could not be read.",
@@ -1565,8 +1574,17 @@ var messages = {
1565
1574
  results: "検索結果",
1566
1575
  noFolder: "フォルダを開くと、ここにファイルを表示します。",
1567
1576
  open: "フォルダを開く…",
1568
- create: "プロジェクトフォルダを作成",
1569
1577
  creating: "プロジェクトフォルダを作成しています…",
1578
+ storageIntro: "編集中の作品を、作品データ・コスチューム・音などのファイルをまとめたプロジェクトフォルダとして保存します。",
1579
+ deviceTitle: "端末のフォルダに保存",
1580
+ deviceDescription: "パソコン上のフォルダを選んで保存します。Finder やエクスプローラーでファイルを確認でき、VS Code などの外部アプリでも扱えます。",
1581
+ deviceNext: "ボタンを押すとフォルダ選択画面が開きます。空のフォルダを選ぶか、その画面で新しいフォルダを作成してください。",
1582
+ deviceCreate: "フォルダを選んで保存…",
1583
+ browserTitle: "このブラウザー内に保存",
1584
+ browserDescription: "名前を入力すると、このサイト専用の保存領域にプロジェクトフォルダを作成します。パソコン上のフォルダを選ぶ必要はありません。Finder やエクスプローラー、外部アプリからファイルを直接見ることはできません。",
1585
+ browserRetention: "保存した作品は、この端末のこのブラウザーのプロファイル内に残ります。サイトデータの削除やブラウザーの自動整理で消える場合があります。SB3・ZIP の書き出しや GitHub への保存で、別の場所にも作品を残してください。",
1586
+ browserReopen: "次回は「ファイル」メニューの「ブラウザーに保存したフォルダを開く…」から開けます。",
1587
+ browserCreate: "名前を付けてブラウザー内に保存…",
1570
1588
  createFailed: "プロジェクトフォルダを作成できませんでした。",
1571
1589
  unavailable: "このエディターのレイアウトではファイルをタブで開けません。",
1572
1590
  failed: "このフォルダを読み込めません。",
@@ -1676,9 +1694,18 @@ background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50
1676
1694
  color:inherit;color:color-mix(in srgb,currentColor 78%,transparent);font-size:.75em;line-height:1.4;
1677
1695
  white-space:normal;overflow-wrap:anywhere}
1678
1696
  .${prefix}-status{opacity:.7;font-style:italic;padding-block:.15em}
1679
- .${prefix}-empty{padding:.5em}
1697
+ .${prefix}-empty{padding:.75em;line-height:1.6;overflow-wrap:anywhere}
1680
1698
  .${prefix}-empty p{margin:0 0 .6em}
1681
- .${prefix}-empty button{color:inherit;background:transparent;border:1px solid currentColor;border-radius:4px;padding:.2em .6em;font:inherit;cursor:pointer}`;
1699
+ .${prefix}-storage{padding-block:.8em;border-block-start:1px solid color-mix(in srgb,currentColor 25%,transparent)}
1700
+ .${prefix}-storage h3{margin:0 0 .5em;font-size:1em}
1701
+ .${prefix}-empty button{color:inherit;background:transparent;border:1px solid currentColor;border-radius:4px;padding:.4em .7em;font:inherit;cursor:pointer;white-space:normal;max-width:100%}
1702
+ .${prefix}-storage button{display:inline-flex;align-items:center;gap:.45em;text-align:start;
1703
+ border-radius:.65rem;padding:.55em .9em;background:var(--looks-secondary,#855cd6);
1704
+ border-color:var(--looks-secondary,#855cd6);color:#fff;font-weight:600;line-height:1.4}
1705
+ .${prefix}-storage button:hover:not(:disabled){background:color-mix(in srgb,var(--looks-secondary,#855cd6) 88%,#000)}
1706
+ .${prefix}-storage button:focus-visible{outline:2px solid var(--looks-secondary,#855cd6);outline-offset:3px}
1707
+ .${prefix}-storage button svg{flex:none}
1708
+ .${prefix}-empty button:disabled{opacity:.6;cursor:wait}`;
1682
1709
  var indent = (level) => ({ paddingInlineStart: `${.25 + level * 1.1}em` });
1683
1710
  var page = "M3.5 1.5h6l3 3v10h-9z";
1684
1711
  var corner = "M9.5 1.5v3h3";
@@ -1718,6 +1745,14 @@ var icons = {
1718
1745
  ],
1719
1746
  "file": [page, corner]
1720
1747
  };
1748
+ var storageIcons = {
1749
+ device: icons.folder,
1750
+ browser: [
1751
+ "M2.5 2.5h11a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z",
1752
+ "M1.5 5.5h13",
1753
+ "M3.5 4h.1M5.5 4h.1"
1754
+ ]
1755
+ };
1721
1756
  var extensionIcons = {
1722
1757
  json: "json",
1723
1758
  svg: "image",
@@ -2540,12 +2575,12 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2540
2575
  const message = messagesFor(locale);
2541
2576
  const [creating, setCreating] = React.useState(false);
2542
2577
  const [createError, setCreateError] = React.useState("");
2543
- const create = async () => {
2578
+ const create = async (location) => {
2544
2579
  if (!createFolder || creating) return;
2545
2580
  setCreating(true);
2546
2581
  setCreateError("");
2547
2582
  try {
2548
- await createFolder();
2583
+ await createFolder(location);
2549
2584
  } catch (_unused5) {
2550
2585
  setCreateError(message.createFailed);
2551
2586
  } finally {
@@ -2635,14 +2670,35 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2635
2670
  }));
2636
2671
  }, [directory, followGit]);
2637
2672
  if (!folder) return null;
2638
- if (!directory) return /* @__PURE__ */ React.createElement("div", { className: `${prefix}-empty` }, /* @__PURE__ */ React.createElement("style", null, css), createFolder ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, projectFolderOverwriteWarning(locale)), /* @__PURE__ */ React.createElement("button", {
2639
- type: "button",
2640
- disabled: creating,
2641
- onClick: () => void create()
2642
- }, message.create), creating && /* @__PURE__ */ React.createElement("p", { role: "status" }, message.creating), createError && /* @__PURE__ */ React.createElement("p", { role: "alert" }, createError)) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, message.noFolder), /* @__PURE__ */ React.createElement("button", {
2643
- type: "button",
2644
- onClick: () => folder.open(locale)
2645
- }, message.open)));
2673
+ if (!directory) {
2674
+ var _folder$locations;
2675
+ return /* @__PURE__ */ React.createElement("div", { className: `${prefix}-empty` }, /* @__PURE__ */ React.createElement("style", null, css), createFolder ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, message.storageIntro), ((_folder$locations = folder.locations) !== null && _folder$locations !== void 0 ? _folder$locations : ["device"]).map((location) => /* @__PURE__ */ React.createElement("section", {
2676
+ key: location,
2677
+ className: `${prefix}-storage`,
2678
+ "data-project-folder-location": location
2679
+ }, /* @__PURE__ */ React.createElement("h3", null, location === "device" ? message.deviceTitle : message.browserTitle), location === "device" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, message.deviceDescription), /* @__PURE__ */ React.createElement("p", null, message.deviceNext), /* @__PURE__ */ React.createElement("p", null, projectFolderOverwriteWarning(locale))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, message.browserDescription), /* @__PURE__ */ React.createElement("p", null, message.browserRetention), /* @__PURE__ */ React.createElement("p", null, message.browserReopen)), /* @__PURE__ */ React.createElement("button", {
2680
+ type: "button",
2681
+ disabled: creating,
2682
+ onClick: () => void create(location)
2683
+ }, /* @__PURE__ */ React.createElement("svg", {
2684
+ viewBox: "0 0 16 16",
2685
+ width: "16",
2686
+ height: "16",
2687
+ fill: "none",
2688
+ stroke: "currentColor",
2689
+ strokeWidth: "1.2",
2690
+ strokeLinecap: "round",
2691
+ strokeLinejoin: "round",
2692
+ "aria-hidden": "true",
2693
+ focusable: "false"
2694
+ }, storageIcons[location].map((d, index) => /* @__PURE__ */ React.createElement("path", {
2695
+ key: index,
2696
+ d
2697
+ }))), /* @__PURE__ */ React.createElement("span", null, location === "device" ? message.deviceCreate : message.browserCreate)))), creating && /* @__PURE__ */ React.createElement("p", { role: "status" }, message.creating), createError && /* @__PURE__ */ React.createElement("p", { role: "alert" }, createError)) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, message.noFolder), /* @__PURE__ */ React.createElement("button", {
2698
+ type: "button",
2699
+ onClick: () => folder.open(locale)
2700
+ }, message.open)));
2701
+ }
2646
2702
  const unsavedPaths = new Set((unsaved === null || unsaved === void 0 ? void 0 : unsaved.directory) === directory ? unsaved.paths : void 0);
2647
2703
  if ((fileEdits === null || fileEdits === void 0 ? void 0 : fileEdits.directory) === directory) for (const path of fileEdits.paths) unsavedPaths.add(path);
2648
2704
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ProjectFolderExplorer, {
@@ -1,9 +1,12 @@
1
1
  /** The project folder mounted for a VM, as a view of the folder follows it. */
2
2
  export type ExplorerMutation = (guard: () => void) => Promise<void>;
3
+ export type ProjectFolderLocation = 'device' | 'browser';
3
4
  export interface FollowedFolder {
4
5
  readonly directory: FileSystemDirectoryHandle | null;
5
6
  /** The folder the user chose for `directory`: itself, or the repository whose `project` folder it is. */
6
7
  readonly root?: FileSystemDirectoryHandle | null;
8
+ /** Storage choices available when creating a project folder. */
9
+ readonly locations?: readonly ProjectFolderLocation[];
7
10
  subscribe(listener: () => void): () => void;
8
11
  subscribeEdits(listener: () => void): () => void;
9
12
  unsavedPaths(): ReadonlySet<string> | null;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import type { ProjectFolderLocation } from './folder-registry.js';
1
2
  import type { BrowserProjects } from './browser-projects.js';
2
3
  import type { FolderHost, FolderVM } from './session.js';
3
4
  export type { Comparison, ComparisonRequest, ComparisonSection, FolderHost, FolderScreenState, FolderVM, OpenResult } from './session.js';
4
5
  export type { ReloadTarget } from './block-reload.js';
5
6
  export { followProjectFolder } from './folder-registry.js';
6
- export type { FollowedFolder } from './folder-registry.js';
7
+ export type { FollowedFolder, ProjectFolderLocation } from './folder-registry.js';
7
8
  export type { DeserializeBlocks } from './script-reload.js';
8
9
  export { createProjectFolder, projectFolderOverwriteWarning } from './create-folder.js';
9
10
  export { openBrowserProjects } from './browser-projects.js';
@@ -53,12 +54,14 @@ export declare function mountProjectFolder({ vm, document, host, locale, autoRel
53
54
  * Creates a project folder from a snapshot. `title` names a folder made in the browser, where the user names a
54
55
  * new folder instead of picking one on the device.
55
56
  */
56
- createFromSnapshot({ prepareFiles, collectEdits, directory, current, title }: {
57
+ createFromSnapshot({ prepareFiles, collectEdits, directory, current, title, location }: {
57
58
  prepareFiles: () => Promise<ReadonlyMap<string, Uint8Array>>;
58
59
  collectEdits?: () => Promise<void>;
59
60
  directory?: FileSystemDirectoryHandle;
60
61
  current?: () => boolean;
61
62
  title?: string;
63
+ /** Explicit destination; omitted uses the device picker when available. */
64
+ location?: ProjectFolderLocation;
62
65
  }): Promise<import("./session.js").OpenResult>;
63
66
  /**
64
67
  * The folder the loaded project came from, or `null` once another project loaded or the folder was
package/dist/index.js CHANGED
@@ -1745,7 +1745,13 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
1745
1745
  };
1746
1746
  };
1747
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;
1748
+ const locations = [];
1749
+ if (devicePicker) locations.push("device");
1750
+ if (browserProjects) locations.push("browser");
1751
+ const pickNewDirectory = async (options, title, location = devicePicker ? "device" : "browser") => {
1752
+ if (!locations.includes(location)) throw new FolderError("unsupported");
1753
+ return location === "device" ? devicePicker.call(view, options) : (await chooseBrowser("create", title)).directory;
1754
+ };
1749
1755
  /** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
1750
1756
  const withBrowserProject = async (directory, run) => {
1751
1757
  const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
@@ -1973,6 +1979,7 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
1973
1979
  get root() {
1974
1980
  return session.root;
1975
1981
  },
1982
+ locations,
1976
1983
  subscribe: (listener) => session.subscribe(listener),
1977
1984
  subscribeEdits: (listener) => session.subscribeEdits(listener),
1978
1985
  unsavedPaths: () => session.unsavedPaths(),
@@ -1991,14 +1998,14 @@ function mountProjectFolder({ vm, document, host, locale = "en", autoReload = tr
1991
1998
  * Creates a project folder from a snapshot. `title` names a folder made in the browser, where the user names a
1992
1999
  * new folder instead of picking one on the device.
1993
2000
  */
1994
- createFromSnapshot({ prepareFiles, collectEdits, directory, current = () => true, title }) {
2001
+ createFromSnapshot({ prepareFiles, collectEdits, directory, current = () => true, title, location }) {
1995
2002
  const message = locale.startsWith("ja") ? "指定されたフォルダは空ではありません。フォルダに保存されている内容が上書きされる場合があります。よろしいですか?" : "The selected folder is not empty. Contents in the folder may be overwritten. Continue?";
1996
2003
  return session.createFromSnapshot(async () => {
1997
2004
  try {
1998
2005
  const selected = directory !== null && directory !== void 0 ? directory : await pickNewDirectory({
1999
2006
  id: "turbowarp-plus-project-folder",
2000
2007
  mode: "readwrite"
2001
- }, title);
2008
+ }, title, location);
2002
2009
  if (!current()) return null;
2003
2010
  const overwrite = !await isProjectFolderEmpty(selected);
2004
2011
  if (!current() || overwrite && !view.confirm(message)) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-project-folder",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Read and save expanded Scratch project folders in TurboWarp Plus Editor",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
package/src/explorer.tsx CHANGED
@@ -7,7 +7,7 @@ import {projectFolderOverwriteWarning} from './create-folder.js';
7
7
  import {followProjectFolder} from './folder-registry.js';
8
8
  import {hiddenEntry, readExplorerState, subscribeExplorerState, writeExplorerState} from './explorer-state.js';
9
9
  import type {ExplorerTreeState} from './explorer-state.js';
10
- import type {ExplorerMutation, FollowedFolder} from './folder-registry.js';
10
+ import type {ExplorerMutation, FollowedFolder, ProjectFolderLocation} from './folder-registry.js';
11
11
  import type {Json, Project} from './source.js';
12
12
  import {canMoveExplorerEntry, copyExplorerDirectory, copyExplorerFile, createExplorerDirectory, deleteExplorerEntry, ExplorerFileError,
13
13
  explorerNameAvailable, moveExplorerEntry, parentPath, renameExplorerEntry, resolveExplorerDirectory} from './explorer-files.js';
@@ -58,7 +58,17 @@ const messages = {
58
58
  label: 'Project folder', loading: 'Loading…', empty: 'This folder is empty.', noMatches: 'No matching files.',
59
59
  results: 'Matching files',
60
60
  noFolder: 'Open a folder to show its files here.', open: 'Open Folder…',
61
- create: 'Create Project Folder', creating: 'Creating project folder…',
61
+ creating: 'Creating project folder…',
62
+ storageIntro: 'Save the current project as a folder containing its project data, costumes, sounds and other files.',
63
+ deviceTitle: 'Save to a folder on this device',
64
+ deviceDescription: 'Choose a folder on your computer. You can view its files in Finder or File Explorer and work with them in VS Code or other apps.',
65
+ deviceNext: 'The button opens a folder picker. Choose an empty folder or create a new one there.',
66
+ deviceCreate: 'Choose a Folder and Save…',
67
+ browserTitle: 'Save in this browser',
68
+ browserDescription: 'Enter a name to create a project folder in this site’s storage, without choosing a folder on your computer. Its files are not directly visible in Finder, File Explorer or other apps.',
69
+ browserRetention: 'The project stays in this browser profile on this device. Clearing site data or automatic browser cleanup may delete it. Keep a copy by exporting an SB3 or ZIP, or saving it to GitHub.',
70
+ browserReopen: 'To continue later, use Open Folder Saved in This Browser… in the File menu.',
71
+ browserCreate: 'Name and Save in This Browser…',
62
72
  createFailed: 'Could not create the project folder.',
63
73
  unavailable: 'File tabs are unavailable in this editor layout.',
64
74
  failed: 'This folder could not be read.', denied: 'Permission to read this folder was not granted.',
@@ -78,7 +88,17 @@ const messages = {
78
88
  label: '作品フォルダ', loading: '読み込んでいます…', empty: 'このフォルダは空です。', noMatches: '該当するファイルはありません。',
79
89
  results: '検索結果',
80
90
  noFolder: 'フォルダを開くと、ここにファイルを表示します。', open: 'フォルダを開く…',
81
- create: 'プロジェクトフォルダを作成', creating: 'プロジェクトフォルダを作成しています…',
91
+ creating: 'プロジェクトフォルダを作成しています…',
92
+ storageIntro: '編集中の作品を、作品データ・コスチューム・音などのファイルをまとめたプロジェクトフォルダとして保存します。',
93
+ deviceTitle: '端末のフォルダに保存',
94
+ deviceDescription: 'パソコン上のフォルダを選んで保存します。Finder やエクスプローラーでファイルを確認でき、VS Code などの外部アプリでも扱えます。',
95
+ deviceNext: 'ボタンを押すとフォルダ選択画面が開きます。空のフォルダを選ぶか、その画面で新しいフォルダを作成してください。',
96
+ deviceCreate: 'フォルダを選んで保存…',
97
+ browserTitle: 'このブラウザー内に保存',
98
+ browserDescription: '名前を入力すると、このサイト専用の保存領域にプロジェクトフォルダを作成します。パソコン上のフォルダを選ぶ必要はありません。Finder やエクスプローラー、外部アプリからファイルを直接見ることはできません。',
99
+ browserRetention: '保存した作品は、この端末のこのブラウザーのプロファイル内に残ります。サイトデータの削除やブラウザーの自動整理で消える場合があります。SB3・ZIP の書き出しや GitHub への保存で、別の場所にも作品を残してください。',
100
+ browserReopen: '次回は「ファイル」メニューの「ブラウザーに保存したフォルダを開く…」から開けます。',
101
+ browserCreate: '名前を付けてブラウザー内に保存…',
82
102
  createFailed: 'プロジェクトフォルダを作成できませんでした。',
83
103
  unavailable: 'このエディターのレイアウトではファイルをタブで開けません。',
84
104
  failed: 'このフォルダを読み込めません。', denied: 'このフォルダを読む許可がありません。',
@@ -191,9 +211,18 @@ background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50
191
211
  color:inherit;color:color-mix(in srgb,currentColor 78%,transparent);font-size:.75em;line-height:1.4;
192
212
  white-space:normal;overflow-wrap:anywhere}
193
213
  .${prefix}-status{opacity:.7;font-style:italic;padding-block:.15em}
194
- .${prefix}-empty{padding:.5em}
214
+ .${prefix}-empty{padding:.75em;line-height:1.6;overflow-wrap:anywhere}
195
215
  .${prefix}-empty p{margin:0 0 .6em}
196
- .${prefix}-empty button{color:inherit;background:transparent;border:1px solid currentColor;border-radius:4px;padding:.2em .6em;font:inherit;cursor:pointer}`;
216
+ .${prefix}-storage{padding-block:.8em;border-block-start:1px solid color-mix(in srgb,currentColor 25%,transparent)}
217
+ .${prefix}-storage h3{margin:0 0 .5em;font-size:1em}
218
+ .${prefix}-empty button{color:inherit;background:transparent;border:1px solid currentColor;border-radius:4px;padding:.4em .7em;font:inherit;cursor:pointer;white-space:normal;max-width:100%}
219
+ .${prefix}-storage button{display:inline-flex;align-items:center;gap:.45em;text-align:start;
220
+ border-radius:.65rem;padding:.55em .9em;background:var(--looks-secondary,#855cd6);
221
+ border-color:var(--looks-secondary,#855cd6);color:#fff;font-weight:600;line-height:1.4}
222
+ .${prefix}-storage button:hover:not(:disabled){background:color-mix(in srgb,var(--looks-secondary,#855cd6) 88%,#000)}
223
+ .${prefix}-storage button:focus-visible{outline:2px solid var(--looks-secondary,#855cd6);outline-offset:3px}
224
+ .${prefix}-storage button svg{flex:none}
225
+ .${prefix}-empty button:disabled{opacity:.6;cursor:wait}`;
197
226
 
198
227
  const indent = (level: number) => ({paddingInlineStart: `${0.25 + level * 1.1}em`});
199
228
 
@@ -213,6 +242,11 @@ const icons: Record<IconKind, string[]> = {
213
242
  'text': [page, corner, 'M5.5 7.5h5M5.5 9.5h5M5.5 11.5h3'],
214
243
  'file': [page, corner]
215
244
  };
245
+ const storageIcons: Record<ProjectFolderLocation, string[]> = {
246
+ device: icons.folder,
247
+ browser: ['M2.5 2.5h11a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z',
248
+ 'M1.5 5.5h13', 'M3.5 4h.1M5.5 4h.1']
249
+ };
216
250
  const extensionIcons: Record<string, IconKind> = {
217
251
  json: 'json', svg: 'image', png: 'image', jpg: 'image', jpeg: 'image', gif: 'image', bmp: 'image', webp: 'image',
218
252
  wav: 'sound', mp3: 'sound', ogg: 'sound', js: 'code', mjs: 'code', ts: 'code', md: 'text', txt: 'text'
@@ -844,8 +878,8 @@ export type FollowFileStatuses = (directory: FileSystemDirectoryHandle,
844
878
  type FolderViewProps = {
845
879
  vm: object;
846
880
  locale?: string;
847
- /** Saves the current project to a local folder. */
848
- createFolder?(): Promise<unknown>;
881
+ /** Saves the current project to the selected storage location. */
882
+ createFolder?(location?: ProjectFolderLocation): Promise<unknown>;
849
883
  marks?: FollowMarks;
850
884
  fileStatuses?: FollowFileStatuses;
851
885
  /** Reports unsaved text edits in open file tabs for the given folder. */
@@ -867,12 +901,12 @@ function FolderView({vm, locale = 'en', marks: followMarks, fileStatuses: follow
867
901
  const message = messagesFor(locale);
868
902
  const [creating, setCreating] = React.useState(false);
869
903
  const [createError, setCreateError] = React.useState('');
870
- const create = async () => {
904
+ const create = async (location: ProjectFolderLocation) => {
871
905
  if (!createFolder || creating) return;
872
906
  setCreating(true);
873
907
  setCreateError('');
874
908
  try {
875
- await createFolder();
909
+ await createFolder(location);
876
910
  } catch {
877
911
  setCreateError(message.createFailed);
878
912
  } finally {
@@ -938,8 +972,27 @@ function FolderView({vm, locale = 'en', marks: followMarks, fileStatuses: follow
938
972
  return <div className={`${prefix}-empty`}>
939
973
  <style>{css}</style>
940
974
  {createFolder ? <>
941
- <p>{projectFolderOverwriteWarning(locale)}</p>
942
- <button type="button" disabled={creating} onClick={() => void create()}>{message.create}</button>
975
+ <p>{message.storageIntro}</p>
976
+ {(folder.locations ?? ['device']).map(location => <section key={location}
977
+ className={`${prefix}-storage`} data-project-folder-location={location}>
978
+ <h3>{location === 'device' ? message.deviceTitle : message.browserTitle}</h3>
979
+ {location === 'device' ? <>
980
+ <p>{message.deviceDescription}</p>
981
+ <p>{message.deviceNext}</p>
982
+ <p>{projectFolderOverwriteWarning(locale)}</p>
983
+ </> : <>
984
+ <p>{message.browserDescription}</p>
985
+ <p>{message.browserRetention}</p>
986
+ <p>{message.browserReopen}</p>
987
+ </>}
988
+ <button type="button" disabled={creating} onClick={() => void create(location)}>
989
+ <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"
990
+ strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">
991
+ {storageIcons[location].map((d, index) => <path key={index} d={d} />)}
992
+ </svg>
993
+ <span>{location === 'device' ? message.deviceCreate : message.browserCreate}</span>
994
+ </button>
995
+ </section>)}
943
996
  {creating && <p role="status">{message.creating}</p>}
944
997
  {createError && <p role="alert">{createError}</p>}
945
998
  </> : <>
@@ -1,10 +1,13 @@
1
1
  /** The project folder mounted for a VM, as a view of the folder follows it. */
2
2
  export type ExplorerMutation = (guard: () => void) => Promise<void>;
3
+ export type ProjectFolderLocation = 'device' | 'browser';
3
4
 
4
5
  export interface FollowedFolder {
5
6
  readonly directory: FileSystemDirectoryHandle | null;
6
7
  /** The folder the user chose for `directory`: itself, or the repository whose `project` folder it is. */
7
8
  readonly root?: FileSystemDirectoryHandle | null;
9
+ /** Storage choices available when creating a project folder. */
10
+ readonly locations?: readonly ProjectFolderLocation[];
8
11
  subscribe(listener: () => void): () => void;
9
12
  subscribeEdits(listener: () => void): () => void;
10
13
  unsavedPaths(): ReadonlySet<string> | null;
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import {FolderError} from './source.js';
2
2
  import {createFolderSession} from './session.js';
3
3
  import {isProjectFolderEmpty} from './create-folder.js';
4
4
  import {registerFolder} from './folder-registry.js';
5
+ import type {ProjectFolderLocation} from './folder-registry.js';
5
6
  import {openBrowserProjects} from './browser-projects.js';
6
7
  import type {BrowserProjects} from './browser-projects.js';
7
8
  import {chooseBrowserProject} from './browser-project-dialog.js';
@@ -10,7 +11,7 @@ import type {Chosen, FolderHost, FolderVM, PickerWindow} from './session.js';
10
11
  export type {Comparison, ComparisonRequest, ComparisonSection, FolderHost, FolderScreenState, FolderVM, OpenResult} from './session.js';
11
12
  export type {ReloadTarget} from './block-reload.js';
12
13
  export {followProjectFolder} from './folder-registry.js';
13
- export type {FollowedFolder} from './folder-registry.js';
14
+ export type {FollowedFolder, ProjectFolderLocation} from './folder-registry.js';
14
15
  export type {DeserializeBlocks} from './script-reload.js';
15
16
  export {createProjectFolder, projectFolderOverwriteWarning} from './create-folder.js';
16
17
  export {openBrowserProjects} from './browser-projects.js';
@@ -123,8 +124,14 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
123
124
  const pickDirectory = devicePicker ?
124
125
  async (options: {id: string; mode: 'readwrite'}): Promise<Chosen> => ({directory: await devicePicker.call(view, options)}) :
125
126
  chooseBrowserFolder;
126
- const pickNewDirectory = async (options: {id: string; mode: 'readwrite'}, title?: string) =>
127
- devicePicker ? devicePicker.call(view, options) : (await chooseBrowser('create', title)).directory;
127
+ const locations: ProjectFolderLocation[] = [];
128
+ if (devicePicker) locations.push('device');
129
+ if (browserProjects) locations.push('browser');
130
+ const pickNewDirectory = async (options: {id: string; mode: 'readwrite'}, title?: string,
131
+ location: ProjectFolderLocation = devicePicker ? 'device' : 'browser') => {
132
+ if (!locations.includes(location)) throw new FolderError('unsupported');
133
+ return location === 'device' ? devicePicker!.call(view, options) : (await chooseBrowser('create', title)).directory;
134
+ };
128
135
  /** Runs `run` with the browser folder of `directory` locked against other tabs, and marks it as updated. */
129
136
  const withBrowserProject = async <T>(directory: FileSystemDirectoryHandle | null, run: () => Promise<T>) => {
130
137
  const project = directory && browserProjects ? await browserProjects.find(directory).catch(() => null) : null;
@@ -314,6 +321,7 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
314
321
  const unregister = registerFolder(vm, {
315
322
  get directory() {return session.directory;},
316
323
  get root() {return session.root;},
324
+ locations,
317
325
  subscribe: listener => session.subscribe(listener),
318
326
  subscribeEdits: listener => session.subscribeEdits(listener),
319
327
  unsavedPaths: () => session.unsavedPaths(),
@@ -333,19 +341,21 @@ export function mountProjectFolder({vm, document, host, locale = 'en', autoReloa
333
341
  * Creates a project folder from a snapshot. `title` names a folder made in the browser, where the user names a
334
342
  * new folder instead of picking one on the device.
335
343
  */
336
- createFromSnapshot({prepareFiles, collectEdits, directory, current = () => true, title}: {
344
+ createFromSnapshot({prepareFiles, collectEdits, directory, current = () => true, title, location}: {
337
345
  prepareFiles: () => Promise<ReadonlyMap<string, Uint8Array>>;
338
346
  collectEdits?: () => Promise<void>;
339
347
  directory?: FileSystemDirectoryHandle;
340
348
  current?: () => boolean;
341
349
  title?: string;
350
+ /** Explicit destination; omitted uses the device picker when available. */
351
+ location?: ProjectFolderLocation;
342
352
  }) {
343
353
  const message = locale.startsWith('ja') ?
344
354
  '指定されたフォルダは空ではありません。フォルダに保存されている内容が上書きされる場合があります。よろしいですか?' :
345
355
  'The selected folder is not empty. Contents in the folder may be overwritten. Continue?';
346
356
  return session.createFromSnapshot(async () => {
347
357
  try {
348
- const selected = directory ?? await pickNewDirectory({id: 'turbowarp-plus-project-folder', mode: 'readwrite'}, title);
358
+ const selected = directory ?? await pickNewDirectory({id: 'turbowarp-plus-project-folder', mode: 'readwrite'}, title, location);
349
359
  if (!current()) return null;
350
360
  const overwrite = !await isProjectFolderEmpty(selected);
351
361
  if (!current() || (overwrite && !view.confirm(message))) return null;