Skip to content

Commit

Permalink
Showing 22 changed files with 183 additions and 231 deletions.
6 changes: 2 additions & 4 deletions src/awesomeUI.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import '@logseq/libs';

import {
settingsLoad,
pluginLoad
} from './modules/internal';
import { pluginLoad } from './modules/plugin/plugin';
import { settingsLoad } from './modules/settings/settings';

import './awesomeUI.css';

9 changes: 3 additions & 6 deletions src/modules/awesomeProps/awesomeProps.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import {
globalContext,
body, doc
} from '../internal';
import { doc, body, globals } from '../globals/globals';

import awesomePropsStyles from './awesomeProps.css?inline';

export const toggleAwesomePropsFeature = () => {
if (globalContext.pluginConfig.featureAwesomeProps) {
if (globals.pluginConfig.featureAwesomeProps) {
awesomePropsLoad();
} else {
awesomePropsLoadUnload();
}
}

export const awesomePropsLoad = async () => {
if (!globalContext.pluginConfig.featureAwesomeProps) {
if (!globals.pluginConfig.featureAwesomeProps) {
return;
}
body.classList.add('awUi-props');
9 changes: 3 additions & 6 deletions src/modules/calendar/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
globalContext,
root, doc
} from '../internal';
import { root, doc, globals } from '../globals/globals';

import calendarStyles from './calendar.css?inline';

@@ -11,15 +8,15 @@ const setSidebarWidthVar = () => {
}

export const toggleCalendarFeature = () => {
if (globalContext.pluginConfig.featureCalendarEnabled) {
if (globals.pluginConfig.featureCalendarEnabled) {
calendarLoad();
} else {
calendarUnload();
}
}

export const calendarLoad = async (agendaPlugin?: HTMLElement) => {
if (!globalContext.pluginConfig.featureCalendarEnabled) {
if (!globals.pluginConfig.featureCalendarEnabled) {
return;
}
logseq.provideStyle({ key: 'awUI-calendar-css', style: calendarStyles });
9 changes: 3 additions & 6 deletions src/modules/columns/columns.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import {
globalContext,
doc
} from '../internal';
import { doc, globals } from '../globals/globals';

import columnsStyles from './columns.css?inline';

export const toggleColumnsFeature = () => {
if (globalContext.pluginConfig.featureColumnsEnabled) {
if (globals.pluginConfig.featureColumnsEnabled) {
columnsLoad();
} else {
columnsUnload();
}
}

export const columnsLoad = async () => {
if (!globalContext.pluginConfig.featureColumnsEnabled) {
if (!globals.pluginConfig.featureColumnsEnabled) {
return;
}
setTimeout(() => {
14 changes: 5 additions & 9 deletions src/modules/features/features.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@

import {
globalContext,
root
} from '../internal';
import { root, globals } from '../globals/globals';

import './features.css';

export const setFeaturesCSSVars = () => {
if (globalContext.pluginConfig.featureHomeButtonEnabled) {
if (globals.pluginConfig.featureHomeButtonEnabled) {
root.style.removeProperty('--awUI-home-button');
} else {
root.style.setProperty('--awUI-home-button', 'none');
}

if (globalContext.pluginConfig.featureSidebarNewPageEnabled) {
if (globals.pluginConfig.featureSidebarNewPageEnabled) {
root.style.setProperty('--awUI-sidebar-new-page', 'block');
} else {
root.style.removeProperty('--awUI-sidebar-new-page');
}

if (globalContext.pluginConfig.featureSidebarPageIconEnabled) {
if (globals.pluginConfig.featureSidebarPageIconEnabled) {
root.style.setProperty('--awUI-sidebar-page-icon', 'visible');
} else {
root.style.removeProperty('--awUI-sidebar-page-icon');
}

if (globalContext.pluginConfig.featureNewBlockBulletEnabled) {
if (globals.pluginConfig.featureNewBlockBulletEnabled) {
root.style.setProperty('--awUI-new-bullet-hidden', 'none');
} else {
root.style.removeProperty('--awUI-new-bullet-hidden');
9 changes: 3 additions & 6 deletions src/modules/flashcard/flashcard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
globalContext,
doc
} from '../internal';
import { doc, globals } from '../globals/globals';

import flashcardAwesomeStyles from './flashcardAwesome.css?inline';
import flashcardFlatStyles from './flashcardFlat.css?inline';

export const toggleContentFlashcard = () => {
if (globalContext.pluginConfig.contentFlashcard != 'Default') {
if (globals.pluginConfig.contentFlashcard != 'Default') {
flashcardLoad();
} else {
flashcardUnload();
@@ -16,7 +13,7 @@ export const toggleContentFlashcard = () => {

export const flashcardLoad = async () => {
let flashcardStyles = '';
switch (globalContext.pluginConfig.contentFlashcard) {
switch (globals.pluginConfig.contentFlashcard) {
case 'Awesome':
flashcardStyles = flashcardAwesomeStyles
break;
25 changes: 11 additions & 14 deletions src/globals/globals.ts → src/modules/globals/globals.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { logseq as PL } from '../../package.json';
import { logseq as PL } from '../../../package.json';

type globalContextType = {
type globalsType = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

export const globalContext: globalContextType = {
export const doc = parent.document;
export const root = doc.documentElement;
export const body = doc.body;

export const globals: globalsType = {
pluginID: PL.id,
pluginConfig: null,
isPluginEnabled: 'is-awUi-enabled',
isSearchOpenedClass: 'is-search-opened',
isThemesOpenedClass: 'is-themes-opened',
isSearchEnabledClass: 'awUi-search',
promoAwesomeStylerMsg: 'To customize UI & content text/bg colors, install "Awesome Styler" (former "Solarized Extended") theme! https://github.com/yoyurec/logseq-awesome-styler',
tabsPluginIframe: null
tabsPluginIframe: null,
getDOMContainers() {
this.modalContainer = doc.querySelector('.ui__modal-panel');
}
};

export let modalContainer: HTMLElement | null;

export const doc = parent.document;
export const root = doc.documentElement;
export const body = doc.body;

export const getDOMContainers = () => {
modalContainer = doc.querySelector('.ui__modal-panel');
}
9 changes: 3 additions & 6 deletions src/modules/headersLabels/headersLabels.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import {
globalContext,
doc
} from '../internal';
import { doc, globals } from '../globals/globals';

import headersLabelsStyles from './headersLabels.css?inline';

export const toggleHeadersLabelsFeature = () => {
if (globalContext.pluginConfig.featureHeadersLabelsEnabled) {
if (globals.pluginConfig.featureHeadersLabelsEnabled) {
headersLabelsLoad();
} else {
headersLabelsUnload();
}
}

export const headersLabelsLoad = async () => {
if (!globalContext.pluginConfig.featureHeadersLabelsEnabled) {
if (!globals.pluginConfig.featureHeadersLabelsEnabled) {
return;
}
setTimeout(() => {
20 changes: 0 additions & 20 deletions src/modules/internal.ts

This file was deleted.

29 changes: 18 additions & 11 deletions src/modules/modalObserver/modalObserver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {
globalContext,
body, modalContainer,
onSearchModalOpen, onSearchModalClose
} from '../internal';
import { body, globals } from '../globals/globals';

import { onSearchModalOpen, onSearchModalClose } from '../search/search';

// Detect modals opened/closed
let modalObserver: MutationObserver;
let modalObserverConfig: MutationObserverInit;

export const modalObserverLoad = () => {
initModalObserver();
runModalObserver();
}

export const modalObserverUnload = () => {
stopModalObserver();
}

const modalCallback: MutationCallback = (mutationsList) => {
for (let i = 0; i < mutationsList.length; i++) {
const mutationItem = mutationsList[i];
@@ -17,26 +24,26 @@ const modalCallback: MutationCallback = (mutationsList) => {
// Search opened
const searchResults = addedNode.querySelector('.ls-search') as HTMLElement;
if (searchResults) {
body.classList.add(globalContext.isSearchOpenedClass);
body.classList.add(globals.isSearchOpenedClass);
onSearchModalOpen(searchResults);
}
// Themes opened
const themesModal = addedNode.querySelector('.cp__themes-installed') as HTMLElement;
if (themesModal) {
body.classList.add(globalContext.isThemesOpenedClass);
body.classList.add(globals.isThemesOpenedClass);
onSearchModalClose();
}
}
if (removedNode && removedNode.childNodes.length) {
// Search opened
const searchResults = removedNode.querySelector('.ls-search') as HTMLElement;
if (searchResults) {
body.classList.remove(globalContext.isSearchOpenedClass);
body.classList.remove(globals.isSearchOpenedClass);
}
// Themes opened
const themesModal = removedNode.querySelector('.cp__themes-installed') as HTMLElement;
if (themesModal) {
body.classList.remove(globalContext.isThemesOpenedClass);
body.classList.remove(globals.isThemesOpenedClass);
}
}
}
@@ -50,10 +57,10 @@ export const initModalObserver = () => {
}

export const runModalObserver = () => {
if (!modalContainer) {
if (!globals.modalContainer) {
return;
}
modalObserver.observe(modalContainer, modalObserverConfig);
modalObserver.observe(globals.modalContainer, modalObserverConfig);
};

export const stopModalObserver = () => {
45 changes: 23 additions & 22 deletions src/modules/plugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import {
globalContext,
doc, root, body, getDOMContainers,
setFeaturesCSSVars,
searchLoad, searchUnload,
rightSidebarLoad, rightSidebarUnload,
tabsPluginLoad, tabsPluginUnload,
tasksLoad, tasksUnload,
headersLabelsLoad, headersLabelsUnload,
columnsLoad, columnsUnload,
quoteLoad, quoteUnload,
awesomePropsLoad, awesomePropsLoadUnload,
calendarLoad, calendarUnload,
hidePropsUnload, hidePropsLoad,
flashcardLoad, flashcardUnload,
} from '../internal';
import { root, doc, body, globals } from '../globals/globals';

import { awesomePropsLoad, awesomePropsLoadUnload } from '../awesomeProps/awesomeProps';
import { calendarLoad, calendarUnload } from '../calendar/calendar';
import { columnsLoad, columnsUnload } from '../columns/columns';
import { setFeaturesCSSVars } from '../features/features';
import { flashcardLoad, flashcardUnload } from '../flashcard/flashcard';
import { headersLabelsLoad, headersLabelsUnload } from '../headersLabels/headersLabels';
import { hidePropsLoad, hidePropsUnload } from '../props/props';
import { quoteLoad, quoteUnload } from '../quote/quote';
import { searchLoad, searchUnload } from '../search/search';
import { rightSidebarLoad, rightSidebarUnload } from '../sidebars/sidebars';
import { tabsPluginLoad, tabsPluginUnload } from '../tabs/tabs';
import { tasksLoad, tasksUnload } from '../tasks/tasks';
import { checkUpdate, getInheritedBackgroundColor } from '../utils/utils';
import { modalObserverLoad, modalObserverUnload } from '../modalObserver/modalObserver';

export const pluginLoad = () => {
body.classList.add(globalContext.isPluginEnabled);
body.classList.add(globals.isPluginEnabled);
registerPlugin();
runStuff();

@@ -28,15 +27,15 @@ export const pluginLoad = () => {
});
}, 2000)

if (globalContext.pluginConfig.featureUpdaterEnabled) {
if (globals.pluginConfig.featureUpdaterEnabled) {
setTimeout(() => {
checkUpdate();
}, 8000)
}
}

const pluginUnload = () => {
body.classList.remove(globalContext.isPluginEnabled);
body.classList.remove(globals.isPluginEnabled);
unregisterPlugin();
stopStuff();
}
@@ -45,7 +44,7 @@ const registerPlugin = async () => {
setTimeout(() => {
if (doc.head) {
const logseqCSS = doc.head.querySelector(`link[href="./css/style.css"]`);
logseqCSS!.insertAdjacentHTML('afterend', `<link rel="stylesheet" id="css-awesomeUI" href="lsp://logseq.io/${globalContext.pluginID}/dist/assets/awesomeUI.css">`)
logseqCSS!.insertAdjacentHTML('afterend', `<link rel="stylesheet" id="css-awesomeUI" href="lsp://logseq.io/${globals.pluginID}/dist/assets/awesomeUI.css">`)
}
}, 100)
}
@@ -56,14 +55,15 @@ const unregisterPlugin = () => {

// Main logic runners
const runStuff = async () => {
getDOMContainers();
globals.getDOMContainers();
setTimeout(() => {
root.style.setProperty('--awUI-calc-bg', getInheritedBackgroundColor(doc.querySelector('.left-sidebar-inner')).trim());
globalContext.tabsPluginIframe = doc.getElementById('logseq-tabs_iframe') as HTMLIFrameElement;
globals.tabsPluginIframe = doc.getElementById('logseq-tabs_iframe') as HTMLIFrameElement;
setFeaturesCSSVars();
searchLoad();
tabsPluginLoad();
awesomePropsLoad();
modalObserverLoad();
tasksLoad();
headersLabelsLoad();
columnsLoad();
@@ -82,6 +82,7 @@ const stopStuff = () => {
tabsPluginUnload();
rightSidebarUnload();
awesomePropsLoadUnload();
modalObserverUnload();
tasksUnload();
headersLabelsUnload();
columnsUnload();
Loading

0 comments on commit d8e8b42

Please sign in to comment.