Skip to content

Commit

Permalink
Introduce Common Selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stvad committed Jun 18, 2020
1 parent d74c04c commit 663f5b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/ts/core/common/dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Selectors} from '../roam/selectors';

export type ValueElement = HTMLTextAreaElement | HTMLInputElement | HTMLSelectElement

export function getActiveEditElement(): ValueElement {
Expand Down Expand Up @@ -25,12 +27,12 @@ export function getTopLevelBlocks() {

export function getLastTopLevelBlock() {
const lastChild = getTopLevelBlocks().lastChild as HTMLElement
return lastChild.querySelector('.roam-block, textarea') as HTMLElement
return lastChild.querySelector(`${Selectors.block}, textarea`) as HTMLElement
}

export function getFirstTopLevelBlock() {
const firstChild = getTopLevelBlocks().firstChild as HTMLElement
return firstChild.querySelector('.roam-block, textarea') as HTMLElement
return firstChild.querySelector(`${Selectors.block}, textarea`) as HTMLElement
}

export function getInputEvent() {
Expand Down
3 changes: 2 additions & 1 deletion src/ts/core/features/estimates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Feature, Settings, Shortcut, String} from '../settings'
import {getActiveEditElement} from '../common/dom'
import {RoamNode} from '../roam/roam-node'
import {Roam} from '../roam/roam'
import {Selectors} from '../roam/selectors';

const estimateProperty: String = {
type: 'string',
Expand All @@ -27,7 +28,7 @@ export const config: Feature = {
}

function getParentElement() {
return getActiveEditElement()?.closest('.roam-block-container')?.parentElement
return getActiveEditElement()?.closest(Selectors.blockContainer)?.parentElement
}

/** I'm still figuring out UX on this one.
Expand Down
3 changes: 2 additions & 1 deletion src/ts/core/features/livePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Navigation} from '../roam/navigation'
import {browser} from 'webextension-polyfill-ts'
import {createPopper, Instance} from '@popperjs/core'
import {delay} from '../common/async';
import {Selectors} from '../roam/selectors';

export const config: Feature = {
id: 'live_preview',
Expand Down Expand Up @@ -236,7 +237,7 @@ class PreviewIframe {
.roam-topbar {
display: none !important;
}
.roam-body-main {
${Selectors.mainPanel} {
top: 0px !important;
}
#buffer {
Expand Down
16 changes: 16 additions & 0 deletions src/ts/core/roam/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const Selectors = {
link: '.rm-page-ref',
block: '.roam-block',
blockContainer: '.roam-block-container',
blockReference: '.rm-block-ref',
title: '.rm-title-display',

mainContent: '.roam-article',
mainPanel: '.roam-body-main',

sidebarContent: '#roam-right-sidebar-content',

highlight: '.block-highlight-blue',
button: '.bp3-button',
closeButton: '.bp3-icon-cross',
}

1 comment on commit 663f5b8

@matiassingers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff @Stvad, let me pull in these changes to my PR 👍

Please sign in to comment.