@kubohiroya/turbowarp-plus-editor-project-folder 0.9.2 → 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.
@@ -34,6 +34,8 @@ export type ProjectFolderExplorerProps = {
34
34
  unsavedPaths?: ReadonlySet<string>;
35
35
  /** Changes after the folder contents have been saved or reloaded. */
36
36
  refreshKey?: number;
37
+ /** Case-insensitive search by file name or relative path. */
38
+ query?: string;
37
39
  /** Called when a file is opened with Enter, Space or a click. */
38
40
  onOpen?(entry: ExplorerEntry): void;
39
41
  /** The tree's accessible name. Defaults to "Project folder". */
@@ -68,6 +70,9 @@ type FolderViewProps = {
68
70
  createFolder?(): Promise<unknown>;
69
71
  marks?: FollowMarks;
70
72
  fileStatuses?: FollowFileStatuses;
73
+ /** Reports unsaved text edits in open file tabs for the given folder. */
74
+ followFileEdits?(directory: FileSystemDirectoryHandle, update: (paths: readonly string[]) => void): () => void;
75
+ query?: string;
71
76
  git?: FollowExplorerGit;
72
77
  /** Opens a transient file tab in the host workspace. */
73
78
  openFile?(request: FilePreviewRequest): boolean;
package/dist/explorer.js CHANGED
@@ -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-Dco5rGKE.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,6 +1479,8 @@ 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…",
1469
1486
  create: "Create Project Folder",
@@ -1474,13 +1491,13 @@ var messages = {
1474
1491
  denied: "Permission to read this folder was not granted.",
1475
1492
  separator: ", ",
1476
1493
  marks: {
1477
- added: "Added",
1478
- modified: "Modified",
1494
+ added: "New file",
1495
+ modified: "Saved, not committed",
1479
1496
  deleted: "Deleted",
1480
1497
  untracked: "Untracked"
1481
1498
  },
1482
1499
  unsaved: "Unsaved changes",
1483
- staged: "Staged",
1500
+ staged: "Added to Git index",
1484
1501
  revisions: {
1485
1502
  committed: "Committed",
1486
1503
  pushed: "Pushed",
@@ -1500,6 +1517,8 @@ var messages = {
1500
1517
  label: "作品フォルダ",
1501
1518
  loading: "読み込んでいます…",
1502
1519
  empty: "このフォルダは空です。",
1520
+ noMatches: "該当するファイルはありません。",
1521
+ results: "検索結果",
1503
1522
  noFolder: "プロジェクトフォルダを開くと、ここにファイルを表示します。",
1504
1523
  open: "プロジェクトフォルダを開く…",
1505
1524
  create: "プロジェクトフォルダを作成",
@@ -1510,13 +1529,13 @@ var messages = {
1510
1529
  denied: "このフォルダを読む許可がありません。",
1511
1530
  separator: "、",
1512
1531
  marks: {
1513
- added: "追加",
1514
- modified: "変更",
1532
+ added: "新しいファイル",
1533
+ modified: "保存済・未コミットの変更",
1515
1534
  deleted: "削除",
1516
1535
  untracked: "未追跡"
1517
1536
  },
1518
1537
  unsaved: "未保存の変更あり",
1519
- staged: "ステージ済み",
1538
+ staged: "Git のインデックスに追加済み",
1520
1539
  revisions: {
1521
1540
  committed: "コミット済み",
1522
1541
  pushed: "プッシュ済み",
@@ -1584,6 +1603,10 @@ var css = `.${prefix}{font:inherit;color:inherit}
1584
1603
  .${prefix}-item{display:grid;grid-template-columns:1em 20px minmax(0,1fr);align-items:center;gap:.2em .4em;
1585
1604
  width:100%;box-sizing:border-box;margin:0;border:0;border-radius:3px;
1586
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}
1587
1610
  .${prefix}-item:hover{background:rgba(128,128,128,.12)}
1588
1611
  .${prefix}-item[aria-selected="true"]{background:rgba(128,128,128,.24)}
1589
1612
  .${prefix}-item:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
@@ -1595,12 +1618,14 @@ background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50
1595
1618
  .${prefix}-label{grid-column:3;display:flex;align-items:center;gap:.4em;min-width:0}
1596
1619
  .${prefix}-filename{display:inline-flex;min-width:0}
1597
1620
  .${prefix}-name{overflow:hidden;text-overflow:ellipsis}
1598
- .${prefix}-item[data-staged] .${prefix}-filename{font-weight:700}
1599
- .${prefix}-item[data-revision="committed"] .${prefix}-filename{color:#174b9d;color:light-dark(#174b9d,#91c1ff)}
1600
- .${prefix}-item[data-revision="pushed"] .${prefix}-filename{color:#67369a;color:light-dark(#67369a,#dfafff)}
1601
- .${prefix}-item[data-revision="merged"] .${prefix}-filename{color:#17603e;color:light-dark(#17603e,#85e3ad)}
1602
- .${prefix}-unsaved{flex:none}
1603
- .${prefix}-mark{flex:none;font-size:.85em;padding:0 .3em;border:1px solid currentColor;border-radius:3px;opacity:.85}
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}
1604
1629
  .${prefix}-description{grid-column:3;min-width:0;padding:.2em .4em;border-radius:3px;background:rgba(128,128,128,.12);
1605
1630
  color:inherit;color:color-mix(in srgb,currentColor 78%,transparent);font-size:.75em;line-height:1.4;
1606
1631
  white-space:normal;overflow-wrap:anywhere}
@@ -1733,6 +1758,142 @@ function Icon({ kind, path, readFile }) {
1733
1758
  onError: () => setState("failed")
1734
1759
  }) : null);
1735
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
+ }
1736
1897
  function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsavedPaths, refreshKey, onOpen, label, mutate, git, isCurrent }) {
1737
1898
  const message = messagesFor(locale);
1738
1899
  const actions = actionMessages(locale);
@@ -1775,6 +1936,8 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1775
1936
  }
1776
1937
  return handle.getFile();
1777
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);
1778
1941
  const tree = useTree({
1779
1942
  rootItemId: rootId,
1780
1943
  initialState: {
@@ -1796,8 +1959,9 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1796
1959
  kind: "file"
1797
1960
  }),
1798
1961
  onPrimaryAction: (item) => {
1962
+ var _fileStatuses$get$cha, _fileStatuses$get;
1799
1963
  const data = item.getItemData();
1800
- 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({
1801
1965
  path: data.path,
1802
1966
  name: data.name,
1803
1967
  kind: "file"
@@ -1823,7 +1987,7 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1823
1987
  path: id,
1824
1988
  kind: "directory"
1825
1989
  };
1826
- } catch (_unused2) {
1990
+ } catch (_unused3) {
1827
1991
  await parent.getFileHandle(name);
1828
1992
  return {
1829
1993
  name,
@@ -1833,22 +1997,23 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1833
1997
  }
1834
1998
  },
1835
1999
  getChildrenWithData: async (id) => {
2000
+ const base = id === rootId ? "" : `${id}/`;
2001
+ const missingChildren = deleted.get(id);
2002
+ const nodes = new Map(missingChildren);
1836
2003
  try {
1837
2004
  const handle = await directoryAt(id);
1838
- const base = id === rootId ? "" : `${id}/`;
1839
- const nodes = [];
1840
- var _iteratorAbruptCompletion = false;
1841
- var _didIteratorError = false;
1842
- var _iteratorError;
2005
+ var _iteratorAbruptCompletion2 = false;
2006
+ var _didIteratorError2 = false;
2007
+ var _iteratorError2;
1843
2008
  try {
1844
- for (var _iterator = _asyncIterator(handle.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
1845
- 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;
1846
2011
  {
1847
2012
  if (entry.name.toLowerCase() === ".git") continue;
1848
2013
  const path = base + entry.name;
1849
2014
  if (entry.kind === "directory") handles.set(path, entry);
1850
2015
  else files.set(path, entry);
1851
- nodes.push({
2016
+ nodes.set(path, {
1852
2017
  name: entry.name,
1853
2018
  path,
1854
2019
  kind: entry.kind
@@ -1856,23 +2021,17 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1856
2021
  }
1857
2022
  }
1858
2023
  } catch (err) {
1859
- _didIteratorError = true;
1860
- _iteratorError = err;
2024
+ _didIteratorError2 = true;
2025
+ _iteratorError2 = err;
1861
2026
  } finally {
1862
2027
  try {
1863
- if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
2028
+ if (_iteratorAbruptCompletion2 && _iterator2.return != null) await _iterator2.return();
1864
2029
  } finally {
1865
- if (_didIteratorError) throw _iteratorError;
2030
+ if (_didIteratorError2) throw _iteratorError2;
1866
2031
  }
1867
2032
  }
1868
- loadedFolders.add(id);
1869
- 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));
1870
- return nodes.map((data) => ({
1871
- id: data.path,
1872
- data
1873
- }));
1874
2033
  } catch (error) {
1875
- return [{
2034
+ if (!missingChildren || error.name !== "NotFoundError") return [{
1876
2035
  id: errorId(id),
1877
2036
  data: {
1878
2037
  name: failure(error, message),
@@ -1881,6 +2040,11 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1881
2040
  }
1882
2041
  }];
1883
2042
  }
2043
+ loadedFolders.add(id);
2044
+ return [...nodes.values()].sort(compareNodes).map((data) => ({
2045
+ id: data.path,
2046
+ data
2047
+ }));
1884
2048
  }
1885
2049
  },
1886
2050
  features: [
@@ -1893,15 +2057,31 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1893
2057
  tree.setMounted(true);
1894
2058
  return () => tree.setMounted(false);
1895
2059
  }, [tree]);
1896
- const lastRefresh = React.useRef(refreshKey);
2060
+ const lastRefresh = React.useRef({
2061
+ refreshKey,
2062
+ deleted
2063
+ });
1897
2064
  React.useEffect(() => {
1898
- if (lastRefresh.current === refreshKey) return;
1899
- lastRefresh.current = refreshKey;
1900
- 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)));
1901
2080
  }, [
1902
2081
  tree,
1903
2082
  loadedFolders,
1904
- refreshKey
2083
+ refreshKey,
2084
+ deleted
1905
2085
  ]);
1906
2086
  const errorText = (error) => {
1907
2087
  if (error instanceof ExplorerFileError) return actions[error.code];
@@ -1989,7 +2169,7 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
1989
2169
  Promise.all(candidates.filter((path) => canMoveExplorerEntry(entry.path, path)).map(async (path) => {
1990
2170
  try {
1991
2171
  return await explorerNameAvailable(await directoryAt(path || rootId), entry.name) ? path : null;
1992
- } catch (_unused3) {
2172
+ } catch (_unused4) {
1993
2173
  return null;
1994
2174
  }
1995
2175
  })).then((paths) => {
@@ -2106,29 +2286,25 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2106
2286
  });
2107
2287
  };
2108
2288
  const renderItem = (item) => {
2109
- var _status$change;
2289
+ var _status$change2;
2110
2290
  const data = item.getItemData();
2111
- const entry = (data === null || data === void 0 ? void 0 : data.path) && data.kind !== "error" ? {
2112
- path: data.path,
2113
- name: data.name,
2114
- kind: data.kind
2115
- } : void 0;
2116
2291
  const itemProps = item.getProps();
2117
2292
  const level = item.getItemMeta().level;
2118
2293
  const folder = item.isFolder();
2119
2294
  const expanded = folder && item.isExpanded();
2120
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;
2121
2296
  const unsaved = (data === null || data === void 0 ? void 0 : data.kind) === "file" && (unsavedPaths === null || unsavedPaths === void 0 ? void 0 : unsavedPaths.has(data.path));
2122
- 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;
2123
- 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;
2124
2303
  const description = data && data.kind !== "error" ? descriptions === null || descriptions === void 0 ? void 0 : descriptions.get(data.path) : void 0;
2125
2304
  const icon = !data || data.kind === "error" ? void 0 : folder ? expanded ? "folder-open" : "folder" : iconFor(data.name);
2126
2305
  const accessibleName = [
2127
2306
  item.getItemName(),
2128
- unsaved && message.unsaved,
2129
- (status === null || status === void 0 ? void 0 : status.staged) && message.staged,
2130
- (status === null || status === void 0 ? void 0 : status.revision) && message.revisions[status.revision],
2131
- markLabel,
2307
+ ...fileStatusLabels(message, unsaved, status, change),
2132
2308
  description
2133
2309
  ].filter(Boolean).join(message.separator);
2134
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));
@@ -2142,6 +2318,7 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2142
2318
  "data-path": data === null || data === void 0 ? void 0 : data.path,
2143
2319
  "data-staged": (status === null || status === void 0 ? void 0 : status.staged) ? "" : void 0,
2144
2320
  "data-revision": status === null || status === void 0 ? void 0 : status.revision,
2321
+ "aria-disabled": change === "deleted" && !folder ? true : void 0,
2145
2322
  title: accessibleName || void 0,
2146
2323
  "data-drop-directory": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" ? entry.path : entry ? parentPath(entry.path) : void 0,
2147
2324
  "data-drop-active": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" && drag === entry.path ? "" : void 0,
@@ -2164,14 +2341,15 @@ function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsave
2164
2341
  }, folder ? expanded ? "▾" : "▸" : ""), icon ? /* @__PURE__ */ React.createElement(Icon, {
2165
2342
  kind: icon,
2166
2343
  path: data.path,
2167
- readFile: icon === "image" ? readFile : void 0
2168
- }) : null, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-label` }, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-filename` }, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-name` }, item.getItemName()), unsaved ? /* @__PURE__ */ React.createElement("span", {
2169
- className: `${prefix}-unsaved`,
2170
- "aria-hidden": "true"
2171
- }, "*") : null), markLabel ? /* @__PURE__ */ React.createElement("span", {
2172
- className: `${prefix}-mark`,
2173
- "aria-hidden": "true"
2174
- }, 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", {
2175
2353
  className: `${prefix}-description`,
2176
2354
  "aria-hidden": "true"
2177
2355
  }, description) : null)];
@@ -2271,10 +2449,12 @@ var keyFor = (directory) => {
2271
2449
  * file. Needs React 16.14–18 from the host.
2272
2450
  */
2273
2451
  function ProjectFolderExplorer(props) {
2274
- 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 })));
2275
2455
  }
2276
2456
  var readJson = async (directory, name) => JSON.parse(await (await (await directory.getFileHandle(name)).getFile()).text());
2277
- function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: followStatuses, git: followGit, openFile, readBaseline, createFolder }) {
2457
+ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: followStatuses, git: followGit, openFile, readBaseline, query, followFileEdits, createFolder }) {
2278
2458
  const message = messagesFor(locale);
2279
2459
  const [creating, setCreating] = React.useState(false);
2280
2460
  const [createError, setCreateError] = React.useState("");
@@ -2284,7 +2464,7 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2284
2464
  setCreateError("");
2285
2465
  try {
2286
2466
  await createFolder();
2287
- } catch (_unused4) {
2467
+ } catch (_unused5) {
2288
2468
  setCreateError(message.createFailed);
2289
2469
  } finally {
2290
2470
  setCreating(false);
@@ -2356,6 +2536,14 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2356
2536
  directory,
2357
2537
  version
2358
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]);
2359
2547
  const [git, setGit] = React.useState();
2360
2548
  React.useEffect(() => {
2361
2549
  if (!directory || !followGit) return;
@@ -2373,14 +2561,17 @@ function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: follo
2373
2561
  type: "button",
2374
2562
  onClick: () => folder.open(locale)
2375
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);
2376
2566
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ProjectFolderExplorer, {
2377
2567
  directory,
2378
2568
  locale,
2379
2569
  descriptions,
2380
2570
  marks,
2381
2571
  refreshKey: version,
2572
+ query,
2382
2573
  fileStatuses: (statuses === null || statuses === void 0 ? void 0 : statuses.directory) === directory ? statuses.paths : void 0,
2383
- unsavedPaths: (unsaved === null || unsaved === void 0 ? void 0 : unsaved.directory) === directory ? unsaved.paths : void 0,
2574
+ unsavedPaths,
2384
2575
  mutate: (operation) => folder.mutate(directory, operation),
2385
2576
  isCurrent: () => folder.directory === directory,
2386
2577
  git: (git === null || git === void 0 ? void 0 : git.directory) === directory ? git.actions : void 0,
@@ -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 {};
package/dist/index.d.ts CHANGED
@@ -25,6 +25,9 @@ export declare function mountProjectFolder({ vm, document, host, locale, autoRel
25
25
  autoReload?: boolean;
26
26
  }): {
27
27
  openDirectory: (directory: FileSystemDirectoryHandle, confirmReplace: () => boolean) => Promise<import("./session.js").OpenResult>;
28
+ unsavedPaths: () => ReadonlySet<string> | null;
29
+ readUnsavedFile: (path: string) => Uint8Array<ArrayBufferLike> | null | undefined;
30
+ subscribeEdits: (listener: () => void) => () => void;
28
31
  save: () => Promise<{
29
32
  status: "saved" | "unchanged";
30
33
  sourceRemoved: string[];