Copy as JSON in JSON tab

This commit is contained in:
Jan Prochazka
2022-07-31 08:10:19 +02:00
parent 88f522084d
commit 27b2fdb507
2 changed files with 14 additions and 2 deletions

View File

@@ -23,4 +23,5 @@
label={labelOverride || `${nodeType} `}
bracketOpen={'{'}
bracketClose={'}'}
elementValue={value}
/>

View File

@@ -4,6 +4,7 @@
import contextMenu, { getContextMenu } from '../utility/contextMenu';
import openNewTab from '../utility/openNewTab';
import _ from 'lodash';
import { copyTextToClipboard } from '../utility/clipboard';
setContext('json-tree-context-key', {});
@@ -34,8 +35,17 @@
if (!closest) return;
const value = elementData.get(closest);
const res = [];
res.push({
text: 'Copy JSON',
onClick: () => {
copyTextToClipboard(JSON.stringify(value, null, 2));
},
});
if (value && _.isArray(value)) {
return {
res.push({
text: 'Open as data sheet',
onClick: () => {
openNewTab(
@@ -53,8 +63,9 @@
}
);
},
};
});
}
return res;
}
</script>