@kubohiroya/turbowarp-plus-editor-project-folder 0.14.0 → 0.15.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.
@@ -29702,6 +29702,201 @@ function rm(elt) {
29702
29702
  elt.remove();
29703
29703
  return next;
29704
29704
  }
29705
+ // src/text-minimap.ts
29706
+ var textMinimap = (label) => ViewPlugin.fromClass(class {
29707
+ constructor(view) {
29708
+ this.view = view;
29709
+ this.drawnColor = "";
29710
+ this.drawnWidth = 0;
29711
+ this.drawnHeight = 0;
29712
+ this.disposed = false;
29713
+ this.measure = () => {
29714
+ if (this.disposed) return;
29715
+ this.view.requestMeasure({
29716
+ key: this,
29717
+ read: (view) => ({
29718
+ width: this.dom.clientWidth,
29719
+ height: this.dom.clientHeight,
29720
+ top: view.scrollDOM.scrollTop,
29721
+ total: view.scrollDOM.scrollHeight,
29722
+ visible: view.scrollDOM.clientHeight,
29723
+ color: view.dom.ownerDocument.defaultView.getComputedStyle(view.contentDOM).color
29724
+ }),
29725
+ write: ({ width, height, top, total, visible, color }, view) => {
29726
+ if (this.disposed || !width || !height || !total) return;
29727
+ const doc = view.state.doc;
29728
+ if (doc !== this.drawnDoc || width !== this.drawnWidth || height !== this.drawnHeight || color !== this.drawnColor) {
29729
+ this.canvas.width = width;
29730
+ this.canvas.height = height;
29731
+ const context = this.canvas.getContext("2d");
29732
+ if (context) {
29733
+ context.fillStyle = color;
29734
+ context.globalAlpha = .65;
29735
+ const rows = Math.min(doc.lines, height);
29736
+ const rowHeight = Math.min(2, height / rows);
29737
+ for (let row = 0; row < rows; row++) {
29738
+ const line = doc.line(1 + Math.floor(row * doc.lines / rows));
29739
+ const text = doc.sliceString(line.from, Math.min(line.to, line.from + width));
29740
+ for (let column = 0; column < text.length; column++) if (!/\s/u.test(text[column])) context.fillRect(column, row * rowHeight, 1, rowHeight);
29741
+ }
29742
+ }
29743
+ this.drawnDoc = doc;
29744
+ this.drawnWidth = width;
29745
+ this.drawnHeight = height;
29746
+ this.drawnColor = color;
29747
+ }
29748
+ this.viewport.style.top = `${top / total * 100}%`;
29749
+ this.viewport.style.height = `${Math.min(1, visible / total) * 100}%`;
29750
+ this.dom.setAttribute("aria-valuemax", String(doc.lines));
29751
+ this.dom.setAttribute("aria-valuenow", String(Math.min(doc.lines, 1 + Math.floor(top / total * doc.lines))));
29752
+ }
29753
+ });
29754
+ };
29755
+ const document = view.dom.ownerDocument;
29756
+ this.dom = document.createElement("div");
29757
+ this.dom.className = "twpf-text-minimap";
29758
+ this.dom.tabIndex = 0;
29759
+ this.dom.setAttribute("role", "slider");
29760
+ this.dom.setAttribute("aria-label", label);
29761
+ this.dom.setAttribute("aria-orientation", "vertical");
29762
+ this.dom.setAttribute("aria-valuemin", "1");
29763
+ this.canvas = document.createElement("canvas");
29764
+ this.canvas.setAttribute("aria-hidden", "true");
29765
+ this.viewport = document.createElement("div");
29766
+ this.viewport.className = "twpf-text-minimap-viewport";
29767
+ this.dom.append(this.canvas, this.viewport);
29768
+ view.dom.append(this.dom);
29769
+ this.dom.addEventListener("pointerdown", (event) => {
29770
+ if (event.button !== 0) return;
29771
+ event.preventDefault();
29772
+ this.dom.focus({ preventScroll: true });
29773
+ this.dom.setPointerCapture(event.pointerId);
29774
+ this.seek(event);
29775
+ });
29776
+ this.dom.addEventListener("pointermove", (event) => {
29777
+ if (this.dom.hasPointerCapture(event.pointerId)) this.seek(event);
29778
+ });
29779
+ this.dom.addEventListener("pointerup", (event) => {
29780
+ if (this.dom.hasPointerCapture(event.pointerId)) this.dom.releasePointerCapture(event.pointerId);
29781
+ });
29782
+ this.dom.addEventListener("keydown", (event) => {
29783
+ const scroll = view.scrollDOM;
29784
+ const line = view.defaultLineHeight;
29785
+ const destinations = {
29786
+ ArrowUp: scroll.scrollTop - line,
29787
+ ArrowDown: scroll.scrollTop + line,
29788
+ PageUp: scroll.scrollTop - scroll.clientHeight,
29789
+ PageDown: scroll.scrollTop + scroll.clientHeight,
29790
+ Home: 0,
29791
+ End: scroll.scrollHeight
29792
+ };
29793
+ if (!(event.key in destinations)) return;
29794
+ event.preventDefault();
29795
+ event.stopPropagation();
29796
+ scroll.scrollTop = destinations[event.key];
29797
+ });
29798
+ view.scrollDOM.addEventListener("scroll", this.measure, { passive: true });
29799
+ const browser = document.defaultView;
29800
+ this.observer = new browser.ResizeObserver(this.measure);
29801
+ this.observer.observe(this.dom);
29802
+ this.measure();
29803
+ }
29804
+ seek(event) {
29805
+ const bounds = this.dom.getBoundingClientRect();
29806
+ if (!bounds.height) return;
29807
+ const scroll = this.view.scrollDOM;
29808
+ scroll.scrollTop = (event.clientY - bounds.top) / bounds.height * scroll.scrollHeight - scroll.clientHeight / 2;
29809
+ }
29810
+ update(update) {
29811
+ if (update.docChanged || update.viewportChanged || update.geometryChanged) this.measure();
29812
+ }
29813
+ destroy() {
29814
+ this.disposed = true;
29815
+ this.observer.disconnect();
29816
+ this.view.scrollDOM.removeEventListener("scroll", this.measure);
29817
+ this.dom.remove();
29818
+ }
29819
+ });
29820
+ // src/external-file-editor.ts
29821
+ async function connectExternalFileEditor(browser, filename, extension, limit) {
29822
+ if (![
29823
+ "127.0.0.1",
29824
+ "localhost",
29825
+ "[::1]"
29826
+ ].includes(browser.location.hostname) || browser.location.protocol !== "http:") return null;
29827
+ const prefix = "/__twpe_yaml";
29828
+ let config;
29829
+ try {
29830
+ const response = await browser.fetch(`${prefix}/config`, {
29831
+ credentials: "same-origin",
29832
+ cache: "no-store"
29833
+ });
29834
+ if (!response.ok) return null;
29835
+ config = await response.json();
29836
+ } catch (_unused) {
29837
+ return null;
29838
+ }
29839
+ if ((config === null || config === void 0 ? void 0 : config.available) !== true || typeof config.token !== "string" || config.editor !== "VSCode") return null;
29840
+ const format = extension === "json" ? "json" : ["yaml", "yml"].includes(extension) ? "yaml" : "text";
29841
+ if (!(Array.isArray(config.formats) ? config.formats : ["yaml", "json"]).includes(format)) return null;
29842
+ const maxBytes = Math.min(limit, Number.isFinite(config.maxSourceBytes) && config.maxSourceBytes > 0 ? config.maxSourceBytes : limit);
29843
+ let session;
29844
+ let closed = false;
29845
+ const request = async (path, method = "GET", body) => {
29846
+ const response = await browser.fetch(`${prefix}${path}`, _objectSpread2({
29847
+ method,
29848
+ credentials: "same-origin",
29849
+ cache: "no-store",
29850
+ headers: _objectSpread2({ "X-TWPE-Yaml-Token": config.token }, body ? { "Content-Type": "application/json" } : {})
29851
+ }, body ? { body: JSON.stringify(body) } : {}));
29852
+ if (!response.ok) throw new Error("External editor request failed.");
29853
+ return response.json();
29854
+ };
29855
+ const checkSource = (source) => {
29856
+ if (typeof source !== "string" || new TextEncoder().encode(source).byteLength > maxBytes || /[\u0000-\u0008\u000b\u000e-\u001f\u007f]/u.test(source)) throw new Error("Invalid external text.");
29857
+ return source;
29858
+ };
29859
+ const endSession = (id) => {
29860
+ request(`/sessions/${id}`, "DELETE").catch(() => {});
29861
+ };
29862
+ const end = () => {
29863
+ if (session) endSession(session.id);
29864
+ session = void 0;
29865
+ };
29866
+ return {
29867
+ get active() {
29868
+ return Boolean(session);
29869
+ },
29870
+ async open(source) {
29871
+ if (closed) return;
29872
+ if (session) {
29873
+ await request(`/sessions/${session.id}`, "POST");
29874
+ return;
29875
+ }
29876
+ const created = await request("/sessions", "POST", {
29877
+ source: checkSource(source),
29878
+ sourceName: filename,
29879
+ format
29880
+ });
29881
+ if (!/^[a-f0-9]{32}$/u.test(created === null || created === void 0 ? void 0 : created.id)) throw new Error("Invalid external editor session.");
29882
+ if (closed) {
29883
+ endSession(created.id);
29884
+ return;
29885
+ }
29886
+ session = { id: created.id };
29887
+ },
29888
+ async read() {
29889
+ if (closed || !session) throw new Error("No external editor session.");
29890
+ const saved = await request(`/sessions/${session.id}`);
29891
+ return checkSource(saved.source);
29892
+ },
29893
+ end,
29894
+ close() {
29895
+ closed = true;
29896
+ end();
29897
+ }
29898
+ };
29899
+ }
29705
29900
  // src/text-file-editor.ts
29706
29901
  var decoder = new TextDecoder("utf-8", {
29707
29902
  fatal: true,
@@ -29782,18 +29977,55 @@ var highlighting = syntaxHighlighting(HighlightStyle.define([
29782
29977
  }
29783
29978
  ]));
29784
29979
  var styles = `
29785
- .twpf-text-file{display:flex;flex-direction:column;height:100%;min-height:0;font:inherit}
29786
- .twpf-file-toolbar,.twpf-diff-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:.4rem;padding:.5rem .7rem;
29980
+ .twpf-text-shell{position:relative;height:100%;min-height:0}
29981
+ .twpf-text-file{position:relative;display:flex;flex-direction:column;height:100%;min-height:0;font:inherit}
29982
+ .twpf-text-file[inert]{opacity:.45}
29983
+ .twpf-external-overlay{position:absolute;z-index:10;inset:0;display:flex;align-items:center;justify-content:center;
29984
+ background:rgba(128,128,128,.16);padding:1rem;box-sizing:border-box}
29985
+ .twpf-external-overlay[hidden]{display:none}
29986
+ .twpf-external-card{max-width:28rem;padding:1rem;border-radius:.5rem;background:var(--ui-primary,#fff);
29987
+ color:var(--text-primary,inherit);box-shadow:0 3px 15px rgba(0,0,0,.2);font:inherit}
29988
+ .twpf-external-card h3{margin:0 0 .7rem;font-size:1rem}
29989
+ .twpf-external-card p{margin:0 0 1rem;font-size:.9rem}
29990
+ .twpf-external-card div{display:flex;flex-wrap:wrap;gap:.5rem}
29991
+ .twpf-external-card button{font:inherit;color:inherit;border:1px solid var(--ui-black-transparent,#888);
29992
+ border-radius:.3rem;background:var(--ui-secondary,#eee);padding:.4rem .6rem;cursor:pointer}
29993
+ .twpf-external-card button:disabled{opacity:.55;cursor:default}
29994
+ .twpf-file-toolbar{position:absolute;z-index:5;top:.5rem;right:1.25rem;display:flex;flex-wrap:wrap;
29995
+ justify-content:flex-end;gap:.4rem;max-width:calc(100% - 2rem);padding:.3rem;border-radius:.5rem;
29996
+ background:var(--ui-primary,#fff);box-shadow:0 1px 6px rgba(0,0,0,.18);opacity:.94}
29997
+ .twpf-diff-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:.4rem;padding:.5rem .7rem;
29787
29998
  border-bottom:1px solid var(--ui-black-transparent,rgba(128,128,128,.25))}
29788
- .twpf-file-path{font-size:.83em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-inline-end:auto;min-width:0}
29789
29999
  .twpf-file-actions{display:flex;gap:.25rem}
30000
+ .twpf-file-modes{display:inline-flex;overflow:hidden;border:1px solid var(--ui-black-transparent,rgba(128,128,128,.35));
30001
+ border-radius:999px;background:var(--ui-secondary,rgba(128,128,128,.1))}
30002
+ .twpf-text-file .twpf-file-modes>button{border:0;border-radius:0;background:transparent;white-space:nowrap}
30003
+ .twpf-text-file .twpf-file-modes>button+button{border-inline-start:1px solid var(--ui-black-transparent,rgba(128,128,128,.35))}
30004
+ .twpf-file-modes>button[aria-checked=true]{background:var(--motion-primary,#2468b7);color:#fff}
30005
+ .twpf-file-modes>button:focus-visible{outline:2px solid var(--motion-primary,#2468b7);outline-offset:-3px}
29790
30006
  .twpf-text-file button{font:inherit;font-size:.85em;color:inherit;background:transparent;border:1px solid
29791
30007
  var(--ui-black-transparent,rgba(128,128,128,.45));border-radius:.3rem;padding:.25rem .55rem;cursor:pointer}
29792
30008
  .twpf-text-file button[aria-pressed=true]{background:var(--motion-primary,#2468b7);border-color:transparent;color:#fff}
29793
30009
  .twpf-text-file button:disabled{opacity:.55;cursor:default}
30010
+ .twpf-text-file button:has(svg){display:inline-flex;align-items:center;justify-content:center;gap:.3rem}
30011
+ .twpf-text-file button svg{width:1rem;height:1rem;flex:none}
29794
30012
  .twpf-file-status,.twpf-diff-status{margin:0;padding:.35rem .7rem;font-size:.82em}
30013
+ .twpf-file-status{position:absolute;z-index:5;bottom:.5rem;left:.5rem;max-width:calc(100% - 10rem);
30014
+ max-height:40%;overflow:auto;border-radius:.3rem;background:var(--ui-primary,#fff);box-shadow:0 1px 6px rgba(0,0,0,.18)}
30015
+ .twpf-file-snackbar{position:absolute;z-index:6;bottom:1rem;left:50%;transform:translateX(-50%);
30016
+ box-sizing:border-box;max-width:calc(100% - 2rem);margin:0;padding:.65rem 1rem;border-radius:.35rem;
30017
+ background:#323232;color:#fff;font-size:.9em;box-shadow:0 2px 8px rgba(0,0,0,.3);pointer-events:none}
29795
30018
  .twpf-file-edit,.twpf-file-diff{flex:1;min-height:0}
30019
+ .twpf-file-diff{padding-top:var(--twpf-toolbar-height,3.25rem)}
29796
30020
  .twpf-file-edit>.cm-editor{height:100%}
30021
+ .twpf-text-file .cm-scroller{overflow:auto}
30022
+ .twpf-text-minimap{position:absolute;z-index:4;right:1.25rem;bottom:1.25rem;width: min(7rem,25%);
30023
+ height:min(10.5rem,35%);overflow:hidden;border:1px solid var(--ui-black-transparent,rgba(128,128,128,.4));
30024
+ border-radius:.3rem;background:var(--ui-primary,#fff);opacity:.85;cursor:pointer;touch-action:none}
30025
+ .twpf-text-minimap:focus-visible{outline:2px solid var(--motion-primary,#2468b7);outline-offset:2px}
30026
+ .twpf-text-minimap canvas{display:block;width:100%;height:100%;pointer-events:none}
30027
+ .twpf-text-minimap-viewport{position:absolute;left:0;right:0;box-sizing:border-box;min-height:2px;
30028
+ border:1px solid var(--motion-primary,#2468b7);background:rgba(76,151,255,.2);pointer-events:none}
29797
30029
  .twpf-file-diff{display:flex;flex-direction:column}
29798
30030
  .twpf-text-file [hidden]{display:none}
29799
30031
  .twpf-diff-headings{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));font-size:.83em;
@@ -29813,15 +30045,30 @@ border-bottom:1px solid var(--ui-black-transparent,rgba(128,128,128,.25))}
29813
30045
  `;
29814
30046
  var messages = {
29815
30047
  en: {
29816
- edit: "Edit",
29817
- diff: "Diff",
30048
+ text: "Normal view",
30049
+ textHint: "Edit the file content in this tab",
30050
+ diff: "Diff view",
30051
+ diffHint: "Compare with the latest commit",
30052
+ viewMode: "View mode",
30053
+ external: "Edit in VSCode",
30054
+ importExternal: "Finish and import edits",
30055
+ externalTitle: "Editing in VSCode",
30056
+ cancelExternal: "Finish without importing",
30057
+ externalUnavailable: "Open the Editor through the local companion to edit this file in VSCode.",
30058
+ externalOpening: "Opening VSCode…",
30059
+ externalHint: "Save in VSCode, then choose “Finish and import edits”. This tab stays locked until you finish.",
30060
+ externalReading: "Reading external edits…",
30061
+ externalImported: "External edits imported. Save the file to keep them.",
30062
+ externalFailed: "External editing failed. Your edits are still here. Check the local companion and try again.",
30063
+ externalReplace: "This tab has also changed. Replace its current content with the file saved in VSCode?",
30064
+ externalChanged: "This tab changed while reading. Import the external edits again to compare.",
29818
30065
  changes: "Changes only",
29819
30066
  whole: "Full file",
29820
30067
  refresh: "Reload latest commit",
29821
30068
  save: "Save file",
29822
30069
  unsaved: "Unsaved changes",
29823
30070
  saving: "Saving…",
29824
- saved: "File saved.",
30071
+ saved: "Saved.",
29825
30072
  conflict: "The file changed outside this tab. Your edits are still here. Reopen the file to load the current version.",
29826
30073
  saveFailed: "The file could not be saved.",
29827
30074
  tooLarge: "The text file exceeds the 4 MiB limit.",
@@ -29836,18 +30083,34 @@ var messages = {
29836
30083
  formatting: "The line endings or UTF-8 BOM differ.",
29837
30084
  before: "Latest commit",
29838
30085
  after: "Current content",
29839
- collapsed: "$ unchanged lines"
30086
+ collapsed: "$ unchanged lines",
30087
+ minimap: "File minimap"
29840
30088
  },
29841
30089
  ja: {
29842
- edit: "編集",
29843
- diff: "差分",
30090
+ text: "通常表示",
30091
+ textHint: "この画面でファイルの内容を編集",
30092
+ diff: "差分表示",
30093
+ diffHint: "最新コミットと現在の内容を比較",
30094
+ viewMode: "表示モード",
30095
+ external: "VSCodeで編集",
30096
+ importExternal: "終了して取り込む",
30097
+ externalTitle: "VSCodeで編集中",
30098
+ cancelExternal: "取り込まずに終了",
30099
+ externalUnavailable: "VSCodeで編集するには、ローカル連携からEditorを開いてください。",
30100
+ externalOpening: "VSCodeを開いています…",
30101
+ externalHint: "VSCodeで保存後、「終了して取り込む」を押してください。終了までこのタブの操作はできません。",
30102
+ externalReading: "外部の編集内容を読み込んでいます…",
30103
+ externalImported: "外部編集を取り込みました。ファイルを保存してください。",
30104
+ externalFailed: "外部編集を利用できませんでした。編集内容は保持しています。ローカル連携を確認して再試行してください。",
30105
+ externalReplace: "この画面にも変更があります。VSCodeで保存した内容で、この画面の内容を置き換えますか?",
30106
+ externalChanged: "読み込み中にこの画面の内容が変わりました。もう一度取り込みを行ってください。",
29844
30107
  changes: "変更箇所のみ",
29845
30108
  whole: "全体",
29846
30109
  refresh: "最新コミットを読み直す",
29847
30110
  save: "ファイルを保存",
29848
30111
  unsaved: "未保存の変更があります",
29849
30112
  saving: "保存中…",
29850
- saved: "ファイルを保存しました。",
30113
+ saved: "保存しました",
29851
30114
  conflict: "ファイルがこのタブの外で変更されました。編集内容はタブに残っています。現在の内容を読むにはファイルを開き直してください。",
29852
30115
  saveFailed: "ファイルを保存できませんでした。",
29853
30116
  tooLarge: "テキストファイルの上限(4 MiB)を超えています。",
@@ -29862,7 +30125,8 @@ var messages = {
29862
30125
  formatting: "改行コードまたは UTF-8 BOM が異なります。",
29863
30126
  before: "最新コミット",
29864
30127
  after: "現在の内容",
29865
- collapsed: "変更のない $ 行"
30128
+ collapsed: "変更のない $ 行",
30129
+ minimap: "ファイルのミニマップ"
29866
30130
  }
29867
30131
  };
29868
30132
  function mountTextFile(parent, options) {
@@ -29874,10 +30138,25 @@ function mountTextFile(parent, options) {
29874
30138
  node.className = className;
29875
30139
  return node;
29876
30140
  };
29877
- const button = (label, action) => {
30141
+ const button = (label, action, icon) => {
29878
30142
  const node = document.createElement("button");
29879
30143
  node.type = "button";
29880
30144
  node.textContent = label;
30145
+ if (icon) {
30146
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
30147
+ svg.setAttribute("viewBox", "0 0 24 24");
30148
+ svg.setAttribute("fill", "none");
30149
+ svg.setAttribute("stroke", "currentColor");
30150
+ svg.setAttribute("stroke-width", "1.8");
30151
+ svg.setAttribute("stroke-linecap", "round");
30152
+ svg.setAttribute("stroke-linejoin", "round");
30153
+ svg.setAttribute("aria-hidden", "true");
30154
+ svg.setAttribute("focusable", "false");
30155
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
30156
+ path.setAttribute("d", icon);
30157
+ svg.append(path);
30158
+ node.prepend(svg);
30159
+ }
29881
30160
  node.addEventListener("click", action);
29882
30161
  return node;
29883
30162
  };
@@ -29886,14 +30165,30 @@ function mountTextFile(parent, options) {
29886
30165
  node.textContent = text;
29887
30166
  node.hidden = !text;
29888
30167
  };
30168
+ const shell = element("div", "twpf-text-shell");
29889
30169
  const panel = element("div", "twpf-text-file");
29890
30170
  const style = document.createElement("style");
29891
30171
  style.textContent = styles;
29892
30172
  const toolbar = element("div", "twpf-file-toolbar");
29893
- const path = element("span", "twpf-file-path");
29894
- path.textContent = path.title = options.path;
30173
+ toolbar.setAttribute("role", "group");
30174
+ toolbar.setAttribute("aria-label", options.path);
29895
30175
  const status = element("p", "twpf-file-status");
29896
30176
  status.setAttribute("role", "status");
30177
+ const snackbar = element("p", "twpf-file-snackbar");
30178
+ snackbar.setAttribute("role", "status");
30179
+ snackbar.setAttribute("aria-atomic", "true");
30180
+ snackbar.hidden = true;
30181
+ let snackbarTimeout;
30182
+ const hideSnackbar = () => {
30183
+ browser === null || browser === void 0 || browser.clearTimeout(snackbarTimeout);
30184
+ snackbarTimeout = void 0;
30185
+ setStatus(snackbar, "");
30186
+ };
30187
+ const showSaved = () => {
30188
+ hideSnackbar();
30189
+ setStatus(snackbar, message.saved);
30190
+ snackbarTimeout = browser === null || browser === void 0 ? void 0 : browser.setTimeout(hideSnackbar, 4e3);
30191
+ };
29897
30192
  const editPane = element("div", "twpf-file-edit");
29898
30193
  const diffPane = element("div", "twpf-file-diff");
29899
30194
  const diffToolbar = element("div", "twpf-diff-toolbar");
@@ -29924,38 +30219,94 @@ function mountTextFile(parent, options) {
29924
30219
  }).doc;
29925
30220
  let merge;
29926
30221
  let saving = false;
30222
+ let externalBusy = false;
30223
+ let externalLocked = false;
30224
+ let externalEditor = null;
30225
+ let externalOriginal;
29927
30226
  let disposed = false;
29928
30227
  let comparison;
29929
30228
  let changesOnly = true;
29930
30229
  let readVersion = 0;
30230
+ let baselineLoading = false;
29931
30231
  const collapseUnchanged = {
29932
30232
  margin: 0,
29933
30233
  minSize: 1
29934
30234
  };
29935
- const edit = button(message.edit, () => showDiff(false));
29936
- const diff = button(message.diff, () => showDiff(true));
29937
- const saveButton = button(message.save, () => void save());
30235
+ const text = button(message.text, () => showDiff(false), "M14 3H5v18h14V8l-5-5v5h5M8 12h8M8 16h8");
30236
+ text.title = message.textHint;
30237
+ const diff = button(message.diff, () => showDiff(true), "M4 3h16v18H4zM12 3v18M6.5 8h3M14.5 8h3M16 6.5v3");
30238
+ diff.title = message.diffHint;
30239
+ const saveButton = button(message.save, () => void save(), "M4 3h13l4 4v14H3V3h1M7 3v6h10V3M7 21v-8h10v8");
30240
+ const externalButton = button(message.external, () => void openExternal(), "M14 3h7v7M21 3l-11 11M11 5H3v16h16v-8");
30241
+ externalButton.disabled = true;
30242
+ externalButton.title = message.externalUnavailable;
30243
+ const overlay = element("div", "twpf-external-overlay");
30244
+ overlay.hidden = true;
30245
+ overlay.setAttribute("role", "dialog");
30246
+ overlay.setAttribute("aria-label", message.externalTitle);
30247
+ const externalCard = element("div", "twpf-external-card");
30248
+ const externalTitle = element("h3", "");
30249
+ externalTitle.textContent = message.externalTitle;
30250
+ const externalStatus = element("p", "");
30251
+ externalStatus.setAttribute("role", "status");
30252
+ const importButton = button(message.importExternal, () => void importExternal());
30253
+ const cancelExternal = button(message.cancelExternal, () => {
30254
+ if (externalBusy || disposed) return;
30255
+ externalEditor === null || externalEditor === void 0 || externalEditor.end();
30256
+ setExternalLocked(false);
30257
+ updateSaveState();
30258
+ externalButton.focus();
30259
+ });
30260
+ const externalActions = element("div", "");
30261
+ externalActions.append(importButton, cancelExternal);
30262
+ externalCard.append(externalTitle, externalStatus, externalActions);
30263
+ overlay.append(externalCard);
29938
30264
  const changes = button(message.changes, () => changeVisibility(true));
29939
30265
  const whole = button(message.whole, () => changeVisibility(false));
29940
30266
  const refresh = button(message.refresh, () => void loadBaseline());
29941
- const modes = element("div", "twpf-file-actions");
29942
- modes.append(edit, diff);
29943
- toolbar.append(path, modes, saveButton);
30267
+ const modes = element("div", "twpf-file-modes");
30268
+ modes.setAttribute("role", "radiogroup");
30269
+ modes.setAttribute("aria-label", message.viewMode);
30270
+ text.setAttribute("role", "radio");
30271
+ diff.setAttribute("role", "radio");
30272
+ modes.append(text, diff);
30273
+ modes.addEventListener("keydown", (event) => {
30274
+ if (![
30275
+ "ArrowLeft",
30276
+ "ArrowRight",
30277
+ "Home",
30278
+ "End"
30279
+ ].includes(event.key)) return;
30280
+ event.preventDefault();
30281
+ event.stopPropagation();
30282
+ const active = event.key === "Home" ? false : event.key === "End" ? true : !comparison;
30283
+ showDiff(active);
30284
+ (active ? diff : text).focus();
30285
+ });
30286
+ toolbar.append(modes, saveButton, externalButton);
29944
30287
  const ranges = element("div", "twpf-file-actions");
29945
30288
  ranges.append(changes, whole);
29946
30289
  diffToolbar.append(ranges, refresh);
29947
- panel.append(style, toolbar, status, editPane, diffPane);
29948
- parent.append(panel);
30290
+ panel.append(style, toolbar, status, snackbar, editPane, diffPane);
30291
+ shell.append(panel, overlay);
30292
+ parent.append(shell);
30293
+ const toolbarObserver = browser && new browser.ResizeObserver(() => {
30294
+ panel.style.setProperty("--twpf-toolbar-height", `calc(${toolbar.getBoundingClientRect().height}px + 1rem)`);
30295
+ });
30296
+ toolbarObserver === null || toolbarObserver === void 0 || toolbarObserver.observe(toolbar);
30297
+ const editing = new Compartment();
29949
30298
  const view = new EditorView({
29950
30299
  parent: editPane,
29951
30300
  doc: savedDoc,
29952
30301
  extensions: [
29953
30302
  common,
30303
+ editing.of([]),
29954
30304
  mixed ? EditorState.lineSeparator.of("\n") : [],
29955
30305
  history(),
29956
30306
  drawSelection(),
29957
30307
  highlightSpecialChars(),
29958
30308
  highlightActiveLine(),
30309
+ textMinimap(message.minimap),
29959
30310
  EditorView.contentAttributes.of({ "aria-label": options.path }),
29960
30311
  keymap.of([...defaultKeymap, ...historyKeymap]),
29961
30312
  EditorView.updateListener.of((update) => {
@@ -29968,7 +30319,10 @@ function mountTextFile(parent, options) {
29968
30319
  let wasDirty = false;
29969
30320
  function updateSaveState(text = saving ? message.saving : dirty() ? message.unsaved : "", contentChanged = false) {
29970
30321
  const isDirty = dirty();
29971
- saveButton.disabled = saving || !isDirty;
30322
+ saveButton.disabled = saving || externalBusy || externalLocked || !isDirty;
30323
+ externalButton.disabled = saving || externalBusy || externalLocked || !externalEditor;
30324
+ importButton.disabled = saving || externalBusy;
30325
+ cancelExternal.disabled = externalBusy;
29972
30326
  setStatus(status, text);
29973
30327
  if (isDirty !== wasDirty || contentChanged && isDirty) {
29974
30328
  var _options$onDirtyChang;
@@ -29976,6 +30330,89 @@ function mountTextFile(parent, options) {
29976
30330
  (_options$onDirtyChang = options.onDirtyChange) === null || _options$onDirtyChang === void 0 || _options$onDirtyChang.call(options);
29977
30331
  }
29978
30332
  }
30333
+ function setExternalLocked(active) {
30334
+ externalLocked = active;
30335
+ if (active) for (const button of panel.querySelectorAll("button")) button.disabled = true;
30336
+ else {
30337
+ text.disabled = diff.disabled = false;
30338
+ changes.disabled = whole.disabled = baselineLoading || !merge;
30339
+ refresh.disabled = baselineLoading || !options.readBaseline;
30340
+ }
30341
+ panel.inert = active;
30342
+ overlay.hidden = !active;
30343
+ view.dispatch({ effects: editing.reconfigure(active ? [EditorState.readOnly.of(true), EditorView.editable.of(false)] : []) });
30344
+ updateSaveState(status.textContent || "");
30345
+ }
30346
+ async function openExternal() {
30347
+ if (!externalEditor || saving || externalBusy || disposed) return;
30348
+ externalBusy = true;
30349
+ setExternalLocked(true);
30350
+ externalStatus.textContent = message.externalOpening;
30351
+ updateSaveState(message.externalOpening);
30352
+ const initial = serialize();
30353
+ const reopening = externalEditor.active;
30354
+ try {
30355
+ await externalEditor.open(initial);
30356
+ if (disposed) return;
30357
+ if (!reopening) externalOriginal = initial;
30358
+ externalStatus.textContent = message.externalHint;
30359
+ updateSaveState(message.externalHint);
30360
+ importButton.focus();
30361
+ } catch (_unused2) {
30362
+ if (!disposed) {
30363
+ setExternalLocked(false);
30364
+ updateSaveState(message.externalFailed);
30365
+ }
30366
+ } finally {
30367
+ externalBusy = false;
30368
+ if (!disposed) {
30369
+ updateSaveState(status.textContent || "");
30370
+ if (externalLocked) importButton.focus();
30371
+ }
30372
+ }
30373
+ }
30374
+ async function importExternal() {
30375
+ if (!(externalEditor === null || externalEditor === void 0 ? void 0 : externalEditor.active) || saving || externalBusy || disposed) return;
30376
+ externalBusy = true;
30377
+ externalStatus.textContent = message.externalReading;
30378
+ updateSaveState(message.externalReading);
30379
+ const beforeRead = serialize();
30380
+ try {
30381
+ const source = await externalEditor.read();
30382
+ if (disposed) return;
30383
+ if (serialize() !== beforeRead) {
30384
+ externalStatus.textContent = message.externalChanged;
30385
+ return updateSaveState(message.externalChanged);
30386
+ }
30387
+ if (beforeRead !== externalOriginal && source !== beforeRead && !(browser === null || browser === void 0 ? void 0 : browser.confirm(message.externalReplace))) {
30388
+ externalStatus.textContent = message.externalHint;
30389
+ return updateSaveState();
30390
+ }
30391
+ const imported = EditorState.create({
30392
+ doc: source.replace(/^\uFEFF/u, ""),
30393
+ extensions: mixed ? EditorState.lineSeparator.of("\n") : []
30394
+ }).doc;
30395
+ view.dispatch({ changes: {
30396
+ from: 0,
30397
+ to: view.state.doc.length,
30398
+ insert: imported
30399
+ } });
30400
+ externalOriginal = serialize();
30401
+ externalEditor.end();
30402
+ setExternalLocked(false);
30403
+ showDiff(false);
30404
+ updateSaveState(message.externalImported);
30405
+ view.focus();
30406
+ } catch (_unused3) {
30407
+ if (!disposed) {
30408
+ externalStatus.textContent = message.externalFailed;
30409
+ updateSaveState(message.externalFailed);
30410
+ }
30411
+ } finally {
30412
+ externalBusy = false;
30413
+ if (!disposed) updateSaveState(status.textContent || "");
30414
+ }
30415
+ }
29979
30416
  async function unchanged(handle) {
29980
30417
  try {
29981
30418
  const file = await handle.getFile();
@@ -29986,14 +30423,16 @@ function mountTextFile(parent, options) {
29986
30423
  }
29987
30424
  }
29988
30425
  async function save() {
29989
- if (saving || disposed || !dirty()) return;
30426
+ if (saving || externalBusy || externalLocked || disposed || !dirty()) return;
29990
30427
  const doc = view.state.doc;
29991
30428
  const content = serialize();
29992
30429
  const bytes = encoder.encode(content);
29993
30430
  if (bytes.byteLength > options.limit) return updateSaveState(message.tooLarge);
30431
+ hideSnackbar();
29994
30432
  saving = true;
29995
30433
  updateSaveState();
29996
30434
  let result = message.saveFailed;
30435
+ let didSave = false;
29997
30436
  let writable;
29998
30437
  try {
29999
30438
  const handle = await options.readHandle();
@@ -30014,13 +30453,17 @@ function mountTextFile(parent, options) {
30014
30453
  writable = void 0;
30015
30454
  saved = content;
30016
30455
  savedDoc = doc;
30017
- result = dirty() ? message.unsaved : message.saved;
30456
+ didSave = true;
30457
+ result = dirty() ? message.unsaved : "";
30018
30458
  } catch (error) {
30019
30459
  if (["NotFoundError", "TypeMismatchError"].includes(error.name)) result = message.conflict;
30020
30460
  } finally {
30021
30461
  await (writable === null || writable === void 0 ? void 0 : writable.abort().catch(() => {}));
30022
30462
  saving = false;
30023
- if (!disposed) updateSaveState(result);
30463
+ if (!disposed) {
30464
+ updateSaveState(result);
30465
+ if (didSave) showSaved();
30466
+ }
30024
30467
  }
30025
30468
  }
30026
30469
  function destroyDiff() {
@@ -30039,16 +30482,20 @@ function mountTextFile(parent, options) {
30039
30482
  comparison = active;
30040
30483
  editPane.hidden = active;
30041
30484
  diffPane.hidden = !active;
30042
- press(edit, !active);
30043
- press(diff, active);
30485
+ text.setAttribute("aria-checked", String(!active));
30486
+ diff.setAttribute("aria-checked", String(active));
30487
+ text.tabIndex = active ? -1 : 0;
30488
+ diff.tabIndex = active ? 0 : -1;
30044
30489
  if (active) loadBaseline();
30045
30490
  else {
30046
30491
  ++readVersion;
30492
+ baselineLoading = false;
30047
30493
  destroyDiff();
30048
30494
  }
30049
30495
  }
30050
30496
  async function loadBaseline() {
30051
30497
  const version = ++readVersion;
30498
+ baselineLoading = true;
30052
30499
  destroyDiff();
30053
30500
  headings.hidden = true;
30054
30501
  changes.disabled = whole.disabled = true;
@@ -30097,18 +30544,21 @@ function mountTextFile(parent, options) {
30097
30544
  }
30098
30545
  });
30099
30546
  headings.hidden = false;
30100
- changes.disabled = whole.disabled = false;
30547
+ changes.disabled = whole.disabled = externalLocked;
30101
30548
  changeVisibility(changesOnly);
30102
30549
  const notice = !base.head ? message.unborn : !base.bytes ? message.missing : merge.chunks.length ? "" : text === edited ? message.same : message.formatting;
30103
30550
  setStatus(diffStatus, notice);
30104
30551
  } catch (error) {
30105
30552
  if (current()) setStatus(diffStatus, (error === null || error === void 0 ? void 0 : error.code) === "large" ? message.tooLarge : message.readFailed);
30106
30553
  } finally {
30107
- if (current()) refresh.disabled = !options.readBaseline;
30554
+ if (current()) {
30555
+ baselineLoading = false;
30556
+ refresh.disabled = externalLocked || !options.readBaseline;
30557
+ }
30108
30558
  }
30109
30559
  }
30110
30560
  const beforeUnload = (event) => {
30111
- if (!dirty()) return;
30561
+ if (!dirty() && !externalLocked) return;
30112
30562
  event.preventDefault();
30113
30563
  event.returnValue = "";
30114
30564
  };
@@ -30122,19 +30572,31 @@ function mountTextFile(parent, options) {
30122
30572
  browser === null || browser === void 0 || browser.addEventListener("beforeunload", beforeUnload);
30123
30573
  showDiff(false);
30124
30574
  updateSaveState();
30575
+ if (browser) connectExternalFileEditor(browser, options.path.split("/").pop(), options.extension, options.limit).then((editor) => {
30576
+ if (disposed) {
30577
+ editor === null || editor === void 0 || editor.close();
30578
+ return;
30579
+ }
30580
+ externalEditor = editor;
30581
+ if (editor) externalButton.title = message.external;
30582
+ updateSaveState(status.textContent || "");
30583
+ });
30125
30584
  return {
30126
30585
  save,
30127
30586
  isDirty: dirty,
30128
30587
  readUnsaved: () => !disposed && dirty() ? encoder.encode(serialize()) : void 0,
30129
30588
  requestClose() {
30130
- if (!saving && (!dirty() || (browser === null || browser === void 0 ? void 0 : browser.confirm(message.close)))) options.close();
30589
+ if (!saving && !externalLocked && (!dirty() || (browser === null || browser === void 0 ? void 0 : browser.confirm(message.close)))) options.close();
30131
30590
  },
30132
30591
  dispose() {
30133
30592
  disposed = true;
30593
+ hideSnackbar();
30594
+ toolbarObserver === null || toolbarObserver === void 0 || toolbarObserver.disconnect();
30595
+ externalEditor === null || externalEditor === void 0 || externalEditor.close();
30134
30596
  browser === null || browser === void 0 || browser.removeEventListener("beforeunload", beforeUnload);
30135
30597
  destroyDiff();
30136
30598
  view.destroy();
30137
- panel.remove();
30599
+ shell.remove();
30138
30600
  }
30139
30601
  };
30140
30602
  }