@torpor/ui 1.3.6 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Accordion/AccordionItem.torp +1 -1
- package/dist/Alert/Alert.torp +41 -0
- package/dist/Alert/index.d.ts +37 -0
- package/dist/Alert/index.js +1 -0
- package/dist/Charts/ChartScatter.torp +167 -0
- package/dist/Charts/ScatterChart.torp +49 -178
- package/dist/Charts/index.d.ts +38 -78
- package/dist/Charts/index.js +2 -4
- package/dist/ColorPicker/ColorPalette.torp +107 -29
- package/dist/ColorPicker/ColorPicker.torp +121 -10
- package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
- package/dist/ColorPicker/ColorPickerArea.torp +175 -0
- package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
- package/dist/ColorPicker/ColorPickerHue.torp +59 -0
- package/dist/ColorPicker/ColorPickerInput.torp +7 -18
- package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
- package/dist/ColorPicker/index.d.ts +139 -14
- package/dist/ColorPicker/index.js +5 -1
- package/dist/ComboBox/ComboBox.torp +40 -5
- package/dist/ComboBox/index.d.ts +5 -2
- package/dist/ComboBox/index.js +1 -2
- package/dist/Contextual/Contextual.torp +25 -77
- package/dist/Contextual/ContextualContent.torp +10 -51
- package/dist/Contextual/ContextualHover.torp +13 -85
- package/dist/Contextual/ContextualTrigger.torp +9 -16
- package/dist/Contextual/ContextualTypes.ts +6 -12
- package/dist/Contextual/index.d.ts +10 -13
- package/dist/DataGrid/DataGrid.torp +2 -2
- package/dist/DataGrid/index.d.ts +1 -1
- package/dist/DatePicker/DatePicker.torp +6 -4
- package/dist/DateRangePicker/DateRangePicker.torp +14 -13
- package/dist/DateTimePicker/DateTimePicker.torp +264 -0
- package/dist/DateTimePicker/index.d.ts +46 -0
- package/dist/DateTimePicker/index.js +1 -0
- package/dist/Dialog/Dialog.torp +0 -1
- package/dist/Dialog/index.d.ts +0 -1
- package/dist/Drawer/Drawer.torp +5 -23
- package/dist/Drawer/DrawerContent.torp +1 -0
- package/dist/Drawer/DrawerOverlay.torp +9 -16
- package/dist/Drawer/DrawerTrigger.torp +9 -24
- package/dist/Drawer/DrawerTypes.ts +3 -1
- package/dist/Form/CheckBox.torp +10 -18
- package/dist/Form/File.torp +10 -18
- package/dist/Form/FileDrop.torp +16 -22
- package/dist/Form/Input.torp +14 -20
- package/dist/Form/Radio.torp +71 -0
- package/dist/Form/RadioGroup.torp +221 -0
- package/dist/Form/RadioGroupTypes.ts +40 -0
- package/dist/Form/Select.torp +10 -18
- package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
- package/dist/Form/TextArea.torp +10 -18
- package/dist/Form/ToggleButton.torp +94 -0
- package/dist/Form/ToggleGroup.torp +150 -0
- package/dist/Form/ToggleGroupTypes.ts +23 -0
- package/dist/Form/index.d.ts +173 -15
- package/dist/Form/index.js +6 -2
- package/dist/ListBox/ListBox.torp +27 -5
- package/dist/ListBox/ListBoxItem.torp +1 -1
- package/dist/ListBox/index.d.ts +6 -2
- package/dist/MaskedInput/MaskedInput.torp +1 -1
- package/dist/Menu/MenuPopoutTrigger.torp +1 -1
- package/dist/MenuBar/MenuBar.torp +5 -3
- package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
- package/dist/Meter/Meter.torp +126 -0
- package/dist/Meter/MeterIndicator.torp +41 -0
- package/dist/Meter/MeterTypes.ts +8 -0
- package/dist/Meter/index.d.ts +79 -0
- package/dist/Meter/index.js +3 -0
- package/dist/Modal/Modal.torp +4 -22
- package/dist/Modal/ModalOverlay.torp +9 -16
- package/dist/NavMenu/NavMenu.torp +5 -3
- package/dist/NumberInput/NumberInput.torp +1 -1
- package/dist/PinInput/PinInput.torp +220 -0
- package/dist/PinInput/index.d.ts +48 -0
- package/dist/PinInput/index.js +1 -0
- package/dist/Popover/Popover.torp +18 -24
- package/dist/Popover/PopoverContent.torp +8 -0
- package/dist/Popover/PopoverHover.torp +30 -3
- package/dist/Popover/PopoverTypes.ts +2 -0
- package/dist/Popover/index.d.ts +8 -1
- package/dist/Rating/Rating.torp +1 -1
- package/dist/SegmentedControl/SegmentedControl.torp +3 -3
- package/dist/SegmentedControl/SegmentedItem.torp +1 -1
- package/dist/SelectBox/SelectBox.torp +40 -5
- package/dist/SelectBox/index.d.ts +5 -2
- package/dist/SelectBox/index.js +1 -2
- package/dist/Slider/Slider.torp +1 -1
- package/dist/SortableList/SortableList.torp +132 -0
- package/dist/SortableList/SortableListItem.torp +117 -0
- package/dist/SortableList/SortableListTypes.ts +16 -0
- package/dist/SortableList/index.d.ts +81 -0
- package/dist/SortableList/index.js +3 -0
- package/dist/TabGroup/TabContent.torp +1 -1
- package/dist/TabGroup/TabGroup.torp +2 -2
- package/dist/TabGroup/TabHeader.torp +1 -1
- package/dist/TagInput/TagInput.torp +1 -1
- package/dist/TimePicker/TimePicker.torp +1 -1
- package/dist/ToolBar/ToolBar.torp +8 -4
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
- package/dist/Tooltip/Tooltip.torp +104 -0
- package/dist/Tooltip/TooltipContent.torp +81 -0
- package/dist/Tooltip/TooltipTrigger.torp +79 -0
- package/dist/Tooltip/TooltipTypes.ts +28 -0
- package/dist/Tooltip/index.d.ts +104 -0
- package/dist/Tooltip/index.js +4 -0
- package/dist/Tree/Tree.torp +1 -1
- package/dist/Tree/TreeItem.torp +1 -1
- package/dist/VirtualList/VirtualList.torp +149 -0
- package/dist/VirtualList/index.d.ts +46 -0
- package/dist/VirtualList/index.js +1 -0
- package/dist/dnd/index.d.ts +2 -0
- package/dist/dnd/index.js +212 -0
- package/dist/dnd/index.js.map +1 -0
- package/dist/loader/index.d.ts +2 -0
- package/dist/{loader-CBGbVpkN.js → loader/index.js} +2 -2
- package/dist/loader/index.js.map +1 -0
- package/dist/utils/PopoutClickTrigger.torp +1 -0
- package/dist/utils/PopoutOverlay.torp +39 -0
- package/dist/utils/PopoutTypes.ts +4 -0
- package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
- package/dist/utils/colorUtils.ts +260 -75
- package/dist/utils/formField.ts +4 -3
- package/dist/utils/handlePopoutButton.ts +43 -0
- package/package.json +41 -5
- package/dist/Charts/GridLines.torp +0 -65
- package/dist/Charts/XAxis.torp +0 -69
- package/dist/Charts/YAxis.torp +0 -49
- package/dist/loader-CBGbVpkN.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as PinInput } from "./PinInput.torp";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import $handle from "../utils/$handle";
|
|
3
|
+
import { createPopoutButtonHandler } from "../utils/handlePopoutButton";
|
|
3
4
|
import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
|
|
4
5
|
import {
|
|
5
6
|
type Point,
|
|
@@ -21,8 +22,13 @@ interface PopoverProps {
|
|
|
21
22
|
visible: Bindable<boolean | undefined>;
|
|
22
23
|
/** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
|
|
23
24
|
anchor?: HTMLElement;
|
|
24
|
-
/** The position to display this popover at if it's contextual, as an alternative to supplying a
|
|
25
|
+
/** The position to display this popover at if it's contextual, as an alternative to supplying a ContextualTrigger */
|
|
25
26
|
position?: Point;
|
|
27
|
+
/**
|
|
28
|
+
* If set to true, the popover is positioned at `position` relative to
|
|
29
|
+
* its anchor instead of by side/alignment. Contextual uses this mode.
|
|
30
|
+
*/
|
|
31
|
+
contextual?: boolean;
|
|
26
32
|
/** Raised when the popover has opened */
|
|
27
33
|
onopen?: () => void;
|
|
28
34
|
/** Raised when the popover has closed */
|
|
@@ -31,6 +37,8 @@ interface PopoverProps {
|
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
39
|
* A popover window that is shown to the user relative to an anchor element.
|
|
40
|
+
* Set `contextual` for Contextual's mode, where the content is positioned at
|
|
41
|
+
* an explicit point instead of beside the anchor.
|
|
34
42
|
*
|
|
35
43
|
* The structure of a Popover is:
|
|
36
44
|
*
|
|
@@ -55,7 +63,8 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
55
63
|
$state.position = $props?.position ?? { x: 0, y: 0 };
|
|
56
64
|
});
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
const { handleButton, getResult } = createPopoutButtonHandler($state);
|
|
59
68
|
|
|
60
69
|
// Set the context to pass down to items
|
|
61
70
|
let context: PopoverContext = {
|
|
@@ -64,6 +73,7 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
64
73
|
state: $state,
|
|
65
74
|
//modal: $props?.modal,
|
|
66
75
|
anchorElement: $props?.anchor ? $unwrap($props.anchor) : undefined,
|
|
76
|
+
isContextual: () => $props?.contextual === true,
|
|
67
77
|
};
|
|
68
78
|
$context[PopoverContextName] = context;
|
|
69
79
|
|
|
@@ -78,30 +88,10 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
78
88
|
if (visible) {
|
|
79
89
|
$props?.onopen?.();
|
|
80
90
|
} else {
|
|
81
|
-
$props?.onclose?.(
|
|
91
|
+
$props?.onclose?.(getResult());
|
|
82
92
|
}
|
|
83
93
|
});
|
|
84
94
|
|
|
85
|
-
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
86
|
-
// Get the button's result
|
|
87
|
-
switch (type) {
|
|
88
|
-
case "confirm": {
|
|
89
|
-
result = value ?? true;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
case "cancel": {
|
|
93
|
-
result = value ?? false;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
default: {
|
|
97
|
-
result = value;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Hide the popover
|
|
103
|
-
$state.visible = false;
|
|
104
|
-
}
|
|
105
95
|
|
|
106
96
|
function handleClickOutside(e: MouseEvent | KeyboardEvent) {
|
|
107
97
|
e.preventDefault();
|
|
@@ -109,7 +99,11 @@ export default function Popover($props: PopoverProps | undefined) {
|
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
@render {
|
|
112
|
-
<div
|
|
102
|
+
<div
|
|
103
|
+
{$props?.id}
|
|
104
|
+
class={["torp-popover", $props?.contextual ? "torp-context" : undefined, $props?.class]}
|
|
105
|
+
{$props?.style}
|
|
106
|
+
>
|
|
113
107
|
<slot />
|
|
114
108
|
</div>
|
|
115
109
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import getId from "../utils/getId";
|
|
3
3
|
import { createPopoutContent } from "../utils/popoutContent";
|
|
4
|
+
import setContextPosition from "../utils/setContextPosition";
|
|
4
5
|
import { type PopoverContext, PopoverContextName } from "./PopoverTypes";
|
|
5
6
|
|
|
6
7
|
interface PopoverContentProps {
|
|
@@ -39,6 +40,13 @@ export default function PopoverContent($props?: PopoverContentProps | undefined)
|
|
|
39
40
|
close: (e) => context.handleClickOutside?.(e),
|
|
40
41
|
side: $props?.side ?? "bottom",
|
|
41
42
|
alignment: $props?.alignment ?? "center",
|
|
43
|
+
position: context.isContextual()
|
|
44
|
+
? () => {
|
|
45
|
+
if (context.anchorElement && div) {
|
|
46
|
+
setContextPosition(context.anchorElement, div, context.state.position);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
42
50
|
ignoreAnchorClicks: true,
|
|
43
51
|
focusFirstElement: () => context.focusFirstElement?.(),
|
|
44
52
|
refocusAnchorOnHide: true,
|
|
@@ -52,6 +52,30 @@ export default function PopoverHover($props?: PopoverHoverProps) {
|
|
|
52
52
|
}
|
|
53
53
|
const $state = context.state;
|
|
54
54
|
|
|
55
|
+
let node: HTMLElement;
|
|
56
|
+
|
|
57
|
+
// In contextual mode the content opens at the pointer, or the centre of
|
|
58
|
+
// the trigger when it was opened by focus
|
|
59
|
+
function activate(point: { clientX: number; clientY: number }) {
|
|
60
|
+
if (!context.isContextual() || !node) return;
|
|
61
|
+
const rect = node.getBoundingClientRect();
|
|
62
|
+
$state.position = { x: point.clientX - rect.left, y: point.clientY - rect.top };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleEnter(e: MouseEvent) {
|
|
66
|
+
if (context.isContextual()) {
|
|
67
|
+
activate(e);
|
|
68
|
+
}
|
|
69
|
+
hover.handleEnter();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleFocus() {
|
|
73
|
+
if (context.isContextual() && node) {
|
|
74
|
+
activate({ clientX: node.offsetWidth / 2, clientY: node.offsetHeight / 2 });
|
|
75
|
+
}
|
|
76
|
+
hover.handleFocus();
|
|
77
|
+
}
|
|
78
|
+
|
|
55
79
|
// Set the trigger ID so that it can be used with aria-labelledby
|
|
56
80
|
$state.triggerId = $props?.id ?? defaultId;
|
|
57
81
|
|
|
@@ -87,12 +111,15 @@ export default function PopoverHover($props?: PopoverHoverProps) {
|
|
|
87
111
|
aria-haspopup={$state.contentRole ?? "true"}
|
|
88
112
|
aria-expanded={$state.visible ? "true" : "false"}
|
|
89
113
|
aria-controls={$state.contentId}
|
|
90
|
-
onmouseenter={
|
|
114
|
+
onmouseenter={handleEnter}
|
|
91
115
|
onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
|
|
92
116
|
onpointerdown={(e: PointerEvent) => hover.handlePointerDown(e)}
|
|
93
|
-
onfocus={
|
|
117
|
+
onfocus={handleFocus}
|
|
94
118
|
onblur={(e: FocusEvent) => hover.handleBlur(e)}
|
|
95
|
-
onmount={
|
|
119
|
+
onmount={(el) => {
|
|
120
|
+
node = el;
|
|
121
|
+
anchor(el);
|
|
122
|
+
}}
|
|
96
123
|
>
|
|
97
124
|
<slot />
|
|
98
125
|
</div>
|
|
@@ -5,6 +5,8 @@ export const PopoverContextName: unique symbol = Symbol.for("torp.Popover");
|
|
|
5
5
|
/** The shared context for popover components (Contextual, Prompt and Popover) */
|
|
6
6
|
export interface PopoverContext extends PopoutContext {
|
|
7
7
|
state: PopoverState;
|
|
8
|
+
/** Whether the popover is positioned at an explicit point */
|
|
9
|
+
isContextual: () => boolean;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export interface PopoverState extends PopoutState {
|
package/dist/Popover/index.d.ts
CHANGED
|
@@ -14,8 +14,13 @@ interface PopoverProps {
|
|
|
14
14
|
visible: Bindable<boolean | undefined>;
|
|
15
15
|
/** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
|
|
16
16
|
anchor?: HTMLElement;
|
|
17
|
-
/** The position to display this popover at if it's contextual, as an alternative to supplying a
|
|
17
|
+
/** The position to display this popover at if it's contextual, as an alternative to supplying a ContextualTrigger */
|
|
18
18
|
position?: Point;
|
|
19
|
+
/**
|
|
20
|
+
* If set to true, the popover is positioned at `position` relative to
|
|
21
|
+
* its anchor instead of by side/alignment. Contextual uses this mode.
|
|
22
|
+
*/
|
|
23
|
+
contextual?: boolean;
|
|
19
24
|
/** Raised when the popover has opened */
|
|
20
25
|
onopen?: () => void;
|
|
21
26
|
/** Raised when the popover has closed */
|
|
@@ -24,6 +29,8 @@ interface PopoverProps {
|
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
31
|
* A popover window that is shown to the user relative to an anchor element.
|
|
32
|
+
* Set `contextual` for Contextual's mode, where the content is positioned at
|
|
33
|
+
* an explicit point instead of beside the anchor.
|
|
27
34
|
*
|
|
28
35
|
* The structure of a Popover is:
|
|
29
36
|
*
|
package/dist/Rating/Rating.torp
CHANGED
|
@@ -59,7 +59,7 @@ export default function Rating($props: RatingProps | undefined) {
|
|
|
59
59
|
|
|
60
60
|
// Wire up the enclosing Form and Field, if any
|
|
61
61
|
const form = createFormField(
|
|
62
|
-
$props?.name,
|
|
62
|
+
() => $props?.name,
|
|
63
63
|
$context[FormContextName] as FormContext | undefined,
|
|
64
64
|
$context[FieldContextName] as FieldContext | undefined,
|
|
65
65
|
);
|
|
@@ -57,7 +57,7 @@ export default function SegmentedControl($props: SegmentedControlProps | undefin
|
|
|
57
57
|
|
|
58
58
|
// Wire up the enclosing Form and Field, if any
|
|
59
59
|
const form = createFormField(
|
|
60
|
-
$props?.name,
|
|
60
|
+
() => $props?.name,
|
|
61
61
|
$context[FormContextName] as FormContext | undefined,
|
|
62
62
|
$context[FieldContextName] as FieldContext | undefined,
|
|
63
63
|
);
|
|
@@ -140,8 +140,8 @@ export default function SegmentedControl($props: SegmentedControlProps | undefin
|
|
|
140
140
|
index,
|
|
141
141
|
value,
|
|
142
142
|
active: false,
|
|
143
|
-
disabled: disabled
|
|
144
|
-
parentDisabled: $props?.disabled
|
|
143
|
+
disabled: disabled === true,
|
|
144
|
+
parentDisabled: $props?.disabled === true,
|
|
145
145
|
setFocused: () => {},
|
|
146
146
|
});
|
|
147
147
|
group.registerItem(itemState);
|
|
@@ -29,7 +29,7 @@ export default function SegmentedItem($props: SegmentedItemProps | undefined) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Register this item with the parent SegmentedControl
|
|
32
|
-
|
|
32
|
+
const $state = context.registerItem($props?.index, $props?.value, $props?.disabled);
|
|
33
33
|
|
|
34
34
|
$run(() => {
|
|
35
35
|
return () => {
|
|
@@ -21,8 +21,11 @@ interface SelectBoxProps {
|
|
|
21
21
|
style?: StyleValue;
|
|
22
22
|
/** The name of the input's form data field */
|
|
23
23
|
name?: string;
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The data value selected by the user, or an array of values if multiple
|
|
26
|
+
* is set. Defaults to the enclosing Field's value when omitted.
|
|
27
|
+
*/
|
|
28
|
+
value?: Bindable<any>;
|
|
26
29
|
/** Whether multiple values can be selected at the same time */
|
|
27
30
|
multiple?: boolean;
|
|
28
31
|
/**
|
|
@@ -67,15 +70,21 @@ interface SelectBoxProps {
|
|
|
67
70
|
*/
|
|
68
71
|
export default function SelectBox($props: SelectBoxProps | undefined) {
|
|
69
72
|
// Wire up the enclosing Form and Field, if any
|
|
73
|
+
const fieldContext = $context[FieldContextName] as FieldContext | undefined;
|
|
70
74
|
const form = createFormField(
|
|
71
|
-
$props?.name,
|
|
75
|
+
() => $props?.name,
|
|
72
76
|
$context[FormContextName] as FormContext | undefined,
|
|
73
|
-
|
|
77
|
+
fieldContext,
|
|
74
78
|
);
|
|
75
79
|
|
|
80
|
+
// The list inside is part of this input, not a separate field: hide the
|
|
81
|
+
// enclosing Field's context so it doesn't resolve the Field's name and
|
|
82
|
+
// submit its own copy of the value
|
|
83
|
+
$context[FieldContextName] = undefined;
|
|
84
|
+
|
|
76
85
|
let $state: SelectBoxState = $watch({
|
|
77
86
|
visible: false,
|
|
78
|
-
value: $props?.value,
|
|
87
|
+
value: $props?.value ?? fieldContext?.state.value,
|
|
79
88
|
contentId: undefined,
|
|
80
89
|
triggerId: undefined,
|
|
81
90
|
contentRole: undefined,
|
|
@@ -83,6 +92,32 @@ export default function SelectBox($props: SelectBoxProps | undefined) {
|
|
|
83
92
|
|
|
84
93
|
$bind($state, $props, "visible", "value");
|
|
85
94
|
|
|
95
|
+
// Point the enclosing Field's Label at the trigger once it registers
|
|
96
|
+
$run(() => {
|
|
97
|
+
if (fieldContext && $state.triggerId) {
|
|
98
|
+
fieldContext.state.inputId = $state.triggerId;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// With no value prop, use the enclosing Field's value as the source and
|
|
103
|
+
// destination, so only the Field needs binding. The initial undefined is
|
|
104
|
+
// skipped so an empty Field doesn't clear a default.
|
|
105
|
+
let firstFromField = true;
|
|
106
|
+
$run(() => {
|
|
107
|
+
const value = fieldContext?.state.value;
|
|
108
|
+
const skip = firstFromField && value === undefined;
|
|
109
|
+
firstFromField = false;
|
|
110
|
+
if (!fieldContext || $props?.value !== undefined || skip) return;
|
|
111
|
+
if (value !== $state.value) {
|
|
112
|
+
$state.value = value;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
$run(() => {
|
|
116
|
+
if ($props?.value === undefined && fieldContext) {
|
|
117
|
+
fieldContext.state.value = $state.value;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
86
121
|
if ($props?.load !== undefined && typeof $props.load !== "function") {
|
|
87
122
|
throw new Error("SelectBox: `load` must be a function");
|
|
88
123
|
}
|
|
@@ -10,8 +10,11 @@ interface SelectBoxProps {
|
|
|
10
10
|
style?: StyleValue;
|
|
11
11
|
/** The name of the input's form data field */
|
|
12
12
|
name?: string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The data value selected by the user, or an array of values if multiple
|
|
15
|
+
* is set. Defaults to the enclosing Field's value when omitted.
|
|
16
|
+
*/
|
|
17
|
+
value?: Bindable<any>;
|
|
15
18
|
/** Whether multiple values can be selected at the same time */
|
|
16
19
|
multiple?: boolean;
|
|
17
20
|
/**
|
package/dist/SelectBox/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as normalizeLoadResult, t as createItemLoader } from "../loader-CBGbVpkN.js";
|
|
2
1
|
import SelectBox from "./SelectBox.torp";
|
|
3
2
|
import SelectBoxContent from "./SelectBoxContent.torp";
|
|
4
3
|
import SelectBoxTrigger from "./SelectBoxTrigger.torp";
|
|
5
|
-
export { SelectBox, SelectBoxContent, SelectBoxTrigger
|
|
4
|
+
export { SelectBox, SelectBoxContent, SelectBoxTrigger };
|
package/dist/Slider/Slider.torp
CHANGED
|
@@ -62,7 +62,7 @@ export default function Slider($props: SliderProps | undefined) {
|
|
|
62
62
|
|
|
63
63
|
// Wire up the enclosing Form and Field, if any
|
|
64
64
|
const form = createFormField(
|
|
65
|
-
$props?.name,
|
|
65
|
+
() => $props?.name,
|
|
66
66
|
$context[FormContextName] as FormContext | undefined,
|
|
67
67
|
$context[FieldContextName] as FieldContext | undefined,
|
|
68
68
|
);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import getId from "../utils/getId";
|
|
3
|
+
import { moveToSlot } from "../utils/reorderList";
|
|
4
|
+
import SortableListItem from "./SortableListItem.torp";
|
|
5
|
+
import {
|
|
6
|
+
type SortableListContext,
|
|
7
|
+
SortableListContextName,
|
|
8
|
+
} from "./SortableListTypes";
|
|
9
|
+
|
|
10
|
+
interface SortableListProps {
|
|
11
|
+
/** An ID for the root element */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Classes for the root element */
|
|
14
|
+
class?: ClassValue;
|
|
15
|
+
/** Styles for the root element */
|
|
16
|
+
style?: StyleValue;
|
|
17
|
+
/** The items, in display order */
|
|
18
|
+
items: Bindable<any[]>;
|
|
19
|
+
/** Extracts the text for an item (defaults to the item itself) */
|
|
20
|
+
getItemLabel?: (item: any) => string;
|
|
21
|
+
/** Extracts a stable key for an item (defaults to its position) */
|
|
22
|
+
getItemValue?: (item: any) => any;
|
|
23
|
+
/** If set to true, the user cannot reorder the items */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** An accessible name for the list */
|
|
26
|
+
ariaLabel?: string;
|
|
27
|
+
/** Raised when the items have been reordered */
|
|
28
|
+
onchange?: (items: any[]) => void;
|
|
29
|
+
/** Raised with the source and destination positions after a reorder */
|
|
30
|
+
onmove?: (from: number, to: number) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A list whose items can be reordered by dragging, or from the keyboard
|
|
35
|
+
* with Alt+Up / Alt+Down (and Alt+Home / Alt+End for the ends).
|
|
36
|
+
*
|
|
37
|
+
* See [the WAI ARIA guidelines for listbox reordering](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/).
|
|
38
|
+
*
|
|
39
|
+
* The structure of a SortableList is:
|
|
40
|
+
*
|
|
41
|
+
* ```
|
|
42
|
+
* <SortableList &items={$state.items} ariaLabel="Steps">
|
|
43
|
+
* <SortableListItem item={item} index={i}>...</SortableListItem>
|
|
44
|
+
* </SortableList>
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* With no children, the items are rendered automatically.
|
|
48
|
+
*/
|
|
49
|
+
export default function SortableList($props: SortableListProps | undefined) {
|
|
50
|
+
let defaultId = getId();
|
|
51
|
+
|
|
52
|
+
let $state = $watch({
|
|
53
|
+
items: ($props?.items ?? []) as any[],
|
|
54
|
+
status: "",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
$bind($state, $props, "items");
|
|
58
|
+
|
|
59
|
+
function getDisabled(): boolean {
|
|
60
|
+
return $props?.disabled === true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getItemLabel(item: any): string {
|
|
64
|
+
if ($props?.getItemLabel) return String($props.getItemLabel(item));
|
|
65
|
+
return typeof item === "string" || typeof item === "number" ? String(item) : "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function keyFor(item: any, index: number): any {
|
|
69
|
+
return $props?.getItemValue ? $props.getItemValue(item) : index;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function announce(message: string) {
|
|
73
|
+
$state.status = message;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function move(from: number, insertAt: number) {
|
|
77
|
+
if (getDisabled()) return;
|
|
78
|
+
const items = $state.items;
|
|
79
|
+
if (from < 0 || from >= items.length) return;
|
|
80
|
+
const to = Math.min(items.length - 1, Math.max(0, from < insertAt ? insertAt - 1 : insertAt));
|
|
81
|
+
if (to === from) return;
|
|
82
|
+
const moved = items[from];
|
|
83
|
+
const next = moveToSlot(items, from, insertAt);
|
|
84
|
+
$state.items = next;
|
|
85
|
+
$props?.onchange?.(next);
|
|
86
|
+
$props?.onmove?.(from, to);
|
|
87
|
+
announce(`Moved ${getItemLabel(moved) || "item"} to position ${to + 1} of ${next.length}.`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let context: SortableListContext = {
|
|
91
|
+
kind: `sortable-list:${defaultId}`,
|
|
92
|
+
getItems: () => $state.items,
|
|
93
|
+
getItemLabel,
|
|
94
|
+
getDisabled,
|
|
95
|
+
move,
|
|
96
|
+
announce,
|
|
97
|
+
};
|
|
98
|
+
$context[SortableListContextName] = context;
|
|
99
|
+
|
|
100
|
+
@render {
|
|
101
|
+
<div
|
|
102
|
+
{$props?.id}
|
|
103
|
+
class={["torp-sortable-list", $props?.class]}
|
|
104
|
+
{$props?.style}
|
|
105
|
+
role="list"
|
|
106
|
+
aria-label={$props?.ariaLabel}
|
|
107
|
+
aria-disabled={getDisabled() ? "true" : undefined}
|
|
108
|
+
>
|
|
109
|
+
<slot>
|
|
110
|
+
@for (let [i, item] of $state.items.entries()) {
|
|
111
|
+
@key = keyFor(item, i)
|
|
112
|
+
<SortableListItem {item} index={i} total={$state.items.length}>
|
|
113
|
+
{getItemLabel(item)}
|
|
114
|
+
</SortableListItem>
|
|
115
|
+
}
|
|
116
|
+
</slot>
|
|
117
|
+
|
|
118
|
+
<div class="torp-sortable-list-status" role="status" aria-live="polite">{$state.status}</div>
|
|
119
|
+
</div>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@style {
|
|
123
|
+
.torp-sortable-list-status {
|
|
124
|
+
position: absolute;
|
|
125
|
+
width: 1px;
|
|
126
|
+
height: 1px;
|
|
127
|
+
overflow: hidden;
|
|
128
|
+
clip-path: inset(50%);
|
|
129
|
+
white-space: nowrap;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import draggable from "../mount/draggable";
|
|
3
|
+
import dropTarget from "../mount/dropTarget";
|
|
4
|
+
import {
|
|
5
|
+
type SortableListContext,
|
|
6
|
+
SortableListContextName,
|
|
7
|
+
} from "./SortableListTypes";
|
|
8
|
+
|
|
9
|
+
interface SortableListItemProps {
|
|
10
|
+
/** The item this row represents */
|
|
11
|
+
item: any;
|
|
12
|
+
/** This item's position in the list */
|
|
13
|
+
index: number;
|
|
14
|
+
/** The number of items in the list */
|
|
15
|
+
total?: number;
|
|
16
|
+
/** An ID for the list item element */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** Classes for the list item element */
|
|
19
|
+
class?: ClassValue;
|
|
20
|
+
/** Styles for the list item element */
|
|
21
|
+
style?: StyleValue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One reorderable item in a SortableList. Dragging it moves it; with focus,
|
|
26
|
+
* Alt+Up / Alt+Down move it one position, and Alt+Home / Alt+End move it to
|
|
27
|
+
* an end of the list.
|
|
28
|
+
*/
|
|
29
|
+
export default function SortableListItem($props: SortableListItemProps | undefined) {
|
|
30
|
+
// Get stuff out of the SortableListContext
|
|
31
|
+
const context = $context[SortableListContextName] as SortableListContext;
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error("SortableListItem must be contained within a SortableList");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Moves this item so that it sits at `insertAt` in the original order */
|
|
37
|
+
function moveTo(insertAt: number) {
|
|
38
|
+
if (context.getDisabled()) return;
|
|
39
|
+
context.move($props?.index ?? 0, insertAt);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function handleKey(e: KeyboardEvent) {
|
|
43
|
+
if (!e.altKey || context.getDisabled()) return;
|
|
44
|
+
const index = $props?.index ?? 0;
|
|
45
|
+
const total = $props?.total ?? context.getItems().length;
|
|
46
|
+
switch (e.key) {
|
|
47
|
+
case "ArrowUp": {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
if (index > 0) moveTo(index - 1);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "ArrowDown": {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
if (index < total - 1) moveTo(index + 2);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "Home": {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
moveTo(0);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "End": {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
moveTo(total);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function wireDrag(el: HTMLElement) {
|
|
71
|
+
const stopDrag = draggable(el, {
|
|
72
|
+
kind: context.kind,
|
|
73
|
+
data: { index: $props?.index ?? 0, item: $props?.item },
|
|
74
|
+
onstart: () => !context.getDisabled(),
|
|
75
|
+
});
|
|
76
|
+
const stopDrop = dropTarget(el, {
|
|
77
|
+
accepts: (info) => info.kind === context.kind,
|
|
78
|
+
dragClass: "torp-sortable-list-item-over",
|
|
79
|
+
ondrop: (info, e) => {
|
|
80
|
+
if (context.getDisabled()) return;
|
|
81
|
+
const from = info.data?.index;
|
|
82
|
+
if (typeof from !== "number") return;
|
|
83
|
+
const rect = el.getBoundingClientRect();
|
|
84
|
+
const after = e.clientY > rect.top + rect.height / 2;
|
|
85
|
+
context.move(from, ($props?.index ?? 0) + (after ? 1 : 0));
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return () => {
|
|
89
|
+
stopDrag();
|
|
90
|
+
stopDrop();
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@render {
|
|
95
|
+
<li
|
|
96
|
+
{$props?.id}
|
|
97
|
+
class={["torp-sortable-list-item", $props?.class]}
|
|
98
|
+
{$props?.style}
|
|
99
|
+
draggable={context.getDisabled() ? undefined : "true"}
|
|
100
|
+
tabindex={context.getDisabled() ? -1 : 0}
|
|
101
|
+
aria-roledescription="sortable item"
|
|
102
|
+
aria-posinset={($props?.index ?? 0) + 1}
|
|
103
|
+
aria-setsize={$props?.total}
|
|
104
|
+
aria-disabled={context.getDisabled() ? "true" : undefined}
|
|
105
|
+
onkeydown={handleKey}
|
|
106
|
+
onmount={wireDrag}
|
|
107
|
+
>
|
|
108
|
+
<slot>{context.getItemLabel($props?.item)}</slot>
|
|
109
|
+
</li>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@style {
|
|
113
|
+
.torp-sortable-list-item-over {
|
|
114
|
+
outline: 1px dashed currentcolor;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const SortableListContextName: unique symbol = Symbol("SortableList");
|
|
2
|
+
|
|
3
|
+
export interface SortableListContext {
|
|
4
|
+
/** A unique kind for this list's drags, so they don't cross lists */
|
|
5
|
+
kind: string;
|
|
6
|
+
/** The items, in display order */
|
|
7
|
+
getItems: () => any[];
|
|
8
|
+
/** The accessible text for an item */
|
|
9
|
+
getItemLabel: (item: any) => string;
|
|
10
|
+
/** Whether the list is disabled */
|
|
11
|
+
getDisabled: () => boolean;
|
|
12
|
+
/** Moves the item at `from` to `insertAt` (an index in the original order) */
|
|
13
|
+
move: (from: number, insertAt: number) => void;
|
|
14
|
+
/** Announces a reorder to assistive tech */
|
|
15
|
+
announce: (message: string) => void;
|
|
16
|
+
}
|