svelte-dnd-action 0.9.38 → 0.9.40

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
@@ -252,9 +252,11 @@ setDebugMode(true);
252
252
 
253
253
  ### Typescript
254
254
 
255
- If you are using Typescript, you will need to add the following block to your `global.d.ts` (at least until [this svelte issue](https://github.com/sveltejs/language-tools/issues/431) is resolved):
255
+ #### Setup (Optional)
256
256
 
257
- #### Svelte 3 or below
257
+ TypeScript support has been added since version 0.9.40 and you do not need to set up any custom typings. However, in case you are using some older version or face some types issue, you will need to add the following block to your `global.d.ts` (at least until [this svelte issue](https://github.com/sveltejs/language-tools/issues/431) is resolved):
258
+
259
+ ##### Svelte 3 or below
258
260
 
259
261
  ```typescript
260
262
  declare type Item = import("svelte-dnd-action").Item;
@@ -267,7 +269,7 @@ declare namespace svelte.JSX {
267
269
  }
268
270
  ```
269
271
 
270
- #### Svelte 4:
272
+ ##### Svelte 4:
271
273
 
272
274
  ```typescript
273
275
  declare type Item = import("svelte-dnd-action").Item;
@@ -281,6 +283,22 @@ declare namespace svelteHTML {
281
283
  ```
282
284
 
283
285
  You may need to edit `tsconfig.json` to include `global.d.ts` if it doesn't already: "include": ["src/**/*", "global.d.ts"].
286
+
287
+ > Note: If you are using Sveltekit you should use `svelte.config.js` to modify the generated `tsconfig.json` rather than adding the `include` element to the root `tsconfig.json`. Adding `include` to the root file will cause issues because it will [override](https://www.typescriptlang.org/tsconfig#extends) the `include` array defined in `.svelte-kit/tsconfig.json`. Example:
288
+ >
289
+ > ```javascript
290
+ > const config = {
291
+ > kit: {
292
+ > typescript: {
293
+ > config(config) {
294
+ > // This path is relative to the ".svelte-kit" folder
295
+ > config.include.push("../global.d.ts");
296
+ > }
297
+ > }
298
+ > }
299
+ > };
300
+ > ```
301
+
284
302
  Then you will be able to use the library with type safety as follows (Typescript gurus out there, improvements are welcome :smile:):
285
303
 
286
304
  ```html
package/dist/index.d.ts CHANGED
@@ -1,14 +1,18 @@
1
+ import type {ActionReturn} from "svelte/action";
2
+
1
3
  /**
2
4
  * A custom action to turn any container to a dnd zone and all of its direct children to draggables
3
5
  * Supports mouse, touch and keyboard interactions.
4
6
  * Dispatches two events that the container is expected to react to by modifying its list of items,
5
7
  * which will then feed back in to this action via the update function
6
8
  */
7
- export declare function dndzone(
9
+ export declare function dndzone<T extends Item>(node: HTMLElement, options: Options<T>): ActionReturn<Options<T>, DndZoneAttributes<T>>;
10
+
11
+ export declare function dndzone<T extends Item>(
8
12
  node: HTMLElement,
9
- options: Options
13
+ options: Options<T>
10
14
  ): {
11
- update: (newOptions: Options) => void;
15
+ update: (newOptions: Options<T>) => void;
12
16
  destroy: () => void;
13
17
  };
14
18
 
@@ -19,8 +23,8 @@ export type TransformDraggedElementFunction = (
19
23
  ) => void;
20
24
 
21
25
  export declare type Item = Record<string, any>;
22
- export interface Options {
23
- items: Item[]; // the list of items that was used to generate the children of the given node
26
+ export interface Options<T extends Item = Item> {
27
+ items: T[]; // the list of items that was used to generate the children of the given node
24
28
  type?: string; // the type of the dnd zone. children dragged from here can only be dropped in other zones of the same type, defaults to a base type
25
29
  flipDurationMs?: number; // if the list animated using flip (recommended), specifies the flip duration such that everything syncs with it without conflict
26
30
  dragDisabled?: boolean;
@@ -35,6 +39,13 @@ export interface Options {
35
39
  centreDraggedOnCursor?: boolean;
36
40
  }
37
41
 
42
+ export interface DndZoneAttributes<T> {
43
+ "on:consider"?: (e: CustomEvent<DndEvent<T>>) => void;
44
+ "on:finalize"?: (e: CustomEvent<DndEvent<T>>) => void;
45
+ onconsider?: (e: CustomEvent<DndEvent<T>>) => void;
46
+ onfinalize?: (e: CustomEvent<DndEvent<T>>) => void;
47
+ }
48
+
38
49
  /**
39
50
  * Will make the screen reader alert the provided text to the user
40
51
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-dnd-action",
3
3
  "description": "*An awesome drag and drop library for Svelte 3 and 4 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
4
- "version": "0.9.38",
4
+ "version": "0.9.40",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"