mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-08 06:29:03 +00:00
chore: update to support notion 2.3.1 (regex-based replacement for updated webpack bundles)
removed use strict from mjs files, where strict mode is assumed/enforced regardless
This commit is contained in:
parent
ef09280f61
commit
44c480062b
@ -4,8 +4,17 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const replaceIfNotFound = (string, search, replacement) =>
|
const replaceIfNotFound = ({ string, mode = "replace" }, search, replacement) =>
|
||||||
string.includes(replacement) ? string : string.replace(search, replacement);
|
string.includes(replacement)
|
||||||
|
? string
|
||||||
|
: string.replace(
|
||||||
|
search,
|
||||||
|
typeof replacement === "string" && mode === "append"
|
||||||
|
? `$&${replacement}`
|
||||||
|
: typeof replacement === "string" && mode === "prepend"
|
||||||
|
? `${replacement}$&`
|
||||||
|
: replacement
|
||||||
|
);
|
||||||
|
|
||||||
// require()-ing the notion-enhancer in worker scripts
|
// require()-ing the notion-enhancer in worker scripts
|
||||||
// or in renderer scripts will throw errors => manually
|
// or in renderer scripts will throw errors => manually
|
||||||
@ -24,10 +33,19 @@ const mainScript = ".webpack/main/index",
|
|||||||
".webpack/renderer/tabs/preload",
|
".webpack/renderer/tabs/preload",
|
||||||
],
|
],
|
||||||
patches = {
|
patches = {
|
||||||
|
// prettier-ignore
|
||||||
[mainScript]: (scriptContent) => {
|
[mainScript]: (scriptContent) => {
|
||||||
scriptContent = injectTriggerOnce(mainScript, scriptContent);
|
scriptContent = injectTriggerOnce(mainScript, scriptContent);
|
||||||
const replace = (...args) =>
|
const replace = (...args) =>
|
||||||
(scriptContent = replaceIfNotFound(scriptContent, ...args));
|
(scriptContent = replaceIfNotFound(
|
||||||
|
{ string: scriptContent, mode: "replace" },
|
||||||
|
...args
|
||||||
|
)),
|
||||||
|
prepend = (...args) =>
|
||||||
|
(scriptContent = replaceIfNotFound(
|
||||||
|
{ string: scriptContent, mode: "prepend" },
|
||||||
|
...args
|
||||||
|
));
|
||||||
|
|
||||||
// https://github.com/notion-enhancer/notion-enhancer/issues/160:
|
// https://github.com/notion-enhancer/notion-enhancer/issues/160:
|
||||||
// enable the notion:// protocol, windows-style tab layouts, and
|
// enable the notion:// protocol, windows-style tab layouts, and
|
||||||
@ -42,28 +60,22 @@ const mainScript = ".webpack/main/index",
|
|||||||
replace(/sandbox:!0/g, `sandbox:!1,nodeIntegration:!0,session:require('electron').session.fromPartition("persist:notion")`);
|
replace(/sandbox:!0/g, `sandbox:!1,nodeIntegration:!0,session:require('electron').session.fromPartition("persist:notion")`);
|
||||||
|
|
||||||
// bypass webRequest filter to load enhancer menu
|
// bypass webRequest filter to load enhancer menu
|
||||||
replace("r.top!==r?t({cancel:!0})", "r.top!==r?t({})");
|
replace(/(\w)\.top!==\w\?(\w)\({cancel:!0}\)/, "$1.top!==$1?$2({})");
|
||||||
|
|
||||||
// https://github.com/notion-enhancer/desktop/issues/291
|
// https://github.com/notion-enhancer/desktop/issues/291
|
||||||
// bypass csp issues by intercepting the notion:// protocol
|
// bypass csp issues by intercepting the notion:// protocol
|
||||||
const protocolHandler = `try{const t=await p.assetCache.handleRequest(e);`,
|
const protocolHandler = /try{const \w=await \w\.assetCache\.handleRequest\(\w\);/,
|
||||||
protocolInterceptor = `{const n="notion://www.notion.so/__notion-enhancer/";if(e.url.startsWith(n))return require("electron").net.fetch(\`file://\${require("path").join(__dirname,"..","..","node_modules","notion-enhancer",e.url.slice(n.length))}\`)}`;
|
protocolInterceptor = `{const n="notion://www.notion.so/__notion-enhancer/";if(e.url.startsWith(n))return require("electron").net.fetch(\`file://\${require("path").join(__dirname,"..","..","node_modules","notion-enhancer",e.url.slice(n.length))}\`)}`;
|
||||||
replace(protocolHandler, protocolInterceptor + protocolHandler);
|
prepend(protocolHandler, protocolInterceptor);
|
||||||
|
|
||||||
// expose the app config to the global namespace for manipulation
|
// expose the app config to the global namespace for manipulation
|
||||||
// e.g. to enable development mode
|
// e.g. to enable development mode
|
||||||
const configDeclaration = `e.exports=JSON.parse('{"env":"production"`,
|
prepend(/\w\.exports=JSON\.parse\('{"env":"production"/, "globalThis.__notionConfig=");
|
||||||
configInterceptor = `globalThis.__notionConfig=${configDeclaration}`;
|
|
||||||
replace(configDeclaration, configInterceptor);
|
|
||||||
|
|
||||||
// expose the app store to the global namespace for reading
|
// expose the app store to the global namespace for reading
|
||||||
// e.g. to check if keep in background is enabled
|
// e.g. to check if keep in background is enabled
|
||||||
const storeDeclaration = "t.Store=(0,p.configureStore)",
|
prepend(/\w\.Store=\(0,\w\.configureStore\)/, "globalThis.__notionStore=");
|
||||||
updateDeclaration = "t.updatePreferences=n.updatePreferences",
|
prepend(/\w\.updatePreferences=\w\.updatePreferences/, "globalThis.__updatePreferences=");
|
||||||
storeInterceptor = `globalThis.__notionStore=${storeDeclaration}`,
|
|
||||||
updateInterceptor = `globalThis.__updatePreferences=${updateDeclaration}`;
|
|
||||||
replace(storeDeclaration, storeInterceptor);
|
|
||||||
replace(updateDeclaration, updateInterceptor);
|
|
||||||
|
|
||||||
// conditionally create frameless windows
|
// conditionally create frameless windows
|
||||||
const titlebarStyle = `titleBarStyle:globalThis.__notionConfig?.titlebarStyle??"hiddenInset"`;
|
const titlebarStyle = `titleBarStyle:globalThis.__notionConfig?.titlebarStyle??"hiddenInset"`;
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import htm from "../vendor/htm.mjs";
|
import htm from "../vendor/htm.mjs";
|
||||||
import lucide from "../vendor/lucide.mjs";
|
import lucide from "../vendor/lucide.mjs";
|
||||||
import {
|
import {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { checkForUpdate } from "./updateCheck.mjs";
|
import { checkForUpdate } from "./updateCheck.mjs";
|
||||||
import { sendTelemetryPing } from "./sendTelemetry.mjs";
|
import { sendTelemetryPing } from "./sendTelemetry.mjs";
|
||||||
import { Modal, Frame } from "./islands/Modal.mjs";
|
import { Modal, Frame } from "./islands/Modal.mjs";
|
||||||
@ -45,7 +43,7 @@ const shouldLoadThemeOverrides = async (api, db) => {
|
|||||||
|
|
||||||
const insertMenu = async (api, db) => {
|
const insertMenu = async (api, db) => {
|
||||||
const notionSidebar = `.notion-sidebar-container .notion-sidebar > :nth-child(3) > div > :nth-child(2)`,
|
const notionSidebar = `.notion-sidebar-container .notion-sidebar > :nth-child(3) > div > :nth-child(2)`,
|
||||||
notionSettingsAndMembers = `${notionSidebar} > [role="button"]:nth-child(3)`,
|
notionSidebarButtons = `${notionSidebar} > [role="button"]`,
|
||||||
{ html, addMutationListener, removeMutationListener } = api,
|
{ html, addMutationListener, removeMutationListener } = api,
|
||||||
{ addKeyListener, platform, enhancerUrl, onMessage } = api,
|
{ addKeyListener, platform, enhancerUrl, onMessage } = api,
|
||||||
menuButtonIconStyle = await db.get("menuButtonIconStyle"),
|
menuButtonIconStyle = await db.get("menuButtonIconStyle"),
|
||||||
@ -89,9 +87,11 @@ const insertMenu = async (api, db) => {
|
|||||||
>notion-enhancer
|
>notion-enhancer
|
||||||
<//>`;
|
<//>`;
|
||||||
const appendToDom = () => {
|
const appendToDom = () => {
|
||||||
const $settings = document.querySelector(notionSettingsAndMembers);
|
|
||||||
document.body.append($modal);
|
document.body.append($modal);
|
||||||
$settings?.after($button);
|
const btns = document.querySelectorAll(notionSidebarButtons);
|
||||||
|
for (const $btn of btns) {
|
||||||
|
if ($btn.textContent.includes("Settings")) $btn.after($button);
|
||||||
|
}
|
||||||
const appended = document.contains($modal) && document.contains($button);
|
const appended = document.contains($modal) && document.contains($button);
|
||||||
if (appended) removeMutationListener(appendToDom);
|
if (appended) removeMutationListener(appendToDom);
|
||||||
};
|
};
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
let __$wrapper;
|
let __$wrapper;
|
||||||
const setupWrapper = () => {
|
const setupWrapper = () => {
|
||||||
const notionHelp = ".notion-help-button",
|
const notionHelp = ".notion-help-button",
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function MenuButton(
|
function MenuButton(
|
||||||
{ icon, notifications, themeOverridesLoaded, ...props },
|
{ icon, notifications, themeOverridesLoaded, ...props },
|
||||||
...children
|
...children
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Modal(props, ...children) {
|
function Modal(props, ...children) {
|
||||||
const { html, extendProps, addKeyListener } = globalThis.__enhancerApi;
|
const { html, extendProps, addKeyListener } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Tooltip } from "./Tooltip.mjs";
|
import { Tooltip } from "./Tooltip.mjs";
|
||||||
import { TopbarButton } from "./TopbarButton.mjs";
|
import { TopbarButton } from "./TopbarButton.mjs";
|
||||||
import { Select } from "../menu/islands/Select.mjs";
|
import { Select } from "../menu/islands/Select.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Tooltip(props, ...children) {
|
function Tooltip(props, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function TopbarButton({ icon, ...props }, ...children) {
|
function TopbarButton({ icon, ...props }, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Popup } from "./Popup.mjs";
|
import { Popup } from "./Popup.mjs";
|
||||||
import { Button } from "./Button.mjs";
|
import { Button } from "./Button.mjs";
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Button({ icon, variant, tagName, ...props }, ...children) {
|
function Button({ icon, variant, tagName, ...props }, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Checkbox({ _get, _set, _requireReload = true, ...props }) {
|
function Checkbox({ _get, _set, _requireReload = true, ...props }) {
|
||||||
let _initialValue;
|
let _initialValue;
|
||||||
const { html, extendProps, setState, useState } = globalThis.__enhancerApi,
|
const { html, extendProps, setState, useState } = globalThis.__enhancerApi,
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Description(props, ...children) {
|
function Description(props, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Button } from "./Button.mjs";
|
import { Button } from "./Button.mjs";
|
||||||
|
|
||||||
function Footer({ categories, transitionDuration = 150 }) {
|
function Footer({ categories, transitionDuration = 150 }) {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Heading(props, ...children) {
|
function Heading(props, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const updateHotkey = (event) => {
|
const updateHotkey = (event) => {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
for (const modifier of ["metaKey", "ctrlKey", "altKey", "shiftKey"]) {
|
for (const modifier of ["metaKey", "ctrlKey", "altKey", "shiftKey"]) {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
import { Input } from "./Input.mjs";
|
import { Input } from "./Input.mjs";
|
||||||
import { Mod } from "./Mod.mjs";
|
import { Mod } from "./Mod.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
import { Toggle } from "./Toggle.mjs";
|
import { Toggle } from "./Toggle.mjs";
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Heading } from "./Heading.mjs";
|
import { Heading } from "./Heading.mjs";
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
import { Checkbox } from "./Checkbox.mjs";
|
import { Checkbox } from "./Checkbox.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Heading } from "./Heading.mjs";
|
import { Heading } from "./Heading.mjs";
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
import { Input } from "./Input.mjs";
|
import { Input } from "./Input.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Popup(
|
function Popup(
|
||||||
{ trigger, mode = "left", width = 250, maxWidth, ...props },
|
{ trigger, mode = "left", width = 250, maxWidth, ...props },
|
||||||
...children
|
...children
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Heading } from "./Heading.mjs";
|
import { Heading } from "./Heading.mjs";
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
import { Checkbox } from "./Checkbox.mjs";
|
import { Checkbox } from "./Checkbox.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Popup } from "./Popup.mjs";
|
import { Popup } from "./Popup.mjs";
|
||||||
|
|
||||||
function Option({ $icon = "", value = "", _get, _set }) {
|
function Option({ $icon = "", value = "", _get, _set }) {
|
||||||
@ -20,7 +18,7 @@ function Option({ $icon = "", value = "", _get, _set }) {
|
|||||||
onmouseover=${(event) => event.target.focus()}
|
onmouseover=${(event) => event.target.focus()}
|
||||||
onclick=${() => _set?.(value)}
|
onclick=${() => _set?.(value)}
|
||||||
onkeydown=${(event) => {
|
onkeydown=${(event) => {
|
||||||
if (["Enter", " "].includes(event.key)) _set?.(value);
|
// if (["Enter", " "].includes(event.key)) _set?.(value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@ -61,6 +59,7 @@ function Select({
|
|||||||
hover:bg-[color:var(--theme--bg-hover)]"
|
hover:bg-[color:var(--theme--bg-hover)]"
|
||||||
></div>`;
|
></div>`;
|
||||||
|
|
||||||
|
let xyz;
|
||||||
const options = values.map((opt) => {
|
const options = values.map((opt) => {
|
||||||
if (["string", "number"].includes(typeof opt)) opt = { value: opt };
|
if (["string", "number"].includes(typeof opt)) opt = { value: opt };
|
||||||
if (!(opt?.$icon instanceof Element)) {
|
if (!(opt?.$icon instanceof Element)) {
|
||||||
@ -71,7 +70,9 @@ function Select({
|
|||||||
return {
|
return {
|
||||||
...opt,
|
...opt,
|
||||||
$option: html`<${Option} ...${{ ...opt, _get, _set }} />`,
|
$option: html`<${Option} ...${{ ...opt, _get, _set }} />`,
|
||||||
$value: html`<div class="inline-flex text-nowrap items-center gap-[6px]">
|
$value: html`<div
|
||||||
|
class="inline-flex text-nowrap items-center gap-[6px]"
|
||||||
|
>
|
||||||
<!-- swap icon/value order for correct display when dir="rtl" -->
|
<!-- swap icon/value order for correct display when dir="rtl" -->
|
||||||
<span>${opt.value}</span>${opt.$icon?.cloneNode(true) ?? ""}
|
<span>${opt.value}</span>${opt.$icon?.cloneNode(true) ?? ""}
|
||||||
</div>`,
|
</div>`,
|
||||||
@ -80,28 +81,33 @@ function Select({
|
|||||||
getSelected = async () => {
|
getSelected = async () => {
|
||||||
const value = (await _get?.()) ?? $select.innerText,
|
const value = (await _get?.()) ?? $select.innerText,
|
||||||
option = options.find((opt) => opt.value === value);
|
option = options.find((opt) => opt.value === value);
|
||||||
if (!option) _set?.(options[0].value);
|
if (!option) {
|
||||||
|
console.log(1, options, options.length, options === xyz);
|
||||||
|
_set?.(options[0].value);
|
||||||
|
}
|
||||||
return option || options[0];
|
return option || options[0];
|
||||||
},
|
},
|
||||||
onKeydown = (event) => {
|
onKeydown = (event) => {
|
||||||
const intercept = () => {
|
// const intercept = () => {
|
||||||
event.preventDefault();
|
// event.preventDefault();
|
||||||
event.stopPropagation();
|
// event.stopPropagation();
|
||||||
};
|
// };
|
||||||
if (event.key === "Escape") {
|
// if (event.key === "Escape") {
|
||||||
intercept(setState({ rerender: true }));
|
// intercept(setState({ rerender: true }));
|
||||||
} else if (!options.length) return;
|
// } else if (!options.length) return;
|
||||||
// prettier-ignore
|
// // prettier-ignore
|
||||||
const $next = options.find(({ $option }) => $option === event.target)
|
// const $next = options.find(({ $option }) => $option === event.target)
|
||||||
?.$option.nextElementSibling ?? options.at(0).$option,
|
// ?.$option.nextElementSibling ?? options.at(0).$option,
|
||||||
$prev = options.find(({ $option }) => $option === event.target)
|
// $prev = options.find(({ $option }) => $option === event.target)
|
||||||
?.$option.previousElementSibling ?? options.at(-1).$option;
|
// ?.$option.previousElementSibling ?? options.at(-1).$option;
|
||||||
// overflow to opposite end of list from dir of travel
|
// // overflow to opposite end of list from dir of travel
|
||||||
if (event.key === "ArrowUp") intercept($prev.focus());
|
// if (event.key === "ArrowUp") intercept($prev.focus());
|
||||||
if (event.key === "ArrowDown") intercept($next.focus());
|
// if (event.key === "ArrowDown") intercept($next.focus());
|
||||||
// re-enable natural tab behaviour in notion interface
|
// // re-enable natural tab behaviour in notion interface
|
||||||
if (event.key === "Tab") event.stopPropagation();
|
// if (event.key === "Tab") event.stopPropagation();
|
||||||
};
|
};
|
||||||
|
xyz = options;
|
||||||
|
console.log(2, options, options.length, options === xyz);
|
||||||
|
|
||||||
let _initialValue;
|
let _initialValue;
|
||||||
useState(["rerender"], async () => {
|
useState(["rerender"], async () => {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Description } from "./Description.mjs";
|
import { Description } from "./Description.mjs";
|
||||||
|
|
||||||
function SidebarHeading({}, ...children) {
|
function SidebarHeading({}, ...children) {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { collectTelemetryData } from "../../sendTelemetry.mjs";
|
import { collectTelemetryData } from "../../sendTelemetry.mjs";
|
||||||
import { Option } from "./Options.mjs";
|
import { Option } from "./Options.mjs";
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Tile({ icon, title, tagName, ...props }, ...children) {
|
function Tile({ icon, title, tagName, ...props }, ...children) {
|
||||||
const { html, extendProps } = globalThis.__enhancerApi;
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
extendProps(props, {
|
extendProps(props, {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function Toggle({ _get, _set, _requireReload = true, ...props }) {
|
function Toggle({ _get, _set, _requireReload = true, ...props }) {
|
||||||
let _initialValue;
|
let _initialValue;
|
||||||
const { html, extendProps, setState, useState } = globalThis.__enhancerApi,
|
const { html, extendProps, setState, useState } = globalThis.__enhancerApi,
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function View({ id }, ...children) {
|
function View({ id }, ...children) {
|
||||||
const { html, setState, useState } = globalThis.__enhancerApi,
|
const { html, setState, useState } = globalThis.__enhancerApi,
|
||||||
// set padding on last child to maintain pad on overflow
|
// set padding on last child to maintain pad on overflow
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { checkForUpdate, isDevelopmentBuild } from "../updateCheck.mjs";
|
import { checkForUpdate, isDevelopmentBuild } from "../updateCheck.mjs";
|
||||||
import { Sidebar } from "./islands/Sidebar.mjs";
|
import { Sidebar } from "./islands/Sidebar.mjs";
|
||||||
import { Footer } from "./islands/Footer.mjs";
|
import { Footer } from "./islands/Footer.mjs";
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const pingEndpoint = "https://notion-enhancer.deno.dev/api/ping",
|
const pingEndpoint = "https://notion-enhancer.deno.dev/api/ping",
|
||||||
collectTelemetryData = async () => {
|
collectTelemetryData = async () => {
|
||||||
const { platform, version } = globalThis.__enhancerApi,
|
const { platform, version } = globalThis.__enhancerApi,
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
let _release;
|
let _release;
|
||||||
const repo = "notion-enhancer/notion-enhancer",
|
const repo = "notion-enhancer/notion-enhancer",
|
||||||
endpoint = `https://api.github.com/repos/${repo}/releases/latest`,
|
endpoint = `https://api.github.com/repos/${repo}/releases/latest`,
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
export default function ({ web, notion }, db) {
|
export default function ({ web, notion }, db) {
|
||||||
let _openPage = {};
|
let _openPage = {};
|
||||||
|
|
||||||
|
@ -5,23 +5,8 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
import { Heading } from "./islands/Heading.mjs";
|
||||||
|
import { PanelDescription } from "./islands/PanelDescription.mjs";
|
||||||
function Heading({ indent, ...props }, ...children) {
|
|
||||||
const { html } = globalThis.__enhancerApi;
|
|
||||||
return html`<div
|
|
||||||
role="button"
|
|
||||||
class="notion-enhancer--outliner-heading block
|
|
||||||
relative cursor-pointer select-none text-[14px]
|
|
||||||
decoration-(2 [color:var(--theme--fg-border)])
|
|
||||||
hover:bg-[color:var(--theme--bg-hover)]
|
|
||||||
py-[6px] pr-[2px] pl-[${indent * 18}px]
|
|
||||||
underline-(~ offset-4) last:mb-[24px]"
|
|
||||||
...${props}
|
|
||||||
>
|
|
||||||
${children}
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async (api, db) => {
|
export default async (api, db) => {
|
||||||
const { html, debounce, addMutationListener, addPanelView } = api,
|
const { html, debounce, addMutationListener, addPanelView } = api,
|
||||||
@ -50,12 +35,7 @@ export default async (api, db) => {
|
|||||||
<path d="M17,20.05h-6c-0.55,0-1-0.45-1-1v0c0-0.55,0.45-1,1-1h6c0.55,0,1,0.45,1,1v0C18,19.6,17.55,20.05,17,20.05z"/>
|
<path d="M17,20.05h-6c-0.55,0-1-0.45-1-1v0c0-0.55,0.45-1,1-1h6c0.55,0,1,0.45,1,1v0C18,19.6,17.55,20.05,17,20.05z"/>
|
||||||
</svg>`,
|
</svg>`,
|
||||||
$view: html`<section>
|
$view: html`<section>
|
||||||
<p
|
<${PanelDescription}>Click on a heading to jump to it.<//>
|
||||||
class="py-[12px] px-[18px]
|
|
||||||
text-([color:var(--theme--fg-secondary)] [13px])"
|
|
||||||
>
|
|
||||||
Click on a heading to jump to it.
|
|
||||||
</p>
|
|
||||||
${$toc}
|
${$toc}
|
||||||
</section>`,
|
</section>`,
|
||||||
});
|
});
|
||||||
|
23
src/extensions/outliner/islands/Heading.mjs
Normal file
23
src/extensions/outliner/islands/Heading.mjs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* notion-enhancer: outliner
|
||||||
|
* (c) 2024 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
||||||
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
|
*/
|
||||||
|
|
||||||
|
function Heading({ indent, ...props }, ...children) {
|
||||||
|
const { html } = globalThis.__enhancerApi;
|
||||||
|
return html`<div
|
||||||
|
role="button"
|
||||||
|
class="notion-enhancer--outliner-heading block
|
||||||
|
relative cursor-pointer select-none text-[14px]
|
||||||
|
decoration-(2 [color:var(--theme--fg-border)])
|
||||||
|
hover:bg-[color:var(--theme--bg-hover)]
|
||||||
|
py-[6px] pr-[2px] pl-[${indent * 18}px]
|
||||||
|
underline-(~ offset-4) last:mb-[24px]"
|
||||||
|
...${props}
|
||||||
|
>
|
||||||
|
${children}
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Heading };
|
16
src/extensions/outliner/islands/PanelDescription.mjs
Normal file
16
src/extensions/outliner/islands/PanelDescription.mjs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* notion-enhancer: outliner
|
||||||
|
* (c) 2024 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
||||||
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
|
*/
|
||||||
|
|
||||||
|
function PanelDescription(props, ...children) {
|
||||||
|
const { html, extendProps } = globalThis.__enhancerApi;
|
||||||
|
extendProps(props, {
|
||||||
|
class: `py-[12px] px-[18px] text-(
|
||||||
|
[13px] [color:var(--theme--fg-secondary)])`,
|
||||||
|
});
|
||||||
|
return html` <p ...${props}>${children}</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PanelDescription };
|
@ -5,8 +5,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { FloatingButton } from "../../core/islands/FloatingButton.mjs";
|
import { FloatingButton } from "../../core/islands/FloatingButton.mjs";
|
||||||
|
|
||||||
export default async (api, db) => {
|
export default async (api, db) => {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Tooltip } from "../../core/islands/Tooltip.mjs";
|
import { Tooltip } from "../../core/islands/Tooltip.mjs";
|
||||||
import { TopbarButton } from "../../core/islands/TopbarButton.mjs";
|
import { TopbarButton } from "../../core/islands/TopbarButton.mjs";
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { createWindowButtons } from "./buttons.mjs";
|
import { createWindowButtons } from "./buttons.mjs";
|
||||||
|
|
||||||
export default async (api, db) => {
|
export default async (api, db) => {
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import { Tooltip } from "../../core/islands/Tooltip.mjs";
|
import { Tooltip } from "../../core/islands/Tooltip.mjs";
|
||||||
import { TopbarButton } from "../../core/islands/TopbarButton.mjs";
|
import { TopbarButton } from "../../core/islands/TopbarButton.mjs";
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
export default (async () => {
|
export default (async () => {
|
||||||
Object.assign((globalThis.__enhancerApi ??= {}), {
|
Object.assign((globalThis.__enhancerApi ??= {}), {
|
||||||
...(globalThis.__getEnhancerApi?.() ?? {}),
|
...(globalThis.__getEnhancerApi?.() ?? {}),
|
||||||
|
Loading…
Reference in New Issue
Block a user