@jbrowse/plugin-grid-bookmark 2.5.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GridBookmarkWidget/components/AssemblySelector.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/AssemblySelector.js +0 -1
- package/dist/GridBookmarkWidget/components/ClearBookmarks.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/ClearBookmarks.js +0 -1
- package/dist/GridBookmarkWidget/components/DeleteBookmark.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/DeleteBookmark.js +0 -1
- package/dist/GridBookmarkWidget/components/DownloadBookmarks.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/DownloadBookmarks.js +0 -1
- package/dist/GridBookmarkWidget/components/GridBookmarkWidget.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/GridBookmarkWidget.js +0 -1
- package/dist/GridBookmarkWidget/components/ImportBookmarks.d.ts +2 -1
- package/dist/GridBookmarkWidget/components/ImportBookmarks.js +0 -1
- package/dist/GridBookmarkWidget/index.js +0 -1
- package/dist/GridBookmarkWidget/model.js +0 -1
- package/dist/GridBookmarkWidget/types.js +0 -1
- package/dist/GridBookmarkWidget/utils.js +0 -1
- package/dist/index.js +2 -5
- package/esm/GridBookmarkWidget/components/AssemblySelector.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/AssemblySelector.js +0 -1
- package/esm/GridBookmarkWidget/components/ClearBookmarks.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/ClearBookmarks.js +0 -1
- package/esm/GridBookmarkWidget/components/DeleteBookmark.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/DeleteBookmark.js +0 -1
- package/esm/GridBookmarkWidget/components/DownloadBookmarks.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/DownloadBookmarks.js +0 -1
- package/esm/GridBookmarkWidget/components/GridBookmarkWidget.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/GridBookmarkWidget.js +0 -1
- package/esm/GridBookmarkWidget/components/ImportBookmarks.d.ts +2 -1
- package/esm/GridBookmarkWidget/components/ImportBookmarks.js +0 -1
- package/esm/GridBookmarkWidget/index.js +0 -1
- package/esm/GridBookmarkWidget/model.js +0 -1
- package/esm/GridBookmarkWidget/types.js +0 -1
- package/esm/GridBookmarkWidget/utils.js +0 -1
- package/esm/index.js +2 -5
- package/package.json +3 -4
- package/dist/GridBookmarkWidget/components/AssemblySelector.js.map +0 -1
- package/dist/GridBookmarkWidget/components/ClearBookmarks.js.map +0 -1
- package/dist/GridBookmarkWidget/components/DeleteBookmark.js.map +0 -1
- package/dist/GridBookmarkWidget/components/DownloadBookmarks.js.map +0 -1
- package/dist/GridBookmarkWidget/components/GridBookmarkWidget.js.map +0 -1
- package/dist/GridBookmarkWidget/components/ImportBookmarks.js.map +0 -1
- package/dist/GridBookmarkWidget/index.js.map +0 -1
- package/dist/GridBookmarkWidget/model.js.map +0 -1
- package/dist/GridBookmarkWidget/types.js.map +0 -1
- package/dist/GridBookmarkWidget/utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/esm/GridBookmarkWidget/components/AssemblySelector.js.map +0 -1
- package/esm/GridBookmarkWidget/components/ClearBookmarks.js.map +0 -1
- package/esm/GridBookmarkWidget/components/DeleteBookmark.js.map +0 -1
- package/esm/GridBookmarkWidget/components/DownloadBookmarks.js.map +0 -1
- package/esm/GridBookmarkWidget/components/GridBookmarkWidget.js.map +0 -1
- package/esm/GridBookmarkWidget/components/ImportBookmarks.js.map +0 -1
- package/esm/GridBookmarkWidget/index.js.map +0 -1
- package/esm/GridBookmarkWidget/model.js.map +0 -1
- package/esm/GridBookmarkWidget/types.js.map +0 -1
- package/esm/GridBookmarkWidget/utils.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/src/GridBookmarkWidget/components/AssemblySelector.tsx +0 -60
- package/src/GridBookmarkWidget/components/ClearBookmarks.tsx +0 -60
- package/src/GridBookmarkWidget/components/DeleteBookmark.tsx +0 -58
- package/src/GridBookmarkWidget/components/DownloadBookmarks.tsx +0 -80
- package/src/GridBookmarkWidget/components/GridBookmarkWidget.test.tsx +0 -161
- package/src/GridBookmarkWidget/components/GridBookmarkWidget.tsx +0 -136
- package/src/GridBookmarkWidget/components/ImportBookmarks.tsx +0 -131
- package/src/GridBookmarkWidget/index.ts +0 -19
- package/src/GridBookmarkWidget/model.ts +0 -66
- package/src/GridBookmarkWidget/types.ts +0 -5
- package/src/GridBookmarkWidget/utils.ts +0 -90
- package/src/__snapshots__/index.test.ts.snap +0 -3
- package/src/index.test.ts +0 -26
- package/src/index.ts +0 -137
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { types, cast, Instance } from 'mobx-state-tree'
|
|
2
|
-
import PluginManager from '@jbrowse/core/PluginManager'
|
|
3
|
-
import { Region } from '@jbrowse/core/util/types'
|
|
4
|
-
import { Region as RegionModel, ElementId } from '@jbrowse/core/util/types/mst'
|
|
5
|
-
|
|
6
|
-
const LabeledRegionModel = types
|
|
7
|
-
.compose(
|
|
8
|
-
RegionModel,
|
|
9
|
-
types.model('Label', { label: types.optional(types.string, '') }),
|
|
10
|
-
)
|
|
11
|
-
.actions(self => ({
|
|
12
|
-
setLabel(label: string) {
|
|
13
|
-
self.label = label
|
|
14
|
-
},
|
|
15
|
-
}))
|
|
16
|
-
|
|
17
|
-
export default function f(pluginManager: PluginManager) {
|
|
18
|
-
return types
|
|
19
|
-
.model('GridBookmarkModel', {
|
|
20
|
-
id: ElementId,
|
|
21
|
-
type: types.literal('GridBookmarkWidget'),
|
|
22
|
-
view: types.safeReference(
|
|
23
|
-
pluginManager.pluggableMstType('view', 'stateModel'),
|
|
24
|
-
),
|
|
25
|
-
bookmarkedRegions: types.array(LabeledRegionModel),
|
|
26
|
-
modelSelectedAssembly: '',
|
|
27
|
-
})
|
|
28
|
-
.actions(self => ({
|
|
29
|
-
importBookmarks(regions: Region[]) {
|
|
30
|
-
self.bookmarkedRegions = cast([...self.bookmarkedRegions, ...regions])
|
|
31
|
-
},
|
|
32
|
-
addBookmark(region: Region) {
|
|
33
|
-
self.bookmarkedRegions.push(region)
|
|
34
|
-
},
|
|
35
|
-
removeBookmark(index: number) {
|
|
36
|
-
self.bookmarkedRegions.splice(index, 1)
|
|
37
|
-
},
|
|
38
|
-
clearAllBookmarks() {
|
|
39
|
-
self.bookmarkedRegions.clear()
|
|
40
|
-
},
|
|
41
|
-
updateBookmarkLabel(index: number, label: string) {
|
|
42
|
-
self.bookmarkedRegions[index]?.setLabel(label)
|
|
43
|
-
},
|
|
44
|
-
setSelectedAssembly(assembly: string) {
|
|
45
|
-
self.modelSelectedAssembly = assembly
|
|
46
|
-
},
|
|
47
|
-
}))
|
|
48
|
-
.views(self => ({
|
|
49
|
-
get selectedAssembly() {
|
|
50
|
-
return (
|
|
51
|
-
self.modelSelectedAssembly ||
|
|
52
|
-
(self.bookmarkedRegions.length
|
|
53
|
-
? self.bookmarkedRegions[0].assemblyName
|
|
54
|
-
: '')
|
|
55
|
-
)
|
|
56
|
-
},
|
|
57
|
-
get assemblies() {
|
|
58
|
-
return [
|
|
59
|
-
...new Set(self.bookmarkedRegions.map(region => region.assemblyName)),
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
}))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type GridBookmarkStateModel = ReturnType<typeof f>
|
|
66
|
-
export type GridBookmarkModel = Instance<GridBookmarkStateModel>
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { saveAs } from 'file-saver'
|
|
2
|
-
import { getSession, assembleLocString } from '@jbrowse/core/util'
|
|
3
|
-
import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
4
|
-
import { AbstractViewModel } from '@jbrowse/core/util/types'
|
|
5
|
-
|
|
6
|
-
// locals
|
|
7
|
-
import { GridBookmarkModel } from './model'
|
|
8
|
-
import { LabeledRegion } from './types'
|
|
9
|
-
|
|
10
|
-
type LGV = LinearGenomeViewModel
|
|
11
|
-
|
|
12
|
-
type MaybeLGV = LGV | undefined
|
|
13
|
-
|
|
14
|
-
export async function navToBookmark(
|
|
15
|
-
locString: string,
|
|
16
|
-
views: AbstractViewModel[],
|
|
17
|
-
model: GridBookmarkModel,
|
|
18
|
-
) {
|
|
19
|
-
const session = getSession(model)
|
|
20
|
-
try {
|
|
21
|
-
// search for exact match to an lgv that this bookmark widget launched, or
|
|
22
|
-
// any lgv that looks like it is relevant to what we are browsing
|
|
23
|
-
const { selectedAssembly } = model
|
|
24
|
-
const newViewId = `${model.id}_${selectedAssembly}`
|
|
25
|
-
let view = (views.find(
|
|
26
|
-
v => v.type === 'LinearGenomeView' && v.id === newViewId,
|
|
27
|
-
) ||
|
|
28
|
-
views.find(
|
|
29
|
-
v =>
|
|
30
|
-
v.type === 'LinearGenomeView' &&
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
v.assemblyNames[0] === selectedAssembly,
|
|
33
|
-
)) as MaybeLGV
|
|
34
|
-
|
|
35
|
-
if (!view) {
|
|
36
|
-
view = session.addView('LinearGenomeView', {
|
|
37
|
-
id: newViewId,
|
|
38
|
-
}) as LGV
|
|
39
|
-
}
|
|
40
|
-
await view.navToLocString(locString, selectedAssembly)
|
|
41
|
-
} catch (e) {
|
|
42
|
-
console.error(e)
|
|
43
|
-
session.notify(`${e}`, 'error')
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function downloadBookmarkFile(
|
|
48
|
-
bookmarkedRegions: LabeledRegion[],
|
|
49
|
-
fileFormat: string,
|
|
50
|
-
model: GridBookmarkModel,
|
|
51
|
-
) {
|
|
52
|
-
const { selectedAssembly } = model
|
|
53
|
-
const fileHeader =
|
|
54
|
-
fileFormat === 'TSV'
|
|
55
|
-
? 'chrom\tstart\tend\tlabel\tassembly_name\tcoord_range\n'
|
|
56
|
-
: ''
|
|
57
|
-
|
|
58
|
-
const fileContents = bookmarkedRegions
|
|
59
|
-
.map(b => {
|
|
60
|
-
const { label } = b
|
|
61
|
-
const labelVal = label === '' ? '.' : label
|
|
62
|
-
const locString = assembleLocString(b)
|
|
63
|
-
|
|
64
|
-
if (fileFormat === 'BED') {
|
|
65
|
-
if (b.assemblyName === selectedAssembly || selectedAssembly === 'all') {
|
|
66
|
-
return `${b.refName}\t${b.start}\t${b.end}\t${labelVal}\n`
|
|
67
|
-
}
|
|
68
|
-
return ''
|
|
69
|
-
} else {
|
|
70
|
-
return `${b.refName}\t${b.start + 1}\t${b.end}\t${labelVal}\t${
|
|
71
|
-
b.assemblyName
|
|
72
|
-
}\t${locString}\n`
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
.reduce((a, b) => a + b, fileHeader)
|
|
76
|
-
|
|
77
|
-
const blob = new Blob([fileContents || ''], {
|
|
78
|
-
type:
|
|
79
|
-
fileFormat === 'BED'
|
|
80
|
-
? 'text/x-bed;charset=utf-8'
|
|
81
|
-
: 'text/tab-separated-values;charset=utf-8',
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const fileName =
|
|
85
|
-
fileFormat === 'BED'
|
|
86
|
-
? `jbrowse_bookmarks_${selectedAssembly}.bed`
|
|
87
|
-
: 'jbrowse_bookmarks.tsv'
|
|
88
|
-
|
|
89
|
-
saveAs(blob, fileName)
|
|
90
|
-
}
|
package/src/index.test.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import PluginManager from '@jbrowse/core/PluginManager'
|
|
2
|
-
import Config from '@jbrowse/plugin-config'
|
|
3
|
-
import { getSnapshot } from 'mobx-state-tree'
|
|
4
|
-
import ThisPlugin from '.'
|
|
5
|
-
|
|
6
|
-
let pluginManager: PluginManager
|
|
7
|
-
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
pluginManager = new PluginManager([new ThisPlugin(), new Config()])
|
|
10
|
-
pluginManager.createPluggableElements()
|
|
11
|
-
pluginManager.configure()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test("won't add if already added", () => {
|
|
15
|
-
expect(() => pluginManager.addPlugin(new ThisPlugin())).toThrow(
|
|
16
|
-
/JBrowse already configured, cannot add plugins/,
|
|
17
|
-
)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('adds grid bookmark widget', () => {
|
|
21
|
-
const GridBookmarkWidget = pluginManager.getWidgetType('GridBookmarkWidget')
|
|
22
|
-
const config = GridBookmarkWidget.configSchema.create({
|
|
23
|
-
type: 'GridBookmarkWidget',
|
|
24
|
-
})
|
|
25
|
-
expect(getSnapshot(config)).toMatchSnapshot()
|
|
26
|
-
})
|
package/src/index.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import Plugin from '@jbrowse/core/Plugin'
|
|
2
|
-
import PluginManager from '@jbrowse/core/PluginManager'
|
|
3
|
-
import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
|
|
4
|
-
import { getSession, isSessionModelWithWidgets } from '@jbrowse/core/util'
|
|
5
|
-
import {
|
|
6
|
-
PluggableElementType,
|
|
7
|
-
ViewType,
|
|
8
|
-
} from '@jbrowse/core/pluggableElementTypes'
|
|
9
|
-
|
|
10
|
-
// icons
|
|
11
|
-
import BookmarkIcon from '@mui/icons-material/Bookmark'
|
|
12
|
-
import BookmarksIcon from '@mui/icons-material/Bookmarks'
|
|
13
|
-
|
|
14
|
-
import GridBookmarkWidgetF from './GridBookmarkWidget'
|
|
15
|
-
|
|
16
|
-
export default class extends Plugin {
|
|
17
|
-
name = 'GridBookmarkPlugin'
|
|
18
|
-
|
|
19
|
-
install(pluginManager: PluginManager) {
|
|
20
|
-
GridBookmarkWidgetF(pluginManager)
|
|
21
|
-
|
|
22
|
-
pluginManager.addToExtensionPoint(
|
|
23
|
-
'Core-extendPluggableElement',
|
|
24
|
-
(pluggableElement: PluggableElementType) => {
|
|
25
|
-
if (pluggableElement.name === 'LinearGenomeView') {
|
|
26
|
-
const { stateModel } = pluggableElement as ViewType
|
|
27
|
-
const newStateModel = stateModel.extend(
|
|
28
|
-
(self: LinearGenomeViewModel) => {
|
|
29
|
-
const superMenuItems = self.menuItems
|
|
30
|
-
const superRubberBandMenuItems = self.rubberBandMenuItems
|
|
31
|
-
return {
|
|
32
|
-
actions: {
|
|
33
|
-
activateBookmarkWidget() {
|
|
34
|
-
const session = getSession(self)
|
|
35
|
-
if (isSessionModelWithWidgets(session)) {
|
|
36
|
-
let bookmarkWidget = session.widgets.get('GridBookmark')
|
|
37
|
-
if (!bookmarkWidget) {
|
|
38
|
-
bookmarkWidget = session.addWidget(
|
|
39
|
-
'GridBookmarkWidget',
|
|
40
|
-
'GridBookmark',
|
|
41
|
-
{ view: self },
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
session.showWidget(bookmarkWidget)
|
|
46
|
-
return bookmarkWidget
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
throw new Error('Could not open bookmark widget')
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
bookmarkCurrentRegion() {
|
|
53
|
-
const selectedRegions = self.getSelectedRegions(
|
|
54
|
-
self.leftOffset,
|
|
55
|
-
self.rightOffset,
|
|
56
|
-
)
|
|
57
|
-
const firstRegion = selectedRegions[0]
|
|
58
|
-
const session = getSession(self)
|
|
59
|
-
if (isSessionModelWithWidgets(session)) {
|
|
60
|
-
const { widgets } = session
|
|
61
|
-
let bookmarkWidget = widgets.get('GridBookmark')
|
|
62
|
-
if (!bookmarkWidget) {
|
|
63
|
-
this.activateBookmarkWidget()
|
|
64
|
-
bookmarkWidget = widgets.get('GridBookmark')
|
|
65
|
-
}
|
|
66
|
-
// @ts-expect-error
|
|
67
|
-
bookmarkWidget.addBookmark(firstRegion)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
views: {
|
|
72
|
-
menuItems() {
|
|
73
|
-
const newMenuItems = [
|
|
74
|
-
...superMenuItems(),
|
|
75
|
-
{ type: 'divider' },
|
|
76
|
-
{
|
|
77
|
-
label: 'Open bookmark widget',
|
|
78
|
-
icon: BookmarksIcon,
|
|
79
|
-
// @ts-expect-error
|
|
80
|
-
onClick: self.activateBookmarkWidget,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
label: 'Bookmark current region',
|
|
84
|
-
icon: BookmarkIcon,
|
|
85
|
-
// @ts-expect-error
|
|
86
|
-
onClick: self.bookmarkCurrentRegion,
|
|
87
|
-
},
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
return newMenuItems
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
rubberBandMenuItems() {
|
|
94
|
-
const newRubberBandMenuItems = [
|
|
95
|
-
...superRubberBandMenuItems(),
|
|
96
|
-
{
|
|
97
|
-
label: 'Bookmark region',
|
|
98
|
-
icon: BookmarkIcon,
|
|
99
|
-
onClick: () => {
|
|
100
|
-
const { leftOffset, rightOffset } = self
|
|
101
|
-
const selectedRegions = self.getSelectedRegions(
|
|
102
|
-
leftOffset,
|
|
103
|
-
rightOffset,
|
|
104
|
-
)
|
|
105
|
-
const firstRegion = selectedRegions[0]
|
|
106
|
-
const session = getSession(self)
|
|
107
|
-
if (isSessionModelWithWidgets(session)) {
|
|
108
|
-
const { widgets } = session
|
|
109
|
-
let bookmarkWidget = widgets.get('GridBookmark')
|
|
110
|
-
if (!bookmarkWidget) {
|
|
111
|
-
// @ts-expect-error
|
|
112
|
-
self.activateBookmarkWidget()
|
|
113
|
-
bookmarkWidget = widgets.get('GridBookmark')
|
|
114
|
-
}
|
|
115
|
-
// @ts-expect-error
|
|
116
|
-
bookmarkWidget.addBookmark(firstRegion)
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
return newRubberBandMenuItems
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
;(pluggableElement as ViewType).stateModel = newStateModel
|
|
130
|
-
}
|
|
131
|
-
return pluggableElement
|
|
132
|
-
},
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
configure(_pluginManager: PluginManager) {}
|
|
137
|
-
}
|