mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 19:59:38 +00:00
Add conditional menu items and disable sticky notes at root
This commit is contained in:
39
dist/birb.js
vendored
39
dist/birb.js
vendored
@@ -1148,6 +1148,11 @@
|
||||
return path === this.getPath();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
areStickyNotesEnabled() {
|
||||
return this.getPath() !== ROOT_PATH;
|
||||
}
|
||||
|
||||
/** @returns {HTMLElement|null} */
|
||||
getActiveEditorElement() {
|
||||
// @ts-expect-error
|
||||
@@ -1313,6 +1318,9 @@
|
||||
* @param {(note: StickyNote) => void} onDelete
|
||||
*/
|
||||
function createNewStickyNote(stickyNotes, onSave, onDelete) {
|
||||
if (getContext().areStickyNotesEnabled() === false) {
|
||||
return;
|
||||
}
|
||||
const id = Date.now().toString();
|
||||
const site = getContext().getPath();
|
||||
const stickyNote = new StickyNote(id, site, "");
|
||||
@@ -1334,23 +1342,34 @@
|
||||
* @param {string} text
|
||||
* @param {() => void} action
|
||||
* @param {boolean} [removeMenu]
|
||||
* @param {boolean} [isDebug]
|
||||
*/
|
||||
constructor(text, action, removeMenu = true, isDebug = false) {
|
||||
constructor(text, action, removeMenu = true) {
|
||||
this.text = text;
|
||||
this.action = action;
|
||||
this.removeMenu = removeMenu;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
}
|
||||
|
||||
class DebugMenuItem extends MenuItem {
|
||||
class ConditionalMenuItem extends MenuItem {
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {() => void} action
|
||||
* @param {() => boolean} condition
|
||||
* @param {boolean} [removeMenu]
|
||||
*/
|
||||
constructor(text, action, condition, removeMenu = true) {
|
||||
super(text, action, removeMenu);
|
||||
this.condition = condition;
|
||||
}
|
||||
}
|
||||
|
||||
class DebugMenuItem extends ConditionalMenuItem {
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {() => void} action
|
||||
*/
|
||||
constructor(text, action, removeMenu = true) {
|
||||
super(text, action, removeMenu, true);
|
||||
super(text, action, () => isDebug(), removeMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1396,7 +1415,7 @@
|
||||
let content = makeElement("birb-window-content");
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
if (!(item instanceof ConditionalMenuItem) || item.condition()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -1453,7 +1472,7 @@
|
||||
}
|
||||
const removeCallback = () => removeMenu();
|
||||
for (const item of menuItems) {
|
||||
if (!item.isDebug || isDebug()) {
|
||||
if (!(item instanceof ConditionalMenuItem) || item.condition()) {
|
||||
content.appendChild(makeMenuItem(item, removeCallback));
|
||||
}
|
||||
}
|
||||
@@ -1955,9 +1974,7 @@
|
||||
const menuItems = [
|
||||
new MenuItem(`Pet ${birdBirb()}`, pet),
|
||||
new MenuItem("Field Guide", insertFieldGuide),
|
||||
...(getContext().areStickyNotesEnabled() ? [
|
||||
new MenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote))
|
||||
] : []),
|
||||
new ConditionalMenuItem("Sticky Note", () => createNewStickyNote(stickyNotes, save, deleteStickyNote), () => getContext().areStickyNotesEnabled()),
|
||||
new MenuItem(`Hide ${birdBirb()}`, () => birb.setVisible(false)),
|
||||
new DebugMenuItem("Freeze/Unfreeze", () => {
|
||||
frozen = !frozen;
|
||||
@@ -1994,7 +2011,7 @@
|
||||
insertModal(`${birdBirb()} Mode`, message);
|
||||
}),
|
||||
new Separator(),
|
||||
new MenuItem("2025.11.14.16", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.16"); }, false),
|
||||
new MenuItem("2025.11.14.47", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.14.47"); }, false),
|
||||
];
|
||||
|
||||
const styleElement = document.createElement("style");
|
||||
|
||||
Reference in New Issue
Block a user