Skip to content

Commit

Permalink
Merge branch 'release/v1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
freder committed Apr 22, 2023
2 parents f665822 + b1b6e1d commit fe31ee3
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 284 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.4.0
### Added
- Setting for whether the first item should be selected when opening the palette or not (#12)
- Setting configuring the max. depth of the displayed items (#14)


## 1.3.1
### Added
- Show notification when current page is not supported (e.g. `Journals`)
Expand Down
459 changes: 231 additions & 228 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-jump-to-block",
"version": "1.3.1",
"version": "1.4.0",
"main": "dist/index.html",
"logseq": {
"id": "logseq-plugin-jump-to-block"
Expand Down
6 changes: 2 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

It lets you fuzzy search the 'table of contents' of the current page and scroll to the selected block. If the any parent blocks of the selected block are collapsed, they will be expanded.

<a href="https://www.buymeacoffee.com/freder" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 50px !important"></a>

---

Execute the `Jump to block…` command via the command palette, or via keyboard shortcut (default: `mod-t`).

<img src="./screenrecording.gif" alt="screen recording" width="700" />

---

<a href="https://www.buymeacoffee.com/freder" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 50px !important"></a>
103 changes: 59 additions & 44 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { BlockEntity } from '@logseq/libs/dist/LSPlugin.user';
import type { InitalSelectionOption } from '../types';

import React, { useEffect, useState, Fragment } from 'react';
import CommandPalette, { Command } from 'react-command-palette';
Expand All @@ -11,6 +12,7 @@ import { prepareLabel } from '../utils';
// @ts-ignore
import theme from '../../node_modules/react-command-palette/dist/themes/sublime-theme';
import '../../node_modules/react-command-palette/dist/themes/sublime.css';
import { defaultMaxDepth, initialSelectionOptionDefault } from '../constants';


type PathItem = {
Expand Down Expand Up @@ -106,6 +108,52 @@ const makeCommands = (
};


const makeStyles = () => {
const computedStyles = getComputedStyle(
window.parent.document.documentElement
);
const bg = computedStyles.getPropertyValue(
'--ls-secondary-background-color'
);
const bgSelection = computedStyles.getPropertyValue(
'--ls-a-chosen-bg'
);
const text = computedStyles.getPropertyValue(
'--ls-primary-text-color'
);
const textSelection = computedStyles.getPropertyValue(
'--ls-secondary-text-color'
);
const input = computedStyles.getPropertyValue(
'--ls-primary-background-color'
);
return css`
.sublime-modal, .sublime-suggestionsList .sublime-suggestion {
background: ${bg} !important;
color: ${text} !important;
}
.sublime-suggestionsList .sublime-suggestionHighlighted {
background: ${bgSelection} !important;
color: ${textSelection} !important;
}
.sublime-suggestion {
background: ${bgSelection} !important;
}
.sublime-input {
background: ${input} !important;
color: ${text} !important;
}
*::-webkit-scrollbar-thumb {
background-color: ${bgSelection} !important;
border: solid 3px ${bg} !important;
}
.indentation {
color: ${bgSelection} !important;
}
`;
};


function App() {
const [open, setOpen] = useState(false);
const [items, setItems] = useState<Command[]>([]);
Expand Down Expand Up @@ -142,7 +190,10 @@ function App() {
return closeHandler();
}

const maxDepth = 3; // TODO: make this configurable
const maxDepth: number = Math.max(
0,
logseq.settings?.maxDepth || defaultMaxDepth
);
const items = makeCommands(blocks, maxDepth);
setItems(items);
setOpen(true);
Expand All @@ -159,55 +210,19 @@ function App() {
[]
);

const computedStyles = getComputedStyle(
window.parent.document.documentElement
);
const bg = computedStyles.getPropertyValue(
'--ls-secondary-background-color'
);
const bgSelection = computedStyles.getPropertyValue(
'--ls-a-chosen-bg'
);
const text = computedStyles.getPropertyValue(
'--ls-primary-text-color'
);
const textSelection = computedStyles.getPropertyValue(
'--ls-secondary-text-color'
);
const input = computedStyles.getPropertyValue(
'--ls-primary-background-color'
);
const initialSelection: InitalSelectionOption = logseq.settings?.initialSelection || initialSelectionOptionDefault;
const highlightFirstSuggestion = initialSelection === 'First block';
// TODO: implement 'Current block'
const defaultInputValue = '';

return <Fragment>
<Global styles={css`
.sublime-modal, .sublime-suggestionsList .sublime-suggestion {
background: ${bg} !important;
color: ${text} !important;
}
.sublime-suggestionsList .sublime-suggestionHighlighted {
background: ${bgSelection} !important;
color: ${textSelection} !important;
}
.sublime-suggestion {
background: ${bgSelection} !important;
}
.sublime-input {
background: ${input} !important;
color: ${text} !important;
}
*::-webkit-scrollbar-thumb {
background-color: ${bgSelection} !important;
border: solid 3px ${bg} !important;
}
.indentation {
color: ${bgSelection} !important;
}
`} />
<Global styles={makeStyles} />
<CommandPalette
open={open}
closeOnSelect
alwaysRenderCommands
highlightFirstSuggestion
highlightFirstSuggestion={highlightFirstSuggestion}
defaultInputValue={defaultInputValue}
resetInputOnOpen
placeholder="Type to filter…"
hotKeys={[]}
Expand Down
4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { InitalSelectionOption } from './types';

export const initialSelectionOptionDefault: InitalSelectionOption = 'Nothing';
export const defaultMaxDepth = 3;
35 changes: 28 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@ import type {
SettingSchemaDesc,
SimpleCommandKeybinding
} from '@logseq/libs/dist/LSPlugin';
import type { InitalSelectionOption } from './types';

import React from 'react';
import ReactDOM from 'react-dom/client';
import '@logseq/libs';

import { makeToolbarIcon } from './toolbar';
import { defaultMaxDepth, initialSelectionOptionDefault } from './constants';
import App from './components/App';



const cmdKey = 'jumpToBlock';
const cmdLabel = 'Jump to block…';
const settingsKey = cmdKey;
const settingsLabel = cmdLabel;
const initialSelectionOptions: InitalSelectionOption[] = [
/* 'Current block', */ 'First block', 'Nothing'
];
const settings: SettingSchemaDesc[] = [
{
key: settingsKey,
title: settingsLabel,
description: 'Jump to a block within the current page',
description: 'Keybinding',
default: 'mod+t',
type: 'string',
},
Expand All @@ -30,6 +36,22 @@ const settings: SettingSchemaDesc[] = [
default: false,
type: 'boolean',
},
{
key: 'initialSelection',
title: 'What to select when opening the palette',
description: '',
default: initialSelectionOptionDefault,
type: 'enum',
enumChoices: initialSelectionOptions as string[],
enumPicker: 'radio',
},
{
key: 'maxDepth',
title: 'Maximum block depth',
description: 'Limits the depth of blocks to be shown in the palette (0 = root-level)',
default: defaultMaxDepth,
type: 'number',
},
];


Expand All @@ -49,17 +71,16 @@ const main = async () => {
// </React.StrictMode>
);

// auto open
const PageSet = new Set();
// auto open palette when opening a page
let pagePath = '';
logseq.App.onRouteChanged(async (event) => {
const autoOpen = logseq.settings?.autoOpen || '';
if (autoOpen === true) {
if (event && event.template === '/page/:name') {
if (!PageSet.has(event.path)) {
PageSet.clear();
if (event.template === '/page/:name') {
if (pagePath !== event.path) {
logseq.showMainUI({ autoFocus: false });
}
await PageSet.add(event.path);
pagePath = event.path;
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO: 'Current block'
export type InitalSelectionOption = 'First block' | 'Nothing';

0 comments on commit fe31ee3

Please sign in to comment.