editorBlock.js 775 B

12345678910111213141516171819202122232425262728293031
  1. import { reactive, nextTick } from 'vue';
  2. import { tasks, categories } from '@/utils/shared';
  3. export function useEditorBlock(selector, editor) {
  4. const block = reactive({
  5. id: '',
  6. data: {},
  7. details: {},
  8. category: {},
  9. });
  10. nextTick(() => {
  11. const element = document.querySelector(selector);
  12. if (block.id || !element) return;
  13. block.id = element.parentElement.parentElement.id.replace('node-', '');
  14. if (block.id) {
  15. const { name, data } = editor.getNodeFromId(block.id);
  16. const details = tasks[name];
  17. block.details = { id: name, ...details };
  18. block.data = data || details.data;
  19. block.category = categories[details.category];
  20. }
  21. editor.updateConnectionNodes(`node-${block.id}`);
  22. });
  23. return block;
  24. }