Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
docs(MovableEventDetails): generate docs for event detail output
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed May 9, 2022
1 parent 083253a commit b10a51c
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/docs/svelte-movable.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ svelte action - `use:movable` move node on mousedown

| Interface | Description |
| --- | --- |
| [MovableEventDetails](./svelte-movable.movableeventdetails.md) | <code>detail</code> payload for <code>movableend</code> and <code>movablestart</code> CustomEvent |
| [MovableLimit](./svelte-movable.movablelimit.md) | The limit within which node can be moved |
| [MovableParameters](./svelte-movable.movableparameters.md) | svelte action parameters to config behavior of movable |

Expand Down
20 changes: 18 additions & 2 deletions api/docs/svelte-movable.movable.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,29 @@ svelte action interface
<-- incorrect usage-->
<Component use:movable/>
```
Be aware of side effects:

- element.style.position is set to `relative` (if not already 'absolute' / 'relative') the first time mousedown is triggered

- document.body.userSelect is set to `none` after `mousedown` and restored on `mouseup`

- document.body.cursor is set to `move` after `mousedown` and restored on `mouseup`

## Example

Typical usage

1. `mousedown` of the trigger `button` element, a `CustomEvent` `movablestart`<!-- -->is dispatched,

2. `mousemove` will trigger `div` to move accordingly;

3. movement will be limited to the border of the `containerNode`<!-- -->, plus and minus 20% of the width &amp; height of the `div` that the action is being used on,

4. `mouseup` will stop the movement; a `CustomEvent` `movableend` is dispatched.

```svelte
<script lang="ts">
import { fade } from 'svelte/transition'
import arrows from 'svelte-awesome/icons/arrows';
import Icon from 'svelte-awesome/components/Icon.svelte';
Expand All @@ -67,8 +83,8 @@ Typical usage
},
trigger: triggerNode,
}}
on:movablestart={() => console.log('movable:start')}
on:movableend={() => console.log('movable:end')}
on:movablestart={(event) => console.log('movable:start', event.detail.node, event.detail.position)}
on:movableend={(event) => console.log('movable:end', event.detail.node, event.detail.position)}
>
<button
bind:this={triggerNode}
Expand Down
40 changes: 40 additions & 0 deletions api/docs/svelte-movable.movableeventdetails.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [svelte-movable](./svelte-movable.md) &gt; [MovableEventDetails](./svelte-movable.movableeventdetails.md)

## MovableEventDetails interface

`detail` payload for `movableend` and `movablestart` CustomEvent

<b>Signature:</b>

```typescript
export interface MovableEventDetails
```

## Example


```svelte
<script>
function handler(event) {
const { position, node } = event.detail;
console.log('action movable was used on element', node);
console.log('last known position:', position);
}
</script>

<div
use:movable
on:movablestart={handler}
on:movableend={handler}
/>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [node](./svelte-movable.movableeventdetails.node.md) | HTMLElement | the node that the action was placed on |
| [position](./svelte-movable.movableeventdetails.position.md) | { left: number; top: number; } | last known position, as in styles.position |

13 changes: 13 additions & 0 deletions api/docs/svelte-movable.movableeventdetails.node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [svelte-movable](./svelte-movable.md) &gt; [MovableEventDetails](./svelte-movable.movableeventdetails.md) &gt; [node](./svelte-movable.movableeventdetails.node.md)

## MovableEventDetails.node property

the node that the action was placed on

<b>Signature:</b>

```typescript
node: HTMLElement;
```
16 changes: 16 additions & 0 deletions api/docs/svelte-movable.movableeventdetails.position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [svelte-movable](./svelte-movable.md) &gt; [MovableEventDetails](./svelte-movable.movableeventdetails.md) &gt; [position](./svelte-movable.movableeventdetails.position.md)

## MovableEventDetails.position property

last known position, as in styles.position

<b>Signature:</b>

```typescript
position: {
left: number;
top: number;
};
```
9 changes: 9 additions & 0 deletions api/svelte-movable.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export function movable(node: HTMLElement, parameters?: Partial<MovableParameter
destroy(): void;
};

// @public
export interface MovableEventDetails {
node: HTMLElement;
position: {
left: number;
top: number;
};
}

// @public
export interface MovableLimit {
delta?: {
Expand Down
11 changes: 7 additions & 4 deletions src/movable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ import { input } from './utils';
*
* <-- incorrect usage-->
* <Component use:movable/>
* ```
*
* ### Side Effects
*
* Be aware that:
* Be aware of side effects:
*
* - element.style.position is set to `relative` (if not already 'absolute' / 'relative') the first time mousedown is triggered
*
* - document.body.userSelect is set to `none` after `mousedown` and restored on `mouseup`
* - document.body.cursor is set to `move` after `mousedown` and restored on `mouseup`
*
* ```
* - document.body.cursor is set to `move` after `mousedown` and restored on `mouseup`
*
* @example Typical usage
*
* 1. `mousedown` of the trigger `button` element, a `CustomEvent` `movablestart`is dispatched,
*
* 2. `mousemove` will trigger `div` to move accordingly;
*
* 3. movement will be limited to the border of the `containerNode`, plus and minus 20% of the width & height of the `div` that the action is being used on,
*
* 4. `mouseup` will stop the movement; a `CustomEvent` `movableend` is dispatched.
*
* ```svelte
Expand Down
21 changes: 20 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,26 @@ export interface MovableParameters {
}

/**
* the detail payload for `movableend` and `movablestart` CustomEvent
* `detail` payload for `movableend` and `movablestart` CustomEvent
* @public
*
* @example
*
* ```svelte
* <script>
* function handler(event) {
* const { position, node } = event.detail;
* console.log('action movable was used on element', node);
* console.log('last known position:', position);
* }
* </script>
*
* <div
* use:movable
* on:movablestart={handler}
* on:movableend={handler}
* />
* ```
*/
export interface MovableEventDetails {
/** the node that the action was placed on */
Expand Down

0 comments on commit b10a51c

Please sign in to comment.