File tree Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -56,15 +56,23 @@ export function savePref (key, value) {
56
56
localStorage . setItem ( PREF_KEY , JSON . stringify ( pref ) )
57
57
}
58
58
59
+ function urlBtoA ( binary ) {
60
+ return btoa ( binary ) . replace ( / \+ / g, '-' ) . replace ( / \/ / g, '_' )
61
+ }
62
+
63
+ function urlAtoB ( base64 ) {
64
+ return atob ( base64 . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) )
65
+ }
66
+
59
67
export function utoa ( data ) {
60
68
const buffer = strToU8 ( data )
61
69
const zipped = zlibSync ( buffer , { level : 9 } )
62
70
const binary = strFromU8 ( zipped , true )
63
- return btoa ( binary )
71
+ return urlBtoA ( binary )
64
72
}
65
73
66
74
export function atou ( base64 ) {
67
- const binary = atob ( base64 )
75
+ const binary = urlAtoB ( base64 )
68
76
69
77
// zlib header (x78), level 9 (xDA)
70
78
if ( binary . startsWith ( '\x78\xDA' ) ) {
Original file line number Diff line number Diff line change 30
30
<slot name =" desc" />
31
31
</section >
32
32
<section class =" actions" >
33
+ <veui-button
34
+ v-tooltip =" t('playInPlayground')"
35
+ ui =" icon"
36
+ @click =" play('VEUI')"
37
+ >
38
+ <veui-icon name =" external-link" />
39
+ </veui-button >
33
40
<veui-button
34
41
v-tooltip =" t('playInCodeSandbox')"
35
42
ui =" icon"
@@ -129,6 +136,7 @@ import OneEditLink from './OneEditLink'
129
136
import OneRepl from ' ./OneRepl'
130
137
import OneFocus from ' ./OneFocus'
131
138
import ' veui-theme-dls-icons/copy'
139
+ import ' veui-theme-dls-icons/external-link'
132
140
133
141
Vue .use (toast)
134
142
@@ -194,11 +202,6 @@ export default {
194
202
track (' play' , { vendor, path: this .path })
195
203
},
196
204
trackCopy (action ) {
197
- if (this .copied ) {
198
- return
199
- }
200
-
201
- this .copied = true
202
205
track (' copy' , { from: ' demo' , path: this .path , action })
203
206
},
204
207
async copy () {
Original file line number Diff line number Diff line change @@ -41,20 +41,22 @@ export default {
41
41
methods: {
42
42
deserialize () {
43
43
try {
44
- const stringified = atou (location .hash .slice (1 ))
45
- const { code , theme } = stringified ? JSON .parse (stringified ) : {}
44
+ const hash = atou (location .hash .slice (1 ))
45
+ const { code , theme } = hash ? JSON .parse (hash ) : {}
46
46
this .code = code || ' '
47
47
config .value .theme = theme || ' '
48
48
} catch (e) {
49
49
console .error (e)
50
50
}
51
51
},
52
52
serialize () {
53
- history .replaceState (
54
- {},
55
- ' ' ,
56
- ` #${ utoa (JSON .stringify ({ code: this .code , theme: config .value .theme || undefined }))} `
53
+ const hash = utoa (
54
+ JSON .stringify ({
55
+ code: this .code ,
56
+ theme: config .value .theme || undefined
57
+ })
57
58
)
59
+ history .replaceState ({}, ' ' , ` #${ hash} ` )
58
60
},
59
61
handleCodeChange (code ) {
60
62
this .code = code
You can’t perform that action at this time.
0 commit comments