Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Konva node ordering based on the svelte component order #64

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/Arc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arc.html), [
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.ArcConfig;
export let handle = new Konva.Arc(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arc.html), [
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Arrow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arrow.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.ArrowConfig;
export let handle = new Konva.Arrow(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arrow.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Circle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Circle.html)
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.CircleConfig;
export let handle = new Konva.Circle(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Circle.html)
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Ellipse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ellipse.html
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.EllipseConfig;
export let handle = new Konva.Ellipse(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ellipse.html
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Image.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Image.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.ImageConfig;
export let handle = new Konva.Image(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Image.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
14 changes: 10 additions & 4 deletions src/lib/Layer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Layer.html),
-->
<script lang="ts">
import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import { type Writable, writable } from 'svelte/store';
import { Container, getParentStage, setContainerContext } from '$lib/util/manageContext';
import { registerEvents } from '$lib/util/events';
import { copyExistingKeys } from './util/copy';
import { OrderManager, getOrderManager, setOrderManagerContext } from './util/manageOrder';

export let config: Konva.LayerConfig = {};
export let handle: Konva.Layer = new Konva.Layer(config);

let inner = writable<null | Konva.Layer>(null);
let parentOrderManager = getOrderManager();
let orderManager = new OrderManager(handle);

let dispatcher = createEventDispatcher();

Expand Down Expand Up @@ -58,12 +61,15 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Layer.html),
});

onDestroy(() => {
if (handle) {
handle.destroy();
}
handle.destroy();
});

setContainerContext(Container.Layer, inner);
setOrderManagerContext(orderManager);

beforeUpdate(() => {
if (parentOrderManager) parentOrderManager.signalComponentOrder(handle);
});
</script>

{#if isReady}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Line.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Line.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.LineConfig;
export let handle = new Konva.Line(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Line.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Path.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Path.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.PathConfig;
export let handle = new Konva.Path(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Path.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Rect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Rect.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.RectConfig;
export let handle = new Konva.Rect(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Rect.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/RegularPolygon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.RegularPolyg
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.RegularPolygonConfig;
export let handle = new Konva.RegularPolygon(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.RegularPolyg
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Ring.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ring.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.RingConfig;
export let handle = new Konva.Ring(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ring.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Shape.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Shape.html),
*/

import Konva from 'konva';
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
import { onMount, onDestroy, beforeUpdate, createEventDispatcher } from 'svelte';
import type { Writable } from 'svelte/store';
import { registerEvents } from '$lib/util/events';
import { getParentContainer, type KonvaParent } from '$lib/util/manageContext';
import { copyExistingKeys } from '$lib/util/copy';
import { getOrderManager } from './util/manageOrder';

export let config: Konva.ShapeConfig;
export let handle = new Konva.Shape(config);

let parent: Writable<null | KonvaParent> = getParentContainer();
let parentOrderManager = getOrderManager();
let dispatcher = createEventDispatcher();

$: handle.setAttrs(config);
Expand All @@ -45,6 +47,10 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Shape.html),
registerEvents(dispatcher, handle);
});

beforeUpdate(() => {
parentOrderManager.signalComponentOrder(handle);
});

onDestroy(() => {
handle.destroy();
});
Expand Down
Loading