Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Maiz committed Jun 30, 2019
2 parents d1553b7 + 4840a8f commit 1b26c6a
Showing 14 changed files with 458 additions and 60 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
English | [简体中文](./CHANGELOG_CN.md)

#### V3.3.1 (2019-06-30)

- [FEATURE] Add TypeScript definition file. (by by @jas0ncn)
- [FIX] Fix switch button position issue. (by @rexschuang)
- [FIX] Avoid scrolling to bottom when away from bottom edge. (by @ele828)
- [FIX] Fix a few minor issues. (by @stenders)


#### V3.3.0 (2019-02-02)

- [FEATURE] Add the ability to collapse the same log.
10 changes: 9 additions & 1 deletion CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
[English](./CHANGELOG.md) | 简体中文

#### V3.3.1 (2019-06-30)

- 【特性】增加 TypeScript 声明文件。(by @jas0ncn
- 【修复】修复开关按钮拖动后位置不对的问题。(by @rexschuang
- 【修复】不在列表底部时避免自动滚动。(by @ele828
- 【修复】修复若干小问题。(by @stenders


#### V3.3.0 (2019-02-02)

-特效】新增自动合并相同日志的能力。频繁输出相同日志时不再会被刷屏。
-特性】新增自动合并相同日志的能力。频繁输出相同日志时不再会被刷屏。
- 【修复】修复格式化日志(如 `console.log('[foo]', 'bar')`)无法显示到 Log 面板的问题。


115 changes: 115 additions & 0 deletions dist/vconsole.min.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* VConsole type definitions
* @see https://github.com/Tencent/vConsole
*/

declare module 'vconsole' {
// VConsole configs
export interface VConsoleConfig {
defaultPlugins?: string[]
onReady?: () => void
onClearLog?: () => void
maxLogNumber?: number
disableLogScrolling?: boolean
}

/**
* VConsole
* @see https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md
*/
export class VConsoleInstance {
constructor (config?: VConsoleConfig)

// properties
readonly version: string
option: VConsoleConfig
readonly activedTab: string
readonly tabList: string[]
readonly $dom: HTMLDivElement

// methods
setOption (config: VConsoleConfig): void;
setOption <TKey extends keyof VConsoleConfig>(key: TKey, value: VConsoleConfig[TKey]): void
destroy (): void
addPlugin (plugin: VConsolePluginInstance): boolean
removePlugin (pluginId: string): boolean
showTab (pluginId: string): void
show (): void
hide (): void
showSwitch (): void
hideSwitch (): void
}

/**
* VConsole Plugin Event List
* @see https://github.com/Tencent/vConsole/blob/dev/doc/plugin_event_list.md
*/
export interface VConsolePluginEventMap {
init (): void

renderTab (
callback: <AnyElement extends { appendTo: () => void }>(html: string | HTMLElement | AnyElement) => void
): void

addTopBar (
callback: (
btnList: {
name: string
data?: { [key: string]: string | number }
className?: string
onClick (e: MouseEvent | TouchEvent): void | boolean
}[]
) => void
): void

addTool (
callback: (
toolList: {
name: string
global?: boolean
onClick (e: MouseEvent | TouchEvent): void | boolean
}[]
) => void
): void

ready (): void

remove (): void

show (): void

hide (): void

showConsole (): void

hideConsole (): void

updateOption (): void
}

/**
* VConsole Plugin
* @see https://github.com/Tencent/vConsole/blob/dev/doc/plugin_getting_started.md
*/
export class VConsolePluginInstance {
constructor (id: string, name?: string)

// properties
id: string
name: string
vConsole: VConsoleInstance

// methods
on<EventName extends keyof VConsolePluginEventMap> (
eventName: EventName,
callback: VConsolePluginEventMap[EventName]
): VConsolePluginInstance
trigger<T = any> (eventName: keyof VConsolePluginEventMap, data: T): VConsolePluginInstance
}

export class VConsole extends VConsoleInstance {
static VConsolePlugin: VConsolePluginInstance
}

export default VConsole
}
4 changes: 2 additions & 2 deletions dist/vconsole.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/plugin_event_list.md
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ myPlugin.on('show', function() {
```


## Hide
## hide

Trigger when a tab is hidden. Only the plugin binded with `renderTab` will receive this event.

2 changes: 1 addition & 1 deletion doc/plugin_event_list_CN.md
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ myPlugin.on('show', function() {
```


## Hide
## hide

当插件的 tab 被隐藏时触发。只有绑定了 `renderTab` 事件的插件才会收到此事件。

167 changes: 166 additions & 1 deletion package-lock.json
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "vconsole",
"version": "3.3.0",
"version": "3.3.1",
"description": "A lightweight, extendable front-end developer tool for mobile web page.",
"homepage": "https://github.com/Tencent/vConsole",
"main": "dist/vconsole.min.js",
"typings": "./index.d.ts",
"scripts": {
"test": "mocha",
"dist": "webpack"
@@ -27,6 +28,7 @@
"babel-loader": "^8.0.4",
"babel-plugin-add-module-exports": "^1.0.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^5.0.3",
"css-loader": "^2.1.0",
"html-loader": "^0.5.5",
"jsdom": "^13.2.0",
7 changes: 4 additions & 3 deletions src/core/core.js
Original file line number Diff line number Diff line change
@@ -273,8 +273,6 @@ class VConsole {
that.switchPos.y = that.switchPos.endY;
that.switchPos.startX = 0;
that.switchPos.startY = 0;
that.switchPos.endX = 0;
that.switchPos.endY = 0;
tool.setStorage('switch_x', that.switchPos.x);
tool.setStorage('switch_y', that.switchPos.y);
});
@@ -731,8 +729,11 @@ class VConsole {
}
// remove DOM
this.$dom.parentNode.removeChild(this.$dom);

// reverse isInited when destroyed
this.isInited = false;
}

} // END class

export default VConsole;
export default VConsole;
61 changes: 19 additions & 42 deletions src/lib/query.js
Original file line number Diff line number Diff line change
@@ -23,32 +23,20 @@ const $ = {};
* @public
*/
$.one = function(selector, contextElement) {
if (contextElement) {
return contextElement.querySelector(selector);
}
return document.querySelector(selector);
return (contextElement || document).querySelector(selector)
}

/**
* get multiple elements
* @public
*/
$.all = function(selector, contextElement) {
let nodeList,
list = [];
if (contextElement) {
nodeList = contextElement.querySelectorAll(selector);
} else {
nodeList = document.querySelectorAll(selector);
}
if (nodeList && nodeList.length > 0) {
list = Array.prototype.slice.call(nodeList);
}
return list;
const nodeList = (contextElement || document).querySelectorAll(selector)
return Array.from(nodeList)
}

/**
* add className to an element
* add className(s) to an or multiple element(s)
* @public
*/
$.addClass = function($el, className) {
@@ -59,18 +47,18 @@ $.addClass = function($el, className) {
$el = [$el];
}
for (let i=0; i<$el.length; i++) {
let name = $el[i].className || '',
arr = name.split(' ');
if (arr.indexOf(className) > -1) {
continue;
if (isArray(className)) {
className.forEach(name => $el[0].classList.add(name));
} else if (className.split(' ')[1]) {
className.split(' ').forEach(name => $el[0].classList.add(name))
} else {
$el[0].classList.add(className);
}
arr.push(className);
$el[i].className = arr.join(' ');
}
}

/**
* remove className from an element
* remove className(s) from an or multiple element(s)
* @public
*/
$.removeClass = function($el, className) {
@@ -81,13 +69,13 @@ $.removeClass = function($el, className) {
$el = [$el];
}
for (let i=0; i<$el.length; i++) {
let arr = $el[i].className.split(' ');
for (let j=0; j<arr.length; j++) {
if (arr[j] == className) {
arr[j] = '';
}
if (isArray(className)) {
className.forEach(name => $el[0].classList.remove(name));
} else if (className.split(' ')[1]) {
className.split(' ').forEach(name => $el[0].classList.remove(name))
} else {
$el[0].classList.remove(className);
}
$el[i].className = arr.join(' ').trim();
}
}

@@ -99,13 +87,7 @@ $.hasClass = function($el, className) {
if (!$el) {
return false;
}
let arr = $el.className.split(' ');
for (let i=0; i<arr.length; i++) {
if (arr[i] == className) {
return true;
}
}
return false;
return $el.classList.contains(className)
}

/**
@@ -120,15 +102,10 @@ $.bind = function($el, eventType, fn, useCapture) {
if (!$el) {
return;
}
if (useCapture === undefined) {
useCapture = false;
}
if (!isArray($el)) {
$el = [$el];
}
for (let i=0; i<$el.length; i++) {
$el[i].addEventListener(eventType, fn, useCapture);
}
$el.forEach(el => el.addEventListener(eventType, fn, !!useCapture))
}

/**
6 changes: 3 additions & 3 deletions src/log/log.js
Original file line number Diff line number Diff line change
@@ -423,7 +423,7 @@ class VConsoleLogTab extends VConsolePlugin {


// scroll to bottom if it is in the bottom before
if (this.isInBottom) {
if (this.isInBottom && this.isShow) {
this.autoScrollToBottom();
}

@@ -434,7 +434,7 @@ class VConsoleLogTab extends VConsolePlugin {
}

/**
*
*
* @protected
*/
printRepeatLog() {
@@ -454,7 +454,7 @@ class VConsoleLogTab extends VConsolePlugin {
}

/**
*
*
* @protected
*/
printNewLog(item, logs) {
2 changes: 1 addition & 1 deletion src/network/network.js
Original file line number Diff line number Diff line change
@@ -369,7 +369,7 @@ class VConsoleNetworkTab extends VConsolePlugin {
query = query.split('&'); // => ['b=c', 'd=?e']
for (let q of query) {
q = q.split('=');
item.getData[ q[0] ] = q[1];
item.getData[ q[0] ] = decodeURIComponent(q[1]);
}
}

115 changes: 115 additions & 0 deletions src/vconsole.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* VConsole type definitions
* @see https://github.com/Tencent/vConsole
*/

declare module 'vconsole' {
// VConsole configs
export interface VConsoleConfig {
defaultPlugins?: string[]
onReady?: () => void
onClearLog?: () => void
maxLogNumber?: number
disableLogScrolling?: boolean
}

/**
* VConsole
* @see https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md
*/
export class VConsoleInstance {
constructor (config?: VConsoleConfig)

// properties
readonly version: string
option: VConsoleConfig
readonly activedTab: string
readonly tabList: string[]
readonly $dom: HTMLDivElement

// methods
setOption (config: VConsoleConfig): void;
setOption <TKey extends keyof VConsoleConfig>(key: TKey, value: VConsoleConfig[TKey]): void
destroy (): void
addPlugin (plugin: VConsolePluginInstance): boolean
removePlugin (pluginId: string): boolean
showTab (pluginId: string): void
show (): void
hide (): void
showSwitch (): void
hideSwitch (): void
}

/**
* VConsole Plugin Event List
* @see https://github.com/Tencent/vConsole/blob/dev/doc/plugin_event_list.md
*/
export interface VConsolePluginEventMap {
init (): void

renderTab (
callback: <AnyElement extends { appendTo: () => void }>(html: string | HTMLElement | AnyElement) => void
): void

addTopBar (
callback: (
btnList: {
name: string
data?: { [key: string]: string | number }
className?: string
onClick (e: MouseEvent | TouchEvent): void | boolean
}[]
) => void
): void

addTool (
callback: (
toolList: {
name: string
global?: boolean
onClick (e: MouseEvent | TouchEvent): void | boolean
}[]
) => void
): void

ready (): void

remove (): void

show (): void

hide (): void

showConsole (): void

hideConsole (): void

updateOption (): void
}

/**
* VConsole Plugin
* @see https://github.com/Tencent/vConsole/blob/dev/doc/plugin_getting_started.md
*/
export class VConsolePluginInstance {
constructor (id: string, name?: string)

// properties
id: string
name: string
vConsole: VConsoleInstance

// methods
on<EventName extends keyof VConsolePluginEventMap> (
eventName: EventName,
callback: VConsolePluginEventMap[EventName]
): VConsolePluginInstance
trigger<T = any> (eventName: keyof VConsolePluginEventMap, data: T): VConsolePluginInstance
}

export class VConsole extends VConsoleInstance {
static VConsolePlugin: VConsolePluginInstance
}

export default VConsole
}
15 changes: 11 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var pkg = require('./package.json');
var Webpack = require('webpack');
var Path = require('path');
const pkg = require('./package.json');
const Webpack = require('webpack');
const Path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
mode: 'production',
@@ -41,6 +42,12 @@ module.exports = {
'Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at',
'http://opensource.org/licenses/MIT',
'Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.'
].join('\n'))
].join('\n')),
new CopyWebpackPlugin([
{
from: Path.resolve(__dirname, './src/vconsole.d.ts'),
to: Path.resolve(__dirname, './dist/vconsole.min.d.ts')
}
])
]
};

0 comments on commit 1b26c6a

Please sign in to comment.