Skip to content

Commit

Permalink
fix(all): imports refactoring
Browse files Browse the repository at this point in the history
yoyurec committed Feb 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 30a54f4 commit d8e8b42
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();
28 changes: 28 additions & 0 deletions src/modules/props/hideProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { doc, globals } from '../globals/globals';


export const hideProps = async () => {
if (!globals.pluginConfig.featureHideDotProps && !globals.pluginConfig.featureHideSetOfProps) {
return;
}
let hidePropsArr: string[] = [];
if (globals.pluginConfig.featureHideSetOfProps) {
hidePropsArr = (globals.pluginConfig.featureHideSetOfProps as string).trim().toLowerCase().replaceAll(', ', ',').split(',');
}
const propKeyList = doc.querySelectorAll('.block-properties .page-property-key');
if (propKeyList.length) {
for (let i = 0; i < propKeyList.length; i++) {
const propKeyItemText = propKeyList[i].textContent;
const propItem = propKeyList[i].parentElement!.parentElement;
if (propKeyItemText && propItem) {
if (globals.pluginConfig.featureHideDotProps && propKeyItemText?.startsWith('.')) {
propItem.classList.add('hidden', 'awUI-hideDotProp');
} else if (globals.pluginConfig.featureHideSetOfProps && hidePropsArr.includes(propKeyItemText)) {
propItem.classList.add('hidden', 'awUI-hideSetOfProps');
} else {
propItem.classList.remove('hidden', 'awUI-hideSetOfProps');
}
}
}
}
};
39 changes: 6 additions & 33 deletions src/modules/props/props.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
globalContext,
doc,
propsChangedObserverInit, propsChangedObserverRun, propsChangedObserverStop
} from '../internal';
import { doc, globals } from '../globals/globals';
import { hideProps } from './hideProps';

import { propsChangedObserverInit, propsChangedObserverRun, propsChangedObserverStop } from './propsObserver';

import './props.css';

@@ -26,15 +25,15 @@ export const hidePropsUnload = () => {
}

export const toggleHideDotPropsFeature = () => {
if (globalContext.pluginConfig.featureHideDotProps) {
if (globals.pluginConfig.featureHideDotProps) {
hideProps();
} else {
hideDotPropsUnload();
}
}

export const toggleHideSetOfPropsFeature = () => {
if (globalContext.pluginConfig.featureHideSetOfProps) {
if (globals.pluginConfig.featureHideSetOfProps) {
hideProps();
} else {
hideSetOfPropsUnload();
@@ -60,29 +59,3 @@ const hideSetOfPropsUnload = () => {
}
}
}

export const hideProps = async () => {
if (!globalContext.pluginConfig.featureHideDotProps && !globalContext.pluginConfig.featureHideSetOfProps) {
return;
}
let hidePropsArr: string[] = [];
if (globalContext.pluginConfig.featureHideSetOfProps) {
hidePropsArr = (globalContext.pluginConfig.featureHideSetOfProps as string).trim().toLowerCase().replaceAll(', ', ',').split(',');
}
const propKeyList = doc.querySelectorAll('.block-properties .page-property-key');
if (propKeyList.length) {
for (let i = 0; i < propKeyList.length; i++) {
const propKeyItemText = propKeyList[i].textContent;
const propItem = propKeyList[i].parentElement!.parentElement;
if (propKeyItemText && propItem) {
if (globalContext.pluginConfig.featureHideDotProps && propKeyItemText?.startsWith('.')) {
propItem.classList.add('hidden', 'awUI-hideDotProp');
} else if (globalContext.pluginConfig.featureHideSetOfProps && hidePropsArr.includes(propKeyItemText)) {
propItem.classList.add('hidden', 'awUI-hideSetOfProps');
} else {
propItem.classList.remove('hidden', 'awUI-hideSetOfProps');
}
}
}
}
}
65 changes: 37 additions & 28 deletions src/modules/props/propsObserver.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
import { doc } from '../internal';
import { hideProps } from '../internal';
import { doc } from '../globals/globals';
import { hideProps } from './hideProps';

let propsChangedObserverConfig: MutationObserverInit;
let propsChangedObserver: MutationObserver;

export const propsChangedObserverInit = () => {
propsChangedObserverConfig = {
attributes: true,
attributeFilter: ['class'],
attributeOldValue: true,
subtree: true
}
const propsChangedCallback: MutationCallback = function (mutationsList) {
for (let i = 0; i < mutationsList.length; i++) {
const mutationItem = mutationsList[i];
const mutationTarget = mutationItem.target as HTMLElement;
if (mutationTarget && mutationTarget.offsetParent?.classList.contains('pre-block') && mutationItem.oldValue === 'editor-wrapper') {
setTimeout(() => {
hideProps();
}, 10)
}
}
}
propsChangedObserver = new MutationObserver(propsChangedCallback);
}
propsChangedObserverConfig = {
attributes: true,
attributeFilter: ['class'],
attributeOldValue: true,
subtree: true,
};
const propsChangedCallback: MutationCallback = function (mutationsList) {
for (let i = 0; i < mutationsList.length; i++) {
const mutationItem = mutationsList[i];
const mutationTarget = mutationItem.target as HTMLElement;
if (
mutationTarget &&
mutationTarget.offsetParent?.classList.contains('pre-block') &&
mutationItem.oldValue === 'editor-wrapper'
) {
setTimeout(() => {
onPropsChanged();
}, 10);
}
}
};
propsChangedObserver = new MutationObserver(propsChangedCallback);
};

const onPropsChanged = () => {
hideProps();
};

export const propsChangedObserverRun = () => {
const preBlock = doc.getElementsByClassName('content')[0]?.firstChild?.firstChild?.firstChild?.firstChild;
if (preBlock) {
propsChangedObserver.observe(preBlock, propsChangedObserverConfig);
}
}
const preBlock =
doc.getElementsByClassName('content')[0]?.firstChild?.firstChild?.firstChild?.firstChild;
if (preBlock) {
propsChangedObserver.observe(preBlock, propsChangedObserverConfig);
}
};

export const propsChangedObserverStop = () => {
propsChangedObserver.disconnect();
}
propsChangedObserver.disconnect();
};
9 changes: 3 additions & 6 deletions src/modules/quote/quote.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 quoteStyles from './quote.css?inline';

export const toggleQuoteFeature = () => {
if (globalContext.pluginConfig.featureQuoteEnabled) {
if (globals.pluginConfig.featureQuoteEnabled) {
quoteLoad();
} else {
quoteUnload();
}
}

export const quoteLoad = async () => {
if (!globalContext.pluginConfig.featureQuoteEnabled) {
if (!globals.pluginConfig.featureQuoteEnabled) {
return;
}
setTimeout(() => {
13 changes: 3 additions & 10 deletions src/modules/search/search.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
globalContext,
body, doc,
initModalObserver, runModalObserver, stopModalObserver
} from '../internal';
import { doc, body, globals } from '../globals/globals';

import './search.css';

@@ -36,25 +32,22 @@ export const onSearchModalClose = () => {

// Reposition toolbar search button
export const searchLoad = async () => {
body.classList.add(globalContext.isSearchEnabledClass);
body.classList.add(globals.isSearchEnabledClass);
const rightToolbar = doc.querySelector('#head .r');
if (rightToolbar) {
const search = doc.getElementById('search-button');
if (search) {
rightToolbar.insertAdjacentElement('afterbegin', search);
}
}
initModalObserver();
runModalObserver();
}

export const searchUnload = () => {
body.classList.remove(globalContext.isSearchEnabledClass);
body.classList.remove(globals.isSearchEnabledClass);
const leftToolbar = doc.querySelector('#head .l');
const search = doc.getElementById('search-button');
if (!leftToolbar || !search) {
return;
}
leftToolbar.insertAdjacentElement('beforeend', search);
stopModalObserver();
}
31 changes: 14 additions & 17 deletions src/modules/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import { LSPluginBaseInfo } from '@logseq/libs/dist/LSPlugin.user';

import {
globalContext,
settingsConfig,
toggleCalendarFeature,
toggleColumnsFeature,
toggleQuoteFeature,
toggleContentFlashcard,
toggleTasksFeature,
toggleHeadersLabelsFeature,
toggleHideDotPropsFeature,
toggleHideSetOfPropsFeature,
toggleAwesomePropsFeature,
setFeaturesCSSVars,
} from '../internal';
import { globals } from '../globals/globals';
import { settingsConfig } from './settingsConfig';
import { toggleTasksFeature } from '../tasks/tasks';
import { toggleColumnsFeature } from '../columns/columns';
import { toggleQuoteFeature } from '../quote/quote';
import { toggleAwesomePropsFeature } from '../awesomeProps/awesomeProps';
import { toggleCalendarFeature } from '../calendar/calendar';
import { setFeaturesCSSVars } from '../features/features';
import { toggleContentFlashcard } from '../flashcard/flashcard';
import { toggleHeadersLabelsFeature } from '../headersLabels/headersLabels';
import { toggleHideDotPropsFeature, toggleHideSetOfPropsFeature } from '../props/props';
import { objectDiff } from '../utils/utils';

import './settings.css';

export const settingsLoad = () => {
logseq.useSettingsSchema(settingsConfig);
globalContext.pluginConfig = logseq.settings;
globals.pluginConfig = logseq.settings;

// Listen settings update
logseq.onSettingsChanged((settings, oldSettings) => {
@@ -30,8 +27,8 @@ export const settingsLoad = () => {

// Setting changed
export const onSettingsChangedCallback = (settings: LSPluginBaseInfo['settings'], oldSettings: LSPluginBaseInfo['settings']) => {
globalContext.pluginConfig = { ...settings };
const settingsDiff = objectDiff({ ...oldSettings }, globalContext.pluginConfig)
globals.pluginConfig = { ...settings };
const settingsDiff = objectDiff({ ...oldSettings }, globals.pluginConfig)
console.log(`AwesomeUI: settings changed:`, settingsDiff);

if (settingsDiff.includes('featureTasksEnabled')) {
6 changes: 2 additions & 4 deletions src/modules/settings/settingsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin.user';
import {
globalContext
} from '../internal';
import { globals } from '../globals/globals';

export const settingsConfig: SettingSchemaDesc[] = [
{
key: 'promoAwesomeStyler',
title: '',
description: globalContext.promoAwesomeStylerMsg,
description: globals.promoAwesomeStylerMsg,
type: 'boolean',
default: false,
},
2 changes: 1 addition & 1 deletion src/modules/sidebars/sidebars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { doc } from '../internal';
import { doc } from '../globals/globals';

import './sidebars.css';

22 changes: 9 additions & 13 deletions src/modules/tabs/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {
globalContext,
root, doc, body,
} from '../internal';
import { root, doc, body, globals } from '../globals/globals';
import { getInheritedBackgroundColor } from '../utils/utils';

import './tabs.css';
import tabsIframeStyles from './tabsIframe.css?inline';
import { getInheritedBackgroundColor } from '../utils/utils';


setTimeout(() => {
// Listen for theme activated
@@ -76,20 +72,20 @@ const tabsPluginEjectCSS = (tabsPluginIframe: HTMLIFrameElement) => {

// First init run
export const tabsPluginLoad = async () => {
if (globalContext.tabsPluginIframe) {
tabPluginInjectCSS(globalContext.tabsPluginIframe);
tabPluginInjectCSSVars(globalContext.tabsPluginIframe);
if (globals.tabsPluginIframe) {
tabPluginInjectCSS(globals.tabsPluginIframe);
tabPluginInjectCSSVars(globals.tabsPluginIframe);
}
}
export const tabsPluginUnload = () => {
if (globalContext.tabsPluginIframe) {
tabsPluginEjectCSS(globalContext.tabsPluginIframe);
if (globals.tabsPluginIframe) {
tabsPluginEjectCSS(globals.tabsPluginIframe);
}
}

export const setTabsStyles = () => {
root.style.setProperty('--awUI-calc-bg', getInheritedBackgroundColor(doc.querySelector('.left-sidebar-inner')).trim());
if (globalContext.tabsPluginIframe) {
tabPluginInjectCSSVars(globalContext.tabsPluginIframe);
if (globals.tabsPluginIframe) {
tabPluginInjectCSSVars(globals.tabsPluginIframe);
}
}
9 changes: 3 additions & 6 deletions src/modules/tasks/tasks.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 tasksStyles from './tasks.css?inline';

export const toggleTasksFeature = () => {
if (globalContext.pluginConfig.featureTasksEnabled) {
if (globals.pluginConfig.featureTasksEnabled) {
tasksLoad();
} else {
tasksUnload();
}
}

export const tasksLoad = async () => {
if (!globalContext.pluginConfig.featureTasksEnabled) {
if (!globals.pluginConfig.featureTasksEnabled) {
return;
}
setTimeout(() => {
6 changes: 3 additions & 3 deletions src/modules/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { packageVersion } from '../../../.version';

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

export const objectDiff = (orig: object, updated: object) => {
const difference = Object.keys(orig).filter((key) => {
@@ -26,7 +26,7 @@ export const getInheritedBackgroundColor = (el: Element | null): string => {

export const checkUpdate = async () => {
const response = await fetch(
`https://api.github.com/repos/yoyurec/${globalContext.pluginID}/releases/latest`,
`https://api.github.com/repos/yoyurec/${globals.pluginID}/releases/latest`,
{ headers: { 'Accept': 'application/vnd.github.v3+json' } }
);
if (!response.ok) {
@@ -39,7 +39,7 @@ export const checkUpdate = async () => {
// https://stackoverflow.com/a/65687141
const hasUpdate = latestReleaseVersion.localeCompare(packageVersion, undefined, { numeric: true, sensitivity: 'base' });
if (hasUpdate == 1) {
logseq.UI.showMsg(`"${globalContext.pluginID}" new version is available! Please, update!`, 'warning', {timeout: 30000});
logseq.UI.showMsg(`"${globals.pluginID}" new version is available! Please, update!`, 'warning', {timeout: 30000});
}
}
}

0 comments on commit d8e8b42

Please sign in to comment.