Sha256: 2b4889094f62c5b56dc525974c80042bf69f885b3dee89e5ed4f85e7b4ccea03

Contents?: true

Size: 1.29 KB

Versions: 21

Compression:

Stored size: 1.29 KB

Contents

import '@github/clipboard-copy-element'

const CLIPBOARD_COPY_TIMER_DURATION = 2000

function showSVG(svg: SVGElement) {
  svg.style.display = 'inline-block'
}

function hideSVG(svg: SVGElement) {
  svg.style.display = 'none'
}

// Toggle a copy button.
function showCopy(button: HTMLElement) {
  const [copyIcon, checkIcon] = button.querySelectorAll<SVGElement>('.octicon')

  if (!copyIcon || !checkIcon) return

  showSVG(copyIcon)
  hideSVG(checkIcon)
}

// Toggle a copy button.
function showCheck(button: HTMLElement) {
  const [copyIcon, checkIcon] = button.querySelectorAll<SVGElement>('.octicon')

  if (!copyIcon || !checkIcon) return

  hideSVG(copyIcon)
  showSVG(checkIcon)
}

const clipboardCopyElementTimers = new WeakMap<HTMLElement, number>()

document.addEventListener('clipboard-copy', ({target}) => {
  if (!(target instanceof HTMLElement)) return
  if (!target.hasAttribute('data-view-component')) return

  const currentTimeout = clipboardCopyElementTimers.get(target)

  if (currentTimeout) {
    clearTimeout(currentTimeout)
    clipboardCopyElementTimers.delete(target)
  } else {
    showCheck(target)
  }

  clipboardCopyElementTimers.set(
    target,
    setTimeout(() => {
      showCopy(target)
      clipboardCopyElementTimers.delete(target)
    }, CLIPBOARD_COPY_TIMER_DURATION),
  )
})

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.32.1 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.32.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.29.1 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.29.0 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.23.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.28.1 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.28.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.27.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.26.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.25.1 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.22.0 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.21.1 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.25.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.24.0 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.21.0 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.20.1 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.20.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.23.0 app/components/primer/beta/clipboard_copy.ts
primer_view_components-0.19.0 app/components/primer/beta/clipboard_copy.ts
openproject-primer_view_components-0.22.2 app/components/primer/beta/clipboard_copy.ts