Skip to content

Commit

Permalink
fix: some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wen-haoming committed Dec 14, 2021
1 parent 57014ee commit 418eca3
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 65 deletions.
2 changes: 1 addition & 1 deletion examples/cra-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"visual-dev": "0.1.0",
"visual-dev": "0.3.0",
"web-vitals": "^1.0.1"
},
"scripts": {
Expand Down
10 changes: 3 additions & 7 deletions examples/umi-app/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ export default defineConfig({
},
routes: [{ path: '/', component: '@/pages/index' }],
fastRefresh: {},
// plugins:[require.resolve('./node_modules/visual-dev/dist/plugins/umi'),],

plugins:['visual-dev/plugins/umi'],

resolve:{
includes:['components']
},
plugins:[require.resolve('../../packages/visual-dev/src/plugins/umi/index.ts'),],
// visualDev:{}
// plugins:['visual-dev/plugins/umi'],
// chainWebpack(memo) {
// memo.plugin('web-devtools').use(WebpackDevtoolPlugin);
// },
Expand Down
2 changes: 1 addition & 1 deletion examples/umi-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react": "17.x",
"react-dom": "17.x",
"umi": "^3.5.17",
"visual-dev": "0.1.8"
"visual-dev": "0.3.1"
},
"devDependencies": {
"@types/react": "^17.0.0",
Expand Down
31 changes: 29 additions & 2 deletions packages/dev-ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
<script setup lang="ts">
import { onMounted, ref, shallowRef, defineAsyncComponent, h } from 'vue';
import { createPrefixContext, createDrawerContext } from './hooks';
import { createPrefixContext, createDrawerContext, useHotkeys } from './hooks';
import { getRequest } from './utils';
createDrawerContext();
const data = createDrawerContext();
const prefix = createPrefixContext('vd');
const AsyncApp = shallowRef<any>(h('span', {}));
// 初始化快捷键
useHotkeys({
toggle_drawer: {
keys: [
['command', 'shift', 'z'],
['ctrl', 'shift', 'z'],
],
callback() {
if (data.visibile) {
data.closeDrawer();
} else {
data.openDrawer();
}
},
},
toggle_aim: {
keys: [
['command', 'shift', 'x'],
['ctrl', 'shift', 'x'],
],
callback() {
data.setIsAimStatus(!data.isAimStatus);
},
},
});
onMounted(async () => {
const { mode } = await getRequest('getConfig');
Expand Down Expand Up @@ -36,6 +62,7 @@ onMounted(async () => {
transition: all 0.2s;
cursor: pointer;
color: var(--v-brand);
z-index: 999999999;
&:hover {
transform: rotateZ(90deg);
left: 5px;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/dev-ui/src/Layout/Nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const router = useRoute();
</div>
<nav class="h-nav">
<div
@click="router?.changeCurrentRoute(route)"
@click="router?.changeCurrentRoute(route as any)"
class="nav-item"
:class="router?.currentRoute.route === route.route && 'active'"
:key="route.route"
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-ui/src/Pages/Docs/SliderLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const handleClick = (menuValue: any) => {
v-for="(value, key, index) in data.sliderObjectOrContent"
:key="String(key) + String(index || 0)"
>
<li
<!-- <li
:class="{ 'l-li': true, active: value === docsData?.docsContent }"
v-if="key !== '__open'"
>
Expand All @@ -69,7 +69,7 @@ const handleClick = (menuValue: any) => {
:slider-object-or-content="value"
/>
</transition>
</li>
</li> -->
</template>
</ul>
</div>
Expand Down
13 changes: 2 additions & 11 deletions packages/dev-ui/src/components/AimMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { ref, watch, onMounted } from 'vue';
import { usePrefix, useAim } from '../hooks';
import SvgIcon from '../IconCompents/SvgIcon.vue';
import { OverLayer } from './OverLayer';
import {
getParentNode,
getElementDimensions,
getCompNameFromStringPath,
postRequest,
launchEditor,
} from '../utils';
import { getParentNode, getElementDimensions, launchEditor } from '../utils';
interface MapPathdata {
[key: string]: { path: string; componentName: string; frame: string };
Expand All @@ -19,16 +13,13 @@ const useAimData = useAim();
const prefix = usePrefix();
const OverLayerRef = ref<OverLayer>();
const domMap = ref(new Map<Element, string>());
const domMap = ref(new WeakMap<Element, string>());
let previosDom: Element | null = null;
onMounted(() => {
// 收集全局带有 data-v-p 属性的 Dom
const collectElement = () => {
const arr = document.querySelectorAll('[data-v-p]');
if (arr.length === 0) return;
domMap.value.clear();
document.querySelectorAll('[data-v-p]').forEach((ele) => {
const attr = ele.getAttribute('data-v-p');
if (attr) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-ui/src/hooks/useRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineAsyncComponent, reactive, provide, inject, shallowRef } from 'vue';
import { reactive, provide, inject } from 'vue';

export const useRouteNamespace = 'useRoute';

Expand All @@ -11,7 +11,7 @@ const rawData = {
routes: [
{
route: 'Docs',
component: shallowRef(defineAsyncComponent(() => import('../Pages/Docs/index.vue'))),
// component: shallowRef(defineAsyncComponent(() => import('../Pages/Docs/index.vue'))),
},
],
currentRoute: {
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-ui/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getParentNode = (ele: Element, cb: (ele: Element) => boolean) => {

while (!cb(ele) && ele.parentNode && ele !== document.body) {
// eslint-disable-next-line no-param-reassign
ele = ele.parentNode;
(ele as any) = ele.parentNode;
}
return ele;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/dev-ui/src/utils/launchEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export function launchEditor({
line?: number | string;
column?: number | string;
}): string {
return EDITORS[editor].replace(/{(.*?)}/g, (_$, $1) => {
return EDITORS[editor].replace(/{(.*?)}/g, (_$: any, $1: any): string => {
if ($1 === 'path') {
return srcPath;
}
if ($1 === 'line') {
return line;
return String(line);
}
return column;
return String(column);
});
}
20 changes: 14 additions & 6 deletions packages/dev-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": true,
"strict": true,
"target": "ES2018",
"module": "ESNext",
"noImplicitAny": false,
"declaration": true,
"moduleResolution": "Node",
"esModuleInterop": true,
"jsx": "preserve",
"sourceMap": true,
"lib": ["ES2018", "DOM"],
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"lib": ["esnext", "dom"],
"baseUrl": "./src",
"rootDir": ".",
"typeRoots": ["node_modules/@types"],
"paths": {
"@": ["./src/*"]
}
},
"exclude": ["node_modules", "**/__test?__", "**/dist"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
2 changes: 1 addition & 1 deletion packages/visual-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "visual-dev",
"version": "0.2.2",
"version": "0.3.9",
"description": "plugin to facilitate project maintenance, provide document rendering, and the ability to locate components to ide",
"main": "./plugins/index.js",
"types": "./plugins/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/visual-dev/src/server/MiddleWare/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getConfig = (props: ServerOptions): RequestHandler => {

if (props.resolve) {
// 窗口模式
mode = 'drawer';
mode = 'aim';
} else {
// 仅显示瞄准
mode = 'aim';
Expand Down
8 changes: 1 addition & 7 deletions packages/visual-dev/src/server/createServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import express, { json } from 'express';
import cors from 'cors';
import launchEditor from '@umijs/launch-editor';
import { SERVER_PORT } from '../index';
import { getMenu, injectFile, pathMapMid, getConfig } from './MiddleWare';

Expand All @@ -26,15 +25,10 @@ export const createServer = async (options: ServerOptions = {}) => {

app.get('/web-devtools/getMenu', getMenu({ includes: resolve.includes }));

app.post('/web-devtools/launchEditor', async (req, res) => {
await launchEditor(process.cwd() + req.body.filePath);
res.send({});
});

app.post('/web-devtools/injectFile', injectFile);

app.listen(port, () => {
// eslint-disable-next-line
console.log(`dev-plugin is listening ${port}`);
console.log(`visual-dev is listening on port : ${port}`);
});
};
28 changes: 11 additions & 17 deletions packages/visual-dev/src/umi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ class WriteAndCopy {
}

export default (api: IApi) => {
api.describe({
key: 'resolve',
config: {
schema(joi) {
return joi.object({
includes: joi.array().items(joi.string()),
});
},
default: {
includes: [],
},
},
enableBy: api.EnableBy.config,
});
// api.describe({
// key: 'visualDev',
// config: {
// schema(joi) {
// return joi.object();
// },
// onChange: api.ConfigChangeType.regenerateTmpFiles,
// },
// enableBy: api.EnableBy.config,
// });

api.modifyBabelOpts((babelOptions) => {
babelOptions.plugins.unshift([insertJSXElementPathPlugin]);
Expand All @@ -64,8 +60,6 @@ export default (api: IApi) => {
});

api.onStart(() => {
createServer({
resolve: api.config.resolve,
});
createServer();
});
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"exclude": ["node_modules"],
"compilerOptions": {
"typeRoots": ["node_modules/@types"],
"target": "ES2018",
Expand All @@ -10,5 +9,6 @@
"noUnusedLocals": true,
"skipLibCheck": true,
"esModuleInterop": true
}
},
"exclude": ["node_modules", "**/__test?__", "**/dist"]
}

0 comments on commit 418eca3

Please sign in to comment.