@skyservice-developers/vue-dev-kit 1.3.9 → 1.4.1

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.3.9",
3
+ "version": "1.4.1",
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",
@@ -108,6 +108,14 @@ export default {
108
108
  type: String,
109
109
  default: 'Останнє відвідування'
110
110
  },
111
+ trackPageName: {
112
+ type: String,
113
+ default: ''
114
+ },
115
+ trackPagePath: {
116
+ type: String,
117
+ default: ''
118
+ },
111
119
  appId: {
112
120
  type: String,
113
121
  default: ''
@@ -116,12 +124,14 @@ export default {
116
124
  data() {
117
125
  return {
118
126
  isDropdownOpen: false,
119
- previousRocketMode: null
127
+ previousRocketMode: null,
128
+ localStorageItems: []
120
129
  }
121
130
  },
122
131
  computed: {
123
132
  sortedItems() {
124
- return [...this.dropdownItems].sort((a, b) => b.lastVisit - a.lastVisit)
133
+ const items = this.dropdownItems.length ? this.dropdownItems : this.localStorageItems
134
+ return [...items].sort((a, b) => b.lastVisit - a.lastVisit)
125
135
  },
126
136
  shouldShowBackButton() {
127
137
  return this.backEvent || (this.showBackButton && isInIframe())
@@ -130,10 +140,27 @@ export default {
130
140
  created() {
131
141
  setSenderId(this.appId || getSenderId())
132
142
  if (isInIframe()) {
143
+ // Track page visit
144
+ if (this.trackPageName) {
145
+ sendToParent({
146
+ type: 'trackVisit',
147
+ name: this.trackPageName,
148
+ path: this.trackPagePath || `/${this.trackPageName}`,
149
+ })
150
+ }
151
+
152
+ // Set rocketMode
133
153
  getParentLocalStorage('rocketMode').then((value) => {
134
154
  this.previousRocketMode = value
135
155
  sendToParent({ type: 'setRocketMode', value: true })
136
156
  })
157
+
158
+ // Load componentStats from parent
159
+ getParentLocalStorage('componentStats').then((data) => {
160
+ if (data != null) {
161
+ this.loadParentComponentStats(data)
162
+ }
163
+ })
137
164
  }
138
165
  },
139
166
  mounted() {
@@ -150,9 +177,38 @@ export default {
150
177
  sendToParent({ type: 'setRocketMode', value: restore })
151
178
  }
152
179
  },
153
- handleBack() {
180
+ findPreviousPage() {
181
+ return this.sortedItems.find(item => item.name !== this.trackPageName)
182
+ },
183
+ loadParentComponentStats(data) {
184
+ try {
185
+ const parsed = typeof data === 'string' ? JSON.parse(data) : data
186
+ if (parsed?.pages) {
187
+ this.localStorageItems = Object.values(parsed.pages)
188
+ }
189
+ } catch {}
190
+ },
191
+ async handleBack() {
154
192
  if (this.backEvent) return this.backEvent()
155
193
 
194
+ // Navigate to the last visited page that isn't the current one
195
+ let previousPage = this.findPreviousPage()
196
+
197
+ // If history not loaded yet, try fetching from parent
198
+ if (!previousPage && isInIframe()) {
199
+ const data = await getParentLocalStorage('componentStats')
200
+ if (data) {
201
+ this.loadParentComponentStats(data)
202
+ previousPage = this.findPreviousPage()
203
+ }
204
+ }
205
+
206
+ if (previousPage) {
207
+ this.restoreRocketMode()
208
+ sendToParent({ type: 'navigate', path: previousPage.path })
209
+ return
210
+ }
211
+
156
212
  this.restoreRocketMode()
157
213
  sendToParent({ type: 'exit' })
158
214
  },
@@ -166,6 +222,9 @@ export default {
166
222
  },
167
223
  selectItem(item) {
168
224
  this.$emit('navigate', item.path)
225
+ if (isInIframe()) {
226
+ sendToParent({ type: 'navigate', path: item.path })
227
+ }
169
228
  this.closeDropdown()
170
229
  },
171
230
  capitalize(str) {
@@ -265,9 +265,31 @@ const restoreRocketMode = () => {
265
265
  }
266
266
  }
267
267
 
268
- const handleBack = () => {
268
+ const findPreviousPage = () => {
269
+ return sortedItems.value.find(item => item.name !== props.trackPageName)
270
+ }
271
+
272
+ const handleBack = async () => {
269
273
  if (props.backEvent) return props.backEvent()
270
274
 
275
+ // Navigate to the last visited page that isn't the current one
276
+ let previousPage = findPreviousPage()
277
+
278
+ // If history not loaded yet, try fetching from parent
279
+ if (!previousPage && isInIframe()) {
280
+ const data = await getParentLocalStorage('componentStats')
281
+ if (data) {
282
+ loadComponentStats(data)
283
+ previousPage = findPreviousPage()
284
+ }
285
+ }
286
+
287
+ if (previousPage) {
288
+ restoreRocketMode()
289
+ sendToParent({ type: 'navigate', path: previousPage.path })
290
+ return
291
+ }
292
+
271
293
  restoreRocketMode()
272
294
  sendToParent({ type: 'exit' })
273
295
  }