@kubohiroya/turbowarp-plus-editor-project-folder 0.19.0 → 0.20.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
@@ -113,6 +113,8 @@ TurboWarp Plus Editor は、ブロックパレットの設定を画面状態(`
113
113
 
114
114
  この OPFS 対応は、ローカル連携の URL から開いた Editor の保存領域が対象です。通常の配信サイトとローカル連携では OPFS の保存領域が異なるため、配信サイトで既に作業している OPFS を直接共有しません。通常の配信サイトを開いたまま外部編集するための別オリジン接続は、この実装には含みません。
115
115
 
116
+ 通常表示で内容の高さが表示領域より小さいときは、スクロール領域の上に操作ボタンの高さに合わせた空欄を設け、先頭行がボタンに隠れないようにします。内容の編集、画面サイズの変更、タブの再表示に応じて再計算します。差分表示にも、操作ボタンが差分や表示範囲の切り替えに重ならない空欄を設けています。
117
+
116
118
  編集画面の右下には、ファイル全体と現在の表示範囲を示すミニマップを表示します。クリック・ドラッグで移動でき、ミニマップにフォーカスすると矢印・Page Up/Page Down・Home/End キーでもスクロールできます。編集、スクロール、パネルのサイズ変更、タブの再表示に追従します。差分表示では編集用のミニマップを隠します。
117
119
 
118
120
  切り戻す場合はこの UI 変更を revert し、パッケージと Editor を再ビルドします。ファイル形式の変更やデータ移行はありません。対象のヘッドレス検証は `node --test test/text-file.browser.js` で実行します。
@@ -11,8 +11,8 @@ export interface BrowserProject {
11
11
  id: string;
12
12
  title: string;
13
13
  /**
14
- * A folder inside the stored folder, `''` for the stored folder itself. Only for compatibility: the Editor opens the
15
- * project at the root of the stored folder, so an entry with another path is not a project folder there.
14
+ * A folder inside the stored folder, `''` for the stored folder itself. Only for entries kept by an earlier version:
15
+ * the Editor opens the project at the root of the stored folder, and `moveProjectToRoot` moves such a project there.
16
16
  */
17
17
  projectPath: string;
18
18
  createdAt: number;
@@ -35,6 +35,12 @@ export interface BrowserProjects {
35
35
  root(id: string): Promise<FileSystemDirectoryHandle | null>;
36
36
  /** The folder `projectPath` inside the entry's stored folder. Opening uses `root` instead. */
37
37
  directory(id: string): Promise<FileSystemDirectoryHandle | null>;
38
+ /**
39
+ * Moves the project of an entry kept by an earlier version, in the folder `projectPath`, to the root of the stored
40
+ * folder, where the Editor opens it, and records that. Nothing moves when a name in that folder is already taken
41
+ * at the root. Resolves with whether the project is at the root.
42
+ */
43
+ moveProjectToRoot(id: string): Promise<boolean>;
38
44
  /** The entry that holds `handle`, or `null` when it is not in the browser's storage. */
39
45
  find(handle: FileSystemHandle): Promise<BrowserProject | null>;
40
46
  touch(id: string): Promise<void>;
package/dist/explorer.js CHANGED
@@ -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-DkIVN2xk.js")]);
1466
+ const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-CeJrx6Ve.js")]);
1467
1467
  if (disposed) return;
1468
1468
  const content = decodeText(bytes);
1469
1469
  if (content === null) {
package/dist/index.js CHANGED
@@ -1041,6 +1041,40 @@ async function writeText(directory, name, text) {
1041
1041
  throw error;
1042
1042
  }
1043
1043
  }
1044
+ var manifestFiles = ["project.source.json", "sb3-source.json"];
1045
+ async function copyEntry(entry, target) {
1046
+ if (entry.kind === "file") {
1047
+ const file = await entry.getFile();
1048
+ const writable = await (await target.getFileHandle(entry.name, { create: true })).createWritable();
1049
+ try {
1050
+ await writable.write(file);
1051
+ await writable.close();
1052
+ } catch (error) {
1053
+ await writable.abort().catch(() => {});
1054
+ throw error;
1055
+ }
1056
+ return;
1057
+ }
1058
+ const directory = await target.getDirectoryHandle(entry.name, { create: true });
1059
+ var _iteratorAbruptCompletion = false;
1060
+ var _didIteratorError = false;
1061
+ var _iteratorError;
1062
+ try {
1063
+ for (var _iterator = _asyncIterator(entry.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
1064
+ const child = _step.value;
1065
+ await copyEntry(child, directory);
1066
+ }
1067
+ } catch (err) {
1068
+ _didIteratorError = true;
1069
+ _iteratorError = err;
1070
+ } finally {
1071
+ try {
1072
+ if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
1073
+ } finally {
1074
+ if (_didIteratorError) throw _iteratorError;
1075
+ }
1076
+ }
1077
+ }
1044
1078
  async function resolvePath(root, path) {
1045
1079
  let directory = root;
1046
1080
  for (const part of path ? path.split("/") : []) directory = await directory.getDirectoryHandle(part);
@@ -1101,12 +1135,12 @@ function openBrowserProjects(view) {
1101
1135
  async list() {
1102
1136
  const { info } = await folders();
1103
1137
  const found = [];
1104
- var _iteratorAbruptCompletion = false;
1105
- var _didIteratorError = false;
1106
- var _iteratorError;
1138
+ var _iteratorAbruptCompletion2 = false;
1139
+ var _didIteratorError2 = false;
1140
+ var _iteratorError2;
1107
1141
  try {
1108
- for (var _iterator = _asyncIterator(info.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
1109
- const entry = _step.value;
1142
+ for (var _iterator2 = _asyncIterator(info.values()), _step2; _iteratorAbruptCompletion2 = !(_step2 = await _iterator2.next()).done; _iteratorAbruptCompletion2 = false) {
1143
+ const entry = _step2.value;
1110
1144
  {
1111
1145
  const id = entry.kind === "file" && entry.name.endsWith(".json") ? entry.name.slice(0, -5) : "";
1112
1146
  if (!idPattern.test(id)) continue;
@@ -1115,13 +1149,13 @@ function openBrowserProjects(view) {
1115
1149
  }
1116
1150
  }
1117
1151
  } catch (err) {
1118
- _didIteratorError = true;
1119
- _iteratorError = err;
1152
+ _didIteratorError2 = true;
1153
+ _iteratorError2 = err;
1120
1154
  } finally {
1121
1155
  try {
1122
- if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
1156
+ if (_iteratorAbruptCompletion2 && _iterator2.return != null) await _iterator2.return();
1123
1157
  } finally {
1124
- if (_didIteratorError) throw _iteratorError;
1158
+ if (_didIteratorError2) throw _iteratorError2;
1125
1159
  }
1126
1160
  }
1127
1161
  return found.sort((a, b) => b.updatedAt - a.updatedAt || a.title.localeCompare(b.title));
@@ -1159,6 +1193,64 @@ function openBrowserProjects(view) {
1159
1193
  throw error;
1160
1194
  }
1161
1195
  },
1196
+ moveProjectToRoot: (id) => exclusive(id, async () => {
1197
+ const project = await readInfo(id);
1198
+ const top = project && await root(id);
1199
+ if (!project || !top) return false;
1200
+ if (!project.projectPath) return true;
1201
+ const parts = project.projectPath.split("/");
1202
+ let source;
1203
+ try {
1204
+ source = await resolvePath(top, project.projectPath);
1205
+ } catch (error) {
1206
+ if (missing(error)) return false;
1207
+ throw error;
1208
+ }
1209
+ const taken = /* @__PURE__ */ new Set();
1210
+ var _iteratorAbruptCompletion3 = false;
1211
+ var _didIteratorError3 = false;
1212
+ var _iteratorError3;
1213
+ try {
1214
+ for (var _iterator3 = _asyncIterator(top.values()), _step3; _iteratorAbruptCompletion3 = !(_step3 = await _iterator3.next()).done; _iteratorAbruptCompletion3 = false) {
1215
+ const entry = _step3.value;
1216
+ taken.add(entry.name);
1217
+ }
1218
+ } catch (err) {
1219
+ _didIteratorError3 = true;
1220
+ _iteratorError3 = err;
1221
+ } finally {
1222
+ try {
1223
+ if (_iteratorAbruptCompletion3 && _iterator3.return != null) await _iterator3.return();
1224
+ } finally {
1225
+ if (_didIteratorError3) throw _iteratorError3;
1226
+ }
1227
+ }
1228
+ const entries = [];
1229
+ var _iteratorAbruptCompletion4 = false;
1230
+ var _didIteratorError4 = false;
1231
+ var _iteratorError4;
1232
+ try {
1233
+ for (var _iterator4 = _asyncIterator(source.values()), _step4; _iteratorAbruptCompletion4 = !(_step4 = await _iterator4.next()).done; _iteratorAbruptCompletion4 = false) {
1234
+ const entry = _step4.value;
1235
+ entries.push(entry);
1236
+ }
1237
+ } catch (err) {
1238
+ _didIteratorError4 = true;
1239
+ _iteratorError4 = err;
1240
+ } finally {
1241
+ try {
1242
+ if (_iteratorAbruptCompletion4 && _iterator4.return != null) await _iterator4.return();
1243
+ } finally {
1244
+ if (_didIteratorError4) throw _iteratorError4;
1245
+ }
1246
+ }
1247
+ if (entries.some((entry) => taken.has(entry.name))) return false;
1248
+ entries.sort((a, b) => Number(manifestFiles.includes(a.name)) - Number(manifestFiles.includes(b.name)));
1249
+ for (const entry of entries) await copyEntry(entry, top);
1250
+ await (await resolvePath(top, parts.slice(0, -1).join("/"))).removeEntry(parts[parts.length - 1], { recursive: true });
1251
+ await writeInfo(_objectSpread2(_objectSpread2({}, project), {}, { projectPath: "" }));
1252
+ return true;
1253
+ }),
1162
1254
  async find(handle) {
1163
1255
  const path = await (await folders()).projects.resolve(handle).catch(() => null);
1164
1256
  return (path === null || path === void 0 ? void 0 : path.length) && idPattern.test(path[0]) ? readInfo(path[0]) : null;
@@ -1613,6 +1705,7 @@ function chooseBrowserProject({ document, projects, locale = "en", purpose, titl
1613
1705
  return element;
1614
1706
  };
1615
1707
  item.append(text, button(message.open, async () => {
1708
+ await projects.moveProjectToRoot(project.id);
1616
1709
  const directory = await projects.root(project.id);
1617
1710
  if (!directory) return render();
1618
1711
  finish({
@@ -30016,6 +30016,7 @@ max-height:40%;overflow:auto;border-radius:.3rem;background:var(--ui-primary,#ff
30016
30016
  box-sizing:border-box;max-width:calc(100% - 2rem);margin:0;padding:.65rem 1rem;border-radius:.35rem;
30017
30017
  background:#323232;color:#fff;font-size:.9em;box-shadow:0 2px 8px rgba(0,0,0,.3);pointer-events:none}
30018
30018
  .twpf-file-edit,.twpf-file-diff{flex:1;min-height:0}
30019
+ .twpf-file-edit.twpf-file-short{padding-top:var(--twpf-toolbar-height,3.25rem)}
30019
30020
  .twpf-file-diff{padding-top:var(--twpf-toolbar-height,3.25rem)}
30020
30021
  .twpf-file-edit>.cm-editor{height:100%}
30021
30022
  .twpf-text-file .cm-scroller{overflow:auto}
@@ -30292,8 +30293,10 @@ function mountTextFile(parent, options) {
30292
30293
  parent.append(shell);
30293
30294
  const toolbarObserver = browser && new browser.ResizeObserver(() => {
30294
30295
  panel.style.setProperty("--twpf-toolbar-height", `calc(${toolbar.getBoundingClientRect().height}px + 1rem)`);
30296
+ measureToolbarSpace();
30295
30297
  });
30296
30298
  toolbarObserver === null || toolbarObserver === void 0 || toolbarObserver.observe(toolbar);
30299
+ toolbarObserver === null || toolbarObserver === void 0 || toolbarObserver.observe(editPane);
30297
30300
  const editing = new Compartment();
30298
30301
  const view = new EditorView({
30299
30302
  parent: editPane,
@@ -30311,9 +30314,23 @@ function mountTextFile(parent, options) {
30311
30314
  keymap.of([...defaultKeymap, ...historyKeymap]),
30312
30315
  EditorView.updateListener.of((update) => {
30313
30316
  if (update.docChanged) updateSaveState(void 0, true);
30317
+ if (update.docChanged || update.geometryChanged) measureToolbarSpace();
30314
30318
  })
30315
30319
  ]
30316
30320
  });
30321
+ function measureToolbarSpace() {
30322
+ if (disposed || comparison) return;
30323
+ view.requestMeasure({
30324
+ key: editPane,
30325
+ read: (view) => {
30326
+ const available = editPane.clientHeight;
30327
+ return available ? view.contentHeight < available : null;
30328
+ },
30329
+ write: (short) => {
30330
+ if (!disposed && !comparison && short !== null) editPane.classList.toggle("twpf-file-short", short);
30331
+ }
30332
+ });
30333
+ }
30317
30334
  const dirty = () => !view.state.doc.eq(savedDoc);
30318
30335
  const serialize = () => bom + (newline === "\n" ? view.state.doc.toString() : view.state.doc.toString().replace(/\n/gu, newline));
30319
30336
  let wasDirty = false;
@@ -30491,6 +30508,7 @@ function mountTextFile(parent, options) {
30491
30508
  ++readVersion;
30492
30509
  baselineLoading = false;
30493
30510
  destroyDiff();
30511
+ measureToolbarSpace();
30494
30512
  }
30495
30513
  }
30496
30514
  async function loadBaseline() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-project-folder",
3
- "version": "0.19.0",
3
+ "version": "0.20.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",
@@ -222,8 +222,10 @@ export function chooseBrowserProject({document, projects, locale = 'en', purpose
222
222
  return element;
223
223
  };
224
224
  item.append(text,
225
- // The project is at the root of the stored folder, as on the device.
225
+ // The project is at the root of the stored folder, as on the device. A folder kept by an earlier
226
+ // version, with its project in project/, moves it there first.
226
227
  button(message.open, async () => {
228
+ await projects.moveProjectToRoot(project.id);
227
229
  const directory = await projects.root(project.id);
228
230
  if (!directory) return render();
229
231
  finish({project, directory});
@@ -12,8 +12,8 @@ export interface BrowserProject {
12
12
  id: string;
13
13
  title: string;
14
14
  /**
15
- * A folder inside the stored folder, `''` for the stored folder itself. Only for compatibility: the Editor opens the
16
- * project at the root of the stored folder, so an entry with another path is not a project folder there.
15
+ * A folder inside the stored folder, `''` for the stored folder itself. Only for entries kept by an earlier version:
16
+ * the Editor opens the project at the root of the stored folder, and `moveProjectToRoot` moves such a project there.
17
17
  */
18
18
  projectPath: string;
19
19
  createdAt: number;
@@ -34,6 +34,12 @@ export interface BrowserProjects {
34
34
  root(id: string): Promise<FileSystemDirectoryHandle | null>;
35
35
  /** The folder `projectPath` inside the entry's stored folder. Opening uses `root` instead. */
36
36
  directory(id: string): Promise<FileSystemDirectoryHandle | null>;
37
+ /**
38
+ * Moves the project of an entry kept by an earlier version, in the folder `projectPath`, to the root of the stored
39
+ * folder, where the Editor opens it, and records that. Nothing moves when a name in that folder is already taken
40
+ * at the root. Resolves with whether the project is at the root.
41
+ */
42
+ moveProjectToRoot(id: string): Promise<boolean>;
37
43
  /** The entry that holds `handle`, or `null` when it is not in the browser's storage. */
38
44
  find(handle: FileSystemHandle): Promise<BrowserProject | null>;
39
45
  touch(id: string): Promise<void>;
@@ -90,6 +96,26 @@ async function writeText(directory: FileSystemDirectoryHandle, name: string, tex
90
96
  }
91
97
  }
92
98
 
99
+ // The files that make a folder a project folder go last, so a copy cut short is no project folder.
100
+ const manifestFiles = ['project.source.json', 'sb3-source.json'];
101
+
102
+ async function copyEntry(entry: FileSystemHandle, target: FileSystemDirectoryHandle): Promise<void> {
103
+ if (entry.kind === 'file') {
104
+ const file = await (entry as FileSystemFileHandle).getFile();
105
+ const writable = await (await target.getFileHandle(entry.name, {create: true})).createWritable();
106
+ try {
107
+ await writable.write(file);
108
+ await writable.close();
109
+ } catch (error) {
110
+ await writable.abort().catch(() => {});
111
+ throw error;
112
+ }
113
+ return;
114
+ }
115
+ const directory = await target.getDirectoryHandle(entry.name, {create: true});
116
+ for await (const child of (entry as IterableDirectory).values()) await copyEntry(child, directory);
117
+ }
118
+
93
119
  async function resolvePath(root: FileSystemDirectoryHandle, path: string) {
94
120
  let directory = root;
95
121
  for (const part of path ? path.split('/') : []) directory = await directory.getDirectoryHandle(part);
@@ -179,6 +205,33 @@ export function openBrowserProjects(view: Window): BrowserProjects | null {
179
205
  throw error;
180
206
  }
181
207
  },
208
+ moveProjectToRoot: id => exclusive(id, async () => {
209
+ const project = await readInfo(id);
210
+ const top = project && await root(id);
211
+ if (!project || !top) return false;
212
+ if (!project.projectPath) return true;
213
+ const parts = project.projectPath.split('/');
214
+ let source: FileSystemDirectoryHandle;
215
+ try {
216
+ source = await resolvePath(top, project.projectPath);
217
+ } catch (error) {
218
+ if (missing(error)) return false;
219
+ throw error;
220
+ }
221
+ // `project/` itself is a name at the root, so a project holding a `project` entry stays where it is.
222
+ const taken = new Set<string>();
223
+ for await (const entry of (top as IterableDirectory).values()) taken.add(entry.name);
224
+ const entries: FileSystemHandle[] = [];
225
+ for await (const entry of (source as IterableDirectory).values()) entries.push(entry);
226
+ if (entries.some(entry => taken.has(entry.name))) return false;
227
+ entries.sort((a, b) => Number(manifestFiles.includes(a.name)) - Number(manifestFiles.includes(b.name)));
228
+ for (const entry of entries) await copyEntry(entry, top);
229
+ // The old folder goes only after the copy is complete.
230
+ const parent = await resolvePath(top, parts.slice(0, -1).join('/'));
231
+ await parent.removeEntry(parts[parts.length - 1], {recursive: true});
232
+ await writeInfo({...project, projectPath: ''});
233
+ return true;
234
+ }),
182
235
  async find(handle) {
183
236
  const path = await (await folders()).projects.resolve(handle).catch(() => null);
184
237
  return path?.length && idPattern.test(path[0]) ? readInfo(path[0]) : null;
@@ -95,6 +95,7 @@ max-height:40%;overflow:auto;border-radius:.3rem;background:var(--ui-primary,#ff
95
95
  box-sizing:border-box;max-width:calc(100% - 2rem);margin:0;padding:.65rem 1rem;border-radius:.35rem;
96
96
  background:#323232;color:#fff;font-size:.9em;box-shadow:0 2px 8px rgba(0,0,0,.3);pointer-events:none}
97
97
  .twpf-file-edit,.twpf-file-diff{flex:1;min-height:0}
98
+ .twpf-file-edit.twpf-file-short{padding-top:var(--twpf-toolbar-height,3.25rem)}
98
99
  .twpf-file-diff{padding-top:var(--twpf-toolbar-height,3.25rem)}
99
100
  .twpf-file-edit>.cm-editor{height:100%}
100
101
  .twpf-text-file .cm-scroller{overflow:auto}
@@ -328,8 +329,10 @@ export function mountTextFile(parent: HTMLElement, options: TextFileOptions) {
328
329
  parent.append(shell);
329
330
  const toolbarObserver = browser && new browser.ResizeObserver(() => {
330
331
  panel.style.setProperty('--twpf-toolbar-height', `calc(${toolbar.getBoundingClientRect().height}px + 1rem)`);
332
+ measureToolbarSpace();
331
333
  });
332
334
  toolbarObserver?.observe(toolbar);
335
+ toolbarObserver?.observe(editPane);
333
336
 
334
337
  const editing = new Compartment();
335
338
  const view = new EditorView({
@@ -339,9 +342,26 @@ export function mountTextFile(parent: HTMLElement, options: TextFileOptions) {
339
342
  highlightActiveLine(), textMinimap(message.minimap),
340
343
  EditorView.contentAttributes.of({'aria-label': options.path}),
341
344
  keymap.of([...defaultKeymap, ...historyKeymap]),
342
- EditorView.updateListener.of(update => {if (update.docChanged) updateSaveState(undefined, true);})
345
+ EditorView.updateListener.of(update => {
346
+ if (update.docChanged) updateSaveState(undefined, true);
347
+ if (update.docChanged || update.geometryChanged) measureToolbarSpace();
348
+ })
343
349
  ]
344
350
  });
351
+ function measureToolbarSpace() {
352
+ if (disposed || comparison) return;
353
+ view.requestMeasure({
354
+ key: editPane,
355
+ read: view => {
356
+ // Include the reserved space when comparing, so adding it cannot flip the decision back.
357
+ const available = editPane.clientHeight;
358
+ return available ? view.contentHeight < available : null;
359
+ },
360
+ write: short => {
361
+ if (!disposed && !comparison && short !== null) editPane.classList.toggle('twpf-file-short', short);
362
+ }
363
+ });
364
+ }
345
365
  const dirty = () => !view.state.doc.eq(savedDoc);
346
366
  const serialize = () => bom + (newline === '\n' ? view.state.doc.toString() : view.state.doc.toString().replace(/\n/gu, newline));
347
367
 
@@ -524,6 +544,7 @@ export function mountTextFile(parent: HTMLElement, options: TextFileOptions) {
524
544
  ++readVersion;
525
545
  baselineLoading = false;
526
546
  destroyDiff();
547
+ measureToolbarSpace();
527
548
  }
528
549
  }
529
550