diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..1414f46
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,12 @@
+{
+ "singleQuote": true,
+ "trailingComma": "all",
+ "printWidth": 120,
+ "semi": false,
+ "overrides": [
+ {
+ "files": ".prettierrc",
+ "options": { "parser": "json" }
+ }
+ ]
+}
diff --git a/src/addToggleMode.js b/src/addToggleMode.js
new file mode 100644
index 0000000..a3cbc76
--- /dev/null
+++ b/src/addToggleMode.js
@@ -0,0 +1,26 @@
+export default function addToggleMode({ id, on, turnOn, off, turnOff }) {
+ var modeIcon = document.createElement('div')
+ modeIcon.id = id
+ modeIcon.className = `bp3-button bp3-minimal bp3-icon-${off} bp3-small`
+
+ var wrapper = document.querySelector('.rm-topbar')
+ wrapper.appendChild(modeIcon)
+
+ function toggleMode() {
+ if (
+ [].find.call(modeIcon.classList, (name) => {
+ return name === 'bp3-icon-' + on
+ })
+ ) {
+ modeIcon.className = `bp3-button bp3-minimal bp3-icon-${off} bp3-small`
+ turnOff && turnOff()
+ } else {
+ modeIcon.className = `bp3-button bp3-minimal bp3-icon-${on} bp3-small`
+ turnOn && turnOn()
+ }
+ }
+
+ modeIcon.addEventListener('click', toggleMode)
+
+ return toggleMode
+}
diff --git a/src/calendar.js b/src/calendar.js
index fa0fe6c..e7e2af0 100644
--- a/src/calendar.js
+++ b/src/calendar.js
@@ -1,24 +1,23 @@
-import addCalendarTimestamp from "./addCalendarTimestamp";
-import { renderReact } from "./components/render";
-import { addToggleMode } from "./focus";
-import { switchTo } from "./utils/helper";
+import addCalendarTimestamp from './addCalendarTimestamp'
+import addToggleMode from './addToggleMode'
+import { renderTimings } from './components/render'
+import { switchTo } from './utils/helper'
export default function toggleCalendarTimestamp() {
function turnOn() {
- switchTo("calendar-mode");
- renderReact();
- addCalendarTimestamp();
+ switchTo('calendar-mode')
+ renderTimings()
+ addCalendarTimestamp()
}
function turnOff() {
- switchTo("simple-calendar-mode");
+ switchTo('simple-calendar-mode')
}
return addToggleMode({
- id: "mode-toggle-calendar",
- on: "cube-add",
- off: "cube",
- styleContent: ``,
+ id: 'mode-toggle-calendar',
+ on: 'cube-add',
+ off: 'cube',
turnOn,
turnOff,
- });
+ })
}
diff --git a/src/components/render.js b/src/components/render.js
index 5cb3df8..cbab749 100644
--- a/src/components/render.js
+++ b/src/components/render.js
@@ -3,7 +3,7 @@ import React from "react";
import ReactDOM from "react-dom";
import Timings from "./Timings";
-export function renderReact() {
+export function renderTimings() {
const root =
document.getElementsByTagName("timings-root")[0] ||
document.createElement("timings-root");
diff --git a/src/css/focus.less b/src/css/focus.less
new file mode 100644
index 0000000..7182095
--- /dev/null
+++ b/src/css/focus.less
@@ -0,0 +1,27 @@
+.focus-mode {
+ .roam-block-container div[id],
+ .cyxy-function, // 彩云小译
+ #show-toc,
+ .roam-title-day-banner,
+ .rm-topbar {
+ opacity: 0.2;
+
+ &:hover {
+ opacity: 1;
+ }
+ }
+
+ .rm-title-display,
+ .rm-reference-main,
+ .window-headers {
+ opacity: 0.5;
+
+ &:hover {
+ opacity: 1;
+ }
+ }
+
+ .roam-toolkit-block-mode--highlight {
+ opacity: 1 !important;
+ }
+}
diff --git a/src/css/index.less b/src/css/index.less
index 4ef7dc9..748858e 100644
--- a/src/css/index.less
+++ b/src/css/index.less
@@ -1,5 +1,6 @@
@import "card.less";
@import "gingko.less";
+@import "focus.less";
@import "calendar.less";
@import "timings.less";
diff --git a/src/focus.js b/src/focus.js
index b4e98bd..0e63ed8 100644
--- a/src/focus.js
+++ b/src/focus.js
@@ -1,39 +1,14 @@
-import { generateStyleScript } from "./utils/helper";
-
-export function addToggleMode({
- id = "mode-toggle-focus",
- on = "eye-on",
- turnOn,
- off = "eye-open",
- turnOff,
- styleContent = "",
-}) {
- var styleScript = generateStyleScript(styleContent);
-
- var modeIcon = document.createElement("div");
- modeIcon.id = id;
- modeIcon.className = `bp3-button bp3-minimal bp3-icon-${off} bp3-small`;
-
- var wrapper = document.querySelector(".rm-topbar");
- wrapper.appendChild(modeIcon);
-
- function toggleMode() {
- if (
- [].find.call(modeIcon.classList, (name) => {
- return name === "bp3-icon-" + on;
- })
- ) {
- modeIcon.className = `bp3-button bp3-minimal bp3-icon-${off} bp3-small`;
- document.head.removeChild(styleScript);
- turnOff && turnOff();
- } else {
- modeIcon.className = `bp3-button bp3-minimal bp3-icon-${on} bp3-small`;
- document.head.appendChild(styleScript);
- turnOn && turnOn();
- }
- }
-
- modeIcon.addEventListener("click", toggleMode);
-
- return toggleMode;
-}
+import addToggleMode from './addToggleMode'
+import { toggleClass } from './utils/helper'
+
+export const toggleFocusMode = addToggleMode({
+ id: 'mode-toggle-focus',
+ on: 'eye-on',
+ off: 'eye-open',
+ turnOn() {
+ document.querySelector('html').classList.add('focus-mode')
+ },
+ turnOff() {
+ document.querySelector('html').classList.remove('focus-mode')
+ },
+})
diff --git a/src/index.js b/src/index.js
index 911340d..6e76058 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,7 @@ import "./css/card.less";
import "./css/gingko.less";
import "./css/calendar.less";
import "./css/share.less";
+import "./css/focus.less";
setTimeout(() => {
initCardifyTheme();
diff --git a/src/switch.js b/src/switch.js
index b138564..fe19228 100644
--- a/src/switch.js
+++ b/src/switch.js
@@ -1,124 +1,100 @@
import hotkeys from 'hotkeys-js'
import tippy from 'tippy.js'
import toggleCalendarTimestamp from './calendar'
-import { addToggleMode } from './focus'
+import { toggleFocusMode } from './focus'
import { appendIcon, switchTo } from './utils/helper'
import { shareAndDownloadImage } from './utils/share-image'
-const initialMode = localStorage.getItem("INIT_MODE") || "document";
-document.querySelector("html").classList.add(initialMode);
+const initialMode = localStorage.getItem('INIT_MODE') || 'document'
+document.querySelector('html').classList.add(initialMode)
-const switchToCardList = function () {
- switchTo("card-mode");
- /*document.querySelector(".zoom-path-view.rm-zoom") &&
- document.querySelector(".zoom-path-view.rm-zoom").firstChild.click();*/
-};
+appendIcon('cardList', function () {
+ switchTo('card-mode')
+})
+appendIcon('cardFlow', function () {
+ switchTo('flow-mode')
+})
+appendIcon('document', function () {
+ switchTo('document-mode')
+})
+appendIcon('download', shareAndDownloadImage)
-appendIcon("cardList", switchToCardList);
-appendIcon("cardFlow", function () {
- switchTo("flow-mode");
-});
-appendIcon("document", function () {
- switchTo("document-mode");
-});
-appendIcon("download", shareAndDownloadImage);
-
-const toggleCalendarMode = toggleCalendarTimestamp();
-const toggleFocusMode = addToggleMode({
- id: "mode-toggle-focus",
- on: "eye-on",
- off: "eye-open",
- styleContent: `
- .roam-block-container div[id],
- .rm-topbar,
- .cyxy-function {
- opacity: 0.2;
- }
- .roam-block-container div[id]:hover,
- .rm-topbar:hover,
- .cyxy-function:hover {
- opacity: 1;
- }
- .roam-toolkit-block-mode--highlight {
- opacity: 1 !important;
- }
-`,
-});
+const toggleCalendarMode = toggleCalendarTimestamp()
export default function initCardifyTheme() {
- hotkeys("alt+shift+1", function (event, handler) {
- event.preventDefault();
- switchToCardList();
- });
- hotkeys("alt+shift+2", function (event, handler) {
- event.preventDefault();
- switchTo("flow-mode");
- });
- hotkeys("alt+shift+3", function (event, handler) {
- event.preventDefault();
- switchTo("document-mode");
- });
- hotkeys("alt+shift+4", function (event, handler) {
- event.preventDefault();
- toggleCalendarMode();
- });
- hotkeys("alt+shift+c", function (event, handler) {
- event.preventDefault();
- toggleCalendarMode();
- });
- hotkeys("alt+shift+5", function (event, handler) {
- event.preventDefault();
- toggleFocusMode();
- });
- hotkeys("alt+shift+f", function (event, handler) {
- event.preventDefault();
- toggleFocusMode();
- });
- hotkeys("alt+shift+d", async function (event, handler) {
- event.preventDefault();
- await shareAndDownloadImage();
- });
- hotkeys("alt+shift+u", async function (event, handler) {
- event.preventDefault();
+ hotkeys('alt+shift+1', function (event, handler) {
+ event.preventDefault()
+ switchTo('card-mode')
+ })
+ hotkeys('alt+shift+2', function (event, handler) {
+ event.preventDefault()
+ switchTo('flow-mode')
+ })
+ hotkeys('alt+shift+3', function (event, handler) {
+ event.preventDefault()
+ switchTo('document-mode')
+ })
+ hotkeys('alt+shift+4', function (event, handler) {
+ event.preventDefault()
+ toggleCalendarMode()
+ })
+ hotkeys('alt+shift+c', function (event, handler) {
+ event.preventDefault()
+ toggleCalendarMode()
+ })
+ hotkeys('alt+shift+5', function (event, handler) {
+ event.preventDefault()
+ toggleFocusMode()
+ })
+ hotkeys('alt+shift+f', function (event, handler) {
+ event.preventDefault()
+ toggleFocusMode()
+ })
+ hotkeys('alt+shift+d', async function (event, handler) {
+ event.preventDefault()
+ await shareAndDownloadImage()
+ })
+ hotkeys('alt+shift+u', async function (event, handler) {
+ event.preventDefault()
document.querySelector('#unlink-finder-icon').click()
- });
+ })
- tippy("#mode-button-cardList", {
+ tippy('#mode-button-cardList', {
content: `Card Listmode (Alt-Shift-1)`,
allowHTML: true,
- theme: "light-border",
- });
+ theme: 'light-border',
+ })
- tippy("#mode-button-cardFlow", {
+ tippy('#mode-button-cardFlow', {
content: `Card Flowmode (Alt-Shift-2)`,
allowHTML: true,
- theme: "light-border",
- });
+ theme: 'light-border',
+ })
- tippy("#mode-button-document", {
+ tippy('#mode-button-document', {
content: `Outlinermode (Alt-Shift-3)`,
allowHTML: true,
- theme: "light-border",
- });
- tippy("#mode-toggle-calendar", {
+ theme: 'light-border',
+ })
+ tippy('#mode-toggle-calendar', {
content: `Calendarmode (Alt-Shift-4/c)`,
allowHTML: true,
- theme: "light-border",
- });
- tippy("#mode-toggle-focus", {
+ theme: 'light-border',
+ })
+ tippy('#mode-toggle-focus', {
content: `Focusmode (Alt-Shift-5/f)`,
allowHTML: true,
- theme: "light-border",
- });
- tippy("#mode-button-download", {
+ theme: 'light-border',
+ })
+ tippy('#mode-button-download', {
content: `Share Cardmode (Alt-Shift-d)`,
allowHTML: true,
- theme: "light-border",
- });
- tippy("#unlink-finder-icon", {
+ theme: 'light-border',
+ })
+ tippy('#unlink-finder-icon', {
content: `Find Unlinkmode (Alt-Shift-u)`,
allowHTML: true,
- theme: "light-border",
- });
- console.log("started styled-roam");
+ theme: 'light-border',
+ })
+ console.log('started styled-roam')
}
diff --git a/src/utils/helper.js b/src/utils/helper.js
index abbb71c..f8a0588 100644
--- a/src/utils/helper.js
+++ b/src/utils/helper.js
@@ -5,11 +5,11 @@ export function createSpacer() {
}
const MODES = {
- cardList: { text: "Card List", icon: "bp3-icon-full-stacked-chart" },
- cardFlow: { text: "Card Flow", icon: "bp3-icon-heat-grid" },
- document: { text: "Document", icon: "bp3-icon-horizontal-bar-chart" },
- download: { text: "Download", icon: "bp3-icon-download" },
-};
+ cardList: { text: 'Card List', icon: 'bp3-icon-full-stacked-chart' },
+ cardFlow: { text: 'Card Flow', icon: 'bp3-icon-heat-grid' },
+ document: { text: 'Document', icon: 'bp3-icon-horizontal-bar-chart' },
+ download: { text: 'Download', icon: 'bp3-icon-download' },
+}
export function appendIcon(type, clickHandler) {
const mode = MODES[type]
@@ -25,7 +25,10 @@ export function appendIcon(type, clickHandler) {
}
export function switchTo(mode) {
- document.querySelector('html').classList = mode
+ console.log(`🎨 switch styled-roam to ${mode} mode.`)
+ const classList = document.querySelector('html').classList
+ const previousMode = localStorage.getItem('INIT_MODE') || 'document'
+ classList.toggle(previousMode).toggle(mode)
localStorage.setItem('INIT_MODE', mode)
}