Skip to content

Commit 346ae64

Browse files
committed
feat: add tabOptions to fixed panel height
1 parent 7198463 commit 346ae64

11 files changed

+69
-42
lines changed

doc/plugin_event_list.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ Trigger while vConsole trying to create a new tab for a plugin. This event will
2626
After binding this event, vConsole will get HTML from your callback to render a tab. A new tab will definitely be added if you bind this event, no matter what tab's HTML you set. Do not bind this event if you don't want to add a new tab.
2727

2828
##### Callback Arguments:
29-
- (required) function(html): a callback function that receives the content HTML of the new tab. `html` can be a HTML `string` or an `HTMLElement` object (Or object which supports `appendTo()` method, like JQuery object).
29+
- (required) function(html, options): a callback function that receives the content HTML of the new tab. `html` can be a HTML `string` or an `HTMLElement` object (Or object which supports `appendTo()` method, like JQuery object), and an optional `object` for tab options.
30+
31+
A tab option is an object with properties:
32+
33+
Property | | | |
34+
------- | ------- | ------- | -------
35+
fixedHeight | boolean | optional | Whether the height of tab is fixed to 100%.
3036

3137
##### Example:
3238

doc/plugin_event_list_CN.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ myPlugin.on('init', function() {
3333
绑定此事件后,vConsole 会认为此插件需要创建新 tab,并会将 callback 中获取的 HTML 用于渲染 tab。因此,只要绑定了此事件,新 tab 肯定会被渲染到页面中,无论 callback 传入的 HTML 是否为空。如果不需要添加新 tab,请不要绑定此事件。
3434

3535
##### Callback 参数
36-
- (必填) function(html): 回调函数,接收一个 HTML 参数用于渲染 tab。`html` 可以为 HTML 字符串,或者 `HTMLElement` 对象(或支持 `appendTo()` 方法的对象,如 jQuery 对象)。
36+
- (必填) function(html, options): 回调函数,第一个参数接收一个 HTML 参数用于渲染 tab。`html` 可以为 HTML 字符串,或者 `HTMLElement` 对象(或支持 `appendTo()` 方法的对象,如 jQuery 对象)。第二个参数接收一个可选配置信息。
37+
38+
配置的参数为:
39+
40+
Property | | | |
41+
------- | ------- | ------- | -------
42+
fixedHeight | boolean | 选填 | tab 高度固定为 100%。
3743

3844
##### 例子:
3945

src/component/recycleScroller/recycleItem.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
bind:this={item}
2929
class="vc-scroller-item"
3030
style:display={show ? "block" : "none"}
31-
style:transform="translateY({top}px) translateZ(0)"
31+
style:top="{top}px"
3232
>
3333
<slot />
3434
</div>

src/component/recycleScroller/recycleScroller.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
position: absolute;
1919
left: 0;
2020
right: 0;
21-
will-change: transform;
2221
}
2322

2423
.vc-scroller-footer {
@@ -35,6 +34,7 @@
3534
}
3635

3736
.vc-scroller-scrollbar-thumb {
37+
position: relative;
3838
width: 100%;
3939
height: 100%;
4040
background: rgba(0,0,0,.5);

src/component/recycleScroller/recycleScroller.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@
234234
235235
const refreshScrollbar = () => {
236236
const pos = scrollHandler.getPosition();
237-
const fac = viewportHeight / (frameHeight + footerHeight);
237+
const fac = 100 / (frameHeight + footerHeight);
238238
scrollbarThumbPos = pos * fac;
239-
scrollbarThumbHeight = 100 * fac;
239+
scrollbarThumbHeight = viewportHeight * fac;
240240
};
241241
242242
const scrollToBottom = (force?: boolean) => {
@@ -515,7 +515,7 @@
515515
<div
516516
class="vc-scroller-scrollbar-thumb"
517517
style:height="{scrollbarThumbHeight}%"
518-
style:transform="translateY({scrollbarThumbPos}px) translateZ(0)"
518+
style:top="{scrollbarThumbPos}%"
519519
/>
520520
</div>
521521
{/if}

src/core/core.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { default as SwitchButton } from './switchButton.svelte';
55
import { contentStore } from './core.model';
66
import Style from './core.less';
7-
import type { IVConsoleTopbarOptions, IVConsoleToolbarOptions } from '../lib/plugin';
7+
import type { IVConsoleTopbarOptions, IVConsoleToolbarOptions, IVConsoleTabOptions } from '../lib/plugin';
88
99
/*************************************
1010
* Public properties
@@ -14,6 +14,7 @@
1414
id: string;
1515
name: string;
1616
hasTabPanel: boolean;
17+
tabOptions?: IVConsoleTabOptions;
1718
topbarList?: IVConsoleTopbarOptions[];
1819
toolbarList?: IVConsoleToolbarOptions[];
1920
}
@@ -345,6 +346,7 @@
345346
<div
346347
id="__vc_plug_{plugin.id}"
347348
class="vc-plugin-box"
349+
class:vc-fixed-height="{plugin.tabOptions?.fixedHeight}"
348350
class:vc-actived="{plugin.id === activedPluginId}"
349351
></div>
350352
{/each}

src/core/core.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,24 @@ export class VConsole {
290290
id: plugin.id,
291291
name: plugin.name,
292292
hasTabPanel: false,
293+
tabOptions: undefined,
293294
topbarList: [],
294295
toolbarList: [],
295296
};
296297
this.compInstance.pluginList = this._reorderPluginList(this.compInstance.pluginList);
297298
// start init
298299
plugin.trigger('init');
299300
// render tab (if it is a tab plugin then it should has tab-related events)
300-
plugin.trigger('renderTab', (tabboxHTML) => {
301+
plugin.trigger('renderTab', (tabboxHTML, options = {}) => {
301302
// render tabbar
302-
this.compInstance.pluginList[plugin.id].hasTabPanel = true;
303+
const pluginInfo = this.compInstance.pluginList[plugin.id]
304+
pluginInfo.hasTabPanel = true;
305+
pluginInfo.tabOptions = options;
303306
// render tabbox
304307
if (!!tabboxHTML) {
305308
// when built-in plugins are initializing in the same time,
306309
// plugin's `.vc-plugin-box` element will be re-order by `pluginOrder` option,
307-
// so the innerHTML should be inserted with a delay
310+
// so the innerHTML should be inserted with a delay
308311
// to make sure getting the right `.vc-plugin-box`. (issue #559)
309312
setTimeout(() => {
310313
const divContentInner = document.querySelector('#__vc_plug_' + plugin.id);

src/core/style/view.less

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@
5757
// content
5858
.vc-content {
5959
background-color: var(--VC-BG-2);
60-
overflow: hidden;
61-
// overflow-x: hidden;
62-
// overflow-y: auto;
60+
overflow-x: hidden;
61+
overflow-y: auto;
6362
position: absolute;
6463
top: (40em / @font);
6564
left: 0;
@@ -75,6 +74,8 @@
7574
.vc-plugin-box {
7675
display: none;
7776
position: relative;
77+
}
78+
.vc-plugin-box.vc-fixed-height {
7879
height: 100%;
7980
}
8081
.vc-plugin-box.vc-actived {

src/lib/plugin.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export interface IVConsoleToolbarOptions {
3030
onClick?: (e: Event, data?: any) => any;
3131
}
3232

33+
export interface IVConsoleTabOptions {
34+
fixedHeight?: boolean
35+
}
36+
3337
/**
3438
* vConsole Plugin Base Class
3539
*/
@@ -40,7 +44,7 @@ export class VConsolePlugin {
4044
protected _id: string;
4145
protected _name: string;
4246
protected _vConsole: VConsole;
43-
47+
4448
constructor(...args);
4549
constructor(id: string, name = 'newPlugin') {
4650
this.id = id;

src/lib/sveltePlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export class VConsoleSveltePlugin<T extends {} = {}> extends VConsolePlugin {
2323

2424
onRenderTab(callback) {
2525
const $container = document.createElement('div');
26-
this.compInstance = new this.CompClass({
26+
const compInstance = this.compInstance = new this.CompClass({
2727
target: $container,
2828
props: this.initialProps,
2929
});
3030
// console.log('onRenderTab', this.compInstance);
31-
callback($container.firstElementChild);
31+
callback($container.firstElementChild, compInstance.options);
3232
}
3333

3434
onRemove() {

src/log/log.svelte

+30-25
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<script lang="ts">
2-
import { onMount, onDestroy } from 'svelte';
3-
import { isMatchedFilterText } from './logTool';
4-
import { VConsoleLogStore as Store } from './log.store';
5-
import LogRow from './logRow.svelte';
6-
import LogCommand from './logCommand.svelte';
7-
import Style from './log.less';
8-
import type { IConsoleLogMethod, IVConsoleLog } from './log.model';
9-
import RecycleScroller from '../component/recycleScroller/recycleScroller.svelte';
2+
import { onMount, onDestroy } from "svelte";
3+
import { isMatchedFilterText } from "./logTool";
4+
import { VConsoleLogStore as Store } from "./log.store";
5+
import LogRow from "./logRow.svelte";
6+
import LogCommand from "./logCommand.svelte";
7+
import Style from "./log.less";
8+
import type { IConsoleLogMethod, IVConsoleLog } from "./log.model";
9+
import RecycleScroller from "../component/recycleScroller/recycleScroller.svelte";
10+
import type { IVConsoleTabOptions } from "../lib/plugin";
1011
11-
export let pluginId: string = 'default';
12+
export let pluginId: string = "default";
1213
export let showCmd: boolean = false;
13-
export let filterType: 'all' | IConsoleLogMethod = 'all';
14+
export let filterType: "all" | IConsoleLogMethod = "all";
1415
export let showTimestamps: boolean = false;
1516
1617
let isInited: boolean = false;
17-
let filterText: string = '';
18+
let filterText: string = "";
1819
let store: ReturnType<typeof Store.get>;
19-
let scrollerHandler
20+
let scrollerHandler;
2021
2122
$: {
2223
if (!isInited) {
@@ -26,16 +27,16 @@
2627
}
2728
}
2829
29-
let logList: IVConsoleLog[] = []
30+
let logList: IVConsoleLog[] = [];
3031
3132
$: {
32-
logList = $store.logList.filter(log =>
33-
// filterType
34-
(filterType === 'all' || filterType === log.type)
35-
&&
36-
// filterText
37-
(filterText === '' || isMatchedFilterText(log, filterText))
38-
)
33+
logList = $store.logList.filter(
34+
(log) =>
35+
// filterType
36+
(filterType === "all" || filterType === log.type) &&
37+
// filterText
38+
(filterText === "" || isMatchedFilterText(log, filterText))
39+
);
3940
}
4041
4142
onMount(() => {
@@ -47,16 +48,20 @@
4748
});
4849
4950
const onFilterText = (e) => {
50-
filterText = e.detail.filterText || '';
51+
filterText = e.detail.filterText || "";
5152
};
5253
5354
export const scrollToTop = () => {
54-
scrollerHandler.scrollTo(0, 500)
55-
}
55+
scrollerHandler.scrollTo(0, 500);
56+
};
5657
5758
export const scrollToBottom = () => {
58-
scrollerHandler.scrollTo(logList.length - 1, 500)
59-
}
59+
scrollerHandler.scrollTo(logList.length - 1, 500);
60+
};
61+
62+
export const options: IVConsoleTabOptions = {
63+
fixedHeight: true,
64+
};
6065
</script>
6166

6267
<div class="vc-plugin-content" class:vc-logs-has-cmd={showCmd}>

0 commit comments

Comments
 (0)