@snap-engine/snapsort-svelte 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Svelte components for SnapEngine drag-and-drop interactions.
4
4
 
5
+ `Container` and `Item` are aliases for the Euclidean
6
+ components. The explicit component pairs are available as Euclidean and
7
+ Progressive variants.
8
+
5
9
  ## Install
6
10
 
7
11
  ```bash
@@ -10,13 +14,22 @@ npm install @snap-engine/snapsort-svelte @snap-engine/snapsort
10
14
 
11
15
  ## Includes
12
16
 
13
- - `ItemContainer`
17
+ - `ContainerEuclidean`
18
+ - `ItemEuclidean`
19
+ - `ContainerProgressive`
20
+ - `ItemProgressive`
21
+ - `Container`
14
22
  - `Item`
15
23
 
16
24
  ## Usage
17
25
 
18
26
  ```svelte
19
27
  <script>
20
- import { ItemContainer, Item } from "@snap-engine/snapsort-svelte";
28
+ import {
29
+ Container,
30
+ Item,
31
+ ContainerProgressive,
32
+ ItemProgressive,
33
+ } from "@snap-engine/snapsort-svelte";
21
34
  </script>
22
- ```
35
+ ```
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@snap-engine/snapsort-svelte",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/tfukaza/SnapEngineJS",
7
+ "directory": "assets/snapsort/svelte"
8
+ },
4
9
  "description": "Svelte components for drag-and-drop system",
5
10
  "type": "module",
6
11
  "svelte": "./src/index.ts",
@@ -8,8 +13,12 @@
8
13
  ".": {
9
14
  "svelte": "./src/index.ts"
10
15
  },
11
- "./ItemContainer.svelte": "./src/ItemContainer.svelte",
12
- "./Item.svelte": "./src/Item.svelte"
16
+ "./Container.svelte": "./src/ContainerEuclidean.svelte",
17
+ "./Item.svelte": "./src/ItemEuclidean.svelte",
18
+ "./ContainerEuclidean.svelte": "./src/ContainerEuclidean.svelte",
19
+ "./ItemEuclidean.svelte": "./src/ItemEuclidean.svelte",
20
+ "./ContainerProgressive.svelte": "./src/ContainerProgressive.svelte",
21
+ "./ItemProgressive.svelte": "./src/ItemProgressive.svelte"
13
22
  },
14
23
  "keywords": [
15
24
  "drag-and-drop",
@@ -20,7 +29,7 @@
20
29
  "author": "Tomoki Fukazawa",
21
30
  "license": "MIT",
22
31
  "dependencies": {
23
- "@snap-engine/snapsort": "^0.1.0"
32
+ "@snap-engine/snapsort": "^0.3.0"
24
33
  },
25
34
  "files": [
26
35
  "src",
@@ -0,0 +1,45 @@
1
+ <script lang="ts">
2
+ import { ContainerEuclidean } from "@snap-engine/snapsort";
3
+ import type { ItemBase, ContainerConfig } from "@snap-engine/snapsort";
4
+
5
+ import { getContext, setContext, onMount, onDestroy } from "svelte";
6
+ import type { Engine } from "@snap-engine/core";
7
+
8
+ let { config, children, container = $bindable(), locked = true, className = "", metadata = {} }: { config: ContainerConfig; children: any; container?: ContainerEuclidean; locked?: boolean; className?: string; metadata?: Record<string, unknown> } =
9
+ $props();
10
+ const engine: Engine = getContext("engine");
11
+
12
+ let itemContainer: ContainerEuclidean = new ContainerEuclidean(engine, null, { ...config });
13
+ itemContainer.locked = locked;
14
+ itemContainer.metadata = metadata;
15
+ const justifyContent = $derived(config.mainAxisAlign === "center" ? "center" : "flex-start");
16
+ // If there's a parent container context, register this container as an item in it
17
+ const parent: ItemBase | null = getContext("container");
18
+ setContext("container", itemContainer);
19
+
20
+ onMount(() => {
21
+ container = itemContainer;
22
+ parent?.addItem(itemContainer);
23
+ });
24
+
25
+ onDestroy(() => {
26
+ itemContainer.destroy();
27
+ });
28
+ </script>
29
+
30
+ <div
31
+ class="snapsort-container snapsort-container-euclidean {className}"
32
+ style="flex-direction: {config.direction}; justify-content: {justifyContent}"
33
+ bind:this={itemContainer.element}
34
+ >
35
+ {@render children?.()}
36
+ </div>
37
+
38
+ <style>
39
+ .snapsort-container {
40
+ position: relative;
41
+ display: flex;
42
+ flex-wrap: wrap;
43
+ align-items: flex-start;
44
+ }
45
+ </style>
@@ -0,0 +1,45 @@
1
+ <script lang="ts">
2
+ import { ContainerProgressive } from "@snap-engine/snapsort";
3
+ import type { ItemBase, ContainerConfig } from "@snap-engine/snapsort";
4
+
5
+ import { getContext, setContext, onMount, onDestroy } from "svelte";
6
+ import type { Engine } from "@snap-engine/core";
7
+
8
+ let { config, children, container = $bindable(), locked = true, className = "", metadata = {} }: { config: ContainerConfig; children: any; container?: ContainerProgressive; locked?: boolean; className?: string; metadata?: Record<string, unknown> } =
9
+ $props();
10
+ const engine: Engine = getContext("engine");
11
+
12
+ let itemContainer: ContainerProgressive = new ContainerProgressive(engine, null, { ...config });
13
+ itemContainer.locked = locked;
14
+ itemContainer.metadata = metadata;
15
+ const justifyContent = $derived(config.mainAxisAlign === "center" ? "center" : "flex-start");
16
+ // If there's a parent container context, register this container as an item in it
17
+ const parent: ItemBase | null = getContext("container");
18
+ setContext("container", itemContainer);
19
+
20
+ onMount(() => {
21
+ container = itemContainer;
22
+ parent?.addItem(itemContainer);
23
+ });
24
+
25
+ onDestroy(() => {
26
+ itemContainer.destroy();
27
+ });
28
+ </script>
29
+
30
+ <div
31
+ class="snapsort-container snapsort-container-progressive {className}"
32
+ style="flex-direction: {config.direction}; justify-content: {justifyContent}"
33
+ bind:this={itemContainer.element}
34
+ >
35
+ {@render children?.()}
36
+ </div>
37
+
38
+ <style>
39
+ .snapsort-container {
40
+ position: relative;
41
+ display: flex;
42
+ flex-wrap: wrap;
43
+ align-items: flex-start;
44
+ }
45
+ </style>
@@ -0,0 +1,58 @@
1
+ <script lang="ts">
2
+ import { getContext, onDestroy, onMount } from "svelte";
3
+ import { ItemEuclidean } from "@snap-engine/snapsort";
4
+ import type {
5
+ ItemBase,
6
+ ContainerBase,
7
+ ItemMetadata,
8
+ } from "@snap-engine/snapsort";
9
+ import type { Engine } from "@snap-engine/core";
10
+
11
+ let {
12
+ children,
13
+ style = "",
14
+ className = "",
15
+ metadata = {},
16
+ }: {
17
+ children: any;
18
+ style?: string;
19
+ className?: string;
20
+ metadata?: ItemMetadata;
21
+ } = $props();
22
+
23
+ const engine: Engine = getContext("engine");
24
+ const container: ContainerBase | null = getContext("container");
25
+ const itemObject: ItemBase = new ItemEuclidean(engine, null);
26
+ itemObject.metadata = metadata;
27
+
28
+ const metadataItemKey = (value: ItemMetadata) => value.itemId ?? null;
29
+ let itemKey = $derived(metadataItemKey(metadata));
30
+
31
+ onMount(() => {
32
+ container?.addItem(itemObject);
33
+ });
34
+
35
+ onDestroy(() => {
36
+ itemObject.destroy();
37
+ });
38
+ </script>
39
+
40
+ <div
41
+ class="snapsort-item snapsort-item-euclidean {className}"
42
+ bind:this={itemObject.element}
43
+ data-snapsort-item-key={itemKey}
44
+ {style}
45
+ >
46
+ {@render children()}
47
+ </div>
48
+
49
+ <style>
50
+ .snapsort-item {
51
+ display: flex;
52
+ flex-direction: column;
53
+ align-items: center;
54
+ justify-content: center;
55
+ padding: var(--size-4);
56
+ box-sizing: border-box;
57
+ }
58
+ </style>
@@ -0,0 +1,58 @@
1
+ <script lang="ts">
2
+ import { getContext, onDestroy, onMount } from "svelte";
3
+ import { ItemProgressive } from "@snap-engine/snapsort";
4
+ import type {
5
+ ItemBase,
6
+ ContainerBase,
7
+ ItemMetadata,
8
+ } from "@snap-engine/snapsort";
9
+ import type { Engine } from "@snap-engine/core";
10
+
11
+ let {
12
+ children,
13
+ style = "",
14
+ className = "",
15
+ metadata = {},
16
+ }: {
17
+ children: any;
18
+ style?: string;
19
+ className?: string;
20
+ metadata?: ItemMetadata;
21
+ } = $props();
22
+
23
+ const engine: Engine = getContext("engine");
24
+ const container: ContainerBase | null = getContext("container");
25
+ const itemObject: ItemBase = new ItemProgressive(engine, null);
26
+ itemObject.metadata = metadata;
27
+
28
+ const metadataItemKey = (value: ItemMetadata) => value.itemId ?? null;
29
+ let itemKey = $derived(metadataItemKey(metadata));
30
+
31
+ onMount(() => {
32
+ container?.addItem(itemObject);
33
+ });
34
+
35
+ onDestroy(() => {
36
+ itemObject.destroy();
37
+ });
38
+ </script>
39
+
40
+ <div
41
+ class="snapsort-item snapsort-item-progressive {className}"
42
+ bind:this={itemObject.element}
43
+ data-snapsort-item-key={itemKey}
44
+ {style}
45
+ >
46
+ {@render children()}
47
+ </div>
48
+
49
+ <style>
50
+ .snapsort-item {
51
+ display: flex;
52
+ flex-direction: column;
53
+ align-items: center;
54
+ justify-content: center;
55
+ padding: var(--size-4);
56
+ box-sizing: border-box;
57
+ }
58
+ </style>
package/src/index.ts CHANGED
@@ -1,2 +1,7 @@
1
- export { default as ItemContainer } from "./ItemContainer.svelte";
2
- export { default as Item } from "./Item.svelte";
1
+ export { default as ContainerEuclidean } from "./ContainerEuclidean.svelte";
2
+ export { default as ItemEuclidean } from "./ItemEuclidean.svelte";
3
+ export { default as ContainerProgressive } from "./ContainerProgressive.svelte";
4
+ export { default as ItemProgressive } from "./ItemProgressive.svelte";
5
+
6
+ export { default as Container } from "./ContainerEuclidean.svelte";
7
+ export { default as Item } from "./ItemEuclidean.svelte";
package/src/Item.svelte DELETED
@@ -1,51 +0,0 @@
1
- <script lang="ts">
2
- import { onMount, getContext, onDestroy } from "svelte";
3
- import { ItemContainer } from "@snap-engine/snapsort";
4
- import { ItemObject } from "@snap-engine/snapsort";
5
- import type { ItemMetadata } from "@snap-engine/snapsort";
6
- import type { Engine } from "@snap-engine/core";
7
-
8
- let { children, style = "", className = "", metadata = {} }: { children: any; style?: string; className?: string; metadata?: ItemMetadata } = $props();
9
- const engine: Engine = getContext("engine");
10
-
11
- const container: ItemContainer = getContext("container");
12
- let itemObject: ItemObject = new ItemObject(engine, null);
13
- const metadataItemKey = (value: ItemMetadata) => {
14
- return value.itemId ?? null;
15
- };
16
- let itemKey = $derived(metadataItemKey(metadata));
17
-
18
- onMount(() => {
19
- if (container) {
20
- container.addItem(itemObject);
21
- }
22
- });
23
-
24
- $effect(() => {
25
- itemObject.metadata = metadata;
26
- });
27
-
28
- onDestroy(() => {
29
- itemObject.destroy();
30
- });
31
- </script>
32
-
33
- <div
34
- class="snapsort-item {className}"
35
- bind:this={itemObject.element}
36
- data-snapsort-item-key={itemKey}
37
- {style}
38
- >
39
- {@render children()}
40
- </div>
41
-
42
- <style>
43
- .snapsort-item {
44
- display: flex;
45
- flex-direction: column;
46
- align-items: center;
47
- justify-content: center;
48
- padding: var(--size-4);
49
- box-sizing: border-box;
50
- }
51
- </style>
@@ -1,51 +0,0 @@
1
- <script lang="ts">
2
- import { ItemContainer } from "@snap-engine/snapsort";
3
- import type { ItemContainerConfig } from "@snap-engine/snapsort";
4
-
5
- import { getContext, setContext, onMount, onDestroy } from "svelte";
6
- import type { Engine } from "@snap-engine/core";
7
- import Item from "./Item.svelte";
8
-
9
- let { config, children, container = $bindable(), locked = true, className = "", metadata = {} }: { config: ItemContainerConfig; children: any; container?: ItemContainer; locked?: boolean; className?: string; metadata?: Record<string, unknown> } =
10
- $props();
11
- const engine: Engine = getContext("engine");
12
-
13
- let itemContainer: ItemContainer = new ItemContainer(engine, null, config);
14
- itemContainer.locked = locked;
15
- itemContainer.metadata = metadata;
16
- container = itemContainer;
17
- // If there's a parent container context, register this container as an item in it
18
- const parent: ItemContainer | Item = getContext("container");
19
- setContext("container", itemContainer);
20
-
21
- onMount(() => {
22
- if (parent) {
23
- parent.addItem(itemContainer);
24
- }
25
- });
26
-
27
- onDestroy(() => {
28
- itemContainer.destroy();
29
- });
30
-
31
- $effect(() => {
32
- itemContainer.metadata = metadata;
33
- });
34
- </script>
35
-
36
- <div
37
- class="snapsort-container {className}"
38
- style="flex-direction: {config.direction}"
39
- bind:this={itemContainer.element}
40
- >
41
- {@render children?.()}
42
- </div>
43
-
44
- <style>
45
- .snapsort-container {
46
- position: relative;
47
- display: flex;
48
- flex-wrap: wrap;
49
- align-items: flex-start;
50
- }
51
- </style>