@torpor/ui 0.3.5 → 0.3.6

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 (225) hide show
  1. package/dist/metafile-esm.json +1 -1
  2. package/package.json +5 -2
  3. package/CHANGELOG.md +0 -344
  4. package/scripts/postbuild.ts +0 -127
  5. package/src/Accordion/Accordion.torp +0 -230
  6. package/src/Accordion/AccordionContent.torp +0 -46
  7. package/src/Accordion/AccordionHeader.torp +0 -45
  8. package/src/Accordion/AccordionItem.torp +0 -101
  9. package/src/Accordion/AccordionTrigger.torp +0 -70
  10. package/src/Accordion/AccordionTypes.ts +0 -36
  11. package/src/Accordion/index.ts +0 -7
  12. package/src/Breadcrumb/Breadcrumb.torp +0 -45
  13. package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
  14. package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
  15. package/src/Breadcrumb/index.ts +0 -5
  16. package/src/Calendar/Calendar.torp +0 -277
  17. package/src/Calendar/CalendarDay.torp +0 -78
  18. package/src/Calendar/CalendarTypes.ts +0 -22
  19. package/src/Calendar/index.ts +0 -4
  20. package/src/Contextual/Contextual.torp +0 -129
  21. package/src/Contextual/ContextualContent.torp +0 -112
  22. package/src/Contextual/ContextualTrigger.torp +0 -70
  23. package/src/Contextual/ContextualTypes.ts +0 -30
  24. package/src/Contextual/index.ts +0 -5
  25. package/src/Dialog/Dialog.torp +0 -136
  26. package/src/Dialog/DialogBody.torp +0 -44
  27. package/src/Dialog/DialogButton.torp +0 -66
  28. package/src/Dialog/DialogFooter.torp +0 -25
  29. package/src/Dialog/DialogHeader.torp +0 -45
  30. package/src/Dialog/DialogTypes.ts +0 -17
  31. package/src/Dialog/index.ts +0 -7
  32. package/src/Disclosure/Disclosure.torp +0 -82
  33. package/src/Disclosure/DisclosureContent.torp +0 -46
  34. package/src/Disclosure/DisclosureHeader.torp +0 -45
  35. package/src/Disclosure/DisclosureTrigger.torp +0 -47
  36. package/src/Disclosure/DisclosureTypes.ts +0 -13
  37. package/src/Disclosure/index.ts +0 -6
  38. package/src/Drawer/Drawer.torp +0 -127
  39. package/src/Drawer/DrawerContent.torp +0 -83
  40. package/src/Drawer/DrawerOverlay.torp +0 -42
  41. package/src/Drawer/DrawerTrigger.torp +0 -39
  42. package/src/Drawer/DrawerTypes.ts +0 -24
  43. package/src/Drawer/index.ts +0 -6
  44. package/src/Form/CheckBox.torp +0 -94
  45. package/src/Form/Field.torp +0 -95
  46. package/src/Form/File.torp +0 -102
  47. package/src/Form/Form.torp +0 -147
  48. package/src/Form/FormTypes.ts +0 -35
  49. package/src/Form/Hidden.torp +0 -25
  50. package/src/Form/Input.torp +0 -112
  51. package/src/Form/Label.torp +0 -35
  52. package/src/Form/Message.torp +0 -39
  53. package/src/Form/Option.torp +0 -28
  54. package/src/Form/Select.torp +0 -101
  55. package/src/Form/StandardSchemaV1.ts +0 -70
  56. package/src/Form/TextArea.torp +0 -105
  57. package/src/Form/index.ts +0 -13
  58. package/src/Menu/Menu.torp +0 -174
  59. package/src/Menu/MenuButton.torp +0 -74
  60. package/src/Menu/MenuCheck.torp +0 -89
  61. package/src/Menu/MenuGroup.torp +0 -31
  62. package/src/Menu/MenuIndicator.torp +0 -40
  63. package/src/Menu/MenuPopout.torp +0 -83
  64. package/src/Menu/MenuPopoutContent.torp +0 -84
  65. package/src/Menu/MenuPopoutTrigger.torp +0 -128
  66. package/src/Menu/MenuRadio.torp +0 -103
  67. package/src/Menu/MenuRadioGroup.torp +0 -109
  68. package/src/Menu/MenuSeparator.torp +0 -26
  69. package/src/Menu/MenuTypes.ts +0 -60
  70. package/src/Menu/index.ts +0 -25
  71. package/src/MenuBar/MenuBar.torp +0 -162
  72. package/src/MenuBar/MenuBarItem.torp +0 -116
  73. package/src/MenuBar/MenuBarItemContent.torp +0 -119
  74. package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
  75. package/src/MenuBar/MenuBarTypes.ts +0 -36
  76. package/src/MenuBar/index.ts +0 -6
  77. package/src/Modal/Modal.torp +0 -122
  78. package/src/Modal/ModalContent.torp +0 -81
  79. package/src/Modal/ModalOverlay.torp +0 -42
  80. package/src/Modal/ModalTrigger.torp +0 -54
  81. package/src/Modal/ModalTypes.ts +0 -22
  82. package/src/Modal/index.ts +0 -10
  83. package/src/Modal/showModal.ts +0 -19
  84. package/src/Modal/showPrompt.ts +0 -23
  85. package/src/NavMenu/NavMenu.torp +0 -190
  86. package/src/NavMenu/NavMenuButton.torp +0 -55
  87. package/src/NavMenu/NavMenuElement.torp +0 -55
  88. package/src/NavMenu/NavMenuGroup.torp +0 -41
  89. package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
  90. package/src/NavMenu/NavMenuLink.torp +0 -60
  91. package/src/NavMenu/NavMenuPopout.torp +0 -89
  92. package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
  93. package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
  94. package/src/NavMenu/NavMenuSeparator.torp +0 -24
  95. package/src/NavMenu/NavMenuTypes.ts +0 -32
  96. package/src/NavMenu/index.ts +0 -23
  97. package/src/Notification/Notification.torp +0 -71
  98. package/src/Notification/NotificationClose.torp +0 -39
  99. package/src/Notification/NotificationContainer.torp +0 -26
  100. package/src/Notification/NotificationContent.torp +0 -25
  101. package/src/Notification/NotificationTypes.ts +0 -5
  102. package/src/Notification/index.ts +0 -13
  103. package/src/Notification/showNotification.ts +0 -30
  104. package/src/Popover/Popover.torp +0 -129
  105. package/src/Popover/PopoverContent.torp +0 -117
  106. package/src/Popover/PopoverTrigger.torp +0 -62
  107. package/src/Popover/PopoverTypes.ts +0 -30
  108. package/src/Popover/index.ts +0 -6
  109. package/src/Popover/showPopover.ts +0 -24
  110. package/src/Slider/Slider.torp +0 -84
  111. package/src/Slider/index.ts +0 -3
  112. package/src/TabGroup/TabContent.torp +0 -49
  113. package/src/TabGroup/TabGroup.torp +0 -250
  114. package/src/TabGroup/TabGroupTypes.ts +0 -44
  115. package/src/TabGroup/TabHeader.torp +0 -81
  116. package/src/TabGroup/TabList.torp +0 -61
  117. package/src/TabGroup/TabTrigger.torp +0 -76
  118. package/src/TabGroup/index.ts +0 -7
  119. package/src/ambient.d.ts +0 -7
  120. package/src/icons/ArrowDown.torp +0 -18
  121. package/src/icons/ArrowLeft.torp +0 -18
  122. package/src/icons/ArrowRight.torp +0 -18
  123. package/src/icons/ArrowUp.torp +0 -18
  124. package/src/icons/Bars.torp +0 -20
  125. package/src/icons/Check.torp +0 -18
  126. package/src/icons/ChevronDown.torp +0 -18
  127. package/src/icons/ChevronLeft.torp +0 -18
  128. package/src/icons/ChevronRight.torp +0 -18
  129. package/src/icons/ChevronUp.torp +0 -18
  130. package/src/icons/Cross.torp +0 -19
  131. package/src/icons/IconTypes.ts +0 -10
  132. package/src/icons/Loading.torp +0 -19
  133. package/src/icons/Minus.torp +0 -18
  134. package/src/icons/Plus.torp +0 -19
  135. package/src/icons/index.ts +0 -31
  136. package/src/motion/fade.ts +0 -16
  137. package/src/motion/grow.ts +0 -23
  138. package/src/motion/index.ts +0 -6
  139. package/src/motion/measure.ts +0 -28
  140. package/src/motion/slide.ts +0 -45
  141. package/src/mount/clickPopover.ts +0 -51
  142. package/src/mount/contextPopover.ts +0 -51
  143. package/src/mount/disableScroll.ts +0 -28
  144. package/src/mount/hoverPopover.ts +0 -58
  145. package/src/mount/hoverTrigger.ts +0 -59
  146. package/src/mount/trapFocus.ts +0 -58
  147. package/src/utils/dateUtils.ts +0 -244
  148. package/src/utils/documentEvents.ts +0 -17
  149. package/src/utils/getId.ts +0 -6
  150. package/src/utils/getScrollParent.ts +0 -22
  151. package/src/utils/setContextPosition.ts +0 -31
  152. package/src/utils/setPopoverPosition.ts +0 -142
  153. package/test/Accordion/accessibility.test.ts +0 -59
  154. package/test/Accordion/components/AccordionAccessibility.torp +0 -44
  155. package/test/Accordion/components/AccordionKeyboard.torp +0 -32
  156. package/test/Accordion/components/AccordionList.torp +0 -23
  157. package/test/Accordion/components/AccordionMultiple.torp +0 -32
  158. package/test/Accordion/components/AccordionSingle.torp +0 -32
  159. package/test/Accordion/for-items.test.ts +0 -52
  160. package/test/Accordion/keyboard.test.ts +0 -64
  161. package/test/Accordion/multiple-item-toggle.test.ts +0 -32
  162. package/test/Accordion/multiple-item-value.test.ts +0 -17
  163. package/test/Accordion/single-item-toggle.test.ts +0 -31
  164. package/test/Accordion/single-item-value.test.ts +0 -17
  165. package/test/Breadcrumb/accessibility.test.ts +0 -29
  166. package/test/Breadcrumb/basic.test.ts +0 -17
  167. package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
  168. package/test/Calendar/components/CalendarTest.torp +0 -9
  169. package/test/Calendar/default.test.ts +0 -18
  170. package/test/Dialog/accessibility-alert.test.ts +0 -40
  171. package/test/Dialog/accessibility-modal.test.ts +0 -52
  172. package/test/Dialog/components/DialogAccessibility.torp +0 -25
  173. package/test/Dialog/components/DialogFunction.torp +0 -36
  174. package/test/Dialog/components/DialogModal.torp +0 -30
  175. package/test/Dialog/components/DialogVariable.torp +0 -33
  176. package/test/Dialog/function.test.ts +0 -26
  177. package/test/Dialog/variable.test.ts +0 -27
  178. package/test/Disclosure/accessibility.test.ts +0 -31
  179. package/test/Disclosure/components/DisclosureTest.torp +0 -17
  180. package/test/Disclosure/default.test.ts +0 -15
  181. package/test/Disclosure/toggle.test.ts +0 -20
  182. package/test/Form/components/FieldTest.torp +0 -25
  183. package/test/Form/components/FormTest.torp +0 -31
  184. package/test/Form/components/InputTest.torp +0 -9
  185. package/test/Form/field.test.ts +0 -34
  186. package/test/Form/form.test.ts +0 -34
  187. package/test/Form/input.test.ts +0 -19
  188. package/test/Menu/accessibility.test.ts +0 -83
  189. package/test/Menu/basic.test.ts +0 -58
  190. package/test/Menu/components/MenuAccessibility.torp +0 -59
  191. package/test/Menu/components/MenuBasic.torp +0 -58
  192. package/test/MenuBar/accessibility.test.ts +0 -87
  193. package/test/MenuBar/basic.test.ts +0 -22
  194. package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
  195. package/test/MenuBar/components/MenuBarBasic.torp +0 -25
  196. package/test/NavMenu/accessibility.test.ts +0 -97
  197. package/test/NavMenu/basic.test.ts +0 -22
  198. package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
  199. package/test/NavMenu/components/NavMenuBasic.torp +0 -28
  200. package/test/Notification/accessibility.test.ts +0 -21
  201. package/test/Notification/components/CustomNotification.torp +0 -14
  202. package/test/Notification/components/NotificationAccessibility.torp +0 -14
  203. package/test/Notification/components/NotificationFunction.torp +0 -17
  204. package/test/Notification/components/NotificationVariable.torp +0 -22
  205. package/test/Notification/function.test.ts +0 -25
  206. package/test/Notification/variable.test.ts +0 -25
  207. package/test/Popover/components/CustomDialog.torp +0 -25
  208. package/test/Popover/components/PopoverFunction.torp +0 -37
  209. package/test/Popover/components/PopoverTrigger.torp +0 -36
  210. package/test/Popover/components/PopoverVariable.torp +0 -40
  211. package/test/Popover/function.test.ts +0 -21
  212. package/test/Popover/trigger.test.ts +0 -27
  213. package/test/Popover/variable.test.ts +0 -27
  214. package/test/TabGroup/accessibility.test.ts +0 -67
  215. package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
  216. package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
  217. package/test/TabGroup/components/TabGroupList.torp +0 -26
  218. package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
  219. package/test/TabGroup/for-items.test.ts +0 -52
  220. package/test/TabGroup/item-trigger.test.ts +0 -33
  221. package/test/TabGroup/item-value.test.ts +0 -17
  222. package/test/TabGroup/keyboard.test.ts +0 -72
  223. package/tsconfig.json +0 -4
  224. package/tsup.config.ts +0 -37
  225. package/vitest.config.ts +0 -12
@@ -1,18 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function ChevronRight($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="12"
12
- >
13
- <g>
14
- <path d="M30,10 L70,50 L30,90" fill="none" />
15
- </g>
16
- </svg>
17
- }
18
- }
@@ -1,18 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function ChevronUp($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="12"
12
- >
13
- <g>
14
- <path d="M10,70 L50,30 L90,70" fill="none" />
15
- </g>
16
- </svg>
17
- }
18
- }
@@ -1,19 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function Cross($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="12"
12
- >
13
- <g>
14
- <path d="M15,15 L85,85" />
15
- <path d="M15,85 L85,15" />
16
- </g>
17
- </svg>
18
- }
19
- }
@@ -1,10 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- export interface IconProps {
4
- /** An ID for the svg element */
5
- id?: string;
6
- /** Classes for the svg element */
7
- class?: ClassValue;
8
- /** Styles for the root element */
9
- style?: StyleValue;
10
- }
@@ -1,19 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function Loading($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="20"
12
- >
13
- <g>
14
- <circle cx="50" cy="50" r="40" fill="none" opacity="0.3" />
15
- <path d="M 22 22 A 40 40 0 0 1 78 22" fill="none" />
16
- </g>
17
- </svg>
18
- }
19
- }
@@ -1,18 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function Minus($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="12"
12
- >
13
- <g>
14
- <path d="M10,50 L90,50" />
15
- </g>
16
- </svg>
17
- }
18
- }
@@ -1,19 +0,0 @@
1
- import { type IconProps } from "./IconTypes";
2
-
3
- export default function Plus($props: IconProps | undefined) {
4
- @render {
5
- <svg
6
- {$props?.id}
7
- class={["torp-icon", $props?.class]}
8
- {$props?.style}
9
- viewBox="0 0 100 100"
10
- stroke-linejoin="round"
11
- stroke-width="12"
12
- >
13
- <g>
14
- <path d="M50,10 L50,90" />
15
- <path d="M10,50 L90,50" />
16
- </g>
17
- </svg>
18
- }
19
- }
@@ -1,31 +0,0 @@
1
- import ArrowDown from "./ArrowDown.torp";
2
- import ArrowLeft from "./ArrowLeft.torp";
3
- import ArrowRight from "./ArrowRight.torp";
4
- import ArrowUp from "./ArrowUp.torp";
5
- import Bars from "./Bars.torp";
6
- import Check from "./Check.torp";
7
- import ChevronDown from "./ChevronDown.torp";
8
- import ChevronLeft from "./ChevronLeft.torp";
9
- import ChevronRight from "./ChevronRight.torp";
10
- import ChevronUp from "./ChevronUp.torp";
11
- import Cross from "./Cross.torp";
12
- import Loading from "./Loading.torp";
13
- import Minus from "./Minus.torp";
14
- import Plus from "./Plus.torp";
15
-
16
- export {
17
- ArrowDown,
18
- ArrowLeft,
19
- ArrowRight,
20
- ArrowUp,
21
- Bars,
22
- Check,
23
- ChevronDown,
24
- ChevronLeft,
25
- ChevronRight,
26
- ChevronUp,
27
- Cross,
28
- Loading,
29
- Minus,
30
- Plus,
31
- };
@@ -1,16 +0,0 @@
1
- import { type Animation } from "@torpor/view";
2
-
3
- export default function fade(
4
- _el: HTMLElement,
5
- options?: number | KeyframeAnimationOptions,
6
- ): Animation {
7
- const keyframes = [
8
- {
9
- opacity: 0,
10
- },
11
- {
12
- opacity: 1,
13
- },
14
- ];
15
- return { keyframes, options };
16
- }
@@ -1,23 +0,0 @@
1
- import { type Animation } from "@torpor/view";
2
- import measure from "./measure";
3
-
4
- export default function grow(
5
- el: HTMLElement,
6
- options?: number | KeyframeAnimationOptions,
7
- ): Animation {
8
- const height = measure(el, (el) => el.clientHeight);
9
- const keyframes = [
10
- {
11
- height: "0px",
12
- overflow: "hidden",
13
- paddingTop: "0px",
14
- paddingBottom: "0px",
15
- marginTop: "0px",
16
- marginBottom: "0px",
17
- },
18
- {
19
- height: height + "px",
20
- },
21
- ];
22
- return { keyframes, options };
23
- }
@@ -1,6 +0,0 @@
1
- import fade from "./fade";
2
- import grow from "./grow";
3
- import measure from "./measure";
4
- import slide from "./slide";
5
-
6
- export { fade, grow, measure, slide };
@@ -1,28 +0,0 @@
1
- /**
2
- * Measures an element before it is added to the DOM
3
- * @param el The element to measure
4
- * @param fn The function to use to get the desired measurement (e.g. el.offsetHeight)
5
- */
6
- export default function measure(el: HTMLElement, fn: (_: HTMLElement) => number): number {
7
- // From https://stackoverflow.com/a/46707458
8
- let oldVisibility = el.style.visibility;
9
- let oldPosition = el.style.position;
10
-
11
- let oldParent = el.parentNode;
12
- let oldBefore = el.nextSibling;
13
-
14
- el.style.visibility = "hidden";
15
- el.style.position = "absolute";
16
-
17
- document.body.appendChild(el);
18
- let result = fn(el);
19
- el.parentNode!.removeChild(el);
20
-
21
- if (oldParent !== null) {
22
- oldParent.insertBefore(el, oldBefore);
23
- el.style.visibility = oldVisibility;
24
- el.style.position = oldPosition;
25
- }
26
-
27
- return result;
28
- }
@@ -1,45 +0,0 @@
1
- import { type Animation } from "@torpor/view";
2
- import measure from "./measure";
3
-
4
- interface Options extends KeyframeAnimationOptions {
5
- side: "left" | "right" | "top" | "bottom";
6
- }
7
-
8
- export default function slide(el: HTMLElement, options?: Options): Animation {
9
- let position = options?.side ?? "left";
10
- switch (position) {
11
- case "left": {
12
- el.style.left = "0px";
13
- const width = measure(el, (el) => el.offsetWidth);
14
- const keyframes = [
15
- { transform: `translateX(-${width}px)` },
16
- { transform: "translateX(0px)" },
17
- ];
18
- return { keyframes, options };
19
- }
20
- case "top": {
21
- el.style.top = "0px";
22
- const height = measure(el, (el) => el.offsetHeight);
23
- const keyframes = [
24
- { transform: `translateY(-${height}px)` },
25
- { transform: "translateY(0px)" },
26
- ];
27
- return { keyframes, options };
28
- }
29
- case "right": {
30
- el.style.right = "0px";
31
- const width = measure(el, (el) => el.offsetWidth);
32
- const keyframes = [{ transform: `translateX(${width}px)` }, { transform: "translateX(0px)" }];
33
- return { keyframes, options };
34
- }
35
- case "bottom": {
36
- el.style.bottom = "0px";
37
- const height = measure(el, (el) => el.offsetHeight);
38
- const keyframes = [
39
- { transform: `translateY(${height}px)` },
40
- { transform: "translateY(0px)" },
41
- ];
42
- return { keyframes, options };
43
- }
44
- }
45
- }
@@ -1,51 +0,0 @@
1
- //import type { Component } from "@torpor/view";
2
- //import showPopover from "../Modal/showModal";
3
- //
4
- //interface ClickPopoverOptions {
5
- // popover: Component;
6
- // props?: Record<PropertyKey, any>;
7
- //}
8
- //
9
- ///**
10
- // * A mount directive for showing a popover when an element is clicked.
11
- // * @param node The element to show the popover for
12
- // * @param options Options for showing the popover, consisting of the popover component and any props
13
- // */
14
- //export default function clickPopover(node: HTMLElement, options: ClickPopoverOptions) {
15
- // const { popover, props } = options;
16
- //
17
- // // Add a click event handler to the node
18
- // node.addEventListener("click", handleClick);
19
- //
20
- // function handleClick(e: MouseEvent) {
21
- // e.preventDefault();
22
- // show();
23
- // }
24
- //
25
- // let div: HTMLDivElement;
26
- //
27
- // function show() {
28
- // // Show the popover in a div
29
- // if (div) {
30
- // document.body.removeChild(div);
31
- // }
32
- // div = document.createElement("div");
33
- // document.body.appendChild(div);
34
- //
35
- // showPopover(popover, node, props, div);
36
- // }
37
- //
38
- // return {
39
- // destroy(): void {
40
- // // Remove the event listener from the node on destroy
41
- // node.removeEventListener("click", handleClick);
42
- //
43
- // // Remove the div we added
44
- // // TODO: Should we do this in more places?
45
- // if (div) {
46
- // document.body.removeChild(div);
47
- // }
48
- // },
49
- // };
50
- //}
51
- //
@@ -1,51 +0,0 @@
1
- //import type { Component } from "@torpor/view";
2
- //import showPopover from "../Modal/showModal";
3
- //
4
- //interface ContextPopoverOptions {
5
- // popover: Component;
6
- // props?: Record<PropertyKey, any>;
7
- //}
8
- //
9
- ///**
10
- // * A mount directive for showing a popover when the user opens an element's context menu.
11
- // * @param node The element to show the popover for
12
- // * @param options Options for showing the popover, consisting of the popover component and any props
13
- // */
14
- //export default function contextPopover(node: HTMLElement, options: ContextPopoverOptions) {
15
- // const { popover, props } = options;
16
- //
17
- // // Add a contextmenu event handler to the node
18
- // node.addEventListener("contextmenu", handleClick);
19
- //
20
- // function handleClick(e: MouseEvent) {
21
- // e.preventDefault();
22
- // show();
23
- // }
24
- //
25
- // let div: HTMLDivElement;
26
- //
27
- // function show() {
28
- // // Show the popover in a div
29
- // if (div) {
30
- // document.body.removeChild(div);
31
- // }
32
- // div = document.createElement("div");
33
- // document.body.appendChild(div);
34
- //
35
- // showPopover(popover, node, props, div);
36
- // }
37
- //
38
- // return {
39
- // destroy(): void {
40
- // // Remove the event listener from the node on destroy
41
- // node.removeEventListener("contextmenu", handleClick);
42
- //
43
- // // Remove the div we added
44
- // // TODO: Should we do this in more places?
45
- // if (div) {
46
- // document.body.removeChild(div);
47
- // }
48
- // },
49
- // };
50
- //}
51
- //
@@ -1,28 +0,0 @@
1
- export function disableScroll(): () => void {
2
- // Remember body styles
3
- const overflowX = document.body.style.overflowY;
4
- const overflowY = document.body.style.overflowY;
5
- const overscrollBehaviourX = document.body.style.overscrollBehaviorX;
6
- const overscrollBehaviourY = document.body.style.overscrollBehaviorY;
7
- const marginRight = document.body.style.marginRight;
8
-
9
- // Get scrollbar width (if visible) so that we can set a margin to avoid things jumping around
10
- // HACK: Does this work in all browsers/systems?
11
- const scrollBarWidth = window.innerWidth - document.body.clientWidth;
12
-
13
- // Set body styles to disallow scrolling
14
- document.body.style.overflowY = "hidden";
15
- document.body.style.overflowY = "hidden";
16
- document.body.style.overscrollBehaviorX = "contain";
17
- document.body.style.overscrollBehaviorY = "contain";
18
- document.body.style.marginRight = scrollBarWidth + "px";
19
-
20
- return () => {
21
- // Reset body styles
22
- document.body.style.overflowY = overflowX;
23
- document.body.style.overflowY = overflowY;
24
- document.body.style.overscrollBehaviorX = overscrollBehaviourX;
25
- document.body.style.overscrollBehaviorY = overscrollBehaviourY;
26
- document.body.style.marginRight = marginRight;
27
- };
28
- }
@@ -1,58 +0,0 @@
1
- //import type { Component } from "@torpor/view";
2
- //import showPopover from "../Modal/showModal";
3
- //import hoverTrigger from "./hoverTrigger";
4
- //
5
- //interface HoverPopoverOptions {
6
- // popover: Component;
7
- // props?: Record<PropertyKey, any>;
8
- // hoverDelay?: number;
9
- // touchDelay?: number;
10
- //}
11
- //
12
- ///**
13
- // * A mount directive for showing a popover when an element is hovered.
14
- // * @param node The element to show the popover for
15
- // * @param options Options for showing the popover, consisting of the popover component, any props and delays for hover and touch
16
- // */
17
- //export default function hoverPopover(node: HTMLElement, options: HoverPopoverOptions): () => void {
18
- // const { popover, props, hoverDelay, touchDelay } = options;
19
- //
20
- // let div: HTMLDivElement | undefined;
21
- //
22
- // function onHover(node: HTMLElement, e: MouseEvent | TouchEvent) {
23
- // // Show the popover in a div
24
- // if (div) {
25
- // document.body.removeChild(div);
26
- // }
27
- // div = document.createElement("div");
28
- // document.body.appendChild(div);
29
- //
30
- // // Get the position relative to the element, so we can reposition on scroll
31
- // const rect = node.getBoundingClientRect();
32
- // let position: { x: number; y: number };
33
- // if (e.type.startsWith("mouse")) {
34
- // const me = e as MouseEvent;
35
- // position = { x: me.clientX - rect.left, y: me.clientY - rect.top };
36
- // } else {
37
- // const te = e as TouchEvent;
38
- // position = {
39
- // x: te.touches[0].clientX - rect.left,
40
- // y: te.touches[0].clientY - rect.top,
41
- // };
42
- // }
43
- // const allProps = Object.assign({}, props, { anchor: node, position });
44
- //
45
- // showPopover(popover, node, allProps, div);
46
- // }
47
- //
48
- // function onExit() {
49
- // // Remove the div
50
- // if (div) {
51
- // document.body.removeChild(div);
52
- // div = undefined;
53
- // }
54
- // }
55
- //
56
- // return hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });
57
- //}
58
- //
@@ -1,59 +0,0 @@
1
- interface HoverTriggerOptions {
2
- onHover: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;
3
- onExit?: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;
4
- hoverDelay?: number;
5
- touchDelay?: number;
6
- }
7
-
8
- export default function hoverTrigger(node: HTMLElement, options: HoverTriggerOptions): () => void {
9
- const { onHover, onExit } = options;
10
- const hoverDelay = options.hoverDelay || 1000;
11
- const touchDelay = options.touchDelay || 1000;
12
-
13
- let interval: NodeJS.Timeout | undefined;
14
-
15
- // Add click event handlers to the node
16
- node.addEventListener("mouseenter", handleMouseEnter);
17
- node.addEventListener("mouseleave", handleMouseLeave);
18
- node.addEventListener("mousemove", handleMouseMove);
19
- node.addEventListener("touchstart", handleMouseEnter);
20
- node.addEventListener("touchend", handleMouseLeave);
21
-
22
- function handleMouseEnter(e: MouseEvent | TouchEvent) {
23
- // Handle the hover after a delay
24
- e.preventDefault();
25
- if (!interval) {
26
- const delay = e.type.startsWith("mouse") ? hoverDelay : touchDelay;
27
- interval = setTimeout(() => onHover(node, e), delay);
28
- }
29
- }
30
-
31
- function handleMouseLeave(e: MouseEvent | TouchEvent) {
32
- // Prevent short hovers or touches from firing the event
33
- if (interval) {
34
- clearTimeout(interval);
35
- interval = undefined;
36
- }
37
-
38
- if (onExit) {
39
- onExit(node, e);
40
- }
41
- }
42
-
43
- function handleMouseMove(e: MouseEvent) {
44
- // Reset the interval on mouse move
45
- if (interval) {
46
- clearTimeout(interval);
47
- interval = setTimeout(() => onHover(node, e), hoverDelay);
48
- }
49
- }
50
-
51
- // Remove the event listeners from the node on destroy
52
- return () => {
53
- node.removeEventListener("mouseenter", handleMouseEnter);
54
- node.removeEventListener("mouseleave", handleMouseLeave);
55
- node.removeEventListener("mousemove", handleMouseMove);
56
- node.removeEventListener("touchstart", handleMouseEnter);
57
- node.removeEventListener("touchend", handleMouseLeave);
58
- };
59
- }
@@ -1,58 +0,0 @@
1
- export interface TrapFocusOptions {
2
- focusableElements: HTMLElement[];
3
- }
4
-
5
- export function trapFocus(node: HTMLElement, options?: TrapFocusOptions): () => void {
6
- options = options || { focusableElements: [] };
7
-
8
- // Selectors for all things that are focusable:
9
- const focusableSelectors = [
10
- "a[href]",
11
- "area[href]",
12
- 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
13
- "select:not([disabled]):not([aria-hidden])",
14
- "textarea:not([disabled]):not([aria-hidden])",
15
- "button:not([disabled]):not([aria-hidden])",
16
- "iframe",
17
- "object",
18
- "embed",
19
- "[contenteditable]",
20
- '[tabindex]:not([tabindex^="-"])',
21
- ];
22
-
23
- // Set the focusable elements array in the options, which can be used in the caller e.g. to focus the first element
24
- options.focusableElements = Array.from(node.querySelectorAll(focusableSelectors.join()));
25
-
26
- // Store first and last focusable elements
27
- const firstFocusableElement = options.focusableElements[0] as HTMLElement;
28
- const lastFocusableElement = options.focusableElements[
29
- options.focusableElements.length - 1
30
- ] as HTMLElement;
31
-
32
- // Add the keydown event listener to the node
33
- node.addEventListener("keydown", handleKey);
34
-
35
- // On Tab or Shift+Tab, move through the focusable elements, wrapping at either end
36
- function handleKey(e: KeyboardEvent) {
37
- if (e.key === "Tab") {
38
- if (e.shiftKey) {
39
- if (document.activeElement === firstFocusableElement) {
40
- // Shift + Tab on the first element, so move to the last one
41
- lastFocusableElement.focus();
42
- e.preventDefault();
43
- }
44
- } else {
45
- if (document.activeElement === lastFocusableElement) {
46
- // Tab on the last element, so move to the first one
47
- firstFocusableElement.focus();
48
- e.preventDefault();
49
- }
50
- }
51
- }
52
- }
53
-
54
- // Remove the keydown event listener from the node on destroy
55
- return () => {
56
- node.removeEventListener("keydown", handleKey);
57
- };
58
- }