@operato/data-grist 2.0.0-beta.12 → 2.0.0-beta.13

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.
@@ -545,6 +545,10 @@ export class DataGridBody extends LitElement {
545
545
  const opacity = selectBlock.style.opacity
546
546
 
547
547
  selectBlock.setAttribute('data-tooltip', 'copied to clipboard!')
548
+ const rect = selectBlock.getBoundingClientRect()
549
+ selectBlock.style.setProperty('--tooltip-top', `${rect.top}px`)
550
+ selectBlock.style.setProperty('--tooltip-left', `${rect.left}px`)
551
+
548
552
  selectBlock.style.backgroundColor = 'red'
549
553
  selectBlock.style.opacity = '0.5'
550
554
  await sleep(500)
@@ -3,10 +3,10 @@ import { css, html, LitElement, PropertyValues, TemplateResult } from 'lit'
3
3
  import { customElement, property } from 'lit/decorators.js'
4
4
 
5
5
  import { TooltipStyles } from '@operato/styles'
6
+ import { TooltipReactiveController } from '@operato/utils'
6
7
 
7
8
  import { ZERO_COLUMN } from '../configure/zero-config'
8
9
  import { ColumnConfig, GristRecord } from '../types'
9
- import { getRenderer } from '../renderers'
10
10
 
11
11
  const DEFAULT_TEXT_ALIGN = 'left'
12
12
 
@@ -103,6 +103,8 @@ export class DataGridField extends LitElement {
103
103
  private _onFieldChange: (e: Event) => void = e => {}
104
104
  private _onKeydownInEditingMode: (e: KeyboardEvent) => void = e => {}
105
105
 
106
+ private tooltipController?: TooltipReactiveController = new TooltipReactiveController(this)
107
+
106
108
  render(): TemplateResult {
107
109
  if (!this.column) {
108
110
  return html``
@@ -8,7 +8,7 @@ import throttle from 'lodash-es/throttle'
8
8
 
9
9
  import { OxPopup } from '@operato/popup'
10
10
  import { TooltipStyles } from '@operato/styles'
11
- import { closestElement, detectOverflow } from '@operato/utils'
11
+ import { TooltipReactiveController, closestElement } from '@operato/utils'
12
12
 
13
13
  import { ZERO_COLUMNS, ZERO_DATA } from '../configure/zero-config'
14
14
  import { FilterStyles } from '../filters/filter-styles'
@@ -163,6 +163,8 @@ export class DataGridHeader extends LitElement {
163
163
  private _lastAccVal?: number
164
164
  private _throttledNotifier?: any
165
165
 
166
+ private tooltipController?: TooltipReactiveController = new TooltipReactiveController(this)
167
+
166
168
  connectedCallback() {
167
169
  super.connectedCallback()
168
170
 
@@ -232,19 +234,9 @@ export class DataGridHeader extends LitElement {
232
234
  >
233
235
  <span
234
236
  for-title
237
+ data-reactive-tooltip
235
238
  style="text-align:${align || column.record.align || 'left'};"
236
239
  @click=${(e: MouseEvent) => this._changeSort(column)}
237
- @mouseover=${(e: MouseEvent) => {
238
- const element = e.target as HTMLSpanElement
239
-
240
- if (detectOverflow(element)) {
241
- element.setAttribute('data-tooltip', element.textContent!.trim())
242
- }
243
- }}
244
- @mouseout=${(e: MouseEvent) => {
245
- const element = e.target as HTMLSpanElement
246
- element.removeAttribute('data-tooltip')
247
- }}
248
240
  >${this._renderHeader(column)}
249
241
  </span>
250
242
 
@@ -11,6 +11,10 @@ function onmouseover(e: Event) {
11
11
  } catch {}
12
12
 
13
13
  element.setAttribute('data-tooltip', JSON5.stringify(parsed, null, 2))
14
+
15
+ const rect = element.getBoundingClientRect()
16
+ element.style.setProperty('--tooltip-top', `${rect.top + rect.height}px`)
17
+ element.style.setProperty('--tooltip-left', `${rect.left}px`)
14
18
  }
15
19
 
16
20
  function onmouseout(e: Event) {
@@ -1,21 +1,9 @@
1
1
  import { html } from 'lit'
2
2
 
3
- import { detectOverflow, format as formatter } from '@operato/utils'
3
+ import { format as formatter } from '@operato/utils'
4
4
 
5
5
  import { FieldRenderer } from '../types'
6
6
 
7
- function onmouseover(e: Event) {
8
- const element = e.target as HTMLSpanElement
9
- if (detectOverflow(element)) {
10
- element.setAttribute('data-tooltip', element.textContent!)
11
- }
12
- }
13
-
14
- function onmouseout(e: Event) {
15
- const element = e.target as HTMLSpanElement
16
- element.removeAttribute('data-tooltip')
17
- }
18
-
19
7
  export const OxGristRendererText: FieldRenderer = (value, column, record, rowIndex, field) => {
20
8
  var { format } = column.record || {}
21
9
 
@@ -24,5 +12,5 @@ export const OxGristRendererText: FieldRenderer = (value, column, record, rowInd
24
12
  text = formatter(format, text)
25
13
  }
26
14
 
27
- return html`<span @mouseover=${onmouseover} @mouseout=${onmouseout}>${text}&nbsp;</span>`
15
+ return html`<span data-reactive-tooltip>${text}&nbsp;</span>`
28
16
  }