WorkflowEditBlock.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div id="workflow-edit-block" class="px-4 overflow-auto scroll pb-1">
  3. <div
  4. class="sticky top-0 z-20 bg-white dark:bg-gray-800 pb-4 mb-2 flex items-center space-x-2"
  5. >
  6. <button @click="$emit('close')">
  7. <v-remixicon name="riArrowLeftLine" />
  8. </button>
  9. <p class="font-semibold inline-block capitalize">
  10. {{ getBlockName() }}
  11. </p>
  12. <div class="flex-grow"></div>
  13. <a
  14. :title="t('common.docs')"
  15. :href="`https://docs.automa.site/blocks/${data.id}.html`"
  16. rel="noopener"
  17. target="_blank"
  18. class="text-gray-600 dark:text-gray-200"
  19. >
  20. <v-remixicon name="riInformationLine" />
  21. </a>
  22. </div>
  23. <component
  24. :is="getEditComponent()"
  25. v-if="blockData"
  26. :key="data.itemId || data.blockId"
  27. v-model:data="blockData"
  28. :block-id="data.blockId"
  29. v-bind="{
  30. fullData: data.id === 'conditions' ? data : null,
  31. editor: data.id === 'conditions' ? editor : null,
  32. connections: data.id === 'wait-connections' ? data.connections : null,
  33. }"
  34. />
  35. </div>
  36. </template>
  37. <script setup>
  38. import { computed } from 'vue';
  39. import { useI18n } from 'vue-i18n';
  40. import customEditComponents from '@business/blocks/editComponents';
  41. const editComponents = require.context(
  42. './edit',
  43. false,
  44. /^(?:.*\/)?Edit[^/]*\.vue$/
  45. );
  46. /* eslint-disable-next-line */
  47. const components = editComponents.keys().reduce((acc, key) => {
  48. const name = key.replace(/(.\/)|\.vue$/g, '');
  49. const componentObj = editComponents(key)?.default ?? {};
  50. acc[name] = componentObj;
  51. return acc;
  52. }, {});
  53. Object.assign(components, customEditComponents());
  54. const props = defineProps({
  55. data: {
  56. type: Object,
  57. default: () => ({}),
  58. },
  59. editor: {
  60. type: Object,
  61. default: () => ({}),
  62. },
  63. workflow: {
  64. type: Object,
  65. default: () => ({}),
  66. },
  67. autocomplete: {
  68. type: Object,
  69. default: () => ({}),
  70. },
  71. dataChanged: Boolean,
  72. });
  73. const emit = defineEmits(['close', 'update', 'update:autocomplete']);
  74. const { t, te } = useI18n();
  75. const blockData = computed({
  76. get() {
  77. return props.data.data;
  78. },
  79. set(data) {
  80. emit('update', data);
  81. },
  82. });
  83. function getEditComponent() {
  84. const editComp = props.data.editComponent;
  85. if (typeof editComp === 'object') return editComp;
  86. return components[editComp];
  87. }
  88. function getBlockName() {
  89. const key = `workflow.blocks.${props.data.id}.name`;
  90. return te(key) ? t(key) : props.data.name;
  91. }
  92. </script>
  93. <style>
  94. #workflow-edit-block hr {
  95. @apply dark:border-gray-700 dark:border-opacity-40 my-4;
  96. }
  97. </style>