@torpor/ui 0.4.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -7
- package/dist/Accordion/Accordion.torp +42 -165
- package/dist/Accordion/AccordionContent.torp +6 -6
- package/dist/Accordion/AccordionHeader.torp +7 -11
- package/dist/Accordion/AccordionItem.torp +24 -24
- package/dist/Accordion/AccordionTrigger.torp +17 -8
- package/dist/Accordion/AccordionTypes.ts +1 -1
- package/dist/Accordion/index.d.ts +23 -25
- package/dist/Accordion/index.js +6 -22
- package/dist/Breadcrumb/Breadcrumb.torp +12 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +6 -6
- package/dist/Breadcrumb/BreadcrumbList.torp +21 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +4 -4
- package/dist/Breadcrumb/index.d.ts +39 -15
- package/dist/Breadcrumb/index.js +5 -14
- package/dist/Calendar/Calendar.torp +163 -156
- package/dist/Calendar/CalendarDay.torp +91 -45
- package/dist/Calendar/CalendarDayHeader.torp +36 -0
- package/dist/Calendar/CalendarGrid.torp +104 -0
- package/dist/Calendar/CalendarGridHeader.torp +43 -0
- package/dist/Calendar/CalendarHeader.torp +48 -0
- package/dist/Calendar/CalendarHeaderTrigger.torp +54 -0
- package/dist/Calendar/CalendarTypes.ts +24 -3
- package/dist/Calendar/buildDays.ts +54 -0
- package/dist/Calendar/index.d.ts +191 -5
- package/dist/Calendar/index.js +8 -10
- package/dist/Carousel/Carousel.torp +180 -0
- package/dist/Carousel/CarouselIndicators.torp +65 -0
- package/dist/Carousel/CarouselNext.torp +43 -0
- package/dist/Carousel/CarouselPrevious.torp +44 -0
- package/dist/Carousel/CarouselSlide.torp +57 -0
- package/dist/Carousel/CarouselTypes.ts +28 -0
- package/dist/Carousel/index.d.ts +147 -0
- package/dist/Carousel/index.js +6 -0
- package/dist/Charts/BarChart.torp +55 -144
- package/dist/Charts/Chart.torp +120 -0
- package/dist/Charts/ChartBars.torp +78 -0
- package/dist/Charts/ChartColumns.torp +66 -0
- package/dist/Charts/ChartGrid.torp +54 -0
- package/dist/Charts/ChartLines.torp +60 -0
- package/dist/Charts/ChartTypes.ts +25 -0
- package/dist/Charts/ChartXAxis.torp +85 -0
- package/dist/Charts/ChartYAxis.torp +107 -0
- package/dist/Charts/ColumnChart.torp +70 -0
- package/dist/Charts/GridLines.torp +4 -4
- package/dist/Charts/LineChart.torp +55 -178
- package/dist/Charts/PieChart.torp +14 -20
- package/dist/Charts/ScatterChart.torp +45 -38
- package/dist/Charts/SparkLine.torp +16 -19
- package/dist/Charts/XAxis.torp +14 -11
- package/dist/Charts/YAxis.torp +10 -8
- package/dist/Charts/index.d.ts +328 -79
- package/dist/Charts/index.js +17 -34
- package/dist/ColorPicker/ColorPalette.torp +154 -0
- package/dist/ColorPicker/ColorPicker.torp +157 -0
- package/dist/ColorPicker/index.d.ts +85 -0
- package/dist/ColorPicker/index.js +3 -0
- package/dist/ComboBox/ComboBox.torp +205 -0
- package/dist/ComboBox/ComboBoxContent.torp +120 -0
- package/dist/ComboBox/ComboBoxInput.torp +161 -0
- package/dist/ComboBox/ComboBoxTrigger.torp +49 -0
- package/dist/ComboBox/ComboBoxTypes.ts +39 -0
- package/dist/ComboBox/index.d.ts +154 -0
- package/dist/ComboBox/index.js +6 -0
- package/dist/CommandPalette/CommandPalette.torp +223 -0
- package/dist/CommandPalette/CommandTypes.ts +14 -0
- package/dist/CommandPalette/index.d.ts +45 -0
- package/dist/CommandPalette/index.js +2 -0
- package/dist/Contextual/Contextual.torp +32 -50
- package/dist/Contextual/ContextualContent.torp +29 -73
- package/dist/Contextual/ContextualHover.torp +112 -0
- package/dist/Contextual/ContextualTrigger.torp +31 -42
- package/dist/Contextual/ContextualTypes.ts +4 -17
- package/dist/Contextual/index.d.ts +44 -27
- package/dist/Contextual/index.js +5 -14
- package/dist/DataGrid/DataGrid.torp +496 -0
- package/dist/DataGrid/DataGridTypes.ts +25 -0
- package/dist/DataGrid/index.d.ts +90 -0
- package/dist/DataGrid/index.js +3 -0
- package/dist/DataGrid/sortRows.ts +32 -0
- package/dist/DatePicker/DatePicker.torp +222 -0
- package/dist/DatePicker/DatePickerHeader.torp +20 -0
- package/dist/DatePicker/index.d.ts +55 -0
- package/dist/DatePicker/index.js +2 -0
- package/dist/DateRangePicker/DateRangePicker.torp +315 -0
- package/dist/DateRangePicker/DateRangePickerDay.torp +137 -0
- package/dist/DateRangePicker/DateRangePickerTypes.ts +21 -0
- package/dist/DateRangePicker/index.d.ts +76 -0
- package/dist/DateRangePicker/index.js +3 -0
- package/dist/Dialog/Dialog.torp +24 -17
- package/dist/Dialog/DialogBody.torp +5 -9
- package/dist/Dialog/DialogButton.torp +12 -12
- package/dist/Dialog/DialogFooter.torp +3 -7
- package/dist/Dialog/DialogHeader.torp +6 -10
- package/dist/Dialog/index.d.ts +27 -27
- package/dist/Dialog/index.js +6 -22
- package/dist/Disclosure/Disclosure.torp +18 -18
- package/dist/Disclosure/DisclosureContent.torp +5 -6
- package/dist/Disclosure/DisclosureHeader.torp +7 -11
- package/dist/Disclosure/DisclosureTrigger.torp +4 -5
- package/dist/Disclosure/index.d.ts +14 -16
- package/dist/Disclosure/index.js +5 -18
- package/dist/Drawer/Drawer.torp +19 -49
- package/dist/Drawer/DrawerContent.torp +70 -13
- package/dist/Drawer/DrawerOverlay.torp +4 -4
- package/dist/Drawer/DrawerTrigger.torp +16 -4
- package/dist/Drawer/DrawerTypes.ts +3 -0
- package/dist/Drawer/index.d.ts +16 -20
- package/dist/Drawer/index.js +5 -18
- package/dist/FocusGroup/FocusGroup.torp +70 -0
- package/dist/FocusGroup/FocusGroupButton.torp +59 -0
- package/dist/FocusGroup/FocusGroupTypes.ts +14 -0
- package/dist/FocusGroup/index.d.ts +44 -0
- package/dist/FocusGroup/index.js +3 -0
- package/dist/Form/CheckBox.torp +27 -18
- package/dist/Form/Field.torp +17 -17
- package/dist/Form/File.torp +31 -22
- package/dist/Form/FileDrop.torp +187 -0
- package/dist/Form/Form.torp +24 -22
- package/dist/Form/FormTypes.ts +2 -0
- package/dist/Form/FormValues.torp +37 -0
- package/dist/Form/Hidden.torp +4 -12
- package/dist/Form/Input.torp +38 -32
- package/dist/Form/Label.torp +3 -3
- package/dist/Form/Message.torp +13 -5
- package/dist/Form/MessageSummary.torp +5 -4
- package/dist/Form/Option.torp +11 -7
- package/dist/Form/Select.torp +32 -28
- package/dist/Form/TextArea.torp +35 -31
- package/dist/Form/Toggle.torp +109 -0
- package/dist/Form/index.d.ts +178 -79
- package/dist/Form/index.js +16 -50
- package/dist/ListBox/ListBox.torp +253 -150
- package/dist/ListBox/ListBoxItem.torp +54 -30
- package/dist/ListBox/ListBoxSeparator.torp +5 -2
- package/dist/ListBox/ListBoxTypes.ts +23 -5
- package/dist/ListBox/LoadedListBoxItems.torp +41 -0
- package/dist/ListBox/index.d.ts +56 -17
- package/dist/ListBox/index.js +4 -14
- package/dist/MaskedInput/MaskedInput.torp +143 -0
- package/dist/MaskedInput/index.d.ts +52 -0
- package/dist/MaskedInput/index.js +2 -0
- package/dist/Menu/Menu.torp +86 -71
- package/dist/Menu/MenuButton.torp +17 -10
- package/dist/Menu/MenuCheck.torp +22 -18
- package/dist/Menu/MenuGroup.torp +4 -4
- package/dist/Menu/MenuIndicator.torp +5 -13
- package/dist/Menu/MenuPopout.torp +20 -50
- package/dist/Menu/MenuPopoutContent.torp +15 -66
- package/dist/Menu/MenuPopoutTrigger.torp +19 -100
- package/dist/Menu/MenuRadio.torp +25 -26
- package/dist/Menu/MenuRadioGroup.torp +25 -68
- package/dist/Menu/MenuSeparator.torp +3 -2
- package/dist/Menu/MenuTypes.ts +9 -19
- package/dist/Menu/index.d.ts +45 -51
- package/dist/Menu/index.js +12 -46
- package/dist/MenuBar/MenuBar.torp +31 -83
- package/dist/MenuBar/MenuBarItem.torp +33 -51
- package/dist/MenuBar/MenuBarItemContent.torp +15 -101
- package/dist/MenuBar/MenuBarItemTrigger.torp +20 -55
- package/dist/MenuBar/MenuBarTypes.ts +11 -10
- package/dist/MenuBar/index.d.ts +17 -19
- package/dist/MenuBar/index.js +5 -18
- package/dist/Modal/Modal.torp +22 -47
- package/dist/Modal/ModalContent.torp +21 -44
- package/dist/Modal/ModalOverlay.torp +4 -4
- package/dist/Modal/ModalTrigger.torp +16 -32
- package/dist/Modal/ModalTypes.ts +5 -16
- package/dist/Modal/index.d.ts +17 -29
- package/dist/Modal/index.js +29 -28
- package/dist/Modal/index.js.map +1 -1
- package/dist/Modal/showPrompt.ts +2 -2
- package/dist/NavMenu/NavMenu.torp +22 -111
- package/dist/NavMenu/NavMenuButton.torp +7 -8
- package/dist/NavMenu/NavMenuElement.torp +6 -7
- package/dist/NavMenu/NavMenuGroup.torp +5 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -8
- package/dist/NavMenu/NavMenuLink.torp +7 -10
- package/dist/NavMenu/NavMenuPopout.torp +15 -60
- package/dist/NavMenu/NavMenuPopoutContent.torp +14 -73
- package/dist/NavMenu/NavMenuPopoutTrigger.torp +17 -99
- package/dist/NavMenu/NavMenuSeparator.torp +3 -7
- package/dist/NavMenu/NavMenuTypes.ts +4 -14
- package/dist/NavMenu/index.d.ts +40 -44
- package/dist/NavMenu/index.js +11 -42
- package/dist/Notification/Notification.torp +12 -24
- package/dist/Notification/NotificationClose.torp +6 -3
- package/dist/Notification/NotificationContainer.torp +3 -7
- package/dist/Notification/NotificationContent.torp +3 -7
- package/dist/Notification/NotificationTypes.ts +1 -1
- package/dist/Notification/index.d.ts +15 -12
- package/dist/Notification/index.js +22 -32
- package/dist/Notification/index.js.map +1 -1
- package/dist/NumberInput/NumberInput.torp +255 -0
- package/dist/NumberInput/index.d.ts +44 -0
- package/dist/NumberInput/index.js +2 -0
- package/dist/Pagination/Pagination.torp +41 -34
- package/dist/Pagination/PaginationItem.torp +50 -13
- package/dist/Pagination/PaginationTypes.ts +3 -6
- package/dist/Pagination/buildPages.ts +9 -5
- package/dist/Pagination/index.d.ts +19 -9
- package/dist/Pagination/index.js +3 -40
- package/dist/Popover/Popover.torp +32 -50
- package/dist/Popover/PopoverContent.torp +27 -76
- package/dist/Popover/PopoverHover.torp +90 -0
- package/dist/Popover/PopoverTrigger.torp +17 -40
- package/dist/Popover/PopoverTypes.ts +4 -17
- package/dist/Popover/index.d.ts +40 -25
- package/dist/Popover/index.js +18 -18
- package/dist/Popover/index.js.map +1 -1
- package/dist/Progress/Progress.torp +88 -0
- package/dist/Progress/index.d.ts +37 -0
- package/dist/Progress/index.js +2 -0
- package/dist/Rating/Rating.torp +225 -0
- package/dist/Rating/index.d.ts +44 -0
- package/dist/Rating/index.js +2 -0
- package/dist/SegmentedControl/SegmentedControl.torp +233 -0
- package/dist/SegmentedControl/SegmentedControlTypes.ts +26 -0
- package/dist/SegmentedControl/SegmentedItem.torp +78 -0
- package/dist/SegmentedControl/index.d.ts +74 -0
- package/dist/SegmentedControl/index.js +3 -0
- package/dist/SelectBox/SelectBox.torp +107 -53
- package/dist/SelectBox/SelectBoxContent.torp +49 -19
- package/dist/SelectBox/SelectBoxTrigger.torp +108 -8
- package/dist/SelectBox/SelectBoxTypes.ts +26 -11
- package/dist/SelectBox/index.d.ts +39 -54
- package/dist/SelectBox/index.js +5 -18
- package/dist/Slider/Slider.torp +245 -0
- package/dist/Slider/index.d.ts +45 -0
- package/dist/Slider/index.js +2 -0
- package/dist/Splitter/Splitter.torp +156 -0
- package/dist/Splitter/SplitterHandle.torp +161 -0
- package/dist/Splitter/SplitterPane.torp +63 -0
- package/dist/Splitter/SplitterTypes.ts +31 -0
- package/dist/Splitter/index.d.ts +103 -0
- package/dist/Splitter/index.js +4 -0
- package/dist/Stepper/Stepper.torp +146 -0
- package/dist/Stepper/StepperMarker.torp +24 -0
- package/dist/Stepper/StepperNext.torp +44 -0
- package/dist/Stepper/StepperPrevious.torp +44 -0
- package/dist/Stepper/StepperStep.torp +90 -0
- package/dist/Stepper/StepperTypes.ts +30 -0
- package/dist/Stepper/index.d.ts +149 -0
- package/dist/Stepper/index.js +6 -0
- package/dist/TabGroup/TabContent.torp +6 -6
- package/dist/TabGroup/TabGroup.torp +97 -113
- package/dist/TabGroup/TabGroupTypes.ts +1 -1
- package/dist/TabGroup/TabHeader.torp +23 -19
- package/dist/TabGroup/TabList.torp +8 -21
- package/dist/TabGroup/TabTrigger.torp +6 -7
- package/dist/TabGroup/index.d.ts +26 -26
- package/dist/TabGroup/index.js +6 -22
- package/dist/TagInput/TagInput.torp +378 -0
- package/dist/TagInput/index.d.ts +48 -0
- package/dist/TagInput/index.js +2 -0
- package/dist/TimePicker/TimePicker.torp +462 -0
- package/dist/TimePicker/index.d.ts +53 -0
- package/dist/TimePicker/index.js +2 -0
- package/dist/ToolBar/ToolBar.torp +29 -110
- package/dist/ToolBar/ToolBarButton.torp +7 -8
- package/dist/ToolBar/ToolBarElement.torp +7 -11
- package/dist/ToolBar/ToolBarPopout.torp +16 -68
- package/dist/ToolBar/ToolBarPopoutContent.torp +15 -73
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +19 -110
- package/dist/ToolBar/ToolBarSeparator.torp +3 -7
- package/dist/ToolBar/ToolBarTypes.ts +7 -14
- package/dist/ToolBar/index.d.ts +30 -32
- package/dist/ToolBar/index.js +8 -30
- package/dist/Tree/Tree.torp +395 -0
- package/dist/Tree/TreeItem.torp +176 -0
- package/dist/Tree/TreeItemChildren.torp +60 -0
- package/dist/Tree/TreeItemContent.torp +46 -0
- package/dist/Tree/TreeItemLabel.torp +94 -0
- package/dist/Tree/TreeItemTrigger.torp +78 -0
- package/dist/Tree/TreeLoadedChildren.torp +122 -0
- package/dist/Tree/TreeTypes.ts +63 -0
- package/dist/Tree/index.d.ts +262 -0
- package/dist/Tree/index.js +7 -0
- package/dist/icons/ChevronDoubleLeft.torp +19 -0
- package/dist/icons/ChevronDoubleRight.torp +19 -0
- package/dist/icons/index.d.ts +61 -1
- package/dist/icons/index.js +17 -58
- package/dist/loader-DEeG5vFY.js +44 -0
- package/dist/loader-DEeG5vFY.js.map +1 -0
- package/dist/motion/index.d.ts +12 -8
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +70 -88
- package/dist/motion/index.js.map +1 -1
- package/dist/mount/draggable.ts +63 -0
- package/dist/mount/dropTarget.ts +108 -0
- package/dist/mount/hoverTrigger.ts +1 -1
- package/dist/utils/$handle.ts +23 -0
- package/dist/utils/LoadedItems.torp +47 -0
- package/dist/utils/PopoutClickTrigger.torp +99 -0
- package/dist/utils/PopoutTypes.ts +59 -12
- package/dist/utils/SubmenuPopout.torp +89 -0
- package/dist/utils/SubmenuPopoutContent.torp +87 -0
- package/dist/utils/SubmenuPopoutTrigger.torp +160 -0
- package/dist/utils/chartColors.ts +13 -13
- package/dist/utils/chartLayout.ts +143 -0
- package/dist/utils/colorUtils.ts +103 -0
- package/dist/utils/createItemGroup.ts +152 -0
- package/dist/utils/dateUtils.ts +8 -7
- package/dist/utils/documentEvents.ts +4 -4
- package/dist/utils/dragState.ts +86 -0
- package/dist/utils/focusGroup.ts +204 -0
- package/dist/utils/focusItem.ts +44 -0
- package/dist/utils/formField.ts +70 -0
- package/dist/utils/hoverOpen.ts +50 -0
- package/dist/utils/hoverReveal.ts +194 -0
- package/dist/utils/loader.ts +113 -0
- package/dist/utils/maskUtils.ts +98 -0
- package/dist/utils/popoutContent.ts +137 -0
- package/dist/utils/reorderList.ts +52 -0
- package/package.json +97 -22
- package/dist/Accordion/index.js.map +0 -1
- package/dist/Breadcrumb/index.js.map +0 -1
- package/dist/Calendar/index.js.map +0 -1
- package/dist/Charts/index.js.map +0 -1
- package/dist/Contextual/index.js.map +0 -1
- package/dist/Dialog/index.js.map +0 -1
- package/dist/Disclosure/index.js.map +0 -1
- package/dist/Drawer/index.js.map +0 -1
- package/dist/Form/index.js.map +0 -1
- package/dist/ListBox/index.js.map +0 -1
- package/dist/Menu/index.js.map +0 -1
- package/dist/MenuBar/index.js.map +0 -1
- package/dist/NavMenu/index.js.map +0 -1
- package/dist/Pagination/index.js.map +0 -1
- package/dist/SelectBox/SelectBoxInput.torp +0 -95
- package/dist/SelectBox/index.js.map +0 -1
- package/dist/TabGroup/index.js.map +0 -1
- package/dist/ToolBar/index.js.map +0 -1
- package/dist/icons/index.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/metafile-esm.json +0 -1
- package/dist/motion/fade.ts +0 -16
- package/dist/motion/grow.ts +0 -23
- package/dist/motion/measure.ts +0 -28
- package/dist/motion/slide.ts +0 -45
- package/dist/mount/index.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -2
|
@@ -4,9 +4,9 @@ interface ToolBarSeparatorProps {
|
|
|
4
4
|
/** An ID for the root element */
|
|
5
5
|
id?: string;
|
|
6
6
|
/** Classes for the root element */
|
|
7
|
-
class?: ClassValue
|
|
7
|
+
class?: ClassValue;
|
|
8
8
|
/** Styles for the root element */
|
|
9
|
-
style?: StyleValue
|
|
9
|
+
style?: StyleValue;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -14,11 +14,7 @@ interface ToolBarSeparatorProps {
|
|
|
14
14
|
*/
|
|
15
15
|
export default function ToolBarSeparator($props: ToolBarSeparatorProps | undefined) {
|
|
16
16
|
@render {
|
|
17
|
-
<div
|
|
18
|
-
{$props?.id}
|
|
19
|
-
class={["torp-tool-bar-separator", $props?.class]}
|
|
20
|
-
role="separator"
|
|
21
|
-
>
|
|
17
|
+
<div {$props?.id} class={["torp-tool-bar-separator", $props?.class]} role="separator">
|
|
22
18
|
<slot />
|
|
23
19
|
</div>
|
|
24
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SubmenuItemState } from "../utils/PopoutTypes";
|
|
2
|
+
|
|
1
3
|
export const ToolBarContextName: unique symbol = Symbol.for("torp.ToolBar");
|
|
2
|
-
export const ToolBarPopoutContextName: unique symbol = Symbol.for("torp.ToolBarPopout");
|
|
3
4
|
export const ToolBarGroupContextName: unique symbol = Symbol.for("torp.ToolBarGroup");
|
|
4
5
|
|
|
5
6
|
export interface ToolBarContext {
|
|
@@ -9,27 +10,19 @@ export interface ToolBarContext {
|
|
|
9
10
|
/** Called from a ToolBarLink or ToolBarButton when a key is pressed */
|
|
10
11
|
handleItemKey: (e: KeyboardEvent) => void;
|
|
11
12
|
|
|
13
|
+
/** Called from a MenuButton when a submenu is shown */
|
|
14
|
+
handlePopout: (index: number) => void;
|
|
15
|
+
|
|
12
16
|
/** Called from each ToolBarLink or ToolBarButton to register itself with this ToolBar */
|
|
13
|
-
registerItem: (
|
|
17
|
+
registerItem: (item: ItemState) => { index: number };
|
|
14
18
|
|
|
15
19
|
orientation: "horizontal" | "vertical";
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export interface ToolBarPopoutContext {
|
|
19
|
-
state: {
|
|
20
|
-
visible: boolean;
|
|
21
|
-
};
|
|
22
|
-
anchorElement?: HTMLElement;
|
|
23
|
-
focusFirstElement?: () => void;
|
|
24
|
-
focusLastElement?: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
export interface ToolBarGroupContext {
|
|
28
23
|
state: {
|
|
29
24
|
headerId: string;
|
|
30
25
|
};
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
export
|
|
34
|
-
setFocused: () => void;
|
|
35
|
-
}
|
|
28
|
+
export type ItemState = SubmenuItemState;
|
package/dist/ToolBar/index.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ interface ToolBarProps {
|
|
|
5
5
|
/** An ID for the root element */
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
10
|
+
style?: StyleValue;
|
|
11
11
|
/** An ARIA label for describing the menu to screen readers */
|
|
12
|
-
ariaLabel?: string | undefined
|
|
12
|
+
ariaLabel?: string | undefined;
|
|
13
13
|
/** The orientation of the menu, which affects keyboard navigation */
|
|
14
|
-
orientation?: "horizontal" | "vertical"
|
|
14
|
+
orientation?: "horizontal" | "vertical";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -44,15 +44,15 @@ interface ToolBarButtonProps {
|
|
|
44
44
|
/** An ID for the root element */
|
|
45
45
|
id?: string;
|
|
46
46
|
/** Classes for the root element */
|
|
47
|
-
class?: ClassValue
|
|
47
|
+
class?: ClassValue;
|
|
48
48
|
/** Styles for the root element */
|
|
49
|
-
style?: StyleValue
|
|
49
|
+
style?: StyleValue;
|
|
50
50
|
/** Whether this button is disabled */
|
|
51
|
-
disabled?: boolean
|
|
51
|
+
disabled?: boolean;
|
|
52
52
|
/** Raised when the button is clicked */
|
|
53
|
-
onclick?: (e: MouseEvent) => void
|
|
53
|
+
onclick?: (e: MouseEvent) => void;
|
|
54
54
|
/** Raised when a key is pressed down */
|
|
55
|
-
onkeydown?: (e: KeyboardEvent) => void
|
|
55
|
+
onkeydown?: (e: KeyboardEvent) => void;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -73,13 +73,13 @@ interface ToolBarElementProps {
|
|
|
73
73
|
/** An ID for the root element */
|
|
74
74
|
id?: string;
|
|
75
75
|
/** Classes for the root element */
|
|
76
|
-
class?: ClassValue
|
|
76
|
+
class?: ClassValue;
|
|
77
77
|
/** Styles for the root element */
|
|
78
|
-
style?: StyleValue
|
|
78
|
+
style?: StyleValue;
|
|
79
79
|
/** Whether this button is disabled */
|
|
80
|
-
disabled?: boolean
|
|
80
|
+
disabled?: boolean;
|
|
81
81
|
/** An element that can be focused via keyboard navigation */
|
|
82
|
-
element?: HTMLElement
|
|
82
|
+
element?: HTMLElement;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -100,21 +100,19 @@ interface ToolBarPopoutProps {
|
|
|
100
100
|
/** An ID for the root element */
|
|
101
101
|
id?: string;
|
|
102
102
|
/** Classes for the root element */
|
|
103
|
-
class?: ClassValue
|
|
103
|
+
class?: ClassValue;
|
|
104
104
|
/** Styles for the root element */
|
|
105
|
-
style?: StyleValue
|
|
105
|
+
style?: StyleValue;
|
|
106
106
|
/** Whether the popout is visible */
|
|
107
|
-
visible
|
|
108
|
-
/** Raised when the popout is opened or closed */
|
|
109
|
-
ontoggle?: (open: boolean) => void,
|
|
107
|
+
visible: Bindable<boolean | undefined>;
|
|
110
108
|
/** Raised when the popout has opened */
|
|
111
|
-
onopen?: () => void
|
|
109
|
+
onopen?: () => void;
|
|
112
110
|
/** Raised when the popout has closed */
|
|
113
|
-
onclose?: (result: any) => void
|
|
111
|
+
onclose?: (result: any) => void;
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
/**
|
|
117
|
-
* A popout that is attached to a
|
|
115
|
+
* A popout that is attached to a toolbar button and can be used to show a submenu.
|
|
118
116
|
*
|
|
119
117
|
* The structure of a ToolBarPopout is:
|
|
120
118
|
*
|
|
@@ -139,13 +137,13 @@ interface ToolBarPopoutContentProps {
|
|
|
139
137
|
/** An ID for the root element */
|
|
140
138
|
id?: string;
|
|
141
139
|
/** Classes for the root element */
|
|
142
|
-
class?: ClassValue
|
|
140
|
+
class?: ClassValue;
|
|
143
141
|
/** Styles for the root element */
|
|
144
|
-
style?: StyleValue
|
|
142
|
+
style?: StyleValue;
|
|
145
143
|
/** Where the popout will be shown, relative to the popout button */
|
|
146
|
-
side?: "top" | "right" | "bottom" | "left"
|
|
144
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
147
145
|
/** How the popout will be aligned, relative to the popout button */
|
|
148
|
-
alignment?: "start" | "center" | "end"
|
|
146
|
+
alignment?: "start" | "center" | "end";
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
/**
|
|
@@ -166,13 +164,13 @@ interface ToolBarPopoutTriggerProps {
|
|
|
166
164
|
/** An ID for the root element */
|
|
167
165
|
id?: string;
|
|
168
166
|
/** Classes for the root element */
|
|
169
|
-
class?: ClassValue
|
|
167
|
+
class?: ClassValue;
|
|
170
168
|
/** Styles for the root element */
|
|
171
|
-
style?: StyleValue
|
|
169
|
+
style?: StyleValue;
|
|
172
170
|
/** The delay before showing the popout, in milliseconds */
|
|
173
|
-
hoverDelay?: number
|
|
171
|
+
hoverDelay?: number;
|
|
174
172
|
/** Whether this button is disabled */
|
|
175
|
-
disabled?: boolean
|
|
173
|
+
disabled?: boolean;
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
/**
|
|
@@ -193,9 +191,9 @@ interface ToolBarSeparatorProps {
|
|
|
193
191
|
/** An ID for the root element */
|
|
194
192
|
id?: string;
|
|
195
193
|
/** Classes for the root element */
|
|
196
|
-
class?: ClassValue
|
|
194
|
+
class?: ClassValue;
|
|
197
195
|
/** Styles for the root element */
|
|
198
|
-
style?: StyleValue
|
|
196
|
+
style?: StyleValue;
|
|
199
197
|
}
|
|
200
198
|
|
|
201
199
|
/**
|
|
@@ -209,4 +207,4 @@ declare function ToolBarSeparator(
|
|
|
209
207
|
$slots?: Record<string, SlotRender>,
|
|
210
208
|
): void;
|
|
211
209
|
|
|
212
|
-
export { ToolBar, ToolBarButton, ToolBarElement, ToolBarPopout, ToolBarPopoutContent, ToolBarPopoutTrigger, ToolBarSeparator };
|
|
210
|
+
export { ToolBar, ToolBarButton, ToolBarElement, ToolBarPopout, ToolBarPopoutContent, ToolBarPopoutTrigger, ToolBarSeparator };
|
package/dist/ToolBar/index.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/ToolBar/ToolBarPopout.torp
|
|
11
|
-
import ToolBarPopout_default from "./ToolBarPopout.torp";
|
|
12
|
-
|
|
13
|
-
// src/ToolBar/ToolBarPopoutContent.torp
|
|
14
|
-
import ToolBarPopoutContent_default from "./ToolBarPopoutContent.torp";
|
|
15
|
-
|
|
16
|
-
// src/ToolBar/ToolBarPopoutTrigger.torp
|
|
17
|
-
import ToolBarPopoutTrigger_default from "./ToolBarPopoutTrigger.torp";
|
|
18
|
-
|
|
19
|
-
// src/ToolBar/ToolBarSeparator.torp
|
|
20
|
-
import ToolBarSeparator_default from "./ToolBarSeparator.torp";
|
|
21
|
-
export {
|
|
22
|
-
ToolBar_default as ToolBar,
|
|
23
|
-
ToolBarButton_default as ToolBarButton,
|
|
24
|
-
ToolBarElement_default as ToolBarElement,
|
|
25
|
-
ToolBarPopout_default as ToolBarPopout,
|
|
26
|
-
ToolBarPopoutContent_default as ToolBarPopoutContent,
|
|
27
|
-
ToolBarPopoutTrigger_default as ToolBarPopoutTrigger,
|
|
28
|
-
ToolBarSeparator_default as ToolBarSeparator
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import ToolBar from "./ToolBar.torp";
|
|
2
|
+
import ToolBarButton from "./ToolBarButton.torp";
|
|
3
|
+
import ToolBarElement from "./ToolBarElement.torp";
|
|
4
|
+
import ToolBarPopout from "./ToolBarPopout.torp";
|
|
5
|
+
import ToolBarPopoutContent from "./ToolBarPopoutContent.torp";
|
|
6
|
+
import ToolBarPopoutTrigger from "./ToolBarPopoutTrigger.torp";
|
|
7
|
+
import ToolBarSeparator from "./ToolBarSeparator.torp";
|
|
8
|
+
export { ToolBar, ToolBarButton, ToolBarElement, ToolBarPopout, ToolBarPopoutContent, ToolBarPopoutTrigger, ToolBarSeparator };
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import $handle from "../utils/$handle";
|
|
3
|
+
import {
|
|
4
|
+
type FieldContext,
|
|
5
|
+
FieldContextName,
|
|
6
|
+
type FormContext,
|
|
7
|
+
FormContextName,
|
|
8
|
+
} from "../Form/FormTypes";
|
|
9
|
+
import type { LoadResult, Loader } from "../utils/loader";
|
|
10
|
+
import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
|
|
11
|
+
import { createItemGroup } from "../utils/createItemGroup";
|
|
12
|
+
import getId from "../utils/getId";
|
|
13
|
+
import createFormField from "../utils/formField";
|
|
14
|
+
import {
|
|
15
|
+
type ItemState,
|
|
16
|
+
type TreeContext,
|
|
17
|
+
type TreeLoadRequest,
|
|
18
|
+
TreeContextName,
|
|
19
|
+
} from "./TreeTypes";
|
|
20
|
+
import FormValues from "../Form/FormValues.torp";
|
|
21
|
+
|
|
22
|
+
interface TreeProps {
|
|
23
|
+
/** An ID for the root element */
|
|
24
|
+
id?: string;
|
|
25
|
+
/** Classes for the root element */
|
|
26
|
+
class?: ClassValue;
|
|
27
|
+
/** Styles for the root element */
|
|
28
|
+
style?: StyleValue;
|
|
29
|
+
/** The value(s) of the expanded TreeItem(s) */
|
|
30
|
+
expanded: Bindable<string | string[] | undefined>;
|
|
31
|
+
/** Whether a single TreeItem or multiple TreeItems can be selected at the same time */
|
|
32
|
+
type?: "single" | "multiple";
|
|
33
|
+
/** The value of the selected TreeItem, or an array of values if the type is "multiple" */
|
|
34
|
+
value: Bindable<string | string[] | undefined>;
|
|
35
|
+
/** If set to true, the user cannot interact with any items in the Tree */
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/** The aria-label for the root element */
|
|
38
|
+
ariaLabel?: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Reads the children of an item from the network (or anywhere async) when
|
|
41
|
+
* the item is first expanded. Receives a request with `item` (the parent
|
|
42
|
+
* item's value). Items load automatically when they set the TreeItem
|
|
43
|
+
* `hasChildren` prop; a TreeItem `load` prop overrides this per item.
|
|
44
|
+
*/
|
|
45
|
+
load?: Loader<any, TreeLoadRequest>;
|
|
46
|
+
/** Called after each successful child load with the normalized result */
|
|
47
|
+
onload?: (result: LoadResult, item: string | undefined) => void;
|
|
48
|
+
/** Extracts the display text for a loaded item (defaults to `label ?? text ?? item`) */
|
|
49
|
+
getItemLabel?: (item: any) => any;
|
|
50
|
+
/** Extracts the value for a loaded item (defaults to `value ?? id`) */
|
|
51
|
+
getItemValue?: (item: any) => any;
|
|
52
|
+
/** Raised when the expanded item(s) have changed */
|
|
53
|
+
onexpand?: (value: string | string[]) => void;
|
|
54
|
+
/** Raised when the selected item(s) have changed */
|
|
55
|
+
/** The name of the component's form data field */
|
|
56
|
+
name?: string;
|
|
57
|
+
onchange?: (value: string | string[] | undefined) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A hierarchical list of items that can be expanded and collapsed to reveal nested content,
|
|
62
|
+
* with support for selecting items.
|
|
63
|
+
*
|
|
64
|
+
* See [the WAI ARIA guidelines for Tree Views](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/).
|
|
65
|
+
*
|
|
66
|
+
* The structure of a Tree is:
|
|
67
|
+
*
|
|
68
|
+
* ```
|
|
69
|
+
* <Tree>
|
|
70
|
+
* <TreeItem>
|
|
71
|
+
* <TreeItemContent>
|
|
72
|
+
* <TreeItemTrigger />
|
|
73
|
+
* <TreeItemLabel />
|
|
74
|
+
* </TreeItemContent>
|
|
75
|
+
* <TreeItemChildren>
|
|
76
|
+
* <TreeItem />
|
|
77
|
+
* </TreeItemChildren>
|
|
78
|
+
* </TreeItem>
|
|
79
|
+
* </Tree>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export default function Tree($props: TreeProps | undefined) {
|
|
83
|
+
let defaultId = getId();
|
|
84
|
+
let root: HTMLElement;
|
|
85
|
+
|
|
86
|
+
// Wire up the enclosing Form and Field, if any
|
|
87
|
+
const form = createFormField(
|
|
88
|
+
$props?.name,
|
|
89
|
+
$context[FormContextName] as FormContext | undefined,
|
|
90
|
+
$context[FieldContextName] as FieldContext | undefined,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Get the current selection type, re-reading $props so changes are picked up
|
|
94
|
+
function getType(): "single" | "multiple" {
|
|
95
|
+
return $props?.type ?? "single";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if ($props?.load !== undefined && typeof $props.load !== "function") {
|
|
99
|
+
throw new Error("Tree: `load` must be a function");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let $state = $watch({
|
|
103
|
+
expanded: $props?.expanded ?? [],
|
|
104
|
+
value: $props?.value ?? (getType() === "single" ? undefined : []),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
$bind($state, $props, "expanded", "value");
|
|
108
|
+
|
|
109
|
+
// Maybe get stuff out of a popout context
|
|
110
|
+
const popoutContext = $context[PopoutContextName] as PopoutContext | undefined;
|
|
111
|
+
if (popoutContext) {
|
|
112
|
+
// Set the content ID and role so that triggers can use them with
|
|
113
|
+
// aria-controls / aria-haspopup
|
|
114
|
+
popoutContext.state.contentId = $props?.id ?? defaultId;
|
|
115
|
+
popoutContext.state.contentRole = "tree";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Expansion behaves like a multiple-select group over the "expanded" flag;
|
|
119
|
+
// selection behaves like a single- or multiple-select group over "selected".
|
|
120
|
+
// Both groups share the same item states.
|
|
121
|
+
const expandedGroup = createItemGroup<ItemState>({
|
|
122
|
+
state: {
|
|
123
|
+
get value() {
|
|
124
|
+
return $state.expanded;
|
|
125
|
+
},
|
|
126
|
+
set value(value) {
|
|
127
|
+
$state.expanded = value;
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
type: "multiple",
|
|
131
|
+
selectedProperty: "expanded",
|
|
132
|
+
});
|
|
133
|
+
const selectGroup = createItemGroup<ItemState>({
|
|
134
|
+
state: $state,
|
|
135
|
+
type: getType,
|
|
136
|
+
selectedProperty: "selected",
|
|
137
|
+
disabled: () => $props?.disabled,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Both groups hold the same item states in the same order
|
|
141
|
+
const itemStates = selectGroup.itemStates;
|
|
142
|
+
|
|
143
|
+
let context: TreeContext = {
|
|
144
|
+
get type() {
|
|
145
|
+
return getType();
|
|
146
|
+
},
|
|
147
|
+
state: $state,
|
|
148
|
+
registerItem,
|
|
149
|
+
removeItem,
|
|
150
|
+
toggleExpand: expandedGroup.toggleItem,
|
|
151
|
+
toggleSelect: (value) => {
|
|
152
|
+
selectGroup.toggleItem(value);
|
|
153
|
+
form.handleInput();
|
|
154
|
+
},
|
|
155
|
+
handleKey,
|
|
156
|
+
focusFirstItem,
|
|
157
|
+
focusLastItem,
|
|
158
|
+
findItem,
|
|
159
|
+
getNextVisibleItem,
|
|
160
|
+
getPreviousVisibleItem,
|
|
161
|
+
getParentItem,
|
|
162
|
+
getFirstChildItem,
|
|
163
|
+
load: typeof $props?.load === "function" ? $props.load : undefined,
|
|
164
|
+
onload: $props?.onload,
|
|
165
|
+
getItemLabel: $props?.getItemLabel,
|
|
166
|
+
getItemValue: $props?.getItemValue,
|
|
167
|
+
};
|
|
168
|
+
$context[TreeContextName] = context;
|
|
169
|
+
|
|
170
|
+
// Dispatch the expand event when the expanded value changes
|
|
171
|
+
$handle((first) => {
|
|
172
|
+
const value = $state.expanded;
|
|
173
|
+
if (!first) $props?.onexpand?.(value);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Dispatch the change event when the selected value changes
|
|
177
|
+
$handle((first) => {
|
|
178
|
+
const value = $state.value;
|
|
179
|
+
if (!first) $props?.onchange?.(value);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
function registerItem(itemState: ItemState, level: number) {
|
|
183
|
+
itemState.level = level;
|
|
184
|
+
expandedGroup.registerItem(itemState);
|
|
185
|
+
selectGroup.registerItem(itemState);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function removeItem(itemIndex: number) {
|
|
189
|
+
expandedGroup.removeItem(itemIndex);
|
|
190
|
+
selectGroup.removeItem(itemIndex);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function handleKey(index: number, e: KeyboardEvent) {
|
|
194
|
+
switch (e.key) {
|
|
195
|
+
case "ArrowUp": {
|
|
196
|
+
e.preventDefault();
|
|
197
|
+
let previousItem = getPreviousVisibleItem(index);
|
|
198
|
+
if (previousItem) {
|
|
199
|
+
previousItem.setFocused();
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "ArrowDown": {
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
let nextItem = getNextVisibleItem(index);
|
|
206
|
+
if (nextItem) {
|
|
207
|
+
nextItem.setFocused();
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case "ArrowLeft": {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
let currentItem = findItem(index);
|
|
214
|
+
if (currentItem && currentItem.expanded) {
|
|
215
|
+
expandedGroup.toggleItem(currentItem.value);
|
|
216
|
+
} else {
|
|
217
|
+
let parentItem = getParentItem(index);
|
|
218
|
+
if (parentItem) {
|
|
219
|
+
parentItem.setFocused();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "ArrowRight": {
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
let currentItem = findItem(index);
|
|
227
|
+
if (currentItem) {
|
|
228
|
+
if (currentItem.expanded) {
|
|
229
|
+
let firstChild = getFirstChildItem(index);
|
|
230
|
+
if (firstChild) {
|
|
231
|
+
firstChild.setFocused();
|
|
232
|
+
}
|
|
233
|
+
} else if (currentItem.hasChildren) {
|
|
234
|
+
expandedGroup.toggleItem(currentItem.value);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case "Home": {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
focusFirstItem();
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case "End": {
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
focusLastItem();
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "Enter":
|
|
250
|
+
case " ": {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
let currentItem = findItem(index);
|
|
253
|
+
if (currentItem) {
|
|
254
|
+
selectGroup.toggleItem(currentItem.value);
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function focusFirstItem() {
|
|
262
|
+
for (let item of itemStates) {
|
|
263
|
+
if (!isItemVisible(item, itemStates)) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
item.setFocused();
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function focusLastItem() {
|
|
272
|
+
for (let i = itemStates.length - 1; i >= 0; i--) {
|
|
273
|
+
let item = itemStates[i];
|
|
274
|
+
if (!isItemVisible(item, itemStates)) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
item.setFocused();
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function findItem(index: number): ItemState | undefined {
|
|
283
|
+
return itemStates.find((item) => item.index === index);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function getNextVisibleItem(index: number): ItemState | undefined {
|
|
287
|
+
let currentItem = findItem(index);
|
|
288
|
+
if (!currentItem) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (currentItem.expanded && currentItem.hasChildren) {
|
|
293
|
+
let nextIndex = index + 1;
|
|
294
|
+
if (nextIndex < itemStates.length) {
|
|
295
|
+
return itemStates[nextIndex];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for (let i = index + 1; i < itemStates.length; i++) {
|
|
300
|
+
let item = itemStates[i];
|
|
301
|
+
if (isItemVisible(item, itemStates) && !item.disabled) {
|
|
302
|
+
return item;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function getPreviousVisibleItem(index: number): ItemState | undefined {
|
|
310
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
311
|
+
let item = itemStates[i];
|
|
312
|
+
if (isItemVisible(item, itemStates) && !item.disabled) {
|
|
313
|
+
return item;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function getParentItem(index: number): ItemState | undefined {
|
|
320
|
+
let currentItem = findItem(index);
|
|
321
|
+
if (!currentItem) {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
326
|
+
let item = itemStates[i];
|
|
327
|
+
if (item.expanded && item.hasChildren && i < index) {
|
|
328
|
+
let nextIndex = i + 1;
|
|
329
|
+
while (nextIndex < itemStates.length) {
|
|
330
|
+
let sibling = itemStates[nextIndex];
|
|
331
|
+
if (sibling.level <= item.level) {
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
if (nextIndex === index) {
|
|
335
|
+
return item;
|
|
336
|
+
}
|
|
337
|
+
nextIndex++;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function getFirstChildItem(index: number): ItemState | undefined {
|
|
346
|
+
let nextIndex = index + 1;
|
|
347
|
+
if (nextIndex < itemStates.length) {
|
|
348
|
+
let child = itemStates[nextIndex];
|
|
349
|
+
if (child.level > itemStates[index].level) {
|
|
350
|
+
return child;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function isItemVisible(item: ItemState, allItems: ItemState[]): boolean {
|
|
357
|
+
if (item.level === 0) {
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
for (let i = item.index - 1; i >= 0; i--) {
|
|
362
|
+
let parentItem = allItems[i];
|
|
363
|
+
if (parentItem.level < item.level) {
|
|
364
|
+
return parentItem.expanded;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@render {
|
|
372
|
+
<div
|
|
373
|
+
id={$props?.id ?? defaultId}
|
|
374
|
+
class={["torp-tree", $props?.class]}
|
|
375
|
+
{$props?.style}
|
|
376
|
+
role="tree"
|
|
377
|
+
aria-label={$props?.ariaLabel}
|
|
378
|
+
aria-multiselectable={getType() === "multiple" ? "true" : undefined}
|
|
379
|
+
data-valid={form.valid ? "valid" : "invalid"}
|
|
380
|
+
aria-describedby={form.messageId}
|
|
381
|
+
aria-invalid={form.inField && !form.valid ? "true" : undefined}
|
|
382
|
+
onfocusout={(e: FocusEvent) => {
|
|
383
|
+
// Only validate when focus leaves the whole tree
|
|
384
|
+
if (!root.contains(e.relatedTarget as Node | null)) {
|
|
385
|
+
form.handleBlur();
|
|
386
|
+
}
|
|
387
|
+
}}
|
|
388
|
+
&ref={root}
|
|
389
|
+
>
|
|
390
|
+
<slot />
|
|
391
|
+
</div>
|
|
392
|
+
|
|
393
|
+
<FormValues name={form.name} value={$state.value} />
|
|
394
|
+
}
|
|
395
|
+
}
|