Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance view-markdown-source with line actions #3594

Merged
merged 10 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions source/features/view-markdown-source.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,79 @@
import './view-markdown-source.css';
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import delegate from 'delegate-it';
import CodeIcon from 'octicon/code.svg';
import FileIcon from 'octicon/file.svg';
import * as pageDetect from 'github-url-detection';

import FileIcon from 'octicon/file.svg';
import CodeIcon from 'octicon/code.svg';
import KebabHorizontalIcon from 'octicon/kebab-horizontal.svg';

import features from '.';
import fetchDom from '../helpers/fetch-dom';
import GitHubURL from '../github-helpers/github-url';
import {getRepoURL} from '../github-helpers';

const lineActions = onetime(() => (
<details
className="details-reset details-overlay BlobToolbar position-absolute js-file-line-actions dropdown d-none"
aria-hidden="true"
>
<summary
className="btn-octicon ml-0 px-2 p-0 bg-white border border-gray-dark rounded-1"
aria-label="Inline file action toolbar"
aria-haspopup="menu"
role="button"
>
<KebabHorizontalIcon/>
</summary>
<details-menu role="menu">
<ul
className="BlobToolbar-dropdown dropdown-menu dropdown-menu-se mt-2"
style={{width: '185px'}}
>
<li>
<clipboard-copy
role="menuitem"
className="dropdown-item zeroclipboard-link"
id="js-copy-lines"
>
Copy line
</clipboard-copy>
</li>
<li>
<clipboard-copy
role="menuitem"
className="dropdown-item zeroclipboard-link"
id="js-copy-permalink"
>
Copy permalink
</clipboard-copy>
</li>
<li>
<a
className="dropdown-item js-update-url-with-hash"
id="js-view-git-blame"
role="menuitem"
href={new GitHubURL(location.href).assign({route: 'blame'}).href}
>
View git blame
</a>
</li>
<li>
<a
className="dropdown-item"
id="js-new-issue"
role="menuitem"
href={`/${getRepoURL()}/issues/new`}
>
Reference in new issue
</a>
</li>
</ul>
</details-menu>
</details>
));

const buttonBodyMap = new WeakMap<Element, Element | Promise<Element>>();

Expand Down Expand Up @@ -53,6 +119,7 @@ async function showSource(): Promise<void> {
sourceButton.classList.add('selected');
renderedButton.classList.remove('selected');
blurButton(sourceButton);
(await source).before(lineActions());

dispatchEvent(sourceButton, 'rgh:view-markdown-source');
}
Expand All @@ -70,6 +137,7 @@ async function showRendered(): Promise<void> {
sourceButton.classList.remove('selected');
renderedButton.classList.add('selected');
blurButton(renderedButton);
lineActions().remove();

dispatchEvent(sourceButton, 'rgh:view-markdown-rendered');
}
Expand Down
1 change: 1 addition & 0 deletions source/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ declare namespace JSX {
'time-ago': BaseIntrinsicElement & {datetime: string; format?: string};
'relative-time': BaseIntrinsicElement & {datetime: string};
'details-dialog': BaseIntrinsicElement & {tabindex: string};
'clipboard-copy': IntrinsicElements['button'];
}

interface IntrinsicAttributes extends BaseIntrinsicElement {
Expand Down