@sveltia/ui 0.2.4 → 0.3.0

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 (122) hide show
  1. package/package/components/{core → button}/button.svelte +2 -1
  2. package/package/components/{core → button}/button.svelte.d.ts +6 -5
  3. package/package/components/{composite → button}/select-button-group.svelte +8 -5
  4. package/package/components/{composite → button}/select-button-group.svelte.d.ts +6 -6
  5. package/package/components/{core → button}/select-button.svelte +2 -2
  6. package/package/components/{core → button}/select-button.svelte.d.ts +2 -2
  7. package/package/components/{composite → calendar}/calendar.svelte +9 -5
  8. package/package/components/{composite → calendar}/calendar.svelte.d.ts +1 -0
  9. package/package/components/{composite → checkbox}/checkbox-group.svelte +3 -2
  10. package/package/components/{composite → checkbox}/checkbox-group.svelte.d.ts +2 -2
  11. package/package/components/{core → checkbox}/checkbox.svelte +38 -17
  12. package/package/components/{core → checkbox}/checkbox.svelte.d.ts +7 -3
  13. package/package/components/{core → dialog}/dialog.svelte +5 -4
  14. package/package/components/{core → dialog}/dialog.svelte.d.ts +2 -1
  15. package/package/components/{composite → disclosure}/disclosure.svelte +5 -4
  16. package/package/components/{composite → disclosure}/disclosure.svelte.d.ts +2 -1
  17. package/package/components/{core/separator.svelte → divider/divider.svelte} +5 -4
  18. package/package/components/divider/divider.svelte.d.ts +29 -0
  19. package/package/components/{core → divider}/spacer.svelte +4 -0
  20. package/package/components/{core → divider}/spacer.svelte.d.ts +1 -0
  21. package/package/components/{core → drawer}/drawer.svelte +5 -4
  22. package/package/components/{core → drawer}/drawer.svelte.d.ts +2 -1
  23. package/package/components/{core → icon}/icon.svelte +5 -0
  24. package/package/components/{core → icon}/icon.svelte.d.ts +6 -2
  25. package/package/components/listbox/listbox.svelte +74 -0
  26. package/package/components/{composite → listbox}/listbox.svelte.d.ts +3 -1
  27. package/package/components/listbox/option-group.svelte +47 -0
  28. package/package/components/listbox/option-group.svelte.d.ts +38 -0
  29. package/package/components/{core → listbox}/option.svelte +34 -2
  30. package/package/components/{core → listbox}/option.svelte.d.ts +7 -3
  31. package/package/components/{core → menu}/menu-button.svelte +3 -17
  32. package/package/components/{core → menu}/menu-button.svelte.d.ts +4 -1
  33. package/package/components/{core → menu}/menu-item-checkbox.svelte +1 -0
  34. package/package/components/{core → menu}/menu-item-checkbox.svelte.d.ts +4 -1
  35. package/package/components/{composite → menu}/menu-item-group.svelte +5 -1
  36. package/package/components/{composite → menu}/menu-item-group.svelte.d.ts +1 -0
  37. package/package/components/{core → menu}/menu-item-radio.svelte +2 -0
  38. package/package/components/{core → menu}/menu-item-radio.svelte.d.ts +5 -1
  39. package/package/components/{core → menu}/menu-item.svelte +6 -6
  40. package/package/components/{core → menu}/menu-item.svelte.d.ts +4 -1
  41. package/package/components/{composite → menu}/menu.svelte +3 -2
  42. package/package/components/{composite → menu}/menu.svelte.d.ts +2 -1
  43. package/package/components/{composite/radio-button-group.svelte → radio/radio-group.svelte} +15 -10
  44. package/package/components/radio/radio-group.svelte.d.ts +40 -0
  45. package/package/components/{core/radio-button.svelte → radio/radio.svelte} +45 -18
  46. package/package/components/radio/radio.svelte.d.ts +43 -0
  47. package/package/components/{composite → select}/combobox.svelte +7 -6
  48. package/package/components/{composite → select}/combobox.svelte.d.ts +4 -3
  49. package/package/components/{composite → select}/select.svelte +3 -1
  50. package/package/components/{composite → select}/select.svelte.d.ts +7 -3
  51. package/package/components/{core → slider}/slider.svelte +82 -57
  52. package/package/components/{core → slider}/slider.svelte.d.ts +12 -10
  53. package/package/components/{core → switch}/switch.svelte +36 -19
  54. package/package/components/{core → switch}/switch.svelte.d.ts +4 -3
  55. package/package/components/table/table-body.svelte +23 -0
  56. package/package/components/table/table-body.svelte.d.ts +34 -0
  57. package/package/components/table/table-cell.svelte +23 -0
  58. package/package/components/table/table-cell.svelte.d.ts +34 -0
  59. package/package/components/table/table-col-header.svelte +23 -0
  60. package/package/components/table/table-col-header.svelte.d.ts +34 -0
  61. package/package/components/table/table-foot.svelte +23 -0
  62. package/package/components/table/table-foot.svelte.d.ts +34 -0
  63. package/package/components/table/table-head.svelte +23 -0
  64. package/package/components/table/table-head.svelte.d.ts +34 -0
  65. package/package/components/table/table-row-header.svelte +23 -0
  66. package/package/components/table/table-row-header.svelte.d.ts +34 -0
  67. package/package/components/table/table-row.svelte +23 -0
  68. package/package/components/table/table-row.svelte.d.ts +38 -0
  69. package/package/components/table/table.svelte +44 -0
  70. package/package/components/table/table.svelte.d.ts +36 -0
  71. package/package/components/{composite → tabs}/tab-list.svelte +3 -2
  72. package/package/components/{composite → tabs}/tab-list.svelte.d.ts +7 -6
  73. package/package/components/{core → tabs}/tab-panel.svelte +2 -1
  74. package/package/components/{core → tabs}/tab-panel.svelte.d.ts +2 -1
  75. package/package/components/{core → tabs}/tab.svelte +3 -2
  76. package/package/components/{core → tabs}/tab.svelte.d.ts +2 -1
  77. package/package/components/{editor/markdown.svelte → text-field/markdown-editor.svelte} +10 -6
  78. package/package/components/text-field/markdown-editor.svelte.d.ts +26 -0
  79. package/package/components/{core → text-field}/number-input.svelte +22 -12
  80. package/package/components/{core → text-field}/number-input.svelte.d.ts +7 -3
  81. package/package/components/{core → text-field}/password-input.svelte +5 -2
  82. package/package/components/{core → text-field}/password-input.svelte.d.ts +8 -3
  83. package/package/components/{core → text-field}/search-bar.svelte +5 -2
  84. package/package/components/{core → text-field}/search-bar.svelte.d.ts +8 -3
  85. package/package/components/{core → text-field}/text-area.svelte +2 -0
  86. package/package/components/{core → text-field}/text-area.svelte.d.ts +9 -5
  87. package/package/components/{core → text-field}/text-input.svelte +3 -1
  88. package/package/components/{core → text-field}/text-input.svelte.d.ts +11 -7
  89. package/package/components/{core → toolbar}/toolbar.svelte +2 -1
  90. package/package/components/{core → toolbar}/toolbar.svelte.d.ts +3 -2
  91. package/package/components/util/app-shell.svelte +10 -36
  92. package/package/components/util/group.js +305 -0
  93. package/package/components/{core → util}/group.svelte +5 -11
  94. package/package/components/{core → util}/group.svelte.d.ts +4 -2
  95. package/package/components/util/popup.d.ts +30 -0
  96. package/package/components/{helpers → util}/popup.js +36 -26
  97. package/package/components/util/popup.svelte +14 -5
  98. package/package/components/util/{misc.d.ts → util.d.ts} +1 -0
  99. package/package/components/util/{misc.js → util.js} +15 -0
  100. package/package/index.d.ts +46 -41
  101. package/package/index.js +48 -83
  102. package/package/styles/core.scss +5 -34
  103. package/package/styles/variables.scss +5 -4
  104. package/package.json +362 -328
  105. package/package/components/composite/grid.svelte +0 -24
  106. package/package/components/composite/grid.svelte.d.ts +0 -31
  107. package/package/components/composite/listbox.svelte +0 -63
  108. package/package/components/composite/radio-button-group.svelte.d.ts +0 -36
  109. package/package/components/core/grid-cell.svelte +0 -13
  110. package/package/components/core/grid-cell.svelte.d.ts +0 -29
  111. package/package/components/core/radio-button.svelte.d.ts +0 -37
  112. package/package/components/core/row-group.svelte +0 -13
  113. package/package/components/core/row-group.svelte.d.ts +0 -29
  114. package/package/components/core/row.svelte +0 -13
  115. package/package/components/core/row.svelte.d.ts +0 -33
  116. package/package/components/core/separator.svelte.d.ts +0 -26
  117. package/package/components/editor/markdown.svelte.d.ts +0 -25
  118. package/package/components/helpers/group.js +0 -251
  119. package/package/components/helpers/popup.d.ts +0 -30
  120. package/package/components/helpers/util.d.ts +0 -1
  121. package/package/components/helpers/util.js +0 -14
  122. /package/package/components/{helpers → util}/group.d.ts +0 -0
@@ -1,24 +0,0 @@
1
- <script>
2
- import { activateGroup } from '../helpers/group';
3
-
4
- /**
5
- * CSS class name on the button.
6
- * @type {string}
7
- */
8
- let className = '';
9
-
10
- export { className as class };
11
-
12
- /** @type {HTMLElement?} */
13
- export let element = undefined;
14
- </script>
15
-
16
- <div
17
- role="grid"
18
- class="sui grid {className}"
19
- {...$$restProps}
20
- bind:this={element}
21
- use:activateGroup
22
- >
23
- <slot />
24
- </div>
@@ -1,31 +0,0 @@
1
- /** @typedef {typeof __propDef.props} GridProps */
2
- /** @typedef {typeof __propDef.events} GridEvents */
3
- /** @typedef {typeof __propDef.slots} GridSlots */
4
- export default class Grid extends SvelteComponentTyped<{
5
- [x: string]: any;
6
- class?: string;
7
- element?: HTMLElement;
8
- }, {
9
- [evt: string]: CustomEvent<any>;
10
- }, {
11
- default: {};
12
- }> {
13
- }
14
- export type GridProps = typeof __propDef.props;
15
- export type GridEvents = typeof __propDef.events;
16
- export type GridSlots = typeof __propDef.slots;
17
- import { SvelteComponentTyped } from "svelte";
18
- declare const __propDef: {
19
- props: {
20
- [x: string]: any;
21
- class?: string;
22
- element?: HTMLElement | null;
23
- };
24
- events: {
25
- [evt: string]: CustomEvent<any>;
26
- };
27
- slots: {
28
- default: {};
29
- };
30
- };
31
- export {};
@@ -1,63 +0,0 @@
1
- <!--
2
- @component
3
- @see https://w3c.github.io/aria/#listbox
4
- @see https://w3c.github.io/aria-practices/#Listbox
5
- -->
6
- <svelte:options accessors={true} />
7
-
8
- <script>
9
- import { activateGroup } from '../helpers/group';
10
-
11
- /**
12
- * CSS class name on the button.
13
- * @type {string}
14
- */
15
- let className = '';
16
-
17
- export { className as class };
18
-
19
- /** @type {HTMLElement?} */
20
- export let element = undefined;
21
-
22
- export let multiple = false;
23
- </script>
24
-
25
- <div
26
- class="sui listbox {className}"
27
- role="listbox"
28
- tabindex="0"
29
- aria-multiselectable={multiple}
30
- {...$$restProps}
31
- bind:this={element}
32
- on:click
33
- on:select
34
- use:activateGroup
35
- >
36
- <slot />
37
- </div>
38
-
39
- <style>[role=listbox] {
40
- display: flex;
41
- flex-direction: column;
42
- color: inherit;
43
- margin: 0;
44
- border-width: 1px;
45
- border-color: var(--control-border-color);
46
- border-radius: 4px;
47
- padding: 4px;
48
- }
49
- [role=listbox] :global([role="separator"]) {
50
- margin: 4px;
51
- }
52
- [role=listbox] :global([role="group"]):not(:first-child) {
53
- margin-top: 16px;
54
- }
55
- [role=listbox] :global([role="group"]):not(:last-child) {
56
- margin-bottom: 16px;
57
- }
58
- [role=listbox] :global([role="group"]) :global(.title) {
59
- margin: 0 8px 8px;
60
- color: var(--secondary-foreground-color);
61
- font-size: var(--font-size--x-small);
62
- text-transform: uppercase;
63
- }</style>
@@ -1,36 +0,0 @@
1
- /** @typedef {typeof __propDef.props} RadioButtonGroupProps */
2
- /** @typedef {typeof __propDef.events} RadioButtonGroupEvents */
3
- /** @typedef {typeof __propDef.slots} RadioButtonGroupSlots */
4
- /**
5
- * The container of `<RadioButton>`s.
6
- * @see https://w3c.github.io/aria/#radiogroup
7
- * @see https://w3c.github.io/aria-practices/#radiobutton
8
- */
9
- export default class RadioButtonGroup extends SvelteComponentTyped<{
10
- class?: string;
11
- element?: HTMLElement;
12
- orientation?: "horizontal" | "vertical";
13
- }, {
14
- [evt: string]: CustomEvent<any>;
15
- }, {
16
- default: {};
17
- }> {
18
- }
19
- export type RadioButtonGroupProps = typeof __propDef.props;
20
- export type RadioButtonGroupEvents = typeof __propDef.events;
21
- export type RadioButtonGroupSlots = typeof __propDef.slots;
22
- import { SvelteComponentTyped } from "svelte";
23
- declare const __propDef: {
24
- props: {
25
- class?: string;
26
- element?: HTMLElement | null;
27
- orientation?: ('horizontal' | 'vertical');
28
- };
29
- events: {
30
- [evt: string]: CustomEvent<any>;
31
- };
32
- slots: {
33
- default: {};
34
- };
35
- };
36
- export {};
@@ -1,13 +0,0 @@
1
- <script>
2
- /**
3
- * CSS class name on the button.
4
- * @type {string}
5
- */
6
- let className = '';
7
-
8
- export { className as class };
9
- </script>
10
-
11
- <div role="gridcell" class="sui grid-cell {className}" {...$$restProps}>
12
- <slot />
13
- </div>
@@ -1,29 +0,0 @@
1
- /** @typedef {typeof __propDef.props} GridCellProps */
2
- /** @typedef {typeof __propDef.events} GridCellEvents */
3
- /** @typedef {typeof __propDef.slots} GridCellSlots */
4
- export default class GridCell extends SvelteComponentTyped<{
5
- [x: string]: any;
6
- class?: string;
7
- }, {
8
- [evt: string]: CustomEvent<any>;
9
- }, {
10
- default: {};
11
- }> {
12
- }
13
- export type GridCellProps = typeof __propDef.props;
14
- export type GridCellEvents = typeof __propDef.events;
15
- export type GridCellSlots = typeof __propDef.slots;
16
- import { SvelteComponentTyped } from "svelte";
17
- declare const __propDef: {
18
- props: {
19
- [x: string]: any;
20
- class?: string;
21
- };
22
- events: {
23
- [evt: string]: CustomEvent<any>;
24
- };
25
- slots: {
26
- default: {};
27
- };
28
- };
29
- export {};
@@ -1,37 +0,0 @@
1
- /** @typedef {typeof __propDef.props} RadioButtonProps */
2
- /** @typedef {typeof __propDef.events} RadioButtonEvents */
3
- /** @typedef {typeof __propDef.slots} RadioButtonSlots */
4
- /**
5
- * @see https://w3c.github.io/aria/#radio
6
- * @see https://w3c.github.io/aria-practices/#radiobutton
7
- */
8
- export default class RadioButton extends SvelteComponentTyped<{
9
- class?: string;
10
- name?: string;
11
- value?: string;
12
- selected?: boolean;
13
- }, {
14
- [evt: string]: CustomEvent<any>;
15
- }, {
16
- default: {};
17
- }> {
18
- }
19
- export type RadioButtonProps = typeof __propDef.props;
20
- export type RadioButtonEvents = typeof __propDef.events;
21
- export type RadioButtonSlots = typeof __propDef.slots;
22
- import { SvelteComponentTyped } from "svelte";
23
- declare const __propDef: {
24
- props: {
25
- class?: string;
26
- name?: string;
27
- value?: string | null;
28
- selected?: boolean;
29
- };
30
- events: {
31
- [evt: string]: CustomEvent<any>;
32
- };
33
- slots: {
34
- default: {};
35
- };
36
- };
37
- export {};
@@ -1,13 +0,0 @@
1
- <script>
2
- /**
3
- * CSS class name on the button.
4
- * @type {string}
5
- */
6
- let className = 'tbody';
7
-
8
- export { className as class };
9
- </script>
10
-
11
- <div role="rowgroup" class="sui row-group {className}" {...$$restProps}>
12
- <slot />
13
- </div>
@@ -1,29 +0,0 @@
1
- /** @typedef {typeof __propDef.props} RowGroupProps */
2
- /** @typedef {typeof __propDef.events} RowGroupEvents */
3
- /** @typedef {typeof __propDef.slots} RowGroupSlots */
4
- export default class RowGroup extends SvelteComponentTyped<{
5
- [x: string]: any;
6
- class?: string;
7
- }, {
8
- [evt: string]: CustomEvent<any>;
9
- }, {
10
- default: {};
11
- }> {
12
- }
13
- export type RowGroupProps = typeof __propDef.props;
14
- export type RowGroupEvents = typeof __propDef.events;
15
- export type RowGroupSlots = typeof __propDef.slots;
16
- import { SvelteComponentTyped } from "svelte";
17
- declare const __propDef: {
18
- props: {
19
- [x: string]: any;
20
- class?: string;
21
- };
22
- events: {
23
- [evt: string]: CustomEvent<any>;
24
- };
25
- slots: {
26
- default: {};
27
- };
28
- };
29
- export {};
@@ -1,13 +0,0 @@
1
- <script>
2
- /**
3
- * CSS class name on the button.
4
- * @type {string}
5
- */
6
- let className = '';
7
-
8
- export { className as class };
9
- </script>
10
-
11
- <div role="row" tabindex="0" class="sui row {className}" {...$$restProps} on:click>
12
- <slot />
13
- </div>
@@ -1,33 +0,0 @@
1
- /** @typedef {typeof __propDef.props} RowProps */
2
- /** @typedef {typeof __propDef.events} RowEvents */
3
- /** @typedef {typeof __propDef.slots} RowSlots */
4
- export default class Row extends SvelteComponentTyped<{
5
- [x: string]: any;
6
- class?: string;
7
- }, {
8
- click: MouseEvent;
9
- } & {
10
- [evt: string]: CustomEvent<any>;
11
- }, {
12
- default: {};
13
- }> {
14
- }
15
- export type RowProps = typeof __propDef.props;
16
- export type RowEvents = typeof __propDef.events;
17
- export type RowSlots = typeof __propDef.slots;
18
- import { SvelteComponentTyped } from "svelte";
19
- declare const __propDef: {
20
- props: {
21
- [x: string]: any;
22
- class?: string;
23
- };
24
- events: {
25
- click: MouseEvent;
26
- } & {
27
- [evt: string]: CustomEvent<any>;
28
- };
29
- slots: {
30
- default: {};
31
- };
32
- };
33
- export {};
@@ -1,26 +0,0 @@
1
- /** @typedef {typeof __propDef.props} SeparatorProps */
2
- /** @typedef {typeof __propDef.events} SeparatorEvents */
3
- /** @typedef {typeof __propDef.slots} SeparatorSlots */
4
- /** @see https://w3c.github.io/aria/#separator */
5
- export default class Separator extends SvelteComponentTyped<{
6
- class?: string;
7
- orientation?: "horizontal" | "vertical";
8
- }, {
9
- [evt: string]: CustomEvent<any>;
10
- }, {}> {
11
- }
12
- export type SeparatorProps = typeof __propDef.props;
13
- export type SeparatorEvents = typeof __propDef.events;
14
- export type SeparatorSlots = typeof __propDef.slots;
15
- import { SvelteComponentTyped } from "svelte";
16
- declare const __propDef: {
17
- props: {
18
- class?: string;
19
- orientation?: ('horizontal' | 'vertical');
20
- };
21
- events: {
22
- [evt: string]: CustomEvent<any>;
23
- };
24
- slots: {};
25
- };
26
- export {};
@@ -1,25 +0,0 @@
1
- /** @typedef {typeof __propDef.props} MarkdownProps */
2
- /** @typedef {typeof __propDef.events} MarkdownEvents */
3
- /** @typedef {typeof __propDef.slots} MarkdownSlots */
4
- export default class Markdown extends SvelteComponentTyped<{
5
- disabled?: boolean;
6
- value?: string;
7
- }, {
8
- [evt: string]: CustomEvent<any>;
9
- }, {}> {
10
- }
11
- export type MarkdownProps = typeof __propDef.props;
12
- export type MarkdownEvents = typeof __propDef.events;
13
- export type MarkdownSlots = typeof __propDef.slots;
14
- import { SvelteComponentTyped } from "svelte";
15
- declare const __propDef: {
16
- props: {
17
- disabled?: boolean;
18
- value?: string | null;
19
- };
20
- events: {
21
- [evt: string]: CustomEvent<any>;
22
- };
23
- slots: {};
24
- };
25
- export {};
@@ -1,251 +0,0 @@
1
- import { sleep } from '../util/misc';
2
- import { getRandomId } from './util';
3
-
4
- const config = {
5
- grid: {
6
- orientation: 'vertical',
7
- childRoles: ['row'],
8
- childSelectedAttr: 'aria-selected',
9
- },
10
- listbox: {
11
- orientation: 'vertical',
12
- childRoles: ['option'],
13
- childSelectedAttr: 'aria-selected',
14
- },
15
- menu: {
16
- orientation: 'vertical',
17
- childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
18
- childSelectedAttr: 'aria-checked',
19
- },
20
- menubar: {
21
- orientation: 'horizontal',
22
- childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
23
- childSelectedAttr: 'aria-checked',
24
- },
25
- radiogroup: {
26
- orientation: 'horizontal',
27
- childRoles: ['radio'],
28
- childSelectedAttr: 'aria-checked',
29
- },
30
- tablist: {
31
- orientation: 'horizontal',
32
- childRoles: ['tab'],
33
- childSelectedAttr: 'aria-selected',
34
- },
35
- };
36
-
37
- /**
38
- * Implement keyboard and mouse interactions for a grouping composite widget.
39
- */
40
- class Group {
41
- /**
42
- *
43
- * @param {HTMLElement} parent Parent element.
44
- * @todo Check for added elements probably with `MutationObserver`.
45
- */
46
- constructor(parent) {
47
- this.parent = parent;
48
- this.role = parent.getAttribute('role');
49
- this.grid = this.role === 'listbox' && parent.matches('.grid');
50
- this.multi = this.parent.getAttribute('aria-multiselectable') === 'true';
51
- this.id = getRandomId(this.role);
52
- this.parentGroupSelector = `[role="group"], [role="${this.role}"]`;
53
-
54
- const { orientation, childSelectedAttr } = config[this.role];
55
-
56
- this.orientation = this.grid
57
- ? 'horizontal'
58
- : this.parent.getAttribute('aria-orientation') || orientation;
59
- this.childSelectedAttr = childSelectedAttr;
60
-
61
- const { allMembers } = this;
62
-
63
- const hasSelected = allMembers.some((element) =>
64
- element.matches(`[${childSelectedAttr}="true"]`),
65
- );
66
-
67
- allMembers.forEach((element, index) => {
68
- const isSelected = element.matches(`[${childSelectedAttr}="true"]`);
69
- const controls = document.querySelector(`#${element.getAttribute('aria-controls')}`);
70
-
71
- element.id ||= `${this.id}-item-${index}`;
72
- element.tabIndex ||= isSelected || (!hasSelected && index === 0) ? 0 : -1;
73
- element.setAttribute(this.childSelectedAttr, String(isSelected));
74
- controls?.setAttribute('aria-labelledby', element.id);
75
- controls?.setAttribute('aria-hidden', String(!isSelected));
76
- });
77
-
78
- parent.addEventListener('click', (event) => {
79
- this.onClick(event);
80
- });
81
-
82
- parent.addEventListener('keydown', (event) => {
83
- this.onKeyDown(event);
84
- });
85
- }
86
-
87
- /** @type {string} */
88
- get selector() {
89
- const roles = config[this.role].childRoles;
90
-
91
- return roles ? roles.map((role) => `[role="${role}"]`).join(',') : '';
92
- }
93
-
94
- /** @type {HTMLElement[]} */
95
- get allMembers() {
96
- // @ts-ignore
97
- return [...this.parent.querySelectorAll(this.selector)];
98
- }
99
-
100
- /** @type {HTMLElement[]} */
101
- get activeMembers() {
102
- return this.allMembers.filter((element) => !element.matches('[aria-disabled="true"]'));
103
- }
104
-
105
- /**
106
- *
107
- * @param {MouseEvent} event `click` event.
108
- */
109
- onClick(event) {
110
- // eslint-disable-next-line prefer-destructuring
111
- const target = /** @type {HTMLButtonElement} */ (event.target);
112
-
113
- if (!target.matches(this.selector)) {
114
- return;
115
- }
116
-
117
- const targetParentGroup = target.closest(this.parentGroupSelector);
118
-
119
- this.allMembers.forEach((element) => {
120
- const isTarget = element === target;
121
-
122
- element.tabIndex = element === target ? 0 : -1;
123
-
124
- // Groups can be nested, e.g. `menu` > `group` > `menuitem`, so check if the parent is the
125
- // same as the target’s parent
126
- if (
127
- (element.matches('[role="radio"], [role="menuitemradio"]') ||
128
- (element.matches('[role="row"], [role="option"], [role="tab"]') && !this.multi)) &&
129
- element.closest(this.parentGroupSelector) === targetParentGroup
130
- ) {
131
- element.setAttribute(this.childSelectedAttr, String(isTarget));
132
- }
133
-
134
- const controls = element.getAttribute('aria-controls');
135
-
136
- if (controls) {
137
- document.getElementById(controls)?.setAttribute('aria-hidden', String(!isTarget));
138
- }
139
- });
140
-
141
- this.parent.dispatchEvent(
142
- new CustomEvent('select', {
143
- detail: {
144
- value: target.value,
145
- name: target.name,
146
- },
147
- }),
148
- );
149
- }
150
-
151
- /**
152
- *
153
- * @param {KeyboardEvent} event `keydown` event.
154
- */
155
- onKeyDown(event) {
156
- // eslint-disable-next-line prefer-destructuring
157
- const target = /** @type {HTMLElement} */ (event.target);
158
- const { key, ctrlKey, metaKey, shiftKey, altKey } = event;
159
-
160
- if (target.matches(this.selector) && !ctrlKey && !metaKey && !shiftKey && !altKey) {
161
- if ([' ', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(key)) {
162
- event.preventDefault();
163
- }
164
-
165
- if (key === ' ' || (key === 'Enter' && !target.matches('button'))) {
166
- event.preventDefault();
167
- target.click();
168
-
169
- return;
170
- }
171
-
172
- const { allMembers, activeMembers } = this;
173
- let index;
174
- let newTarget;
175
-
176
- if (this.grid) {
177
- const colCount = Math.floor(this.parent.clientWidth / target.clientWidth);
178
-
179
- index = allMembers.indexOf(target);
180
-
181
- if (key === 'ArrowUp' && index > 0) {
182
- newTarget = allMembers[index - colCount];
183
- }
184
-
185
- if (key === 'ArrowDown' && index < allMembers.length - 1) {
186
- newTarget = allMembers[index + colCount];
187
- }
188
-
189
- if (key === 'ArrowLeft' && index > 0) {
190
- newTarget = allMembers[index - 1];
191
- }
192
-
193
- if (key === 'ArrowRight' && index < allMembers.length - 1) {
194
- newTarget = allMembers[index + 1];
195
- }
196
-
197
- if (newTarget?.getAttribute('aria-disabled') === 'true') {
198
- newTarget = undefined;
199
- }
200
- } else {
201
- index = activeMembers.indexOf(target);
202
-
203
- if (key === (this.orientation === 'horizontal' ? 'ArrowLeft' : 'ArrowUp')) {
204
- if (index > 0) {
205
- // Previous member
206
- newTarget = activeMembers[index - 1];
207
- }
208
-
209
- if (index === 0) {
210
- // Last member
211
- newTarget = activeMembers[activeMembers.length - 1];
212
- }
213
- }
214
-
215
- if (key === (this.orientation === 'horizontal' ? 'ArrowRight' : 'ArrowDown')) {
216
- if (index < activeMembers.length - 1) {
217
- // Next member
218
- newTarget = activeMembers[index + 1];
219
- }
220
-
221
- if (index === activeMembers.length - 1) {
222
- // First member
223
- [newTarget] = activeMembers;
224
- }
225
- }
226
- }
227
-
228
- if (newTarget && newTarget !== target) {
229
- activeMembers.forEach((element) => {
230
- element.tabIndex = element === newTarget ? 0 : -1;
231
- });
232
-
233
- newTarget.focus();
234
- }
235
- }
236
- }
237
- }
238
-
239
- /**
240
- * Activate a new group.
241
- * @param {...any} args Arguments.
242
- */
243
- export const activateGroup = (...args) => {
244
- (async () => {
245
- // Wait a bit before the relevant components, including the `aria-controls` target are mounted
246
- await sleep(100);
247
-
248
- // @ts-ignore
249
- return new Group(...args);
250
- })();
251
- };
@@ -1,30 +0,0 @@
1
- export function activatePopup(...args: any[]): Popup;
2
- /**
3
- *
4
- */
5
- declare class Popup {
6
- /**
7
- *
8
- * @param {HTMLElement} anchorElement
9
- * @param {HTMLElement} popupElement
10
- * @param {PopupPosition} position
11
- */
12
- constructor(anchorElement: HTMLElement, popupElement: HTMLElement, position: PopupPosition);
13
- open: import("svelte/store").Writable<boolean>;
14
- style: import("svelte/store").Writable<{
15
- inset: any;
16
- zIndex: any;
17
- width: any;
18
- height: any;
19
- }>;
20
- observer: IntersectionObserver;
21
- anchorElement: HTMLElement;
22
- popupElement: HTMLElement;
23
- position: PopupPosition;
24
- id: string;
25
- /**
26
- * Continue checking the position in case the window or parent element resizes.
27
- */
28
- checkPosition(): void;
29
- }
30
- export {};
@@ -1 +0,0 @@
1
- export function getRandomId(prefix?: string, length?: number): string;
@@ -1,14 +0,0 @@
1
- /**
2
- * Get a random ID that can be used for elements.
3
- * @param {string} [prefix] Prefix to be added to the ID, e.g. `popup`.
4
- * @param {number} [length] Number of characters to be used in the ID.
5
- * @returns {string} Generated ID.
6
- */
7
- export const getRandomId = (prefix = '', length = 7) =>
8
- [
9
- prefix,
10
- new Array(length)
11
- .fill()
12
- .map(() => '0123456789abcdef'[Math.floor(Math.random() * 12)])
13
- .join(''),
14
- ].join('-');
File without changes