@farm-investimentos/front-mfe-components 15.14.13 → 15.14.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "15.14.13",
3
+ "version": "15.14.14",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -37,4 +37,4 @@
37
37
  left: 50% !important;
38
38
  transform: translate(-50%, -50%) !important;
39
39
  }
40
- }
40
+ }
@@ -21,6 +21,8 @@
21
21
  import { ref, watch, reactive, onBeforeUnmount, toRefs, defineComponent, nextTick } from 'vue';
22
22
  import { calculateMainZindex, isChildOfFixedElement } from '../../helpers';
23
23
 
24
+ const CLOSE_ALL_CONTEXT_MENUS_EVENT = 'farm-contextmenu:close-all';
25
+
24
26
  export default defineComponent({
25
27
  name: 'farm-contextmenu',
26
28
  props: {
@@ -89,6 +91,7 @@ export default defineComponent({
89
91
  } as any);
90
92
 
91
93
  const inputValue = ref(props.value);
94
+ const instanceContextId = Math.random().toString(36).substring(7);
92
95
 
93
96
  let hasBeenBoostrapped = false;
94
97
 
@@ -112,6 +115,15 @@ export default defineComponent({
112
115
  calculatePosition();
113
116
  };
114
117
 
118
+ const closeAllHandler = (event: CustomEvent) => {
119
+ if (event.detail?.exceptId !== instanceContextId && inputValue.value) {
120
+ inputValue.value = false;
121
+ emit('input', false);
122
+ }
123
+ };
124
+
125
+ window.addEventListener(CLOSE_ALL_CONTEXT_MENUS_EVENT, closeAllHandler as any);
126
+
115
127
  watch(
116
128
  () => props.value,
117
129
  newValue => {
@@ -234,10 +246,20 @@ export default defineComponent({
234
246
  window.removeEventListener('click', outClick);
235
247
  document.querySelector('body').removeChild(popup.value);
236
248
  }
249
+ window.removeEventListener(CLOSE_ALL_CONTEXT_MENUS_EVENT, closeAllHandler as any);
237
250
  });
238
251
 
239
252
  const click = () => {
240
- inputValue.value = !inputValue.value;
253
+ const willOpen = !inputValue.value;
254
+
255
+ if (willOpen) {
256
+ const closeEvent = new CustomEvent(CLOSE_ALL_CONTEXT_MENUS_EVENT, {
257
+ detail: { exceptId: instanceContextId }
258
+ });
259
+ window.dispatchEvent(closeEvent);
260
+ }
261
+
262
+ inputValue.value = willOpen;
241
263
  emit('input', inputValue.value);
242
264
  };
243
265
 
@@ -1,7 +1,8 @@
1
1
  <template>
2
2
  <farm-contextmenu
3
3
  :class="{ 'farm-context-menu': true, 'farm-context-menu--disabled': disabled }"
4
- v-model="value"
4
+ :value="value"
5
+ @input="value = $event"
5
6
  >
6
7
  <template v-slot:activator>
7
8
  <farm-btn
@@ -9,7 +10,6 @@
9
10
  title="Ver opções"
10
11
  color="secondary-green"
11
12
  :disabled="disabled"
12
- @click="toggleValue"
13
13
  >
14
14
  <farm-icon size="md">dots-horizontal</farm-icon>
15
15
  </farm-btn>
@@ -70,15 +70,11 @@ export default defineComponent({
70
70
  };
71
71
  },
72
72
  methods: {
73
- onClick(handler) {
73
+ onClick(handler: string) {
74
74
  if (handler !== undefined) {
75
75
  this.$emit(handler);
76
76
  }
77
77
  },
78
- toggleValue(event: MouseEvent) {
79
- this.value = !this.value;
80
- event.stopPropagation();
81
- },
82
78
  },
83
79
  });
84
80
  </script>