leafer-x-tooltip-canvas 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -0
- package/README.md +6 -0
- package/dev/bundle.js +49 -5
- package/dist/index.cjs +48 -4
- package/dist/index.esm.js +48 -4
- package/dist/index.esm.min.js +1 -1
- package/dist/index.js +48 -4
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/src/Tooltip.ts +32 -0
- package/src/TooltipPlugin.ts +29 -4
- package/src/defaultConfig.ts +1 -0
- package/src/interface/config.ts +1 -0
- package/types/index.d.ts +2 -0
package/package.json
CHANGED
package/src/Tooltip.ts
CHANGED
|
@@ -70,6 +70,16 @@ export class Tooltip extends Pen implements ITooltip {
|
|
|
70
70
|
this.show()
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @description Debug 日志输出
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private log(...args: unknown[]) {
|
|
78
|
+
if (this.config?.debug) {
|
|
79
|
+
console.log('[Tooltip]', ...args)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
/**
|
|
74
84
|
* @description tooltip
|
|
75
85
|
* @param pos 位置信息
|
|
@@ -88,6 +98,25 @@ export class Tooltip extends Pen implements ITooltip {
|
|
|
88
98
|
fontFamily,
|
|
89
99
|
} = this.config.style
|
|
90
100
|
let offset = this.config.offset
|
|
101
|
+
|
|
102
|
+
this.log('createShapes', {
|
|
103
|
+
target: {
|
|
104
|
+
tag: this.target?.tag,
|
|
105
|
+
id: this.target?.id,
|
|
106
|
+
className: this.target?.className,
|
|
107
|
+
parent: {
|
|
108
|
+
tag: this.target?.parent?.tag,
|
|
109
|
+
id: this.target?.parent?.id,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
pointer: pos,
|
|
113
|
+
offset,
|
|
114
|
+
renderPos: { x: pos.x + offset[0], y: pos.y + offset[1] },
|
|
115
|
+
size: { width, height },
|
|
116
|
+
style: { backgroundColor, stroke, color, padding, borderRadius, fontSize },
|
|
117
|
+
text,
|
|
118
|
+
})
|
|
119
|
+
|
|
91
120
|
this.setStyle({
|
|
92
121
|
fill: backgroundColor,
|
|
93
122
|
stroke,
|
|
@@ -129,6 +158,7 @@ export class Tooltip extends Pen implements ITooltip {
|
|
|
129
158
|
|
|
130
159
|
public show(pos = this.__.pointerPos) {
|
|
131
160
|
this.clearShowHideTimers()
|
|
161
|
+
this.log('show', { pos, delay: this.config.showDelay, isShow: this.isShow })
|
|
132
162
|
this.showTimerId = setTimeout(() => {
|
|
133
163
|
this.createShapes(pos)
|
|
134
164
|
this.showTimerId = null // 定时器执行完毕,清空引用
|
|
@@ -137,6 +167,7 @@ export class Tooltip extends Pen implements ITooltip {
|
|
|
137
167
|
|
|
138
168
|
public hide(immediate = false) {
|
|
139
169
|
this.clearShowHideTimers()
|
|
170
|
+
this.log('hide', { immediate, delay: this.config.hideDelay, isShow: this.isShow })
|
|
140
171
|
if (immediate) {
|
|
141
172
|
this.destroy()
|
|
142
173
|
} else {
|
|
@@ -150,6 +181,7 @@ export class Tooltip extends Pen implements ITooltip {
|
|
|
150
181
|
|
|
151
182
|
public update(pos: IPos) {
|
|
152
183
|
this.clearShowHideTimers()
|
|
184
|
+
this.log('update', { pos, isShow: this.isShow })
|
|
153
185
|
if (this.isShow) {
|
|
154
186
|
// 已显示,立即更新位置
|
|
155
187
|
this.createShapes(pos)
|
package/src/TooltipPlugin.ts
CHANGED
|
@@ -39,6 +39,16 @@ export class TooltipPlugin {
|
|
|
39
39
|
private excludesTypeSet: Set<string> = new Set()
|
|
40
40
|
private ignoreTypeSet: Set<string> = new Set()
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @description Debug 日志输出
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private log(...args: unknown[]) {
|
|
47
|
+
if (this.config.debug) {
|
|
48
|
+
console.log('[TooltipPlugin]', ...args)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
constructor(instance: ILeafer | App, config?: IUserConfig) {
|
|
43
53
|
this.instance = instance
|
|
44
54
|
this.config = this.mergeConfig(defaultConfig, config)
|
|
@@ -142,12 +152,14 @@ export class TooltipPlugin {
|
|
|
142
152
|
)
|
|
143
153
|
|
|
144
154
|
const target = this.filterTarget(result.throughPath.list)
|
|
155
|
+
|
|
145
156
|
if (!target) {
|
|
146
157
|
this.hideTooltip()
|
|
147
158
|
return
|
|
148
159
|
}
|
|
149
160
|
|
|
150
|
-
|
|
161
|
+
const allowed = this.handleAllowed(target)
|
|
162
|
+
if (!allowed) {
|
|
151
163
|
this.hideTooltip()
|
|
152
164
|
return
|
|
153
165
|
}
|
|
@@ -188,6 +200,7 @@ export class TooltipPlugin {
|
|
|
188
200
|
|
|
189
201
|
// 如果没有配置任何过滤规则,默认允许
|
|
190
202
|
if (!hasIncludesRule && !hasExcludesRule) {
|
|
203
|
+
this.log('allowed', { target: target.tag, result: true, reason: 'no rules' })
|
|
191
204
|
return true
|
|
192
205
|
}
|
|
193
206
|
|
|
@@ -195,11 +208,21 @@ export class TooltipPlugin {
|
|
|
195
208
|
const matchesExclude = targetIdentifiers.some((id) => this.excludesTypeSet.has(id))
|
|
196
209
|
|
|
197
210
|
// includes 优先级高于 excludes
|
|
198
|
-
if (matchesInclude)
|
|
199
|
-
|
|
211
|
+
if (matchesInclude) {
|
|
212
|
+
this.log('allowed', { target: target.tag, result: true, reason: 'matches include' })
|
|
213
|
+
return true // 匹配白名单,直接允许(即使也在黑名单中)
|
|
214
|
+
}
|
|
215
|
+
if (matchesExclude) {
|
|
216
|
+
this.log('allowed', { target: target.tag, result: false, reason: 'matches exclude' })
|
|
217
|
+
return false // 不在白名单但在黑名单,拒绝
|
|
218
|
+
}
|
|
200
219
|
|
|
201
220
|
// 两者都不匹配的情况
|
|
202
|
-
if (hasIncludesRule)
|
|
221
|
+
if (hasIncludesRule) {
|
|
222
|
+
this.log('allowed', { target: target.tag, result: false, reason: 'has include rule but not matched' })
|
|
223
|
+
return false // 有白名单规则但不匹配 → 拒绝
|
|
224
|
+
}
|
|
225
|
+
this.log('allowed', { target: target.tag, result: true, reason: 'only exclude rule, not matched' })
|
|
203
226
|
return true // 只有黑名单规则且不匹配 → 允许
|
|
204
227
|
}
|
|
205
228
|
|
|
@@ -241,6 +264,7 @@ export class TooltipPlugin {
|
|
|
241
264
|
const cachedTooltip = this.tooltipCache.get(id)
|
|
242
265
|
if (cachedTooltip && cachedTooltip.parent) {
|
|
243
266
|
// 实例有效,直接更新
|
|
267
|
+
this.log('tooltip update', { id, x: event.x, y: event.y })
|
|
244
268
|
cachedTooltip.update({ x: event.x, y: event.y })
|
|
245
269
|
} else {
|
|
246
270
|
// 实例已被销毁或不存在,移除无效缓存并创建新实例
|
|
@@ -248,6 +272,7 @@ export class TooltipPlugin {
|
|
|
248
272
|
this.tooltipCache.delete(id)
|
|
249
273
|
}
|
|
250
274
|
|
|
275
|
+
this.log('tooltip create', { id, x: event.x, y: event.y, target: target.tag })
|
|
251
276
|
const tooltip = new Tooltip({
|
|
252
277
|
id,
|
|
253
278
|
pointerPos: { x: event.x, y: event.y },
|
package/src/defaultConfig.ts
CHANGED
package/src/interface/config.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { App } from '@leafer-ui/core';
|
|
|
2
2
|
import { IFontWeight, ILeafer } from '@leafer-ui/interface';
|
|
3
3
|
|
|
4
4
|
interface IUserConfig {
|
|
5
|
+
debug?: boolean;
|
|
5
6
|
reference?: 'pointer' | 'element';
|
|
6
7
|
showDelay?: number;
|
|
7
8
|
arrow?: boolean;
|
|
@@ -39,6 +40,7 @@ declare class TooltipPlugin {
|
|
|
39
40
|
private includesTypeSet;
|
|
40
41
|
private excludesTypeSet;
|
|
41
42
|
private ignoreTypeSet;
|
|
43
|
+
private log;
|
|
42
44
|
constructor(instance: ILeafer | App, config?: IUserConfig);
|
|
43
45
|
private mergeConfig;
|
|
44
46
|
private isAppInstance;
|