view.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.VueShapeView = void 0;
  4. const x6_1 = require("@antv/x6");
  5. const vue_demi_1 = require("vue-demi");
  6. const registry_1 = require("./registry");
  7. const teleport_1 = require("./teleport");
  8. class VueShapeView extends x6_1.NodeView {
  9. getComponentContainer() {
  10. return this.selectors && this.selectors.foContent;
  11. }
  12. confirmUpdate(flag) {
  13. const ret = super.confirmUpdate(flag);
  14. return this.handleAction(ret, VueShapeView.action, () => {
  15. this.renderVueComponent();
  16. });
  17. }
  18. targetId() {
  19. return `${this.graph.view.cid}:${this.cell.id}`;
  20. }
  21. renderVueComponent() {
  22. this.unmountVueComponent();
  23. const root = this.getComponentContainer();
  24. const node = this.cell;
  25. const graph = this.graph;
  26. if (root) {
  27. const { component } = registry_1.shapeMaps[node.shape];
  28. if (component) {
  29. if (vue_demi_1.isVue2) {
  30. const Vue = vue_demi_1.Vue2;
  31. this.vm = new Vue({
  32. el: root,
  33. render(h) {
  34. return h(component, { node, graph });
  35. },
  36. provide() {
  37. return {
  38. getNode: () => node,
  39. getGraph: () => graph,
  40. };
  41. },
  42. });
  43. }
  44. else if (vue_demi_1.isVue3) {
  45. if ((0, teleport_1.isActive)()) {
  46. (0, teleport_1.connect)(this.targetId(), component, root, node, graph);
  47. }
  48. else {
  49. this.vm = (0, vue_demi_1.createApp)({
  50. render() {
  51. return (0, vue_demi_1.h)(component, { node, graph });
  52. },
  53. provide() {
  54. return {
  55. getNode: () => node,
  56. getGraph: () => graph,
  57. };
  58. },
  59. });
  60. this.vm.mount(root);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. unmountVueComponent() {
  67. const root = this.getComponentContainer();
  68. if (this.vm) {
  69. vue_demi_1.isVue2 && this.vm.$destroy();
  70. vue_demi_1.isVue3 && this.vm.unmount();
  71. this.vm = null;
  72. }
  73. if (root) {
  74. root.innerHTML = '';
  75. }
  76. return root;
  77. }
  78. onMouseDown(e, x, y) {
  79. const target = e.target;
  80. const tagName = target.tagName.toLowerCase();
  81. if (tagName === 'input') {
  82. const type = target.getAttribute('type');
  83. if (type == null ||
  84. [
  85. 'text',
  86. 'password',
  87. 'number',
  88. 'email',
  89. 'search',
  90. 'tel',
  91. 'url',
  92. ].includes(type)) {
  93. return;
  94. }
  95. }
  96. super.onMouseDown(e, x, y);
  97. }
  98. unmount() {
  99. if ((0, teleport_1.isActive)()) {
  100. (0, teleport_1.disconnect)(this.targetId());
  101. }
  102. this.unmountVueComponent();
  103. super.unmount();
  104. return this;
  105. }
  106. }
  107. exports.VueShapeView = VueShapeView;
  108. (function (VueShapeView) {
  109. VueShapeView.action = 'vue';
  110. VueShapeView.config({
  111. bootstrap: [VueShapeView.action],
  112. actions: {
  113. component: VueShapeView.action,
  114. },
  115. });
  116. x6_1.NodeView.registry.register('vue-shape-view', VueShapeView, true);
  117. })(VueShapeView = exports.VueShapeView || (exports.VueShapeView = {}));
  118. //# sourceMappingURL=view.js.map