Skip to content

Commit

Permalink
Merge pull request #118 from TeselaGen/removeClipboardPackage
Browse files Browse the repository at this point in the history
fix: removeClipboardPackage
  • Loading branch information
jgespinosa10 authored Dec 18, 2024
2 parents 658d39d + d6d327d commit 90baa03
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 240 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"axios": "^0.21.1",
"browser-or-node": "^2.0.0",
"classnames": "^2.3.2",
"clipboard": "2.0.8",
"color": "^3.2.1",
"combokeys": "^3.0.1",
"copy-to-clipboard": "^3.3.1",
Expand Down
126 changes: 49 additions & 77 deletions packages/ove/src/AlignmentView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Droppable,
Draggable as DndDraggable
} from "@hello-pangea/dnd";
import Clipboard from "clipboard";
import React from "react";
import { connect } from "react-redux";
import {
Expand Down Expand Up @@ -104,6 +103,7 @@ export class AlignmentView extends React.Component {
this.handleAlignmentCopy
);
}

getMaxLength = () => {
const { alignmentTracks } = this.props;
const { sequenceData = { sequence: "" }, alignmentData } =
Expand Down Expand Up @@ -175,6 +175,7 @@ export class AlignmentView extends React.Component {
this.onShortcutCopy &&
document.removeEventListener("keydown", this.handleAlignmentCopy);
}

handleAlignmentCopy = event => {
if (
event.key === "c" &&
Expand All @@ -196,6 +197,7 @@ export class AlignmentView extends React.Component {
event.preventDefault();
}
};

getAllAlignmentsFastaText = () => {
const selectionLayer =
this.props.store.getState().VectorEditor.__allEditorsOptions.alignments[
Expand All @@ -214,6 +216,7 @@ export class AlignmentView extends React.Component {
});
return seqDataOfAllTracksToCopy.join("");
};

state = {
alignmentName: this.props.alignmentName,
isTrackDragging: false,
Expand All @@ -222,6 +225,7 @@ export class AlignmentView extends React.Component {
width: 0,
nameDivWidth: 140
};

easyStore = store({
selectionLayer: { start: -1, end: -1 },
caretPosition: -1,
Expand Down Expand Up @@ -280,6 +284,7 @@ export class AlignmentView extends React.Component {
}, 5000);
}
}

componentDidMount() {
const updateAlignmentSelection = newRangeOrCaret => {
this.updateSelectionOrCaret(false, newRangeOrCaret, {
Expand Down Expand Up @@ -1194,6 +1199,44 @@ export class AlignmentView extends React.Component {

const alignmentData = track.alignmentData;
const { name } = alignmentData;

const copySpecificAlignmentFasta = async () => {
const { selectionLayer } =
this.props.store.getState().VectorEditor
.__allEditorsOptions.alignments[
this.props.id
] || {};
const seqDataToCopy = getSequenceDataBetweenRange(
alignmentData,
selectionLayer
).sequence;
const seqDataToCopyAsFasta = `>${name}\r\n${seqDataToCopy}\r\n`;
await navigator.clipboard.writeText(
seqDataToCopyAsFasta
);
};

const copySpecificAlignment = async () => {
const { selectionLayer } =
this.props.store.getState().VectorEditor
.__allEditorsOptions.alignments[
this.props.id
] || {};
const seqDataToCopy = getSequenceDataBetweenRange(
alignmentData,
selectionLayer
).sequence;
await navigator.clipboard.writeText(
seqDataToCopy
);
};

const getAllAlignmentsFastaText = async () => {
await navigator.clipboard.writeText(
this.getAllAlignmentsFastaText()
);
};

showContextMenu(
[
...(additionalSelectionLayerRightClickedOptions
Expand All @@ -1207,61 +1250,17 @@ export class AlignmentView extends React.Component {
className:
"copyAllAlignmentsFastaClipboardHelper",
hotkey: "cmd+c",
willUnmount: () => {
this
.copyAllAlignmentsFastaClipboardHelper &&
this.copyAllAlignmentsFastaClipboardHelper.destroy();
},
didMount: () => {
this.copyAllAlignmentsFastaClipboardHelper =
new Clipboard(
`.copyAllAlignmentsFastaClipboardHelper`,
{
action: "copyAllAlignmentsFasta",
text: () => {
return this.getAllAlignmentsFastaText();
}
}
);
},
onClick: () => {
getAllAlignmentsFastaText();
window.toastr.success("Selection Copied");
}
},
{
text: `Copy Selection of ${name} as Fasta`,
className:
"copySpecificAlignmentFastaClipboardHelper",
willUnmount: () => {
this
.copySpecificAlignmentFastaClipboardHelper &&
this.copySpecificAlignmentFastaClipboardHelper.destroy();
},
didMount: () => {
this.copySpecificAlignmentFastaClipboardHelper =
new Clipboard(
`.copySpecificAlignmentFastaClipboardHelper`,
{
action: "copySpecificAlignmentFasta",
text: () => {
const { selectionLayer } =
this.props.store.getState()
.VectorEditor
.__allEditorsOptions.alignments[
this.props.id
] || {};
const seqDataToCopy =
getSequenceDataBetweenRange(
alignmentData,
selectionLayer
).sequence;
const seqDataToCopyAsFasta = `>${name}\r\n${seqDataToCopy}\r\n`;
return seqDataToCopyAsFasta;
}
}
);
},
onClick: () => {
copySpecificAlignmentFasta();
window.toastr.success(
"Selection Copied As Fasta"
);
Expand All @@ -1271,35 +1270,8 @@ export class AlignmentView extends React.Component {
text: `Copy Selection of ${name}`,
className:
"copySpecificAlignmentAsPlainClipboardHelper",
willUnmount: () => {
this
.copySpecificAlignmentAsPlainClipboardHelper &&
this.copySpecificAlignmentAsPlainClipboardHelper.destroy();
},
didMount: () => {
this.copySpecificAlignmentAsPlainClipboardHelper =
new Clipboard(
`.copySpecificAlignmentAsPlainClipboardHelper`,
{
action: "copySpecificAlignmentFasta",
text: () => {
const { selectionLayer } =
this.props.store.getState()
.VectorEditor
.__allEditorsOptions.alignments[
this.props.id
] || {};
const seqDataToCopy =
getSequenceDataBetweenRange(
alignmentData,
selectionLayer
).sequence;
return seqDataToCopy;
}
}
);
},
onClick: () => {
copySpecificAlignment();
window.toastr.success("Selection Copied");
}
}
Expand All @@ -1313,7 +1285,7 @@ export class AlignmentView extends React.Component {
sequenceLength={sequenceLength}
charWidth={this.getCharWidthInLinearView()}
row={{ start: 0, end: sequenceLength - 1 }}
></PerformantSelectionLayer>
/>
<PerformantCaret
leftMargin={this.state.nameDivWidth}
className="veAlignmentSelectionLayer"
Expand Down Expand Up @@ -1679,7 +1651,7 @@ export class AlignmentView extends React.Component {
sequenceLength={sequenceLength}
charWidth={this.getMinCharWidth(true)}
row={{ start: 0, end: sequenceLength - 1 }}
></PerformantSelectionLayer>
/>
<PerformantCaret
style={{
opacity: 0.2
Expand Down
Loading

0 comments on commit 90baa03

Please sign in to comment.