Skip to content

Commit

Permalink
feat: support multiple position
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvanduocit committed Dec 13, 2022
1 parent 763245f commit 670740d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
5 changes: 4 additions & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare type WebviewTag = {
setAttribute(allowpopups: string, true1: string): void
setAttribute(allowpopups: string, attr: string): void
reload(): void
loadURL(pageUrl: string): void
goBack(): void
Expand All @@ -12,10 +12,13 @@ declare type WebviewTag = {
addClass(cls: string): void
}

declare type GateFrameOptionType = 'left' | 'center' | 'right'

declare type GateFrameOption = {
id: string
icon: string
title: string
url: string
hasRibbon?: boolean
position?: GateFrameOptionType
}
1 change: 1 addition & 0 deletions src/fns/createEmptyGateOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const createEmptyGateOption = (): GateFrameOption => {
title: '',
icon: 'dice',
hasRibbon: true,
position: "right",
url: ''
}
}
11 changes: 11 additions & 0 deletions src/fns/formEditGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export const formEditGate = (
})
)

new Setting(contentEl).setName('Pin to menu').addDropdown((text) =>
text
.addOption('left', 'Left')
.addOption('right', 'Right')
.addOption('center', 'Center')
.setValue(gateOptions.position ?? 'right')
.onChange(async (value) => {
gateOptions.position = value as GateFrameOptionType
})
)

new Setting(contentEl).addButton((btn) =>
btn
.setButtonText(gateOptions.id ? 'Update' : 'Create')
Expand Down
27 changes: 23 additions & 4 deletions src/fns/openView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@ import { GateView } from '../GateView'

export const openView = async (
workspace: Workspace,
id: string
id: string,
position?: GateFrameOptionType
): Promise<void> => {
let leaf: WorkspaceLeaf
let leafs = workspace.getLeavesOfType(id)
if (leafs.length == 0) {
await workspace.getLeaf(false).setViewState({ type: id, active: true })
createView(workspace, id, position)
}

leaf = workspace.getLeavesOfType(id)[0]
workspace.revealLeaf(leaf)
}

if (leaf.view instanceof GateView) {
leaf.view.focus()
const createView = (
workspace: Workspace,
id: string,
position?: GateFrameOptionType
) => {
let leaf: WorkspaceLeaf | undefined
switch (position) {
case "left":
leaf = workspace.getLeftLeaf(false)
break
case "center":
leaf = workspace.getLeaf(false)
break
case "right":
default:
leaf = workspace.getRightLeaf(false)
break
}

leaf?.setViewState({ type: id, active: true })
}
2 changes: 1 addition & 1 deletion src/fns/registerGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const registerGate = (plugin: Plugin, options: GateFrameOption) => {

if (options.hasRibbon) {
plugin.addRibbonIcon(iconName, options.title, async (evt: MouseEvent) =>
openView(plugin.app.workspace, options.id)
openView(plugin.app.workspace, options.id, options.position)
)
}

Expand Down
12 changes: 6 additions & 6 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
}
}

.open-gate-webview {
.open-gate-view {
padding: 0 !important;
overflow: hidden !important;
}

.open-gate-view webview {
width: 100%;
height: 100%;
border: none;
background-color: var(--open-gate-background);
}

.open-gate-view {
padding: 0 !important;
overflow: hidden !important;
}

.gate-header {
display: flex;
justify-content: space-between;
Expand Down

0 comments on commit 670740d

Please sign in to comment.