Skip to content

Commit 342e5f0

Browse files
committed
feat(yasqe): add showShareButton and showFullscreenButton options
The developer guide listed a showShareButton option that did not exist, and the fullscreen button could not be hidden at all. Both options default to true and also hide the matching mobile menu items. Closes #251
1 parent 0ac3b21 commit 342e5f0

5 files changed

Lines changed: 94 additions & 39 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@matdata/yasqe": minor
3+
---
4+
5+
New `showShareButton` and `showFullscreenButton` options hide the Share and Fullscreen buttons of the editor, also in the mobile menu and the Ctrl+K search. In Yasgui, set them under `yasqe`, for example `yasqe: { showShareButton: false, showFullscreenButton: false }`.

‎docs/developer-guide.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,13 @@ interface YasqeConfig {
813813
// shows Run in its query bar; `yasqe: { showQueryButton: false }`
814814
// in the Yasgui config hides that Run button too
815815

816-
// Show share button
817-
showShareButton: boolean; // default: false
816+
// Show the Share button (and its item in the mobile menu).
817+
// Setting createShareableLink to null also hides it
818+
showShareButton: boolean; // default: true
819+
820+
// Show the Fullscreen button (and its item in the mobile menu).
821+
// F11 still toggles the fullscreen editor
822+
showFullscreenButton: boolean; // default: true
818823

819824
// Persistent storage ID
820825
persistenceId?: string | ((yasqe: Yasqe) => string);

‎packages/yasqe/src/defaults.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ SELECT * WHERE {
124124
persistencyExpire: 60 * 60 * 24 * 30,
125125

126126
showQueryButton: true,
127+
showShareButton: true,
128+
showFullscreenButton: true,
127129

128130
hintConfig: {},
129131
resizeable: true,

‎packages/yasqe/src/index.ts‎

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class Yasqe extends EditorFacade {
385385
/**
386386
* draw share link button (SECOND)
387387
*/
388-
if (this.config.createShareableLink) {
388+
if (this.config.createShareableLink && this.config.showShareButton) {
389389
const shareIcon = document.createElement("i");
390390
addClass(shareIcon, "fas");
391391
addClass(shareIcon, "fa-share-nodes");
@@ -723,26 +723,28 @@ export class Yasqe extends EditorFacade {
723723
/**
724724
* Draw fullscreen btn (SIXTH)
725725
*/
726-
this.fullscreenBtn = document.createElement("button");
727-
addClass(this.fullscreenBtn, "yasqe_fullscreenButton");
728-
const fullscreenIcon = document.createElement("i");
729-
addClass(fullscreenIcon, "fas");
730-
addClass(fullscreenIcon, "fa-expand");
731-
addClass(fullscreenIcon, "fullscreenIcon");
732-
fullscreenIcon.setAttribute("aria-hidden", "true");
733-
this.fullscreenBtn.appendChild(fullscreenIcon);
734-
const fullscreenExitIcon = document.createElement("i");
735-
addClass(fullscreenExitIcon, "fas");
736-
addClass(fullscreenExitIcon, "fa-compress");
737-
addClass(fullscreenExitIcon, "fullscreenExitIcon");
738-
fullscreenExitIcon.setAttribute("aria-hidden", "true");
739-
this.fullscreenBtn.appendChild(fullscreenExitIcon);
740-
this.fullscreenBtn.onclick = () => {
741-
this.toggleFullscreen();
742-
};
743-
this.fullscreenBtn.title = "Toggle fullscreen (F11)";
744-
this.fullscreenBtn.setAttribute("aria-label", "Toggle fullscreen");
745-
buttons.appendChild(this.fullscreenBtn);
726+
if (this.config.showFullscreenButton) {
727+
this.fullscreenBtn = document.createElement("button");
728+
addClass(this.fullscreenBtn, "yasqe_fullscreenButton");
729+
const fullscreenIcon = document.createElement("i");
730+
addClass(fullscreenIcon, "fas");
731+
addClass(fullscreenIcon, "fa-expand");
732+
addClass(fullscreenIcon, "fullscreenIcon");
733+
fullscreenIcon.setAttribute("aria-hidden", "true");
734+
this.fullscreenBtn.appendChild(fullscreenIcon);
735+
const fullscreenExitIcon = document.createElement("i");
736+
addClass(fullscreenExitIcon, "fas");
737+
addClass(fullscreenExitIcon, "fa-compress");
738+
addClass(fullscreenExitIcon, "fullscreenExitIcon");
739+
fullscreenExitIcon.setAttribute("aria-hidden", "true");
740+
this.fullscreenBtn.appendChild(fullscreenExitIcon);
741+
this.fullscreenBtn.onclick = () => {
742+
this.toggleFullscreen();
743+
};
744+
this.fullscreenBtn.title = "Toggle fullscreen (F11)";
745+
this.fullscreenBtn.setAttribute("aria-label", "Toggle fullscreen");
746+
buttons.appendChild(this.fullscreenBtn);
747+
}
746748

747749
/**
748750
* Draw hamburger menu button and dropdown (for mobile)
@@ -765,7 +767,7 @@ export class Yasqe extends EditorFacade {
765767
buttons.appendChild(this.hamburgerMenu);
766768

767769
// Add menu items
768-
if (this.config.createShareableLink) {
770+
if (this.shareBtn) {
769771
const shareItem = document.createElement("button");
770772
shareItem.className = "yasqe_hamburgerMenuItem";
771773
const shareIconMenu = document.createElement("i");
@@ -851,21 +853,23 @@ export class Yasqe extends EditorFacade {
851853
this.hamburgerMenu.appendChild(mapItem);
852854
}
853855

854-
const fullscreenItem = document.createElement("button");
855-
fullscreenItem.className = "yasqe_hamburgerMenuItem";
856-
const fullscreenIconMenu = document.createElement("i");
857-
addClass(fullscreenIconMenu, "fas");
858-
addClass(fullscreenIconMenu, "fa-expand");
859-
fullscreenIconMenu.setAttribute("aria-hidden", "true");
860-
fullscreenItem.appendChild(fullscreenIconMenu);
861-
const fullscreenLabel = document.createElement("span");
862-
fullscreenLabel.textContent = "Fullscreen";
863-
fullscreenItem.appendChild(fullscreenLabel);
864-
fullscreenItem.onclick = () => {
865-
this.closeHamburgerMenu();
866-
this.toggleFullscreen();
867-
};
868-
this.hamburgerMenu.appendChild(fullscreenItem);
856+
if (this.config.showFullscreenButton) {
857+
const fullscreenItem = document.createElement("button");
858+
fullscreenItem.className = "yasqe_hamburgerMenuItem";
859+
const fullscreenIconMenu = document.createElement("i");
860+
addClass(fullscreenIconMenu, "fas");
861+
addClass(fullscreenIconMenu, "fa-expand");
862+
fullscreenIconMenu.setAttribute("aria-hidden", "true");
863+
fullscreenItem.appendChild(fullscreenIconMenu);
864+
const fullscreenLabel = document.createElement("span");
865+
fullscreenLabel.textContent = "Fullscreen";
866+
fullscreenItem.appendChild(fullscreenLabel);
867+
fullscreenItem.onclick = () => {
868+
this.closeHamburgerMenu();
869+
this.toggleFullscreen();
870+
};
871+
this.hamburgerMenu.appendChild(fullscreenItem);
872+
}
869873

870874
// Toggle hamburger menu
871875
this.hamburgerBtn.onclick = (e) => {
@@ -2522,6 +2526,14 @@ export interface Config extends Omit<EditorOptions, "extraKeys"> {
25222526
* Show the Run button in the editor. Yasgui sets this to false: it shows its own Run button in the query bar.
25232527
*/
25242528
showQueryButton: boolean;
2529+
/**
2530+
* Show the Share button (and its item in the mobile menu). Setting `createShareableLink` to null also hides it.
2531+
*/
2532+
showShareButton: boolean;
2533+
/**
2534+
* Show the Fullscreen button (and its item in the mobile menu). F11 still toggles fullscreen.
2535+
*/
2536+
showFullscreenButton: boolean;
25252537
requestConfig: RequestConfig<Yasqe> | ((yasqe: Yasqe) => RequestConfig<Yasqe>);
25262538
pluginButtons: (() => HTMLElement[] | HTMLElement) | undefined;
25272539
highlightSelectionMatches: boolean | { showToken?: RegExp; annotateScrollbar?: boolean };

‎test/run.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ describe("Yasqe", function () {
8484
await page.keyboard.up("Control");
8585
}
8686

87+
describe("Editor buttons", function () {
88+
function countButtons() {
89+
return page.evaluate(() => {
90+
const wrapper = window.yasqe.getWrapperElement();
91+
return {
92+
share: wrapper.querySelectorAll(".yasqe_share").length,
93+
fullscreen: wrapper.querySelectorAll(".yasqe_fullscreenButton").length,
94+
menu: Array.from(wrapper.querySelectorAll(".yasqe_hamburgerMenuItem span")).map((el) => el.textContent),
95+
};
96+
});
97+
}
98+
it("shows the share and fullscreen buttons by default", async function () {
99+
const buttons = await countButtons();
100+
expect(buttons.share).to.equal(1);
101+
expect(buttons.fullscreen).to.equal(1);
102+
expect(buttons.menu).to.include.members(["Share", "Fullscreen"]);
103+
});
104+
it("hides them with showShareButton and showFullscreenButton", async function () {
105+
await page.evaluate(() => {
106+
const el = document.createElement("div");
107+
document.body.appendChild(el);
108+
window.yasqe = new window.Yasqe(el, { showShareButton: false, showFullscreenButton: false });
109+
});
110+
const buttons = await countButtons();
111+
expect(buttons.share).to.equal(0);
112+
expect(buttons.fullscreen).to.equal(0);
113+
expect(buttons.menu).to.not.include.members(["Share"]);
114+
expect(buttons.menu).to.not.include.members(["Fullscreen"]);
115+
});
116+
});
117+
87118
describe("Autoformatting", function () {
88119
it("With literal", async function () {
89120
const value = await page.evaluate(() => {

0 commit comments

Comments
 (0)