@kubohiroya/turbowarp-plus-editor-project-folder 0.9.1 → 0.9.3

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/dist/explorer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as _asyncIterator, S as _objectSpread2, d as manifestFile, g as projectFile, r as FolderError, t as followProjectFolder, u as isObject } from "./shared-JdaDvk2R.js";
1
+ import { E as _asyncIterator, T as _objectSpread2, a as projectFolderOverwriteWarning, m as manifestFile, o as FolderError, p as isObject, t as followProjectFolder, y as projectFile } from "./shared-Dz9dzxQF.js";
2
2
  import * as React from "react";
3
3
  import { useEffect, useState } from "react";
4
4
  import { createPortal } from "react-dom";
@@ -1147,8 +1147,8 @@ var actionMessages = (locale = "en") => locale.toLowerCase().startsWith("ja") ?
1147
1147
  newName: "新しい名前",
1148
1148
  cancel: "キャンセル",
1149
1149
  remove: (name, folder) => folder ? `「${name}」とその中身を削除しますか?` : `「${name}」を削除しますか?`,
1150
- stage: "Git にステージ",
1151
- unstage: "Git のステージを解除",
1150
+ stage: "次のコミットに含める",
1151
+ unstage: "次のコミットから外す",
1152
1152
  working: "処理中…",
1153
1153
  copyFailed: "コピーできませんでした",
1154
1154
  filesOnly: "ファイルをドロップしてください。",
@@ -1373,7 +1373,7 @@ function createFilePreview(directory, documentId, { name, path }, locale, readBa
1373
1373
  filename: name,
1374
1374
  title: name,
1375
1375
  transient: true,
1376
- mount(element, close) {
1376
+ mount(element, close, onSaveAvailable) {
1377
1377
  const message = locale.toLowerCase().startsWith("ja") ? messages$1.ja : messages$1.en;
1378
1378
  const { ownerDocument: document } = element;
1379
1379
  const panel = document.createElement("div");
@@ -1420,7 +1420,7 @@ function createFilePreview(directory, documentId, { name, path }, locale, readBa
1420
1420
  status.textContent = message.large;
1421
1421
  return;
1422
1422
  }
1423
- const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-kI7qYraF.js")]);
1423
+ const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-BqC3-Bzi.js")]);
1424
1424
  if (disposed) return;
1425
1425
  const content = decodeText(bytes);
1426
1426
  if (content === null) {
@@ -1435,14 +1435,29 @@ function createFilePreview(directory, documentId, { name, path }, locale, readBa
1435
1435
  limit: textLimit,
1436
1436
  readHandle,
1437
1437
  close,
1438
- readBaseline: readBaseline && (() => readBaseline(directory, path, 4194304))
1438
+ readBaseline: readBaseline && (() => readBaseline(directory, path, 4194304)),
1439
+ hostSaveShortcut: Boolean(onSaveAvailable),
1440
+ onDirtyChange: onSaveAvailable
1439
1441
  });
1440
1442
  status.remove();
1443
+ onSaveAvailable === null || onSaveAvailable === void 0 || onSaveAvailable();
1441
1444
  };
1442
1445
  load().catch(() => {
1443
1446
  if (!disposed) status.textContent = message.failed;
1444
1447
  });
1445
1448
  return {
1449
+ get save() {
1450
+ return textSession === null || textSession === void 0 ? void 0 : textSession.save;
1451
+ },
1452
+ get fileEdit() {
1453
+ return textSession && {
1454
+ directory,
1455
+ path,
1456
+ isDirty: textSession.isDirty,
1457
+ readUnsaved: textSession.readUnsaved,
1458
+ save: textSession.save
1459
+ };
1460
+ },
1446
1461
  requestClose() {
1447
1462
  if (textSession) textSession.requestClose();
1448
1463
  else close();
@@ -1464,20 +1479,25 @@ var messages = {
1464
1479
  label: "Project folder",
1465
1480
  loading: "Loading…",
1466
1481
  empty: "This folder is empty.",
1482
+ noMatches: "No matching files.",
1483
+ results: "Matching files",
1467
1484
  noFolder: "Open a project folder to show its files here.",
1468
1485
  open: "Open Project Folder…",
1486
+ create: "Create Project Folder",
1487
+ creating: "Creating project folder…",
1488
+ createFailed: "Could not create the project folder.",
1469
1489
  unavailable: "File tabs are unavailable in this editor layout.",
1470
1490
  failed: "This folder could not be read.",
1471
1491
  denied: "Permission to read this folder was not granted.",
1472
1492
  separator: ", ",
1473
1493
  marks: {
1474
- added: "Added",
1475
- modified: "Modified",
1494
+ added: "New file",
1495
+ modified: "Saved, not committed",
1476
1496
  deleted: "Deleted",
1477
1497
  untracked: "Untracked"
1478
1498
  },
1479
1499
  unsaved: "Unsaved changes",
1480
- staged: "Staged",
1500
+ staged: "Added to Git index",
1481
1501
  revisions: {
1482
1502
  committed: "Committed",
1483
1503
  pushed: "Pushed",
@@ -1497,20 +1517,25 @@ var messages = {
1497
1517
  label: "作品フォルダ",
1498
1518
  loading: "読み込んでいます…",
1499
1519
  empty: "このフォルダは空です。",
1520
+ noMatches: "該当するファイルはありません。",
1521
+ results: "検索結果",
1500
1522
  noFolder: "プロジェクトフォルダを開くと、ここにファイルを表示します。",
1501
1523
  open: "プロジェクトフォルダを開く…",
1524
+ create: "プロジェクトフォルダを作成",
1525
+ creating: "プロジェクトフォルダを作成しています…",
1526
+ createFailed: "プロジェクトフォルダを作成できませんでした。",
1502
1527
  unavailable: "このエディターのレイアウトではファイルをタブで開けません。",
1503
1528
  failed: "このフォルダを読み込めません。",
1504
1529
  denied: "このフォルダを読む許可がありません。",
1505
1530
  separator: "、",
1506
1531
  marks: {
1507
- added: "追加",
1508
- modified: "変更",
1532
+ added: "新しいファイル",
1533
+ modified: "保存済・未コミットの変更",
1509
1534
  deleted: "削除",
1510
1535
  untracked: "未追跡"
1511
1536
  },
1512
1537
  unsaved: "未保存の変更あり",
1513
- staged: "ステージ済み",
1538
+ staged: "Git のインデックスに追加済み",
1514
1539
  revisions: {
1515
1540
  committed: "コミット済み",
1516
1541
  pushed: "プッシュ済み",
@@ -1575,8 +1600,13 @@ var failure = (error, message) => error instanceof DOMException && (error.name =
1575
1600
  var prefix = "twpf-explorer";
1576
1601
  var entryDragType = "application/x-twpf-explorer-entry";
1577
1602
  var css = `.${prefix}{font:inherit;color:inherit}
1578
- .${prefix}-item{display:flex;align-items:center;gap:.4em;width:100%;box-sizing:border-box;margin:0;border:0;border-radius:3px;
1603
+ .${prefix}-item{display:grid;grid-template-columns:1em 20px minmax(0,1fr);align-items:center;gap:.2em .4em;
1604
+ width:100%;box-sizing:border-box;margin:0;border:0;border-radius:3px;
1579
1605
  padding-block:.15em;padding-inline-end:.4em;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer;white-space:nowrap}
1606
+ .${prefix}-search-result{display:block;width:100%;text-align:start;color:inherit;font:inherit;background:transparent;
1607
+ border:0;border-radius:3px;padding:.35em .5em;overflow-wrap:anywhere;cursor:pointer}
1608
+ .${prefix}-search-result:hover{background:rgba(128,128,128,.12)}
1609
+ .${prefix}-search-result:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
1580
1610
  .${prefix}-item:hover{background:rgba(128,128,128,.12)}
1581
1611
  .${prefix}-item[aria-selected="true"]{background:rgba(128,128,128,.24)}
1582
1612
  .${prefix}-item:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
@@ -1585,15 +1615,20 @@ padding-block:.15em;padding-inline-end:.4em;background:none;color:inherit;font:i
1585
1615
  .${prefix}-icon img{width:20px;height:20px;object-fit:contain;border-radius:2px;
1586
1616
  background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50%) 0 0/8px 8px}
1587
1617
  .${prefix}-icon img[hidden]{display:none}
1618
+ .${prefix}-label{grid-column:3;display:flex;align-items:center;gap:.4em;min-width:0}
1588
1619
  .${prefix}-filename{display:inline-flex;min-width:0}
1589
1620
  .${prefix}-name{overflow:hidden;text-overflow:ellipsis}
1590
- .${prefix}-item[data-staged] .${prefix}-filename{font-weight:700}
1591
- .${prefix}-item[data-revision="committed"] .${prefix}-filename{color:#174b9d;color:light-dark(#174b9d,#91c1ff)}
1592
- .${prefix}-item[data-revision="pushed"] .${prefix}-filename{color:#67369a;color:light-dark(#67369a,#dfafff)}
1593
- .${prefix}-item[data-revision="merged"] .${prefix}-filename{color:#17603e;color:light-dark(#17603e,#85e3ad)}
1594
- .${prefix}-unsaved{flex:none}
1595
- .${prefix}-mark{flex:none;font-size:.85em;padding:0 .3em;border:1px solid currentColor;border-radius:3px;opacity:.85}
1596
- .${prefix}-description{overflow:hidden;text-overflow:ellipsis;opacity:.7;font-size:.9em}
1621
+ .${prefix}-marker{flex:none;white-space:pre}
1622
+ .${prefix}-item[data-staged] .${prefix}-name, .${prefix}-search-result[data-staged] .${prefix}-name,
1623
+ .${prefix}-name[data-git-change="modified"], .${prefix}-name[data-git-change="added"]{font-weight:700}
1624
+ .${prefix}-name[data-revision="committed"]{color:#174b9d;color:light-dark(#174b9d,#91c1ff)}
1625
+ .${prefix}-name[data-revision="pushed"]{color:#67369a;color:light-dark(#67369a,#dfafff)}
1626
+ .${prefix}-name[data-revision="merged"]{color:#17603e;color:light-dark(#17603e,#85e3ad)}
1627
+ .${prefix}-name[data-git-change="deleted"]{text-decoration:line-through}
1628
+ .${prefix}-item[aria-disabled="true"], .${prefix}-search-result:disabled{cursor:default}
1629
+ .${prefix}-description{grid-column:3;min-width:0;padding:.2em .4em;border-radius:3px;background:rgba(128,128,128,.12);
1630
+ color:inherit;color:color-mix(in srgb,currentColor 78%,transparent);font-size:.75em;line-height:1.4;
1631
+ white-space:normal;overflow-wrap:anywhere}
1597
1632
  .${prefix}-status{opacity:.7;font-style:italic;padding-block:.15em}
1598
1633
  .${prefix}-empty{padding:.5em}
1599
1634
  .${prefix}-empty p{margin:0 0 .6em}
@@ -1723,6 +1758,142 @@ function Icon({ kind, path, readFile }) {
1723
1758
  onError: () => setState("failed")
1724
1759
  }) : null);
1725
1760
  }
1761
+ function FileStatusMarkers({ unsaved, change }) {
1762
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, unsaved && /* @__PURE__ */ React.createElement("span", {
1763
+ className: `${prefix}-marker`,
1764
+ "data-tw-plus-unsaved-marker": true,
1765
+ "aria-hidden": "true"
1766
+ }, " *"), change === "untracked" && /* @__PURE__ */ React.createElement("span", {
1767
+ className: `${prefix}-marker`,
1768
+ "aria-hidden": "true"
1769
+ }, " ✨"));
1770
+ }
1771
+ function fileStatusLabels(message, unsaved, status, change) {
1772
+ return [
1773
+ unsaved && message.unsaved,
1774
+ (status === null || status === void 0 ? void 0 : status.staged) && message.staged,
1775
+ (status === null || status === void 0 ? void 0 : status.revision) && message.revisions[status.revision],
1776
+ change && message.marks[change]
1777
+ ];
1778
+ }
1779
+ function deletedPaths(fileStatuses, marks) {
1780
+ const paths = /* @__PURE__ */ new Set();
1781
+ for (const [path, mark] of marks !== null && marks !== void 0 ? marks : []) if (mark === "deleted") paths.add(path);
1782
+ for (const [path, status] of fileStatuses !== null && fileStatuses !== void 0 ? fileStatuses : []) if (status.change === "deleted") paths.add(path);
1783
+ else paths.delete(path);
1784
+ return paths;
1785
+ }
1786
+ function deletedChildren(paths) {
1787
+ const folders = /* @__PURE__ */ new Map();
1788
+ for (const path of paths) {
1789
+ const parts = path.split("/");
1790
+ let parent = rootId;
1791
+ for (const [index, name] of parts.entries()) {
1792
+ const child = parent === rootId ? name : parent + "/" + name;
1793
+ const kind = index === parts.length - 1 ? "file" : "directory";
1794
+ let children = folders.get(parent);
1795
+ if (!children) folders.set(parent, children = /* @__PURE__ */ new Map());
1796
+ children.set(child, {
1797
+ name,
1798
+ path: child,
1799
+ kind,
1800
+ deleted: true
1801
+ });
1802
+ parent = child;
1803
+ }
1804
+ }
1805
+ return folders;
1806
+ }
1807
+ function FileSearch({ directory, query, locale, refreshKey, marks, fileStatuses, unsavedPaths, onOpen }) {
1808
+ const message = messagesFor(locale);
1809
+ const [index, setIndex] = React.useState();
1810
+ React.useEffect(() => {
1811
+ let current = true;
1812
+ setIndex(void 0);
1813
+ const files = [];
1814
+ let failed = false;
1815
+ const walk = async (folder, base) => {
1816
+ try {
1817
+ var _iteratorAbruptCompletion = false;
1818
+ var _didIteratorError = false;
1819
+ var _iteratorError;
1820
+ try {
1821
+ for (var _iterator = _asyncIterator(folder.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
1822
+ const entry = _step.value;
1823
+ {
1824
+ if (!current) return;
1825
+ if (entry.name.toLowerCase() === ".git") continue;
1826
+ const path = base + entry.name;
1827
+ if (entry.kind === "directory") await walk(entry, path + "/");
1828
+ else files.push({
1829
+ path,
1830
+ name: entry.name,
1831
+ kind: "file"
1832
+ });
1833
+ }
1834
+ }
1835
+ } catch (err) {
1836
+ _didIteratorError = true;
1837
+ _iteratorError = err;
1838
+ } finally {
1839
+ try {
1840
+ if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
1841
+ } finally {
1842
+ if (_didIteratorError) throw _iteratorError;
1843
+ }
1844
+ }
1845
+ } catch (_unused2) {
1846
+ failed = true;
1847
+ }
1848
+ };
1849
+ walk(directory, "").then(() => {
1850
+ if (current) setIndex({
1851
+ files,
1852
+ failed
1853
+ });
1854
+ });
1855
+ return () => {
1856
+ current = false;
1857
+ };
1858
+ }, [directory, refreshKey]);
1859
+ const paths = deletedPaths(fileStatuses, marks);
1860
+ const files = new Map(index === null || index === void 0 ? void 0 : index.files.map((entry) => [entry.path, entry]));
1861
+ for (const path of paths) if (!files.has(path)) files.set(path, {
1862
+ name: path.split("/").pop(),
1863
+ path,
1864
+ kind: "file"
1865
+ });
1866
+ const matches = [...files.values()].filter((entry) => entry.path.toLowerCase().includes(query)).sort((a, b) => a.path.localeCompare(b.path, locale, { numeric: true }));
1867
+ return /* @__PURE__ */ React.createElement("div", {
1868
+ className: prefix,
1869
+ role: "group",
1870
+ "aria-label": message.results
1871
+ }, matches === null || matches === void 0 ? void 0 : matches.map((entry) => {
1872
+ var _status$change;
1873
+ const unsaved = unsavedPaths === null || unsavedPaths === void 0 ? void 0 : unsavedPaths.has(entry.path);
1874
+ const status = fileStatuses === null || fileStatuses === void 0 ? void 0 : fileStatuses.get(entry.path);
1875
+ const change = (_status$change = status === null || status === void 0 ? void 0 : status.change) !== null && _status$change !== void 0 ? _status$change : marks === null || marks === void 0 ? void 0 : marks.get(entry.path);
1876
+ const accessibleName = [entry.path, ...fileStatusLabels(message, unsaved, status, change)].filter(Boolean).join(message.separator);
1877
+ return /* @__PURE__ */ React.createElement("button", {
1878
+ key: entry.path,
1879
+ type: "button",
1880
+ className: `${prefix}-search-result`,
1881
+ "aria-label": accessibleName,
1882
+ title: accessibleName,
1883
+ "data-staged": (status === null || status === void 0 ? void 0 : status.staged) ? "" : void 0,
1884
+ "data-revision": status === null || status === void 0 ? void 0 : status.revision,
1885
+ disabled: paths.has(entry.path),
1886
+ onClick: () => onOpen === null || onOpen === void 0 ? void 0 : onOpen(entry)
1887
+ }, /* @__PURE__ */ React.createElement("span", {
1888
+ className: `${prefix}-name`,
1889
+ "data-git-change": change,
1890
+ "data-revision": status === null || status === void 0 ? void 0 : status.revision
1891
+ }, entry.path), /* @__PURE__ */ React.createElement(FileStatusMarkers, {
1892
+ unsaved,
1893
+ change
1894
+ }));
1895
+ }), !index ? /* @__PURE__ */ React.createElement("p", { role: "status" }, message.loading) : index.failed ? /* @__PURE__ */ React.createElement("p", { role: "status" }, message.failed) : !(matches === null || matches === void 0 ? void 0 : matches.length) && /* @__PURE__ */ React.createElement("p", { role: "status" }, message.noMatches));
1896
+ }
1726
1897
  function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsavedPaths, refreshKey, onOpen, label, mutate, git, isCurrent }) {
1727
1898
  const message = messagesFor(locale);
1728
1899
  const actions = actionMessages(locale);
@@ -1765,6 +1936,8 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1765
1936
  }
1766
1937
  return handle.getFile();
1767
1938
  };
1939
+ const deleted = React.useMemo(() => deletedChildren(deletedPaths(fileStatuses, marks)), [fileStatuses, marks]);
1940
+ const compareNodes = (a, b) => (a.kind === "directory" ? 0 : 1) - (b.kind === "directory" ? 0 : 1) || collator.compare(a.name, b.name) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
1768
1941
  const tree = useTree({
1769
1942
  rootItemId: rootId,
1770
1943
  initialState: {
@@ -1786,8 +1959,9 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1786
1959
  kind: "file"
1787
1960
  }),
1788
1961
  onPrimaryAction: (item) => {
1962
+ var _fileStatuses$get$cha, _fileStatuses$get;
1789
1963
  const data = item.getItemData();
1790
- if ((data === null || data === void 0 ? void 0 : data.kind) === "file") onOpen === null || onOpen === void 0 || onOpen({
1964
+ if ((data === null || data === void 0 ? void 0 : data.kind) === "file" && !data.deleted && ((_fileStatuses$get$cha = fileStatuses === null || fileStatuses === void 0 || (_fileStatuses$get = fileStatuses.get(data.path)) === null || _fileStatuses$get === void 0 ? void 0 : _fileStatuses$get.change) !== null && _fileStatuses$get$cha !== void 0 ? _fileStatuses$get$cha : marks === null || marks === void 0 ? void 0 : marks.get(data.path)) !== "deleted") onOpen === null || onOpen === void 0 || onOpen({
1791
1965
  path: data.path,
1792
1966
  name: data.name,
1793
1967
  kind: "file"
@@ -1813,7 +1987,7 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1813
1987
  path: id,
1814
1988
  kind: "directory"
1815
1989
  };
1816
- } catch (_unused2) {
1990
+ } catch (_unused3) {
1817
1991
  await parent.getFileHandle(name);
1818
1992
  return {
1819
1993
  name,
@@ -1823,22 +1997,23 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1823
1997
  }
1824
1998
  },
1825
1999
  getChildrenWithData: async (id) => {
2000
+ const base = id === rootId ? "" : `${id}/`;
2001
+ const missingChildren = deleted.get(id);
2002
+ const nodes = new Map(missingChildren);
1826
2003
  try {
1827
2004
  const handle = await directoryAt(id);
1828
- const base = id === rootId ? "" : `${id}/`;
1829
- const nodes = [];
1830
- var _iteratorAbruptCompletion = false;
1831
- var _didIteratorError = false;
1832
- var _iteratorError;
2005
+ var _iteratorAbruptCompletion2 = false;
2006
+ var _didIteratorError2 = false;
2007
+ var _iteratorError2;
1833
2008
  try {
1834
- for (var _iterator = _asyncIterator(handle.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
1835
- const entry = _step.value;
2009
+ for (var _iterator2 = _asyncIterator(handle.values()), _step2; _iteratorAbruptCompletion2 = !(_step2 = await _iterator2.next()).done; _iteratorAbruptCompletion2 = false) {
2010
+ const entry = _step2.value;
1836
2011
  {
1837
2012
  if (entry.name.toLowerCase() === ".git") continue;
1838
2013
  const path = base + entry.name;
1839
2014
  if (entry.kind === "directory") handles.set(path, entry);
1840
2015
  else files.set(path, entry);
1841
- nodes.push({
2016
+ nodes.set(path, {
1842
2017
  name: entry.name,
1843
2018
  path,
1844
2019
  kind: entry.kind
@@ -1846,23 +2021,17 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1846
2021
  }
1847
2022
  }
1848
2023
  } catch (err) {
1849
- _didIteratorError = true;
1850
- _iteratorError = err;
2024
+ _didIteratorError2 = true;
2025
+ _iteratorError2 = err;
1851
2026
  } finally {
1852
2027
  try {
1853
- if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
2028
+ if (_iteratorAbruptCompletion2 && _iterator2.return != null) await _iterator2.return();
1854
2029
  } finally {
1855
- if (_didIteratorError) throw _iteratorError;
2030
+ if (_didIteratorError2) throw _iteratorError2;
1856
2031
  }
1857
2032
  }
1858
- loadedFolders.add(id);
1859
- nodes.sort((a, b) => (a.kind === "directory" ? 0 : 1) - (b.kind === "directory" ? 0 : 1) || collator.compare(a.name, b.name) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
1860
- return nodes.map((data) => ({
1861
- id: data.path,
1862
- data
1863
- }));
1864
2033
  } catch (error) {
1865
- return [{
2034
+ if (!missingChildren || error.name !== "NotFoundError") return [{
1866
2035
  id: errorId(id),
1867
2036
  data: {
1868
2037
  name: failure(error, message),
@@ -1871,6 +2040,11 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1871
2040
  }
1872
2041
  }];
1873
2042
  }
2043
+ loadedFolders.add(id);
2044
+ return [...nodes.values()].sort(compareNodes).map((data) => ({
2045
+ id: data.path,
2046
+ data
2047
+ }));
1874
2048
  }
1875
2049
  },
1876
2050
  features: [
@@ -1883,15 +2057,31 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1883
2057
  tree.setMounted(true);
1884
2058
  return () => tree.setMounted(false);
1885
2059
  }, [tree]);
1886
- const lastRefresh = React.useRef(refreshKey);
2060
+ const lastRefresh = React.useRef({
2061
+ refreshKey,
2062
+ deleted
2063
+ });
1887
2064
  React.useEffect(() => {
1888
- if (lastRefresh.current === refreshKey) return;
1889
- lastRefresh.current = refreshKey;
1890
- Promise.all([...loadedFolders].map((id) => tree.getItemInstance(id).invalidateChildrenIds(true)));
2065
+ const previous = lastRefresh.current;
2066
+ lastRefresh.current = {
2067
+ refreshKey,
2068
+ deleted
2069
+ };
2070
+ const affected = [...loadedFolders].filter((id) => {
2071
+ if (previous.refreshKey !== refreshKey) return true;
2072
+ const before = previous.deleted.get(id);
2073
+ const after = deleted.get(id);
2074
+ return (before === null || before === void 0 ? void 0 : before.size) !== (after === null || after === void 0 ? void 0 : after.size) || [...after !== null && after !== void 0 ? after : []].some(([path, node]) => {
2075
+ var _before$get;
2076
+ return (before === null || before === void 0 || (_before$get = before.get(path)) === null || _before$get === void 0 ? void 0 : _before$get.kind) !== node.kind;
2077
+ });
2078
+ });
2079
+ Promise.all(affected.map((id) => tree.getItemInstance(id).invalidateChildrenIds(true)));
1891
2080
  }, [
1892
2081
  tree,
1893
2082
  loadedFolders,
1894
- refreshKey
2083
+ refreshKey,
2084
+ deleted
1895
2085
  ]);
1896
2086
  const errorText = (error) => {
1897
2087
  if (error instanceof ExplorerFileError) return actions[error.code];
@@ -1979,7 +2169,7 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1979
2169
  Promise.all(candidates.filter((path) => canMoveExplorerEntry(entry.path, path)).map(async (path) => {
1980
2170
  try {
1981
2171
  return await explorerNameAvailable(await directoryAt(path || rootId), entry.name) ? path : null;
1982
- } catch (_unused3) {
2172
+ } catch (_unused4) {
1983
2173
  return null;
1984
2174
  }
1985
2175
  })).then((paths) => {
@@ -2096,29 +2286,25 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2096
2286
  });
2097
2287
  };
2098
2288
  const renderItem = (item) => {
2099
- var _status$change;
2289
+ var _status$change2;
2100
2290
  const data = item.getItemData();
2101
- const entry = (data === null || data === void 0 ? void 0 : data.path) && data.kind !== "error" ? {
2102
- path: data.path,
2103
- name: data.name,
2104
- kind: data.kind
2105
- } : void 0;
2106
2291
  const itemProps = item.getProps();
2107
2292
  const level = item.getItemMeta().level;
2108
2293
  const folder = item.isFolder();
2109
2294
  const expanded = folder && item.isExpanded();
2110
2295
  const status = (data === null || data === void 0 ? void 0 : data.kind) === "file" ? fileStatuses === null || fileStatuses === void 0 ? void 0 : fileStatuses.get(data.path) : void 0;
2111
2296
  const unsaved = (data === null || data === void 0 ? void 0 : data.kind) === "file" && (unsavedPaths === null || unsavedPaths === void 0 ? void 0 : unsavedPaths.has(data.path));
2112
- const mark = (_status$change = status === null || status === void 0 ? void 0 : status.change) !== null && _status$change !== void 0 ? _status$change : data && data.kind !== "error" ? marks === null || marks === void 0 ? void 0 : marks.get(data.path) : void 0;
2113
- const markLabel = mark ? message.marks[mark] : "";
2297
+ const change = (data === null || data === void 0 ? void 0 : data.deleted) ? "deleted" : (_status$change2 = status === null || status === void 0 ? void 0 : status.change) !== null && _status$change2 !== void 0 ? _status$change2 : (data === null || data === void 0 ? void 0 : data.kind) === "file" ? marks === null || marks === void 0 ? void 0 : marks.get(data.path) : void 0;
2298
+ const entry = (data === null || data === void 0 ? void 0 : data.path) && data.kind !== "error" && change !== "deleted" ? {
2299
+ path: data.path,
2300
+ name: data.name,
2301
+ kind: data.kind
2302
+ } : void 0;
2114
2303
  const description = data && data.kind !== "error" ? descriptions === null || descriptions === void 0 ? void 0 : descriptions.get(data.path) : void 0;
2115
2304
  const icon = !data || data.kind === "error" ? void 0 : folder ? expanded ? "folder-open" : "folder" : iconFor(data.name);
2116
2305
  const accessibleName = [
2117
2306
  item.getItemName(),
2118
- unsaved && message.unsaved,
2119
- (status === null || status === void 0 ? void 0 : status.staged) && message.staged,
2120
- (status === null || status === void 0 ? void 0 : status.revision) && message.revisions[status.revision],
2121
- markLabel,
2307
+ ...fileStatusLabels(message, unsaved, status, change),
2122
2308
  description
2123
2309
  ].filter(Boolean).join(message.separator);
2124
2310
  const moveDestination = (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" && (move === null || move === void 0 ? void 0 : move.destinations.has(entry.path));
@@ -2132,7 +2318,8 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2132
2318
  "data-path": data === null || data === void 0 ? void 0 : data.path,
2133
2319
  "data-staged": (status === null || status === void 0 ? void 0 : status.staged) ? "" : void 0,
2134
2320
  "data-revision": status === null || status === void 0 ? void 0 : status.revision,
2135
- title: unsaved || (status === null || status === void 0 ? void 0 : status.staged) || (status === null || status === void 0 ? void 0 : status.revision) ? accessibleName : void 0,
2321
+ "aria-disabled": change === "deleted" && !folder ? true : void 0,
2322
+ title: accessibleName || void 0,
2136
2323
  "data-drop-directory": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" ? entry.path : entry ? parentPath(entry.path) : void 0,
2137
2324
  "data-drop-active": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" && drag === entry.path ? "" : void 0,
2138
2325
  "data-move-directory": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" ? entry.path : void 0,
@@ -2154,14 +2341,15 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2154
2341
  }, folder ? expanded ? "▾" : "▸" : ""), icon ? /* @__PURE__ */ React.createElement(Icon, {
2155
2342
  kind: icon,
2156
2343
  path: data.path,
2157
- readFile: icon === "image" ? readFile : void 0
2158
- }) : null, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-filename` }, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-name` }, item.getItemName()), unsaved ? /* @__PURE__ */ React.createElement("span", {
2159
- className: `${prefix}-unsaved`,
2160
- "aria-hidden": "true"
2161
- }, "*") : null), markLabel ? /* @__PURE__ */ React.createElement("span", {
2162
- className: `${prefix}-mark`,
2163
- "aria-hidden": "true"
2164
- }, markLabel) : null, description ? /* @__PURE__ */ React.createElement("span", {
2344
+ readFile: icon === "image" && change !== "deleted" ? readFile : void 0
2345
+ }) : null, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-label` }, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-filename` }, /* @__PURE__ */ React.createElement("span", {
2346
+ className: `${prefix}-name`,
2347
+ "data-git-change": change,
2348
+ "data-revision": status === null || status === void 0 ? void 0 : status.revision
2349
+ }, item.getItemName()), /* @__PURE__ */ React.createElement(FileStatusMarkers, {
2350
+ unsaved,
2351
+ change
2352
+ }))), description ? /* @__PURE__ */ React.createElement("span", {
2165
2353
  className: `${prefix}-description`,
2166
2354
  "aria-hidden": "true"
2167
2355
  }, description) : null)];
@@ -2261,11 +2449,27 @@ var keyFor = (directory) => {
2261
2449
  * file. Needs React 16.14–18 from the host.
2262
2450
  */
2263
2451
  function ProjectFolderExplorer(props) {
2264
- return /* @__PURE__ */ React.createElement(Explorer, _objectSpread2({ key: keyFor(props.directory) }, props));
2452
+ var _props$query;
2453
+ const query = (_props$query = props.query) === null || _props$query === void 0 ? void 0 : _props$query.trim().toLowerCase();
2454
+ return /* @__PURE__ */ React.createElement(React.Fragment, { key: keyFor(props.directory) }, /* @__PURE__ */ React.createElement("div", { hidden: Boolean(query) }, /* @__PURE__ */ React.createElement(Explorer, props)), query && /* @__PURE__ */ React.createElement(FileSearch, _objectSpread2(_objectSpread2({}, props), {}, { query })));
2265
2455
  }
2266
2456
  var readJson = async (directory, name) => JSON.parse(await (await (await directory.getFileHandle(name)).getFile()).text());
2267
- function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: followStatuses, git: followGit, openFile, readBaseline }) {
2457
+ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: followStatuses, git: followGit, openFile, readBaseline, query, followFileEdits, createFolder }) {
2268
2458
  const message = messagesFor(locale);
2459
+ const [creating, setCreating] = React.useState(false);
2460
+ const [createError, setCreateError] = React.useState("");
2461
+ const create = async () => {
2462
+ if (!createFolder || creating) return;
2463
+ setCreating(true);
2464
+ setCreateError("");
2465
+ try {
2466
+ await createFolder();
2467
+ } catch (_unused5) {
2468
+ setCreateError(message.createFailed);
2469
+ } finally {
2470
+ setCreating(false);
2471
+ }
2472
+ };
2269
2473
  const [{ folder, directory, version }, setFollowed] = React.useState({
2270
2474
  directory: null,
2271
2475
  version: 0
@@ -2332,6 +2536,14 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2332
2536
  directory,
2333
2537
  version
2334
2538
  ]);
2539
+ const [fileEdits, setFileEdits] = React.useState();
2540
+ React.useEffect(() => {
2541
+ if (!directory || !followFileEdits) return;
2542
+ return followFileEdits(directory, (paths) => setFileEdits({
2543
+ directory,
2544
+ paths
2545
+ }));
2546
+ }, [directory, followFileEdits]);
2335
2547
  const [git, setGit] = React.useState();
2336
2548
  React.useEffect(() => {
2337
2549
  if (!directory || !followGit) return;
@@ -2341,18 +2553,25 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2341
2553
  }));
2342
2554
  }, [directory, followGit]);
2343
2555
  if (!folder) return null;
2344
- if (!directory) return /* @__PURE__ */ React.createElement("div", { className: `${prefix}-empty` }, /* @__PURE__ */ React.createElement("style", null, css), /* @__PURE__ */ React.createElement("p", null, message.noFolder), /* @__PURE__ */ React.createElement("button", {
2556
+ 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", {
2345
2557
  type: "button",
2346
- onClick: () => folder.open(locale !== null && locale !== void 0 ? locale : "en")
2347
- }, message.open));
2558
+ disabled: creating,
2559
+ onClick: () => void create()
2560
+ }, 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", {
2561
+ type: "button",
2562
+ onClick: () => folder.open(locale)
2563
+ }, message.open)));
2564
+ const unsavedPaths = new Set((unsaved === null || unsaved === void 0 ? void 0 : unsaved.directory) === directory ? unsaved.paths : void 0);
2565
+ if ((fileEdits === null || fileEdits === void 0 ? void 0 : fileEdits.directory) === directory) for (const path of fileEdits.paths) unsavedPaths.add(path);
2348
2566
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ProjectFolderExplorer, {
2349
2567
  directory,
2350
2568
  locale,
2351
2569
  descriptions,
2352
2570
  marks,
2353
2571
  refreshKey: version,
2572
+ query,
2354
2573
  fileStatuses: (statuses === null || statuses === void 0 ? void 0 : statuses.directory) === directory ? statuses.paths : void 0,
2355
- unsavedPaths: (unsaved === null || unsaved === void 0 ? void 0 : unsaved.directory) === directory ? unsaved.paths : void 0,
2574
+ unsavedPaths,
2356
2575
  mutate: (operation) => folder.mutate(directory, operation),
2357
2576
  isCurrent: () => folder.directory === directory,
2358
2577
  git: (git === null || git === void 0 ? void 0 : git.directory) === directory ? git.actions : void 0,
@@ -2368,18 +2587,11 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2368
2587
  /**
2369
2588
  * Renders the explorer of the project folder open for `vm`, for a side panel of the host: its files with what each is
2370
2589
  * for, and `marks` (such as the Git status) when given. It follows the folder as it opens, closes and saves; with no
2371
- * folder open it offers Open Project Folder…, and it renders nothing while no project folder is mounted for `vm`.
2590
+ * folder open it offers to create one when the host supplies a command, or to open an existing one.
2591
+ * It renders nothing while no project folder is mounted for `vm`.
2372
2592
  * Pass the same `marks` function across renders, or the marks are followed again.
2373
2593
  */
2374
- function renderProjectFolderExplorer(createElement, { vm, locale = "en", marks, fileStatuses, git, openFile, readBaseline }) {
2375
- return createElement(FolderView, {
2376
- vm,
2377
- locale,
2378
- marks,
2379
- fileStatuses,
2380
- git,
2381
- openFile,
2382
- readBaseline
2383
- });
2594
+ function renderProjectFolderExplorer(createElement, props) {
2595
+ return createElement(FolderView, props);
2384
2596
  }
2385
2597
  export { ProjectFolderExplorer, describeProjectFolder, renderProjectFolderExplorer };
@@ -1,3 +1,15 @@
1
+ interface FilePreviewSession {
2
+ requestClose(): void;
3
+ dispose(): void;
4
+ save?: () => Promise<void>;
5
+ readonly fileEdit?: {
6
+ directory: FileSystemDirectoryHandle;
7
+ path: string;
8
+ isDirty(): boolean;
9
+ readUnsaved(): Uint8Array | undefined;
10
+ save(): Promise<void>;
11
+ };
12
+ }
1
13
  export interface FilePreviewRequest {
2
14
  reference: {
3
15
  providerId: string;
@@ -6,10 +18,7 @@ export interface FilePreviewRequest {
6
18
  filename: string;
7
19
  title: string;
8
20
  transient: true;
9
- mount(element: HTMLElement, close: () => void): {
10
- requestClose(): void;
11
- dispose(): void;
12
- };
21
+ mount(element: HTMLElement, close: () => void, onSaveAvailable?: () => void): FilePreviewSession;
13
22
  }
14
23
  export type FileBaseline = {
15
24
  branch: string | undefined;
@@ -22,3 +31,4 @@ export declare function createFilePreview(directory: FileSystemDirectoryHandle,
22
31
  name: string;
23
32
  path: string;
24
33
  }, locale: string, readBaseline?: ReadFileBaseline): FilePreviewRequest;
34
+ export {};