-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathside-panel.tsx
More file actions
130 lines (116 loc) · 3.9 KB
/
Copy pathside-panel.tsx
File metadata and controls
130 lines (116 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// eslint-disable-next-line no-use-before-define
import React from 'react'
import { AbstractPanel } from './panel'
import { RemixPluginPanel } from '@remix-ui/panel'
import packageJson from '../../../../../package.json'
import { RemixUIPanelHeader } from '@remix-ui/panel'
import { PluginViewWrapper } from '@remix-ui/helper'
// const csjs = require('csjs-inject')
const sidePanel = {
name: 'sidePanel',
displayName: 'Side Panel',
description: 'Remix IDE side panel',
version: packageJson.version,
methods: ['addView', 'removeView', 'currentFocus', 'pinView', 'unPinView', 'focus', 'showContent']
}
export class SidePanel extends AbstractPanel {
sideelement: any
loggedState: any
dispatch: React.Dispatch<any> = () => {}
constructor() {
super(sidePanel)
this.sideelement = document.createElement('section')
this.sideelement.setAttribute('class', 'panel plugin-manager')
}
onActivation() {
this.renderComponent()
// Toggle content
this.on('menuicons', 'toggleContent', (name) => {
if (!this.plugins[name]) return
if (this.plugins[name].active) {
// TODO: Only keep `this.emit` (issue#2210)
this.emit('toggle', name)
this.events.emit('toggle', name)
return
}
this.showContent(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('showing', name)
this.events.emit('showing', name)
})
// Force opening
this.on('menuicons', 'showContent', (name) => {
if (!this.plugins[name]) return
this.showContent(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('showing', name)
this.events.emit('showing', name)
})
}
focus(name) {
this.emit('focusChanged', name)
super.focus(name)
}
removeView(profile) {
if (this.plugins[profile.name] && this.plugins[profile.name].active) this.call('menuicons', 'select', 'filePanel')
super.removeView(profile)
this.renderComponent()
}
addView(profile, view) {
super.addView(profile, view)
this.call('menuicons', 'linkContent', profile)
this.renderComponent()
}
async pinView (profile) {
const active = this.currentFocus()
await this.call('pinnedPanel', 'pinView', profile, this.plugins[profile.name]?.view)
if (this.plugins[profile.name].active) {
this.call('menuicons', 'select', 'filePanel')
}
if (active === profile.name) this.call('menuicons', 'select', active.length > 1 ? active : 'filePanel')
super.remove(profile.name)
this.renderComponent()
}
async unPinView (profile, view) {
const activePlugin = this.currentFocus()
if (activePlugin === profile.name) throw new Error(`Plugin ${profile.name} already unpinned`)
this.loggedState = await this.call('pluginStateLogger', 'getPluginState', profile.name)
super.addView(profile, view)
this.plugins[activePlugin].active = false
this.plugins[profile.name].active = true
if (profile.name !== 'remixaiassistant') {
this.showContent(profile.name)
}
this.emit('focusChanged', profile.name)
// this.showContent(profile.name)
}
/**
* Display content and update the header
* @param {String} name The name of the plugin to display
*/
async showContent(name) {
super.showContent(name)
this.emit('focusChanged', name)
this.renderComponent()
}
setDispatch(dispatch: React.Dispatch<any>) {
this.dispatch = dispatch
}
render() {
return (
<section className="panel plugin-manager">
{' '}
<PluginViewWrapper plugin={this} />
</section>
)
}
updateComponent(state: any) {
return <RemixPluginPanel header={<RemixUIPanelHeader plugins={state.plugins} pinView={this.pinView.bind(this)} unPinView={this.unPinView.bind(this)}></RemixUIPanelHeader>} plugins={state.plugins} pluginState={state.pluginState} />
}
renderComponent() {
this.dispatch({
plugins: this.plugins,
pluginState: this.loggedState
})
}
}