@torpor/ui 0.0.17 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/Accordion/Accordion.torp +53 -54
- package/dist/Accordion/AccordionContent.torp +5 -5
- package/dist/Accordion/AccordionHeader.torp +5 -4
- package/dist/Accordion/AccordionItem.torp +13 -8
- package/dist/Accordion/AccordionTrigger.torp +5 -5
- package/dist/Accordion/AccordionTypes.ts +1 -0
- package/dist/Dialog/Dialog.torp +156 -0
- package/dist/Dialog/DialogBody.torp +34 -0
- package/dist/Dialog/DialogButton.torp +48 -0
- package/dist/Dialog/DialogFooter.torp +13 -0
- package/dist/Dialog/DialogHeader.torp +34 -0
- package/dist/Dialog/DialogTypes.ts +16 -0
- package/dist/Dialog/index.cjs +53 -0
- package/dist/Dialog/index.cjs.map +1 -0
- package/dist/Dialog/index.js +22 -0
- package/dist/Dialog/index.js.map +1 -0
- package/dist/NavMenu/NavMenu.torp +178 -0
- package/dist/NavMenu/NavMenuButton.torp +46 -0
- package/dist/NavMenu/NavMenuElement.torp +43 -0
- package/dist/NavMenu/NavMenuGroup.torp +30 -0
- package/dist/NavMenu/NavMenuGroupHeader.torp +30 -0
- package/dist/NavMenu/NavMenuLink.torp +52 -0
- package/dist/NavMenu/NavMenuPopout.torp +69 -0
- package/dist/NavMenu/NavMenuPopoutButton.torp +120 -0
- package/dist/NavMenu/NavMenuPopoutContent.torp +79 -0
- package/dist/NavMenu/NavMenuSeparator.torp +14 -0
- package/dist/NavMenu/NavMenuTypes.ts +32 -0
- package/dist/NavMenu/index.cjs +78 -0
- package/dist/NavMenu/index.cjs.map +1 -0
- package/dist/NavMenu/index.js +42 -0
- package/dist/NavMenu/index.js.map +1 -0
- package/dist/Offscreen/Offscreen.torp +93 -0
- package/dist/Offscreen/index.cjs +33 -0
- package/dist/Offscreen/index.cjs.map +1 -0
- package/dist/Offscreen/index.js +6 -0
- package/dist/Offscreen/index.js.map +1 -0
- package/dist/Popover/Popover.torp +105 -0
- package/dist/Popover/PopoverContent.torp +78 -0
- package/dist/Popover/PopoverContentAnchored.torp +107 -0
- package/dist/Popover/PopoverContentContextual.torp +99 -0
- package/dist/Popover/PopoverOverlay.torp +32 -0
- package/dist/Popover/PopoverTrigger.torp +29 -0
- package/dist/Popover/PopoverTriggerContextual.torp +37 -0
- package/dist/Popover/PopoverTriggerHover.torp +38 -0
- package/dist/Popover/PopoverTypes.ts +30 -0
- package/dist/Popover/index.cjs +222 -0
- package/dist/Popover/index.cjs.map +1 -0
- package/dist/Popover/index.js +183 -0
- package/dist/Popover/index.js.map +1 -0
- package/dist/Popover/mountClickPopover.ts +50 -0
- package/dist/Popover/mountContextPopover.ts +50 -0
- package/dist/Popover/mountHoverPopover.ts +57 -0
- package/dist/Popover/showPopover.ts +24 -0
- package/dist/Popover/showPopoverPrompt.ts +23 -0
- package/dist/TabGroup/TabContent.torp +4 -4
- package/dist/TabGroup/TabGroup.torp +64 -62
- package/dist/TabGroup/TabGroupTypes.ts +1 -0
- package/dist/TabGroup/TabHeader.torp +10 -8
- package/dist/TabGroup/TabList.torp +4 -3
- package/dist/TabGroup/TabTrigger.torp +6 -6
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/mount/disableScroll.ts +28 -0
- package/dist/mount/hoverTrigger.ts +59 -0
- package/dist/mount/trapFocus.ts +58 -0
- package/dist/utils/documentEvents.ts +17 -0
- package/dist/utils/getScrollParent.ts +22 -0
- package/dist/utils/setContextPosition.ts +31 -0
- package/dist/utils/setPopoverPosition.ts +138 -0
- package/package.json +26 -6
- package/scripts/postbuild.ts +17 -5
- package/src/Accordion/Accordion.torp +53 -54
- package/src/Accordion/AccordionContent.torp +5 -5
- package/src/Accordion/AccordionHeader.torp +5 -4
- package/src/Accordion/AccordionItem.torp +13 -8
- package/src/Accordion/AccordionTrigger.torp +5 -5
- package/src/Accordion/AccordionTypes.ts +1 -0
- package/src/Dialog/Dialog.torp +156 -0
- package/src/Dialog/DialogBody.torp +34 -0
- package/src/Dialog/DialogButton.torp +48 -0
- package/src/Dialog/DialogFooter.torp +13 -0
- package/src/Dialog/DialogHeader.torp +34 -0
- package/src/Dialog/DialogTypes.ts +16 -0
- package/src/Dialog/index.ts +7 -0
- package/src/Dialog.ts +7 -0
- package/src/NavMenu/NavMenu.torp +178 -0
- package/src/NavMenu/NavMenuButton.torp +46 -0
- package/src/NavMenu/NavMenuElement.torp +43 -0
- package/src/NavMenu/NavMenuGroup.torp +30 -0
- package/src/NavMenu/NavMenuGroupHeader.torp +30 -0
- package/src/NavMenu/NavMenuLink.torp +52 -0
- package/src/NavMenu/NavMenuPopout.torp +69 -0
- package/src/NavMenu/NavMenuPopoutButton.torp +120 -0
- package/src/NavMenu/NavMenuPopoutContent.torp +79 -0
- package/src/NavMenu/NavMenuSeparator.torp +14 -0
- package/src/NavMenu/NavMenuTypes.ts +32 -0
- package/src/NavMenu/index.ts +23 -0
- package/src/NavMenu.ts +23 -0
- package/src/Offscreen/Offscreen.torp +93 -0
- package/src/Offscreen/index.ts +3 -0
- package/src/Popover/Popover.torp +105 -0
- package/src/Popover/PopoverContent.torp +78 -0
- package/src/Popover/PopoverContentAnchored.torp +107 -0
- package/src/Popover/PopoverContentContextual.torp +99 -0
- package/src/Popover/PopoverOverlay.torp +32 -0
- package/src/Popover/PopoverTrigger.torp +29 -0
- package/src/Popover/PopoverTriggerContextual.torp +37 -0
- package/src/Popover/PopoverTriggerHover.torp +38 -0
- package/src/Popover/PopoverTypes.ts +30 -0
- package/src/Popover/index.ts +29 -0
- package/src/Popover/mountClickPopover.ts +50 -0
- package/src/Popover/mountContextPopover.ts +50 -0
- package/src/Popover/mountHoverPopover.ts +57 -0
- package/src/Popover/showPopover.ts +24 -0
- package/src/Popover/showPopoverPrompt.ts +23 -0
- package/src/Popover.ts +29 -0
- package/src/TabGroup/TabContent.torp +4 -4
- package/src/TabGroup/TabGroup.torp +64 -62
- package/src/TabGroup/TabGroupTypes.ts +1 -0
- package/src/TabGroup/TabHeader.torp +10 -8
- package/src/TabGroup/TabList.torp +4 -3
- package/src/TabGroup/TabTrigger.torp +6 -6
- package/src/mount/disableScroll.ts +28 -0
- package/src/mount/hoverTrigger.ts +59 -0
- package/src/mount/trapFocus.ts +58 -0
- package/src/utils/documentEvents.ts +17 -0
- package/src/utils/getScrollParent.ts +22 -0
- package/src/utils/setContextPosition.ts +31 -0
- package/src/utils/setPopoverPosition.ts +138 -0
- package/test/Accordion/accessibility.test.ts +0 -3
- package/test/Accordion/for-items.test.ts +2 -4
- package/test/Accordion/keyboard.test.ts +0 -3
- package/test/Accordion/multiple-item-toggle.test.ts +3 -5
- package/test/Accordion/single-item-toggle.test.ts +3 -5
- package/test/Dialog/accessibility-alert.test.ts +40 -0
- package/test/Dialog/accessibility-modal.test.ts +52 -0
- package/test/Dialog/components/CustomDialog.torp +20 -0
- package/test/Dialog/components/DialogAccessibility.torp +31 -0
- package/test/Dialog/components/DialogFunction.torp +22 -0
- package/test/Dialog/components/DialogVariable.torp +35 -0
- package/test/Dialog/function.test.ts +26 -0
- package/test/Dialog/variable.test.ts +27 -0
- package/test/NavMenu/accessibility.test.ts +97 -0
- package/test/NavMenu/basic.test.ts +22 -0
- package/test/NavMenu/components/NavMenu.torp +28 -0
- package/test/NavMenu/components/NavMenuAccessibility.torp +35 -0
- package/test/TabGroup/for-items.test.ts +2 -4
- package/test/TabGroup/item-trigger.test.ts +10 -11
- package/tsup.config.ts +9 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Popover/index.ts","../../src/Popover/showPopover.ts","../../src/Popover/mountClickPopover.ts","../../src/Popover/mountContextPopover.ts","../../src/mount/hoverTrigger.ts","../../src/Popover/mountHoverPopover.ts","../../src/Popover/showPopoverPrompt.ts"],"sourcesContent":["import Popover from \"./Popover.torp\";\nimport PopoverContent from \"./PopoverContent.torp\";\nimport PopoverContentAnchored from \"./PopoverContentAnchored.torp\";\nimport PopoverContentContextual from \"./PopoverContentContextual.torp\";\nimport PopoverOverlay from \"./PopoverOverlay.torp\";\nimport PopoverTrigger from \"./PopoverTrigger.torp\";\nimport PopoverTriggerContextual from \"./PopoverTriggerContextual.torp\";\nimport PopoverTriggerHover from \"./PopoverTriggerHover.torp\";\nimport clickPopover from \"./mountClickPopover\";\nimport contextPopover from \"./mountContextPopover\";\nimport hoverPopover from \"./mountHoverPopover\";\nimport showPopover from \"./showPopover\";\nimport showPopoverPrompt from \"./showPopoverPrompt\";\n\nexport {\n\tPopover,\n\tPopoverOverlay,\n\tPopoverTrigger,\n\tPopoverTriggerHover,\n\tPopoverTriggerContextual,\n\tPopoverContentAnchored,\n\tPopoverContentContextual,\n\tPopoverContent,\n\tshowPopover,\n\tshowPopoverPrompt,\n\tclickPopover,\n\tcontextPopover,\n\thoverPopover,\n};\n","// TODO: Allow passing in a variable -- so that you can show an inline popover\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code.\n * @param popover The popover component\n * @param anchor The element to use as an anchor for the popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopover(\n\tpopover: Component,\n\tanchor: HTMLElement,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Add the anchor element to the properties\n\tconst allProps = Object.assign({}, props, { anchor });\n\n\t// Create the popover\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tpopover(target || anchor.parentElement || document.body, null, allProps);\n}\n","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ClickPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when an element is clicked.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function clickPopover(node: HTMLElement, options: ClickPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a click event handler to the node\n\tnode.addEventListener(\"click\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"click\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ContextPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when the user opens an element's context menu.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function contextPopover(node: HTMLElement, options: ContextPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a contextmenu event handler to the node\n\tnode.addEventListener(\"contextmenu\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"contextmenu\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","interface HoverTriggerOptions {\n\tonHover: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\tonExit?: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\nexport default function hoverTrigger(node: HTMLElement, options: HoverTriggerOptions): () => void {\n\tconst { onHover, onExit } = options;\n\tconst hoverDelay = options.hoverDelay || 1000;\n\tconst touchDelay = options.touchDelay || 1000;\n\n\tlet interval: NodeJS.Timeout | undefined;\n\n\t// Add click event handlers to the node\n\tnode.addEventListener(\"mouseenter\", handleMouseEnter);\n\tnode.addEventListener(\"mouseleave\", handleMouseLeave);\n\tnode.addEventListener(\"mousemove\", handleMouseMove);\n\tnode.addEventListener(\"touchstart\", handleMouseEnter);\n\tnode.addEventListener(\"touchend\", handleMouseLeave);\n\n\tfunction handleMouseEnter(e: MouseEvent | TouchEvent) {\n\t\t// Handle the hover after a delay\n\t\te.preventDefault();\n\t\tif (!interval) {\n\t\t\tconst delay = e.type.startsWith(\"mouse\") ? hoverDelay : touchDelay;\n\t\t\tinterval = setTimeout(() => onHover(node, e), delay);\n\t\t}\n\t}\n\n\tfunction handleMouseLeave(e: MouseEvent | TouchEvent) {\n\t\t// Prevent short hovers or touches from firing the event\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = undefined;\n\t\t}\n\n\t\tif (onExit) {\n\t\t\tonExit(node, e);\n\t\t}\n\t}\n\n\tfunction handleMouseMove(e: MouseEvent) {\n\t\t// Reset the interval on mouse move\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = setTimeout(() => onHover(node, e), hoverDelay);\n\t\t}\n\t}\n\n\t// Remove the event listeners from the node on destroy\n\treturn () => {\n\t\tnode.removeEventListener(\"mouseenter\", handleMouseEnter);\n\t\tnode.removeEventListener(\"mouseleave\", handleMouseLeave);\n\t\tnode.removeEventListener(\"mousemove\", handleMouseMove);\n\t\tnode.removeEventListener(\"touchstart\", handleMouseEnter);\n\t\tnode.removeEventListener(\"touchend\", handleMouseLeave);\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport hoverTrigger from \"../mount/hoverTrigger\";\nimport showPopover from \"./showPopover\";\n\ninterface HoverPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\n/**\n * A mount directive for showing a popover when an element is hovered.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component, any props and delays for hover and touch\n */\nexport default function hoverPopover(node: HTMLElement, options: HoverPopoverOptions): () => void {\n\tconst { popover, props, hoverDelay, touchDelay } = options;\n\n\tlet div: HTMLDivElement | undefined;\n\n\tfunction onHover(node: HTMLElement, e: MouseEvent | TouchEvent) {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\t// Get the position relative to the element, so we can reposition on scroll\n\t\tconst rect = node.getBoundingClientRect();\n\t\tlet position: { x: number; y: number };\n\t\tif (e.type.startsWith(\"mouse\")) {\n\t\t\tconst me = e as MouseEvent;\n\t\t\tposition = { x: me.clientX - rect.left, y: me.clientY - rect.top };\n\t\t} else {\n\t\t\tconst te = e as TouchEvent;\n\t\t\tposition = {\n\t\t\t\tx: te.touches[0].clientX - rect.left,\n\t\t\t\ty: te.touches[0].clientY - rect.top,\n\t\t\t};\n\t\t}\n\t\tconst allProps = Object.assign({}, props, { anchor: node, position });\n\n\t\tshowPopover(popover, node, allProps, div);\n\t}\n\n\tfunction onExit() {\n\t\t// Remove the div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t\tdiv = undefined;\n\t\t}\n\t}\n\n\treturn hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code, and asynchronously returns the value selected by the user.\n * @param popover The popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopoverPrompt(\n\tpopover: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the callback\n\t\tconst allProps = Object.assign({}, props, { callback: resolve });\n\n\t\t// Create the popover\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tpopover(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;;;;;;;;;;;;;;;;;;;;;;;;;;ACWe,SAAR,YACN,SACA,QACA,OACA,QACO;AAEP,QAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC;AAIpD,UAAQ,UAAU,OAAO,iBAAiB,SAAS,MAAM,MAAM,QAAQ;AACxE;;;ACVe,SAAR,aAA8B,MAAmB,SAA8B;AACrF,QAAM,EAAE,SAAS,MAAM,IAAI;AAG3B,OAAK,iBAAiB,SAAS,WAAW;AAE1C,WAAS,YAAY,GAAe;AACnC,MAAE,eAAe;AACjB,SAAK;AAAA,EACN;AAEA,MAAI;AAEJ,WAAS,OAAO;AAEf,QAAI,KAAK;AACR,eAAS,KAAK,YAAY,GAAG;AAAA,IAC9B;AACA,UAAM,SAAS,cAAc,KAAK;AAClC,aAAS,KAAK,YAAY,GAAG;AAE7B,gBAAY,SAAS,MAAM,OAAO,GAAG;AAAA,EACtC;AAEA,SAAO;AAAA,IACN,UAAgB;AAEf,WAAK,oBAAoB,SAAS,WAAW;AAI7C,UAAI,KAAK;AACR,iBAAS,KAAK,YAAY,GAAG;AAAA,MAC9B;AAAA,IACD;AAAA,EACD;AACD;;;ACpCe,SAAR,eAAgC,MAAmB,SAAgC;AACzF,QAAM,EAAE,SAA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AO,IAAI,QAAQ,CAAC,YAAY;AAE/B,UAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,UAAU,QAAQ,CAAC;AAI/D,YAAQ,UAAU,SAAS,MAAM,MAAM,QAAQ;AAAA,EAChD,CAAC;AACF;","names":["node"]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// src/Popover/Popover.torp
|
|
2
|
+
import Popover_default from "./Popover.torp";
|
|
3
|
+
|
|
4
|
+
// src/Popover/PopoverContent.torp
|
|
5
|
+
import PopoverContent_default from "./PopoverContent.torp";
|
|
6
|
+
|
|
7
|
+
// src/Popover/PopoverContentAnchored.torp
|
|
8
|
+
import PopoverContentAnchored_default from "./PopoverContentAnchored.torp";
|
|
9
|
+
|
|
10
|
+
// src/Popover/PopoverContentContextual.torp
|
|
11
|
+
import PopoverContentContextual_default from "./PopoverContentContextual.torp";
|
|
12
|
+
|
|
13
|
+
// src/Popover/PopoverOverlay.torp
|
|
14
|
+
import PopoverOverlay_default from "./PopoverOverlay.torp";
|
|
15
|
+
|
|
16
|
+
// src/Popover/PopoverTrigger.torp
|
|
17
|
+
import PopoverTrigger_default from "./PopoverTrigger.torp";
|
|
18
|
+
|
|
19
|
+
// src/Popover/PopoverTriggerContextual.torp
|
|
20
|
+
import PopoverTriggerContextual_default from "./PopoverTriggerContextual.torp";
|
|
21
|
+
|
|
22
|
+
// src/Popover/PopoverTriggerHover.torp
|
|
23
|
+
import PopoverTriggerHover_default from "./PopoverTriggerHover.torp";
|
|
24
|
+
|
|
25
|
+
// src/Popover/showPopover.ts
|
|
26
|
+
function showPopover(popover, anchor, props, target) {
|
|
27
|
+
const allProps = Object.assign({}, props, { anchor });
|
|
28
|
+
popover(target || anchor.parentElement || document.body, null, allProps);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/Popover/mountClickPopover.ts
|
|
32
|
+
function clickPopover(node, options) {
|
|
33
|
+
const { popover, props } = options;
|
|
34
|
+
node.addEventListener("click", handleClick);
|
|
35
|
+
function handleClick(e) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
show();
|
|
38
|
+
}
|
|
39
|
+
let div;
|
|
40
|
+
function show() {
|
|
41
|
+
if (div) {
|
|
42
|
+
document.body.removeChild(div);
|
|
43
|
+
}
|
|
44
|
+
div = document.createElement("div");
|
|
45
|
+
document.body.appendChild(div);
|
|
46
|
+
showPopover(popover, node, props, div);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
destroy() {
|
|
50
|
+
node.removeEventListener("click", handleClick);
|
|
51
|
+
if (div) {
|
|
52
|
+
document.body.removeChild(div);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/Popover/mountContextPopover.ts
|
|
59
|
+
function contextPopover(node, options) {
|
|
60
|
+
const { popover, props } = options;
|
|
61
|
+
node.addEventListener("contextmenu", handleClick);
|
|
62
|
+
function handleClick(e) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
show();
|
|
65
|
+
}
|
|
66
|
+
let div;
|
|
67
|
+
function show() {
|
|
68
|
+
if (div) {
|
|
69
|
+
document.body.removeChild(div);
|
|
70
|
+
}
|
|
71
|
+
div = document.createElement("div");
|
|
72
|
+
document.body.appendChild(div);
|
|
73
|
+
showPopover(popover, node, props, div);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
destroy() {
|
|
77
|
+
node.removeEventListener("contextmenu", handleClick);
|
|
78
|
+
if (div) {
|
|
79
|
+
document.body.removeChild(div);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/mount/hoverTrigger.ts
|
|
86
|
+
function hoverTrigger(node, options) {
|
|
87
|
+
const { onHover, onExit } = options;
|
|
88
|
+
const hoverDelay = options.hoverDelay || 1e3;
|
|
89
|
+
const touchDelay = options.touchDelay || 1e3;
|
|
90
|
+
let interval;
|
|
91
|
+
node.addEventListener("mouseenter", handleMouseEnter);
|
|
92
|
+
node.addEventListener("mouseleave", handleMouseLeave);
|
|
93
|
+
node.addEventListener("mousemove", handleMouseMove);
|
|
94
|
+
node.addEventListener("touchstart", handleMouseEnter);
|
|
95
|
+
node.addEventListener("touchend", handleMouseLeave);
|
|
96
|
+
function handleMouseEnter(e) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
if (!interval) {
|
|
99
|
+
const delay = e.type.startsWith("mouse") ? hoverDelay : touchDelay;
|
|
100
|
+
interval = setTimeout(() => onHover(node, e), delay);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function handleMouseLeave(e) {
|
|
104
|
+
if (interval) {
|
|
105
|
+
clearTimeout(interval);
|
|
106
|
+
interval = void 0;
|
|
107
|
+
}
|
|
108
|
+
if (onExit) {
|
|
109
|
+
onExit(node, e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function handleMouseMove(e) {
|
|
113
|
+
if (interval) {
|
|
114
|
+
clearTimeout(interval);
|
|
115
|
+
interval = setTimeout(() => onHover(node, e), hoverDelay);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return () => {
|
|
119
|
+
node.removeEventListener("mouseenter", handleMouseEnter);
|
|
120
|
+
node.removeEventListener("mouseleave", handleMouseLeave);
|
|
121
|
+
node.removeEventListener("mousemove", handleMouseMove);
|
|
122
|
+
node.removeEventListener("touchstart", handleMouseEnter);
|
|
123
|
+
node.removeEventListener("touchend", handleMouseLeave);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/Popover/mountHoverPopover.ts
|
|
128
|
+
function hoverPopover(node, options) {
|
|
129
|
+
const { popover, props, hoverDelay, touchDelay } = options;
|
|
130
|
+
let div;
|
|
131
|
+
function onHover(node2, e) {
|
|
132
|
+
if (div) {
|
|
133
|
+
document.body.removeChild(div);
|
|
134
|
+
}
|
|
135
|
+
div = document.createElement("div");
|
|
136
|
+
document.body.appendChild(div);
|
|
137
|
+
const rect = node2.getBoundingClientRect();
|
|
138
|
+
let position;
|
|
139
|
+
if (e.type.startsWith("mouse")) {
|
|
140
|
+
const me = e;
|
|
141
|
+
position = { x: me.clientX - rect.left, y: me.clientY - rect.top };
|
|
142
|
+
} else {
|
|
143
|
+
const te = e;
|
|
144
|
+
position = {
|
|
145
|
+
x: te.touches[0].clientX - rect.left,
|
|
146
|
+
y: te.touches[0].clientY - rect.top
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const allProps = Object.assign({}, props, { anchor: node2, position });
|
|
150
|
+
showPopover(popover, node2, allProps, div);
|
|
151
|
+
}
|
|
152
|
+
function onExit() {
|
|
153
|
+
if (div) {
|
|
154
|
+
document.body.removeChild(div);
|
|
155
|
+
div = void 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/Popover/showPopoverPrompt.ts
|
|
162
|
+
function showPopoverPrompt(popover, props, target) {
|
|
163
|
+
return new Promise((resolve) => {
|
|
164
|
+
const allProps = Object.assign({}, props, { callback: resolve });
|
|
165
|
+
popover(target || document.body, null, allProps);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
Popover_default as Popover,
|
|
170
|
+
PopoverContent_default as PopoverContent,
|
|
171
|
+
PopoverContentAnchored_default as PopoverContentAnchored,
|
|
172
|
+
PopoverContentContextual_default as PopoverContentContextual,
|
|
173
|
+
PopoverOverlay_default as PopoverOverlay,
|
|
174
|
+
PopoverTrigger_default as PopoverTrigger,
|
|
175
|
+
PopoverTriggerContextual_default as PopoverTriggerContextual,
|
|
176
|
+
PopoverTriggerHover_default as PopoverTriggerHover,
|
|
177
|
+
clickPopover,
|
|
178
|
+
contextPopover,
|
|
179
|
+
hoverPopover,
|
|
180
|
+
showPopover,
|
|
181
|
+
showPopoverPrompt
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Popover/showPopover.ts","../../src/Popover/mountClickPopover.ts","../../src/Popover/mountContextPopover.ts","../../src/mount/hoverTrigger.ts","../../src/Popover/mountHoverPopover.ts","../../src/Popover/showPopoverPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline popover\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code.\n * @param popover The popover component\n * @param anchor The element to use as an anchor for the popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopover(\n\tpopover: Component,\n\tanchor: HTMLElement,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Add the anchor element to the properties\n\tconst allProps = Object.assign({}, props, { anchor });\n\n\t// Create the popover\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tpopover(target || anchor.parentElement || document.body, null, allProps);\n}\n","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ClickPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when an element is clicked.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function clickPopover(node: HTMLElement, options: ClickPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a click event handler to the node\n\tnode.addEventListener(\"click\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"click\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport showPopover from \"./showPopover\";\n\ninterface ContextPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n}\n\n/**\n * A mount directive for showing a popover when the user opens an element's context menu.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component and any props\n */\nexport default function contextPopover(node: HTMLElement, options: ContextPopoverOptions) {\n\tconst { popover, props } = options;\n\n\t// Add a contextmenu event handler to the node\n\tnode.addEventListener(\"contextmenu\", handleClick);\n\n\tfunction handleClick(e: MouseEvent) {\n\t\te.preventDefault();\n\t\tshow();\n\t}\n\n\tlet div: HTMLDivElement;\n\n\tfunction show() {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\tshowPopover(popover, node, props, div);\n\t}\n\n\treturn {\n\t\tdestroy(): void {\n\t\t\t// Remove the event listener from the node on destroy\n\t\t\tnode.removeEventListener(\"contextmenu\", handleClick);\n\n\t\t\t// Remove the div we added\n\t\t\t// TODO: Should we do this in more places?\n\t\t\tif (div) {\n\t\t\t\tdocument.body.removeChild(div);\n\t\t\t}\n\t\t},\n\t};\n}\n","interface HoverTriggerOptions {\n\tonHover: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\tonExit?: (node: HTMLElement, e: TouchEvent | MouseEvent) => void;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\nexport default function hoverTrigger(node: HTMLElement, options: HoverTriggerOptions): () => void {\n\tconst { onHover, onExit } = options;\n\tconst hoverDelay = options.hoverDelay || 1000;\n\tconst touchDelay = options.touchDelay || 1000;\n\n\tlet interval: NodeJS.Timeout | undefined;\n\n\t// Add click event handlers to the node\n\tnode.addEventListener(\"mouseenter\", handleMouseEnter);\n\tnode.addEventListener(\"mouseleave\", handleMouseLeave);\n\tnode.addEventListener(\"mousemove\", handleMouseMove);\n\tnode.addEventListener(\"touchstart\", handleMouseEnter);\n\tnode.addEventListener(\"touchend\", handleMouseLeave);\n\n\tfunction handleMouseEnter(e: MouseEvent | TouchEvent) {\n\t\t// Handle the hover after a delay\n\t\te.preventDefault();\n\t\tif (!interval) {\n\t\t\tconst delay = e.type.startsWith(\"mouse\") ? hoverDelay : touchDelay;\n\t\t\tinterval = setTimeout(() => onHover(node, e), delay);\n\t\t}\n\t}\n\n\tfunction handleMouseLeave(e: MouseEvent | TouchEvent) {\n\t\t// Prevent short hovers or touches from firing the event\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = undefined;\n\t\t}\n\n\t\tif (onExit) {\n\t\t\tonExit(node, e);\n\t\t}\n\t}\n\n\tfunction handleMouseMove(e: MouseEvent) {\n\t\t// Reset the interval on mouse move\n\t\tif (interval) {\n\t\t\tclearTimeout(interval);\n\t\t\tinterval = setTimeout(() => onHover(node, e), hoverDelay);\n\t\t}\n\t}\n\n\t// Remove the event listeners from the node on destroy\n\treturn () => {\n\t\tnode.removeEventListener(\"mouseenter\", handleMouseEnter);\n\t\tnode.removeEventListener(\"mouseleave\", handleMouseLeave);\n\t\tnode.removeEventListener(\"mousemove\", handleMouseMove);\n\t\tnode.removeEventListener(\"touchstart\", handleMouseEnter);\n\t\tnode.removeEventListener(\"touchend\", handleMouseLeave);\n\t};\n}\n","import type { Component } from \"@torpor/view\";\nimport hoverTrigger from \"../mount/hoverTrigger\";\nimport showPopover from \"./showPopover\";\n\ninterface HoverPopoverOptions {\n\tpopover: Component;\n\tprops?: Record<PropertyKey, any>;\n\thoverDelay?: number;\n\ttouchDelay?: number;\n}\n\n/**\n * A mount directive for showing a popover when an element is hovered.\n * @param node The element to show the popover for\n * @param options Options for showing the popover, consisting of the popover component, any props and delays for hover and touch\n */\nexport default function hoverPopover(node: HTMLElement, options: HoverPopoverOptions): () => void {\n\tconst { popover, props, hoverDelay, touchDelay } = options;\n\n\tlet div: HTMLDivElement | undefined;\n\n\tfunction onHover(node: HTMLElement, e: MouseEvent | TouchEvent) {\n\t\t// Show the popover in a div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t}\n\t\tdiv = document.createElement(\"div\");\n\t\tdocument.body.appendChild(div);\n\n\t\t// Get the position relative to the element, so we can reposition on scroll\n\t\tconst rect = node.getBoundingClientRect();\n\t\tlet position: { x: number; y: number };\n\t\tif (e.type.startsWith(\"mouse\")) {\n\t\t\tconst me = e as MouseEvent;\n\t\t\tposition = { x: me.clientX - rect.left, y: me.clientY - rect.top };\n\t\t} else {\n\t\t\tconst te = e as TouchEvent;\n\t\t\tposition = {\n\t\t\t\tx: te.touches[0].clientX - rect.left,\n\t\t\t\ty: te.touches[0].clientY - rect.top,\n\t\t\t};\n\t\t}\n\t\tconst allProps = Object.assign({}, props, { anchor: node, position });\n\n\t\tshowPopover(popover, node, allProps, div);\n\t}\n\n\tfunction onExit() {\n\t\t// Remove the div\n\t\tif (div) {\n\t\t\tdocument.body.removeChild(div);\n\t\t\tdiv = undefined;\n\t\t}\n\t}\n\n\treturn hoverTrigger(node, { onHover, onExit, hoverDelay, touchDelay });\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a popover component in code, and asynchronously returns the value selected by the user.\n * @param popover The popover component\n * @param props The properties for the popover component\n * @param target The target element to show the popover in\n * @returns The value selected by the user\n */\nexport default function showPopoverPrompt(\n\tpopover: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the callback\n\t\tconst allProps = Object.assign({}, props, { callback: resolve });\n\n\t\t// Create the popover\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tpopover(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;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AA,IAC9B;AACA,UAAM,SAAS,cAAc,KAAK;AAClC,aAAS,KAAK,YAAY,GAAG;AAG7B,UAAM,OAAOA,MAAK,sBAAsB;AACxC,QAAI;AACJ,QAAI,EAAE,KAAK,WAAW,OAAO,GAAG;AAC/B,YAAM,KAAK;AACX,iBAAW,EAAE,GAAG,GAAG,UAAU,KAAK,MAAM,GAAG,GAAG,UAAU,KAAK,IAAI;AAAA,IAClE,OAAO;AACN,YAAM,KAAK;AACX,iBAAW;AAAA,QACV,GAAG,GAAG,QAAQ,CAAC,EAAE,UAAU,KAAK;AAAA,QAChC,GAAG,GAAG,QAAQ,CAAC,EAAE,UAAU,KAAK;AAAA,MACjC;AAAA,IACD;AACA,UAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,QAAQA,OAAM,SAAS,CAAC;AAEpE,gBAAY,SAASA,OAAM,UAAU,GAAG;AAAA,EACzC;AAEA,WAAS,SAAS;AAEjB,QAAI,KAAK;AACR,eAAS,KAAK,YAAY,GAAG;AAC7B,YAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO,aAAa,MAAM,EAAE,SAAS,QAAQ,YAAY,WAAW,CAAC;AACtE;;;AC/Ce,SAAR,kBACN,SACA,OACA,QACgB;AAChB,SAAO,IAAI,QAAQ,CAAC,YAAY;AAE/B,UAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,UAAU,QAAQ,CAAC;AAI/D,YAAQ,UAAU,SAAS,MAAM,MAAM,QAAQ;AAAA,EAChD,CAAC;AACF;","names":["node"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Component } from "@torpor/view";
|
|
2
|
+
import showPopover from "./showPopover";
|
|
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
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Component } from "@torpor/view";
|
|
2
|
+
import showPopover from "./showPopover";
|
|
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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Component } from "@torpor/view";
|
|
2
|
+
import hoverTrigger from "../mount/hoverTrigger";
|
|
3
|
+
import showPopover from "./showPopover";
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// TODO: Allow passing in a variable -- so that you can show an inline popover
|
|
2
|
+
import type { Component } from "@torpor/view";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shows a popover component in code.
|
|
6
|
+
* @param popover The popover component
|
|
7
|
+
* @param anchor The element to use as an anchor for the popover component
|
|
8
|
+
* @param props The properties for the popover component
|
|
9
|
+
* @param target The target element to show the popover in
|
|
10
|
+
* @returns The value selected by the user
|
|
11
|
+
*/
|
|
12
|
+
export default function showPopover(
|
|
13
|
+
popover: Component,
|
|
14
|
+
anchor: HTMLElement,
|
|
15
|
+
props?: Record<PropertyKey, any>,
|
|
16
|
+
target?: Element,
|
|
17
|
+
): void {
|
|
18
|
+
// Add the anchor element to the properties
|
|
19
|
+
const allProps = Object.assign({}, props, { anchor });
|
|
20
|
+
|
|
21
|
+
// Create the popover
|
|
22
|
+
// TODO: This needs to clean up after itself, like the mount methods do
|
|
23
|
+
popover(target || anchor.parentElement || document.body, null, allProps);
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Component } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shows a popover component in code, and asynchronously returns the value selected by the user.
|
|
5
|
+
* @param popover The popover component
|
|
6
|
+
* @param props The properties for the popover component
|
|
7
|
+
* @param target The target element to show the popover in
|
|
8
|
+
* @returns The value selected by the user
|
|
9
|
+
*/
|
|
10
|
+
export default function showPopoverPrompt(
|
|
11
|
+
popover: Component,
|
|
12
|
+
props?: Record<PropertyKey, any>,
|
|
13
|
+
target?: Element,
|
|
14
|
+
): Promise<void> {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
// Add the promise as the callback
|
|
17
|
+
const allProps = Object.assign({}, props, { callback: resolve });
|
|
18
|
+
|
|
19
|
+
// Create the popover
|
|
20
|
+
// TODO: This needs to clean up after itself, like the use methods do
|
|
21
|
+
popover(target || document.body, null, allProps);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import getId from
|
|
2
|
-
import { TabGroupContextName, type TabGroupContext } from
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { TabGroupContextName, type TabGroupContext } from "./TabGroupTypes";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Content for a TabGroup, which can be revealed or hidden by an associated TabTrigger.
|
|
@@ -11,7 +11,7 @@ export default function TabContent($props: any) {
|
|
|
11
11
|
|
|
12
12
|
const context = $context[TabGroupContextName] as TabGroupContext;
|
|
13
13
|
if (!context) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error("TabContent must be contained within a TabGroup");
|
|
15
15
|
}
|
|
16
16
|
let $state = $context[TabGroupContextName].registerItem($props.index, $props.value);
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ export default function TabContent($props: any) {
|
|
|
21
21
|
@render {
|
|
22
22
|
<div
|
|
23
23
|
id={$props.id}
|
|
24
|
-
class=
|
|
24
|
+
class={`torp-tab-content ${$props.class ?? ""}`.trim()}
|
|
25
25
|
role="tabpanel"
|
|
26
26
|
aria-labelledby={$state.headerId}
|
|
27
27
|
data-orientation={$props.orientation}
|