vue-stack-tabs 0.1.37 → 0.1.39

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.
@@ -1,70 +1,70 @@
1
- import type { ITabBase } from '../model/TabModel'
2
- import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from 'lz-string'
3
- import Hex from 'hex-encoding'
4
- import { blake3 } from '@noble/hashes/blake3'
5
-
6
- /**
7
- * compress tab info to string
8
- * format:
9
- * {tab id}{current timestamp}{tab name}{tab closable}
10
- * @param tabData
11
- */
12
- export const encodeTabInfo = (tabData: ITabBase): string => {
13
- // const info: ITabBase = {
14
- // id: tabData.id,
15
- // title: tabData.title,
16
- // iframe: tabData.iframe,
17
- // closable: tabData.closable,
18
- // refreshable: tabData.refreshable
19
- // }
20
- const info = `${tabData.id}|${tabData.title}|${tabData.iframe ? 'Y' : 'N'}|${tabData.closable ? 'Y' : 'N'}|${tabData.refreshable ? 'Y' : 'N'}`
21
- return compressToEncodedURIComponent(info)
22
- // const compressed = await compress(new TextEncoder().encode(info))
23
- // return fromUint8Array(compressed, true)
24
- // return compressToEncodedURIComponent(
25
- // `${tabData.id}|${tabData.title}|${tabData.iframe ? 'Y' : 'N'}|${tabData.closable ? 'Y' : 'N'}|${tabData.refreshable ? 'Y' : 'N'}`
26
- // )
27
- }
28
-
29
- export const decodeTabInfo = (tab: string): ITabBase => {
30
- // const decompressed = await decompress(toUint8Array(tab))
31
- const tabString = decompressFromEncodedURIComponent(tab)
32
- // const tabString = new TextDecoder().decode(decompressed)
33
- // return JSON.parse(new TextDecoder().decode(decompressed))
34
- // const tabString = decompressFromEncodedURIComponent(tab)
35
- const tabValues: string[] = tabString.split('|')
36
- return {
37
- id: tabValues[0],
38
- title: tabValues[1],
39
- iframe: tabValues[2] === 'Y',
40
- closable: tabValues[3] === 'Y',
41
- refreshable: tabValues[4] === 'Y'
42
- }
43
- }
44
-
45
- export const createPageId = (tabId: string, path: string, query: Object): string => {
46
- const queryArray = []
47
- console.log(query)
48
- type ObjectKey = keyof typeof query
49
- for (const key in query) {
50
- if (!key.startsWith('__')) {
51
- queryArray.push({
52
- key,
53
- value: query[key as ObjectKey]
54
- })
55
- }
56
- }
57
- queryArray.sort((a, b) => {
58
- let result = 0
59
- if (a.key > b.key) {
60
- result = 1
61
- } else if (a.key < b.key) {
62
- result = -1
63
- }
64
- return result
65
- })
66
- const hash = blake3(`${tabId}|${path}|${JSON.stringify(queryArray)}`)
67
- return Hex.encode(hash)
68
- // return uuidv5(`${tabId}|${path}|${JSON.stringify(queryArray)}`, uuidv5.URL).replaceAll('-', '')
69
- // return await blake3(`${tabId}|${path}|${JSON.stringify(queryArray)}`)
70
- }
1
+ import type { ITabBase } from '../model/TabModel'
2
+ import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from 'lz-string'
3
+ import Hex from 'hex-encoding'
4
+ import { blake3 } from '@noble/hashes/blake3'
5
+
6
+ /**
7
+ * compress tab info to string
8
+ * format:
9
+ * {tab id}{current timestamp}{tab name}{tab closable}
10
+ * @param tabData
11
+ */
12
+ export const encodeTabInfo = (tabData: ITabBase): string => {
13
+ // const info: ITabBase = {
14
+ // id: tabData.id,
15
+ // title: tabData.title,
16
+ // iframe: tabData.iframe,
17
+ // closable: tabData.closable,
18
+ // refreshable: tabData.refreshable
19
+ // }
20
+ const info = `${tabData.id}|${tabData.title}|${tabData.iframe ? 'Y' : 'N'}|${tabData.closable ? 'Y' : 'N'}|${tabData.refreshable ? 'Y' : 'N'}`
21
+ return compressToEncodedURIComponent(info)
22
+ // const compressed = await compress(new TextEncoder().encode(info))
23
+ // return fromUint8Array(compressed, true)
24
+ // return compressToEncodedURIComponent(
25
+ // `${tabData.id}|${tabData.title}|${tabData.iframe ? 'Y' : 'N'}|${tabData.closable ? 'Y' : 'N'}|${tabData.refreshable ? 'Y' : 'N'}`
26
+ // )
27
+ }
28
+
29
+ export const decodeTabInfo = (tab: string): ITabBase => {
30
+ // const decompressed = await decompress(toUint8Array(tab))
31
+ const tabString = decompressFromEncodedURIComponent(tab)
32
+ // const tabString = new TextDecoder().decode(decompressed)
33
+ // return JSON.parse(new TextDecoder().decode(decompressed))
34
+ // const tabString = decompressFromEncodedURIComponent(tab)
35
+ const tabValues: string[] = tabString.split('|')
36
+ return {
37
+ id: tabValues[0],
38
+ title: tabValues[1],
39
+ iframe: tabValues[2] === 'Y',
40
+ closable: tabValues[3] === 'Y',
41
+ refreshable: tabValues[4] === 'Y'
42
+ }
43
+ }
44
+
45
+ export const createPageId = (tabId: string, path: string, query: Object): string => {
46
+ const queryArray = []
47
+ console.log(query)
48
+ type ObjectKey = keyof typeof query
49
+ for (const key in query) {
50
+ if (!key.startsWith('__')) {
51
+ queryArray.push({
52
+ key,
53
+ value: query[key as ObjectKey]
54
+ })
55
+ }
56
+ }
57
+ queryArray.sort((a, b) => {
58
+ let result = 0
59
+ if (a.key > b.key) {
60
+ result = 1
61
+ } else if (a.key < b.key) {
62
+ result = -1
63
+ }
64
+ return result
65
+ })
66
+ const hash = blake3(`${tabId}|${path}|${JSON.stringify(queryArray)}`)
67
+ return Hex.encode(hash)
68
+ // return uuidv5(`${tabId}|${path}|${JSON.stringify(queryArray)}`, uuidv5.URL).replaceAll('-', '')
69
+ // return await blake3(`${tabId}|${path}|${JSON.stringify(queryArray)}`)
70
+ }