Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,7 @@ body.preview-active .preview-pane {
disabled to block re-entry, so undo the :disabled dim — a spinner at 35%
opacity reads as broken, not busy. */
.preview-toolbar .preview-download.is-downloading { opacity: 1; }
.preview-toolbar .preview-overflow.is-downloading > svg { display: none; }
.download-spinner {
width: 14px;
height: 14px;
Expand Down Expand Up @@ -4038,6 +4039,8 @@ body.preview-active .preview-pane {
The chrome is shared with publish/share above. These are its own pieces:
headings, form controls, the collision card and the footer. */
.preview-github-btn { position: relative; }
/* On "…" the attention dot sits opposite the unsaved-code dot. */
.preview-toolbar .preview-overflow .preview-github-dot { top: 3px; right: auto; left: 3px; }
.preview-github-dot {
position: absolute;
top: 4px;
Expand Down Expand Up @@ -5619,7 +5622,10 @@ body.preview-active.chat-hidden .chat {
display:flex }` (0,1,1) — a bare `.preview-overflow` would lose to it and the
button would leak onto desktop. */
.view-seg { display: none; }
.preview-toolbar .preview-overflow { display: none; }
.preview-toolbar .preview-overflow:not(.has-dev-tools) { display: none; }
/* The developer tools (code, download, GitHub) open from the "…" menu
beside Publish at every width; their buttons stay in the DOM for it to drive. */
.preview-toolbar .preview-dev-tools { display: none; }

/* The segmented control itself. A pill-shaped track holding two equal segments;
the active one (set by syncViewSeg from the body view-state) gets a raised
Expand Down Expand Up @@ -6063,12 +6069,12 @@ body.preview-active.chat-hidden .chat {
}
}

/* Phones can't fit the version-history / download buttons beside the centered
/* Phones can't fit the version-history buttons beside the centered
switcher and Publish, so they collapse into the overflow ("…") menu. The
buttons stay in the DOM (hidden) — the menu triggers their clicks — so all
their existing logic is reused. */
.preview-history-group { display: none; }
body.preview-active .preview-overflow { display: inline-flex; }
body.preview-active .preview-toolbar .preview-overflow { display: inline-flex; }
}

/* Very small phones (≤380px): trim chrome a touch more. */
Expand Down
21 changes: 16 additions & 5 deletions src/js/github-ui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// github-ui.js — the Source control toolbar button and popover, which save a
// github-ui.js — the GitHub toolbar button and popover, which save a
// project to GitHub (the UI half of js/github-sync.js).
//
// One popover per project, with the toolbar's popover rules: one open at a
Expand Down Expand Up @@ -238,13 +238,15 @@
const now = id ? Sync.stateFor(id) : null;
const s = now && now.kind === 'checking' && now.prev ? now.prev : now;
const attention = !!(link && !link.disconnected && s && ['collision', 'history', 'secret', 'signed-out', 'repo-missing', 'branch-missing', 'rules', 'archived', 'error'].includes(s.kind));
$btn.find('.preview-github-dot').prop('hidden', !attention);
// The button itself is never shown: it opens from the "…" menu, whose
// button carries the dot too.
$btn.add('.preview-overflow').find('.preview-github-dot').prop('hidden', !attention);
const state = !link || link.disconnected || !s ? ''
: s.kind === 'up-to-date' ? 'Saved to GitHub'
: s.kind === 'saving' ? 'Saving to GitHub…'
: s.kind === 'bringing' ? 'Bringing in changes from GitHub…'
: attention ? 'Needs your attention' : '';
const title = state ? `Source control — ${state}` : 'Source control';
const title = state ? `GitHub — ${state}` : 'GitHub';
$btn.attr('title', title).attr('aria-label', title);
}

Expand Down Expand Up @@ -333,6 +335,15 @@
redraw();
});

// Return focus to whatever control opens the panel: the toolbar button
// when it shows, otherwise the "…" menu's button (focusing a hidden
// element silently no-ops).
function focusTrigger() {
const $btn = $('.preview-github-btn');
if ($btn.is(':visible')) $btn.trigger('focus');
else $('.preview-overflow').trigger('focus');
}

$(document).on('click', '.preview-github-btn', function (e) {
e.preventDefault();
e.stopPropagation();
Expand All @@ -342,13 +353,13 @@
e.preventDefault();
e.stopPropagation();
closePanel();
$('.preview-github-btn').trigger('focus');
focusTrigger();
});
$(document).on('keydown', '.preview-github-panel', function (e) {
if (e.key === 'Escape') {
e.preventDefault();
closePanel();
$('.preview-github-btn').trigger('focus');
focusTrigger();
}
});
$(document).on('click', function (e) {
Expand Down
63 changes: 40 additions & 23 deletions src/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,17 +1340,21 @@ window.showAppPreview = function(url, opts) {
${window.FEATURE_FLAGS.issues ? `<button class="preview-issues" title="Issues" aria-haspopup="dialog" aria-expanded="false">${window.issues_svg}<span class="issues-count-badge" aria-hidden="true" hidden></span></button>` : ''}
<button class="preview-versions" title="Version history" aria-haspopup="dialog" aria-expanded="false">${window.history_svg}</button>
${window.FEATURE_FLAGS.shareDraftLink ? `<button class="preview-share" title="Share draft" aria-haspopup="dialog" aria-expanded="false">${window.link_svg}</button>` : ''}
<!-- Developer tools: the code, the download, and source control. -->
${window.FEATURE_FLAGS.codeEditor ? `<span class="preview-toolbar-divider"></span><button type="button" class="pane-mode-btn pane-mode-code" data-mode="code" title="View code" aria-pressed="false">${window.code_svg}<span class="sr-only">View code</span><span class="pane-mode-dot" aria-label="Unsaved changes" hidden></span></button>` : ''}
</div>
<!-- Developer tools: the code, the download, and GitHub.
They open from the "…" menu beside Publish, so these buttons
are never shown (CSS); they stay in the DOM so the menu can
drive their existing handlers. -->
<div class="preview-dev-tools">
${window.FEATURE_FLAGS.codeEditor ? `<button type="button" class="pane-mode-btn pane-mode-code" data-mode="code" title="View code" aria-pressed="false">${window.code_svg}<span class="sr-only">View code</span><span class="pane-mode-dot" aria-label="Unsaved changes" hidden></span></button>` : ''}
${window.FEATURE_FLAGS.downloadProject ? `<button class="preview-download" title="Download project">${window.download_svg}</button>` : ''}
${window.GitHubSync ? `<button class="preview-github-btn" title="Source control" aria-label="Source control" aria-haspopup="dialog" aria-expanded="false">${window.source_control_svg || ''}<span class="preview-github-dot" aria-hidden="true" hidden></span></button>` : ''}
${window.GitHubSync ? `<button class="preview-github-btn" title="GitHub" aria-label="GitHub" aria-haspopup="dialog" aria-expanded="false">${window.source_control_svg || ''}<span class="preview-github-dot" aria-hidden="true" hidden></span></button>` : ''}
</div>
<!-- Phones don't have room for the history/download buttons next to the
centered switcher + Publish, so they collapse into this overflow
menu (shown only on mobile via CSS); the buttons above stay in the
DOM, hidden, so the menu can drive their existing handlers. -->
<button class="preview-overflow" title="More" aria-haspopup="true" aria-expanded="false">${window.more_svg}<span class="pane-mode-dot" aria-hidden="true" hidden></span></button>
<span class="preview-toolbar-divider"></span>
<!-- The "…" menu holds the developer tools above. Phones also don't
have room for the history buttons next to the centered switcher
+ Publish, so on mobile they join the menu too (the group above
is hidden via CSS and the menu drives its buttons). -->
<button class="preview-overflow${window.FEATURE_FLAGS.codeEditor || window.FEATURE_FLAGS.downloadProject || window.GitHubSync ? ' has-dev-tools' : ''}" title="More" aria-haspopup="true" aria-expanded="false">${window.more_svg}<span class="pane-mode-dot" aria-hidden="true" hidden></span><span class="preview-github-dot" aria-hidden="true" hidden></span></button>
<button class="preview-publish-btn" data-state="unpublished" title="Publish your site" aria-haspopup="dialog" aria-expanded="false">
<span class="preview-publish-label">Publish</span>
<span class="preview-publish-dot" aria-hidden="true"></span>
Expand Down Expand Up @@ -4547,6 +4551,10 @@ $(document).on('click', '.preview-download', async function() {
const $btn = $(this);
$btn.prop('disabled', true).addClass('is-downloading')
.html('<span class="download-spinner"></span>');
// The button opens from the "…" menu and is never shown, so the spinner
// shows on "…" instead.
const $more = $('.preview-overflow').addClass('is-downloading');
$more.prepend('<span class="download-spinner"></span>');
const minSpin = new Promise(resolve => setTimeout(resolve, 1000));
try {
const title = generateChatTitle(chatHistory).replace(/[^a-zA-Z0-9_-]/g, '_');
Expand All @@ -4560,6 +4568,7 @@ $(document).on('click', '.preview-download', async function() {
} finally {
await minSpin;
$btn.html(window.download_svg).removeClass('is-downloading').prop('disabled', false);
$more.removeClass('is-downloading').children('.download-spinner').remove();
}
});

Expand Down Expand Up @@ -4593,10 +4602,12 @@ $(document).on('click', '.view-seg-btn', function() {
}
});

// Mobile only: overflow ("…") menu in the preview toolbar. History/download don't
// fit alongside the centered switcher + Publish on a phone, so they live here.
// The menu items drive the existing (CSS-hidden) toolbar buttons so all their
// logic — panel toggle, download flow, disabled states — is reused as-is.
// Overflow ("…") menu beside Publish in the preview toolbar. It always holds
// the developer tools (code, download, GitHub); on a phone, where the
// history buttons don't fit alongside the centered switcher + Publish, they
// join it too. The menu items drive the existing (CSS-hidden) toolbar buttons
// so all their logic — panel toggle, download flow, disabled states — is
// reused as-is.
let overflowMenuOpen = false;
// Outside interaction: puter's capture-phase pointerdown removes the menu; sync
// the flag + aria (which also drives the button's active look) the same way the
Expand All @@ -4620,7 +4631,9 @@ $(document).on('click', '.preview-overflow', function(e) {

const rect = this.getBoundingClientRect();
const items = [];
if (window.FEATURE_FLAGS.issues) {
// The history group is hidden on phones only; there its tools join the menu.
const historyInMenu = !$('.preview-history-group').is(':visible');
if (historyInMenu && window.FEATURE_FLAGS.issues) {
// The toolbar button's count badge is hidden with it on mobile, so the
// open-issue count rides the menu label instead.
const openIssues = window.getOpenIssuesCount?.() || 0;
Expand All @@ -4630,20 +4643,22 @@ $(document).on('click', '.preview-overflow', function(e) {
action: () => $('.preview-issues').trigger('click'),
});
}
items.push({
icon: svgDataUri(window.history_svg),
label: 'Version history',
action: () => $('.preview-versions').trigger('click'),
});
if (window.FEATURE_FLAGS.shareDraftLink) {
if (historyInMenu) {
items.push({
icon: svgDataUri(window.history_svg),
label: 'Version history',
action: () => $('.preview-versions').trigger('click'),
});
}
if (historyInMenu && window.FEATURE_FLAGS.shareDraftLink) {
items.push({
icon: svgDataUri(window.link_svg),
label: 'Share draft',
action: () => $('.preview-share').trigger('click'),
});
}
// The code view opens from here on phones; while it is open, the toolbar's
// Back to preview button is the way out, so the row goes.
// While the code view is open, the toolbar's Back to preview button is the
// way out, so the row goes.
if (window.FEATURE_FLAGS.codeEditor && !$('.preview-pane').hasClass('code-mode')) {
// The dot on "…" means unsaved code edits; the label says so in words.
const unsaved = !$('.pane-mode-code .pane-mode-dot').prop('hidden');
Expand All @@ -4661,12 +4676,14 @@ $(document).on('click', '.preview-overflow', function(e) {
});
}
if (window.GitHubSync && window.source_control_svg) {
const attention = !$('.preview-github-btn .preview-github-dot').prop('hidden');
items.push({
icon: svgDataUri(window.source_control_svg),
label: 'Source control',
label: attention ? 'GitHub (needs attention)' : 'GitHub',
action: () => $('.preview-github-btn').trigger('click'),
});
}
if (!items.length) return;
puter.ui.contextMenu({
...menuThemeOption(),
// Right-anchored trigger: x is the menu's left edge but flips to
Expand Down
Loading