@txstate-mws/svelte-components 1.0.2 → 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/README.md +33 -14
- package/{dist/ts/actions → actions}/buttonify.d.ts +0 -0
- package/{dist/actions → actions}/buttonify.js +1 -6
- package/{dist/ts/actions → actions}/glue.d.ts +1 -1
- package/{dist/actions → actions}/glue.js +8 -13
- 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/{dist/ts/actions → actions}/portal.d.ts +0 -0
- package/actions/portal.js +13 -0
- package/{dist/ts/actions → actions}/resize.d.ts +6 -2
- package/actions/resize.js +57 -0
- package/{dist/ts/actions → actions}/sticky.d.ts +2 -2
- package/{dist/actions → actions}/sticky.js +11 -19
- package/{dist/ts/actions → actions}/stickyfixed.d.ts +2 -2
- package/{dist/actions → actions}/stickyfixed.js +15 -24
- 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/{dist/components → components}/CollapsingTable.svelte +12 -13
- package/components/CollapsingTable.svelte.d.ts +59 -0
- package/{dist/ts/components → components}/ConditionalWrapper.svelte +6 -7
- package/components/ConditionalWrapper.svelte.d.ts +23 -0
- package/{dist/components → components}/FocusLock.svelte +11 -9
- package/components/FocusLock.svelte.d.ts +26 -0
- package/{dist/components → components}/Modal.svelte +5 -4
- package/components/Modal.svelte.d.ts +27 -0
- package/components/MultiSelect.svelte +179 -0
- package/components/MultiSelect.svelte.d.ts +35 -0
- package/{dist/components → components}/PopupMenu.svelte +29 -24
- package/components/PopupMenu.svelte.d.ts +45 -0
- package/{dist/components → components}/ScreenReaderOnly.svelte +1 -1
- package/components/ScreenReaderOnly.svelte.d.ts +20 -0
- package/{dist/ts/components → components}/index.d.ts +3 -0
- package/components/index.js +9 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +47 -77
- package/types/CardLayout.d.ts +14 -0
- package/types/CardLayout.js +1 -0
- package/{dist/ts/types → types}/CollapsingTable.d.ts +0 -0
- package/{dist/ts/tests/Actions/Actions.stories.d.ts → types/CollapsingTable.js} +0 -0
- package/{dist/ts/types → types}/PopupMenu.d.ts +0 -0
- package/{dist/ts/tests/CollapsingTable/CollapsingTable.stories.d.ts → types/PopupMenu.js} +0 -0
- package/types/index.d.ts +3 -0
- package/types/index.js +3 -0
- package/{dist/ts/lib → util}/bodyoffset.d.ts +2 -1
- package/{dist/lib → util}/bodyoffset.js +10 -14
- package/util/index.d.ts +3 -0
- package/util/index.js +3 -0
- package/{dist/ts/lib → util}/repositioned.d.ts +1 -2
- package/{dist/lib → util}/repositioned.js +13 -24
- package/util/util.d.ts +5 -0
- package/util/util.js +33 -0
- package/LICENSE +0 -21
- package/dist/actions/buttonify.js.map +0 -1
- package/dist/actions/glue.js.map +0 -1
- package/dist/actions/index.js +0 -20
- package/dist/actions/index.js.map +0 -1
- package/dist/actions/offset.js +0 -35
- package/dist/actions/offset.js.map +0 -1
- package/dist/actions/portal.js +0 -19
- package/dist/actions/portal.js.map +0 -1
- package/dist/actions/resize.js +0 -48
- package/dist/actions/resize.js.map +0 -1
- package/dist/actions/sticky.js.map +0 -1
- package/dist/actions/stickyfixed.js.map +0 -1
- package/dist/components/ConditionalWrapper.svelte +0 -38
- package/dist/components/index.js +0 -19
- package/dist/components/index.js.map +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/lib/activestore.js +0 -123
- package/dist/lib/activestore.js.map +0 -1
- package/dist/lib/bodyoffset.js.map +0 -1
- package/dist/lib/convertedstore.js +0 -41
- package/dist/lib/convertedstore.js.map +0 -1
- package/dist/lib/derivedstore.js +0 -65
- package/dist/lib/derivedstore.js.map +0 -1
- package/dist/lib/index.js +0 -22
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/repositioned.js.map +0 -1
- package/dist/lib/safestore.js +0 -16
- package/dist/lib/safestore.js.map +0 -1
- package/dist/lib/store.js +0 -27
- package/dist/lib/store.js.map +0 -1
- package/dist/lib/substore.js +0 -47
- package/dist/lib/substore.js.map +0 -1
- package/dist/lib/util.js +0 -16
- package/dist/lib/util.js.map +0 -1
- package/dist/ts/actions/index.d.ts +0 -7
- package/dist/ts/actions/offset.d.ts +0 -15
- package/dist/ts/components/CollapsingTable.svelte +0 -147
- package/dist/ts/components/FocusLock.svelte +0 -101
- package/dist/ts/components/Modal.svelte +0 -54
- package/dist/ts/components/PopupMenu.svelte +0 -279
- package/dist/ts/components/ScreenReaderOnly.svelte +0 -26
- package/dist/ts/index.d.ts +0 -4
- package/dist/ts/lib/activestore.d.ts +0 -60
- package/dist/ts/lib/convertedstore.d.ts +0 -16
- package/dist/ts/lib/derivedstore.d.ts +0 -23
- package/dist/ts/lib/index.d.ts +0 -9
- package/dist/ts/lib/safestore.d.ts +0 -4
- package/dist/ts/lib/store.d.ts +0 -16
- package/dist/ts/lib/substore.d.ts +0 -24
- package/dist/ts/lib/util.d.ts +0 -2
- package/dist/ts/tests/Actions/Offset.svelte +0 -34
- package/dist/ts/tests/Actions/Resize.svelte +0 -31
- package/dist/ts/tests/Actions/Sticky.svelte +0 -65
- package/dist/ts/tests/CollapsingTable/CollapsingTable.test.d.ts +0 -1
- package/dist/ts/tests/CollapsingTable/CollapsingTableTest.svelte +0 -36
- package/dist/ts/tests/Modal/Modal.stories.d.ts +0 -1
- package/dist/ts/tests/Modal/Modal.test.d.ts +0 -1
- package/dist/ts/tests/Modal/ModalTest.svelte +0 -58
- package/dist/ts/tests/PopupMenu/PopupMenu.stories.d.ts +0 -1
- package/dist/ts/tests/PopupMenu/PopupMenu.test.d.ts +0 -1
- package/dist/ts/tests/PopupMenu/PopupMenuBody.svelte +0 -34
- package/dist/ts/tests/PopupMenu/PopupMenuButtonIsParent.svelte +0 -36
- package/dist/ts/tests/PopupMenu/PopupMenuComplex.svelte +0 -34
- package/dist/ts/tests/PopupMenu/PopupMenuSimple.svelte +0 -36
- package/dist/ts/tests/stores/deepstore.test.d.ts +0 -1
- package/dist/ts/types/index.d.ts +0 -2
- package/dist/types/CollapsingTable.js +0 -3
- package/dist/types/CollapsingTable.js.map +0 -1
- package/dist/types/PopupMenu.js +0 -3
- package/dist/types/PopupMenu.js.map +0 -1
- package/dist/types/index.js +0 -15
- package/dist/types/index.js.map +0 -1
- 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/esm/index.js +0 -1
- package/esm/package.json +0 -3
package/README.md
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
# svelte-components
|
|
2
2
|
A set of generically useful components for svelte.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
[CollapsingTable](/docs/CollapsingTable.md)
|
|
6
|
-
[ConditionalWrapper](/docs/ConditionalWrapper.md)
|
|
7
|
-
[FocusLock](/docs/Modal.md#FocusLock)
|
|
8
|
-
[Modal](/docs/Modal.md#Modal)
|
|
9
|
-
[PopupMenu](/docs/PopupMenu.md)
|
|
10
|
-
[ScreenReaderOnly](/docs/ScreenReaderOnly.md)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[use:buttonify](/docs/actions.md#use:buttonify)
|
|
14
|
-
[use:glue](/docs/actions.md#use:glue)
|
|
15
|
-
[use:offset](/docs/actions.md#use:offset)
|
|
16
|
-
[use:portal](/docs/actions.md#use:portal)
|
|
17
|
-
[use:resize](/docs/actions.md#use:resize)
|
|
4
|
+
## Components
|
|
5
|
+
- [CollapsingTable](/docs/CollapsingTable.md)
|
|
6
|
+
- [ConditionalWrapper](/docs/ConditionalWrapper.md)
|
|
7
|
+
- [FocusLock](/docs/Modal.md#FocusLock)
|
|
8
|
+
- [Modal](/docs/Modal.md#Modal)
|
|
9
|
+
- [PopupMenu](/docs/PopupMenu.md)
|
|
10
|
+
- [ScreenReaderOnly](/docs/ScreenReaderOnly.md)
|
|
11
|
+
|
|
12
|
+
## Actions
|
|
13
|
+
- [use:buttonify](/docs/actions.md#use:buttonify)
|
|
14
|
+
- [use:glue](/docs/actions.md#use:glue)
|
|
15
|
+
- [use:offset](/docs/actions.md#use:offset)
|
|
16
|
+
- [use:portal](/docs/actions.md#use:portal)
|
|
17
|
+
- [use:resize](/docs/actions.md#use:resize)
|
|
18
|
+
|
|
19
|
+
## Developing
|
|
20
|
+
|
|
21
|
+
Installed dependencies with `npm install`, then start the development server:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run dev
|
|
25
|
+
|
|
26
|
+
# or start the server and open the app in a new browser tab
|
|
27
|
+
npm run dev -- --open
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Publishing to npm
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm run package
|
|
34
|
+
cd package
|
|
35
|
+
npm publish
|
|
36
|
+
```
|
|
File without changes
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buttonify = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Turns any HTML element into an accessible button that responds to keyboard events and has
|
|
6
3
|
* role="button" and the tabindex attribute set. You are still responsible for making sure it has
|
|
7
4
|
* readable content or a good label.
|
|
8
5
|
*/
|
|
9
|
-
function buttonify(node) {
|
|
6
|
+
export function buttonify(node) {
|
|
10
7
|
function keydown(e) {
|
|
11
8
|
if (e.key === 'Enter') {
|
|
12
9
|
if (!e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
@@ -27,5 +24,3 @@ function buttonify(node) {
|
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
exports.buttonify = buttonify;
|
|
31
|
-
//# sourceMappingURL=buttonify.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SettableSubject } from '
|
|
1
|
+
import type { SettableSubject } from '@txstate-mws/svelte-store';
|
|
2
2
|
export declare type GlueAlignOpts = 'auto' | 'bottomleft' | 'bottomright' | 'topleft' | 'topright';
|
|
3
3
|
export interface GlueArgs<T extends GlueAlignStore = GlueAlignStore> {
|
|
4
4
|
target: HTMLElement;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.glue = void 0;
|
|
4
|
-
const lib_1 = require("../lib");
|
|
1
|
+
import { sharedOffsetParent, targetOffset, watchForPositionChangeInContainer } from '../util/index.js';
|
|
5
2
|
let setBodyRelative = false;
|
|
6
|
-
function glue(el, { target, align = 'auto', cover = false, store }) {
|
|
3
|
+
export function glue(el, { target, align = 'auto', cover = false, store }) {
|
|
7
4
|
if (!setBodyRelative) {
|
|
8
5
|
setBodyRelative = true;
|
|
9
6
|
document.body.style.position = 'relative';
|
|
10
7
|
}
|
|
11
8
|
let halign;
|
|
12
9
|
let valign;
|
|
13
|
-
let sharedOffset =
|
|
10
|
+
let sharedOffset = sharedOffsetParent(el, target);
|
|
14
11
|
function reposition(offset) {
|
|
15
12
|
if (!target || !sharedOffset || !(el.offsetParent instanceof HTMLElement))
|
|
16
13
|
return;
|
|
17
14
|
let autoalign = align;
|
|
18
|
-
const parentoffset = el.offsetParent === sharedOffset && target !== sharedOffset ? { top: 0, left: 0, bottom: 0, right: 0 } :
|
|
15
|
+
const parentoffset = el.offsetParent === sharedOffset && target !== sharedOffset ? { top: 0, left: 0, bottom: 0, right: 0 } : targetOffset(el.offsetParent, sharedOffset);
|
|
19
16
|
if (align === 'auto') {
|
|
20
17
|
const rect = target.getBoundingClientRect();
|
|
21
18
|
const leftright = window.innerWidth - rect.right > rect.left ? 'left' : 'right';
|
|
@@ -63,19 +60,19 @@ function glue(el, { target, align = 'auto', cover = false, store }) {
|
|
|
63
60
|
valign = 'top';
|
|
64
61
|
halign = 'right';
|
|
65
62
|
}
|
|
66
|
-
store
|
|
63
|
+
store?.update(v => ({ ...v, valign, halign }));
|
|
67
64
|
}
|
|
68
|
-
const { destroy, update } =
|
|
65
|
+
const { destroy, update } = watchForPositionChangeInContainer(target, sharedOffset, reposition);
|
|
69
66
|
return {
|
|
70
67
|
update({ target: utarget, align: ualign = 'auto', cover: ucover = false, store: ustore }) {
|
|
71
68
|
align = ualign;
|
|
72
69
|
cover = ucover;
|
|
73
70
|
if (ustore && ustore !== store) {
|
|
74
|
-
ustore.update(v => (
|
|
71
|
+
ustore.update(v => ({ ...v, valign, halign }));
|
|
75
72
|
store = ustore;
|
|
76
73
|
}
|
|
77
74
|
if (target !== utarget) {
|
|
78
|
-
sharedOffset =
|
|
75
|
+
sharedOffset = sharedOffsetParent(el, utarget);
|
|
79
76
|
target = utarget;
|
|
80
77
|
update(target, sharedOffset, reposition);
|
|
81
78
|
}
|
|
@@ -83,5 +80,3 @@ function glue(el, { target, align = 'auto', cover = false, store }) {
|
|
|
83
80
|
destroy
|
|
84
81
|
};
|
|
85
82
|
}
|
|
86
|
-
exports.glue = glue;
|
|
87
|
-
//# sourceMappingURL=glue.js.map
|
package/actions/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Store } from '@txstate-mws/svelte-store';
|
|
2
|
+
import type { WritableSubject } from '@txstate-mws/svelte-store';
|
|
3
|
+
import type { ElementOffsets } from '../util/index.js';
|
|
4
|
+
interface OffsetConfig<T extends ElementOffsets = ElementOffsets> {
|
|
5
|
+
debounce?: boolean | number;
|
|
6
|
+
store?: WritableSubject<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare class OffsetStore extends Store<ElementOffsets> {
|
|
9
|
+
constructor(initialState?: ElementOffsets);
|
|
10
|
+
}
|
|
11
|
+
export declare function offset(el: HTMLElement, config?: OffsetConfig): {
|
|
12
|
+
update(newConfig?: OffsetConfig): void;
|
|
13
|
+
destroy: () => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Store } from '@txstate-mws/svelte-store';
|
|
2
|
+
import { debounced, watchForPositionChange } from '../util/index.js';
|
|
3
|
+
export class OffsetStore extends Store {
|
|
4
|
+
constructor(initialState) {
|
|
5
|
+
super(initialState ?? { top: 0, right: 0, bottom: 0, left: 0 });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function offset(el, config) {
|
|
9
|
+
if (config?.debounce === true)
|
|
10
|
+
config.debounce = 100;
|
|
11
|
+
let lastOffset = {};
|
|
12
|
+
function lookforoffsetchange(current) {
|
|
13
|
+
lastOffset = current;
|
|
14
|
+
if (config?.store)
|
|
15
|
+
config.store.update(v => ({ ...v, ...current }));
|
|
16
|
+
el.dispatchEvent(new CustomEvent('offset', { detail: current }));
|
|
17
|
+
}
|
|
18
|
+
let resolvedchange = config?.debounce ? debounced(lookforoffsetchange, config.debounce) : lookforoffsetchange;
|
|
19
|
+
const { destroy, update } = watchForPositionChange(el, resolvedchange);
|
|
20
|
+
return {
|
|
21
|
+
update(newConfig) {
|
|
22
|
+
if (newConfig?.debounce === true)
|
|
23
|
+
newConfig.debounce = 100;
|
|
24
|
+
if (newConfig?.store !== config?.store) {
|
|
25
|
+
newConfig?.store?.update(v => ({ ...v, ...lastOffset }));
|
|
26
|
+
}
|
|
27
|
+
if (newConfig?.debounce !== config?.debounce) {
|
|
28
|
+
resolvedchange = newConfig?.debounce ? debounced(lookforoffsetchange, newConfig.debounce) : lookforoffsetchange;
|
|
29
|
+
update(el, resolvedchange);
|
|
30
|
+
}
|
|
31
|
+
config = newConfig;
|
|
32
|
+
},
|
|
33
|
+
destroy
|
|
34
|
+
};
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Store } from '@txstate-mws/svelte-store';
|
|
2
|
+
import type { SettableSubject } from '@txstate-mws/svelte-store';
|
|
2
3
|
export interface ElementSize {
|
|
3
4
|
clientWidth?: number;
|
|
4
5
|
clientHeight?: number;
|
|
@@ -9,8 +10,11 @@ interface ResizeConfig {
|
|
|
9
10
|
debounce?: boolean | number;
|
|
10
11
|
store?: SettableSubject<ElementSize>;
|
|
11
12
|
}
|
|
13
|
+
export declare class ResizeStore extends Store<ElementSize> {
|
|
14
|
+
constructor(initialState?: ElementSize);
|
|
15
|
+
}
|
|
12
16
|
export declare function resize(el: HTMLElement, config?: ResizeConfig): void | {
|
|
13
|
-
update(newConfig?: ResizeConfig
|
|
17
|
+
update(newConfig?: ResizeConfig): void;
|
|
14
18
|
destroy(): void;
|
|
15
19
|
};
|
|
16
20
|
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { equal } from 'txstate-utils';
|
|
2
|
+
import { Store } from '@txstate-mws/svelte-store';
|
|
3
|
+
import { debounced } from '../util/index.js';
|
|
4
|
+
export class ResizeStore extends Store {
|
|
5
|
+
constructor(initialState) {
|
|
6
|
+
super(initialState ?? typeof window === 'undefined'
|
|
7
|
+
? {
|
|
8
|
+
clientWidth: 1024,
|
|
9
|
+
clientHeight: 1024,
|
|
10
|
+
offsetWidth: 1024,
|
|
11
|
+
offsetHeight: 1024
|
|
12
|
+
}
|
|
13
|
+
: {
|
|
14
|
+
clientWidth: window.innerWidth,
|
|
15
|
+
clientHeight: window.innerHeight,
|
|
16
|
+
offsetWidth: window.innerWidth,
|
|
17
|
+
offsetHeight: window.innerHeight
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function resize(el, config) {
|
|
22
|
+
if (config?.debounce === true)
|
|
23
|
+
config.debounce = 100;
|
|
24
|
+
let lastSize = {};
|
|
25
|
+
function watch() {
|
|
26
|
+
const current = { clientWidth: el.clientWidth, clientHeight: el.clientHeight, offsetWidth: el.offsetWidth, offsetHeight: el.offsetHeight };
|
|
27
|
+
if (!equal(lastSize, current)) {
|
|
28
|
+
lastSize = current;
|
|
29
|
+
if (config?.store)
|
|
30
|
+
config.store.set(current);
|
|
31
|
+
el.dispatchEvent(new CustomEvent('resize', { detail: current }));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (typeof ResizeObserver === 'undefined')
|
|
35
|
+
return watch(); // support SSR
|
|
36
|
+
let observer = new ResizeObserver(config?.debounce ? debounced(watch, config.debounce) : watch);
|
|
37
|
+
observer.observe(el);
|
|
38
|
+
watch();
|
|
39
|
+
return {
|
|
40
|
+
update(newConfig) {
|
|
41
|
+
if (newConfig?.debounce === true)
|
|
42
|
+
newConfig.debounce = 100;
|
|
43
|
+
if (newConfig?.store !== config?.store) {
|
|
44
|
+
newConfig?.store?.set(lastSize);
|
|
45
|
+
}
|
|
46
|
+
if (!!newConfig?.debounce !== !!config?.debounce) {
|
|
47
|
+
observer.disconnect();
|
|
48
|
+
observer = new ResizeObserver(newConfig?.debounce ? debounced(watch, newConfig.debounce) : watch);
|
|
49
|
+
observer.observe(el);
|
|
50
|
+
}
|
|
51
|
+
config = newConfig;
|
|
52
|
+
},
|
|
53
|
+
destroy() {
|
|
54
|
+
observer.disconnect();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SettableSubject } from '
|
|
1
|
+
import type { SettableSubject } from '@txstate-mws/svelte-store';
|
|
2
2
|
export interface StickyArgs<T extends StickyStore = StickyStore> {
|
|
3
3
|
target?: HTMLElement;
|
|
4
4
|
store?: SettableSubject<T>;
|
|
@@ -28,6 +28,6 @@ export interface StickyStore {
|
|
|
28
28
|
* fragile if your markup/CSS situation is very complex.
|
|
29
29
|
*/
|
|
30
30
|
export declare function sticky(el: HTMLElement, config?: StickyArgs): {
|
|
31
|
-
update: (newConfig?: StickyArgs
|
|
31
|
+
update: (newConfig?: StickyArgs) => void;
|
|
32
32
|
destroy: () => void;
|
|
33
33
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sticky = void 0;
|
|
4
|
-
const lib_1 = require("../lib");
|
|
1
|
+
import { bodyOffset, watchForPositionChange } from '../util/index.js';
|
|
5
2
|
let scrolled = false;
|
|
6
3
|
/**
|
|
7
4
|
* A robust implementation of stickyness based on `transform: translateY()`. Only use when
|
|
@@ -23,22 +20,21 @@ let scrolled = false;
|
|
|
23
20
|
* and therefore animates better than this. However, it has a lot more work to do and is more
|
|
24
21
|
* fragile if your markup/CSS situation is very complex.
|
|
25
22
|
*/
|
|
26
|
-
function sticky(el, config) {
|
|
23
|
+
export function sticky(el, config) {
|
|
27
24
|
let floating;
|
|
28
25
|
let translateY;
|
|
29
26
|
let scrollstart = Number.MAX_SAFE_INTEGER;
|
|
30
27
|
let scrollend = Number.MAX_SAFE_INTEGER;
|
|
31
28
|
function recalc(scroll) {
|
|
32
|
-
var _a;
|
|
33
29
|
const newTranslateY = Math.max(Math.min(scroll, scrollend) - scrollstart, 0);
|
|
34
30
|
if (newTranslateY !== translateY) {
|
|
35
31
|
el.style.transform = `translateY(${newTranslateY}px)`;
|
|
36
32
|
translateY = newTranslateY;
|
|
37
33
|
floating = scroll >= scrollstart;
|
|
38
|
-
|
|
34
|
+
config?.store?.update(v => ({ ...v, translateY, floating }));
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
|
-
function onscroll(
|
|
37
|
+
function onscroll(_) {
|
|
42
38
|
recalc(window.scrollY);
|
|
43
39
|
}
|
|
44
40
|
function onwheel(e) {
|
|
@@ -55,29 +51,27 @@ function sticky(el, config) {
|
|
|
55
51
|
}
|
|
56
52
|
let lastOffsetParent = el.offsetParent;
|
|
57
53
|
function onpositionchange(offset) {
|
|
58
|
-
var _a;
|
|
59
54
|
const offsetParent = el.offsetParent;
|
|
60
55
|
if (!(offsetParent instanceof HTMLElement))
|
|
61
56
|
return;
|
|
62
57
|
if (lastOffsetParent !== offsetParent) {
|
|
63
|
-
offset[0] =
|
|
58
|
+
offset[0] = bodyOffset(offsetParent);
|
|
64
59
|
update(offsetParent, onpositionchange);
|
|
65
60
|
lastOffsetParent = offsetParent;
|
|
66
61
|
}
|
|
67
62
|
scrollstart = offset[0].top + el.offsetTop;
|
|
68
|
-
const containeroffset =
|
|
69
|
-
scrollend = Math.max(scrollstart, containeroffset.top + (
|
|
63
|
+
const containeroffset = config?.target ? offset[1] : offset[0];
|
|
64
|
+
scrollend = Math.max(scrollstart, containeroffset.top + (config?.target ?? offsetParent).clientHeight - el.offsetHeight);
|
|
70
65
|
recalc(window.scrollY);
|
|
71
66
|
}
|
|
72
|
-
const { destroy, update } =
|
|
67
|
+
const { destroy, update } = watchForPositionChange([el.offsetParent, config?.target], onpositionchange);
|
|
73
68
|
window.addEventListener('scroll', onscroll, { passive: true });
|
|
74
69
|
window.addEventListener('wheel', onwheel, { passive: false });
|
|
75
70
|
function stickyUpdate(newConfig) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(_a = newConfig === null || newConfig === void 0 ? void 0 : newConfig.store) === null || _a === void 0 ? void 0 : _a.update(v => (Object.assign(Object.assign({}, v), { translateY, floating })));
|
|
71
|
+
if (newConfig?.store !== config?.store)
|
|
72
|
+
newConfig?.store?.update(v => ({ ...v, translateY, floating }));
|
|
79
73
|
config = newConfig;
|
|
80
|
-
update([el.offsetParent, config
|
|
74
|
+
update([el.offsetParent, config?.target], onpositionchange);
|
|
81
75
|
}
|
|
82
76
|
function stickyDestroy() {
|
|
83
77
|
window.removeEventListener('scroll', onscroll);
|
|
@@ -89,5 +83,3 @@ function sticky(el, config) {
|
|
|
89
83
|
destroy: stickyDestroy
|
|
90
84
|
};
|
|
91
85
|
}
|
|
92
|
-
exports.sticky = sticky;
|
|
93
|
-
//# sourceMappingURL=sticky.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StickyArgs } from './sticky';
|
|
1
|
+
import type { StickyArgs } from './sticky.js';
|
|
2
2
|
/**
|
|
3
3
|
* An implementation of stickyness based on `positon: fixed`. Only use when
|
|
4
4
|
* `position: sticky` won't work for you. If `position: sticky` does work for you, use it,
|
|
@@ -20,6 +20,6 @@ import { StickyArgs } from './sticky';
|
|
|
20
20
|
* so it will visually lag a bit on mobile.
|
|
21
21
|
*/
|
|
22
22
|
export declare function stickyfixed(el: HTMLElement, config?: StickyArgs): {
|
|
23
|
-
update: (newConfig?: StickyArgs
|
|
23
|
+
update: (newConfig?: StickyArgs) => void;
|
|
24
24
|
destroy: () => void;
|
|
25
25
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stickyfixed = void 0;
|
|
4
|
-
const lib_1 = require("../lib");
|
|
1
|
+
import { bodyOffset, watchForPositionChange } from '../util/index.js';
|
|
5
2
|
/**
|
|
6
3
|
* An implementation of stickyness based on `positon: fixed`. Only use when
|
|
7
4
|
* `position: sticky` won't work for you. If `position: sticky` does work for you, use it,
|
|
@@ -22,7 +19,7 @@ const lib_1 = require("../lib");
|
|
|
22
19
|
* and is less fragile than this. However, it cannot do its work before the scroll on mobile, only after,
|
|
23
20
|
* so it will visually lag a bit on mobile.
|
|
24
21
|
*/
|
|
25
|
-
function stickyfixed(el, config) {
|
|
22
|
+
export function stickyfixed(el, config) {
|
|
26
23
|
let floating;
|
|
27
24
|
let translateY;
|
|
28
25
|
let scrollstart = Number.MAX_SAFE_INTEGER;
|
|
@@ -32,10 +29,9 @@ function stickyfixed(el, config) {
|
|
|
32
29
|
let left;
|
|
33
30
|
let top = 0;
|
|
34
31
|
function generatespacer(mutations) {
|
|
35
|
-
|
|
36
|
-
if (mutations === null || mutations === void 0 ? void 0 : mutations.every(m => m.attributeName === 'style'))
|
|
32
|
+
if (mutations?.every(m => m.attributeName === 'style'))
|
|
37
33
|
return;
|
|
38
|
-
spacer
|
|
34
|
+
spacer?.remove();
|
|
39
35
|
spacer = el.cloneNode(true);
|
|
40
36
|
spacer.setAttribute('aria-hidden', 'true');
|
|
41
37
|
spacer.style.position = '';
|
|
@@ -46,7 +42,7 @@ function stickyfixed(el, config) {
|
|
|
46
42
|
for (const td of tds)
|
|
47
43
|
td.style.width = '';
|
|
48
44
|
if (floating)
|
|
49
|
-
|
|
45
|
+
el.parentElement?.insertBefore(spacer, el);
|
|
50
46
|
}
|
|
51
47
|
const mutationobserver = new MutationObserver(generatespacer);
|
|
52
48
|
mutationobserver.observe(el, {
|
|
@@ -85,14 +81,13 @@ function stickyfixed(el, config) {
|
|
|
85
81
|
}
|
|
86
82
|
const resizeobserver = new ResizeObserver(adjustwidths);
|
|
87
83
|
function recalc(scroll) {
|
|
88
|
-
var _a, _b;
|
|
89
84
|
const newTranslateY = Math.max(Math.min(scroll - 1, scrollend) - scrollstart, 0);
|
|
90
85
|
const newFloating = newTranslateY > 0;
|
|
91
86
|
const newTop = Math.max(Math.min(scrollend - scroll, 0), -2 * elheight);
|
|
92
87
|
if (newFloating !== floating) {
|
|
93
88
|
floating = newFloating;
|
|
94
89
|
if (floating) {
|
|
95
|
-
|
|
90
|
+
el.parentElement?.insertBefore(spacer, el);
|
|
96
91
|
el.style.position = 'fixed';
|
|
97
92
|
el.style.top = `${Math.min(scrollend - scroll, 0)}px`;
|
|
98
93
|
el.style.left = `${left}px`;
|
|
@@ -109,7 +104,7 @@ function stickyfixed(el, config) {
|
|
|
109
104
|
}
|
|
110
105
|
if (newTranslateY !== translateY) {
|
|
111
106
|
translateY = newTranslateY;
|
|
112
|
-
|
|
107
|
+
config?.store?.update(v => ({ ...v, translateY, floating }));
|
|
113
108
|
}
|
|
114
109
|
if (top !== newTop) {
|
|
115
110
|
top = newTop;
|
|
@@ -117,17 +112,16 @@ function stickyfixed(el, config) {
|
|
|
117
112
|
el.style.top = `${top}px`;
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
|
-
function onscroll(
|
|
115
|
+
function onscroll(_) {
|
|
121
116
|
recalc(window.scrollY);
|
|
122
117
|
}
|
|
123
118
|
let lastOffsetParent = el.offsetParent;
|
|
124
119
|
function onpositionchange(offset) {
|
|
125
|
-
var _a, _b;
|
|
126
120
|
const offsetParent = el.offsetParent;
|
|
127
121
|
if (!(offsetParent instanceof HTMLElement))
|
|
128
122
|
return;
|
|
129
123
|
if (lastOffsetParent !== offsetParent) {
|
|
130
|
-
offset[0] =
|
|
124
|
+
offset[0] = bodyOffset(offsetParent);
|
|
131
125
|
update(offsetParent, onpositionchange);
|
|
132
126
|
lastOffsetParent = offsetParent;
|
|
133
127
|
}
|
|
@@ -138,18 +132,17 @@ function stickyfixed(el, config) {
|
|
|
138
132
|
if (el.tagName === 'TR') {
|
|
139
133
|
scrollstart -= borderspacing;
|
|
140
134
|
}
|
|
141
|
-
const containeroffset =
|
|
142
|
-
scrollend = Math.max(scrollstart, containeroffset.top + (
|
|
135
|
+
const containeroffset = config?.target ? offset[1] ?? offset[0] : offset[0];
|
|
136
|
+
scrollend = Math.max(scrollstart, containeroffset.top + (config?.target ?? offsetParent).clientHeight - el.offsetHeight);
|
|
143
137
|
recalc(window.scrollY);
|
|
144
138
|
}
|
|
145
|
-
const { destroy, update } =
|
|
139
|
+
const { destroy, update } = watchForPositionChange([el.offsetParent, config?.target], onpositionchange);
|
|
146
140
|
window.addEventListener('scroll', onscroll, { passive: true });
|
|
147
141
|
function stickyUpdate(newConfig) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
(_a = newConfig === null || newConfig === void 0 ? void 0 : newConfig.store) === null || _a === void 0 ? void 0 : _a.update(v => (Object.assign(Object.assign({}, v), { translateY, floating })));
|
|
142
|
+
if (newConfig?.store !== config?.store)
|
|
143
|
+
newConfig?.store?.update(v => ({ ...v, translateY, floating }));
|
|
151
144
|
config = newConfig;
|
|
152
|
-
update([el.offsetParent, config
|
|
145
|
+
update([el.offsetParent, config?.target], onpositionchange);
|
|
153
146
|
}
|
|
154
147
|
function stickyDestroy() {
|
|
155
148
|
resizeobserver.disconnect();
|
|
@@ -162,5 +155,3 @@ function stickyfixed(el, config) {
|
|
|
162
155
|
destroy: stickyDestroy
|
|
163
156
|
};
|
|
164
157
|
}
|
|
165
|
-
exports.stickyfixed = stickyfixed;
|
|
166
|
-
//# sourceMappingURL=stickyfixed.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script >export let className = '';
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import { resize } from '../actions';
|
|
4
|
+
import { CARDLAYOUT } from '../types';
|
|
5
|
+
const block = { element: undefined };
|
|
6
|
+
const { registerBlock, gutter, recalculate } = getContext(CARDLAYOUT);
|
|
7
|
+
const { width, order, linebreak } = registerBlock(block);
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<li class="cardlayout-card {className}" bind:this={block.element} use:resize on:resize={recalculate} style="margin-bottom: {$gutter}px; width: {$width}; order: {$order};">
|
|
11
|
+
<slot></slot>
|
|
12
|
+
</li>
|
|
13
|
+
{#if $linebreak}
|
|
14
|
+
<li aria-hidden="true" class="cardlayout-columnbreak" style:order={$order}></li>
|
|
15
|
+
{/if}
|
|
16
|
+
|
|
17
|
+
<style>
|
|
18
|
+
.cardlayout-columnbreak {
|
|
19
|
+
width: 0;
|
|
20
|
+
height: 100%;
|
|
21
|
+
visibility: hidden;
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
className?: string;
|
|
5
|
+
};
|
|
6
|
+
events: {
|
|
7
|
+
[evt: string]: CustomEvent<any>;
|
|
8
|
+
};
|
|
9
|
+
slots: {
|
|
10
|
+
default: {};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare type CardProps = typeof __propDef.props;
|
|
14
|
+
export declare type CardEvents = typeof __propDef.events;
|
|
15
|
+
export declare type CardSlots = typeof __propDef.slots;
|
|
16
|
+
export default class Card extends SvelteComponentTyped<CardProps, CardEvents, CardSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|