|
| 1 | +import 'dockview-core/dist/styles/dockview.css'; |
| 2 | +import { |
| 3 | + createDockview, |
| 4 | + DockviewGroupPanel, |
| 5 | + GroupPanelPartInitParameters, |
| 6 | + IContentRenderer, |
| 7 | + IGroupHeaderProps, |
| 8 | + IHeaderActionsRenderer, |
| 9 | +} from 'dockview-core'; |
| 10 | +import './index.css'; |
| 11 | + |
| 12 | +class Panel implements IContentRenderer { |
| 13 | + private readonly _element: HTMLElement; |
| 14 | + |
| 15 | + get element(): HTMLElement { |
| 16 | + return this._element; |
| 17 | + } |
| 18 | + |
| 19 | + constructor() { |
| 20 | + this._element = document.createElement('div'); |
| 21 | + this._element.style.display = 'flex'; |
| 22 | + this._element.style.justifyContent = 'center'; |
| 23 | + this._element.style.alignItems = 'center'; |
| 24 | + this._element.style.color = 'gray'; |
| 25 | + this._element.style.height = '100%'; |
| 26 | + } |
| 27 | + |
| 28 | + init(parameters: GroupPanelPartInitParameters): void { |
| 29 | + // |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +class PrefixHeader implements IHeaderActionsRenderer { |
| 34 | + private readonly _element: HTMLElement; |
| 35 | + |
| 36 | + get element(): HTMLElement { |
| 37 | + return this._element; |
| 38 | + } |
| 39 | + |
| 40 | + constructor(group: DockviewGroupPanel) { |
| 41 | + this._element = document.createElement('div'); |
| 42 | + this._element.className = 'dockview-groupcontrol-demo'; |
| 43 | + this._element.innerText = '🌲'; |
| 44 | + } |
| 45 | + |
| 46 | + init(parameters: IGroupHeaderProps): void { |
| 47 | + // |
| 48 | + } |
| 49 | + |
| 50 | + dispose(): void { |
| 51 | + // |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class RightHeaderActions implements IHeaderActionsRenderer { |
| 56 | + private readonly _element: HTMLElement; |
| 57 | + private readonly _disposables: (() => void)[] = []; |
| 58 | + |
| 59 | + get element(): HTMLElement { |
| 60 | + return this._element; |
| 61 | + } |
| 62 | + |
| 63 | + constructor(group: DockviewGroupPanel) { |
| 64 | + this._element = document.createElement('div'); |
| 65 | + this._element.className = 'dockview-groupcontrol-demo'; |
| 66 | + } |
| 67 | + |
| 68 | + init(parameters: IGroupHeaderProps): void { |
| 69 | + const group = parameters.group; |
| 70 | + |
| 71 | + const span = document.createElement('span'); |
| 72 | + span.className = 'dockview-groupcontrol-demo-group-active'; |
| 73 | + |
| 74 | + this._element.appendChild(span); |
| 75 | + |
| 76 | + const d1 = group.api.onDidActiveChange(() => { |
| 77 | + span.style.background = group.api.isActive ? 'green' : 'red'; |
| 78 | + span.innerText = `${ |
| 79 | + group.api.isActive ? 'Group Active' : 'Group Inactive' |
| 80 | + }`; |
| 81 | + }); |
| 82 | + |
| 83 | + span.style.background = group.api.isActive ? 'green' : 'red'; |
| 84 | + span.innerText = `${ |
| 85 | + group.api.isActive ? 'Group Active' : 'Group Inactive' |
| 86 | + }`; |
| 87 | + |
| 88 | + this._disposables.push(() => d1.dispose()); |
| 89 | + } |
| 90 | + |
| 91 | + dispose(): void { |
| 92 | + this._disposables.forEach((dispose) => dispose()); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +class LeftHeaderActions implements IHeaderActionsRenderer { |
| 97 | + private readonly _element: HTMLElement; |
| 98 | + private readonly _disposables: (() => void)[] = []; |
| 99 | + |
| 100 | + get element(): HTMLElement { |
| 101 | + return this._element; |
| 102 | + } |
| 103 | + |
| 104 | + constructor(group: DockviewGroupPanel) { |
| 105 | + console.log('group', group); |
| 106 | + this._element = document.createElement('div'); |
| 107 | + this._element.className = 'dockview-groupcontrol-demo'; |
| 108 | + } |
| 109 | + |
| 110 | + init(parameters: IGroupHeaderProps): void { |
| 111 | + const group = parameters.group; |
| 112 | + |
| 113 | + const span = document.createElement('span'); |
| 114 | + span.className = 'dockview-groupcontrol-demo-active-panel'; |
| 115 | + |
| 116 | + this._element.appendChild(span); |
| 117 | + |
| 118 | + const d1 = group.api.onDidActivePanelChange((event) => { |
| 119 | + console.log('event', event); |
| 120 | + span.innerText = `activePanel: ${event.panel?.id || 'null'}`; |
| 121 | + }); |
| 122 | + |
| 123 | + console.log('group.activePanel', group.activePanel); |
| 124 | + |
| 125 | + span.innerText = `activePanel: ${group.activePanel?.id || 'null'}`; |
| 126 | + |
| 127 | + this._disposables.push(() => d1.dispose()); |
| 128 | + } |
| 129 | + |
| 130 | + dispose(): void { |
| 131 | + this._disposables.forEach((dispose) => dispose()); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +const api = createDockview(document.getElementById('app'), { |
| 136 | + className: 'dockview-theme-abyss', |
| 137 | + createComponent: (options): IContentRenderer => { |
| 138 | + switch (options.name) { |
| 139 | + case 'default': |
| 140 | + return new Panel(); |
| 141 | + default: |
| 142 | + throw new Error('Panel not found'); |
| 143 | + } |
| 144 | + }, |
| 145 | + createPrefixHeaderActionComponent: (group): IHeaderActionsRenderer => { |
| 146 | + return new PrefixHeader(group); |
| 147 | + }, |
| 148 | + createLeftHeaderActionComponent: (group): IHeaderActionsRenderer => { |
| 149 | + return new LeftHeaderActions(group); |
| 150 | + }, |
| 151 | + createRightHeaderActionComponent: (group): IHeaderActionsRenderer => { |
| 152 | + return new RightHeaderActions(group); |
| 153 | + }, |
| 154 | +}); |
| 155 | + |
| 156 | +api.addPanel({ |
| 157 | + id: 'panel_1', |
| 158 | + component: 'default', |
| 159 | + title: 'Panel 1', |
| 160 | +}); |
| 161 | + |
| 162 | +api.addPanel({ |
| 163 | + id: 'panel_2', |
| 164 | + component: 'default', |
| 165 | + title: 'Panel 2', |
| 166 | + position: { |
| 167 | + direction: 'right', |
| 168 | + }, |
| 169 | +}); |
| 170 | + |
| 171 | +api.addPanel({ |
| 172 | + id: 'panel_3', |
| 173 | + component: 'default', |
| 174 | + title: 'Panel 3', |
| 175 | + position: { |
| 176 | + direction: 'below', |
| 177 | + }, |
| 178 | +}); |
0 commit comments