diff --git a/package-lock.json b/package-lock.json index 59b0429..5680143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@sveltejs/adapter-static": "^3.0.1", "@sveltejs/kit": "^2.5.7", - "@sveltejs/package": "^2.1.0", + "@sveltejs/package": "^2.3.1", "@tailwindcss/typography": "^0.5.7", "@testing-library/svelte": "^5.1.0", "@types/lodash.clonedeep": "^4.5.7", @@ -1075,16 +1075,16 @@ } }, "node_modules/@sveltejs/package": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@sveltejs/package/-/package-2.2.5.tgz", - "integrity": "sha512-H0dFDrp7b/tr4zrUzOfqPKHG8y6ceNlGKPfSpp4ym1kTPWP79Mea5rvDlcmsbOS26FmHN/vttubalBdOCGA6qA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@sveltejs/package/-/package-2.3.1.tgz", + "integrity": "sha512-JvR2J4ost1oCn1CSdqenYRwGX/1RX+7LN+VZ71aPnz3JAlIFaEKQd1pBxlb+OSQTfeugJO0W39gB9voAbBO5ow==", "dev": true, "dependencies": { - "chokidar": "^3.5.3", + "chokidar": "^3.6.0", "kleur": "^4.1.5", "sade": "^1.8.1", "semver": "^7.5.4", - "svelte2tsx": "~0.6.27" + "svelte2tsx": "~0.7.0" }, "bin": { "svelte-package": "svelte-package.js" @@ -1093,7 +1093,7 @@ "node": "^16.14 || >=18" }, "peerDependencies": { - "svelte": "^3.44.0 || ^4.0.0" + "svelte": "^3.44.0 || ^4.0.0 || ^5.0.0-next.1" } }, "node_modules/@sveltejs/vite-plugin-svelte": { @@ -2210,16 +2210,10 @@ } }, "node_modules/chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -2232,6 +2226,9 @@ "engines": { "node": ">= 8.10.0" }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, "optionalDependencies": { "fsevents": "~2.3.2" } @@ -7224,9 +7221,9 @@ } }, "node_modules/svelte2tsx": { - "version": "0.6.27", - "resolved": "https://registry.npmjs.org/svelte2tsx/-/svelte2tsx-0.6.27.tgz", - "integrity": "sha512-E1uPW1o6VsbRz+nUk3fznZ2lSmCITAJoNu8AYefWSvIwE2pSB01i5sId4RMbWNzfcwCQl1DcgGShCPcldl4rvg==", + "version": "0.7.7", + "resolved": "https://registry.npmjs.org/svelte2tsx/-/svelte2tsx-0.7.7.tgz", + "integrity": "sha512-HAIxtk5TUHXvCRKApKfxoh1BGT85S/17lS3DvbfxRKFd+Ghr5YScqBvd+sU+p7vJFw48LNkzdFk+ooNVk3e4kA==", "dev": true, "dependencies": { "dedent-js": "^1.0.1", diff --git a/package.json b/package.json index fb27d91..bc941c9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "devDependencies": { "@sveltejs/adapter-static": "^3.0.1", "@sveltejs/kit": "^2.5.7", - "@sveltejs/package": "^2.1.0", + "@sveltejs/package": "^2.3.1", "@tailwindcss/typography": "^0.5.7", "@testing-library/svelte": "^5.1.0", "@types/lodash.clonedeep": "^4.5.7", diff --git a/src/lib/Arc.svelte b/src/lib/Arc.svelte index 653b18d..b8b1aac 100644 --- a/src/lib/Arc.svelte +++ b/src/lib/Arc.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arc.html), [ let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Arc(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Arc(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Arrow.svelte b/src/lib/Arrow.svelte index c698d49..f881a56 100644 --- a/src/lib/Arrow.svelte +++ b/src/lib/Arrow.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arrow.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Arrow(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Arrow(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Circle.svelte b/src/lib/Circle.svelte index 8bc8907..6627aba 100644 --- a/src/lib/Circle.svelte +++ b/src/lib/Circle.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Circle.html) let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Circle(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Circle(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Ellipse.svelte b/src/lib/Ellipse.svelte index 4436ca7..af2328c 100644 --- a/src/lib/Ellipse.svelte +++ b/src/lib/Ellipse.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ellipse.html let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Ellipse(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Ellipse(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Group.svelte b/src/lib/Group.svelte index ebe623e..37c2048 100644 --- a/src/lib/Group.svelte +++ b/src/lib/Group.svelte @@ -36,42 +36,45 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Group.html), children, config = $bindable({}), staticConfig = false, + handle = $bindable(), ...eventHooks - }: PropsContainer = $props(); + }: PropsContainer = $props(); - export const handle = new Konva.Group(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Group(config); + handle = _handle; const inner = writable(null); let isReady = $state(false); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); const parent: Writable = getParentContainer(); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); - inner.set(handle); + inner.set(_handle); isReady = true; }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); setContainerContext(Container.Group, inner); diff --git a/src/lib/Image.svelte b/src/lib/Image.svelte index 91518f1..c6a1a22 100644 --- a/src/lib/Image.svelte +++ b/src/lib/Image.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Image.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Image(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Image(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Label.svelte b/src/lib/Label.svelte index b422e7d..8c3e32d 100644 --- a/src/lib/Label.svelte +++ b/src/lib/Label.svelte @@ -37,42 +37,45 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Label.html), children, config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: PropsContainer = $props(); + }: PropsContainer = $props(); - export const handle = new Konva.Label(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Label(config); + handle = _handle; const inner = writable(null); let isReady = $state(false); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); const parent: Writable = getParentContainer(); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); - inner.set(handle); + inner.set(_handle); isReady = true; }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); setContainerContext(Container.Label, inner); diff --git a/src/lib/Layer.svelte b/src/lib/Layer.svelte index a12f30c..a7f11b1 100644 --- a/src/lib/Layer.svelte +++ b/src/lib/Layer.svelte @@ -33,44 +33,45 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Layer.html), children, config = $bindable({}), staticConfig = false, + handle = $bindable(), ...eventHooks - }: PropsContainer = $props(); + }: PropsContainer = $props(); - export const handle = new Konva.Layer(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Layer(config); + handle = _handle; const inner = writable(null); let isReady = $state(false); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); let parent: Writable = getParentStage(); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); - inner.set(handle); + inner.set(_handle); isReady = true; }); onDestroy(() => { - if (handle) { - handle.destroy(); - } + _handle.destroy(); }); setContainerContext(Container.Layer, inner); diff --git a/src/lib/Line.svelte b/src/lib/Line.svelte index c0ea819..79d5d8b 100644 --- a/src/lib/Line.svelte +++ b/src/lib/Line.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Line.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Line(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Line(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Path.svelte b/src/lib/Path.svelte index 12c8794..019d141 100644 --- a/src/lib/Path.svelte +++ b/src/lib/Path.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Path.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Path(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Path(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Rect.svelte b/src/lib/Rect.svelte index bb9721a..2bc3c21 100644 --- a/src/lib/Rect.svelte +++ b/src/lib/Rect.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Rect.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Rect(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Rect(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/RegularPolygon.svelte b/src/lib/RegularPolygon.svelte index 9f670b0..3f1cf8d 100644 --- a/src/lib/RegularPolygon.svelte +++ b/src/lib/RegularPolygon.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.RegularPolyg let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.RegularPolygon(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.RegularPolygon(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Ring.svelte b/src/lib/Ring.svelte index 0ccb6b5..c3a7194 100644 --- a/src/lib/Ring.svelte +++ b/src/lib/Ring.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ring.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Ring(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Ring(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Shape.svelte b/src/lib/Shape.svelte index 2a7c46b..658cdbd 100644 --- a/src/lib/Shape.svelte +++ b/src/lib/Shape.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Shape.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Shape(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Shape(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Sprite.svelte b/src/lib/Sprite.svelte index 096b714..36154e8 100644 --- a/src/lib/Sprite.svelte +++ b/src/lib/Sprite.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Sprite.html) let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Sprite(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Sprite(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Stage.svelte b/src/lib/Stage.svelte index 7bcc194..339ac26 100644 --- a/src/lib/Stage.svelte +++ b/src/lib/Stage.svelte @@ -29,8 +29,8 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Stage.html), let { children, config = $bindable(), - handle = $bindable(), staticConfig = false, + handle = $bindable(), ...restProps }: StageProps = $props(); handle = null; // A bit of a workaround as bindings on fallback values are disallowed in runes mode (https://github.com/sveltejs/svelte/issues/9764) diff --git a/src/lib/Star.svelte b/src/lib/Star.svelte index b642df6..c412646 100644 --- a/src/lib/Star.svelte +++ b/src/lib/Star.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Star.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Star(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Star(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Tag.svelte b/src/lib/Tag.svelte index 550ec9a..1bb8f65 100644 --- a/src/lib/Tag.svelte +++ b/src/lib/Tag.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Tag.html), [ let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Tag(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Tag(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Text.svelte b/src/lib/Text.svelte index 74ad1bf..986d418 100644 --- a/src/lib/Text.svelte +++ b/src/lib/Text.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Text.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Text(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Text(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/TextPath.svelte b/src/lib/TextPath.svelte index 44c45fe..8c5c050 100644 --- a/src/lib/TextPath.svelte +++ b/src/lib/TextPath.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.TextPath.htm let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.TextPath(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.TextPath(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Transformer.svelte b/src/lib/Transformer.svelte index 191c2e0..22d45dd 100644 --- a/src/lib/Transformer.svelte +++ b/src/lib/Transformer.svelte @@ -35,34 +35,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Transformer. let { config = $bindable({}), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Transformer(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Transformer(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/Wedge.svelte b/src/lib/Wedge.svelte index 93e48be..1e7fdc4 100644 --- a/src/lib/Wedge.svelte +++ b/src/lib/Wedge.svelte @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Wedge.html), let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.Wedge(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.Wedge(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); }); diff --git a/src/lib/util/props.ts b/src/lib/util/props.ts index b6a65ea..4fac746 100644 --- a/src/lib/util/props.ts +++ b/src/lib/util/props.ts @@ -1,26 +1,26 @@ import type Konva from 'konva'; -import type { Bindable, Snippet } from 'svelte'; +import type { Bindable, Binding, Snippet } from 'svelte'; import { type KonvaEventHooks } from '$lib/util/events'; /** * Shared props type used on all svelte-konva components */ -export type Props = { +export type Props = { config: Config; staticConfig?: boolean; + handle?: Node; } & KonvaEventHooks; /** * Props extension for konva container types which can hold more konva nodes */ -export interface PropsContainer extends Props { +export interface PropsContainer extends Props { children?: Snippet; } /** * Special props extension for svelte-konva Stage (Forwards rest props to canvas div container) */ -export interface StageProps extends PropsContainer { - readonly handle?: null | Konva.Stage; +export interface StageProps extends PropsContainer { [key: string]: any; } diff --git a/src/templates/svelteKonvaComponent.hbs b/src/templates/svelteKonvaComponent.hbs index d0db478..a98db8d 100644 --- a/src/templates/svelteKonvaComponent.hbs +++ b/src/templates/svelteKonvaComponent.hbs @@ -30,34 +30,37 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.{{ component let { config = $bindable(), staticConfig = false, + handle = $bindable(), ...eventHooks - }: Props = $props(); + }: Props = $props(); - export const handle = new Konva.{{ componentName }}(config); + // Hide inner handle behind a shadow variable to prevent users from overwriting it + const _handle = new Konva.{{ componentName }}(config); + handle = _handle; const parent: Writable = getParentContainer(); $effect(() => { - handle.setAttrs(config); + _handle.setAttrs(config); }); onMount(() => { - $parent!.add(handle); + $parent!.add(_handle); if (!staticConfig) { - handle.on('transformend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('transformend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); - handle.on('dragend', () => { - copyExistingKeys(config, handle.getAttrs()); + _handle.on('dragend', () => { + copyExistingKeys(config, _handle.getAttrs()); }); } - registerEvents(eventHooks, handle); + registerEvents(eventHooks, _handle); }); onDestroy(() => { - handle.destroy(); + _handle.destroy(); });