Skip to content

Hyperlink feature in progress #313

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions src/hyperlink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//Hyperlink related functions

export function stringToHyperlink(rawData: any): any {
try {
//checks if the rawData provided is a valid url
const url = new URL(rawData);
//turns url into a hyperlink
const hyperlink = rawData.link(url);
return hyperlink;
} catch (e) {
return rawData;
}
}

export function checkHyperlink(rawData: any): any {
try {
//checks if the rawData provided is a valid url
new URL(rawData);
return true;
} catch (e) {
return false;
}
}
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ function addCommands(
}
});

commands.addCommand(CommandIDs.openLinkContextMenu, {
label: 'Open Link',
execute: () => {
tracker.currentWidget &&
tracker.currentWidget.content.commandSignal.emit('open-link');
}
});

commands.addCommand(CommandIDs.clearCells, {
label: 'Clear Contents',
execute: () => {
Expand Down Expand Up @@ -397,6 +405,8 @@ function addCommands(
'cutContextMenu',
'copyContextMenu',
'pasteContextMenu',
'separator',
'openLinkContextMenu', //temporarily here to display the open link command on the context menu
'separator'
];

Expand Down Expand Up @@ -709,5 +719,6 @@ export const CommandIDs: { [key: string]: string } = {
save: 'tde-save',
clearCells: 'tde-clear-contents',
clearColumns: 'tde-clear-columns',
clearRows: 'tde-clear-rows'
clearRows: 'tde-clear-rows',
openLinkContextMenu: 'tde:open-link'
};
13 changes: 12 additions & 1 deletion src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { unsaveDialog } from './dialog';
import { PaintedGrid } from './grid';
import { HeaderTextRenderer } from './headercelleditor';
import { RichKeyHandler } from './keyhandler';
import { checkHyperlink } from './hyperlink';

const CSV_CLASS = 'jp-CSVViewer';
const CSV_GRID_CLASS = 'jp-CSVViewer-grid';
Expand Down Expand Up @@ -553,6 +554,15 @@ export class DSVEditor extends Widget {
let update: DSVEditor.ModelChangedArgs | null = null;

switch (command) {
case 'open-link': {
const cellData = this.dataModel.data('body', r1, c1);
const checkedHyperlink = checkHyperlink(cellData);
if (checkedHyperlink) {
window.open(cellData, '_blank');
}
break;
}

case 'insert-rows-above': {
update = this.dataModel.addRows('body', r1, rowSpan);
break;
Expand Down Expand Up @@ -894,7 +904,8 @@ export namespace DSVEditor {
| 'paste-cells'
| 'undo'
| 'redo'
| 'save';
| 'save'
| 'open-link';
/**

* The arguments emitted to the Editor when the datamodel changes
Expand Down