Skip to content

Commit c314dc6

Browse files
committed
feat: improved "Copy Value"
1 parent 7a3e42f commit c314dc6

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

packages/shared-utils/src/util.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,18 @@ class ReviveCache {
174174

175175
const reviveCache = new ReviveCache(1000)
176176

177-
export function stringify (data) {
177+
const replacers = {
178+
internal: replacerForInternal,
179+
user: replaceForUser,
180+
}
181+
182+
export function stringify (data, target: keyof typeof replacers = 'internal') {
178183
// Create a fresh cache for each serialization
179184
encodeCache.clear()
180-
return stringifyCircularAutoChunks(data, replacer)
185+
return stringifyCircularAutoChunks(data, replacers[target])
181186
}
182187

183-
function replacer (key) {
188+
function replacerForInternal (key) {
184189
// @ts-ignore
185190
const val = this[key]
186191
const type = typeof val
@@ -244,6 +249,29 @@ function replacer (key) {
244249
return sanitize(val)
245250
}
246251

252+
// @TODO revive from backend to have more data to the clipboard
253+
function replaceForUser (key) {
254+
// @ts-ignore
255+
let val = this[key]
256+
const type = typeof val
257+
if (val?._custom && 'value' in val._custom) {
258+
val = val._custom.value
259+
}
260+
if (type !== 'object') {
261+
if (val === UNDEFINED) {
262+
return undefined
263+
} else if (val === INFINITY) {
264+
return Infinity
265+
} else if (val === NEGATIVE_INFINITY) {
266+
return -Infinity
267+
} else if (val === NAN) {
268+
return NaN
269+
}
270+
return val
271+
}
272+
return sanitize(val)
273+
}
274+
247275
export function getCustomMapDetails (val) {
248276
const list = []
249277
val.forEach(
@@ -706,7 +734,7 @@ export function copyToClipboard (state) {
706734
if (typeof state !== 'object') {
707735
text = String(state)
708736
} else {
709-
text = stringify(state)
737+
text = stringify(state, 'user')
710738
}
711739

712740
navigator.clipboard.writeText(text)

0 commit comments

Comments
 (0)