BlockBase.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div ref="rootRef" class="group relative overflow-x-hiddenx">
  3. <div
  4. class="
  5. z-10
  6. flex
  7. items-center
  8. bg-white
  9. relative
  10. rounded-lg
  11. overflow-hidden
  12. p-4
  13. "
  14. >
  15. <span
  16. :class="categories[state.blockData.category]?.color"
  17. class="inline-block p-2 mr-2 rounded-lg bg-green-200"
  18. >
  19. <v-remixicon
  20. :path="icons[state.blockData.icon] || icons.riGlobalLine"
  21. />
  22. </span>
  23. <div style="max-width: 220px">
  24. <p class="font-semibold leading-none whitespace-nowrap">
  25. {{ state.blockData.name }}
  26. </p>
  27. <p class="text-gray-600 text-overflow leading-tight">
  28. {{ state.blockData.description }}
  29. </p>
  30. </div>
  31. </div>
  32. <div
  33. class="
  34. absolute
  35. top-0
  36. transition-transform
  37. duration-300
  38. group-hover:translate-y-16
  39. pt-4
  40. ml-1
  41. menu
  42. "
  43. >
  44. <div class="bg-accent px-4 py-2 text-white rounded-lg flex items-center">
  45. <button class="-ml-1">
  46. <v-remixicon size="20" :path="icons.riPencilLine" />
  47. </button>
  48. <hr class="border-r border-gray-600 h-5 mx-3" />
  49. <button
  50. class="-mr-1"
  51. @click="emitter.emit('block:delete', state.blockId)"
  52. >
  53. <v-remixicon size="20" :path="icons.riDeleteBin7Line" />
  54. </button>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <script setup>
  60. import { ref, nextTick, shallowReactive } from 'vue';
  61. import { VRemixIcon as VRemixicon } from 'v-remixicon';
  62. import emitter from 'tiny-emitter/instance';
  63. import { icons } from '@/lib/v-remixicon';
  64. import { tasks, categories } from '@/utils/shared';
  65. const props = defineProps({
  66. editor: {
  67. type: Object,
  68. default: () => ({}),
  69. },
  70. });
  71. const rootRef = ref(null);
  72. const state = shallowReactive({
  73. blockId: '',
  74. blockData: {},
  75. });
  76. nextTick(() => {
  77. state.blockId = rootRef.value?.parentElement.parentElement.id.replace(
  78. 'node-',
  79. ''
  80. );
  81. if (state.blockId) {
  82. const { name } = props.editor.getNodeFromId(state.blockId);
  83. state.blockData = tasks[name];
  84. }
  85. });
  86. </script>