Skip to content

Commit

Permalink
refactor: expose drag action instead of event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lee committed May 26, 2022
1 parent 3816b45 commit b3bf2cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/lib/plugins/addResizedColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ResizedColumnsColumnOptions = {
export type ResizedColumnsPropSet = NewTablePropSet<{
'thead.tr.th': {
(node: Element): void;
drag: (event: Event) => void;
drag: (node: Element) => void;
disabled: boolean;
};
}>;
Expand Down Expand Up @@ -194,7 +194,16 @@ export const addResizedColumns =
},
};
};
action.drag = dragStart;
action.drag = (node: Element) => {
node.addEventListener('mousedown', dragStart);
node.addEventListener('touchstart', dragStart);
return {
destroy() {
node.removeEventListener('mousedown', dragStart);
node.removeEventListener('touchstart', dragStart);
},
};
};
action.disabled = isCellDisabled(cell, disabledResizeIds);
const props = derived([], () => {
return action;
Expand Down
7 changes: 1 addition & 6 deletions src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,7 @@
<Render of={props.filter.render} />
{/if}
{#if !props.resize.disabled}
<div
class="resizer"
on:click|stopPropagation
on:mousedown={props.resize.drag}
on:touchstart={props.resize.drag}
/>
<div class="resizer" on:click|stopPropagation use:props.resize.drag />
{/if}
</th>
</Subscribe>
Expand Down

0 comments on commit b3bf2cd

Please sign in to comment.