pinokiod 8.3.23 → 8.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/index.js +12 -5
- package/server/lib/app_run_tabs.js +51 -0
- package/server/public/agent-bar.js +1 -1
- package/server/public/app-run-tabs.js +30 -0
- package/server/public/files-app/open-folder.js +77 -0
- package/server/public/files-app/toolbar.css +28 -0
- package/server/public/git-page.css +521 -0
- package/server/public/git-page.js +625 -0
- package/server/public/universal-launcher.js +4 -4
- package/server/public/urldropdown.js +0 -1
- package/server/routes/git_page.js +30 -0
- package/server/views/app.ejs +24 -29
- package/server/views/file_browser.ejs +17 -31
- package/server/views/git_page.ejs +21 -0
- package/server/views/index.ejs +2 -2
- package/server/views/partials/home_action_modal.ejs +0 -7
- package/test/launch-settings-ui.test.js +1 -1
- package/test/url-split-modal.test.js +1 -1
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
// The app's Git page (server/views/git_page.ejs), opened as a tab on the app page.
|
|
2
|
+
//
|
|
3
|
+
// Repositories on the left, with their status. The selected repository's four
|
|
4
|
+
// sections on the right: Changes, History, Fork, Publish. Everything is drawn on
|
|
5
|
+
// the page: forms, confirmations and the terminal of a running git script all
|
|
6
|
+
// appear in the section itself. Nothing opens as a popup.
|
|
7
|
+
//
|
|
8
|
+
// The status is checked when the page opens, each time its tab is brought to the
|
|
9
|
+
// front, when Refresh is pressed, and after an action that changes it. Never on a
|
|
10
|
+
// timer, and never by watching files.
|
|
11
|
+
(() => {
|
|
12
|
+
const root = document.getElementById('git-page')
|
|
13
|
+
if (!root) {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
const appName = root.dataset.name || ''
|
|
17
|
+
const appCwd = root.dataset.cwd || ''
|
|
18
|
+
const SECTIONS = ['changes', 'history', 'fork', 'publish']
|
|
19
|
+
|
|
20
|
+
const state = {
|
|
21
|
+
repos: [], // from the last check
|
|
22
|
+
checkedAt: 0,
|
|
23
|
+
checking: null,
|
|
24
|
+
error: '',
|
|
25
|
+
repoKey: null, // selected repository
|
|
26
|
+
section: root.dataset.publish === '1' ? 'publish' : 'changes',
|
|
27
|
+
info: new Map(), // repoKey -> history data (commits, branches, remote, GitHub state)
|
|
28
|
+
changes: null, // the Changes section: { repoKey, selected:Set, open:index, message, messageEdited, confirmReset, error }
|
|
29
|
+
commit: null, // the History section's open commit: { oid, title, changes, open, cwd }
|
|
30
|
+
publishSkipCommit: new Set(),
|
|
31
|
+
run: null, // a running script: { title, url, finished, afterClose }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------- helpers
|
|
35
|
+
const h = (tag, props, ...children) => {
|
|
36
|
+
const node = document.createElement(tag)
|
|
37
|
+
Object.entries(props || {}).forEach(([key, value]) => {
|
|
38
|
+
if (value === false || value === null || value === undefined) return
|
|
39
|
+
if (key === 'class') node.className = value
|
|
40
|
+
else if (key === 'text') node.textContent = value
|
|
41
|
+
else if (key.startsWith('on')) node.addEventListener(key.slice(2), value)
|
|
42
|
+
else if (key in node && key !== 'list') node[key] = value
|
|
43
|
+
else node.setAttribute(key, value)
|
|
44
|
+
})
|
|
45
|
+
children.flat().forEach((child) => {
|
|
46
|
+
if (child === false || child === null || child === undefined) return
|
|
47
|
+
node.append(child.nodeType ? child : document.createTextNode(String(child)))
|
|
48
|
+
})
|
|
49
|
+
return node
|
|
50
|
+
}
|
|
51
|
+
const icon = (name) => h('i', { class: name, 'aria-hidden': 'true' })
|
|
52
|
+
const button = (label, onclick, options = {}) => h('button', {
|
|
53
|
+
type: 'button',
|
|
54
|
+
class: `git-btn${options.primary ? ' git-btn--primary' : ''}${options.danger ? ' git-btn--danger' : ''}`,
|
|
55
|
+
disabled: Boolean(options.disabled),
|
|
56
|
+
title: options.title || null,
|
|
57
|
+
onclick,
|
|
58
|
+
}, options.icon ? icon(options.icon) : null, label)
|
|
59
|
+
const notice = (title, text, ...actions) => h('div', { class: 'git-notice' },
|
|
60
|
+
h('div', { class: 'git-notice-title', text: title }),
|
|
61
|
+
text ? h('div', { class: 'git-notice-text', text }) : null,
|
|
62
|
+
actions.length ? h('div', { class: 'git-notice-actions' }, actions) : null)
|
|
63
|
+
|
|
64
|
+
const encodeRepoPath = (value) => String(value || '').split('/').map(encodeURIComponent).join('/')
|
|
65
|
+
const isOid = (value) => typeof value === 'string' && /^[0-9a-f]{7,40}$/i.test(value)
|
|
66
|
+
const isUntracked = (status) => /new|add|untracked/i.test(status || '')
|
|
67
|
+
const shellQuote = (value) => `"${String(value).replace(/(["`$\\])/g, '\\$1')}"`
|
|
68
|
+
const getJson = async (url) => {
|
|
69
|
+
const response = await fetch(url, { cache: 'no-store' })
|
|
70
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
71
|
+
return response.json()
|
|
72
|
+
}
|
|
73
|
+
const repo = () => state.repos.find((entry) => entry.repoParam === state.repoKey) || null
|
|
74
|
+
const hasRemote = (entry) => Boolean(entry && typeof entry.url === 'string' && entry.url.trim())
|
|
75
|
+
const cwdOf = (entry) => {
|
|
76
|
+
const info = entry ? state.info.get(entry.repoParam) : null
|
|
77
|
+
if (info && info.dir) return info.dir
|
|
78
|
+
const source = entry && (entry.git_push_url || entry.git_commit_url)
|
|
79
|
+
if (source) {
|
|
80
|
+
try {
|
|
81
|
+
const cwd = new URL(source, window.location.origin).searchParams.get('cwd')
|
|
82
|
+
if (cwd) return cwd
|
|
83
|
+
} catch (_) {}
|
|
84
|
+
}
|
|
85
|
+
return appCwd
|
|
86
|
+
}
|
|
87
|
+
const scriptUrl = (name, cwd, params = {}) => {
|
|
88
|
+
const query = new URLSearchParams({ cwd, ...params })
|
|
89
|
+
return `/run/scripts/git/${name}.json?${query.toString()}`
|
|
90
|
+
}
|
|
91
|
+
// a script that tells the page when it is done
|
|
92
|
+
const callbackUrl = (name, cwd, params = {}) => `${scriptUrl(name, cwd, params)}&callback_target=parent&callback=$location.href`
|
|
93
|
+
|
|
94
|
+
const remoteWebUrl = (remoteUrl) => {
|
|
95
|
+
const raw = typeof remoteUrl === 'string' ? remoteUrl.trim() : ''
|
|
96
|
+
if (!raw) return ''
|
|
97
|
+
if (/^https?:\/\//i.test(raw)) return raw.replace(/\.git$/i, '')
|
|
98
|
+
const ssh = raw.match(/^ssh:\/\/(?:[^@/]+@)?([^/]+)\/(.+?)(?:\.git)?$/i)
|
|
99
|
+
if (ssh) return `https://${ssh[1]}/${ssh[2]}`
|
|
100
|
+
const scp = raw.match(/^(?:[^@]+@)?([^:/]+):(.+?)(?:\.git)?$/)
|
|
101
|
+
if (scp) return `https://${scp[1]}/${scp[2]}`
|
|
102
|
+
return ''
|
|
103
|
+
}
|
|
104
|
+
const openExternal = (url) => {
|
|
105
|
+
const agent = document.body.getAttribute('data-agent')
|
|
106
|
+
window.open(url, '_blank', agent === 'electron' ? 'browser' : undefined)
|
|
107
|
+
}
|
|
108
|
+
const forkDefaultName = (entry) => {
|
|
109
|
+
const web = remoteWebUrl(entry && entry.url)
|
|
110
|
+
const fromRemote = web.split('/').filter(Boolean).pop()
|
|
111
|
+
if (fromRemote) return fromRemote
|
|
112
|
+
const fromName = String((entry && (entry.name || entry.repoParam)) || '').split('/').filter(Boolean).pop()
|
|
113
|
+
return fromName || appName || 'fork'
|
|
114
|
+
}
|
|
115
|
+
const suggestMessage = (changes) => {
|
|
116
|
+
if (!changes.length) return 'Update files'
|
|
117
|
+
const groups = { Add: [], Update: [], Delete: [], Rename: [] }
|
|
118
|
+
changes.forEach((change) => {
|
|
119
|
+
const status = String(change.status || '').toLowerCase()
|
|
120
|
+
if (status.includes('new') || status.includes('add')) groups.Add.push(change.file)
|
|
121
|
+
else if (status.includes('delete') || status.includes('remove')) groups.Delete.push(change.file)
|
|
122
|
+
else if (status.includes('rename') || status.includes('moved')) groups.Rename.push(change.file)
|
|
123
|
+
else groups.Update.push(change.file)
|
|
124
|
+
})
|
|
125
|
+
return Object.entries(groups)
|
|
126
|
+
.filter(([, files]) => files.length)
|
|
127
|
+
.map(([verb, files]) => (files.length === 1 ? `${verb} ${files[0]}` : `${verb} ${files.length} files`))
|
|
128
|
+
.join(', ')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ------------------------------------------------------------------ data
|
|
132
|
+
const check = () => {
|
|
133
|
+
if (state.checking) return state.checking
|
|
134
|
+
state.checking = (async () => {
|
|
135
|
+
try {
|
|
136
|
+
const data = await getJson(`/info/gitstatus/${encodeURIComponent(appName)}?force=1`)
|
|
137
|
+
let repos = Array.isArray(data.repos) ? data.repos : []
|
|
138
|
+
if (repos.length === 0) {
|
|
139
|
+
// a folder with no repository yet: its files, ready for a first commit
|
|
140
|
+
const fallback = await getJson(`/gitcommit/HEAD/${encodeRepoPath(appName)}`)
|
|
141
|
+
const changes = Array.isArray(fallback.changes) ? fallback.changes : []
|
|
142
|
+
repos = [{
|
|
143
|
+
name: appName,
|
|
144
|
+
main: true,
|
|
145
|
+
repoParam: appName,
|
|
146
|
+
changeCount: changes.length,
|
|
147
|
+
changes,
|
|
148
|
+
git_commit_url: fallback.git_commit_url || null,
|
|
149
|
+
url: null,
|
|
150
|
+
}]
|
|
151
|
+
}
|
|
152
|
+
repos.sort((a, b) => (a.main === b.main ? String(a.name).localeCompare(String(b.name)) : (a.main ? -1 : 1)))
|
|
153
|
+
state.repos = repos
|
|
154
|
+
state.error = ''
|
|
155
|
+
if (!repos.some((entry) => entry.repoParam === state.repoKey)) {
|
|
156
|
+
state.repoKey = repos[0] ? repos[0].repoParam : null
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
state.error = 'Could not load the repositories.'
|
|
160
|
+
}
|
|
161
|
+
state.info.clear()
|
|
162
|
+
state.checkedAt = Date.now()
|
|
163
|
+
state.checking = null
|
|
164
|
+
render()
|
|
165
|
+
})()
|
|
166
|
+
render()
|
|
167
|
+
return state.checking
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// History data for the selected repository: commits, branches, remote and
|
|
171
|
+
// whether GitHub is connected. Loaded when a section needs it, kept until the
|
|
172
|
+
// next check.
|
|
173
|
+
const loadInfo = (key) => {
|
|
174
|
+
const known = state.info.get(key)
|
|
175
|
+
if (known) return known.pending || Promise.resolve(known)
|
|
176
|
+
const pending = getJson(`/info/git/HEAD/${encodeRepoPath(key)}`)
|
|
177
|
+
.catch(() => ({ failed: true }))
|
|
178
|
+
.then((data) => {
|
|
179
|
+
if (state.info.get(key) && state.info.get(key).pending === pending) {
|
|
180
|
+
state.info.set(key, data)
|
|
181
|
+
render()
|
|
182
|
+
}
|
|
183
|
+
return data
|
|
184
|
+
})
|
|
185
|
+
state.info.set(key, { pending })
|
|
186
|
+
return pending
|
|
187
|
+
}
|
|
188
|
+
const infoOf = (key) => {
|
|
189
|
+
const data = state.info.get(key)
|
|
190
|
+
if (!data) {
|
|
191
|
+
loadInfo(key)
|
|
192
|
+
return null
|
|
193
|
+
}
|
|
194
|
+
return data.pending ? null : data
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ------------------------------------------------------- running a script
|
|
198
|
+
// A git script runs in Pinokio's terminal view, shown in the section. Scripts
|
|
199
|
+
// that report back (commit, checkout) close it themselves; the others show
|
|
200
|
+
// their output until Close is pressed.
|
|
201
|
+
const run = (title, url, afterClose) => {
|
|
202
|
+
state.run = { title, url, finished: false, afterClose: afterClose || null }
|
|
203
|
+
render()
|
|
204
|
+
}
|
|
205
|
+
const closeRun = () => {
|
|
206
|
+
const finished = state.run
|
|
207
|
+
state.run = null
|
|
208
|
+
const done = check()
|
|
209
|
+
if (finished && finished.afterClose) {
|
|
210
|
+
done.then(finished.afterClose)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
window.addEventListener('message', (event) => {
|
|
214
|
+
const data = event.data
|
|
215
|
+
if (!data) return
|
|
216
|
+
if (event.source === window.parent && window.parent !== window) {
|
|
217
|
+
// the app page tells the tab it brings to the front
|
|
218
|
+
if (data.action === 'foreground' && !state.run && Date.now() - state.checkedAt > 2000) {
|
|
219
|
+
check()
|
|
220
|
+
}
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
if (!state.run) return
|
|
224
|
+
if (typeof data.callback === 'string' && data.callback.startsWith('$')) {
|
|
225
|
+
closeRun()
|
|
226
|
+
} else if (data.type === 'pinokio:socket-closed') {
|
|
227
|
+
state.run.finished = true
|
|
228
|
+
const footer = root.querySelector('.git-run-status')
|
|
229
|
+
if (footer) footer.textContent = 'Finished.'
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
const runPanel = () => h('div', { class: 'git-run' },
|
|
233
|
+
h('div', { class: 'git-run-header' },
|
|
234
|
+
h('div', { class: 'git-run-title', text: state.run.title }),
|
|
235
|
+
h('div', { class: 'git-run-status', text: state.run.finished ? 'Finished.' : '' }),
|
|
236
|
+
button('Close', closeRun)),
|
|
237
|
+
h('iframe', { class: 'git-run-frame', src: state.run.url, allow: 'fullscreen *' }))
|
|
238
|
+
|
|
239
|
+
// ------------------------------------------------------------- file diffs
|
|
240
|
+
const diffLines = (data) => {
|
|
241
|
+
if (data.binary) return h('div', { class: 'git-empty', text: 'Binary file' })
|
|
242
|
+
if (!Array.isArray(data.diff) || data.diff.length === 0) {
|
|
243
|
+
return h('div', { class: 'git-empty', text: 'No changes to display' })
|
|
244
|
+
}
|
|
245
|
+
return h('div', { class: 'git-diff-lines' }, data.diff.map((line) => h('div', {
|
|
246
|
+
class: `git-diff-line${line.type === 'add' ? ' git-diff-line--add' : line.type === 'del' ? ' git-diff-line--del' : ''}`,
|
|
247
|
+
},
|
|
248
|
+
h('span', { class: 'git-diff-num', text: line.lineOld === null || line.lineOld === undefined ? '' : String(line.lineOld) }),
|
|
249
|
+
h('span', { class: 'git-diff-num', text: line.lineNew === null || line.lineNew === undefined ? '' : String(line.lineNew) }),
|
|
250
|
+
h('span', { class: 'git-diff-code', text: line.line }))))
|
|
251
|
+
}
|
|
252
|
+
// The diff of one changed file, with a button that opens the file itself.
|
|
253
|
+
const diffViewer = (change, repoKey) => {
|
|
254
|
+
const body = h('div', { class: 'git-diff-body' }, h('div', { class: 'git-empty', text: 'Loading...' }))
|
|
255
|
+
getJson(change.diffpath)
|
|
256
|
+
.then((data) => body.replaceChildren(diffLines(data)))
|
|
257
|
+
.catch(() => body.replaceChildren(h('div', { class: 'git-empty', text: 'Could not load the diff' })))
|
|
258
|
+
const relative = String(change.file || '').split('/').map(encodeURIComponent).join('/')
|
|
259
|
+
return h('div', { class: 'git-diff' },
|
|
260
|
+
h('div', { class: 'git-diff-header' },
|
|
261
|
+
h('div', { class: 'git-diff-title', text: change.file }),
|
|
262
|
+
button('Open in explorer', () => { fetch(`/api/${encodeRepoPath(repoKey)}/${relative}?fs=view`).catch(() => {}) }, { icon: 'fa-solid fa-folder-open' })),
|
|
263
|
+
body)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ---------------------------------------------------------------- Changes
|
|
267
|
+
const changesSection = (entry) => {
|
|
268
|
+
const changes = Array.isArray(entry.changes) ? entry.changes : []
|
|
269
|
+
if (!state.changes || state.changes.repoKey !== entry.repoParam || state.changes.count !== changes.length) {
|
|
270
|
+
state.changes = {
|
|
271
|
+
repoKey: entry.repoParam,
|
|
272
|
+
count: changes.length,
|
|
273
|
+
selected: new Set(changes.map((_, index) => index)),
|
|
274
|
+
open: changes.length ? 0 : -1,
|
|
275
|
+
message: '',
|
|
276
|
+
messageEdited: false,
|
|
277
|
+
confirmReset: false,
|
|
278
|
+
error: '',
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const view = state.changes
|
|
282
|
+
if (changes.length === 0) {
|
|
283
|
+
return h('div', { class: 'git-empty', text: 'No changes. Everything is committed.' })
|
|
284
|
+
}
|
|
285
|
+
const picked = changes.filter((_, index) => view.selected.has(index))
|
|
286
|
+
if (!view.messageEdited) {
|
|
287
|
+
view.message = suggestMessage(picked)
|
|
288
|
+
}
|
|
289
|
+
const tracked = picked.filter((change) => !isUntracked(change.status)).map((change) => change.path || change.file)
|
|
290
|
+
const untracked = picked.filter((change) => isUntracked(change.status)).map((change) => change.path || change.file)
|
|
291
|
+
|
|
292
|
+
const selectAll = h('input', {
|
|
293
|
+
type: 'checkbox',
|
|
294
|
+
checked: picked.length === changes.length,
|
|
295
|
+
onchange: (event) => {
|
|
296
|
+
view.selected = new Set(event.target.checked ? changes.map((_, index) => index) : [])
|
|
297
|
+
render()
|
|
298
|
+
},
|
|
299
|
+
})
|
|
300
|
+
selectAll.indeterminate = picked.length > 0 && picked.length < changes.length
|
|
301
|
+
|
|
302
|
+
const files = h('div', { class: 'git-files' },
|
|
303
|
+
h('label', { class: 'git-file git-file--all' }, selectAll, h('span', { class: 'git-file-name', text: 'Select all' })),
|
|
304
|
+
changes.map((change, index) => h('div', {
|
|
305
|
+
class: `git-file${view.open === index ? ' git-file--open' : ''}`,
|
|
306
|
+
onclick: () => { view.open = index; render() },
|
|
307
|
+
},
|
|
308
|
+
h('input', {
|
|
309
|
+
type: 'checkbox',
|
|
310
|
+
checked: view.selected.has(index),
|
|
311
|
+
onclick: (event) => event.stopPropagation(),
|
|
312
|
+
onchange: (event) => {
|
|
313
|
+
if (event.target.checked) view.selected.add(index)
|
|
314
|
+
else view.selected.delete(index)
|
|
315
|
+
render()
|
|
316
|
+
},
|
|
317
|
+
}),
|
|
318
|
+
h('span', { class: 'git-file-name', text: change.file, title: change.file }),
|
|
319
|
+
h('span', { class: 'git-file-status', text: change.status }))),
|
|
320
|
+
h('div', { class: 'git-files-actions' },
|
|
321
|
+
view.confirmReset
|
|
322
|
+
? h('div', { class: 'git-confirm' },
|
|
323
|
+
h('div', { class: 'git-confirm-text', text: `Discard the changes in ${picked.length} file${picked.length === 1 ? '' : 's'}? This cannot be undone.` }),
|
|
324
|
+
button('Discard', async () => {
|
|
325
|
+
view.confirmReset = false
|
|
326
|
+
view.error = ''
|
|
327
|
+
try {
|
|
328
|
+
const response = await fetch('/terminals/git/reset-files', {
|
|
329
|
+
method: 'POST',
|
|
330
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
331
|
+
body: JSON.stringify({ cwd: cwdOf(entry), tracked_paths: tracked, untracked_paths: untracked }),
|
|
332
|
+
})
|
|
333
|
+
const payload = await response.json().catch(() => null)
|
|
334
|
+
if (!response.ok || !payload || payload.ok !== true) {
|
|
335
|
+
throw new Error(payload && payload.error ? payload.error : 'Failed to reset selected files.')
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
view.error = error.message
|
|
339
|
+
}
|
|
340
|
+
check()
|
|
341
|
+
}, { danger: true }),
|
|
342
|
+
button('Cancel', () => { view.confirmReset = false; render() }))
|
|
343
|
+
: button(`Reset selected (${picked.length})`, () => { view.confirmReset = true; render() }, {
|
|
344
|
+
icon: 'fa-solid fa-arrow-rotate-left',
|
|
345
|
+
disabled: picked.length === 0,
|
|
346
|
+
})))
|
|
347
|
+
|
|
348
|
+
const messageInput = h('input', {
|
|
349
|
+
type: 'text',
|
|
350
|
+
class: 'git-input',
|
|
351
|
+
value: view.message,
|
|
352
|
+
placeholder: 'Commit message',
|
|
353
|
+
'aria-label': 'Commit message',
|
|
354
|
+
oninput: (event) => {
|
|
355
|
+
view.message = event.target.value
|
|
356
|
+
view.messageEdited = true
|
|
357
|
+
},
|
|
358
|
+
})
|
|
359
|
+
const commit = () => {
|
|
360
|
+
const message = view.message.trim() || suggestMessage(picked)
|
|
361
|
+
const params = { message }
|
|
362
|
+
if (tracked.length) params.paths = tracked.map(shellQuote).join(' ')
|
|
363
|
+
if (untracked.length) params.untracked_paths = untracked.map(shellQuote).join(' ')
|
|
364
|
+
state.changes = null
|
|
365
|
+
run(`Committing ${picked.length} file${picked.length === 1 ? '' : 's'}`, callbackUrl('commit_files', cwdOf(entry), params))
|
|
366
|
+
}
|
|
367
|
+
return h('div', { class: 'git-changes' },
|
|
368
|
+
view.error ? h('div', { class: 'git-error', text: view.error }) : null,
|
|
369
|
+
h('div', { class: 'git-split' },
|
|
370
|
+
files,
|
|
371
|
+
view.open >= 0 && changes[view.open] ? diffViewer(changes[view.open], entry.repoParam) : h('div', { class: 'git-empty', text: 'Select a file to view its changes' })),
|
|
372
|
+
h('div', { class: 'git-commit-bar' },
|
|
373
|
+
messageInput,
|
|
374
|
+
button('Commit', commit, { primary: true, disabled: picked.length === 0, title: picked.length === 0 ? 'Select at least one file' : null })))
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ---------------------------------------------------------------- History
|
|
378
|
+
const commitView = (entry) => {
|
|
379
|
+
const view = state.commit
|
|
380
|
+
const checkout = () => {
|
|
381
|
+
state.commit = null
|
|
382
|
+
run(`Checking out ${view.oid.slice(0, 7)}`, callbackUrl('checkout', view.cwd, { commit: view.oid }))
|
|
383
|
+
}
|
|
384
|
+
return h('div', { class: 'git-commit' },
|
|
385
|
+
h('div', { class: 'git-commit-header' },
|
|
386
|
+
button('History', () => { state.commit = null; render() }, { icon: 'fa-solid fa-arrow-left' }),
|
|
387
|
+
h('div', { class: 'git-commit-title', text: view.title, title: view.title }),
|
|
388
|
+
h('code', { class: 'git-oid', text: view.oid.slice(0, 7) }),
|
|
389
|
+
button('Check out this commit', checkout, { icon: 'fa-solid fa-clock-rotate-left' })),
|
|
390
|
+
!view.changes
|
|
391
|
+
? h('div', { class: 'git-empty', text: view.failed ? 'Could not load this commit' : 'Loading...' })
|
|
392
|
+
: view.changes.length === 0
|
|
393
|
+
? h('div', { class: 'git-empty', text: 'No file changes in this commit' })
|
|
394
|
+
: h('div', { class: 'git-split' },
|
|
395
|
+
h('div', { class: 'git-files' }, view.changes.map((change, index) => h('div', {
|
|
396
|
+
class: `git-file${view.open === index ? ' git-file--open' : ''}`,
|
|
397
|
+
onclick: () => { view.open = index; render() },
|
|
398
|
+
},
|
|
399
|
+
h('span', { class: 'git-file-name', text: change.file, title: change.file }),
|
|
400
|
+
h('span', { class: 'git-file-status', text: change.status })))),
|
|
401
|
+
diffViewer(view.changes[view.open], entry.repoParam)))
|
|
402
|
+
}
|
|
403
|
+
const openCommit = (entry, info, item) => {
|
|
404
|
+
const view = { oid: item.oid, title: String(item.commit.message || '').split('\n')[0], changes: null, open: 0, cwd: info.dir || cwdOf(entry) }
|
|
405
|
+
state.commit = view
|
|
406
|
+
render()
|
|
407
|
+
getJson(item.info)
|
|
408
|
+
.then((data) => { view.changes = Array.isArray(data.changes) ? data.changes : [] })
|
|
409
|
+
.catch(() => { view.failed = true })
|
|
410
|
+
.then(() => { if (state.commit === view) render() })
|
|
411
|
+
}
|
|
412
|
+
const historySection = (entry) => {
|
|
413
|
+
if (state.commit) return commitView(entry)
|
|
414
|
+
const info = infoOf(entry.repoParam)
|
|
415
|
+
if (!info) return h('div', { class: 'git-empty', text: 'Loading history...' })
|
|
416
|
+
if (info.failed) return h('div', { class: 'git-empty', text: 'Could not load the history' })
|
|
417
|
+
const commits = Array.isArray(info.log) ? info.log : []
|
|
418
|
+
const cwd = info.dir || cwdOf(entry)
|
|
419
|
+
const branches = (Array.isArray(info.branches) ? info.branches : [])
|
|
420
|
+
.map((item) => item && item.branch)
|
|
421
|
+
.filter((name) => typeof name === 'string' && name && !isOid(name))
|
|
422
|
+
const current = typeof info.branch === 'string' && !isOid(info.branch) && info.branch !== 'HEAD' ? info.branch : null
|
|
423
|
+
const checkout = (target) => run(`Checking out ${target}`, callbackUrl('checkout', cwd, { commit: target }))
|
|
424
|
+
const newest = current || ['main', 'master', 'develop', 'dev'].find((name) => branches.includes(name)) || branches[0] || null
|
|
425
|
+
const select = branches.length
|
|
426
|
+
? h('select', { class: 'git-input git-input--select', 'aria-label': 'Select branch' },
|
|
427
|
+
branches.map((name) => h('option', { value: name, selected: name === current, text: name })))
|
|
428
|
+
: null
|
|
429
|
+
const web = remoteWebUrl(info.remote)
|
|
430
|
+
const last = commits[0]
|
|
431
|
+
const summary = [`${commits.length} commit${commits.length === 1 ? '' : 's'}`]
|
|
432
|
+
if (last && window.timeago) summary.push(`Updated ${timeago.format(new Date(last.commit.author.timestamp * 1000))}`)
|
|
433
|
+
return h('div', { class: 'git-history' },
|
|
434
|
+
h('div', { class: 'git-history-bar' },
|
|
435
|
+
h('div', { class: 'git-history-summary' },
|
|
436
|
+
h('span', { text: summary.join(' · ') }),
|
|
437
|
+
web ? h('a', { class: 'git-link', href: web, text: web.replace(/^https?:\/\//, ''), onclick: (event) => { event.preventDefault(); openExternal(web) } }) : null),
|
|
438
|
+
h('div', { class: 'git-history-viewing', text: `Currently viewing ${current || info.ref || 'HEAD'}` }),
|
|
439
|
+
button('Return to newest commit', () => checkout(newest), { icon: 'fa-solid fa-arrow-rotate-left', disabled: !newest }),
|
|
440
|
+
select,
|
|
441
|
+
select ? button('Switch', () => checkout(select.value), { icon: 'fa-solid fa-code-branch' }) : null),
|
|
442
|
+
commits.length === 0
|
|
443
|
+
? h('div', { class: 'git-empty', text: info.logError ? 'No commits yet' : 'No commits' })
|
|
444
|
+
: h('div', { class: 'git-commits' }, commits.map((item) => h('button', {
|
|
445
|
+
type: 'button',
|
|
446
|
+
class: 'git-commit-row',
|
|
447
|
+
onclick: () => openCommit(entry, info, item),
|
|
448
|
+
},
|
|
449
|
+
h('div', { class: 'git-commit-message', text: String(item.commit.message || '').split('\n')[0] }),
|
|
450
|
+
h('div', { class: 'git-commit-meta' },
|
|
451
|
+
h('span', { text: item.commit.author.name }),
|
|
452
|
+
window.timeago ? h('span', { text: timeago.format(new Date(item.commit.author.timestamp * 1000)) }) : null,
|
|
453
|
+
h('code', { class: 'git-oid', text: item.oid.slice(0, 7) }))))))
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// ------------------------------------------------------- Fork and Publish
|
|
457
|
+
const loginNotice = (purpose) => notice(
|
|
458
|
+
'Log in to GitHub',
|
|
459
|
+
`Connect your GitHub account to ${purpose}.`,
|
|
460
|
+
button('Log in', () => { (window.parent || window).location.href = '/github' }, { primary: true, icon: 'fa-brands fa-github' }))
|
|
461
|
+
|
|
462
|
+
const forkSection = (entry) => {
|
|
463
|
+
const info = infoOf(entry.repoParam)
|
|
464
|
+
if (!info) return h('div', { class: 'git-empty', text: 'Loading...' })
|
|
465
|
+
if (!info.connected) return loginNotice('fork this repository')
|
|
466
|
+
if (!hasRemote(entry)) {
|
|
467
|
+
return notice('Remote required', 'This repository does not have a remote configured, so it cannot be forked.')
|
|
468
|
+
}
|
|
469
|
+
const name = h('input', { type: 'text', class: 'git-input', value: forkDefaultName(entry), id: 'git-fork-name' })
|
|
470
|
+
const org = h('input', { type: 'text', class: 'git-input', placeholder: 'Organization name', 'aria-label': 'Organization name' })
|
|
471
|
+
const orgRow = h('div', { class: 'git-field', hidden: true }, org)
|
|
472
|
+
const toOrg = h('input', { type: 'checkbox', onchange: (event) => { orgRow.hidden = !event.target.checked; if (event.target.checked) org.focus() } })
|
|
473
|
+
const error = h('div', { class: 'git-error', hidden: true })
|
|
474
|
+
const submit = () => {
|
|
475
|
+
const forkName = name.value.trim()
|
|
476
|
+
const orgName = toOrg.checked ? org.value.trim() : ''
|
|
477
|
+
if (!forkName || (toOrg.checked && !orgName)) {
|
|
478
|
+
error.textContent = !forkName ? 'Enter a repository name for the fork' : 'Enter the organization name or uncheck the option'
|
|
479
|
+
error.hidden = false
|
|
480
|
+
return
|
|
481
|
+
}
|
|
482
|
+
const params = { name: forkName, ts: Date.now() }
|
|
483
|
+
if (orgName) params.org = orgName
|
|
484
|
+
run(`Forking ${entry.name} as ${forkName}`, scriptUrl('fork', cwdOf(entry), params))
|
|
485
|
+
}
|
|
486
|
+
return h('div', { class: 'git-form' },
|
|
487
|
+
h('div', { class: 'git-form-title', text: 'Fork repository' }),
|
|
488
|
+
h('div', { class: 'git-form-remote', text: entry.url }),
|
|
489
|
+
h('label', { class: 'git-label', for: 'git-fork-name', text: 'Fork name' }),
|
|
490
|
+
h('div', { class: 'git-field' }, name),
|
|
491
|
+
h('label', { class: 'git-check' }, toOrg, 'Fork into organization'),
|
|
492
|
+
orgRow,
|
|
493
|
+
error,
|
|
494
|
+
h('div', { class: 'git-form-actions' }, button('Fork on GitHub', submit, { primary: true, icon: 'fa-brands fa-github' })))
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const publishSection = (entry) => {
|
|
498
|
+
const info = infoOf(entry.repoParam)
|
|
499
|
+
if (!info) return h('div', { class: 'git-empty', text: 'Loading...' })
|
|
500
|
+
if (info.failed) return notice('Unable to check repository state', 'Refresh and try again.')
|
|
501
|
+
if (!info.connected) return loginNotice('publish this workspace')
|
|
502
|
+
const review = button('Review files', () => { state.section = 'changes'; render() }, { primary: true })
|
|
503
|
+
if (info.gitDirExists === false) {
|
|
504
|
+
return notice(`${entry.name} isn't a Git repository yet`, 'Initialize git in this folder and save a version before publishing.', review)
|
|
505
|
+
}
|
|
506
|
+
const hasHead = typeof info.hasHead === 'boolean' ? info.hasHead : (Array.isArray(info.log) && info.log.length > 0)
|
|
507
|
+
if (!hasHead) {
|
|
508
|
+
return notice(`Create your first commit for ${entry.name}`, 'Save a version on the main branch before publishing to GitHub.', review)
|
|
509
|
+
}
|
|
510
|
+
const count = Number(entry.changeCount) || 0
|
|
511
|
+
if (count > 0 && !state.publishSkipCommit.has(entry.repoParam)) {
|
|
512
|
+
return notice(
|
|
513
|
+
`${count} uncommitted change${count === 1 ? '' : 's'}`,
|
|
514
|
+
'Commit them first if you want them included in what you publish.',
|
|
515
|
+
button('Review and commit', () => { state.section = 'changes'; render() }, { primary: true }),
|
|
516
|
+
button('Continue without committing', () => { state.publishSkipCommit.add(entry.repoParam); render() }))
|
|
517
|
+
}
|
|
518
|
+
if (!hasRemote(entry)) {
|
|
519
|
+
const name = h('input', { type: 'text', class: 'git-input', placeholder: 'Enter repository name', id: 'git-create-name' })
|
|
520
|
+
const isPrivate = h('input', { type: 'checkbox' })
|
|
521
|
+
const error = h('div', { class: 'git-error', hidden: true, text: 'Repository name is required' })
|
|
522
|
+
const submit = () => {
|
|
523
|
+
const repoName = name.value.trim()
|
|
524
|
+
if (!repoName) {
|
|
525
|
+
error.hidden = false
|
|
526
|
+
return
|
|
527
|
+
}
|
|
528
|
+
run(`Creating ${repoName} on GitHub`, scriptUrl('create', cwdOf(entry), { name: repoName, visibility: isPrivate.checked ? 'private' : 'public' }))
|
|
529
|
+
}
|
|
530
|
+
return h('div', { class: 'git-form' },
|
|
531
|
+
h('div', { class: 'git-form-title', text: 'Create a GitHub repository' }),
|
|
532
|
+
h('div', { class: 'git-form-remote', text: `${entry.name} has no remote yet. Create one on GitHub to publish it.` }),
|
|
533
|
+
h('label', { class: 'git-label', for: 'git-create-name', text: 'Repository name' }),
|
|
534
|
+
h('div', { class: 'git-field' }, name),
|
|
535
|
+
h('label', { class: 'git-check' }, isPrivate, 'Private repository'),
|
|
536
|
+
error,
|
|
537
|
+
h('div', { class: 'git-form-actions' }, button('Create on GitHub', submit, { primary: true, icon: 'fa-brands fa-github' })))
|
|
538
|
+
}
|
|
539
|
+
const web = remoteWebUrl(entry.url)
|
|
540
|
+
return h('div', { class: 'git-form' },
|
|
541
|
+
h('div', { class: 'git-form-title', text: 'Publish to GitHub' }),
|
|
542
|
+
h('div', { class: 'git-form-remote', text: entry.url }),
|
|
543
|
+
h('div', { class: 'git-notice-text', text: 'Pushes your committed changes to this remote.' }),
|
|
544
|
+
h('div', { class: 'git-form-actions' },
|
|
545
|
+
button('Publish', () => run(`Publishing ${entry.name}`, scriptUrl('push', cwdOf(entry), { ts: Date.now() })), { primary: true, icon: 'fa-brands fa-github' }),
|
|
546
|
+
web ? button('View on GitHub', () => openExternal(web)) : null))
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// ----------------------------------------------------------------- render
|
|
550
|
+
const sectionBody = (entry) => {
|
|
551
|
+
if (state.run) return runPanel()
|
|
552
|
+
if (state.section === 'history') return historySection(entry)
|
|
553
|
+
if (state.section === 'fork') return forkSection(entry)
|
|
554
|
+
if (state.section === 'publish') return publishSection(entry)
|
|
555
|
+
return changesSection(entry)
|
|
556
|
+
}
|
|
557
|
+
const render = () => {
|
|
558
|
+
// a field being typed in keeps its text and the cursor across a redraw
|
|
559
|
+
const active = document.activeElement
|
|
560
|
+
const typing = active && root.contains(active) && active.tagName === 'INPUT' && active.type === 'text' ? active : null
|
|
561
|
+
const entry = repo()
|
|
562
|
+
const checked = state.checking
|
|
563
|
+
? 'Checking...'
|
|
564
|
+
: state.checkedAt
|
|
565
|
+
? `Checked at ${new Date(state.checkedAt).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}`
|
|
566
|
+
: ''
|
|
567
|
+
const side = h('aside', { class: 'git-side' },
|
|
568
|
+
h('div', { class: 'git-side-top' },
|
|
569
|
+
h('div', { class: 'git-checked', text: checked }),
|
|
570
|
+
h('button', { type: 'button', class: 'git-btn git-btn--icon', title: 'Refresh', 'aria-label': 'Refresh', disabled: Boolean(state.checking), onclick: () => { check() } }, icon('fa-solid fa-rotate'))),
|
|
571
|
+
state.repos.map((item) => {
|
|
572
|
+
const count = Number(item.changeCount) || 0
|
|
573
|
+
return h('button', {
|
|
574
|
+
type: 'button',
|
|
575
|
+
class: `git-repo${item.repoParam === state.repoKey ? ' git-repo--selected' : ''}`,
|
|
576
|
+
onclick: () => {
|
|
577
|
+
if (state.run) return
|
|
578
|
+
state.repoKey = item.repoParam
|
|
579
|
+
state.commit = null
|
|
580
|
+
render()
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
h('div', { class: 'git-repo-name', text: item.name, title: item.name }),
|
|
584
|
+
h('div', { class: `git-repo-status ${count > 0 ? 'git-repo-status--dirty' : 'git-repo-status--clean'}`, text: count > 0 ? `${count} change${count === 1 ? '' : 's'}` : 'Clean' }))
|
|
585
|
+
}))
|
|
586
|
+
let main
|
|
587
|
+
if (!entry) {
|
|
588
|
+
main = h('div', { class: 'git-empty', text: state.error || (state.checking ? 'Checking repositories...' : 'No Git repositories detected') })
|
|
589
|
+
} else {
|
|
590
|
+
const web = remoteWebUrl(entry.url)
|
|
591
|
+
main = h('div', { class: 'git-main-inner' },
|
|
592
|
+
h('div', { class: 'git-main-header' },
|
|
593
|
+
h('div', { class: 'git-main-title', text: entry.name }),
|
|
594
|
+
web
|
|
595
|
+
? h('a', { class: 'git-link', href: web, text: web.replace(/^https?:\/\//, ''), onclick: (event) => { event.preventDefault(); openExternal(web) } })
|
|
596
|
+
: h('span', { class: 'git-main-remote', text: entry.url || 'No remote' })),
|
|
597
|
+
h('div', { class: 'git-tabs', role: 'tablist' }, SECTIONS.map((name) => h('button', {
|
|
598
|
+
type: 'button',
|
|
599
|
+
role: 'tab',
|
|
600
|
+
class: `git-tab${state.section === name ? ' git-tab--selected' : ''}`,
|
|
601
|
+
'aria-selected': state.section === name ? 'true' : 'false',
|
|
602
|
+
disabled: Boolean(state.run),
|
|
603
|
+
text: name.charAt(0).toUpperCase() + name.slice(1),
|
|
604
|
+
onclick: () => {
|
|
605
|
+
state.section = name
|
|
606
|
+
state.commit = null
|
|
607
|
+
render()
|
|
608
|
+
},
|
|
609
|
+
}))),
|
|
610
|
+
h('div', { class: 'git-section' }, state.error ? h('div', { class: 'git-error', text: state.error }) : null, sectionBody(entry)))
|
|
611
|
+
}
|
|
612
|
+
const typedValue = typing ? { id: typing.id, value: typing.value, start: typing.selectionStart, end: typing.selectionEnd } : null
|
|
613
|
+
root.replaceChildren(side, h('main', { class: 'git-main' }, main))
|
|
614
|
+
if (typedValue) {
|
|
615
|
+
const again = typedValue.id ? document.getElementById(typedValue.id) : root.querySelector('.git-commit-bar .git-input')
|
|
616
|
+
if (again) {
|
|
617
|
+
again.value = typedValue.value
|
|
618
|
+
again.focus()
|
|
619
|
+
try { again.setSelectionRange(typedValue.start, typedValue.end) } catch (_) {}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
check()
|
|
625
|
+
})()
|
|
@@ -4598,7 +4598,7 @@
|
|
|
4598
4598
|
if (ui.intent === 'create_app') {
|
|
4599
4599
|
setSubmissionState(ui, {
|
|
4600
4600
|
title: 'Creating app...',
|
|
4601
|
-
description: 'Setting up the new app and preparing
|
|
4601
|
+
description: 'Setting up the new app and preparing its page.',
|
|
4602
4602
|
label: files.length ? 'Uploading files' : 'Preparing app workspace',
|
|
4603
4603
|
detail: files.length
|
|
4604
4604
|
? 'Uploading your files, then creating the app folder and first git commit.'
|
|
@@ -4612,7 +4612,7 @@
|
|
|
4612
4612
|
if (ui.intent === 'create_app') {
|
|
4613
4613
|
setSubmissionState(ui, {
|
|
4614
4614
|
title: 'Creating app...',
|
|
4615
|
-
description: 'Setting up the new app and preparing
|
|
4615
|
+
description: 'Setting up the new app and preparing its page.',
|
|
4616
4616
|
label: 'Preparing app workspace',
|
|
4617
4617
|
detail: 'Creating the app folder, starter files, and first git commit. This usually takes a few seconds.',
|
|
4618
4618
|
confirmLabel: 'Working...'
|
|
@@ -4635,8 +4635,8 @@
|
|
|
4635
4635
|
}
|
|
4636
4636
|
setSubmissionState(ui, {
|
|
4637
4637
|
title: 'Opening app...',
|
|
4638
|
-
description: 'The app is ready. Opening
|
|
4639
|
-
label: 'Opening
|
|
4638
|
+
description: 'The app is ready. Opening it now.',
|
|
4639
|
+
label: 'Opening the app',
|
|
4640
4640
|
detail: 'Redirecting to the new app.',
|
|
4641
4641
|
confirmLabel: 'Opening...'
|
|
4642
4642
|
});
|
|
@@ -195,7 +195,6 @@ function initUrlDropdown(config = {}) {
|
|
|
195
195
|
if (!projectCtx) return '';
|
|
196
196
|
const modes = [
|
|
197
197
|
{ key: 'run', label: 'Run', icon: 'fa-solid fa-circle-play', suffix: '' },
|
|
198
|
-
{ key: 'dev', label: 'Dev', icon: 'fa-solid fa-code', suffix: '/dev' },
|
|
199
198
|
{ key: 'files', label: 'Files', icon: 'fa-solid fa-file-lines', suffix: '/files' },
|
|
200
199
|
].filter((mode) => includeFiles || mode.key !== 'files');
|
|
201
200
|
|