@antv/component 2.1.10 → 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.
Files changed (53) hide show
  1. package/dist/component.min.js +1 -1
  2. package/esm/ui/axis/guides/labels.js +6 -2
  3. package/esm/ui/axis/guides/labels.js.map +1 -1
  4. package/esm/ui/legend/category.js +2 -2
  5. package/esm/ui/legend/category.js.map +1 -1
  6. package/esm/ui/legend/types.d.ts +4 -1
  7. package/esm/ui/navigator/index.js +1 -0
  8. package/esm/ui/navigator/index.js.map +1 -1
  9. package/esm/ui/scrollbar/index.js.map +1 -1
  10. package/esm/ui/select/select.js.map +1 -1
  11. package/esm/ui/slider/index.js +0 -1
  12. package/esm/ui/slider/index.js.map +1 -1
  13. package/esm/ui/tooltip/index.js +11 -4
  14. package/esm/ui/tooltip/index.js.map +1 -1
  15. package/esm/util/extend-display-object.js +5 -1
  16. package/esm/util/extend-display-object.js.map +1 -1
  17. package/esm/util/parse-height-from-html.js +0 -1
  18. package/esm/util/parse-height-from-html.js.map +1 -1
  19. package/esm/util/string.d.ts +1 -0
  20. package/esm/util/string.js +10 -0
  21. package/esm/util/string.js.map +1 -1
  22. package/lib/ui/axis/guides/labels.js +5 -1
  23. package/lib/ui/axis/guides/labels.js.map +1 -1
  24. package/lib/ui/legend/category.js +2 -2
  25. package/lib/ui/legend/category.js.map +1 -1
  26. package/lib/ui/legend/types.d.ts +4 -1
  27. package/lib/ui/navigator/index.js +1 -0
  28. package/lib/ui/navigator/index.js.map +1 -1
  29. package/lib/ui/scrollbar/index.js.map +1 -1
  30. package/lib/ui/select/select.js.map +1 -1
  31. package/lib/ui/slider/index.js +0 -1
  32. package/lib/ui/slider/index.js.map +1 -1
  33. package/lib/ui/tooltip/index.js +10 -3
  34. package/lib/ui/tooltip/index.js.map +1 -1
  35. package/lib/util/extend-display-object.js +5 -1
  36. package/lib/util/extend-display-object.js.map +1 -1
  37. package/lib/util/parse-height-from-html.js +0 -1
  38. package/lib/util/parse-height-from-html.js.map +1 -1
  39. package/lib/util/string.d.ts +1 -0
  40. package/lib/util/string.js +11 -0
  41. package/lib/util/string.js.map +1 -1
  42. package/package.json +1 -1
  43. package/src/ui/axis/guides/labels.ts +9 -1
  44. package/src/ui/legend/category.ts +2 -2
  45. package/src/ui/legend/types.ts +5 -1
  46. package/src/ui/navigator/index.ts +1 -0
  47. package/src/ui/scrollbar/index.ts +6 -6
  48. package/src/ui/select/select.ts +1 -1
  49. package/src/ui/slider/index.ts +2 -3
  50. package/src/ui/tooltip/index.ts +12 -4
  51. package/src/util/extend-display-object.ts +9 -1
  52. package/src/util/parse-height-from-html.ts +0 -1
  53. package/src/util/string.ts +12 -0
@@ -67,5 +67,9 @@ export type ContinuousStyleProps = LegendBaseStyleProps &
67
67
 
68
68
  export type ContinuousOptions = ComponentOptions<ContinuousStyleProps>;
69
69
 
70
- export type CategoryStyleProps = LegendBaseStyleProps & CategoryItemsStyleProps;
70
+ export type CategoryStyleProps = LegendBaseStyleProps &
71
+ CategoryItemsStyleProps & {
72
+ dx?: number;
73
+ dy?: number;
74
+ };
71
75
  export type CategoryOptions = ComponentOptions<CategoryStyleProps>;
@@ -146,6 +146,7 @@ export class Navigator extends Component<NavigatorStyleProps> {
146
146
  );
147
147
 
148
148
  onAnimateFinished(animation, () => {
149
+ animation?.cancel();
149
150
  this.innerCurrPage = pageNum;
150
151
  this.playState = 'idle';
151
152
  this.setVisiblePages([pageNum]);
@@ -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
  }
@@ -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
  },
@@ -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
  }
@@ -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');
@@ -11,5 +11,13 @@ export function renderExtDo(el: ExtendDisplayObject): DisplayObject {
11
11
 
12
12
  export function renderHtmlExtDo(el: ExtendDisplayObject, style: Partial<HTMLStyleProps>): DisplayObject {
13
13
  if (typeof el === 'function') return el();
14
- return isString(el) || isNumber(el) ? new HTML({ style: { ...style, innerHTML: String(el) } }) : el;
14
+ return isString(el) || isNumber(el)
15
+ ? new HTML({
16
+ style: {
17
+ pointerEvents: 'auto',
18
+ ...style,
19
+ innerHTML: el as string | HTMLElement,
20
+ },
21
+ })
22
+ : el;
15
23
  }
@@ -3,7 +3,6 @@ export const parseHeightFromHTML = (html: string): number => {
3
3
  const parser = new DOMParser();
4
4
  const doc = parser.parseFromString(html, 'text/html');
5
5
  const el = doc.body.firstElementChild;
6
- console.log(el?.getClientRects(), 11);
7
6
 
8
7
  if (!el) return 0;
9
8
 
@@ -1,3 +1,15 @@
1
+ const HTML_ESCAPE_MAP: Record<string, string> = {
2
+ '&': '&amp;',
3
+ '<': '&lt;',
4
+ '>': '&gt;',
5
+ '"': '&quot;',
6
+ "'": '&#39;',
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
  }