@skyservice-developers/vue-dev-kit 1.2.1 → 1.2.3
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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isInIframe } from './webviewCheck'
|
|
2
|
+
|
|
3
|
+
const TIMEOUT = 3000
|
|
4
|
+
let counter = 0
|
|
5
|
+
|
|
6
|
+
function generateRequestId() {
|
|
7
|
+
return `req_${++counter}_${Date.now()}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function requestFromParent(source, key) {
|
|
11
|
+
if (!isInIframe()) return Promise.resolve(null)
|
|
12
|
+
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const requestId = generateRequestId()
|
|
15
|
+
|
|
16
|
+
const timeout = setTimeout(() => {
|
|
17
|
+
window.removeEventListener('message', handler)
|
|
18
|
+
resolve(null)
|
|
19
|
+
}, TIMEOUT)
|
|
20
|
+
|
|
21
|
+
function handler(event) {
|
|
22
|
+
if (
|
|
23
|
+
event.data?.type === 'DATA_RESPONSE' &&
|
|
24
|
+
event.data?.requestId === requestId
|
|
25
|
+
) {
|
|
26
|
+
clearTimeout(timeout)
|
|
27
|
+
window.removeEventListener('message', handler)
|
|
28
|
+
resolve(event.data.data ?? null)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
window.addEventListener('message', handler)
|
|
33
|
+
|
|
34
|
+
window.parent.postMessage(
|
|
35
|
+
{ type: 'DATA_REQUEST', requestId, source, key },
|
|
36
|
+
'*',
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getParentLocalStorage(key) {
|
|
42
|
+
return requestFromParent('localStorage', key)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getParentStoreValue(key) {
|
|
46
|
+
return requestFromParent('store', key)
|
|
47
|
+
}
|
|
@@ -80,6 +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 } from '../../shared/utils/parentBridge'
|
|
83
84
|
|
|
84
85
|
const props = defineProps({
|
|
85
86
|
title: {
|
|
@@ -121,8 +122,34 @@ const emit = defineEmits(['back', 'navigate'])
|
|
|
121
122
|
const dropdownRef = ref(null)
|
|
122
123
|
const isDropdownOpen = ref(false)
|
|
123
124
|
|
|
125
|
+
const localStorageItems = ref([])
|
|
126
|
+
|
|
127
|
+
function loadComponentStats(raw) {
|
|
128
|
+
try {
|
|
129
|
+
if (!raw) return
|
|
130
|
+
const data = typeof raw === 'string' ? JSON.parse(raw) : raw
|
|
131
|
+
if (data?.pages) {
|
|
132
|
+
localStorageItems.value = Object.values(data.pages)
|
|
133
|
+
}
|
|
134
|
+
} catch {}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Load from local localStorage first
|
|
138
|
+
loadComponentStats(localStorage['componentStats'])
|
|
139
|
+
|
|
140
|
+
// If in iframe, request from parent and update
|
|
141
|
+
if (isInIframe()) {
|
|
142
|
+
getParentLocalStorage('componentStats').then((data) => {
|
|
143
|
+
if (data != null) {
|
|
144
|
+
localStorage.setItem('componentStats', JSON.stringify(data))
|
|
145
|
+
loadComponentStats(data)
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
124
150
|
const sortedItems = computed(() => {
|
|
125
|
-
|
|
151
|
+
const items = props.dropdownItems.length ? props.dropdownItems : localStorageItems.value
|
|
152
|
+
return [...items].sort((a, b) => b.lastVisit - a.lastVisit)
|
|
126
153
|
})
|
|
127
154
|
|
|
128
155
|
const toggleDropdown = () => {
|
|
@@ -333,7 +360,6 @@ const handleBack = () => {
|
|
|
333
360
|
flex-direction: row;
|
|
334
361
|
align-items: center;
|
|
335
362
|
justify-content: space-between;
|
|
336
|
-
gap: var(--sky-header-actions-gap, 12px);
|
|
337
363
|
}
|
|
338
364
|
|
|
339
365
|
.btn-back {
|