mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 17:46:56 +03:00
added copy to clipboard functionality to Tree, in Actions and State tab, updates permissions, copy to clipboard, chrome, edge, firefox
This commit is contained in:
parent
3b7bca2dbb
commit
8fe79d2eb9
|
@ -61,7 +61,9 @@
|
||||||
"storage",
|
"storage",
|
||||||
"file:///*",
|
"file:///*",
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*"
|
"https://*/*",
|
||||||
|
"clipboardWrite",
|
||||||
|
"clipboardRead"
|
||||||
],
|
],
|
||||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;",
|
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;",
|
||||||
"update_url": "https://clients2.google.com/service/update2/crx",
|
"update_url": "https://clients2.google.com/service/update2/crx",
|
||||||
|
|
|
@ -61,7 +61,9 @@
|
||||||
"storage",
|
"storage",
|
||||||
"file:///*",
|
"file:///*",
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*"
|
"https://*/*",
|
||||||
|
"clipboardWrite",
|
||||||
|
"clipboardRead"
|
||||||
],
|
],
|
||||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;"
|
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;"
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,9 @@
|
||||||
"storage",
|
"storage",
|
||||||
"file:///*",
|
"file:///*",
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*"
|
"https://*/*",
|
||||||
|
"clipboardWrite",
|
||||||
|
"clipboardRead"
|
||||||
],
|
],
|
||||||
"content_security_policy": "script-src 'self'; object-src 'self'; img-src 'self' data:;"
|
"content_security_policy": "script-src 'self'; object-src 'self'; img-src 'self' data:;"
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"immutable": "^4.3.5",
|
"immutable": "^4.3.5",
|
||||||
"javascript-stringify": "^2.1.0",
|
"javascript-stringify": "^2.1.0",
|
||||||
"jsondiffpatch": "^0.6.0",
|
"jsondiffpatch": "^0.6.0",
|
||||||
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"react-base16-styling": "^0.9.1",
|
"react-base16-styling": "^0.9.1",
|
||||||
"react-json-tree": "^0.18.0",
|
"react-json-tree": "^0.18.0",
|
||||||
|
@ -66,6 +67,7 @@
|
||||||
"@types/dateformat": "^5.0.2",
|
"@types/dateformat": "^5.0.2",
|
||||||
"@types/hex-rgba": "^1.0.3",
|
"@types/hex-rgba": "^1.0.3",
|
||||||
"@types/history": "^4.7.11",
|
"@types/history": "^4.7.11",
|
||||||
|
"@types/lodash.clonedeep": "^4.5.9",
|
||||||
"@types/lodash.debounce": "^4.0.9",
|
"@types/lodash.debounce": "^4.0.9",
|
||||||
"@types/react": "^18.2.58",
|
"@types/react": "^18.2.58",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
|
|
|
@ -10,6 +10,8 @@ import ActionPreviewHeader from './ActionPreviewHeader';
|
||||||
import DiffTab from './tabs/DiffTab';
|
import DiffTab from './tabs/DiffTab';
|
||||||
import StateTab from './tabs/StateTab';
|
import StateTab from './tabs/StateTab';
|
||||||
import ActionTab from './tabs/ActionTab';
|
import ActionTab from './tabs/ActionTab';
|
||||||
|
import { getValueByPath } from './utils/getValueByPath';
|
||||||
|
import { copyToClipboard } from './utils/copyToClipboard';
|
||||||
|
|
||||||
export interface TabComponentProps<S, A extends Action<string>> {
|
export interface TabComponentProps<S, A extends Action<string>> {
|
||||||
labelRenderer: LabelRenderer;
|
labelRenderer: LabelRenderer;
|
||||||
|
@ -184,7 +186,7 @@ class ActionPreview<S, A extends Action<string>> extends Component<
|
||||||
|
|
||||||
labelRenderer: LabelRenderer = ([key, ...rest], nodeType, expanded) => {
|
labelRenderer: LabelRenderer = ([key, ...rest], nodeType, expanded) => {
|
||||||
const { onInspectPath, inspectedPath } = this.props;
|
const { onInspectPath, inspectedPath } = this.props;
|
||||||
|
const reversedPath = [key, ...rest].reverse();
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<span>{key}</span>
|
<span>{key}</span>
|
||||||
|
@ -202,11 +204,38 @@ class ActionPreview<S, A extends Action<string>> extends Component<
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onInspectPath([
|
onInspectPath([
|
||||||
...inspectedPath.slice(0, inspectedPath.length - 1),
|
...inspectedPath.slice(0, inspectedPath.length - 1),
|
||||||
...[key, ...rest].reverse(),
|
...reversedPath,
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{'(pin)'}
|
{'(pin)'}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
css={(theme) => ({
|
||||||
|
fontSize: '0.7em',
|
||||||
|
paddingLeft: '5px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
'&:hover': {
|
||||||
|
textDecoration: 'underline',
|
||||||
|
},
|
||||||
|
color: theme.PIN_COLOR,
|
||||||
|
})}
|
||||||
|
onClick={event => {
|
||||||
|
event.stopPropagation();
|
||||||
|
let objectForCopying;
|
||||||
|
if (this.props.tabName === 'Action') {
|
||||||
|
objectForCopying = getValueByPath(this.props.action, reversedPath);
|
||||||
|
} else if (this.props.tabName === 'State') {
|
||||||
|
objectForCopying = getValueByPath(this.props.nextState, reversedPath);
|
||||||
|
}
|
||||||
|
if (objectForCopying !== undefined) {
|
||||||
|
copyToClipboard(objectForCopying);
|
||||||
|
} else {
|
||||||
|
console.error('Unable to find the object to copy');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{'(copy)'}
|
||||||
</span>
|
</span>
|
||||||
{!expanded && ': '}
|
{!expanded && ': '}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import cloneDeep from 'lodash.clonedeep';
|
||||||
|
|
||||||
|
export function copyToClipboard(object: any){
|
||||||
|
try {
|
||||||
|
const deepCopiedObject = cloneDeep(object);
|
||||||
|
const jsonString = JSON.stringify(deepCopiedObject, null, 2);
|
||||||
|
void navigator.clipboard.writeText(jsonString);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error during copy: ', err);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
export function getValueByPath(obj: any, path: (string | number)[]){
|
||||||
|
let current: any = obj;
|
||||||
|
for (let i = 0; i < path.length; i++) {
|
||||||
|
const key = path[i];
|
||||||
|
const adjustedKey = typeof key === 'string' && !isNaN(Number(key)) ? parseInt(key, 10) : key;
|
||||||
|
if (current[adjustedKey] === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
current = current[adjustedKey];
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
|
@ -1614,6 +1614,9 @@ importers:
|
||||||
jsondiffpatch:
|
jsondiffpatch:
|
||||||
specifier: ^0.6.0
|
specifier: ^0.6.0
|
||||||
version: 0.6.0
|
version: 0.6.0
|
||||||
|
lodash.clonedeep:
|
||||||
|
specifier: ^4.5.0
|
||||||
|
version: 4.5.0
|
||||||
lodash.debounce:
|
lodash.debounce:
|
||||||
specifier: ^4.0.8
|
specifier: ^4.0.8
|
||||||
version: 4.0.8
|
version: 4.0.8
|
||||||
|
@ -1669,6 +1672,9 @@ importers:
|
||||||
'@types/history':
|
'@types/history':
|
||||||
specifier: ^4.7.11
|
specifier: ^4.7.11
|
||||||
version: 4.7.11
|
version: 4.7.11
|
||||||
|
'@types/lodash.clonedeep':
|
||||||
|
specifier: ^4.5.9
|
||||||
|
version: 4.5.9
|
||||||
'@types/lodash.debounce':
|
'@types/lodash.debounce':
|
||||||
specifier: ^4.0.9
|
specifier: ^4.0.9
|
||||||
version: 4.0.9
|
version: 4.0.9
|
||||||
|
@ -10273,6 +10279,12 @@ packages:
|
||||||
'@types/lodash': 4.14.202
|
'@types/lodash': 4.14.202
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@types/lodash.clonedeep@4.5.9:
|
||||||
|
resolution: {integrity: sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==}
|
||||||
|
dependencies:
|
||||||
|
'@types/lodash': 4.14.202
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/lodash.curry@4.1.9:
|
/@types/lodash.curry@4.1.9:
|
||||||
resolution: {integrity: sha512-QV967vSflHEza0d0IMTK7fwbl+baPBXZjcESeAHrA5eSE+EHetaggZjPpkzX1NJh4qa8DLOLScwUR+f7FN85Zg==}
|
resolution: {integrity: sha512-QV967vSflHEza0d0IMTK7fwbl+baPBXZjcESeAHrA5eSE+EHetaggZjPpkzX1NJh4qa8DLOLScwUR+f7FN85Zg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -16841,6 +16853,10 @@ packages:
|
||||||
/lodash-es@4.17.21:
|
/lodash-es@4.17.21:
|
||||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
||||||
|
|
||||||
|
/lodash.clonedeep@4.5.0:
|
||||||
|
resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/lodash.curry@4.1.1:
|
/lodash.curry@4.1.1:
|
||||||
resolution: {integrity: sha512-/u14pXGviLaweY5JI0IUzgzF2J6Ne8INyzAZjImcryjgkZ+ebruBxy2/JaOOkTqScddcYtakjhSaeemV8lR0tA==}
|
resolution: {integrity: sha512-/u14pXGviLaweY5JI0IUzgzF2J6Ne8INyzAZjImcryjgkZ+ebruBxy2/JaOOkTqScddcYtakjhSaeemV8lR0tA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
Loading…
Reference in New Issue
Block a user