Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
661cca3
Cleanup TS warnings in SelectListOptions/SelectField
techniq Jun 22, 2024
2311bb7
Update Sveld type definitions
techniq Jun 22, 2024
53ecb0a
Ignore mising href (provided by markdown/mdsvex)
techniq Jun 22, 2024
ffb0a3a
Fix SveldJson rest_props type
techniq Jun 22, 2024
82992d8
Fix parsing slot prop type
techniq Jun 22, 2024
0329352
[Backdrop] Add aria role
techniq Jun 22, 2024
27c1521
[Breadcrumb] Add `number` to items type
techniq Jun 22, 2024
75dc4ed
[ButtonGroup] Remove mouse/keyboard event handlers (a11y). Use wrappi…
techniq Jun 22, 2024
d8583ec
[Checkbox] Fix type error (code path never reachable regardless)
techniq Jun 22, 2024
fabe5a5
[Code] Remove settings classes (Code is not exposed in top-level expo…
techniq Jun 22, 2024
4f9cbba
Fix/workaround more warnings and errors
techniq Jun 22, 2024
8f2896c
Ignore more warnings
techniq Jun 22, 2024
516d9a5
More ts errors
techniq Jun 22, 2024
37f1c4c
More ts errors handling
techniq Jun 23, 2024
b1b9beb
Add `FormatNumberStyle` to top-level exports
techniq Jun 23, 2024
41839b7
Add types for custom events from actions
techniq Jun 23, 2024
4fb69e3
Fix format type on MonthList and YearList
techniq Jun 23, 2024
7fae975
Fix/ignore remaining ts warnings in src/lib
techniq Jun 23, 2024
0d33827
Cleanup remaining aria warnings and more ts error cleanup
techniq Jun 23, 2024
44361e0
More TS error cleanup
techniq Jun 23, 2024
e76f0a0
Improve DateButton format prop type
techniq Jun 23, 2024
3014c44
Improve type of `ScrollShadowOptions`
techniq Jun 23, 2024
058ae75
Fix/ignore types on observer examples
techniq Jun 23, 2024
f76424b
Remove no longer available error details
techniq Jun 23, 2024
b3d9232
Improve expireObject() util
techniq Jun 23, 2024
ed2c5af
Work around parsing issue
techniq Jun 23, 2024
817fb8a
Even more TS improvements
techniq Jun 23, 2024
61a6e5b
Fix/workaround last 2 errors
techniq Jun 23, 2024
55ca530
Refine PageData type and improve ViewSourceButton types
techniq Jun 23, 2024
248df70
Run svelte-check during CI
techniq Jun 23, 2024
9b25619
Add changeset
techniq Jun 23, 2024
0dfe413
Add workspace level (recursive) `pnpm check`
techniq Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-bananas-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': minor
---

Cleanup a11y and TS warnings/errors
5 changes: 5 additions & 0 deletions .changeset/healthy-seas-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': minor
---

[ButtonGroup] Remove mouse/keyboard event handlers (a11y). Use wrapping container to stop event propagation
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:

- run: pnpm install --frozen-lockfile

- run: pnpm check

- run: pnpm lint

- run: pnpm test:unit
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"test:unit": "pnpm -r test:unit",
"build": "rimraf packages/*/dist && pnpm -r build",
"check": "pnpm -r check",
"lint": "pnpm -r lint",
"format": "pnpm -r format",
"changeset": "changeset",
Expand Down
18 changes: 17 additions & 1 deletion packages/svelte-ux/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
declare namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}

interface PageData {
meta: {
title?: string;
description?: string;
source?: string;
pageSource?: string;
api?: SveldJson;
features?: string[];
related?: string[];
hideUsage?: boolean;
hideTableOfContents?: boolean;
status?: string;
};
}

// interface PageState {}
// interface Platform {}
}
2 changes: 2 additions & 0 deletions packages/svelte-ux/src/docs/Link.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- href provided by markdown/mdsvex -->
<!-- svelte-ignore a11y-missing-attribute -->
<a class="text-primary font-medium" {...$$restProps}>
<slot />
</a>
8 changes: 5 additions & 3 deletions packages/svelte-ux/src/docs/ViewSourceButton.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';
import { mdiGithub } from '@mdi/js';

import Button from '../lib/components/Button.svelte';
import Code from '../lib/components/Code.svelte';
import Dialog from '../lib/components/Dialog.svelte';
import Toggle from '../lib/components/Toggle.svelte';
import Tooltip from '../lib/components/Tooltip.svelte';

export let label: string;
export let source: string;
export let href: string;
export let icon: string;
export let source: string | undefined = undefined;
export let href: string | undefined = undefined;
export let icon: ComponentProps<Button>['icon'];
</script>

{#if source}
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte-ux/src/lib/actions/_domTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export default class DomTracker {
const existingAction = this.changes.actions.get(action.name);
if (existingAction) {
// Action already created, call action's update() (if available)
existingAction.update?.(options);
existingAction.update?.(options as any);
} else {
// Add new action
this.changes.actions.set(action.name, action(this.node, options));
this.changes.actions.set(action.name, action(this.node, options as any));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-ux/src/lib/actions/dataBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type DataBackgroundOptions = {
*/
baseline?: boolean;

tweened?: Parameters<typeof tweened>[1];
tweened?: Parameters<typeof tweened<number | null>>[1];
};

export const dataBackground: Action<HTMLElement, DataBackgroundOptions> = (node, options) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte-ux/src/lib/actions/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type MovableOptions = {
/**
* Track mouse position changes from mouse down on node to mouse up
*/
export const movable: Action<HTMLElement, MovableOptions> = (node, options = {}) => {
export const movable: Action<HTMLElement, MovableOptions | undefined> = (node, options = {}) => {
let lastX = 0;
let lastY = 0;

Expand Down Expand Up @@ -184,7 +184,7 @@ type MouseCoordsOptions = {
};

/** Set relative mouse coordinates as --x/--y CSS variables */
export const mouseCoords: Action<HTMLElement, HTMLElement> = (node, target = node) => {
export const mouseCoords: Action<HTMLElement, HTMLElement | undefined> = (node, target = node) => {
function onMouseMove(e: MouseEvent) {
// Mouse coordinates relative to node instead of viewport (`e.offsetX/Y` changes based on target/children)
const rect = node.getBoundingClientRect();
Expand All @@ -209,7 +209,7 @@ export const mouseCoords: Action<HTMLElement, HTMLElement> = (node, target = nod
node.addEventListener('mouseleave', onMouseLeave);

return {
update(target: HTMLElement) {
update(target: HTMLElement | undefined) {
target = target;
},
destroy() {
Expand Down
7 changes: 0 additions & 7 deletions packages/svelte-ux/src/lib/actions/observable.d.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/svelte-ux/src/lib/actions/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const resize: Action<HTMLElement> = (node) => {
};
};

export const intersection: Action<HTMLElement, IntersectionObserverInit> = (node, options) => {
export const intersection: Action<HTMLElement, IntersectionObserverInit | undefined> = (
node,
options = {}
) => {
// TODO: Support defininting `options.root = node.parentNode` easily (maybe querySelector() string?)

let observer = new IntersectionObserver(
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte-ux/src/lib/actions/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { portal } from './portal.js';

export type PopoverOptions = {
anchorEl?: HTMLElement;
anchorEl?: Element | HTMLElement;
placement?: Placement;
offset?: OffsetOptions;
padding?: number;
Expand Down Expand Up @@ -71,7 +71,7 @@ export const popover: Action<Element | HTMLElement, PopoverOptions> = (node, opt
left: `${x}px`,
top: `${y}px`,
...(options?.matchWidth && {
width: `${anchorEl.offsetWidth}px`,
width: `${(anchorEl as HTMLElement).offsetWidth}px`,
}),
});
});
Expand Down
20 changes: 6 additions & 14 deletions packages/svelte-ux/src/lib/actions/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,12 @@ export const scrollIntoView: Action<HTMLElement, ScrollIntoViewOptions | undefin
return { update };
};

type ScrollShadowOptions = {
top?: {
color?: string;
};
bottom?: {
color?: string;
};
left?: {
color?: string;
};
right?: {
color?: string;
};
};
type ScrollShadowOptions = Partial<
Record<
'top' | 'bottom' | 'left' | 'right',
{ color?: string; offset?: number; blur?: number; spread?: number; scrollRatio?: number }
>
>;

export const scrollShadow: Action<HTMLElement, ScrollShadowOptions | undefined> = (
node,
Expand Down
31 changes: 18 additions & 13 deletions packages/svelte-ux/src/lib/actions/spotlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,25 @@ export const spotlight: Action<HTMLElement, SpotlightOptions> = (node, options)
'relative',
'isolate',

options?.radius && '[--spotlight-radius:var(--default-spotlight-radius)]',
options?.borderWidth && '[--spotlight-border-width:var(--default-spotlight-border-width)]',
options?.borderColorStops &&
'[--spotlight-border-color-stops:var(--default-spotlight-border-color-stops)]',
options?.surfaceColorStops &&
'[--spotlight-surface-color-stops:var(--default-spotlight-surface-color-stops)]',
options?.radius ? '[--spotlight-radius:var(--default-spotlight-radius)]' : '',
options?.borderWidth ? '[--spotlight-border-width:var(--default-spotlight-border-width)]' : '',
options?.borderColorStops
? '[--spotlight-border-color-stops:var(--default-spotlight-border-color-stops)]'
: '',
options?.surfaceColorStops
? '[--spotlight-surface-color-stops:var(--default-spotlight-surface-color-stops)]'
: '',

options?.hover?.radius && 'hover:[--spotlight-radius:var(--hover-spotlight-radius)]',
options?.hover?.borderWidth &&
'hover:[--spotlight-border-width:var(--hover-spotlight-border-width)]',
options?.hover?.borderColorStops &&
'hover:[--spotlight-border-color-stops:var(--hover-spotlight-border-color-stops)]',
options?.hover?.surfaceColorStops &&
'hover:[--spotlight-surface-color-stops:var(--hover-spotlight-surface-color-stops)]',
options?.hover?.radius ? 'hover:[--spotlight-radius:var(--hover-spotlight-radius)]' : '',
options?.hover?.borderWidth
? 'hover:[--spotlight-border-width:var(--hover-spotlight-border-width)]'
: '',
options?.hover?.borderColorStops
? 'hover:[--spotlight-border-color-stops:var(--hover-spotlight-border-color-stops)]'
: '',
options?.hover?.surfaceColorStops
? 'hover:[--spotlight-surface-color-stops:var(--hover-spotlight-surface-color-stops)]'
: '',

// Spotlight applied as :after element with 2 background gradients. padding-box for surface, and border-box for border
'before:absolute',
Expand Down
8 changes: 7 additions & 1 deletion packages/svelte-ux/src/lib/actions/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const tableCell: Action<HTMLElement, TableCellOptions> = (node, options)
if (column.dataBackground) {
const extents = extent(tableData ?? [], (d) => getCellValue(column, d));

// @ts-ignore
tracker.addAction(dataBackground, {
value: context.cellValue,
domain: tableData ? [min([0, extents[0]]), max([0, extents[1]])] : undefined,
Expand All @@ -174,7 +175,11 @@ export const tableCell: Action<HTMLElement, TableCellOptions> = (node, options)
};
};

function getClasses(classProp: ColumnDef['classes']['td'], context: ResolveContext): string[] {
function getClasses(
// @ts-ignore
classProp: ColumnDef['classes']['td'],
context: ResolveContext
): string[] {
const resolvedClassProp = typeof classProp === 'function' ? classProp(context) : classProp;

if (typeof resolvedClassProp === 'string') {
Expand All @@ -188,6 +193,7 @@ function getClasses(classProp: ColumnDef['classes']['td'], context: ResolveConte
}

function getStyleProperties(
// @ts-ignore
styleProp: ColumnDef['style']['td'],
context: ResolveContext
): string[][] {
Expand Down
24 changes: 24 additions & 0 deletions packages/svelte-ux/src/lib/actions/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md
declare namespace svelteHTML {
interface HTMLAttributes<T> {
// use:intersection
'on:intersecting'?: (event: CustomEvent<IntersectionObserverEntry>) => void;

// use:mutate
'on:mutate'?: (event: CustomEvent<MutationRecord[]>) => void;

// use:movable
'on:movestart'?: (event: CustomEvent<{ x: number; y: number }>) => void;
'on:move'?: (event: CustomEvent<{ x: number; y: number; dx: number; dy: number }>) => void;
'on:moveend'?: (event: CustomEvent<{ x: number; y: number }>) => void;

// use:popover
'on:clickOutside'?: (event: CustomEvent) => void;

// use:overflow
'on:overflow'?: (event: CustomEvent<{ overflowX: number; overflowY: number }>) => void;

// use:longpress
'on:longpress'?: (event: CustomEvent) => void;
}
}
46 changes: 23 additions & 23 deletions packages/svelte-ux/src/lib/components/ApiDocs.d.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
// See: https://github.com/carbon-design-system/sveld/blob/main/src/ComponentParser.ts#L26
// See: https://github.com/mattjennings/vite-plugin-sveld/blob/main/types.d.ts

interface SveldProp {
name: string;
kind: string;
kind: 'let' | 'const' | 'function';
constant: boolean;
type?: string;
value?: any;
description?: string;
isFunction: boolean;
isFunctionDeclaration: boolean;
isRequired: boolean;
constant: boolean;
reactive: boolean;
}

interface SveldSlot {
name: string;
name?: string;
default: boolean;
fallback: string;
slot_props: string;
fallback?: string;
slot_props?: string;
description?: string;
}

interface SveldEvent {
type: string;
interface ForwardedEvent {
type: 'forwarded';
name: string;
element: string;
element: ComponentInlineElement | ComponentElement;
}

interface DispatchedEvent {
type: 'dispatched';
name: string;
detail?: any;
description?: string;
}

type SvelteEvent = ForwardedEvent | DispatchedEvent;

interface SveldRestProps {
type: string;
type: 'InlineComponent' | 'Element';
name: string;
}

interface SveldTypedefs {
type: string;
name: string;
description?: string;
ts: string;
}

interface SveldModuleExport {
name: string;
kind: string;
type?: string;
value: string;
isFunction: boolean;
isFunctionDeclaration: boolean;
isRequired: boolean;
constant: boolean;
reactive: boolean;
}

interface SveldJson {
props: SveldProp[];
slots: SveldSlot[];
events: SveldEvent[];
typedefs: SveldTypedefs[];
rest_props: SveldRestProps[];
moduleExports: SveldModuleExport[];
rest_props: SveldRestProps;
moduleExports: SveldProp[];
componentComment?: string;
extends?: {
interface: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-ux/src/lib/components/ApiDocs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@

<div slot="actions" class="flex flex-wrap justify-end gap-1">
{#if slot.slot_props != '{}'}
{#each parseSlotProps(slot.slot_props) as { key, value }}
{#each parseSlotProps(slot.slot_props ?? '') as { key, value }}
<Tooltip title="slot prop" offset={2}>
<div
class="inline-block border bg-orange-500/10 border-orange-500 text-orange-600 px-2 rounded-full text-xs cursor-help"
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-ux/src/lib/components/Backdrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
in:fade|global={fadeParams}
out:fade={fadeParams}
use:portalAction={portal}
role="none"
>
<slot />
</div>
Loading