🤷‍♂️ RStudio Addin to Search and Copy Emoji
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

105 lines
2.9KB

  1. import { EmojiButton } from './emoji-button.js' // @joeattardi/emoji-button
  2. const pickerTypePlugin = {
  3. render(picker) {
  4. const choices = [
  5. {value: 'unicode', label: '<span>Unicode</span>'},
  6. {value: 'html', label: '<span>HTML</span>'},
  7. {value: 'emo_ji', label: '<span style="font-family: monospace;">emo::ji</span>'}
  8. ]
  9. function htmlToElems(html) {
  10. let temp = document.createElement('template');
  11. temp.innerHTML = html;
  12. return temp.content.childNodes;
  13. }
  14. function makeRadioElement({value, label}) {
  15. const div = document.createElement('div')
  16. const divLabel = document.createElement('label')
  17. divLabel.classList = 'radio-inline'
  18. const input = document.createElement('input')
  19. input.type = 'radio'
  20. input.name = 'picker_type'
  21. input.value = value
  22. if (document.getElementById('picker-gadget').matches('.' + value)) {
  23. input.checked = 'checked'
  24. }
  25. divLabel.appendChild(input)
  26. divLabel.appendChild(htmlToElems(label)[0])
  27. div.appendChild(divLabel)
  28. return div
  29. }
  30. const div = document.createElement('div')
  31. div.id = 'picker_type'
  32. const label = document.createElement('label')
  33. label.classList = 'control-label'
  34. label['for'] = 'picker_type'
  35. label.innerText = 'Insert as...'
  36. div.appendChild(label)
  37. choices.map(makeRadioElement).forEach(el => div.appendChild(el))
  38. return div;
  39. }
  40. }
  41. const picker = new EmojiButton({
  42. position: {
  43. top: '0',
  44. right: '0',
  45. bottom: '0',
  46. left: '0'
  47. },
  48. autoHide: false,
  49. theme: document.getElementById('picker-gadget').matches('.dark-theme') ? 'dark' : 'light',
  50. // plugins: [closePlugin, insertEmoji]
  51. plugins: [pickerTypePlugin]
  52. })
  53. picker.on('emoji', function(selection) {
  54. selection.html = he.encode(selection.emoji)
  55. Shiny.setInputValue('emoji', selection, { priority: 'event' });
  56. });
  57. picker.togglePicker(document.getElementById('emoji-picker'))
  58. document.querySelector('.emoji-picker__wrapper').addEventListener('keydown', function(ev) {
  59. if (ev.keyCode === 27) {
  60. ev.stopPropagation()
  61. Shiny.setInputValue('close', Date.now())
  62. }
  63. })
  64. // Communicate choices of emoji type to insert ...
  65. const pickerInput = document.getElementById('picker_type')
  66. function reportPickerType() {
  67. const choices = [...pickerInput.querySelectorAll('input')]
  68. const value = choices.filter(item => item.checked).map(item => item.value)
  69. Shiny.setInputValue('picker_type', value[0])
  70. }
  71. function updatePickerType(value) {
  72. const choices = [...pickerInput.querySelectorAll('input')]
  73. choices.forEach(function(choice) {
  74. if (choice.value === value) {
  75. choice.checked = 'checked'
  76. Shiny.setInputValue('picker_type', value)
  77. } else {
  78. choice.removeAttribute('checked')
  79. }
  80. })
  81. }
  82. pickerInput.addEventListener('change', reportPickerType)
  83. $().on('shiny:sessioninitialized', reportPickerType)
  84. Shiny.addCustomMessageHandler('update_picker_type', updatePickerType)