Skip to content

Commit 9caeb73

Browse files
authored
Decorated Blocks & Live Preview fixes (#426)
* remove defaultEnabled, update README * consolidate camel case "WorkBench" * 1.2.1 * async getParseRoamMarked() * 1.2.2 * update decorated blocks documentation * live preview padding fix * refactor parseRoamMarked await * remove defaultEnabled, update README * async getParseRoamMarked() * 1.2.2 * update decorated blocks documentation * live preview padding fix * refactor parseRoamMarked await
1 parent eab36ef commit 9caeb73

10 files changed

Lines changed: 72 additions & 51 deletions

docs/decorated-blocks.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,39 @@ Toggle the Decorated Blocks module on inside WorkBench.
88

99
![](media/toggle-decorated-blocks.png)
1010

11-
Once enabled, a command will become enabled, `Toggle Block Decorators`. This will open a dialog allowing the user to specify which type of block decorations they would like to their graph. The following are supported:
11+
Once enabled, a command will become enabled, `Toggle Block Decorators`. This will open a dialog allowing the user to specify which type of block decorations they would like to their graph.
1212

13-
Move Todos Enabled - a right facing triangle will appear next to blocks that have TODOs. Clicking this button will will bring up a date time popover, giving users the option to move the block to a future date.
13+
It's possible to assign a unique hotkey to this command, should you prefer to do so. To accomplish this, navigate to either `Settings` > `Hotkeys` or the WorkBench Extension Settings.
1414

15-
Move Tags Enabled - a right facing triangle will appear next to blocks that have a tag. Clicking this button will will bring up a date time popover, giving users the option to move the block to a future date.
15+
The following decorations are supported:
1616

17-
Context Enabled - Replace the `parent` tag with a rendering of the parent block and the `page` tag with a rendering of the block's page name.
17+
## Move Todos Enabled
1818

19-
Hex Color Preview Enabled - Tags that are 6 alpha numeric characters will display the color the tag represents.
19+
![](media/decorated-blocks-move-todos.png)
2020

21-
It's possible to assign a unique hotkey to this command, should you prefer to do so. To accomplish this, navigate to either `Settings` > `Hotkeys` or the WorkBench Extension Settings.
21+
On a Daily Notes Page, When you hover over a block that contains a `TODO`, a right facing triangle will appear to the right.
22+
23+
Clicking this button will will bring up a date time popover, giving users the option to move the block to a future date.
24+
25+
## Move Tags Enabled
26+
27+
![](media/decorated-blocks-move-tags.png)
28+
29+
On a Daily Notes Page, When you hover over a tag (eg. `#someTag` or `[[someTag]]`), a right facing triangle will appear to the right.
30+
31+
Clicking this button will will bring up a date time popover, giving users the option to move the block to a future date.
32+
33+
## Context Enabled
34+
35+
![](media/decorated-blocks-context.png)
36+
37+
Enabling this will
38+
39+
- replace a `#parent` tag with a rendering of the parent block
40+
- a `#page` tag with a rendering of the block's page name.
41+
42+
## Hex Color Preview Enabled
43+
44+
![](media/decorated-blocks-hex-color.png)
45+
46+
Tags that are 6 alpha numeric characters will display the color the tag represents. (eg. `#880808`)
8.6 KB
Loading
3.29 KB
Loading
1.6 KB
Loading
2.31 KB
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/mozilla-readability": "^0.2.0",
2424
"@types/turndown": "^5.0.1"
2525
},
26-
"version": "1.2.1",
26+
"version": "1.2.2",
2727
"samepage": {
2828
"extends": "node_modules/roamjs-components/package.json"
2929
}

src/features/decorators.tsx

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ const DecoratorSettings = ({ isOpen, onClose }: RoamOverlayProps) => {
311311
);
312312
};
313313

314-
export const toggleFeature = (flag: boolean, extensionAPI: OnloadArgs["extensionAPI"] ) => {
314+
export const toggleFeature = (
315+
flag: boolean,
316+
extensionAPI: OnloadArgs["extensionAPI"]
317+
) => {
315318
if (flag) {
316319
extensionAPI.ui.commandPalette.addCommand({
317320
label: "(WB) Toggle Block Decorators",
318-
callback: () => renderOverlay({ Overlay: DecoratorSettings}),
321+
callback: () => renderOverlay({ Overlay: DecoratorSettings }),
319322
});
320323
toggleDecorations(true);
321324
} else {
@@ -331,9 +334,9 @@ const unloads = new Set<() => void>();
331334
export const toggleDecorations = (flag: boolean) => {
332335
if (flag) {
333336
const archivedDefault = !!get("decoratorsMoveArchives"); // Improve the UX for this if feature is re-requested
334-
337+
335338
const opts = JSON.parse(localStorageGet("decorators") || "{}") as Record<
336-
typeof settings[number],
339+
(typeof settings)[number],
337340
boolean
338341
>;
339342
if (opts["Move Todos Enabled"]) {
@@ -411,32 +414,34 @@ export const toggleDecorations = (flag: boolean) => {
411414
getParseInline().then(
412415
(parseInline) => (text: string) => parseInline(text, context)
413416
);
414-
let parseRoamMarked: Awaited<ReturnType<typeof getParseRoamMarked>>;
415-
getParseRoamMarked().then((f) => (parseRoamMarked = f));
416-
const parentTagObserver = createHashtagObserver({
417-
attribute: "data-roamjs-context-parent",
418-
callback: (s) => {
419-
if (s.getAttribute("data-tag") === "parent") {
420-
const uid = getBlockUidFromTarget(s);
421-
const parentUid = getParentUidByBlockUid(uid);
422-
const parentText = getTextByBlockUid(parentUid);
423-
s.className = "rm-block-ref dont-focus-block";
424-
s.style.userSelect = "none";
425-
s.innerHTML = parseRoamMarked(parentText);
426-
s.onmousedown = (e) => e.stopPropagation();
427-
s.onclick = (e) => {
428-
if (e.shiftKey) {
429-
openBlockInSidebar(parentUid);
430-
} else {
431-
window.roamAlphaAPI.ui.mainWindow.openBlock({
432-
block: { uid: parentUid },
433-
});
434-
}
435-
};
436-
}
437-
},
438-
});
439-
unloads.add(() => parentTagObserver.disconnect());
417+
const init = async () => {
418+
const parseRoamMarked = await getParseRoamMarked();
419+
const parentTagObserver = createHashtagObserver({
420+
attribute: "data-roamjs-context-parent",
421+
callback: (s) => {
422+
if (s.getAttribute("data-tag") === "parent") {
423+
const uid = getBlockUidFromTarget(s);
424+
const parentUid = getParentUidByBlockUid(uid);
425+
const parentText = getTextByBlockUid(parentUid);
426+
s.className = "rm-block-ref dont-focus-block";
427+
s.style.userSelect = "none";
428+
s.innerHTML = parseRoamMarked(parentText);
429+
s.onmousedown = (e) => e.stopPropagation();
430+
s.onclick = (e) => {
431+
if (e.shiftKey) {
432+
openBlockInSidebar(parentUid);
433+
} else {
434+
window.roamAlphaAPI.ui.mainWindow.openBlock({
435+
block: { uid: parentUid },
436+
});
437+
}
438+
};
439+
}
440+
},
441+
});
442+
unloads.add(() => parentTagObserver.disconnect());
443+
};
444+
init();
440445

441446
const pageTagObserver = createHashtagObserver({
442447
attribute: "data-roamjs-context-page",

src/features/livePreview.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const TooltipContent = ({
6666
ref={containerRef}
6767
className={"roamjs-workbench-live-preview"}
6868
style={{
69-
paddingTop: !isEmpty ? 16 : 0,
69+
padding: "0 24px",
7070
}}
7171
>
7272
{isEmpty && (
@@ -189,17 +189,7 @@ export const toggleFeature = (flag: boolean) => {
189189
},
190190
});
191191
addStyle(
192-
`.roamjs-workbench-live-preview>div>div>.rm-block-main,
193-
.roamjs-workbench-live-preview>div>div>.rm-inline-references,
194-
.roamjs-workbench-live-preview>div>div>.rm-block-children>.rm-multibar {
195-
display: none;
196-
}
197-
198-
.roamjs-workbench-live-preview>div>div>.rm-block-children {
199-
margin-left: -4px;
200-
}
201-
202-
.roamjs-workbench-live-preview {
192+
`.roamjs-workbench-live-preview {
203193
overflow-y: scroll;
204194
}
205195

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export default runExtension(async ({ extensionAPI, extension }) => {
152152
FEATURES.forEach(({ id, module }) => {
153153
const flag = extensionAPI.settings.get(id);
154154
const unset = typeof flag === "undefined" || flag === null;
155+
if (unset) extensionAPI.settings.set(id, false);
155156
flags.push(unset || flag === false ? false : (flag as boolean));
156157
module.toggleFeature(unset ? false : (flag as boolean), extensionAPI);
157158
});

0 commit comments

Comments
 (0)