Skip to content

Commit

Permalink
fix: some more type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hperrin committed Sep 12, 2021
1 parent f654b9b commit f4b8568
Show file tree
Hide file tree
Showing 98 changed files with 192 additions and 89 deletions.
1 change: 1 addition & 0 deletions packages/banner/Banner.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CloseReason } from '@material/banner';
5 changes: 2 additions & 3 deletions packages/banner/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Banner from './Banner.svelte';
export * from './Banner.types';

import Label from '@smui/common/CommonLabel.svelte';
import Icon from '@smui/common/CommonIcon.svelte';
import { Label, Icon } from '@smui/common';

export default Banner;

export { CloseReason } from '@material/banner';
export { Label, Icon };
3 changes: 1 addition & 2 deletions packages/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import Button from './Button.svelte';
import Group from './Group.svelte';
export * from './GroupItem';
import GroupItem from './GroupItem';
import Label from '@smui/common/CommonLabel.svelte';
import Icon from '@smui/common/CommonIcon.svelte';
import { Label, Icon } from '@smui/common';

export default Button;

Expand Down
2 changes: 1 addition & 1 deletion packages/chips/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
dispatch,
ActionArray,
} from '@smui/common/internal';
import Checkmark from './Checkmark.svelte';
import type { SMUIChipsPrimaryActionAccessor } from './Text.types';
import Checkmark from './Checkmark.svelte';
const forwardEvents = forwardEventsBuilder(get_current_component());
Expand Down
3 changes: 2 additions & 1 deletion packages/common/A.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let href = 'javascript:void(0);';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Aside.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/CommonIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
<script lang="ts">
import { getContext, SvelteComponent } from 'svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, classMap } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, classMap } from './internal';
import I from './I.svelte';
import Svg from './Svg.svelte';
Expand Down
3 changes: 2 additions & 1 deletion packages/common/CommonLabel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import type { SMUIComponent } from './SMUIComponent';
import { getContext } from 'svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, classMap } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, classMap } from './internal';
import Span from './Span.svelte';
const forwardEvents = forwardEventsBuilder(get_current_component());
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Div.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Em.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H1.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H3.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H4.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H5.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/H6.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Hr.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/I.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Img.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let alt = '';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Li.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Section.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Span.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Strong.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
5 changes: 3 additions & 2 deletions packages/common/Svg.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
const forwardEvents = forwardEventsBuilder(get_current_component());
let element: HTMLOrSVGElement;
let element: SVGSVGElement;
export function getElement() {
return element;
Expand Down
3 changes: 2 additions & 1 deletion packages/common/Ul.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<script lang="ts">
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions } from './internal';
import type { ActionArray } from './useActions';
import { forwardEventsBuilder, useActions } from './internal';
export let use: ActionArray = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/common/forwardEventsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function forwardEventsBuilder(component: SvelteComponent) {
bubble(component, e);
}

return (node: Element) => {
return (node: HTMLElement | SVGElement) => {
const destructors: (() => void)[] = [];
const forwardDestructors: { [k: string]: () => void } = {};

Expand Down
34 changes: 26 additions & 8 deletions packages/common/useActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,46 @@ export type SvelteActionReturnType<P> = {
destroy?: () => void;
} | void;

export type SvelteActionType<P> = (
export type SvelteHTMLActionType<P> = (
node: HTMLElement,
params?: P
) => SvelteActionReturnType<P>;

export type ActionEntry<P extends any = any> =
| SvelteActionType<P>
| [SvelteActionType<P>, P];
export type HTMLActionEntry<P extends any = any> =
| SvelteHTMLActionType<P>
| [SvelteHTMLActionType<P>, P];

export type ActionArray = ActionEntry[];
export type HTMLActionArray = HTMLActionEntry[];

export function useActions(node: HTMLElement, actions: ActionArray) {
export type SvelteSVGActionType<P> = (
node: SVGElement,
params?: P
) => SvelteActionReturnType<P>;

export type SVGActionEntry<P extends any = any> =
| SvelteSVGActionType<P>
| [SvelteSVGActionType<P>, P];

export type SVGActionArray = SVGActionEntry[];

export type ActionArray = HTMLActionArray | SVGActionArray;

export function useActions(
node: HTMLElement | SVGElement,
actions: ActionArray
) {
let actionReturns: SvelteActionReturnType<any>[] = [];

if (actions) {
for (let i = 0; i < actions.length; i++) {
const actionEntry = actions[i];
const action = Array.isArray(actionEntry) ? actionEntry[0] : actionEntry;
if (Array.isArray(actionEntry) && actionEntry.length > 1) {
actionReturns.push(action(node, actionEntry[1]));
actionReturns.push(
action(node as HTMLElement & SVGElement, actionEntry[1])
);
} else {
actionReturns.push(action(node));
actionReturns.push(action(node as HTMLElement & SVGElement));
}
}
}
Expand Down
Loading

0 comments on commit f4b8568

Please sign in to comment.