Skip to content

Commit

Permalink
feat(properties): option to hide plugin props
Browse files Browse the repository at this point in the history
option to hide props
  • Loading branch information
sawhney17 authored Jul 4, 2022
2 parents c815e36 + b9c37e0 commit b4cc59f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-banners-plugin",
"version": "1.4.0",
"version": "1.5.0",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
38 changes: 33 additions & 5 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ const defaultConfig: IAssetsRecord = {
}
};
let customPropsConfig: IAssetsRecord;
let timeout: number;
let timeout: number;
let hidePluginProps: boolean;

const settingsDefaultPageBanner = "https://wallpaperaccess.com/full/1146672.jpg";
const settingsDefaultJournalBanner = "https://images.unsplash.com/photo-1646026371686-79950ceb6daa?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1034&q=80";
const settingsArray: SettingSchemaDesc[] = [
{
key: "hidePluginProps",
title: "Hide plugin props",
type: "boolean",
description: "Show plugin props only on edit?",
default: "false",
},
{
key: "bannerHeight",
title: "Banner height",
Expand Down Expand Up @@ -156,7 +164,7 @@ const initStyles = () => {
z-index:2;
line-height: initial;
}
body:is([data-page="page"],[data-page="home"]).is-banner-active :is(.page-title, .journal-title) {
body:is([data-page="page"],[data-page="home"]).is-banner-active :is(.ls-page-title, .page-title, .journal-title) {
margin-top: 35px;
}
body:is([data-page="page"],[data-page="home"]).is-banner-active.is-icon-active #journals .journal-item:first-child {
Expand All @@ -179,6 +187,7 @@ const readPluginSettings = () => {
const pluginSettings = logseq.settings;
if (pluginSettings) {
({
hidePluginProps,
bannerHeight,
useDefaultBanner: useDefault.banner,
useDefaultIcon: useDefault.pageIcon,
Expand All @@ -195,6 +204,18 @@ const readPluginSettings = () => {
}
}

// Hide props
const hideProps = () => {
const propBlockKeys = top?.document.getElementsByClassName("page-property-key");
if (propBlockKeys?.length) {
for (let i = 0; i < propBlockKeys.length; i++) {
if (propBlockKeys[i].textContent === "banner" || propBlockKeys[i].textContent === "page-icon") {
propBlockKeys[i].parentElement!.style.display = hidePluginProps ? "none" : "block" ;
}
}
}
}

// Render
const render = async () => {
// "Delete" icon on ever render start if no default allowed
Expand Down Expand Up @@ -412,6 +433,7 @@ const clearIcon = () => {
const routeChangedCallback = () => {
console.info(`#${pluginId}: page route changed`);
// Content reloaded, so need reconnect props listeners
hideProps();
propsChangedObserverStop();
setTimeout(() => {
propsChangedObserverRun();
Expand All @@ -420,6 +442,13 @@ const routeChangedCallback = () => {
}, timeout)
}

// Setting changed
const onSettingsChangedCallback = () => {
readPluginSettings();
root.style.setProperty("--bannerHeight", `${bannerHeight}`);
render();
}

// On Logseq ready - MAIN
const main = async () => {
console.info(`#${pluginId}: MAIN`);
Expand All @@ -429,6 +458,7 @@ const main = async () => {

readPluginSettings();
initStyles();
hideProps();
setTimeout(() => {
render();
}, timeout*2)
Expand All @@ -446,9 +476,7 @@ const main = async () => {

// Listen settings update
logseq.onSettingsChanged(() => {
readPluginSettings();
root.style.setProperty("--bannerHeight", `${bannerHeight}`);
render();
onSettingsChangedCallback();
})
}, 4000);

Expand Down

0 comments on commit b4cc59f

Please sign in to comment.