@skyservice-developers/vue-dev-kit 1.2.8 → 1.3.0

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": "@skyservice-developers/vue-dev-kit",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "description": "Vue 2 and Vue 3 developer toolkit - components and helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/vue3/vue-dev-kit.cjs",
@@ -1 +1,2 @@
1
1
  export { webviewCheck, isIosWebview, isAndroidWebview, isCefWebview, isWebview, isInIframe } from './webviewCheck'
2
+ export { getParentLocalStorage, getParentStoreValue, getParentWindowValue, sendToParent, setSenderId, getSenderId } from './parentBridge'
@@ -2,11 +2,36 @@ import { isInIframe } from './webviewCheck'
2
2
 
3
3
  const TIMEOUT = 3000
4
4
  let counter = 0
5
+ let _senderId = null
5
6
 
6
7
  function generateRequestId() {
7
8
  return `req_${++counter}_${Date.now()}`
8
9
  }
9
10
 
11
+ function generateAppId() {
12
+ return 'APP_' + Math.random().toString(36).slice(2, 10)
13
+ }
14
+
15
+ export function setSenderId(id) {
16
+ _senderId = id
17
+ }
18
+
19
+ export function getSenderId() {
20
+ if (!_senderId) {
21
+ _senderId = generateAppId()
22
+ }
23
+ return _senderId
24
+ }
25
+
26
+ export function sendToParent(message) {
27
+ if (!isInIframe()) return
28
+ window.parent.postMessage({
29
+ ...message,
30
+ sender: getSenderId(),
31
+ target: message.target || 'DASHBOARD',
32
+ }, '*')
33
+ }
34
+
10
35
  function requestFromParent(source, key) {
11
36
  if (!isInIframe()) return Promise.resolve(null)
12
37
 
@@ -19,22 +44,26 @@ function requestFromParent(source, key) {
19
44
  }, TIMEOUT)
20
45
 
21
46
  function handler(event) {
47
+ const d = event.data
22
48
  if (
23
- event.data?.type === 'DATA_RESPONSE' &&
24
- event.data?.requestId === requestId
49
+ d?.type === 'DATA_RESPONSE' &&
50
+ d?.requestId === requestId &&
51
+ (!d.target || d.target === getSenderId())
25
52
  ) {
26
53
  clearTimeout(timeout)
27
54
  window.removeEventListener('message', handler)
28
- resolve(event.data.data ?? null)
55
+ resolve(d.data ?? null)
29
56
  }
30
57
  }
31
58
 
32
59
  window.addEventListener('message', handler)
33
60
 
34
- window.parent.postMessage(
35
- { type: 'DATA_REQUEST', requestId, source, key },
36
- '*',
37
- )
61
+ sendToParent({
62
+ type: 'DATA_REQUEST',
63
+ requestId,
64
+ source,
65
+ key,
66
+ })
38
67
  })
39
68
  }
40
69
 
@@ -80,7 +80,7 @@
80
80
  <script setup>
81
81
  import { ref, computed, onMounted, onUnmounted } from 'vue'
82
82
  import { isInIframe } from '../../shared/utils/webviewCheck'
83
- import { getParentLocalStorage, getParentWindowValue } from '../../shared/utils/parentBridge'
83
+ import { getParentLocalStorage, getParentWindowValue, sendToParent, setSenderId, getSenderId } from '../../shared/utils/parentBridge'
84
84
 
85
85
  const props = defineProps({
86
86
  title: {
@@ -123,8 +123,15 @@ const props = defineProps({
123
123
  type: String,
124
124
  default: "",
125
125
  },
126
+ appId: {
127
+ type: String,
128
+ default: "",
129
+ },
126
130
  });
127
131
 
132
+ // Initialize sender ID from prop or generate
133
+ setSenderId(props.appId || getSenderId())
134
+
128
135
  const emit = defineEmits(['back', 'navigate'])
129
136
 
130
137
  const dropdownRef = ref(null)
@@ -134,15 +141,17 @@ const localStorageItems = ref([])
134
141
  const parentLang = ref({})
135
142
 
136
143
  // Track page visit in parent's componentStats
137
- console.log('[Header] trackPageName:', props.trackPageName, 'isInIframe:', isInIframe())
138
144
  if (isInIframe() && props.trackPageName) {
139
- const msg = {
145
+ sendToParent({
140
146
  type: 'trackVisit',
141
147
  name: props.trackPageName,
142
148
  path: props.trackPagePath || `/${props.trackPageName}`,
143
- }
144
- console.log('[Header] sending trackVisit:', msg)
145
- window.parent.postMessage(msg, '*')
149
+ })
150
+ }
151
+
152
+ // Set rocketMode in parent
153
+ if (isInIframe()) {
154
+ sendToParent({ type: 'setRocketMode', value: true })
146
155
  }
147
156
 
148
157
  // Load translations from parent
@@ -195,7 +204,7 @@ const closeDropdown = () => {
195
204
  const selectItem = (item) => {
196
205
  emit('navigate', item.path)
197
206
  if (isInIframe()) {
198
- window.parent.postMessage({ type: 'navigate', path: item.path }, '*')
207
+ sendToParent({ type: 'navigate', path: item.path })
199
208
  }
200
209
  closeDropdown()
201
210
  }
@@ -243,7 +252,7 @@ const shouldShowBackButton = computed(() => {
243
252
  const handleBack = () => {
244
253
  if (props.backEvent) return props.backEvent()
245
254
 
246
- window.parent.postMessage({ type: 'exit' }, '*')
255
+ sendToParent({ type: 'exit' })
247
256
  }
248
257
  </script>
249
258