-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from novrain/feature/using_lumino_widget
Feature/using lumino widget
- Loading branch information
Showing
14 changed files
with
597 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Message } from '@lumino/messaging' | ||
import { Widget } from '@lumino/widgets' | ||
|
||
export interface Item { | ||
id: string, | ||
name: string, | ||
} | ||
|
||
export interface OnClose { | ||
(msg: Message): void | ||
} | ||
|
||
export interface OnActive { | ||
(msg: Message): void | ||
} | ||
|
||
export interface Options { | ||
closable?: boolean | ||
onClose?: OnClose | ||
onActive?: OnActive | ||
} | ||
|
||
export interface WidgetEvent { | ||
msg: Message | ||
item: Item | ||
widget: ItemWidget | ||
} | ||
|
||
export class ItemWidget extends Widget { | ||
closable: boolean | ||
item: Item | ||
onClose?: OnClose | ||
onActive?: OnActive | ||
|
||
constructor(item: Item, { closable = true, onClose }: Options) { | ||
super({ node: ItemWidget.createNode(item) }) | ||
this.closable = closable | ||
// classes and flags | ||
this.setFlag(Widget.Flag.DisallowLayout) | ||
this.addClass('lumino-content') | ||
// tab title | ||
this.title.label = item.name | ||
this.title.closable = closable | ||
this.item = item | ||
this.onClose = onClose | ||
} | ||
|
||
static createNode(item: Item) { | ||
const div = document.createElement('div') | ||
div.setAttribute('id', item.id) | ||
return div | ||
} | ||
|
||
protected onActivateRequest(msg: Message): void { | ||
super.onActivateRequest(msg) | ||
if (this.onActive) { | ||
this.onActive(msg) | ||
} | ||
} | ||
|
||
protected onCloseRequest(msg: Message): void { | ||
if (this.onClose) { | ||
this.onClose(msg) | ||
} else { | ||
super.onCloseRequest(msg) | ||
} | ||
} | ||
|
||
doClose(msg: Message): void { | ||
super.onCloseRequest(msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<template> | ||
<div class="lumino-container" | ||
ref="container"> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import "@fortawesome/fontawesome-free/css/all.css" | ||
import '@lumino/default-theme/style/index.css' | ||
import { BoxPanel, DockPanel, Widget } from '@lumino/widgets' | ||
import { provide, onMounted, onUpdated, ref, onUnmounted } from 'vue' | ||
const boxPanel = new BoxPanel({ direction: 'left-to-right', spacing: 0 }) | ||
const dockPanel = new DockPanel() | ||
boxPanel.id = 'box-panel' | ||
dockPanel.id = 'dock-panel' | ||
provide('boxPanel', boxPanel) | ||
provide('dockPanel', dockPanel) | ||
const container = ref<HTMLElement | null>(null) | ||
const onWindowResize = () => { | ||
boxPanel.update() | ||
} | ||
onMounted(() => { | ||
boxPanel.addWidget(dockPanel) | ||
BoxPanel.setStretch(dockPanel, 1) | ||
if (container.value) { | ||
Widget.attach(boxPanel, container.value) | ||
} | ||
window.addEventListener('resize', onWindowResize) | ||
}) | ||
onUnmounted(() => { | ||
window.removeEventListener('resize', onWindowResize) | ||
}) | ||
onUpdated(() => { | ||
boxPanel.update() | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.lumino-container { | ||
display: flex; | ||
flex: 1; | ||
:deep(#box-panel) { | ||
display: flex; | ||
flex: 1; | ||
.lumino-content { | ||
border: 1px solid #c0c0c0; | ||
border-top: none; | ||
background: white; | ||
position: relative; | ||
overflow: auto; | ||
display: flex; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<div v-show="false"> | ||
<div class="lumino-widget" | ||
ref="realEl"> | ||
<slot></slot> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Message } from '@lumino/messaging' | ||
import { BoxPanel, DockPanel, Widget } from '@lumino/widgets' | ||
import { inject, nextTick, onMounted, ref, watch } from 'vue' | ||
import { ItemWidget, Item } from './ItemWidget' | ||
const props = defineProps(['item', 'closable']) | ||
const emits = defineEmits(['close', 'active']) | ||
const boxPanel: BoxPanel | undefined = inject('boxPanel') | ||
const dockPanel: DockPanel | undefined = inject('dockPanel') | ||
const realEl = ref() | ||
const onLuminoWidgetClose = (msg: Message) => { | ||
emits('close', { msg, item: props.item, widget: luminoWidget }) | ||
} | ||
const onLuminoWidgetActive = (msg: Message) => { | ||
emits('close', { msg, item: props.item, widget: luminoWidget }) | ||
} | ||
const luminoWidget = new ItemWidget(props.item, { | ||
closable: props.closable, | ||
onClose: onLuminoWidgetClose, | ||
onActive: onLuminoWidgetActive | ||
}) | ||
watch(() => props.item, (newItem: Item, oldItem: Item) => { | ||
luminoWidget.title.label = newItem.name | ||
}, { deep: true }) | ||
onMounted(() => { | ||
const widgets = dockPanel!.widgets() | ||
if (!Array.from(widgets).find((w: Widget) => { | ||
return w.id === props.item.id | ||
})) { | ||
dockPanel!.addWidget(luminoWidget) | ||
nextTick(() => { | ||
document.getElementById(props.item.id)?.appendChild(realEl.value) | ||
}) | ||
} | ||
}) | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.lumino-widget { | ||
display: flex; | ||
flex: 1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.