@txstate-mws/svelte-components 1.0.0 → 1.0.4

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.
Files changed (130) hide show
  1. package/README.md +33 -14
  2. package/{dist/ts/actions → actions}/buttonify.d.ts +0 -0
  3. package/{dist/actions → actions}/buttonify.js +1 -6
  4. package/{dist/ts/actions → actions}/glue.d.ts +1 -1
  5. package/{dist/actions → actions}/glue.js +8 -13
  6. package/actions/index.d.ts +7 -0
  7. package/actions/index.js +7 -0
  8. package/actions/offset.d.ts +15 -0
  9. package/actions/offset.js +35 -0
  10. package/{dist/ts/actions → actions}/portal.d.ts +0 -0
  11. package/actions/portal.js +13 -0
  12. package/{dist/ts/actions → actions}/resize.d.ts +6 -2
  13. package/actions/resize.js +45 -0
  14. package/{dist/ts/actions → actions}/sticky.d.ts +2 -2
  15. package/{dist/actions → actions}/sticky.js +10 -18
  16. package/{dist/ts/actions → actions}/stickyfixed.d.ts +2 -2
  17. package/{dist/actions → actions}/stickyfixed.js +14 -23
  18. package/{dist/components → components}/CollapsingTable.svelte +12 -13
  19. package/components/CollapsingTable.svelte.d.ts +59 -0
  20. package/{dist/ts/components → components}/ConditionalWrapper.svelte +6 -7
  21. package/components/ConditionalWrapper.svelte.d.ts +23 -0
  22. package/{dist/components → components}/FocusLock.svelte +15 -11
  23. package/components/FocusLock.svelte.d.ts +26 -0
  24. package/{dist/components → components}/Modal.svelte +5 -4
  25. package/components/Modal.svelte.d.ts +27 -0
  26. package/{dist/components → components}/PopupMenu.svelte +13 -16
  27. package/components/PopupMenu.svelte.d.ts +44 -0
  28. package/{dist/components → components}/ScreenReaderOnly.svelte +1 -1
  29. package/components/ScreenReaderOnly.svelte.d.ts +20 -0
  30. package/{dist/ts/components → components}/index.d.ts +0 -0
  31. package/components/index.js +6 -0
  32. package/index.d.ts +4 -0
  33. package/index.js +4 -0
  34. package/package.json +47 -75
  35. package/{dist/ts/types → types}/CollapsingTable.d.ts +0 -0
  36. package/{dist/ts/tests/Actions/Actions.stories.d.ts → types/CollapsingTable.js} +0 -0
  37. package/{dist/ts/types → types}/PopupMenu.d.ts +0 -0
  38. package/{dist/ts/tests/CollapsingTable/CollapsingTable.stories.d.ts → types/PopupMenu.js} +0 -0
  39. package/types/index.d.ts +2 -0
  40. package/types/index.js +2 -0
  41. package/{dist/ts/lib → util}/bodyoffset.d.ts +2 -1
  42. package/{dist/lib → util}/bodyoffset.js +10 -14
  43. package/util/index.d.ts +3 -0
  44. package/util/index.js +3 -0
  45. package/{dist/ts/lib → util}/repositioned.d.ts +1 -2
  46. package/{dist/lib → util}/repositioned.js +13 -24
  47. package/{dist/ts/lib → util}/util.d.ts +0 -0
  48. package/util/util.js +10 -0
  49. package/LICENSE +0 -21
  50. package/dist/actions/buttonify.js.map +0 -1
  51. package/dist/actions/glue.js.map +0 -1
  52. package/dist/actions/index.js +0 -20
  53. package/dist/actions/index.js.map +0 -1
  54. package/dist/actions/offset.js +0 -35
  55. package/dist/actions/offset.js.map +0 -1
  56. package/dist/actions/portal.js +0 -19
  57. package/dist/actions/portal.js.map +0 -1
  58. package/dist/actions/resize.js +0 -48
  59. package/dist/actions/resize.js.map +0 -1
  60. package/dist/actions/sticky.js.map +0 -1
  61. package/dist/actions/stickyfixed.js.map +0 -1
  62. package/dist/components/ConditionalWrapper.svelte +0 -38
  63. package/dist/components/index.js +0 -19
  64. package/dist/components/index.js.map +0 -1
  65. package/dist/index.js +0 -17
  66. package/dist/index.js.map +0 -1
  67. package/dist/lib/activestore.js +0 -123
  68. package/dist/lib/activestore.js.map +0 -1
  69. package/dist/lib/bodyoffset.js.map +0 -1
  70. package/dist/lib/convertedstore.js +0 -41
  71. package/dist/lib/convertedstore.js.map +0 -1
  72. package/dist/lib/derivedstore.js +0 -65
  73. package/dist/lib/derivedstore.js.map +0 -1
  74. package/dist/lib/index.js +0 -22
  75. package/dist/lib/index.js.map +0 -1
  76. package/dist/lib/repositioned.js.map +0 -1
  77. package/dist/lib/safestore.js +0 -16
  78. package/dist/lib/safestore.js.map +0 -1
  79. package/dist/lib/store.js +0 -27
  80. package/dist/lib/store.js.map +0 -1
  81. package/dist/lib/substore.js +0 -47
  82. package/dist/lib/substore.js.map +0 -1
  83. package/dist/lib/util.js +0 -16
  84. package/dist/lib/util.js.map +0 -1
  85. package/dist/ts/actions/index.d.ts +0 -7
  86. package/dist/ts/actions/offset.d.ts +0 -15
  87. package/dist/ts/components/CollapsingTable.svelte +0 -147
  88. package/dist/ts/components/FocusLock.svelte +0 -99
  89. package/dist/ts/components/Modal.svelte +0 -54
  90. package/dist/ts/components/PopupMenu.svelte +0 -279
  91. package/dist/ts/components/ScreenReaderOnly.svelte +0 -26
  92. package/dist/ts/index.d.ts +0 -4
  93. package/dist/ts/lib/activestore.d.ts +0 -60
  94. package/dist/ts/lib/convertedstore.d.ts +0 -16
  95. package/dist/ts/lib/derivedstore.d.ts +0 -23
  96. package/dist/ts/lib/index.d.ts +0 -9
  97. package/dist/ts/lib/safestore.d.ts +0 -4
  98. package/dist/ts/lib/store.d.ts +0 -16
  99. package/dist/ts/lib/substore.d.ts +0 -24
  100. package/dist/ts/tests/Actions/Offset.svelte +0 -34
  101. package/dist/ts/tests/Actions/Resize.svelte +0 -31
  102. package/dist/ts/tests/Actions/Sticky.svelte +0 -65
  103. package/dist/ts/tests/CollapsingTable/CollapsingTable.test.d.ts +0 -1
  104. package/dist/ts/tests/CollapsingTable/CollapsingTableTest.svelte +0 -36
  105. package/dist/ts/tests/Modal/Modal.stories.d.ts +0 -1
  106. package/dist/ts/tests/Modal/Modal.test.d.ts +0 -1
  107. package/dist/ts/tests/Modal/ModalTest.svelte +0 -58
  108. package/dist/ts/tests/PopupMenu/PopupMenu.stories.d.ts +0 -1
  109. package/dist/ts/tests/PopupMenu/PopupMenu.test.d.ts +0 -1
  110. package/dist/ts/tests/PopupMenu/PopupMenuBody.svelte +0 -34
  111. package/dist/ts/tests/PopupMenu/PopupMenuButtonIsParent.svelte +0 -36
  112. package/dist/ts/tests/PopupMenu/PopupMenuComplex.svelte +0 -34
  113. package/dist/ts/tests/PopupMenu/PopupMenuSimple.svelte +0 -36
  114. package/dist/ts/tests/stores/deepstore.test.d.ts +0 -1
  115. package/dist/ts/types/index.d.ts +0 -2
  116. package/dist/types/CollapsingTable.js +0 -3
  117. package/dist/types/CollapsingTable.js.map +0 -1
  118. package/dist/types/PopupMenu.js +0 -3
  119. package/dist/types/PopupMenu.js.map +0 -1
  120. package/dist/types/index.js +0 -15
  121. package/dist/types/index.js.map +0 -1
  122. package/docs/CollapsingTable.md +0 -79
  123. package/docs/ConditionalWrapper.md +0 -35
  124. package/docs/Modal.md +0 -63
  125. package/docs/PopupMenu.md +0 -31
  126. package/docs/ScreenReaderOnly.md +0 -10
  127. package/docs/actions.md +0 -84
  128. package/docs/stores.md +0 -203
  129. package/esm/index.js +0 -1
  130. 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
- # 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)
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 '../lib';
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
- "use strict";
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 = (0, lib_1.sharedOffsetParent)(el, target);
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 } : (0, lib_1.targetOffset)(el.offsetParent, sharedOffset);
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 === null || store === void 0 ? void 0 : store.update(v => (Object.assign(Object.assign({}, v), { valign, halign })));
63
+ store?.update(v => ({ ...v, valign, halign }));
67
64
  }
68
- const { destroy, update } = (0, lib_1.watchForPositionChangeInContainer)(target, sharedOffset, reposition);
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 => (Object.assign(Object.assign({}, v), { valign, halign })));
71
+ ustore.update(v => ({ ...v, valign, halign }));
75
72
  store = ustore;
76
73
  }
77
74
  if (target !== utarget) {
78
- sharedOffset = (0, lib_1.sharedOffsetParent)(el, utarget);
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
@@ -0,0 +1,7 @@
1
+ export * from './buttonify.js';
2
+ export * from './glue.js';
3
+ export * from './offset.js';
4
+ export * from './portal.js';
5
+ export * from './resize.js';
6
+ export * from './sticky.js';
7
+ export * from './stickyfixed.js';
@@ -0,0 +1,7 @@
1
+ export * from './buttonify.js';
2
+ export * from './glue.js';
3
+ export * from './offset.js';
4
+ export * from './portal.js';
5
+ export * from './resize.js';
6
+ export * from './sticky.js';
7
+ export * from './stickyfixed.js';
@@ -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
@@ -0,0 +1,13 @@
1
+ export function portal(el, target = document.body) {
2
+ function update(target = document.body) {
3
+ target?.appendChild(el);
4
+ }
5
+ function destroy() {
6
+ el.parentElement?.removeChild(el);
7
+ }
8
+ update(target);
9
+ return {
10
+ update,
11
+ destroy
12
+ };
13
+ }
@@ -1,4 +1,5 @@
1
- import { SettableSubject } from '../lib';
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 | undefined): void;
17
+ update(newConfig?: ResizeConfig): void;
14
18
  destroy(): void;
15
19
  };
16
20
  export {};
@@ -0,0 +1,45 @@
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 ?? { clientWidth: 1024, clientHeight: 1024, offsetWidth: 1024, offsetHeight: 1024 });
7
+ }
8
+ }
9
+ export function resize(el, config) {
10
+ if (config?.debounce === true)
11
+ config.debounce = 100;
12
+ let lastSize = {};
13
+ function watch() {
14
+ const current = { clientWidth: el.clientWidth, clientHeight: el.clientHeight, offsetWidth: el.offsetWidth, offsetHeight: el.offsetHeight };
15
+ if (!equal(lastSize, current)) {
16
+ lastSize = current;
17
+ if (config?.store)
18
+ config.store.set(current);
19
+ el.dispatchEvent(new CustomEvent('resize', { detail: current }));
20
+ }
21
+ }
22
+ if (!ResizeObserver)
23
+ return watch(); // support SSR
24
+ let observer = new ResizeObserver(config?.debounce ? debounced(watch, config.debounce) : watch);
25
+ observer.observe(el);
26
+ watch();
27
+ return {
28
+ update(newConfig) {
29
+ if (newConfig?.debounce === true)
30
+ newConfig.debounce = 100;
31
+ if (newConfig?.store !== config?.store) {
32
+ newConfig?.store?.set(lastSize);
33
+ }
34
+ if (!!newConfig?.debounce !== !!config?.debounce) {
35
+ observer.disconnect();
36
+ observer = new ResizeObserver(newConfig?.debounce ? debounced(watch, newConfig.debounce) : watch);
37
+ observer.observe(el);
38
+ }
39
+ config = newConfig;
40
+ },
41
+ destroy() {
42
+ observer.disconnect();
43
+ }
44
+ };
45
+ }
@@ -1,4 +1,4 @@
1
- import { SettableSubject } from '../lib';
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<StickyStore> | undefined) => void;
31
+ update: (newConfig?: StickyArgs) => void;
32
32
  destroy: () => void;
33
33
  };
@@ -1,7 +1,4 @@
1
- "use strict";
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,19 +20,18 @@ 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
- (_a = config === null || config === void 0 ? void 0 : config.store) === null || _a === void 0 ? void 0 : _a.update(v => (Object.assign(Object.assign({}, v), { translateY, floating })));
34
+ config?.store?.update(v => ({ ...v, translateY, floating }));
39
35
  }
40
36
  }
41
37
  function onscroll(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] = (0, lib_1.bodyOffset)(offsetParent);
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 = (config === null || config === void 0 ? void 0 : config.target) ? offset[1] : offset[0];
69
- scrollend = Math.max(scrollstart, containeroffset.top + ((_a = config === null || config === void 0 ? void 0 : config.target) !== null && _a !== void 0 ? _a : offsetParent).clientHeight - el.offsetHeight);
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 } = (0, lib_1.watchForPositionChange)([el.offsetParent, config === null || config === void 0 ? void 0 : config.target], onpositionchange);
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
- var _a;
77
- if ((newConfig === null || newConfig === void 0 ? void 0 : newConfig.store) !== (config === null || config === void 0 ? void 0 : config.store))
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 === null || config === void 0 ? void 0 : config.target], onpositionchange);
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<import("./sticky").StickyStore> | undefined) => void;
23
+ update: (newConfig?: StickyArgs) => void;
24
24
  destroy: () => void;
25
25
  };
@@ -1,7 +1,4 @@
1
- "use strict";
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
- var _a;
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 === null || spacer === void 0 ? void 0 : spacer.remove();
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
- (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(spacer, el);
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
- (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(spacer, el);
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
- (_b = config === null || config === void 0 ? void 0 : config.store) === null || _b === void 0 ? void 0 : _b.update(v => (Object.assign(Object.assign({}, v), { translateY, floating })));
107
+ config?.store?.update(v => ({ ...v, translateY, floating }));
113
108
  }
114
109
  if (top !== newTop) {
115
110
  top = newTop;
@@ -122,12 +117,11 @@ function stickyfixed(el, config) {
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] = (0, lib_1.bodyOffset)(offsetParent);
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 = (config === null || config === void 0 ? void 0 : config.target) ? (_a = offset[1]) !== null && _a !== void 0 ? _a : offset[0] : offset[0];
142
- scrollend = Math.max(scrollstart, containeroffset.top + ((_b = config === null || config === void 0 ? void 0 : config.target) !== null && _b !== void 0 ? _b : offsetParent).clientHeight - el.offsetHeight);
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 } = (0, lib_1.watchForPositionChange)([el.offsetParent, config === null || config === void 0 ? void 0 : config.target], onpositionchange);
139
+ const { destroy, update } = watchForPositionChange([el.offsetParent, config?.target], onpositionchange);
146
140
  window.addEventListener('scroll', onscroll, { passive: true });
147
141
  function stickyUpdate(newConfig) {
148
- var _a;
149
- if ((newConfig === null || newConfig === void 0 ? void 0 : newConfig.store) !== (config === null || config === void 0 ? void 0 : config.store))
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 === null || config === void 0 ? void 0 : config.target], onpositionchange);
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
@@ -1,6 +1,6 @@
1
- <script>var _a;
2
- import { Store, classes } from '../lib';
1
+ <script >import { Store } from '@txstate-mws/svelte-store';
3
2
  import { derived } from 'svelte/store';
3
+ import { classes } from '../util';
4
4
  import DefaultPopupMenu from './PopupMenu.svelte';
5
5
  import ScreenReaderOnly from './ScreenReaderOnly.svelte';
6
6
  export let tableClass = '';
@@ -22,8 +22,8 @@ let columns;
22
22
  let width = 320;
23
23
  let selected;
24
24
  let identifyingkeys = [];
25
- $: firstrow = (_a = items === null || items === void 0 ? void 0 : items[0]) !== null && _a !== void 0 ? _a : {};
26
- $: columns = config !== null && config !== void 0 ? config : Object.keys(firstrow).map(key => ({ key }));
25
+ $: firstrow = items?.[0] ?? {};
26
+ $: columns = config ?? Object.keys(firstrow).map(key => ({ key }));
27
27
  function reactToColumns(columns) {
28
28
  if (!columns.some(c => c.neverhide)) {
29
29
  columns[0].neverhide = true;
@@ -40,7 +40,7 @@ function reactToColumns(columns) {
40
40
  return sortedcolumns;
41
41
  }
42
42
  $: sortedcolumns = reactToColumns(columns);
43
- $: itemkeys = items.map(item => { var _a, _b; return (_b = (_a = item.id) !== null && _a !== void 0 ? _a : item._id) !== null && _b !== void 0 ? _b : identifyingkeys.map(k => item[k]).join('.'); });
43
+ $: itemkeys = items.map(item => item.id ?? item._id ?? identifyingkeys.map(k => item[k]).join('.'));
44
44
  const state = new Store({
45
45
  keepcolumns: [],
46
46
  hiddencolumns: [],
@@ -48,28 +48,27 @@ const state = new Store({
48
48
  });
49
49
  const menuitems = derived(state, obj => obj.hiddencolumns.map(c => ({ value: c.key, label: c.title })));
50
50
  function react(..._) {
51
- var _a, _b, _c, _d;
52
- const selectedcol = (_a = sortedcolumns.find(c => c.key === (selected === null || selected === void 0 ? void 0 : selected.value))) !== null && _a !== void 0 ? _a : columns[1];
51
+ const selectedcol = sortedcolumns.find(c => c.key === selected?.value) ?? columns[1];
53
52
  const keepcolumns = [];
54
53
  const hiddencolumns = [];
55
- let used = sortedcolumns.filter(c => c.neverhide || c === selectedcol).reduce((sum, col) => { var _a; return sum + ((_a = col.width) !== null && _a !== void 0 ? _a : defaultCellWidth); }, 0);
54
+ let used = sortedcolumns.filter(c => c.neverhide || c === selectedcol).reduce((sum, col) => sum + (col.width ?? defaultCellWidth), 0);
56
55
  for (const col of sortedcolumns) {
57
- if (col.neverhide || col === selectedcol || used + ((_b = col.width) !== null && _b !== void 0 ? _b : defaultCellWidth) < width) {
56
+ if (col.neverhide || col === selectedcol || used + (col.width ?? defaultCellWidth) < width) {
58
57
  keepcolumns.push(col);
59
58
  if (col !== selectedcol && !col.neverhide)
60
- used += (_c = col.width) !== null && _c !== void 0 ? _c : defaultCellWidth;
59
+ used += col.width ?? defaultCellWidth;
61
60
  }
62
61
  else
63
62
  hiddencolumns.push(col);
64
63
  }
65
64
  for (const col of keepcolumns) {
66
- col.widthPercent = 100 * ((_d = col.width) !== null && _d !== void 0 ? _d : defaultCellWidth) / used;
65
+ col.widthPercent = 100 * (col.width ?? defaultCellWidth) / used;
67
66
  }
68
67
  const dropdowncolumn = hiddencolumns.length ? keepcolumns[keepcolumns.length - 1] : undefined;
69
68
  state.set({ keepcolumns, hiddencolumns, dropdowncolumn });
70
69
  }
71
70
  $: react(width, selected);
72
- let headers = [];
71
+ const headers = [];
73
72
  $: menubuttonelement = headers[$state.keepcolumns.length - 1];
74
73
  </script>
75
74
 
@@ -113,7 +112,7 @@ $: menubuttonelement = headers[$state.keepcolumns.length - 1];
113
112
  </table>
114
113
  </div>
115
114
  {#if $menuitems.length > 0}
116
- <svelte:component this={PopupMenu} {menuContainerClass} {menuClass} {menuItemClass} {menuItemHilitedClass} items={$menuitems} buttonelement={menubuttonelement} on:change={e => selected = e.detail}></svelte:component>
115
+ <svelte:component this={PopupMenu} {menuContainerClass} {menuClass} {menuItemClass} {menuItemHilitedClass} items={$menuitems} buttonelement={menubuttonelement} on:change={e => { selected = e.detail }}></svelte:component>
117
116
  {/if}
118
117
 
119
118
  <style>
@@ -0,0 +1,59 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { CollapsingTableColumn } from '../types';
3
+ import DefaultPopupMenu from './PopupMenu.svelte';
4
+ declare const __propDef: {
5
+ props: {
6
+ tableClass?: string;
7
+ bodyRowClass?: string;
8
+ bodyCellClass?: string;
9
+ headerRowClass?: string;
10
+ headerCellClass?: string;
11
+ menuContainerClass?: string;
12
+ menuClass?: string;
13
+ menuItemClass?: string;
14
+ menuItemHilitedClass?: string;
15
+ items: any[];
16
+ config?: CollapsingTableColumn[] | undefined;
17
+ defaultCellWidth?: number;
18
+ PopupMenu?: typeof DefaultPopupMenu;
19
+ slots?: Record<string, boolean>;
20
+ stickyheader?: boolean;
21
+ };
22
+ events: {
23
+ [evt: string]: CustomEvent<any>;
24
+ };
25
+ slots: {
26
+ headercell: {
27
+ column: CollapsingTableColumn & {
28
+ widthPercent?: number;
29
+ };
30
+ key: string;
31
+ title: string;
32
+ item: any;
33
+ value: any;
34
+ };
35
+ dropicon: {
36
+ column: CollapsingTableColumn & {
37
+ widthPercent?: number;
38
+ };
39
+ item: any;
40
+ value: any;
41
+ };
42
+ default: {
43
+ key: string;
44
+ value: any;
45
+ item: any;
46
+ };
47
+ footer: {
48
+ item: any;
49
+ key: any;
50
+ value: any;
51
+ };
52
+ };
53
+ };
54
+ export declare type CollapsingTableProps = typeof __propDef.props;
55
+ export declare type CollapsingTableEvents = typeof __propDef.events;
56
+ export declare type CollapsingTableSlots = typeof __propDef.slots;
57
+ export default class CollapsingTable extends SvelteComponentTyped<CollapsingTableProps, CollapsingTableEvents, CollapsingTableSlots> {
58
+ }
59
+ export {};
@@ -1,10 +1,9 @@
1
- <script lang="ts">
2
- export let condition: boolean|undefined
3
- export let component: Function|undefined = undefined
4
- export let a = false
5
- export let span = false
6
- export let element: HTMLElement|undefined = undefined
7
- $: passthrough = (({ condition, component, a, span, element, ...passthrough }) => passthrough)($$props)
1
+ <script >export let condition;
2
+ export let component = undefined;
3
+ export let a = false;
4
+ export let span = false;
5
+ export let element = undefined;
6
+ $: passthrough = (({ condition, component, a, span, element, ...passthrough }) => passthrough)($$props);
8
7
  </script>
9
8
 
10
9
  {#if condition || (typeof condition === 'undefined' && component)}