Skip to content

Commit

Permalink
fix(bug): toggles of plugin settings #148
Browse files Browse the repository at this point in the history
  • Loading branch information
YU000jp committed Jul 19, 2024
1 parent eba7439 commit 308eaed
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 106 deletions.
31 changes: 17 additions & 14 deletions src/boundaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,24 @@ const daysForEach = (days: number[], startDate: Date, boundariesInner: HTMLDivEl

// 20240121
// 祝日のカラーリング機能
const configPreferredLanguage = getConfigPreferredLanguage()
// Chinese lunar-calendar and holidays
if (logseq.settings!.booleanLunarCalendar === true // プラグイン設定で太陰暦オンの場合
&& (configPreferredLanguage === "zh-Hant" //中国語の場合
|| configPreferredLanguage === "zh-CN")) {
dayOfWeekElement.style.fontSize = ".88em"
dayOfWeekElement.innerHTML += ` <smaLl>${lunarString(day, dayElement, true)}</small>` //文字数が少ないため、小さく祝日名を表示する
} else {
// World holidays
const displayNameOfHoliday = holidaysWorld(day, dayElement, true)
if (displayNameOfHoliday
&& (configPreferredLanguage === "ja" //日本語の場合
|| configPreferredLanguage === "ko" // 韓国語の場合
)) dayOfWeekElement.innerHTML += ` <smaLl>${displayNameOfHoliday}</small>` //文字数が少ないため、小さく祝日名を表示する
if (logseq.settings!.booleanBoundariesHolidays === true) {
const configPreferredLanguage = getConfigPreferredLanguage()
// Chinese lunar-calendar and holidays
if (logseq.settings!.booleanLunarCalendar === true // プラグイン設定で太陰暦オンの場合
&& (configPreferredLanguage === "zh-Hant" //中国語の場合
|| configPreferredLanguage === "zh-CN")) {
dayOfWeekElement.style.fontSize = ".88em"
dayOfWeekElement.innerHTML += ` <smaLl>${lunarString(day, dayElement, true)}</small>` //文字数が少ないため、小さく祝日名を表示する
} else {
// World holidays
const displayNameOfHoliday = holidaysWorld(day, dayElement, true)
if (displayNameOfHoliday
&& (configPreferredLanguage === "ja" //日本語の場合
|| configPreferredLanguage === "ko" // 韓国語の場合
)) dayOfWeekElement.innerHTML += ` <smaLl>${displayNameOfHoliday}</small>` //文字数が少ないため、小さく祝日名を表示する
}
}

dayElement.appendChild(dayOfWeekElement)
const dayOfMonthElement: HTMLSpanElement = document.createElement('span')
dayOfMonthElement.classList.add('dayOfMonth')
Expand Down
23 changes: 12 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,18 @@ const main = async () => {
//ページ遷移時に実行 (Journal boundariesとBehind Journal Titleの更新)
logseq.App.onRouteChanged(({ template }) => {

if (logseq.settings!.booleanBoundaries === true
&& template === "/page/:name")
//page only
//div.is-journals
setTimeout(() => boundaries("is-journals"), 20)
else
if (logseq.settings!.booleanJournalsBoundaries === true
&& template === "/")
//journals only
//div#journals
setTimeout(() => boundaries("journals"), 20)
if (logseq.settings!.booleanBoundariesAll === true)
if (logseq.settings!.booleanBoundaries === true
&& template === "/page/:name")
//page only
//div.is-journals
setTimeout(() => boundaries("is-journals"), 20)
else
if (logseq.settings!.booleanJournalsBoundaries === true
&& template === "/")
//journals only
//div#journals
setTimeout(() => boundaries("journals"), 20)

// 左サイドバーのカレンダーを更新する
if (logseq.settings!.booleanLeftCalendar === true)
Expand Down
12 changes: 6 additions & 6 deletions src/left-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getConfigPreferredDateFormat, getConfigPreferredLanguage, pluginName }
import { openPageToSingleDay } from "./boundaries"
import { holidaysWorld, lunarString } from "./holidays"
import { getWeeklyNumberFromDate, getWeeklyNumberString, localizeDayOfWeekString, localizeMonthDayString, localizeMonthString, openPageFromPageName, removeElementById } from "./lib"
import { isCommonSettingsChanged } from "./onSettingsChanged"

export const keyLeftCalendarContainer = "left-calendar-container"

Expand All @@ -25,10 +26,7 @@ export const loadLeftCalendar = () => {
if (oldSet.booleanLcWeekNumber !== newSet.booleanLcWeekNumber
|| oldSet.booleanLcHolidays !== newSet.booleanLcHolidays
|| oldSet.lcHolidaysAlert !== newSet.lcHolidaysAlert
|| oldSet.localizeOrEnglish !== newSet.localizeOrEnglish
|| oldSet.holidaysCountry !== newSet.holidaysCountry
|| oldSet.holidaysState !== newSet.holidaysState
|| oldSet.holidaysRegion !== newSet.holidaysRegion
|| isCommonSettingsChanged(newSet, oldSet) === true //共通処理
)
refreshCalendar(currentCalendarDate, false, false)

Expand Down Expand Up @@ -102,8 +100,10 @@ export const createCalendar = (targetDate: Date, preferredDateFormat: string, in

//カレンダーは7列x5行。週番号の1列を左に追加して、合計8列にする

const calendarFirstDay: Date = ISO ? startOfISOWeek(startOfMonthDay)
: startOfWeek(startOfMonthDay, { weekStartsOn }) //ISO(EU) formatかどうかで分岐
const calendarFirstDay: Date = logseq.settings!.boundariesWeekStart === "unset"
&& ISO ?
startOfISOWeek(startOfMonthDay)
: startOfWeek(startOfMonthDay, { weekStartsOn })
const calendarLastDay: Date = addDays(calendarFirstDay, 34) //35日後の日付を取得
const eachDays = eachDayOfInterval({ start: calendarFirstDay, end: calendarLastDay })//すべての行の日付を取得

Expand Down
16 changes: 10 additions & 6 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,27 @@ body {
}
}

&[data-key="booleanBoundaries"]:has(input.form-checkbox:not(:checked))+div.desc-item[data-key="booleanJournalsBoundaries"] {
&[data-key="booleanBoundariesAll"]:has(input.form-checkbox:not(:checked))+div.desc-item[data-key="booleanBoundaries"] {
display: none;

&+div.desc-item[data-key="booleanBoundariesOnWeeklyJournal"] {
&+div.desc-item[data-key="booleanJournalsBoundaries"] {
display: none;

&+div.desc-item[data-key="boundariesBottom"] {
&+div.desc-item[data-key="booleanBoundariesOnWeeklyJournal"] {
display: none;

&+div.desc-item[data-key="booleanBoundariesShowMonth"] {
&+div.desc-item[data-key="boundariesBottom"] {
display: none;

&+div.desc-item[data-key="booleanBoundariesShowWeekNumber"] {
&+div.desc-item[data-key="booleanBoundariesShowMonth"] {
display: none;

&+div.desc-item[data-key="booleanBoundariesHolidays"] {
&+div.desc-item[data-key="booleanBoundariesShowWeekNumber"] {
display: none;

&+div.desc-item[data-key="booleanBoundariesHolidays"] {
display: none;
}
}
}
}
Expand Down
124 changes: 77 additions & 47 deletions src/onSettingsChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,89 @@ let processingSettingsChanged: boolean = false
let processingRenamePage: boolean = false


export const isCommonSettingsChanged = (oldSet: LSPluginBaseInfo["settings"], newSet: LSPluginBaseInfo["settings"]): boolean => {
if (
//共通設定
oldSet.weekNumberFormat !== newSet.weekNumberFormat
|| oldSet.localizeOrEnglish !== newSet.localizeOrEnglish
|| oldSet.holidaysCountry !== newSet.holidaysCountry
|| oldSet.holidaysState !== newSet.holidaysState
|| oldSet.holidaysRegion !== newSet.holidaysRegion
|| oldSet.booleanLunarCalendar !== newSet.booleanLunarCalendar
|| oldSet.booleanUnderLunarCalendar !== newSet.booleanUnderLunarCalendar
|| oldSet.choiceHolidaysColor !== newSet.choiceHolidaysColor
|| oldSet.booleanBoundariesIndicator !== newSet.booleanBoundariesIndicator
|| oldSet.boundariesWeekStart !== newSet.boundariesWeekStart
|| oldSet.booleanWeekendsColor !== newSet.booleanWeekendsColor
|| oldSet.boundariesHighlightColorSinglePage !== newSet.boundariesHighlightColorSinglePage
|| oldSet.boundariesHighlightColorToday !== newSet.boundariesHighlightColorToday
//booleanNoPageFoundCreatePageは反映不要
//booleanBoundariesFuturePageは反映不要

//Weekly Journalの設定
|| oldSet.weekNumberOptions !== newSet.weekNumberOptions
)
return true
else
return false
}


// ユーザー設定が変更されたときに実行

export const onSettingsChanged = () => {
logseq.onSettingsChanged((newSet: LSPluginBaseInfo["settings"], oldSet: LSPluginBaseInfo["settings"]) => {


if ((oldSet.booleanBoundaries === true
&& newSet.booleanBoundaries === false)
if (
(oldSet.booleanBoundariesAll === true
&& newSet.booleanBoundariesAll === false)
|| (oldSet.booleanBoundaries === true
&& newSet.booleanBoundaries === false)
|| (oldSet.booleanJournalsBoundaries === true
&& newSet.booleanJournalsBoundaries === false
&& parent.document.getElementById("journals") as Node)) removeBoundaries() //boundariesを削除する
&& newSet.booleanJournalsBoundaries === false)
|| (oldSet.booleanBoundariesOnWeeklyJournal === true
&& newSet.booleanBoundariesOnWeeklyJournal === false)
)
removeBoundaries() //boundariesを削除する
else
if (oldSet.booleanBoundaries === false
&& newSet.booleanBoundaries === true)
SettingsChangedJournalBoundariesEnable() //Journal boundariesを表示する
else
if (oldSet.booleanJournalsBoundaries === false
&& newSet.booleanJournalsBoundaries === true
&& parent.document.getElementById("journals") as Node)
boundaries("journals") //日誌の場合のみ


if (oldSet.boundariesWeekStart !== newSet.boundariesWeekStart
|| oldSet.localizeOrEnglish !== newSet.localizeOrEnglish
|| oldSet.weekNumberFormat !== newSet.weekNumberFormat
|| oldSet.booleanBoundariesFuturePage !== newSet.booleanBoundariesFuturePage
if (
(oldSet.booleanBoundariesAll === false
&& newSet.booleanBoundariesAll === true)
|| (oldSet.booleanBoundaries === false
&& newSet.booleanBoundaries === true)
|| (oldSet.booleanJournalsBoundaries === false
&& newSet.booleanJournalsBoundaries === true)
|| (oldSet.booleanBoundariesOnWeeklyJournal === false
&& newSet.booleanBoundariesOnWeeklyJournal === true)
)
SettingsChangedJournalBoundariesEnable(newSet)


if (isCommonSettingsChanged(oldSet, newSet) === true
|| oldSet.booleanWeeklyJournal !== newSet.booleanWeeklyJournal
|| oldSet.boundariesBottom !== newSet.boundariesBottom
|| oldSet.booleanBoundariesShowMonth !== newSet.booleanBoundariesShowMonth
|| oldSet.booleanBoundariesShowWeekNumber !== newSet.booleanBoundariesShowWeekNumber
|| oldSet.booleanWeekendsColor !== newSet.booleanWeekendsColor
|| oldSet.boundariesHighlightColorSinglePage !== newSet.boundariesHighlightColorSinglePage
|| oldSet.boundariesHighlightColorToday !== newSet.boundariesHighlightColorToday
|| oldSet.booleanWeeklyJournal !== newSet.booleanWeeklyJournal
|| oldSet.booleanBoundariesIndicator !== newSet.booleanBoundariesIndicator
|| oldSet.booleanBoundariesHolidays !== newSet.booleanBoundariesHolidays
|| oldSet.holidaysCountry !== newSet.holidaysCountry
|| oldSet.holidaysState !== newSet.holidaysState
|| oldSet.holidaysRegion !== newSet.holidaysRegion
|| oldSet.choiceHolidaysColor !== newSet.choiceHolidaysColor
|| oldSet.booleanLunarCalendar !== newSet.booleanLunarCalendar
|| oldSet.weekNumberOptions !== newSet.weekNumberOptions) {
//Journal boundariesを再表示する
) {
//再表示 Boundaries
removeBoundaries()
SettingsChangedJournalBoundariesEnable()
SettingsChangedJournalBoundariesEnable(newSet)
}


if (oldSet.localizeOrEnglish !== newSet.localizeOrEnglish
if (isCommonSettingsChanged(oldSet, newSet) === true
|| oldSet.booleanDayOfWeek !== newSet.booleanDayOfWeek
|| oldSet.longOrShort !== newSet.longOrShort
|| oldSet.booleanWeekNumber !== newSet.booleanWeekNumber
|| oldSet.weekNumberOfTheYearOrMonth !== newSet.weekNumberOfTheYearOrMonth
|| oldSet.booleanWeekendsColor !== newSet.booleanWeekendsColor
|| oldSet.weekNumberFormat !== newSet.weekNumberFormat
|| oldSet.booleanRelativeTime !== newSet.booleanRelativeTime
|| oldSet.booleanWeeklyJournal !== newSet.booleanWeeklyJournal
|| oldSet.booleanWeekNumberHideYear !== newSet.booleanWeekNumberHideYear
|| oldSet.booleanSettingsButton !== newSet.booleanSettingsButton
|| oldSet.booleanMonthlyJournalLink !== newSet.booleanMonthlyJournalLink
|| oldSet.holidaysCountry !== newSet.holidaysCountry
|| oldSet.holidaysState !== newSet.holidaysState
|| oldSet.holidaysRegion !== newSet.holidaysRegion
|| oldSet.choiceHolidaysColor !== newSet.choiceHolidaysColor
|| oldSet.booleanUnderLunarCalendar !== newSet.booleanUnderLunarCalendar
|| oldSet.underHolidaysAlert !== newSet.underHolidaysAlert
|| oldSet.weekNumberOptions !== newSet.weekNumberOptions
|| oldSet.booleanBesideJournalTitle !== newSet.booleanBesideJournalTitle) {
//再表示 Behind Journal Title
removeTitleQuery()
Expand Down Expand Up @@ -153,12 +171,24 @@ export const onSettingsChanged = () => {


//Journal boundariesを表示する 設定変更時に実行
export const SettingsChangedJournalBoundariesEnable = () =>
setTimeout(() =>
boundaries(parent.document.getElementById("journals") as Node ?
"journals"
: "is-journals"),
100)
export const SettingsChangedJournalBoundariesEnable = (newSet: LSPluginBaseInfo["settings"]) => {
if (newSet.booleanBoundariesAll === true)
setTimeout(() => {
if (newSet.booleanJournalsBoundaries === true
&& parent.document.getElementById("journals") as Node)

boundaries("journals")
else
if (newSet.booleanBoundaries === true
&& parent.document.body.querySelector("div#main-content-container div.is-journals.page>div.relative") as Node)
boundaries("is-journals")
else
if (newSet.booleanBoundariesOnWeeklyJournal === true
&& parent.document.body.querySelector("div#main-content-container div.page.relative>div.relative") as Node)
boundaries("weeklyJournal")
},
100)
}


// 年間のすべての週番号の配列を用意する
Expand Down Expand Up @@ -200,7 +230,7 @@ const changeWeekNumberToQuarterly = async (separateString: string, revert: boole
processingRenamePage = true

const targetList: string[] = getTargetList()
const targetList2 = ["Q1", "Q2", "Q3", "Q4", "Q4"]
const targetList2 = ["Q1", "Q2", "Q3", "Q4"]
const weekList = getWeekList()
for (const year of targetList)
for (const week of weekList) {
Expand Down
3 changes: 2 additions & 1 deletion src/quarterlyJournal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const currentPageIsQuarterlyJournal = async (titleElement: HTMLElement, m
const monthStartDay = startOfMonth(new Date(year, month - 1, 1)) //月初の日付

//Journal Boundariesを表示する
if (logseq.settings!.booleanBoundariesOnWeeklyJournal === true
if ((logseq.settings!.booleanBoundariesAll === true
&& logseq.settings!.booleanBoundariesOnWeeklyJournal === true)
&& !parent.document.getElementById("weekBoundaries")
&& processingFoundBoundaries !== true) {
processingFoundBoundaries = true
Expand Down
37 changes: 22 additions & 15 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ export const settingsTemplate = (userLanguage): SettingSchemaDesc[] => [
description: t("2 or 3 character alphanumeric code or blank (default)"),
default: "",
},
{
key: "booleanLunarCalendar",
title: t("Enable Lunar-calendar based (Chinese only)"),
type: "boolean",
default: true,
description: t("Other language regions are not affected."),
},
{
key: "booleanUnderLunarCalendar",
title: t("Enable month and day of lunar-calendar (Chinese only)"),
type: "boolean",
default: true,
description: t("Other language regions are not affected."),
},
{
key: "choiceHolidaysColor",
title: t("Holidays > Highlight Color"),
Expand All @@ -128,13 +142,6 @@ export const settingsTemplate = (userLanguage): SettingSchemaDesc[] => [
default: "--highlight-bg-color",
description: "default: `--highlight-bg-color`",
},
{
key: "booleanLunarCalendar",
title: t("Enable Lunar-calendar based (Chinese only)"),
type: "boolean",
default: true,
description: t("Other language regions are not affected."),
},
{//20240120
key: "booleanBoundariesIndicator",
title: t("Show indicator of journal entries") + "🆙",
Expand Down Expand Up @@ -189,13 +196,6 @@ export const settingsTemplate = (userLanguage): SettingSchemaDesc[] => [
default: true,
description: "",
},
{
key: "booleanUnderLunarCalendar",
title: t("Enable month and day of lunar-calendar (Chinese only)"),
type: "boolean",
default: true,
description: t("Other language regions are not affected."),
},


//Behind journal title
Expand Down Expand Up @@ -294,10 +294,17 @@ export const settingsTemplate = (userLanguage): SettingSchemaDesc[] => [
description: "",
},
{ // 有効トグル
key: "booleanBoundaries",
key: "booleanBoundariesAll",
title: t("Enable feature"),
type: "boolean",
default: true,
description: "",
},
{ // 有効トグル
key: "booleanBoundaries",
title: "",
type: "boolean",
default: true,
description: t("Use on single journal"),
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
"This is a breaking change for existing users. Please change the old page name using one of the following toggles.": "これは、既存のユーザーにとって重大な変更です。以下のいずれかのトグルで旧ページ名を変更してください。",
"This month": "今月",
"Today": "今日",
"Use on Weekly Journal": "週次ジャーナルでの利用",
"Use on journals": "日誌での使用",
"Use on single journal": "シングル・ジャーナルで使用",
"Use on Weekly Journal": "週次ジャーナルで使用",
"Use on journals": "日誌で使用",
"Use on single journal": "日付ページで使用",
"User color": "ユーザーカラー",
"Week": "",
"Week number calculation (across years)": "週番号の計算 (年全体)",
Expand Down
Loading

0 comments on commit 308eaed

Please sign in to comment.