@txstate-mws/svelte-components 1.1.0 → 1.1.1
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/actions/buttonify.d.ts +8 -0
- package/actions/buttonify.js +26 -0
- package/actions/glue.d.ts +16 -0
- package/actions/glue.js +82 -0
- package/actions/index.d.ts +7 -0
- package/actions/index.js +7 -0
- package/actions/offset.d.ts +15 -0
- package/actions/offset.js +35 -0
- package/actions/portal.d.ts +4 -0
- package/actions/portal.js +13 -0
- package/actions/resize.d.ts +20 -0
- package/actions/resize.js +57 -0
- package/actions/sticky.d.ts +33 -0
- package/actions/sticky.js +85 -0
- package/actions/stickyfixed.d.ts +25 -0
- package/actions/stickyfixed.js +157 -0
- package/components/Card.svelte +23 -0
- package/components/Card.svelte.d.ts +18 -0
- package/components/CardLayout.svelte +197 -0
- package/components/CardLayout.svelte.d.ts +21 -0
- package/{src/lib/components → components}/CollapsingTable.svelte +63 -65
- package/components/CollapsingTable.svelte.d.ts +59 -0
- package/{src/lib/components → components}/ConditionalWrapper.svelte +6 -7
- package/components/ConditionalWrapper.svelte.d.ts +23 -0
- package/components/FocusLock.svelte +107 -0
- package/components/FocusLock.svelte.d.ts +26 -0
- package/{src/lib/components → components}/Modal.svelte +22 -24
- package/components/Modal.svelte.d.ts +27 -0
- package/components/MultiSelect.svelte +179 -0
- package/components/MultiSelect.svelte.d.ts +35 -0
- package/components/PopupMenu.svelte +287 -0
- package/components/PopupMenu.svelte.d.ts +45 -0
- package/{src/lib/components → components}/ScreenReaderOnly.svelte +3 -4
- package/components/ScreenReaderOnly.svelte.d.ts +20 -0
- package/components/index.d.ts +9 -0
- package/components/index.js +9 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +34 -13
- package/types/CardLayout.d.ts +14 -0
- package/types/CardLayout.js +1 -0
- package/types/CollapsingTable.d.ts +8 -0
- package/types/CollapsingTable.js +1 -0
- package/types/PopupMenu.d.ts +5 -0
- package/types/PopupMenu.js +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.js +3 -0
- package/util/bodyoffset.d.ts +14 -0
- package/util/bodyoffset.js +72 -0
- package/util/index.d.ts +3 -0
- package/util/index.js +3 -0
- package/util/repositioned.d.ts +12 -0
- package/util/repositioned.js +81 -0
- package/util/util.d.ts +5 -0
- package/util/util.js +33 -0
- package/.eslintrc.cjs +0 -37
- package/docs/CollapsingTable.md +0 -79
- package/docs/ConditionalWrapper.md +0 -35
- package/docs/Modal.md +0 -63
- package/docs/PopupMenu.md +0 -31
- package/docs/ScreenReaderOnly.md +0 -10
- package/docs/actions.md +0 -84
- package/docs/stores.md +0 -203
- package/playwright.config.js +0 -112
- package/src/app.html +0 -14
- package/src/global.d.ts +0 -1
- package/src/lib/actions/buttonify.ts +0 -27
- package/src/lib/actions/glue.ts +0 -96
- package/src/lib/actions/index.ts +0 -7
- package/src/lib/actions/offset.ts +0 -43
- package/src/lib/actions/portal.ts +0 -13
- package/src/lib/actions/resize.ts +0 -72
- package/src/lib/actions/sticky.ts +0 -105
- package/src/lib/actions/stickyfixed.ts +0 -160
- package/src/lib/components/Card.svelte +0 -25
- package/src/lib/components/CardLayout.svelte +0 -188
- package/src/lib/components/FocusLock.svelte +0 -102
- package/src/lib/components/MultiSelect.svelte +0 -174
- package/src/lib/components/PopupMenu.svelte +0 -285
- package/src/lib/components/index.ts +0 -9
- package/src/lib/index.ts +0 -4
- package/src/lib/types/CardLayout.ts +0 -14
- package/src/lib/types/CollapsingTable.ts +0 -8
- package/src/lib/types/PopupMenu.ts +0 -5
- package/src/lib/types/index.ts +0 -3
- package/src/lib/util/bodyoffset.ts +0 -77
- package/src/lib/util/index.ts +0 -3
- package/src/lib/util/repositioned.ts +0 -91
- package/src/lib/util/util.ts +0 -36
- package/src/routes/__layout.svelte +0 -125
- package/src/routes/actions/index.svelte +0 -1
- package/src/routes/actions/offset.svelte +0 -4
- package/src/routes/actions/offsetdebounce.svelte +0 -4
- package/src/routes/actions/resize.svelte +0 -4
- package/src/routes/actions/resizedebounce.svelte +0 -4
- package/src/routes/actions/sticky.svelte +0 -4
- package/src/routes/cards/index.svelte +0 -4
- package/src/routes/cards/preserve.svelte +0 -4
- package/src/routes/collapsingtable/index.svelte +0 -4
- package/src/routes/collapsingtable/stickyheader.svelte +0 -4
- package/src/routes/index.svelte +0 -2
- package/src/routes/modal.svelte +0 -4
- package/src/routes/multiselect.svelte +0 -4
- package/src/routes/popupmenu/body.svelte +0 -4
- package/src/routes/popupmenu/complex.svelte +0 -4
- package/src/routes/popupmenu/empty.svelte +0 -5
- package/src/routes/popupmenu/index.svelte +0 -4
- package/src/routes/popupmenu/parent.svelte +0 -4
- package/src/routes/popupmenu/scrollable.svelte +0 -27
- package/src/routes/popupmenu/showselected.svelte +0 -4
- package/src/test/Cards.svelte +0 -64
- package/src/test/CollapsingTableTest.svelte +0 -36
- package/src/test/ModalTest.svelte +0 -58
- package/src/test/MultiSelectTest.svelte +0 -26
- package/src/test/Offset.svelte +0 -32
- package/src/test/PopupMenuBody.svelte +0 -34
- package/src/test/PopupMenuButtonIsParent.svelte +0 -36
- package/src/test/PopupMenuComplex.svelte +0 -34
- package/src/test/PopupMenuSimple.svelte +0 -36
- package/src/test/Resize.svelte +0 -29
- package/src/test/Sticky.svelte +0 -65
- package/static/layout.css +0 -263
- package/svelte.config.js +0 -15
- package/tests/.eslintrc.cjs +0 -19
- package/tests/CardLayout.test.js +0 -41
- package/tests/CollapsingTable.test.js +0 -37
- package/tests/Modal.test.js +0 -18
- package/tests/MultiSelect.test.js +0 -58
- package/tests/PopupMenu.test.js +0 -55
- package/tests/common.js +0 -4
- package/tsconfig.json +0 -31
package/package.json
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txstate-mws/svelte-components",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Svelte components that are generically useful.",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"dev": "svelte-kit dev",
|
|
7
|
-
"build": "svelte-kit build",
|
|
8
|
-
"package": "svelte-kit package",
|
|
9
|
-
"preview": "svelte-kit preview",
|
|
10
|
-
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
11
|
-
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
|
12
|
-
"lint": "eslint --ignore-path .gitignore .",
|
|
13
|
-
"test": "playwright test tests"
|
|
14
|
-
},
|
|
15
5
|
"dependencies": {
|
|
16
6
|
"@txstate-mws/svelte-store": "^1.0.3",
|
|
17
7
|
"tabbable": "^5.2.1",
|
|
@@ -31,5 +21,36 @@
|
|
|
31
21
|
"tslib": "^2.3.1",
|
|
32
22
|
"typescript": "^4.4.3"
|
|
33
23
|
},
|
|
34
|
-
"type": "module"
|
|
35
|
-
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
"./actions/buttonify": "./actions/buttonify.js",
|
|
28
|
+
"./actions/glue": "./actions/glue.js",
|
|
29
|
+
"./actions": "./actions/index.js",
|
|
30
|
+
"./actions/offset": "./actions/offset.js",
|
|
31
|
+
"./actions/portal": "./actions/portal.js",
|
|
32
|
+
"./actions/resize": "./actions/resize.js",
|
|
33
|
+
"./actions/sticky": "./actions/sticky.js",
|
|
34
|
+
"./actions/stickyfixed": "./actions/stickyfixed.js",
|
|
35
|
+
"./components/Card.svelte": "./components/Card.svelte",
|
|
36
|
+
"./components/CardLayout.svelte": "./components/CardLayout.svelte",
|
|
37
|
+
"./components/CollapsingTable.svelte": "./components/CollapsingTable.svelte",
|
|
38
|
+
"./components/ConditionalWrapper.svelte": "./components/ConditionalWrapper.svelte",
|
|
39
|
+
"./components/FocusLock.svelte": "./components/FocusLock.svelte",
|
|
40
|
+
"./components/Modal.svelte": "./components/Modal.svelte",
|
|
41
|
+
"./components/MultiSelect.svelte": "./components/MultiSelect.svelte",
|
|
42
|
+
"./components/PopupMenu.svelte": "./components/PopupMenu.svelte",
|
|
43
|
+
"./components/ScreenReaderOnly.svelte": "./components/ScreenReaderOnly.svelte",
|
|
44
|
+
"./components": "./components/index.js",
|
|
45
|
+
".": "./index.js",
|
|
46
|
+
"./types/CardLayout": "./types/CardLayout.js",
|
|
47
|
+
"./types/CollapsingTable": "./types/CollapsingTable.js",
|
|
48
|
+
"./types/PopupMenu": "./types/PopupMenu.js",
|
|
49
|
+
"./types": "./types/index.js",
|
|
50
|
+
"./util/bodyoffset": "./util/bodyoffset.js",
|
|
51
|
+
"./util": "./util/index.js",
|
|
52
|
+
"./util/repositioned": "./util/repositioned.js",
|
|
53
|
+
"./util/util": "./util/util.js"
|
|
54
|
+
},
|
|
55
|
+
"svelte": "./index.js"
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SettableSubject } from '@txstate-mws/svelte-store';
|
|
2
|
+
export declare const CARDLAYOUT: {};
|
|
3
|
+
export interface Block {
|
|
4
|
+
element: HTMLElement;
|
|
5
|
+
order?: SettableSubject<number>;
|
|
6
|
+
linebreak?: SettableSubject<boolean>;
|
|
7
|
+
width?: SettableSubject<string>;
|
|
8
|
+
height?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CardLayoutContext {
|
|
11
|
+
registerBlock: (block: Block) => Block;
|
|
12
|
+
recalculate: () => void;
|
|
13
|
+
gutter: SettableSubject<number>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CARDLAYOUT = {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare type ElementOffsets = Partial<ReturnType<typeof bodyOffset>>;
|
|
2
|
+
export declare function bodyOffset(ele: HTMLElement): {
|
|
3
|
+
right: number;
|
|
4
|
+
bottom: number;
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function targetOffset(ele: HTMLElement, target: HTMLElement): {
|
|
9
|
+
right: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
top: number;
|
|
12
|
+
left: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function sharedOffsetParent(a: HTMLElement, b: HTMLElement): HTMLElement;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function bodyOffset(ele) {
|
|
2
|
+
return targetOffset(ele, document.body);
|
|
3
|
+
}
|
|
4
|
+
export function targetOffset(ele, target) {
|
|
5
|
+
const offset = targetOffsetRecursive(ele, target);
|
|
6
|
+
return {
|
|
7
|
+
...offset,
|
|
8
|
+
right: target.offsetWidth - offset.left - ele.offsetWidth,
|
|
9
|
+
bottom: target.offsetHeight - offset.top - ele.offsetHeight
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function sharedOffsetParent(a, b) {
|
|
13
|
+
if (!a || !b)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (a.contains(b) && a.firstElementChild.offsetParent === a)
|
|
16
|
+
return a;
|
|
17
|
+
if (b.contains(a) && b.firstElementChild.offsetParent === b)
|
|
18
|
+
return b;
|
|
19
|
+
let c = a.offsetParent;
|
|
20
|
+
while (c instanceof HTMLElement && !c.contains(b))
|
|
21
|
+
c = c.offsetParent;
|
|
22
|
+
return c;
|
|
23
|
+
}
|
|
24
|
+
function targetOffsetRecursive(ele, target, currentOffset) {
|
|
25
|
+
const { x, y } = getTranslate(ele);
|
|
26
|
+
const offset = {
|
|
27
|
+
top: ele.offsetTop + (currentOffset?.top ?? 0) + y,
|
|
28
|
+
left: ele.offsetLeft + (currentOffset?.left ?? 0) + x
|
|
29
|
+
};
|
|
30
|
+
if (ele.offsetParent instanceof HTMLElement && target !== ele.offsetParent && target.contains(ele.offsetParent))
|
|
31
|
+
return targetOffsetRecursive(ele.offsetParent, target, offset);
|
|
32
|
+
return offset;
|
|
33
|
+
}
|
|
34
|
+
function getTranslate(element) {
|
|
35
|
+
const style = window.getComputedStyle(element);
|
|
36
|
+
const matrix = style.transform;
|
|
37
|
+
// No transform property. Simply return 0 values.
|
|
38
|
+
if (matrix === 'none' || !matrix) {
|
|
39
|
+
return {
|
|
40
|
+
x: 0,
|
|
41
|
+
y: 0,
|
|
42
|
+
z: 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Can either be 2d or 3d transform
|
|
46
|
+
const matrixType = matrix.includes('3d') ? '3d' : '2d';
|
|
47
|
+
const matrixValues = matrix.match(/matrix.*\((.+)\)/)[1].split(', ');
|
|
48
|
+
// 2d matrices have 6 values
|
|
49
|
+
// Last 2 values are X and Y.
|
|
50
|
+
// 2d matrices does not have Z value.
|
|
51
|
+
if (matrixType === '2d') {
|
|
52
|
+
return {
|
|
53
|
+
x: Number(matrixValues[4]),
|
|
54
|
+
y: Number(matrixValues[5]),
|
|
55
|
+
z: 0
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// 3d matrices have 16 values
|
|
59
|
+
// The 13th, 14th, and 15th values are X, Y, and Z
|
|
60
|
+
if (matrixType === '3d') {
|
|
61
|
+
return {
|
|
62
|
+
x: Number(matrixValues[12]),
|
|
63
|
+
y: Number(matrixValues[13]),
|
|
64
|
+
z: Number(matrixValues[14])
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
x: 0,
|
|
69
|
+
y: 0,
|
|
70
|
+
z: 0
|
|
71
|
+
};
|
|
72
|
+
}
|
package/util/index.d.ts
ADDED
package/util/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElementOffsets } from './bodyoffset.js';
|
|
2
|
+
export declare function watchForMutations(cb: () => void): {
|
|
3
|
+
destroy(): void;
|
|
4
|
+
};
|
|
5
|
+
export declare function watchForPositionChange(el: (HTMLElement | undefined)[] | HTMLElement | undefined, cb: ((offset: Required<ElementOffsets>) => void) | ((offsets: Required<ElementOffsets>[]) => void)): {
|
|
6
|
+
update(newEl: (HTMLElement | undefined)[] | HTMLElement | undefined, newCb: ((offset: Required<ElementOffsets>) => void) | ((offsets: Required<ElementOffsets>[]) => void)): void;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function watchForPositionChangeInContainer(el: HTMLElement | undefined, container: HTMLElement | undefined, cb: (offset: Required<ElementOffsets>) => void): {
|
|
10
|
+
update(newEl: HTMLElement | undefined, newContainer: HTMLElement | undefined, newCb: (offset: Required<ElementOffsets>) => void): void;
|
|
11
|
+
destroy: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { equal, isNotNull, randomid, toArray } from 'txstate-utils';
|
|
2
|
+
import { bodyOffset, targetOffset } from './bodyoffset.js';
|
|
3
|
+
const observers = new Map();
|
|
4
|
+
let mutationobserver;
|
|
5
|
+
export function watchForMutations(cb) {
|
|
6
|
+
function watch() {
|
|
7
|
+
for (const cb of observers.values())
|
|
8
|
+
cb();
|
|
9
|
+
}
|
|
10
|
+
if (observers.size === 0) {
|
|
11
|
+
mutationobserver ?? (mutationobserver = new MutationObserver(watch));
|
|
12
|
+
window.addEventListener('resize', watch, { passive: true });
|
|
13
|
+
mutationobserver.observe(document.body, {
|
|
14
|
+
subtree: true,
|
|
15
|
+
childList: true,
|
|
16
|
+
attributes: true,
|
|
17
|
+
characterData: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const id = randomid();
|
|
21
|
+
observers.set(id, cb);
|
|
22
|
+
cb();
|
|
23
|
+
return {
|
|
24
|
+
destroy() {
|
|
25
|
+
observers.delete(id);
|
|
26
|
+
if (observers.size === 0) {
|
|
27
|
+
window.removeEventListener('resize', watch);
|
|
28
|
+
mutationobserver.disconnect();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function watchForPositionChange(el, cb) {
|
|
34
|
+
let lastoffsets = [];
|
|
35
|
+
let els = toArray(el).filter(isNotNull);
|
|
36
|
+
function watch() {
|
|
37
|
+
const offsets = els.map(bodyOffset);
|
|
38
|
+
if (offsets.some((offset, i) => !equal(offset, lastoffsets[i]))) {
|
|
39
|
+
lastoffsets = offsets;
|
|
40
|
+
Array.isArray(el) ? cb(offsets) : cb(offsets[0]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const { destroy } = watchForMutations(watch);
|
|
44
|
+
return {
|
|
45
|
+
update(newEl, newCb) {
|
|
46
|
+
const changed = newEl !== el || newCb !== cb;
|
|
47
|
+
if (changed) {
|
|
48
|
+
el = newEl;
|
|
49
|
+
els = toArray(el).filter(isNotNull);
|
|
50
|
+
cb = newCb;
|
|
51
|
+
watch();
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
destroy
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function watchForPositionChangeInContainer(el, container, cb) {
|
|
58
|
+
let lastoffset;
|
|
59
|
+
function watch() {
|
|
60
|
+
if (!el || !container)
|
|
61
|
+
return;
|
|
62
|
+
const offset = targetOffset(el, container);
|
|
63
|
+
if (!equal(offset, lastoffset)) {
|
|
64
|
+
lastoffset = offset;
|
|
65
|
+
cb(offset);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const { destroy } = watchForMutations(watch);
|
|
69
|
+
return {
|
|
70
|
+
update(newEl, newContainer, newCb) {
|
|
71
|
+
const changed = newEl !== el || newContainer !== container || newCb !== cb;
|
|
72
|
+
if (changed) {
|
|
73
|
+
el = newEl;
|
|
74
|
+
container = newContainer;
|
|
75
|
+
cb = newCb;
|
|
76
|
+
watch();
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
destroy
|
|
80
|
+
};
|
|
81
|
+
}
|
package/util/util.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function classes(...classNames: (string | undefined)[]): string;
|
|
2
|
+
export declare function debounced(fn: Function, timeout: number): (...args: any[]) => void;
|
|
3
|
+
export declare function debouncedPromise<T>(fn: (..._: any) => Promise<T> | T, timeout: number, defaultValue: T): (..._: any) => Promise<T>;
|
|
4
|
+
export declare function modifierKey(e: any): any;
|
|
5
|
+
export declare function selectionIsLeft(ele: HTMLInputElement | HTMLTextAreaElement): boolean;
|
package/util/util.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function classes(...classNames) {
|
|
2
|
+
return classNames.filter(Boolean).join(' ');
|
|
3
|
+
}
|
|
4
|
+
export function debounced(fn, timeout) {
|
|
5
|
+
let timer;
|
|
6
|
+
return (...args) => {
|
|
7
|
+
clearTimeout(timer);
|
|
8
|
+
timer = setTimeout(() => fn(...args), timeout);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function debouncedPromise(fn, timeout, defaultValue) {
|
|
12
|
+
let version = 0;
|
|
13
|
+
return async (...args) => {
|
|
14
|
+
const myversion = ++version;
|
|
15
|
+
return await new Promise(resolve => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
if (version === myversion) {
|
|
18
|
+
version = 0;
|
|
19
|
+
resolve(fn(...args));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
resolve(defaultValue);
|
|
23
|
+
}
|
|
24
|
+
}, timeout);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function modifierKey(e) {
|
|
29
|
+
return e.ctrlKey || e.altKey || e.metaKey || e.key === 'Insert';
|
|
30
|
+
}
|
|
31
|
+
export function selectionIsLeft(ele) {
|
|
32
|
+
return ele.selectionStart === 0 && ele.selectionEnd === 0;
|
|
33
|
+
}
|
package/.eslintrc.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
parser: '@typescript-eslint/parser',
|
|
4
|
-
extends: 'standard-with-typescript',
|
|
5
|
-
plugins: ['svelte3', '@typescript-eslint'],
|
|
6
|
-
ignorePatterns: ['*.cjs', 'package/**/*', 'svelte.config.js', 'playwright.config.js'],
|
|
7
|
-
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
|
|
8
|
-
settings: {
|
|
9
|
-
'svelte3/typescript': () => require('typescript')
|
|
10
|
-
},
|
|
11
|
-
rules: {
|
|
12
|
-
'import/first': 'off',
|
|
13
|
-
'no-multiple-empty-lines': 'off',
|
|
14
|
-
'no-undef-init': 'off',
|
|
15
|
-
'no-unused-vars': 'off',
|
|
16
|
-
'no-use-before-define': 'off',
|
|
17
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
18
|
-
'@typescript-eslint/array-type': 'off',
|
|
19
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
20
|
-
'@typescript-eslint/no-unused-vars': 'off', // typescript does this better
|
|
21
|
-
'@typescript-eslint/require-await': 'off',
|
|
22
|
-
'@typescript-eslint/return-await': ['error', 'always'],
|
|
23
|
-
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
24
|
-
'@typescript-eslint/prefer-readonly': ['off']
|
|
25
|
-
},
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: './tsconfig.json',
|
|
28
|
-
sourceType: 'module',
|
|
29
|
-
extraFileExtensions: ['.svelte'],
|
|
30
|
-
ecmaVersion: 2020
|
|
31
|
-
},
|
|
32
|
-
env: {
|
|
33
|
-
browser: true,
|
|
34
|
-
es2017: true,
|
|
35
|
-
node: true
|
|
36
|
-
}
|
|
37
|
-
};
|
package/docs/CollapsingTable.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# Collapsing Table
|
|
2
|
-
|
|
3
|
-
This component is meant to help make tables responsive by eliminating columns (from the right) as the screen width reduces. When there are hidden columns, the last column header becomes a dropdown button allowing the selection of another column to be displayed instead.
|
|
4
|
-
|
|
5
|
-
# Usage
|
|
6
|
-
|
|
7
|
-
The only required prop is an `items` array of objects. Column headers will automatically be detected from object keys if no column configuration is present.
|
|
8
|
-
|
|
9
|
-
## Column Configuration
|
|
10
|
-
|
|
11
|
-
A `config` prop allows you to pass an array of column definitions. If passed, only these columns will appear, other keys in your `items` objects will be ignored.
|
|
12
|
-
|
|
13
|
-
### Variables accepted for each column
|
|
14
|
-
|
|
15
|
-
* `key: string` corresponds to object key in your `items` objects
|
|
16
|
-
* `title?: string` a display name for this column's header
|
|
17
|
-
* `width?: number` a guess at how wide in pixels this column will be; helps decide when to hide
|
|
18
|
-
columns, default 150
|
|
19
|
-
* `neverhide?: boolean`<br>
|
|
20
|
-
setting to make sure this column is never hidden; good to set on
|
|
21
|
-
the column that is most identifying for each row, like a name.
|
|
22
|
-
by default the leftmost column will stick around as identifying
|
|
23
|
-
* `bodyCellClass?: string` CSS class to set on `td` elements in the body area
|
|
24
|
-
* `headerCellClass?: string` CSS class to set on `td` elements in the header row
|
|
25
|
-
|
|
26
|
-
## Optional Props
|
|
27
|
-
* `tableClass` CSS class for the `table`
|
|
28
|
-
* `bodyRowClass` CSS class for `tr` in the body area
|
|
29
|
-
* `bodyCellClass` CSS class for `td` in the body area, additional to the one set in column config
|
|
30
|
-
* `headerRowClass` CSS class for `tr` on the header row
|
|
31
|
-
* `headerCellClass` CSS class for `th` in the header row, additional to the one set in column config
|
|
32
|
-
* `menuClass` CSS class for the `ul` dropdown menu
|
|
33
|
-
* `menuItemClass` CSS class for `li` in the dropdown menu
|
|
34
|
-
* `menuItemHilitedClass` CSS class for `li` in the dropdown menu when they are currently hilited/active
|
|
35
|
-
* `defaultCellWidth`, guess for any column width in pixels, allows you to hide columns earlier/later, default 150
|
|
36
|
-
|
|
37
|
-
## Slots
|
|
38
|
-
Lots of slots are provided for extra configuration.
|
|
39
|
-
|
|
40
|
-
### Default Slot
|
|
41
|
-
The default slot is used for each table cell in the body area. It is optional and falls back to {value}.
|
|
42
|
-
Because of the way slots work, your slot content will be executed in every cell. So if you need to do
|
|
43
|
-
something special for just one cell, you have to use an if/else block to identify the special cell,
|
|
44
|
-
falling back to {value} for everything else:
|
|
45
|
-
```svelte
|
|
46
|
-
<CollapsingTable items={myItems} let:item let:key let:value>
|
|
47
|
-
{#if key === 'myspecialkey'}
|
|
48
|
-
<MySpecialComponent>{value}</MySpecialComponent>
|
|
49
|
-
{:else}
|
|
50
|
-
{value}
|
|
51
|
-
{/if}
|
|
52
|
-
</CollapsingTable>
|
|
53
|
-
```
|
|
54
|
-
The slot props are `item`, `key`, and `value`.
|
|
55
|
-
### Header Cell Slot
|
|
56
|
-
A slot named `headercell` allows you to do the same thing for cells in the header row that the
|
|
57
|
-
default slot allows for body cells.
|
|
58
|
-
```svelte
|
|
59
|
-
<CollapsingTable items={myItems} let:column let:key let:title>
|
|
60
|
-
<div slot="headercell">
|
|
61
|
-
{#if key === 'myspecialkey'}
|
|
62
|
-
<MySpecialComponent>{title}</MySpecialComponent>
|
|
63
|
-
{:else}
|
|
64
|
-
{title}
|
|
65
|
-
{/if}
|
|
66
|
-
</div>
|
|
67
|
-
</CollapsingTable>
|
|
68
|
-
```
|
|
69
|
-
The slot props are `column`, `key`, and `title`. `column` is the configuration object for the
|
|
70
|
-
current column, `title` is `column.title || column.key`. The title/key will be used as fallback
|
|
71
|
-
content if you do not specify a header slot.
|
|
72
|
-
### Dropdown Icon Slot
|
|
73
|
-
A slot is provided for you to provide a custom icon for the column header that is serving as the
|
|
74
|
-
dropdown button.
|
|
75
|
-
```svelte
|
|
76
|
-
<CollapsingTable items={myItems}>
|
|
77
|
-
<i type='fa caret-down' slot="dropicon" aria-hidden="true"></i>
|
|
78
|
-
</CollapsingTable>
|
|
79
|
-
```
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Conditional Wrapper
|
|
2
|
-
Sometimes you want to wrap a complex bit of HTML in a certain element based on a condition,
|
|
3
|
-
and not wrap it at all if the condition isn't met. Without help, this situation results in a
|
|
4
|
-
lot of duplicate code because you have to have an if/else block outside the whole thing, and
|
|
5
|
-
the complex HTML goes in both branches:
|
|
6
|
-
```svelte
|
|
7
|
-
{#if shouldwrap}
|
|
8
|
-
<div class="wrapper">
|
|
9
|
-
... a whole bunch of html ...
|
|
10
|
-
</div>
|
|
11
|
-
{:else}
|
|
12
|
-
... a whole bunch of html, again ...
|
|
13
|
-
{/if}
|
|
14
|
-
```
|
|
15
|
-
With this component, you can de-duplicate like this:
|
|
16
|
-
```svelte
|
|
17
|
-
<ConditionalWrapper class="wrapper" condition={shouldwrap}>
|
|
18
|
-
... a whole bunch of html ...
|
|
19
|
-
</ConditionalWrapper>
|
|
20
|
-
```
|
|
21
|
-
Any props you provide (except the ConditionalWrapper props like `condition`) will pass through
|
|
22
|
-
to the wrapper element/component, if it gets inserted.
|
|
23
|
-
|
|
24
|
-
## Props
|
|
25
|
-
* `condition: boolean|undefined` (required) - Whether or not to wrap the element. Accepts `undefined`
|
|
26
|
-
for convenience when evaluating presence of an optional variable.
|
|
27
|
-
* `component?: SvelteComponent` (optional) - The wrapper will be a svelte component instead of a DOM
|
|
28
|
-
element. Props all get passed through.
|
|
29
|
-
* `a: boolean` (optional) - The wrapper will be a link element.
|
|
30
|
-
* `span: boolean` (optional) - The wrapper will be a span element.
|
|
31
|
-
* `element?: HTMLElement` (for binding) - If the wrapper is a DOM element, bind this prop to get a
|
|
32
|
-
reference to wrapper element (if it exists). If the wrapper is a svelte component, this will be
|
|
33
|
-
passed to it as a prop so that the wrapper component can bind it to a DOM element.
|
|
34
|
-
|
|
35
|
-
If none of `a`, `span`, or `component` props are specified, the default is to create a `div` wrapper.
|
package/docs/Modal.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Modal
|
|
2
|
-
The Modal component is designed to block out the screen and focus the user on the content inside the Modal.
|
|
3
|
-
|
|
4
|
-
It provides only the backdrop and a scrollable container for your content. If your content should have a background color, be sure to add it yourself.
|
|
5
|
-
|
|
6
|
-
Any time the Modal is in the DOM, it will take over the screen. You make it go away by removing it from the DOM.
|
|
7
|
-
|
|
8
|
-
## Example Usage
|
|
9
|
-
```svelte
|
|
10
|
-
<script>
|
|
11
|
-
let showMyModal = false
|
|
12
|
-
</script>
|
|
13
|
-
<button on:click={() => showMyModal = true}>Show Modal</button>
|
|
14
|
-
{#if showMyModal}
|
|
15
|
-
<Modal on:escape={() => showMyModal = false}>
|
|
16
|
-
This is a modal dialog!
|
|
17
|
-
</Modal>
|
|
18
|
-
{/if}
|
|
19
|
-
<style>
|
|
20
|
-
:global(.modal-container) { background: white; }
|
|
21
|
-
</style>
|
|
22
|
-
```
|
|
23
|
-
## Custom Events
|
|
24
|
-
* `on:escape` - dispatched when the user does something that would normally dismiss a modal, such as clicking in the darkened backdrop or pressing the Escape key. You should listen for this and dismiss your modal. If you do not listen for this event, users will only be able to escape by some other means provided within your content. Be careful not to trap them!
|
|
25
|
-
|
|
26
|
-
## Props
|
|
27
|
-
* `opaque: boolean` (default `false`) - Make the backdrop completely opaque so that it cannot be seen through. This is a more jarring experience for users but sometimes you don't want background content to be visible at all.
|
|
28
|
-
* `containerClass: string` (default `''`) - A class to be added to the scrollable container inside the backdrop. This container will always have the `.modal-container` class regardless of this prop.
|
|
29
|
-
* `escapable: boolean` (default `true`) - Let screen readers know that they can escape the modal by pressing the Escape key. If you are not listening for `on:escape` then you should set this `false` to avoid giving screen reader users false information.
|
|
30
|
-
* `hidefocus: boolean` (default `true`) - Focus must be moved to the modal when it opens, in order to maintain accessibility. This component avoids making the focus visible to users by default as it might be visually disconcerting. So on mount, focus is moved to an invisible element above your content. If you prefer focus to be visible to users, set this to `false` and focus will automatically be moved to the first element in your content that has a tabindex and therefore be visible to users. This prop is overridden if you provide an `initialfocus`.
|
|
31
|
-
* `hidefocuslabel: string` (default `focus is above modal dialog, start tabbing`) - The message that will be read out to users using a screen reader when the focus is on the invisible element created by the `hidefocus` prop.
|
|
32
|
-
* `initialfocus: string` (default `undefined`) - A selector to be used to locate and set focus on an element in your content, on mount. Use if you want focus on a specific element when the modal opens. Overrides `hidefocus`.
|
|
33
|
-
* `returnfocusto: HTMLElement` (default element that had focus was when modal opened) - Use to control where focus moves when the modal closes. If not provided, component automatically saves the element that had focus on mount. Usually it's the button that triggered the modal.
|
|
34
|
-
|
|
35
|
-
# FocusLock
|
|
36
|
-
The FocusLock component is for creating accessible modal dialogs that do not have a darkened backdrop. It shares many props and behaviors with Modal because the Modal component uses a FocusLock itself.
|
|
37
|
-
|
|
38
|
-
Any time the FocusLock is in the DOM, it will lock screen readers inside it. You release them by removing it from the DOM. Regular users are NOT trapped and may interact with other screen elements. When they do, the `escape` event will be fired, allowing you to remove the dialog.
|
|
39
|
-
|
|
40
|
-
FocusLocks can be nested. The user will be trapped inside the deepest FocusLock present in the DOM. When it goes away, they'll be trapped inside the previous FocusLock, and so on.
|
|
41
|
-
|
|
42
|
-
## Custom Events
|
|
43
|
-
* `on:escape` - dispatched when the user does something to dismiss the dialog, such as pressing the Escape key or clicking outside the dialog area. You should listen for this and remove the FocusLock. If you do not listen for this event, users will only be able to escape by some other means provided within your content. Be careful not to trap them!
|
|
44
|
-
|
|
45
|
-
## Example Usage
|
|
46
|
-
```svelte
|
|
47
|
-
<script>
|
|
48
|
-
let showMyDialog = false
|
|
49
|
-
</script>
|
|
50
|
-
<button on:click={() => showMyDialog = true}>Show Dialog</button>
|
|
51
|
-
{#if showMyDialog}
|
|
52
|
-
<FocusLock on:escape={() => showMyDialog = false}>
|
|
53
|
-
Screen readers cannot escape this!
|
|
54
|
-
<button on:click={() => showMyDialog = false}>Collapse Dialog</button>
|
|
55
|
-
</FocusLock>
|
|
56
|
-
{/if}
|
|
57
|
-
```
|
|
58
|
-
## Props
|
|
59
|
-
* `escapable: boolean` (default `true`) - Controls whether the focus lock can be easily escaped by pressing the Escape key or clicking the invisible focus (see `hidefocus`). If you set this `false` you must provide a way to dismiss the lock inside your content or screen readers will be trapped.
|
|
60
|
-
* `hidefocus: boolean` (default `true`) - Focus must be moved to the modal when it opens, in order to maintain accessibility. This component avoids making the focus visible to users by default as it might be visually disconcerting. So on mount, focus is moved to an invisible element above your content. If you prefer focus to be visible to users, set this to `false` and focus will automatically be moved to the first element in your content that has a tabindex and therefore be visible to users. This prop is overridden if you provide an `initialfocus`.
|
|
61
|
-
* `hidefocuslabel: string` (default `focus is above modal dialog, start tabbing`) - The message that will be read out to users using a screen reader when the focus is on the invisible element created by the `hidefocus` prop.
|
|
62
|
-
* `initialfocus: string` (default `undefined`) - A selector to be used to locate and set focus on an element in your content, on mount. Use if you want focus on a specific element when the lock mounts. Overrides `hidefocus`.
|
|
63
|
-
* `returnfocusto: HTMLElement` (default element that had focus was when focuslock mounted) - Use to control where focus moves when the lock ends. If not provided, component automatically saves the element that had focus on mount. Usually it's the button that triggered the dialog.
|
package/docs/PopupMenu.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# PopupMenu
|
|
2
|
-
|
|
3
|
-
This component is meant to display a menu of options to the user, activated by clicking
|
|
4
|
-
any element. It can also be controlled from the parent, by binding the `menushown` boolean.
|
|
5
|
-
|
|
6
|
-
## Props
|
|
7
|
-
* `buttonelement: HTMLElement` (required) - The DOM element that will act as the "button" for this menu. The menu will be placed next to the button and be controlled by the button. Keyboard access will be enabled when the button has focus. This component adds all appropriate attributes (tabindex, roles, and aria) automatically.
|
|
8
|
-
* `items: PopupMenuItem[]` (required) - The list of menu items to be shown. Parent may change this at any time based on user activity.
|
|
9
|
-
* `menushown?: boolean` (default `false`) - Bind this prop to track/change the visible state of the menu from the parent.
|
|
10
|
-
* `value?: string` (default no selection) - Bind this prop to track/change the currently selected value from the parent.
|
|
11
|
-
* `align?: GlueAlignOpts` (default `auto`) - Control where the menu will appear. Default is to use the current viewport to make a decision to maximize potential for menu growth.
|
|
12
|
-
* `cover?: boolean` (default `false`) - When the menu is active, should it cover the button or be rendered above/below it?
|
|
13
|
-
* `showSelected?: boolean` (default `true`) - When an item is currently selected, should it appear in the menu (with a visual indicator), or simply be removed from the list (showSelected: `false`)?
|
|
14
|
-
* `width?: string` (default `undefined`) - When defined, this width will be passed through to the menu's CSS width. Use a valid CSS dimension such as `33em` or `159px`. Generally this will be used when you need to match the menu width to something else, like the button. If the width is static like `100%` a simple CSS rule is likely more efficient.
|
|
15
|
-
* `computedalign: readable<{ valign: 'top'|'bottom', halign: 'left'|'right' }>` (default store is provided) - Bind this prop to receive a store that is updated each time a menu placement decision is made. Example of when this is useful is when you are trying to round corners of your button and need to know whether the menu is above or below your button so you know which corners to round and which to leave square. Note that the values do not update when the menu is hidden, so you may need to rely on `menushown` as well.
|
|
16
|
-
* `usePortal?: HTMLElement|true` (default `false`) - If the menu would be clipped by an `overflow: hidden`, you can set this prop and it will be placed in the specified container, or the `document.body` if you simply say `true`. Placement will still be calculated correctly, unless there are scrolling containers between the button and the menu.
|
|
17
|
-
* `emptyText?: string` (default `¯\_(ツ)_/¯`) - When there are no items (e.g. it's a filtered search and there were no results), we still display one disabled item in the menu to let the user know what is going on. Use this prop to specify the message.
|
|
18
|
-
* `menuContainerClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
|
|
19
|
-
* `menuClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
|
|
20
|
-
* `menuItemClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
|
|
21
|
-
* `menuItemHilitedClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
|
|
22
|
-
* `menuItemSelectedClass?: string` (default `''`) - CSS class to pass through so you can do extra styling work
|
|
23
|
-
|
|
24
|
-
## Events
|
|
25
|
-
* `on:change` - Dispatched any time a new value is selected. Does not fire when you change the `value` property from the outside. Event detail will be the full PopupMenuItem object that was selected.
|
|
26
|
-
|
|
27
|
-
## Types
|
|
28
|
-
* `PopupMenuItem: { value: string, label?: string, disabled?: boolean }` - Each item must have a unique non-empty value. Display label is optional, as is a `disabled` status that will show the item in the list but not allow users to hilite or select it.
|
|
29
|
-
|
|
30
|
-
## Disabling
|
|
31
|
-
Since there are so many different possibilities for the button you attach to, the PopupMenu does not have a `disabled` prop. If the PopupMenu should be disabled, simply remove it from the DOM with an `{#if}` block. Remember to also set `aria-disabled` on your button and likely provide some visual indicators like `cursor: default` or the `disabled` attribute on elements that support it.
|
package/docs/ScreenReaderOnly.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# ScreenReaderOnly
|
|
2
|
-
This component is for adding text that can be read to screen readers while remaining
|
|
3
|
-
invisible to regular users. It accepts `arialive` and `ariaatomic` props to pass through to
|
|
4
|
-
the corresponding HTML attributes. It also accepts an `id` prop in case you need to
|
|
5
|
-
point at it with an aria-describedby attribute on some other element.
|
|
6
|
-
|
|
7
|
-
Using this component is often better than using aria-label because aria-label still has poor support
|
|
8
|
-
and sometimes is not good enough to make WAVE happy with an empty icon-link. It's also a
|
|
9
|
-
good way to add additional text when sighted users have a little text already, e.g. to add
|
|
10
|
-
interactivity instructions.
|