@antv/component 2.1.11 → 2.1.12
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/dist/component.min.js +1 -1
- package/esm/ui/axis/guides/labels.js +0 -6
- package/esm/ui/axis/guides/labels.js.map +1 -1
- package/esm/ui/legend/category.js +2 -2
- package/esm/ui/legend/category.js.map +1 -1
- package/esm/ui/legend/types.d.ts +4 -1
- package/esm/ui/navigator/index.js +1 -0
- package/esm/ui/navigator/index.js.map +1 -1
- package/esm/ui/scrollbar/index.js.map +1 -1
- package/esm/ui/select/select.js.map +1 -1
- package/esm/ui/slider/index.js +0 -1
- package/esm/ui/slider/index.js.map +1 -1
- package/esm/ui/tooltip/index.js +11 -4
- package/esm/ui/tooltip/index.js.map +1 -1
- package/esm/util/parse-height-from-html.js +0 -1
- package/esm/util/parse-height-from-html.js.map +1 -1
- package/esm/util/string.d.ts +1 -0
- package/esm/util/string.js +10 -0
- package/esm/util/string.js.map +1 -1
- package/lib/ui/axis/guides/labels.js +0 -6
- package/lib/ui/axis/guides/labels.js.map +1 -1
- package/lib/ui/legend/category.js +2 -2
- package/lib/ui/legend/category.js.map +1 -1
- package/lib/ui/legend/types.d.ts +4 -1
- package/lib/ui/navigator/index.js +1 -0
- package/lib/ui/navigator/index.js.map +1 -1
- package/lib/ui/scrollbar/index.js.map +1 -1
- package/lib/ui/select/select.js.map +1 -1
- package/lib/ui/slider/index.js +0 -1
- package/lib/ui/slider/index.js.map +1 -1
- package/lib/ui/tooltip/index.js +10 -3
- package/lib/ui/tooltip/index.js.map +1 -1
- package/lib/util/parse-height-from-html.js +0 -1
- package/lib/util/parse-height-from-html.js.map +1 -1
- package/lib/util/string.d.ts +1 -0
- package/lib/util/string.js +11 -0
- package/lib/util/string.js.map +1 -1
- package/package.json +1 -1
- package/src/ui/axis/guides/labels.ts +0 -7
- package/src/ui/legend/category.ts +2 -2
- package/src/ui/legend/types.ts +5 -1
- package/src/ui/navigator/index.ts +1 -0
- package/src/ui/scrollbar/index.ts +6 -6
- package/src/ui/select/select.ts +1 -1
- package/src/ui/slider/index.ts +2 -3
- package/src/ui/tooltip/index.ts +12 -4
- package/src/util/parse-height-from-html.ts +0 -1
- package/src/util/string.ts +12 -0
|
@@ -148,8 +148,8 @@ export class Scrollbar extends Component<ScrollbarStyleProps> {
|
|
|
148
148
|
value: newValue,
|
|
149
149
|
},
|
|
150
150
|
};
|
|
151
|
-
this.dispatchEvent(new CustomEvent('scroll', evtVal));
|
|
152
|
-
this.dispatchEvent(new CustomEvent('valuechange', evtVal));
|
|
151
|
+
this.dispatchEvent(new CustomEvent('scroll', evtVal) as any);
|
|
152
|
+
this.dispatchEvent(new CustomEvent('valuechange', evtVal) as any);
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
public bindEvents() {
|
|
@@ -194,18 +194,18 @@ export class Scrollbar extends Component<ScrollbarStyleProps> {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
private onThumbMouseenter = (e: CustomEvent) => {
|
|
197
|
-
this.dispatchEvent(new CustomEvent('thumbMouseenter', { detail: e.detail }));
|
|
197
|
+
this.dispatchEvent(new CustomEvent('thumbMouseenter', { detail: e.detail }) as any);
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
private onTrackMouseenter = (e: CustomEvent) => {
|
|
201
|
-
this.dispatchEvent(new CustomEvent('trackMouseenter', { detail: e.detail }));
|
|
201
|
+
this.dispatchEvent(new CustomEvent('trackMouseenter', { detail: e.detail }) as any);
|
|
202
202
|
};
|
|
203
203
|
|
|
204
204
|
private onThumbMouseleave = (e: CustomEvent) => {
|
|
205
|
-
this.dispatchEvent(new CustomEvent('thumbMouseleave', { detail: e.detail }));
|
|
205
|
+
this.dispatchEvent(new CustomEvent('thumbMouseleave', { detail: e.detail }) as any);
|
|
206
206
|
};
|
|
207
207
|
|
|
208
208
|
private onTrackMouseleave = (e: CustomEvent) => {
|
|
209
|
-
this.dispatchEvent(new CustomEvent('trackMouseleave', { detail: e.detail }));
|
|
209
|
+
this.dispatchEvent(new CustomEvent('trackMouseleave', { detail: e.detail }) as any);
|
|
210
210
|
};
|
|
211
211
|
}
|
package/src/ui/select/select.ts
CHANGED
|
@@ -165,7 +165,7 @@ export class Select extends Component<SelectStyleProps> {
|
|
|
165
165
|
onClick: (value, option, item) => {
|
|
166
166
|
this.setValue(value);
|
|
167
167
|
onSelect?.(value, option, item);
|
|
168
|
-
this.dispatchEvent(new CustomEvent('change', { detail: { value, option, item } }));
|
|
168
|
+
this.dispatchEvent(new CustomEvent('change', { detail: { value, option, item } }) as any);
|
|
169
169
|
hide(this.dropdown);
|
|
170
170
|
},
|
|
171
171
|
},
|
package/src/ui/slider/index.ts
CHANGED
|
@@ -535,7 +535,7 @@ export class Slider extends Component<SliderStyleProps> {
|
|
|
535
535
|
private dispatchCustomEvent(target: Selection, event: string, name: string) {
|
|
536
536
|
target.on(event, (e: MouseEvent) => {
|
|
537
537
|
e.stopPropagation();
|
|
538
|
-
this.dispatchEvent(new CustomEvent(name, { detail: e }));
|
|
538
|
+
this.dispatchEvent(new CustomEvent(name, { detail: e }) as any);
|
|
539
539
|
});
|
|
540
540
|
}
|
|
541
541
|
|
|
@@ -613,7 +613,6 @@ export class Slider extends Component<SliderStyleProps> {
|
|
|
613
613
|
};
|
|
614
614
|
|
|
615
615
|
private onDragEnd = () => {
|
|
616
|
-
document.removeEventListener('pointermove', this.onDragging);
|
|
617
616
|
document.removeEventListener('pointermove', this.onDragging);
|
|
618
617
|
document.removeEventListener('pointerup', this.onDragEnd);
|
|
619
618
|
this.target = '';
|
|
@@ -628,7 +627,7 @@ export class Slider extends Component<SliderStyleProps> {
|
|
|
628
627
|
const evt = new CustomEvent('valuechange', {
|
|
629
628
|
detail: { oldValue: internalOldValue, value },
|
|
630
629
|
});
|
|
631
|
-
this.dispatchEvent(evt);
|
|
630
|
+
this.dispatchEvent(evt as any);
|
|
632
631
|
onChange?.(value);
|
|
633
632
|
};
|
|
634
633
|
}
|
package/src/ui/tooltip/index.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { substitute, createDOM } from '@antv/util';
|
|
2
2
|
import { Component } from '../../core';
|
|
3
3
|
import { Group } from '../../shapes';
|
|
4
|
-
import { BBox, applyStyleSheet, replaceChildren } from '../../util';
|
|
4
|
+
import { BBox, applyStyleSheet, escapeHtml, replaceChildren } from '../../util';
|
|
5
5
|
import { getClassNames, getDefaultTooltipStyle } from './constant';
|
|
6
6
|
import type { TooltipOptions, TooltipPosition, TooltipStyleProps } from './types';
|
|
7
7
|
|
|
8
8
|
export type { TooltipStyleProps, TooltipOptions };
|
|
9
9
|
|
|
10
|
+
function sanitizeDatum(datum: Record<string, any>) {
|
|
11
|
+
const sanitized: Record<string, any> = {};
|
|
12
|
+
Object.keys(datum).forEach((key) => {
|
|
13
|
+
sanitized[key] = escapeHtml(datum[key]);
|
|
14
|
+
});
|
|
15
|
+
return sanitized;
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
export class Tooltip extends Component<TooltipStyleProps> {
|
|
11
19
|
public static tag = 'tooltip';
|
|
12
20
|
|
|
@@ -30,7 +38,7 @@ export class Tooltip extends Component<TooltipStyleProps> {
|
|
|
30
38
|
const { data, template } = this.attributes;
|
|
31
39
|
return data.map(({ name = '', color = 'black', index, ...rest }, idx) => {
|
|
32
40
|
const datum = { name, color, index: index ?? idx, ...rest };
|
|
33
|
-
return createDOM(substitute(template.item!, datum)) as HTMLElement;
|
|
41
|
+
return createDOM(substitute(template.item!, sanitizeDatum(datum))) as HTMLElement;
|
|
34
42
|
});
|
|
35
43
|
}
|
|
36
44
|
|
|
@@ -57,7 +65,7 @@ export class Tooltip extends Component<TooltipStyleProps> {
|
|
|
57
65
|
prefixCls: '',
|
|
58
66
|
container: `<div class="${CLASS_NAME.CONTAINER}"></div>`,
|
|
59
67
|
title: `<div class="${CLASS_NAME.TITLE}"></div>`,
|
|
60
|
-
item: `<li class="${CLASS_NAME.LIST_ITEM}" data-index={index}>
|
|
68
|
+
item: `<li class="${CLASS_NAME.LIST_ITEM}" data-index="{index}">
|
|
61
69
|
<span class="${CLASS_NAME.NAME}">
|
|
62
70
|
<span class="${CLASS_NAME.MARKER}" style="background:{color}"></span>
|
|
63
71
|
<span class="${CLASS_NAME.NAME_LABEL}" title="{name}">{name}</span>
|
|
@@ -146,7 +154,7 @@ export class Tooltip extends Component<TooltipStyleProps> {
|
|
|
146
154
|
else {
|
|
147
155
|
if (title) {
|
|
148
156
|
container.innerHTML = template.title!;
|
|
149
|
-
container.getElementsByClassName(CLASS_NAME.TITLE)[0].innerHTML = title;
|
|
157
|
+
container.getElementsByClassName(CLASS_NAME.TITLE)[0].innerHTML = escapeHtml(title);
|
|
150
158
|
} else container.getElementsByClassName(CLASS_NAME.TITLE)?.[0]?.remove();
|
|
151
159
|
const itemsElements = this.HTMLTooltipItemsElements;
|
|
152
160
|
const ul = document.createElement('ul');
|
package/src/util/string.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const HTML_ESCAPE_MAP: Record<string, string> = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
"'": ''',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function escapeHtml(value: unknown): string {
|
|
10
|
+
return String(value).replace(/[&<>"']/g, (character) => HTML_ESCAPE_MAP[character]);
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
export function toUppercaseFirstLetter(string: string) {
|
|
2
14
|
return string.toString().charAt(0).toUpperCase() + string.toString().slice(1);
|
|
3
15
|
}
|