mbeditor 0.14.1 → 0.14.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/app/assets/javascripts/mbeditor/application.js +5 -1
  4. data/app/assets/javascripts/mbeditor/collaboration_identity.js +4 -2
  5. data/app/assets/javascripts/mbeditor/collaboration_service.js +74 -2
  6. data/app/assets/javascripts/mbeditor/components/AiRoundTripModal.js +452 -0
  7. data/app/assets/javascripts/mbeditor/components/ChangelogView.js +1 -1
  8. data/app/assets/javascripts/mbeditor/components/CombinedFileView.js +44 -29
  9. data/app/assets/javascripts/mbeditor/components/DiffViewer.js +2 -1
  10. data/app/assets/javascripts/mbeditor/components/EditorPanel.js +33 -27
  11. data/app/assets/javascripts/mbeditor/components/FileHistoryPanel.js +2 -7
  12. data/app/assets/javascripts/mbeditor/components/FileTree.js +144 -4
  13. data/app/assets/javascripts/mbeditor/components/GitPanel.js +1 -1
  14. data/app/assets/javascripts/mbeditor/components/ImportConflictModal.js +7 -68
  15. data/app/assets/javascripts/mbeditor/components/ImportDialog.js +2 -16
  16. data/app/assets/javascripts/mbeditor/components/MbeditorApp.js +368 -471
  17. data/app/assets/javascripts/mbeditor/components/ModalDialog.js +203 -0
  18. data/app/assets/javascripts/mbeditor/components/PastePlaceModal.js +1 -9
  19. data/app/assets/javascripts/mbeditor/components/Popover.js +88 -0
  20. data/app/assets/javascripts/mbeditor/components/PopupMenu.js +166 -0
  21. data/app/assets/javascripts/mbeditor/components/ProblemsPanel.js +8 -4
  22. data/app/assets/javascripts/mbeditor/components/QuickOpenDialog.js +5 -7
  23. data/app/assets/javascripts/mbeditor/components/SettingsModal.js +3 -14
  24. data/app/assets/javascripts/mbeditor/components/ShortcutHelp.js +5 -26
  25. data/app/assets/javascripts/mbeditor/components/TabBar.js +15 -32
  26. data/app/assets/javascripts/mbeditor/components/TestResultsPanel.js +2 -7
  27. data/app/assets/javascripts/mbeditor/editor_plugins.js +3 -23
  28. data/app/assets/javascripts/mbeditor/file_service.js +1 -1
  29. data/app/assets/javascripts/mbeditor/git_service.js +0 -7
  30. data/app/assets/javascripts/mbeditor/patch_select.js +156 -0
  31. data/app/assets/javascripts/mbeditor/tab_manager.js +22 -0
  32. data/app/assets/stylesheets/mbeditor/application.css +7 -110
  33. data/app/assets/stylesheets/mbeditor/editor.css +200 -194
  34. data/app/assets/stylesheets/mbeditor/glass.css +1 -1
  35. data/app/channels/mbeditor/collaboration_channel.rb +24 -5
  36. data/app/controllers/mbeditor/editors_controller.rb +75 -38
  37. data/app/controllers/mbeditor/git_controller.rb +1 -12
  38. data/app/services/mbeditor/ai_bundle_service.rb +181 -0
  39. data/app/services/mbeditor/archive_service.rb +43 -6
  40. data/app/services/mbeditor/availability_probe.rb +2 -2
  41. data/app/services/mbeditor/code_search_service.rb +1 -3
  42. data/app/services/mbeditor/collaboration_doc_store.rb +37 -1
  43. data/app/services/mbeditor/exclusion_matcher.rb +0 -4
  44. data/app/services/mbeditor/file_import_service.rb +4 -1
  45. data/app/services/mbeditor/file_operation_service.rb +3 -3
  46. data/app/services/mbeditor/git_service.rb +11 -45
  47. data/app/services/mbeditor/js_definition_service.rb +1 -0
  48. data/app/services/mbeditor/model_graph_service.rb +1 -0
  49. data/app/services/mbeditor/patch_apply_service.rb +185 -0
  50. data/app/services/mbeditor/rails_related_files_service.rb +1 -1
  51. data/app/services/mbeditor/redmine_config_error.rb +6 -0
  52. data/app/services/mbeditor/redmine_disabled_error.rb +10 -0
  53. data/app/services/mbeditor/redmine_service.rb +0 -8
  54. data/app/services/mbeditor/ruby_definition_service.rb +1 -0
  55. data/app/services/mbeditor/schema_service.rb +1 -0
  56. data/app/services/mbeditor/test_runner_service.rb +1 -1
  57. data/lib/mbeditor/rack/silence_ping_request.rb +14 -14
  58. data/lib/mbeditor/route_map.rb +5 -2
  59. data/lib/mbeditor/ruby_lsp_client.rb +7 -26
  60. data/lib/mbeditor/version.rb +1 -1
  61. data/public/monaco-editor/VERSIONS +2 -1
  62. data/public/monaco-editor/monaco.js +226 -226
  63. metadata +11 -4
  64. data/app/assets/javascripts/mbeditor/components/CommitGraph.js +0 -65
  65. data/app/services/mbeditor/git_commit_graph_service.rb +0 -62
@@ -0,0 +1,452 @@
1
+ 'use strict';
2
+
3
+ // Round trip with a web chat: "Export" downloads the chosen directories as one
4
+ // markdown bundle to upload; "Apply diff" checks and applies the unified diff
5
+ // the chat replies with. Reuses the schema-modal shell and the import-conflict
6
+ // buttons; refreshing open tabs after an apply is left to the files_changed
7
+ // broadcast the server sends for the write.
8
+ var AI_SELECTION_KEY = 'mbeditor.aiBundle.selection';
9
+
10
+ function aiFolderPaths(nodes, into) {
11
+ nodes.forEach(function (n) {
12
+ if (n.type !== 'folder') return;
13
+ into[n.path] = true;
14
+ aiFolderPaths(n.children || [], into);
15
+ });
16
+ return into;
17
+ }
18
+
19
+ // A saved directory that has since been deleted would 404 the whole export, so
20
+ // saved dirs are checked against the tree (when it has loaded).
21
+ function aiLoadSelection(treeData) {
22
+ try {
23
+ var saved = JSON.parse(localStorage.getItem(AI_SELECTION_KEY) || '{}');
24
+ var dirs = Array.isArray(saved.dirs) ? saved.dirs : [];
25
+ if (treeData.length) {
26
+ var known = aiFolderPaths(treeData, {});
27
+ dirs = dirs.filter(function (d) { return known[d]; });
28
+ }
29
+ return { dirs: dirs, topFiles: saved.topFiles === true };
30
+ } catch (e) {
31
+ return { dirs: [], topFiles: false };
32
+ }
33
+ }
34
+
35
+ function aiHumanSize(bytes) {
36
+ return bytes >= 1048576 ? (bytes / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(bytes / 1024)) + ' KB';
37
+ }
38
+
39
+ // A pasted bundle lands entirely in the chat's context; no sandbox sees it.
40
+ var AI_PASTE_TOKEN_WARN = 100000;
41
+
42
+ var AI_COLORIZE_MAX_LINES = 2000;
43
+
44
+ function aiHeaderClass(text) {
45
+ return /^(---|\+\+\+) /.test(text) ? 'file' : 'meta';
46
+ }
47
+
48
+ function aiBodyClass(c) {
49
+ return c === '+' ? 'add' : c === '-' ? 'del' : c === '\\' ? 'meta' : 'ctx';
50
+ }
51
+
52
+ // One hunk. Plain text nodes first; when Monaco can tokenise the file's
53
+ // language the code is swapped for its markup, keeping the +/- line colours.
54
+ var AiDiffHunk = function AiDiffHunk(_ref) {
55
+ var h = React.createElement;
56
+ var lines = _ref.text.replace(/\n$/, '').split('\n');
57
+ var body = lines.slice(1);
58
+ var _html = React.useState(null);
59
+ var html = _html[0];
60
+ var setHtml = _html[1];
61
+
62
+ React.useEffect(function () {
63
+ setHtml(null);
64
+ var lang = window.MbeditorLanguageForPath && window.MbeditorLanguageForPath(_ref.path);
65
+ if (!lang || body.length > AI_COLORIZE_MAX_LINES) return undefined;
66
+ var cancelled = false;
67
+ var code = body.filter(function (l) { return l[0] !== '\\'; }).map(function (l) { return l.slice(1); });
68
+ try {
69
+ window.monaco.editor.colorize(code.join('\n'), lang, {}).then(function (out) {
70
+ var parts = out.split('<br/>');
71
+ if (parts.length === code.length + 1 && parts[parts.length - 1] === '') parts.pop();
72
+ if (!cancelled && parts.length === code.length) setHtml(parts);
73
+ }, function () { /* plain text stays */ });
74
+ } catch (e) { /* plain text stays */ }
75
+ return function () { cancelled = true; };
76
+ }, [_ref.text, _ref.path]);
77
+
78
+ var n = 0;
79
+ return h('div', { className: _ref.on ? '' : 'ai-diff-off' },
80
+ h('div', { className: 'ai-diff-line ai-diff-hunk ai-hunk-row' }, _ref.checkbox, lines[0]),
81
+ body.map(function (l, i) {
82
+ var colored = html && l[0] !== '\\' ? html[n++] : null;
83
+ return h('div', { key: i, className: 'ai-diff-line ai-diff-' + aiBodyClass(l[0]) },
84
+ h('span', { className: 'ai-diff-prefix' }, l[0] || ' '),
85
+ // colorize returns Monaco's own escaped token markup, built from the
86
+ // diff text but never containing it raw; this is the one place HTML
87
+ // is injected, and nothing else from the patch goes through it.
88
+ colored !== null
89
+ ? h('span', { dangerouslySetInnerHTML: { __html: colored } })
90
+ : l.slice(1));
91
+ }));
92
+ };
93
+
94
+ var AiRoundTripModal = function AiRoundTripModal(_ref) {
95
+ var h = React.createElement;
96
+ var treeData = _ref.treeData || [];
97
+ var onClose = _ref.onClose;
98
+
99
+ var _tab = React.useState('export');
100
+ var tab = _tab[0];
101
+ var setTab = _tab[1];
102
+
103
+ var initial = React.useMemo(function () { return aiLoadSelection(treeData); }, []);
104
+ var _dirs = React.useState(initial.dirs);
105
+ var dirs = _dirs[0];
106
+ var setDirs = _dirs[1];
107
+ var _top = React.useState(initial.topFiles);
108
+ var topFiles = _top[0];
109
+ var setTopFiles = _top[1];
110
+ var _open = React.useState({});
111
+ var open = _open[0];
112
+ var setOpen = _open[1];
113
+ var _exp = React.useState({ busy: false, error: null, stats: null, pendingCopy: null, notice: null });
114
+ var exp = _exp[0];
115
+ var setExp = _exp[1];
116
+
117
+ // Fetched on open so the click can call writeText synchronously and keep the
118
+ // user gesture in Safari.
119
+ var _prompt = React.useState(null);
120
+ var promptText = _prompt[0];
121
+ var setPromptText = _prompt[1];
122
+ React.useEffect(function () {
123
+ fetch(window.mbeditorBasePath() + '/ai_bundle?prompt=1').then(function (r) {
124
+ return r.ok ? r.text() : null;
125
+ }).then(setPromptText, function () { setPromptText(null); });
126
+ }, []);
127
+
128
+ var _patch = React.useState('');
129
+ var patch = _patch[0];
130
+ var setPatch = _patch[1];
131
+ var _apply = React.useState({ busy: false, error: null, files: null, checkedPatch: null, applied: false });
132
+ var apply = _apply[0];
133
+ var setApply = _apply[1];
134
+
135
+ var rootFiles = treeData.filter(function (n) { return n.type === 'file'; });
136
+
137
+ var persist = function (nextDirs, nextTop) {
138
+ try { localStorage.setItem(AI_SELECTION_KEY, JSON.stringify({ dirs: nextDirs, topFiles: nextTop })); } catch (e) { /* storage unavailable */ }
139
+ };
140
+ var toggleDir = function (path) {
141
+ var next = dirs.indexOf(path) === -1 ? dirs.concat(path) : dirs.filter(function (p) { return p !== path; });
142
+ setDirs(next);
143
+ persist(next, topFiles);
144
+ };
145
+ var toggleTop = function () {
146
+ setTopFiles(!topFiles);
147
+ persist(dirs, !topFiles);
148
+ };
149
+ var coveredBy = function (path) {
150
+ return dirs.some(function (d) { return path.indexOf(d + '/') === 0; });
151
+ };
152
+
153
+ var selectedPaths = dirs.filter(function (d) { return !coveredBy(d); })
154
+ .concat(topFiles ? rootFiles.map(function (f) { return f.path; }) : []);
155
+
156
+ var errorMessage = function (err) {
157
+ return (err && err.response && err.response.data && err.response.data.error) || (err && err.message) || 'Request failed';
158
+ };
159
+
160
+ var fetchBundle = function () {
161
+ var url = window.mbeditorBasePath() + '/ai_bundle?' + selectedPaths.map(function (p) {
162
+ return 'paths[]=' + encodeURIComponent(p);
163
+ }).join('&');
164
+ return fetch(url).then(function (resp) {
165
+ if (!resp.ok) {
166
+ return resp.json().catch(function () { return {}; }).then(function (body) {
167
+ throw new Error((body && body.error) || ('HTTP ' + resp.status));
168
+ });
169
+ }
170
+ var disposition = resp.headers.get('Content-Disposition');
171
+ var match = disposition && disposition.match(/filename="([^"]+)"/);
172
+ var num = function (name) { return parseInt(resp.headers.get(name), 10) || 0; };
173
+ return resp.blob().then(function (blob) {
174
+ return {
175
+ blob: blob, filename: (match && match[1]) || 'bundle.md',
176
+ stats: {
177
+ files: num('X-Mbeditor-Bundle-Files'), bytes: num('X-Mbeditor-Bundle-Bytes')
178
+ }
179
+ };
180
+ });
181
+ });
182
+ };
183
+
184
+ var idle = { busy: false, error: null, stats: null, pendingCopy: null, notice: null };
185
+
186
+ var download = function () {
187
+ setExp(Object.assign({}, idle, { busy: true }));
188
+ fetchBundle().then(function (r) {
189
+ var objectUrl = URL.createObjectURL(r.blob);
190
+ var link = document.createElement('a');
191
+ link.href = objectUrl;
192
+ link.download = r.filename;
193
+ link.rel = 'noopener';
194
+ document.body.appendChild(link);
195
+ link.click();
196
+ document.body.removeChild(link);
197
+ setTimeout(function () { URL.revokeObjectURL(objectUrl); }, 60000);
198
+ setExp(Object.assign({}, idle, { stats: Object.assign({ filename: r.filename }, r.stats) }));
199
+ }).catch(function (err) {
200
+ setExp(Object.assign({}, idle, { error: err.message || 'network error' }));
201
+ });
202
+ };
203
+
204
+ var copied = function (stats) {
205
+ setExp(Object.assign({}, idle, { stats: Object.assign({ filename: 'Copied' }, stats), notice: 'Copied to clipboard.' }));
206
+ };
207
+
208
+ var copyFailed = function (err) {
209
+ setExp(Object.assign({}, idle, { error: 'Could not copy: ' + (err && err.message || 'clipboard unavailable') }));
210
+ };
211
+
212
+ var writeClipboard = function (text, stats) {
213
+ return navigator.clipboard.writeText(text).then(function () { copied(stats); }, copyFailed);
214
+ };
215
+
216
+ // Safari drops the user gesture across an async fetch, so where ClipboardItem
217
+ // exists the write starts synchronously inside the click and is handed a
218
+ // promise for the text. An oversized bundle rejects that promise, so nothing
219
+ // is copied, and the text kept in `big` goes to "Copy anyway", which writes
220
+ // inside its own click.
221
+ var copyBundle = function () {
222
+ setExp(Object.assign({}, idle, { busy: true }));
223
+ var big = null;
224
+ var stats = null;
225
+ var buildError = null;
226
+ var load = fetchBundle().then(function (r) {
227
+ stats = r.stats;
228
+ return r.blob.text().then(function (text) {
229
+ if (r.stats.bytes / 4 > AI_PASTE_TOKEN_WARN) {
230
+ big = text;
231
+ throw new Error('Over ' + AI_PASTE_TOKEN_WARN.toLocaleString() + ' tokens, not copied');
232
+ }
233
+ return text;
234
+ });
235
+ }, function (err) {
236
+ buildError = err;
237
+ throw err;
238
+ });
239
+ var fail = function (err) {
240
+ if (big !== null) setExp(Object.assign({}, idle, { pendingCopy: { text: big, stats: stats } }));
241
+ else if (buildError) setExp(Object.assign({}, idle, { error: 'Could not build bundle: ' + (buildError.message || 'request failed') }));
242
+ else copyFailed(err);
243
+ };
244
+ if (window.ClipboardItem && navigator.clipboard && navigator.clipboard.write) {
245
+ var item = new ClipboardItem({
246
+ 'text/plain': load.then(function (text) { return new Blob([text], { type: 'text/plain' }); })
247
+ });
248
+ navigator.clipboard.write([item]).then(function () { copied(stats); }, fail);
249
+ } else {
250
+ load.then(function (text) { return writeClipboard(text, stats); }, fail);
251
+ }
252
+ };
253
+
254
+ var copyPrompt = function () {
255
+ navigator.clipboard.writeText(promptText).then(function () {
256
+ setExp(Object.assign({}, idle, { notice: 'Prompt copied. Fill in the TASK line after pasting.' }));
257
+ }, copyFailed);
258
+ };
259
+
260
+ var loadPatchFile = function (e) {
261
+ var file = e.target.files && e.target.files[0];
262
+ e.target.value = '';
263
+ if (!file) return;
264
+ file.text().then(function (text) {
265
+ setPatch(text);
266
+ setApply({ busy: false, error: null, files: null, checkedPatch: null, applied: false });
267
+ });
268
+ };
269
+
270
+ var postPatch = function (text, check) {
271
+ return axios.post(window.mbeditorBasePath() + '/apply_patch', { patch: text, check: check });
272
+ };
273
+
274
+ var check = function () {
275
+ var text = patch;
276
+ setApply({ busy: true, error: null, files: null, checkedPatch: null, applied: false });
277
+ postPatch(text, true).then(function (resp) {
278
+ var parsed = window.MbeditorPatchSelect.parse(resp.data.patch);
279
+ setApply({
280
+ busy: false, error: null, files: resp.data.files, checkedPatch: text, applied: false,
281
+ diff: resp.data.patch, parsed: parsed, sel: window.MbeditorPatchSelect.defaultSelection(parsed)
282
+ });
283
+ }, function (err) {
284
+ setApply({ busy: false, error: errorMessage(err), files: null, checkedPatch: null, applied: false });
285
+ });
286
+ };
287
+
288
+ var dirtyTouched = function () {
289
+ var touched = {};
290
+ window.MbeditorPatchSelect.touchedPaths(apply.parsed, apply.sel, apply.files).forEach(function (p) { touched[p] = true; });
291
+ var names = [];
292
+ EditorStore.getState().panes.forEach(function (p) {
293
+ p.tabs.forEach(function (t) { if (t.dirty && touched[t.path]) names.push(t.path); });
294
+ });
295
+ return names;
296
+ };
297
+
298
+ var applyPatch = function () {
299
+ var dirty = dirtyTouched();
300
+ if (dirty.length) {
301
+ setApply(Object.assign({}, apply, { error: 'Save or close these files first, they have unsaved changes: ' + dirty.join(', ') }));
302
+ return;
303
+ }
304
+ setApply(Object.assign({}, apply, { busy: true, error: null }));
305
+ postPatch(window.MbeditorPatchSelect.build(apply.parsed, apply.sel), false).then(function (resp) {
306
+ setApply({ busy: false, error: null, files: resp.data.files, checkedPatch: null, applied: true });
307
+ }, function (err) {
308
+ setApply(Object.assign({}, apply, { busy: false, error: errorMessage(err) }));
309
+ });
310
+ };
311
+
312
+ var setSel = function (i, next) {
313
+ var sel = apply.sel.slice();
314
+ sel[i] = next;
315
+ setApply(Object.assign({}, apply, { sel: sel }));
316
+ };
317
+
318
+ var renderDir = function (node, covered) {
319
+ var folders = (node.children || []).filter(function (c) { return c.type === 'folder'; });
320
+ var isOpen = open[node.path];
321
+ return h('li', { key: node.path },
322
+ h('div', { className: 'ai-dir-row' },
323
+ h('button', {
324
+ type: 'button', className: 'ai-dir-toggle', disabled: folders.length === 0,
325
+ 'aria-label': (isOpen ? 'Collapse ' : 'Expand ') + node.name,
326
+ onClick: function () { var o = Object.assign({}, open); o[node.path] = !isOpen; setOpen(o); }
327
+ }, h('i', { className: 'fas fa-chevron-' + (isOpen ? 'down' : 'right'), style: { opacity: folders.length ? 1 : 0 } })),
328
+ h('label', null,
329
+ h('input', {
330
+ type: 'checkbox', checked: covered || dirs.indexOf(node.path) !== -1, disabled: covered,
331
+ onChange: function () { toggleDir(node.path); }
332
+ }),
333
+ ' ' + node.name)),
334
+ isOpen && folders.length > 0 && h('ul', { className: 'ai-dir-list' },
335
+ folders.map(function (c) { return renderDir(c, covered || dirs.indexOf(node.path) !== -1); })));
336
+ };
337
+
338
+ var exportPane = h('div', { className: 'ai-pane' },
339
+ h('p', { className: 'ai-hint' }, 'Pick what the assistant should see. Upload the .md to the chat, then paste the prompt with it.'),
340
+ h('ul', { className: 'ai-dir-list' },
341
+ treeData.filter(function (n) { return n.type === 'folder' && n.name !== '.git'; }).map(function (n) { return renderDir(n, false); }),
342
+ h('li', { key: '__top_files' },
343
+ h('div', { className: 'ai-dir-row' },
344
+ h('span', { className: 'ai-dir-toggle' }),
345
+ h('label', null,
346
+ h('input', { type: 'checkbox', checked: topFiles, onChange: toggleTop }),
347
+ ' Top-level files (' + rootFiles.length + ')')))),
348
+ exp.error && h('div', { className: 'ai-error' }, exp.error),
349
+ exp.pendingCopy && h('div', { className: 'ai-error' },
350
+ 'About ' + Math.round(exp.pendingCopy.stats.bytes / 4).toLocaleString() + ' tokens. Pasted text goes entirely into the chat context and no sandbox sees it. Prefer Download .md. ',
351
+ h('button', {
352
+ type: 'button', className: 'import-conflict-btn',
353
+ onClick: function () { writeClipboard(exp.pendingCopy.text, exp.pendingCopy.stats); }
354
+ }, 'Copy anyway')),
355
+ exp.stats && h('div', { className: 'ai-result' },
356
+ exp.stats.filename + ': ' + exp.stats.files + ' files, ' + aiHumanSize(exp.stats.bytes) +
357
+ ', about ' + Math.round(exp.stats.bytes / 4).toLocaleString() + ' tokens'),
358
+ exp.notice && h('div', { className: 'ai-result' }, exp.notice)
359
+ );
360
+
361
+ var filesList = apply.files && h('ul', { className: 'import-conflict-list ai-files' },
362
+ apply.files.map(function (f) {
363
+ return h('li', { key: f.path, title: f.path },
364
+ h('span', { className: 'ai-status ai-status-' + f.status }, f.status),
365
+ ' ' + (f.from ? f.from + ' -> ' : '') + f.path + ' +' + f.added + ' -' + f.removed);
366
+ }));
367
+
368
+ var previewing = !apply.applied && !!apply.diff && apply.checkedPatch === patch;
369
+
370
+ var applyPane = h('div', { className: 'ai-pane' },
371
+ !previewing && h('p', { className: 'ai-hint' }, 'Paste the assistant\'s reply. Surrounding text and the code fence are ignored.'),
372
+ !previewing && h('label', { className: 'ai-file' }, 'Load .patch file: ',
373
+ h('input', { type: 'file', accept: '.patch,.diff,.txt', onChange: loadPatchFile })),
374
+ !previewing && h('textarea', {
375
+ className: 'ai-patch', value: patch, spellCheck: false, placeholder: 'diff --git a/... b/...',
376
+ onChange: function (e) { setPatch(e.target.value); }
377
+ }),
378
+ apply.error && h('pre', { className: 'ai-error' }, apply.error),
379
+ apply.applied && h('div', { className: 'ai-result' }, 'Applied ' + apply.files.length + ' file' + (apply.files.length === 1 ? '' : 's') + '.'),
380
+ previewing && h('div', { className: 'ai-result' }, 'Check passed. Will change:',
381
+ h('button', { type: 'button', className: 'ai-edit-diff', onClick: function () {
382
+ setApply({ busy: false, error: null, files: null, checkedPatch: null, applied: false });
383
+ } }, 'Edit diff')),
384
+ apply.applied && filesList,
385
+ previewing && h('div', { className: 'ai-diff', tabIndex: 0, 'aria-label': 'Diff preview' },
386
+ apply.parsed.map(function (f, i) {
387
+ var s = apply.sel[i];
388
+ var all = s.every(Boolean);
389
+ var some = s.some(Boolean);
390
+ return h('div', { key: i },
391
+ h('label', { className: 'ai-file-row' },
392
+ h('input', {
393
+ type: 'checkbox', checked: all,
394
+ ref: function (el) { if (el) el.indeterminate = some && !all; },
395
+ onChange: function () { setSel(i, s.map(function () { return !all; })); }
396
+ }),
397
+ h('span', { className: 'ai-status ai-status-' + f.status }, f.status),
398
+ (f.from ? f.from + ' -> ' : '') + f.path),
399
+ h('div', { className: some ? '' : 'ai-diff-off' },
400
+ f.header.replace(/\n$/, '').split('\n').map(function (l, k) {
401
+ return h('div', { key: k, className: 'ai-diff-line ai-diff-' + aiHeaderClass(l) }, l);
402
+ })),
403
+ f.hunks.map(function (text, j) {
404
+ return h(AiDiffHunk, {
405
+ key: j, text: text, path: f.path, on: f.atomic ? s[0] : s[j],
406
+ checkbox: f.atomic ? null : h('input', {
407
+ type: 'checkbox', checked: !!s[j], 'aria-label': 'Include hunk',
408
+ onChange: function () { var next = s.slice(); next[j] = !s[j]; setSel(i, next); }
409
+ })
410
+ });
411
+ }));
412
+ }))
413
+ );
414
+
415
+ var counts = previewing ? window.MbeditorPatchSelect.count(apply.parsed, apply.sel) : null;
416
+ var canApply = previewing && counts.selected > 0 && !apply.busy;
417
+ var exportDisabled = exp.busy || selectedPaths.length === 0;
418
+ var footer = tab === 'export'
419
+ ? [
420
+ h('button', { key: 'prompt', type: 'button', className: 'import-conflict-btn', disabled: promptText === null, onClick: copyPrompt }, 'Copy prompt'),
421
+ h('button', { key: 'copy', type: 'button', className: 'import-conflict-btn', disabled: exportDisabled, onClick: copyBundle }, 'Copy to clipboard'),
422
+ h('button', { key: 'md', type: 'button', className: 'import-conflict-btn import-conflict-btn-primary', disabled: exportDisabled, onClick: download }, exp.busy ? 'Building...' : 'Download .md')
423
+ ]
424
+ : [
425
+ h('button', {
426
+ key: 'check', type: 'button', className: 'import-conflict-btn',
427
+ disabled: apply.busy || !patch.trim(), onClick: check
428
+ }, 'Check'),
429
+ h('button', {
430
+ key: 'apply', type: 'button', className: 'import-conflict-btn import-conflict-btn-primary',
431
+ disabled: !canApply, onClick: applyPatch
432
+ }, counts ? 'Apply ' + counts.selected + ' of ' + counts.total + ' changes' : 'Apply')
433
+ ];
434
+
435
+ var tabButton = function (id, label) {
436
+ return h('button', {
437
+ type: 'button', role: 'tab', 'aria-selected': tab === id,
438
+ className: 'ai-tab' + (tab === id ? ' active' : ''), onClick: function () { setTab(id); }
439
+ }, label);
440
+ };
441
+
442
+ return h(window.ModalDialog, { className: 'schema-modal ai-modal', label: 'AI export and apply', onDismiss: onClose },
443
+ h('div', { className: 'schema-modal-header' },
444
+ h('div', { className: 'ai-tabs', role: 'tablist' }, tabButton('export', 'Export'), tabButton('apply', 'Apply diff'))),
445
+ h('div', { className: 'schema-modal-body' }, tab === 'export' ? exportPane : applyPane),
446
+ h('div', { className: 'import-conflict-actions' },
447
+ h('button', { type: 'button', className: 'import-conflict-btn', onClick: onClose }, 'Close'),
448
+ footer)
449
+ );
450
+ };
451
+
452
+ window.AiRoundTripModal = AiRoundTripModal;
@@ -53,7 +53,7 @@
53
53
  return '<h1 class="changelog-h1">' + text + '</h1>\n';
54
54
  };
55
55
 
56
- renderer.list = function(body, ordered, start) {
56
+ renderer.list = function(body, ordered) {
57
57
  var tag = ordered ? 'ol' : 'ul';
58
58
  var cls = ordered ? '' : ' class="changelog-list"';
59
59
  return '<' + tag + cls + '>\n' + body + '</' + tag + '>\n';
@@ -18,17 +18,6 @@
18
18
  return lang ? lang.id : null;
19
19
  }
20
20
 
21
- function download(path) {
22
- var link = document.createElement('a');
23
- link.href = window.mbeditorBasePath() + '/raw?download=1&path=' + encodeURIComponent(path);
24
- link.download = path.split('/').pop();
25
- link.rel = 'noopener';
26
- document.body.appendChild(link);
27
- link.click();
28
- document.body.removeChild(link);
29
- EditorStore.setStatus('Downloading ' + link.download + '...', 'info');
30
- }
31
-
32
21
  function copyText(text, okMsg, failMsg) {
33
22
  if (!navigator.clipboard) return;
34
23
  navigator.clipboard.writeText(text).then(
@@ -51,7 +40,7 @@
51
40
  function close(n) {
52
41
  while (open.length > n) { var o = open.pop(); out.push(indentOf(lines[o.start_line - 1]) + 'end'); }
53
42
  }
54
- info.methods.filter(function (m, i) { return picked[i]; })
43
+ info.methods.filter(function (_m, i) { return picked[i]; })
55
44
  .sort(function (a, b) { return a.start_line - b.start_line; })
56
45
  .forEach(function (m) {
57
46
  var chain = info.owners.filter(function (o) { return contains(o, m); });
@@ -76,23 +65,28 @@
76
65
  }
77
66
 
78
67
  // paths: ordered file paths; files: path -> loaded entry; info: path -> {methods, owners};
79
- // picked: path -> {methodIndex: true}. A file with any picked method exports only those.
80
- function buildMarkdown(paths, files, info, picked) {
68
+ // picked: path -> {methodIndex: true}; excluded: path -> true. A file with any picked
69
+ // method exports only those. Returns '' when no loaded file is included.
70
+ function buildMarkdown(paths, files, info, picked, excluded) {
71
+ var index = [];
81
72
  var parts = [];
82
73
  paths.forEach(function (path) {
83
74
  var e = files[path];
84
- if (!e || e.content == null) return;
75
+ if (excluded[path] || !e || e.content == null) return;
85
76
  var sel = picked[path] || {};
86
77
  var body = e.content;
78
+ var line = '- ' + path;
87
79
  if (info[path] && info[path].methods && Object.keys(sel).some(function (k) { return sel[k]; })) {
88
80
  body = methodSlice(e.content, info[path], sel);
81
+ line += ' (methods: ' + info[path].methods.filter(function (_m, i) { return sel[i]; }).map(function (m) { return m.name; }).join(', ') + ')';
89
82
  }
83
+ index.push(line);
90
84
  var fence = fenceFor(body);
91
85
  var ext = (/\.([^./]+)$/.exec(path) || [])[1] || '';
92
86
  var lang = { rb: 'ruby', js: 'javascript', jsx: 'jsx', ts: 'typescript', tsx: 'tsx', yml: 'yaml', md: 'markdown', sh: 'bash' }[ext] || ext;
93
87
  parts.push('## ' + path + '\n\n' + fence + lang + '\n' + body.replace(/\n$/, '') + '\n' + fence + '\n');
94
88
  });
95
- return parts.join('\n');
89
+ return index.length ? '# Files\n' + index.join('\n') + '\n\n' + parts.join('\n') : '';
96
90
  }
97
91
 
98
92
  function bundleName() {
@@ -143,6 +137,10 @@
143
137
  });
144
138
  }, [paths, files]);
145
139
 
140
+ var _x = useState({});
141
+ var excluded = _x[0];
142
+ var setExcluded = _x[1];
143
+
146
144
  var toggle = function (path, i) {
147
145
  setPicked(function (prev) {
148
146
  var o = Object.assign({}, prev);
@@ -151,8 +149,18 @@
151
149
  o[path] = sel;
152
150
  return o;
153
151
  });
152
+ setExcluded(function (prev) { var o = Object.assign({}, prev); delete o[path]; return o; });
154
153
  };
155
154
 
155
+ var toggleFile = function (path) {
156
+ setExcluded(function (prev) { var o = Object.assign({}, prev); if (o[path]) delete o[path]; else o[path] = true; return o; });
157
+ };
158
+
159
+ var exportMd = function (action) {
160
+ var md = buildMarkdown(paths, files, info, picked, excluded);
161
+ if (!md) { EditorStore.setStatus('No files selected', 'info'); return; }
162
+ action(md);
163
+ };
156
164
 
157
165
  useEffect(function () {
158
166
  var cancelled = false;
@@ -180,8 +188,24 @@
180
188
 
181
189
  return React.createElement('div', { className: 'combined-view' },
182
190
  React.createElement('div', { className: 'combined-toolbar' },
183
- React.createElement('button', { type: 'button', className: 'combined-file-btn', onClick: function () { downloadText(buildMarkdown(paths, files, info, picked), bundleName()); } }, 'Download .md'),
184
- React.createElement('button', { type: 'button', className: 'combined-file-btn', onClick: function () { copyText(buildMarkdown(paths, files, info, picked), 'Copied Markdown bundle', 'Could not copy Markdown bundle'); } }, 'Copy .md')
191
+ React.createElement('button', { type: 'button', className: 'combined-file-btn', onClick: function () { exportMd(function (md) { copyText(md, 'Copied Markdown bundle', 'Could not copy Markdown bundle'); }); } }, 'Copy .md'),
192
+ React.createElement('button', { type: 'button', className: 'combined-file-btn', onClick: function () { exportMd(function (md) { downloadText(md, bundleName()); }); } }, 'Download .md')
193
+ ),
194
+ React.createElement('div', { className: 'combined-picker' },
195
+ paths.map(function (path) {
196
+ var methods = info[path] && info[path].methods;
197
+ return React.createElement('div', { key: path },
198
+ React.createElement('label', { className: 'combined-pick-file' },
199
+ React.createElement('input', { type: 'checkbox', checked: !excluded[path], onChange: function () { toggleFile(path); } }),
200
+ path),
201
+ methods && methods.map(function (m, i) {
202
+ var label = (m.owner ? m.owner + (m.singleton ? '.' : '#') : (m.singleton ? '.' : '#')) + m.name;
203
+ return React.createElement('label', { key: i, className: 'combined-pick-method', title: 'lines ' + m.start_line + '-' + m.end_line },
204
+ React.createElement('input', { type: 'checkbox', checked: !!(picked[path] && picked[path][i]), onChange: function () { toggle(path, i); } }),
205
+ label);
206
+ })
207
+ );
208
+ })
185
209
  ),
186
210
  props.total > paths.length && React.createElement('div', { className: 'combined-note' },
187
211
  'Showing the first ' + paths.length + ' of ' + props.total + ' files.'),
@@ -189,17 +213,7 @@
189
213
  var e = files[path];
190
214
  return React.createElement('section', { key: path, className: 'combined-file' },
191
215
  React.createElement('div', { className: 'combined-file-header' },
192
- React.createElement('span', { className: 'combined-file-path' }, path),
193
- React.createElement('button', { type: 'button', className: 'combined-file-btn', disabled: !e || e.content == null, onClick: function () { copyText(e.content, 'Copied ' + path, 'Could not copy ' + path); } }, 'Copy'),
194
- React.createElement('button', { type: 'button', className: 'combined-file-btn', onClick: function () { download(path); } }, 'Download')
195
- ),
196
- info[path] && info[path].methods && info[path].methods.length > 0 && React.createElement('div', { className: 'combined-methods' },
197
- info[path].methods.map(function (m, i) {
198
- var label = (m.owner ? m.owner + (m.singleton ? '.' : '#') : (m.singleton ? '.' : '#')) + m.name;
199
- return React.createElement('label', { key: i, className: 'combined-method', title: 'lines ' + m.start_line + '-' + m.end_line },
200
- React.createElement('input', { type: 'checkbox', checked: !!(picked[path] && picked[path][i]), onChange: function () { toggle(path, i); } }),
201
- label);
202
- })
216
+ React.createElement('span', { className: 'combined-file-path' }, path)
203
217
  ),
204
218
  !e ? React.createElement('div', { className: 'combined-note' }, 'Loading...') :
205
219
  e.note ? React.createElement('div', { className: 'combined-note' }, e.note) :
@@ -210,5 +224,6 @@
210
224
  );
211
225
  };
212
226
 
227
+ window.MbeditorLanguageForPath = languageFor;
213
228
  window.CombinedFileView = CombinedFileView;
214
229
  })();
@@ -39,7 +39,8 @@ var DiffViewer = function DiffViewer(_ref) {
39
39
  scrollBeyondLastLine: false,
40
40
  fontFamily: editorPrefs.fontFamily || "'JetBrains Mono', 'Fira Code', 'Menlo', 'Consolas', monospace",
41
41
  fontSize: editorPrefs.fontSize || 13,
42
- wordWrap: editorPrefs.wordWrap || 'off'
42
+ wordWrap: editorPrefs.wordWrap || 'off',
43
+ useShadowDOM: false // same unthemed-context-menu reason as EditorPanel
43
44
  });
44
45
 
45
46
  diffEditor.setModel({