Skip to content

Commit 9d8dba6

Browse files
author
马军
committed
fix: input过滤 #57
1 parent 7ce0b1c commit 9d8dba6

File tree

7 files changed

+135
-14
lines changed

7 files changed

+135
-14
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,9 @@
132132
"source.fixAll.eslint": "never",
133133
"source.fixAll.stylelint": "explicit"
134134
}
135-
}
135+
},
136+
"i18n-ally.localesPaths": [
137+
"packages/common/i18n",
138+
"packages/common/i18n/src/locales"
139+
]
136140
}

packages/common/i18n/src/locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"comprehensive": "comprehensive",
55
"comprehensive2": "comprehensive2",
66
"customizeButtons": "customizeButtons",
7-
"Selecto": "Selecto test"
7+
"selecto": "Selecto test",
8+
"input": "input test"
89
},
910
"common": {
1011
"code": "Code",

packages/common/i18n/src/locales/zh.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"comprehensive2": "综合(另外写法)",
66
"customizeButtons": "自定义按键",
77
"moveble": "moveble插件结合",
8-
"Selecto": "Selecto测试"
8+
"selecto": "Selecto测试",
9+
"input": "input测试"
910
},
1011
"common": {
1112
"code": "代码",

packages/docs/src/examples/input.vue

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<template>
2+
<div>
3+
<div class="wrapper whitewrapper" :style="rectStyle">
4+
<sketch-rule ref="sketchruleRef" v-bind="post">
5+
<template #default>
6+
<div data-type="page" :style="canvasStyle">
7+
<el-input v-model="inputValue" type="text" />
8+
</div>
9+
</template>
10+
<template #btn="{ reset, zoomIn, zoomOut }">
11+
<div class="btns">
12+
<button @click.stop="reset">还原</button>
13+
<button @click.stop="zoomIn">放大</button>
14+
<button @click.stop="zoomOut">缩小</button>
15+
</div>
16+
</template>
17+
</sketch-rule>
18+
</div>
19+
</div>
20+
</template>
21+
<script setup lang="ts">
22+
import bgImg from '../assets/bg.png'
23+
import { computed, ref, reactive } from 'vue'
24+
import SketchRule from 'vue3-sketch-ruler'
25+
import 'vue3-sketch-ruler/lib/style.css'
26+
const sketchruleRef = ref()
27+
const post = reactive({
28+
thick: 20,
29+
width: 1470,
30+
height: 700,
31+
showShadowText: false,
32+
canvasWidth: 1000,
33+
canvasHeight: 500,
34+
showRuler: true,
35+
palette: { bgColor: 'transparent', lineType: 'dashed' },
36+
isShowReferLine: true,
37+
shadow: {
38+
x: 0,
39+
y: 0,
40+
width: 300,
41+
height: 300
42+
},
43+
lines: {
44+
h: [0, 250],
45+
v: [0, 500]
46+
}
47+
})
48+
49+
const rectStyle = computed(() => {
50+
return {
51+
width: `${post.width}px`,
52+
height: `${post.height}px`
53+
}
54+
})
55+
56+
const inputValue = ref('')
57+
58+
const canvasStyle = computed(() => {
59+
return {
60+
width: `${post.canvasWidth}px`,
61+
height: `${post.canvasHeight}px`
62+
}
63+
})
64+
</script>
65+
66+
<style lang="scss">
67+
.wrapper {
68+
margin: 0 auto;
69+
background-size:
70+
21px 21px,
71+
21px 21px;
72+
border: 1px solid #dadadc;
73+
}
74+
.whitewrapper {
75+
background-color: #fafafc;
76+
background-image: linear-gradient(#fafafc 20px, transparent 0),
77+
linear-gradient(90deg, transparent 20px, #373739 0);
78+
}
79+
.img-style {
80+
width: 100%;
81+
height: 100%;
82+
}
83+
.btns {
84+
position: absolute;
85+
display: flex;
86+
bottom: 20px;
87+
right: 40px;
88+
z-index: 999;
89+
}
90+
91+
</style>

packages/docs/src/router/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export const menuRoutes: RouteRecordRaw[] = [
4040
path: 'selecto',
4141
component: () => import('../examples/SelectoDemo.vue'),
4242
meta: {
43-
title: 'Selecto'
43+
title: 'selecto'
4444
}
45-
}
45+
},
4646

47-
// {
48-
// path: 'temp',
49-
// component: () => import('@/examples/temp.vue'),
50-
// meta: {
51-
// title: 'temp'
52-
// }
53-
// }
47+
{
48+
path: 'input',
49+
component: () => import('@/examples/input.vue'),
50+
meta: {
51+
title: 'input'
52+
}
53+
}
5454
]
5555

5656
const routes: RouteRecordRaw[] = [

packages/sketch-ruler/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"url": "https://gitee.com/majun2232/vue3-sketch-Ruler"
1919
},
2020
"sideEffects": false,
21-
"main_": "lib/index.js",
22-
"main": "src/index.ts",
21+
"main": "lib/index.js",
22+
"main1": "src/index.ts",
2323
"style": "lib/style.css",
2424
"types": "lib/index.d.ts",
2525
"scripts": {

packages/sketch-ruler/src/sketch-ruler/index.vue

+24
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ const handleWheel = (e: WheelEvent) => {
169169
}
170170
}
171171
const handleSpaceKeyDown = (e: KeyboardEvent) => {
172+
// 检查当前焦点元素
173+
const activeElement = document.activeElement
174+
// fix: #57 如果焦点在monaco-editor、input、textarea或其他可编辑元素中,则不处理空格事件
175+
if (
176+
activeElement?.closest('.monaco-editor') ||
177+
activeElement?.tagName === 'INPUT' ||
178+
activeElement?.tagName === 'TEXTAREA' ||
179+
activeElement?.getAttribute('contenteditable') === 'true'
180+
) {
181+
return
182+
}
183+
172184
if (e.key === ' ') {
173185
cursorClass.value = 'grabCursor'
174186
panzoomInstance.value?.bind()
@@ -177,6 +189,18 @@ const handleSpaceKeyDown = (e: KeyboardEvent) => {
177189
}
178190
179191
const handleSpaceKeyUp = (e: KeyboardEvent) => {
192+
// 检查当前焦点元素
193+
const activeElement = document.activeElement
194+
// 如果焦点在monaco-editor、input、textarea或其他可编辑元素中,则不处理空格事件
195+
if (
196+
activeElement?.closest('.monaco-editor') ||
197+
activeElement?.tagName === 'INPUT' ||
198+
activeElement?.tagName === 'TEXTAREA' ||
199+
activeElement?.getAttribute('contenteditable') === 'true'
200+
) {
201+
return
202+
}
203+
180204
if (e.key === ' ') {
181205
panzoomInstance.value?.destroy()
182206
cursorClass.value = 'defaultCursor'

0 commit comments

Comments
 (0)