editorBlock.js 988 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. retrieved: false,
  10. containerEl: null,
  11. });
  12. nextTick(() => {
  13. const rootElement = editor.rootElement || document;
  14. const element = rootElement.querySelector(selector);
  15. if (block.id || !element) return;
  16. block.containerEl = element.parentElement.parentElement;
  17. block.id = block.containerEl.id.replace('node-', '');
  18. if (block.id) {
  19. const { name, data } = editor.getNodeFromId(block.id);
  20. const details = tasks[name];
  21. block.details = { id: name, ...details };
  22. block.data = data || details.data;
  23. block.category = categories[details.category];
  24. }
  25. setTimeout(() => {
  26. editor.updateConnectionNodes(`node-${block.id}`);
  27. }, 200);
  28. });
  29. block.retrieved = true;
  30. return block;
  31. }