diff --git a/manifest.ts b/manifest.ts
index f9a96b7..f23eb19 100755
--- a/manifest.ts
+++ b/manifest.ts
@@ -8,6 +8,7 @@ const manifest: chrome.runtime.ManifestV3 = {
name: "KonvaJS Devtools",
version: packageJson.version,
description: packageJson.description,
+ permissions: ["storage"],
// options_page: "src/pages/options/index.html",
background: {
service_worker: "src/pages/background/index.js",
diff --git a/package.json b/package.json
index c14126d..f53a15f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "konva-inspector",
- "version": "0.0.4",
+ "version": "0.0.6",
"description": "Devtools for your Konva App",
"license": "MIT",
"repository": {
diff --git a/src/pages/content/index.ts b/src/pages/content/index.ts
index 5b29209..89c9ded 100644
--- a/src/pages/content/index.ts
+++ b/src/pages/content/index.ts
@@ -1,9 +1,7 @@
-let lastResult = false;
-
detect();
const interval = setInterval(detect, 5000);
-function detect() {
+function detect(requestDetectionCallback?: (data: any) => void) {
try {
const s = document.createElement("script");
s.src = chrome.runtime.getURL("src/pages/detector/index.js");
@@ -12,13 +10,12 @@ function detect() {
document.addEventListener(
"__KONVA_DEVTOOLS__DETECTION_RESULT",
function (e: CustomEvent) {
- lastResult = e.detail;
-
chrome.runtime.sendMessage({
type: "__KONVA_DEVTOOLS__BROADCAST_RESULT",
- result: lastResult,
+ result: e.detail,
});
s.remove();
+ requestDetectionCallback && requestDetectionCallback(e.detail);
}
);
@@ -32,7 +29,7 @@ function detect() {
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request["type"] == "__KONVA_DEVTOOLS__REQUEST_DETECTION") {
- sendResponse(lastResult);
+ detect(sendResponse);
}
return true; // this make sure sendResponse will work asynchronously
});
diff --git a/src/pages/panel/components/Element.tsx b/src/pages/panel/components/Element.tsx
index ab932f8..86a80f9 100644
--- a/src/pages/panel/components/Element.tsx
+++ b/src/pages/panel/components/Element.tsx
@@ -7,6 +7,7 @@ import { bridge } from "..";
interface IProps {
searchText: string;
selectedNode: OutlineNode | null;
+ activeNode: OutlineNode | null;
stageIndex: number;
indent: number;
node: OutlineNode;
@@ -16,6 +17,7 @@ interface IProps {
export default function Element({
searchText,
selectedNode,
+ activeNode,
stageIndex,
indent,
node,
@@ -41,20 +43,21 @@ export default function Element({
return (
<>
{
const data = await bridge
(
- `__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.select(${node._id}, ${stageIndex})`
+ `window.__KONVA_DEVTOOLS_GLOBAL_HOOK__ && window.__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.select(${node._id}, ${stageIndex})`
);
onSelectNode(data);
}}
onMouseEnter={() => {
bridge(
- `__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.activate(${node._id}, ${stageIndex})`
+ `window.__KONVA_DEVTOOLS_GLOBAL_HOOK__ && window.__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.activate(${node._id}, ${stageIndex})`
);
}}
>
@@ -78,6 +81,7 @@ export default function Element({
key={item._id}
searchText={searchText}
selectedNode={selectedNode}
+ activeNode={activeNode}
stageIndex={stageIndex}
indent={indent + 1}
node={item}
diff --git a/src/pages/panel/components/InspectedElement.tsx b/src/pages/panel/components/InspectedElement.tsx
index 6ab5c23..53306e4 100644
--- a/src/pages/panel/components/InspectedElement.tsx
+++ b/src/pages/panel/components/InspectedElement.tsx
@@ -26,9 +26,11 @@ export default function InspectedElement({ selectedNode }: IProps) {
const updateAttr = async (attrName: string, val: any) => {
await bridge(
- `__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.updateAttrs(${JSON.stringify({
- [attrName]: val,
- })})`
+ `window.__KONVA_DEVTOOLS_GLOBAL_HOOK__ && window.__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.updateAttrs(${JSON.stringify(
+ {
+ [attrName]: val,
+ }
+ )})`
);
setNodeAttrs((current) => ({
...current,
@@ -38,6 +40,12 @@ export default function InspectedElement({ selectedNode }: IProps) {
const attrs = selectedNode?.isShape ? SHAPE_ATTRS : ATTRS;
+ const copyToClipBoard = () => {
+ bridge(
+ `window.copy(window.__KONVA_DEVTOOLS_GLOBAL_HOOK__ && window.__KONVA_DEVTOOLS_GLOBAL_HOOK__.selection.selected().attrs)`
+ );
+ };
+
return (
<>
@@ -54,7 +62,11 @@ export default function InspectedElement({ selectedNode }: IProps) {
Attributes
-