Skip to content

Commit

Permalink
Update SvelteKit & prettier plugin, Mark bindable props as bindable, …
Browse files Browse the repository at this point in the history
…Make container nodes accept children and switch from slot to @render blocks
  • Loading branch information
TeyKey1 committed Apr 24, 2024
1 parent be572b9 commit d1d28f5
Show file tree
Hide file tree
Showing 33 changed files with 98 additions and 62 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.0.4",
"@sveltejs/kit": "^2.5.7",
"@sveltejs/package": "^2.1.0",
"@tailwindcss/typography": "^0.5.7",
"@testing-library/svelte": "^5.1.0",
Expand All @@ -61,7 +61,7 @@
"lodash.clonedeep": "^4.5.0",
"plop": "^4.0.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-svelte": "^3.2.3",
"svelte": "5.0.0-next.114",
"svelte-check": "^3.6.9",
"svelte-highlight": "^7.3.0",
Expand Down Expand Up @@ -269,4 +269,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion src/lib/Arc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arc.html), [
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.ArcConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.ArcConfig> = $props();
export const handle = new Konva.Arc(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Arrow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Arrow.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.ArrowConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.ArrowConfig> = $props();
export const handle = new Konva.Arrow(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Circle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Circle.html)
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.CircleConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.CircleConfig> = $props();
export const handle = new Konva.Circle(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Ellipse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ellipse.html
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.EllipseConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.EllipseConfig> = $props();
export const handle = new Konva.Ellipse(config);
Expand Down
12 changes: 8 additions & 4 deletions src/lib/Group.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Group.html),
} from '$lib/util/manageContext';
import { registerEvents, type KonvaEvents } from '$lib/util/events';
import { copyExistingKeys } from '$lib/util/object';
import { type Props } from '$lib/util/props';
import { type PropsContainer } from '$lib/util/props';
interface $$Events extends KonvaEvents {}
let { config = {}, staticConfig = false }: Props<Konva.GroupConfig | undefined> = $props();
let {
children,
config = $bindable({}),
staticConfig = false
}: PropsContainer<Konva.GroupConfig | undefined> = $props();
export const handle = new Konva.Group(config);
Expand Down Expand Up @@ -76,6 +80,6 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Group.html),
setContainerContext(Container.Group, inner);
</script>

{#if isReady}
<slot />
{#if isReady && children}
{@render children()}
{/if}
2 changes: 1 addition & 1 deletion src/lib/Image.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Image.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.ImageConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.ImageConfig> = $props();
export const handle = new Konva.Image(config);
Expand Down
12 changes: 8 additions & 4 deletions src/lib/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Label.html),
type KonvaParent
} from '$lib/util/manageContext';
import { registerEvents, type KonvaEvents } from '$lib/util/events';
import { type Props } from '$lib/util/props';
import { type PropsContainer } from '$lib/util/props';
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.LabelConfig> = $props();
let {
children,
config = $bindable(),
staticConfig = false
}: PropsContainer<Konva.LabelConfig> = $props();
export const handle = new Konva.Label(config);
Expand Down Expand Up @@ -77,6 +81,6 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Label.html),
setContainerContext(Container.Label, inner);
</script>

{#if isReady}
<slot />
{#if isReady && children}
{@render children()}
{/if}
12 changes: 8 additions & 4 deletions src/lib/Layer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Layer.html),
import { Container, getParentStage, setContainerContext } from '$lib/util/manageContext';
import { registerEvents, type KonvaEvents } from '$lib/util/events';
import { copyExistingKeys } from '$lib/util/object';
import { type Props } from '$lib/util/props';
import { type PropsContainer } from '$lib/util/props';
interface $$Events extends KonvaEvents {}
let { config = {}, staticConfig = false }: Props<Konva.LayerConfig | undefined> = $props();
let {
children,
config = $bindable({}),
staticConfig = false
}: PropsContainer<Konva.LayerConfig | undefined> = $props();
export const handle = new Konva.Layer(config);
Expand Down Expand Up @@ -75,6 +79,6 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Layer.html),
setContainerContext(Container.Layer, inner);
</script>

{#if isReady}
<slot />
{#if isReady && children}
{@render children()}
{/if}
2 changes: 1 addition & 1 deletion src/lib/Line.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Line.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.LineConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.LineConfig> = $props();
export const handle = new Konva.Line(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Path.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Path.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.PathConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.PathConfig> = $props();
export const handle = new Konva.Path(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Rect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Rect.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.RectConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.RectConfig> = $props();
export const handle = new Konva.Rect(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/RegularPolygon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.RegularPolyg
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.RegularPolygonConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.RegularPolygonConfig> = $props();
export const handle = new Konva.RegularPolygon(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Ring.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Ring.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.RingConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.RingConfig> = $props();
export const handle = new Konva.Ring(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Shape.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Shape.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.ShapeConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.ShapeConfig> = $props();
export const handle = new Konva.Shape(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Sprite.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Sprite.html)
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.SpriteConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.SpriteConfig> = $props();
export const handle = new Konva.Sprite(config);
Expand Down
12 changes: 9 additions & 3 deletions src/lib/Stage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Stage.html),
interface $$Events extends KonvaEvents {}
let { config, handle, staticConfig = false, ...restProps }: StageProps = $props();
let {
children,
config = $bindable(),
handle = $bindable(),
staticConfig = false,
...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)
let _handle: Konva.Stage | null = null; // Hide inner handle behind a shadow variable to prevent users from overwriting it
Expand Down Expand Up @@ -74,7 +80,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Stage.html),
</script>

<div bind:this={stage} {...restProps}>
{#if isReady}
<slot />
{#if isReady && children}
{@render children()}
{/if}
</div>
2 changes: 1 addition & 1 deletion src/lib/Star.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Star.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.StarConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.StarConfig> = $props();
export const handle = new Konva.Star(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Tag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Tag.html), [
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.TagConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.TagConfig> = $props();
export const handle = new Konva.Tag(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Text.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.TextConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.TextConfig> = $props();
export const handle = new Konva.Text(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/TextPath.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.TextPath.htm
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.TextPathConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.TextPathConfig> = $props();
export const handle = new Konva.TextPath(config);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Transformer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Transformer.
interface $$Events extends KonvaEvents {}
let { config = {}, staticConfig = false }: Props<Konva.TransformerConfig | undefined> = $props();
let { config = $bindable({}), staticConfig = false }: Props<Konva.TransformerConfig | undefined> =
$props();
export const handle = new Konva.Transformer(config);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Wedge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Further information: [Konva API docs](https://konvajs.org/api/Konva.Wedge.html),
interface $$Events extends KonvaEvents {}
let { config, staticConfig = false }: Props<Konva.WedgeConfig> = $props();
let { config = $bindable(), staticConfig = false }: Props<Konva.WedgeConfig> = $props();
export const handle = new Konva.Wedge(config);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/util/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type Konva from 'konva';
import type { Bindable, Snippet } from 'svelte';

/**
* Shared props type used on all svelte-konva components
Expand All @@ -8,10 +9,17 @@ export type Props<Config> = {
staticConfig?: boolean;
};

/**
* Props extension for konva container types which can hold more konva nodes
*/
export interface PropsContainer<Config> extends Props<Config> {
children?: Snippet;
}

/**
* Special props extension for svelte-konva Stage (Forwards rest props to canvas div container)
*/
export interface StageProps extends Props<Konva.ContainerConfig> {
export interface StageProps extends PropsContainer<Konva.ContainerConfig> {
readonly handle?: null | Konva.Stage;
[key: string]: any;
}
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</div>
</div>
<div class="drawer-side shadow">
<label for="my-drawer-2" class="drawer-overlay" />
<label for="my-drawer-2" class="drawer-overlay"></label>
<ul class="menu menu-compact p-4 overflow-y-auto w-80 bg-base-200 text-base-content h-full">
<!-- Sidebar content here -->
<li>
Expand Down
Loading

0 comments on commit d1d28f5

Please sign in to comment.