Skip to content

Commit

Permalink
[refactor] re-arrage files and folder
Browse files Browse the repository at this point in the history
  • Loading branch information
GarinZ committed Jan 13, 2023
1 parent dce0f2c commit bcac63c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tabs } from 'webextension-polyfill';

import { BrowserExtensionUtils, FancyTreeUtils, logLazy } from './utils';
import { BrowserExtensionUtils, FancyTreeUtils, logLazy } from '../utils';

interface DND5Data {
dataTransfer: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Tabs, Windows } from 'webextension-polyfill';
import browser from 'webextension-polyfill';

import TreeNodeTpl, { TPL_CONSTANTS } from '../templates/tree-node-tpl';
import TreeNodeTpl, { TPL_CONSTANTS } from '../../templates/tree-node-tpl';
import * as TabNodes from '../node-builders';
import { createWindowNode } from '../node-builders';
import type { NodeType, TreeData, TreeNode } from '../nodes';
import { NodeUtils } from '../utils';
import { DND5_CONFIG } from './configs';
import * as TabNodes from './node-builders';
import { createWindowNode } from './node-builders';
import type { NodeType, TreeData, TreeNode } from './nodes';
import { ViewTabIndexUtils } from './tab-index-utils';
import { NodeUtils } from './utils';

type Tab = Tabs.Tab;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
export const ViewTabIndexUtils = {
// 添加tab
// 1. 根据index找到元素
// 2. 选择适合的方式添加元素
// 3. 后面元素的index + 1

// 删除tab
// 1. 删除元素
// 2. 后面元素的index - 1

// 移动tab
// 1. 根据index找到元素
// 2. 和目标元素交换index

increaseIndex: (tree: Fancytree.Fancytree, windowId: number, index: number) => {
const parentNode = tree.getNodeByKey(`${windowId}`);
parentNode.visit((node) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { onMessage } from '@garinz/webext-bridge';

import { FancyTabMasterTree } from './fancy-tab-master-tree';
import { FancyTabMasterTree } from './fancy-tab-master-tree/fancy-tab-master-tree';

const tree = new FancyTabMasterTree('#tree');
tree.initTree();
Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"module": "ESNext",
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
"@/*": ["src/*"],
"?/*": ["test/*"]
},
"typeRoots": ["../node_modules/@types", "./typings"],
"types": ["jquery", "webext-bridge", "jquery.fancytree"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import type { Tabs } from 'webextension-polyfill';

import type { TabData } from '../../src/tree/nodes';
import { createTab, initFancytree } from '../utils/gen-utils';
import { toAsciiTree } from '../utils/print-utils';
import type { TabData } from '@/tree/nodes';

import { createTab, initFancytree } from '../../utils/gen-utils';
import { toAsciiTree } from '../../utils/print-utils';
import { SINGLE_TAB_WINDOW } from './mock-data';

type FancytreeNode = Fancytree.FancytreeNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TabData, TreeData, TreeNode, WindowData } from '../../src/tree/nodes';
import type { TabData, TreeData, TreeNode, WindowData } from '../../../src/tree/nodes';

export const SINGLE_TAB_WINDOW = [
{
Expand Down
4 changes: 2 additions & 2 deletions test/utils/gen-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import type { Tabs } from 'webextension-polyfill';

import { FancyTabMasterTree } from '../../src/tree/fancy-tab-master-tree';
import { FancyTabMasterTree } from '../../src/tree/fancy-tab-master-tree/fancy-tab-master-tree';
import type { TreeData, TreeNode } from '../../src/tree/nodes';

import 'jquery.fancytree';
import 'jquery.fancytree/dist/modules/jquery.fancytree.dnd5';
import 'jquery.fancytree/dist/modules/jquery.fancytree.childcounter';

export function initFancytree(source: TreeNode<TreeData>[]) {
export function initFancytree(source: TreeNode<TreeData>[]): FancyTabMasterTree {
document.body.innerHTML = '<div id="tree">';
const tree = new FancyTabMasterTree('#tree');
tree.initTree(source);
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"module": "ESNext",
"baseUrl": "./",
"types": ["jquery", "webext-bridge", "jquery.fancytree", "jest"],
"typeRoots": ["node_modules/@types", "src/typings"]
"typeRoots": ["node_modules/@types", "src/typings"],
"paths": {
"@/*": ["src/*"]
}
},
"exclude": ["manifest.ts"]
}

0 comments on commit bcac63c

Please sign in to comment.