@torpor/ui 1.3.5 → 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.
Files changed (129) hide show
  1. package/dist/Accordion/AccordionItem.torp +1 -1
  2. package/dist/Alert/Alert.torp +41 -0
  3. package/dist/Alert/index.d.ts +37 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Charts/ChartScatter.torp +167 -0
  6. package/dist/Charts/ScatterChart.torp +49 -178
  7. package/dist/Charts/index.d.ts +38 -78
  8. package/dist/Charts/index.js +2 -4
  9. package/dist/ColorPicker/ColorPalette.torp +107 -29
  10. package/dist/ColorPicker/ColorPicker.torp +121 -10
  11. package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
  12. package/dist/ColorPicker/ColorPickerArea.torp +175 -0
  13. package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
  14. package/dist/ColorPicker/ColorPickerHue.torp +59 -0
  15. package/dist/ColorPicker/ColorPickerInput.torp +7 -18
  16. package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
  17. package/dist/ColorPicker/index.d.ts +139 -14
  18. package/dist/ColorPicker/index.js +5 -1
  19. package/dist/ComboBox/ComboBox.torp +40 -5
  20. package/dist/ComboBox/index.d.ts +5 -2
  21. package/dist/ComboBox/index.js +1 -2
  22. package/dist/Contextual/Contextual.torp +25 -77
  23. package/dist/Contextual/ContextualContent.torp +10 -51
  24. package/dist/Contextual/ContextualHover.torp +13 -85
  25. package/dist/Contextual/ContextualTrigger.torp +9 -16
  26. package/dist/Contextual/ContextualTypes.ts +6 -12
  27. package/dist/Contextual/index.d.ts +10 -13
  28. package/dist/DataGrid/DataGrid.torp +21 -3
  29. package/dist/DataGrid/index.d.ts +1 -1
  30. package/dist/DatePicker/DatePicker.torp +6 -4
  31. package/dist/DateRangePicker/DateRangePicker.torp +14 -13
  32. package/dist/DateTimePicker/DateTimePicker.torp +264 -0
  33. package/dist/DateTimePicker/index.d.ts +46 -0
  34. package/dist/DateTimePicker/index.js +1 -0
  35. package/dist/Dialog/Dialog.torp +0 -1
  36. package/dist/Dialog/index.d.ts +0 -1
  37. package/dist/Drawer/Drawer.torp +5 -23
  38. package/dist/Drawer/DrawerContent.torp +1 -0
  39. package/dist/Drawer/DrawerOverlay.torp +9 -16
  40. package/dist/Drawer/DrawerTrigger.torp +9 -24
  41. package/dist/Drawer/DrawerTypes.ts +3 -1
  42. package/dist/Form/CheckBox.torp +10 -18
  43. package/dist/Form/File.torp +10 -18
  44. package/dist/Form/FileDrop.torp +16 -22
  45. package/dist/Form/Input.torp +14 -20
  46. package/dist/Form/Radio.torp +71 -0
  47. package/dist/Form/RadioGroup.torp +221 -0
  48. package/dist/Form/RadioGroupTypes.ts +40 -0
  49. package/dist/Form/Select.torp +10 -18
  50. package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
  51. package/dist/Form/TextArea.torp +10 -18
  52. package/dist/Form/ToggleButton.torp +94 -0
  53. package/dist/Form/ToggleGroup.torp +150 -0
  54. package/dist/Form/ToggleGroupTypes.ts +23 -0
  55. package/dist/Form/index.d.ts +173 -15
  56. package/dist/Form/index.js +6 -2
  57. package/dist/ListBox/ListBox.torp +27 -5
  58. package/dist/ListBox/ListBoxItem.torp +1 -1
  59. package/dist/ListBox/index.d.ts +6 -2
  60. package/dist/MaskedInput/MaskedInput.torp +1 -1
  61. package/dist/Menu/MenuPopoutTrigger.torp +1 -1
  62. package/dist/MenuBar/MenuBar.torp +5 -3
  63. package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
  64. package/dist/Meter/Meter.torp +126 -0
  65. package/dist/Meter/MeterIndicator.torp +41 -0
  66. package/dist/Meter/MeterTypes.ts +8 -0
  67. package/dist/Meter/index.d.ts +79 -0
  68. package/dist/Meter/index.js +3 -0
  69. package/dist/Modal/Modal.torp +4 -22
  70. package/dist/Modal/ModalOverlay.torp +9 -16
  71. package/dist/NavMenu/NavMenu.torp +5 -3
  72. package/dist/NumberInput/NumberInput.torp +1 -1
  73. package/dist/PinInput/PinInput.torp +220 -0
  74. package/dist/PinInput/index.d.ts +48 -0
  75. package/dist/PinInput/index.js +1 -0
  76. package/dist/Popover/Popover.torp +18 -24
  77. package/dist/Popover/PopoverContent.torp +8 -0
  78. package/dist/Popover/PopoverHover.torp +30 -3
  79. package/dist/Popover/PopoverTypes.ts +2 -0
  80. package/dist/Popover/index.d.ts +8 -1
  81. package/dist/Rating/Rating.torp +1 -1
  82. package/dist/SegmentedControl/SegmentedControl.torp +3 -3
  83. package/dist/SegmentedControl/SegmentedItem.torp +1 -1
  84. package/dist/SelectBox/SelectBox.torp +40 -5
  85. package/dist/SelectBox/index.d.ts +5 -2
  86. package/dist/SelectBox/index.js +1 -2
  87. package/dist/Slider/Slider.torp +1 -1
  88. package/dist/SortableList/SortableList.torp +132 -0
  89. package/dist/SortableList/SortableListItem.torp +117 -0
  90. package/dist/SortableList/SortableListTypes.ts +16 -0
  91. package/dist/SortableList/index.d.ts +81 -0
  92. package/dist/SortableList/index.js +3 -0
  93. package/dist/TabGroup/TabContent.torp +1 -1
  94. package/dist/TabGroup/TabGroup.torp +2 -2
  95. package/dist/TabGroup/TabHeader.torp +1 -1
  96. package/dist/TagInput/TagInput.torp +1 -1
  97. package/dist/TimePicker/TimePicker.torp +1 -1
  98. package/dist/ToolBar/ToolBar.torp +8 -4
  99. package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
  100. package/dist/Tooltip/Tooltip.torp +104 -0
  101. package/dist/Tooltip/TooltipContent.torp +81 -0
  102. package/dist/Tooltip/TooltipTrigger.torp +79 -0
  103. package/dist/Tooltip/TooltipTypes.ts +28 -0
  104. package/dist/Tooltip/index.d.ts +104 -0
  105. package/dist/Tooltip/index.js +4 -0
  106. package/dist/Tree/Tree.torp +1 -1
  107. package/dist/Tree/TreeItem.torp +1 -1
  108. package/dist/VirtualList/VirtualList.torp +149 -0
  109. package/dist/VirtualList/index.d.ts +46 -0
  110. package/dist/VirtualList/index.js +1 -0
  111. package/dist/dnd/index.d.ts +2 -0
  112. package/dist/dnd/index.js +212 -0
  113. package/dist/dnd/index.js.map +1 -0
  114. package/dist/loader/index.d.ts +2 -0
  115. package/dist/{loader-DEeG5vFY.js → loader/index.js} +10 -3
  116. package/dist/loader/index.js.map +1 -0
  117. package/dist/utils/PopoutClickTrigger.torp +1 -0
  118. package/dist/utils/PopoutOverlay.torp +39 -0
  119. package/dist/utils/PopoutTypes.ts +4 -0
  120. package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
  121. package/dist/utils/colorUtils.ts +260 -75
  122. package/dist/utils/formField.ts +4 -3
  123. package/dist/utils/handlePopoutButton.ts +43 -0
  124. package/dist/utils/loader.ts +20 -3
  125. package/package.json +41 -5
  126. package/dist/Charts/GridLines.torp +0 -65
  127. package/dist/Charts/XAxis.torp +0 -69
  128. package/dist/Charts/YAxis.torp +0 -49
  129. package/dist/loader-DEeG5vFY.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { parseHex } from "../utils/colorUtils";
3
+ import { type ColorPickerContext, ColorPickerContextName } from "./ColorPickerTypes";
4
+
5
+ interface ColorPickerEyedropperProps {
6
+ /** Classes for the button */
7
+ class?: ClassValue;
8
+ /** Styles for the button */
9
+ style?: StyleValue;
10
+ /** An accessible name for the button; falls back to the picker's ariaLabel */
11
+ ariaLabel?: string;
12
+ /** Text to display in the button (default: an eyedropper icon) */
13
+ children?: any;
14
+ }
15
+
16
+ interface EyeDropperResult {
17
+ sRGBHex: string;
18
+ }
19
+
20
+ interface EyeDropperInstance {
21
+ open: (options?: { signal?: AbortSignal }) => Promise<EyeDropperResult>;
22
+ }
23
+
24
+ type EyeDropperConstructor = new () => EyeDropperInstance;
25
+
26
+ /**
27
+ * A button that samples a color from anywhere on the screen with the
28
+ * browser's EyeDropper API. Rendered only when the browser supports it.
29
+ */
30
+ export default function ColorPickerEyedropper($props: ColorPickerEyedropperProps | undefined) {
31
+ // Get stuff out of the ColorPicker context
32
+ const context = $context[ColorPickerContextName] as ColorPickerContext;
33
+ if (!context) {
34
+ throw new Error("ColorPickerEyedropper must be contained within a ColorPicker");
35
+ }
36
+
37
+ function getEyeDropper(): EyeDropperConstructor | undefined {
38
+ if (typeof window === "undefined") return undefined;
39
+ return (window as any).EyeDropper as EyeDropperConstructor | undefined;
40
+ }
41
+
42
+ function label(): string {
43
+ const base = $props?.ariaLabel ?? context.getAriaLabel();
44
+ return base ? `${base} eyedropper` : "Pick a color from the screen";
45
+ }
46
+
47
+ async function handleClick() {
48
+ if (context.getDisabled()) return;
49
+ const EyeDropper = getEyeDropper();
50
+ if (!EyeDropper) return;
51
+ try {
52
+ const result = await new EyeDropper().open();
53
+ const color = parseHex(result.sRGBHex);
54
+ if (color) {
55
+ context.commitValue(color);
56
+ }
57
+ } catch {
58
+ // The user cancelled the eyedropper; nothing to change
59
+ }
60
+ }
61
+
62
+ @render {
63
+ @if (getEyeDropper()) {
64
+ <button
65
+ type="button"
66
+ class={["torp-color-picker-eyedropper", $props?.class]}
67
+ {$props?.style}
68
+ aria-label={label()}
69
+ aria-disabled={context.getDisabled() ? "true" : undefined}
70
+ disabled={context.getDisabled()}
71
+ onclick={handleClick}
72
+ >
73
+ <slot>💧</slot>
74
+ </button>
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,59 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { type ColorPickerContext, ColorPickerContextName } from "./ColorPickerTypes";
3
+
4
+ interface ColorPickerHueProps {
5
+ /** Classes for the slider */
6
+ class?: ClassValue;
7
+ /** Styles for the slider */
8
+ style?: StyleValue;
9
+ /** An accessible name for the slider; falls back to the picker's ariaLabel */
10
+ ariaLabel?: string;
11
+ }
12
+
13
+ /**
14
+ * A hue slider for a ColorPicker, from red through the spectrum and back.
15
+ */
16
+ export default function ColorPickerHue($props: ColorPickerHueProps | undefined) {
17
+ // Get stuff out of the ColorPicker context
18
+ const context = $context[ColorPickerContextName] as ColorPickerContext;
19
+ if (!context) {
20
+ throw new Error("ColorPickerHue must be contained within a ColorPicker");
21
+ }
22
+
23
+ function label(): string {
24
+ const base = $props?.ariaLabel ?? context.getAriaLabel();
25
+ return base ? `${base} hue` : "Hue";
26
+ }
27
+
28
+ function handleInput(e: Event) {
29
+ const hue = Number((e.currentTarget as HTMLInputElement).value);
30
+ if (!Number.isFinite(hue)) return;
31
+ const hsv = context.getHsv();
32
+ // A black or gray color has no usable saturation/brightness yet;
33
+ // moving the hue starts from a vivid color so the change is visible
34
+ context.commitHsv({
35
+ h: hue,
36
+ s: hsv.s || 1,
37
+ v: hsv.v || 1,
38
+ });
39
+ }
40
+
41
+ @render {
42
+ <input
43
+ type="range"
44
+ class={["torp-color-picker-hue", $props?.class]}
45
+ style={[
46
+ $props?.style,
47
+ "background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)",
48
+ ]}
49
+ min="0"
50
+ max="360"
51
+ step="1"
52
+ value={Math.round(context.getHsv().h)}
53
+ aria-label={label()}
54
+ aria-disabled={context.getDisabled() ? "true" : undefined}
55
+ disabled={context.getDisabled()}
56
+ oninput={handleInput}
57
+ />
58
+ }
59
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { parseHex } from "../utils/colorUtils";
2
+ import { parseColor } from "../utils/colorUtils";
3
3
  import { type ColorPickerContext, ColorPickerContextName } from "./ColorPickerTypes";
4
4
 
5
5
  interface ColorPickerInputProps {
@@ -16,9 +16,9 @@ interface ColorPickerInputProps {
16
16
  }
17
17
 
18
18
  /**
19
- * The hex text field of a ColorPicker, for entering arbitrary colors as
20
- * "#rrggbb". Values commit on blur or Enter, invalid text reverting like
21
- * NumberInput.
19
+ * The text field of a ColorPicker, for entering arbitrary colors as hex,
20
+ * `rgb()` or `hsl()`. Values commit on blur or Enter, invalid text
21
+ * reverting like NumberInput.
22
22
  */
23
23
  export default function ColorPickerInput($props: ColorPickerInputProps | undefined) {
24
24
  let hexInput: HTMLInputElement | undefined;
@@ -51,7 +51,7 @@ export default function ColorPickerInput($props: ColorPickerInputProps | undefin
51
51
 
52
52
  function commit() {
53
53
  $state.editing = false;
54
- const next = parseHex($state.text);
54
+ const next = parseColor($state.text);
55
55
  if ($state.text.trim() !== "" && !next) {
56
56
  // Not a color: revert to the last committed value
57
57
  $state.text = context.getValue() ?? "";
@@ -81,17 +81,8 @@ export default function ColorPickerInput($props: ColorPickerInputProps | undefin
81
81
  }
82
82
  }
83
83
 
84
- function handleChange() {
85
- commit();
86
- }
87
-
88
84
  // Keep the input's value in sync with the text; typing sets the
89
85
  // property directly, so an attribute alone would not update it
90
- function syncInput() {
91
- if (hexInput && !$state.editing && hexInput.value !== display()) {
92
- hexInput.value = display();
93
- }
94
- }
95
86
  $run(() => {
96
87
  const text = display();
97
88
  const editing = $state.editing;
@@ -99,7 +90,6 @@ export default function ColorPickerInput($props: ColorPickerInputProps | undefin
99
90
  hexInput.value = text;
100
91
  }
101
92
  });
102
- $onmount(() => syncInput());
103
93
 
104
94
  @render {
105
95
  <input
@@ -108,13 +98,12 @@ export default function ColorPickerInput($props: ColorPickerInputProps | undefin
108
98
  class={["torp-color-picker-input", $props?.class]}
109
99
  {$props?.style}
110
100
  spellcheck="false"
111
- placeholder="#rrggbb"
101
+ placeholder="#rrggbb, rgb() or hsl()"
112
102
  aria-label={label()}
113
103
  value={display()}
114
104
  disabled={getDisabled()}
115
105
  oninput={handleInput}
116
- onchange={handleChange}
117
- onblur={handleChange}
106
+ onblur={commit}
118
107
  onkeydown={handleKey}
119
108
  onmount={(el) => {
120
109
  hexInput = el;
@@ -1,3 +1,5 @@
1
+ import type { Hsv } from "../utils/colorUtils";
2
+
1
3
  export const ColorPickerContextName: unique symbol = Symbol.for("torp.ColorPicker");
2
4
 
3
5
  export interface ColorPickerContext {
@@ -7,6 +9,14 @@ export interface ColorPickerContext {
7
9
  getValue: () => string | undefined;
8
10
  /** An accessible name for the picker */
9
11
  getAriaLabel: () => string | undefined;
10
- /** Commits a hex input value, reporting it when it changes the value */
12
+ /** Commits a parsed color value, reporting it when it changes the value */
11
13
  commitValue: (value: string | undefined) => void;
14
+ /** The current color as hue/saturation/value */
15
+ getHsv: () => Hsv;
16
+ /** Commits a hue/saturation/value color, keeping the current alpha */
17
+ commitHsv: (hsv: Hsv, alpha?: number) => void;
18
+ /** The current alpha in [0..1] */
19
+ getAlpha: () => number;
20
+ /** Sets the current alpha, keeping the hue/saturation/value */
21
+ setAlpha: (alpha: number) => void;
12
22
  }
@@ -10,8 +10,19 @@ interface ColorPaletteProps {
10
10
  style?: StyleValue;
11
11
  /** The selected color as "#rrggbb"; undefined if nothing is selected */
12
12
  value?: Bindable<string | undefined>;
13
- /** The colors to offer (default: a built-in gray + hue palette) */
14
- colors?: string[];
13
+ /**
14
+ * The colors to offer (default: a built-in gray + hue palette). Each entry
15
+ * is either a hex string or `{ value, name }`; names are used as the
16
+ * swatches' accessible names instead of the raw hex.
17
+ */
18
+ colors?: Color[];
19
+ /** The number of swatches per row, for up/down arrow movement (default 6) */
20
+ columns?: number;
21
+ /**
22
+ * If true, selecting the swatch that is already selected clears the
23
+ * value. Off by default, like a radio group.
24
+ */
25
+ allowClear?: boolean;
15
26
  /** If set to true, the user cannot interact with this palette */
16
27
  disabled?: boolean;
17
28
  /** An accessible name for the palette */
@@ -24,8 +35,11 @@ interface ColorPaletteProps {
24
35
 
25
36
  /**
26
37
  * A grid of color swatches that behaves like a radio group: one swatch can
27
- * be selected, clicking it again deselects, and the arrow keys move through
28
- * the swatches selecting as they go.
38
+ * be selected, and the arrow keys move focus and selection through the
39
+ * swatches. Left/Right move by one swatch, Up/Down by one row.
40
+ *
41
+ * Set `allowClear` to let clicking (or pressing Space on) the selected swatch
42
+ * deselect it, like Rating.
29
43
  *
30
44
  * Use ColorPicker instead when arbitrary hex values should be enterable
31
45
  * alongside the palette.
@@ -49,13 +63,28 @@ interface ColorPickerProps {
49
63
  style?: StyleValue;
50
64
  /** The selected color as "#rrggbb"; undefined if nothing is selected */
51
65
  value?: Bindable<string | undefined>;
52
- /** The colors offered in the palette */
53
- colors?: string[];
54
66
  /**
55
- * If set to true, a text field for arbitrary hex values ("#ff8800") is
56
- * shown below the palette
67
+ * The colors offered in the palette. Each entry is either a hex string or
68
+ * `{ value, name }`; names are used as the swatches' accessible names.
69
+ */
70
+ colors?: Color[];
71
+ /** The number of swatches per row, for up/down arrow movement (default 6) */
72
+ columns?: number;
73
+ /** If true, selecting the already-selected swatch clears the value */
74
+ allowClear?: boolean;
75
+ /**
76
+ * If set to true, a text field for arbitrary color values ("#ff8800",
77
+ * "rgb(255 136 0)", "hsl(32 100% 50%)") is shown below the palette
57
78
  */
58
79
  showInput?: boolean;
80
+ /** If set to true, a 2D saturation/brightness area is shown above the palette */
81
+ showArea?: boolean;
82
+ /** If set to true, a hue slider is shown above the palette */
83
+ showHue?: boolean;
84
+ /** If set to true, an alpha slider is shown above the palette */
85
+ showAlpha?: boolean;
86
+ /** If set to true, an eyedropper button is shown when the browser supports it */
87
+ showEyedropper?: boolean;
59
88
  /** If set to true, the user cannot interact with this picker */
60
89
  disabled?: boolean;
61
90
  /** An accessible name for the picker */
@@ -67,8 +96,13 @@ interface ColorPickerProps {
67
96
  }
68
97
 
69
98
  /**
70
- * A color input: a ColorPalette with an optional hex text field, sharing a
71
- * single bound value.
99
+ * A color input: a ColorPalette with optional saturation/brightness, hue
100
+ * and alpha controls and a text field, sharing a single bound value.
101
+ * Enable `showArea`, `showHue`, `showAlpha` and `showEyedropper` for the
102
+ * full picker; by default it is just a swatch palette.
103
+ *
104
+ * Values are normalized hex colors, with an alpha channel when the color
105
+ * isn't fully opaque ("#ff8800", "#ff880080").
72
106
  *
73
107
  * ```
74
108
  * <ColorPicker name="accent" showInput &value={$state.accent} />
@@ -95,6 +129,97 @@ declare function ColorPicker(
95
129
 
96
130
 
97
131
 
132
+ interface ColorPickerAlphaProps {
133
+ /** Classes for the slider */
134
+ class?: ClassValue;
135
+ /** Styles for the slider */
136
+ style?: StyleValue;
137
+ /** An accessible name for the slider; falls back to the picker's ariaLabel */
138
+ ariaLabel?: string;
139
+ }
140
+
141
+ /**
142
+ * An alpha (opacity) slider for a ColorPicker.
143
+ */
144
+ declare function ColorPickerAlpha(
145
+ $parent: ParentNode,
146
+ $anchor: Node | null,
147
+ $props: ColorPickerAlphaProps | undefined,
148
+ $context?: Record<PropertyKey, any>,
149
+ $slots?: Record<string, SlotRender>,
150
+ ): void;
151
+
152
+
153
+
154
+ interface ColorPickerAreaProps {
155
+ /** Classes for the area */
156
+ class?: ClassValue;
157
+ /** Styles for the area */
158
+ style?: StyleValue;
159
+ }
160
+
161
+ /**
162
+ * A two-dimensional saturation/brightness area for a ColorPicker. Dragging
163
+ * or using the arrow keys selects a saturation (horizontal) and brightness
164
+ * (vertical) within the current hue.
165
+ */
166
+ declare function ColorPickerArea(
167
+ $parent: ParentNode,
168
+ $anchor: Node | null,
169
+ $props: ColorPickerAreaProps | undefined,
170
+ $context?: Record<PropertyKey, any>,
171
+ $slots?: Record<string, SlotRender>,
172
+ ): void;
173
+
174
+
175
+
176
+ interface ColorPickerEyedropperProps {
177
+ /** Classes for the button */
178
+ class?: ClassValue;
179
+ /** Styles for the button */
180
+ style?: StyleValue;
181
+ /** An accessible name for the button; falls back to the picker's ariaLabel */
182
+ ariaLabel?: string;
183
+ /** Text to display in the button (default: an eyedropper icon) */
184
+ children?: any;
185
+ }
186
+
187
+ /**
188
+ * A button that samples a color from anywhere on the screen with the
189
+ * browser's EyeDropper API. Rendered only when the browser supports it.
190
+ */
191
+ declare function ColorPickerEyedropper(
192
+ $parent: ParentNode,
193
+ $anchor: Node | null,
194
+ $props: ColorPickerEyedropperProps | undefined,
195
+ $context?: Record<PropertyKey, any>,
196
+ $slots?: Record<string, SlotRender>,
197
+ ): void;
198
+
199
+
200
+
201
+ interface ColorPickerHueProps {
202
+ /** Classes for the slider */
203
+ class?: ClassValue;
204
+ /** Styles for the slider */
205
+ style?: StyleValue;
206
+ /** An accessible name for the slider; falls back to the picker's ariaLabel */
207
+ ariaLabel?: string;
208
+ }
209
+
210
+ /**
211
+ * A hue slider for a ColorPicker, from red through the spectrum and back.
212
+ */
213
+ declare function ColorPickerHue(
214
+ $parent: ParentNode,
215
+ $anchor: Node | null,
216
+ $props: ColorPickerHueProps | undefined,
217
+ $context?: Record<PropertyKey, any>,
218
+ $slots?: Record<string, SlotRender>,
219
+ ): void;
220
+
221
+
222
+
98
223
  interface ColorPickerInputProps {
99
224
  /** An ID for the input element */
100
225
  id?: string;
@@ -109,9 +234,9 @@ interface ColorPickerInputProps {
109
234
  }
110
235
 
111
236
  /**
112
- * The hex text field of a ColorPicker, for entering arbitrary colors as
113
- * "#rrggbb". Values commit on blur or Enter, invalid text reverting like
114
- * NumberInput.
237
+ * The text field of a ColorPicker, for entering arbitrary colors as hex,
238
+ * `rgb()` or `hsl()`. Values commit on blur or Enter, invalid text
239
+ * reverting like NumberInput.
115
240
  */
116
241
  declare function ColorPickerInput(
117
242
  $parent: ParentNode,
@@ -121,4 +246,4 @@ declare function ColorPickerInput(
121
246
  $slots?: Record<string, SlotRender>,
122
247
  ): void;
123
248
 
124
- export { ColorPalette, ColorPicker, ColorPickerInput };
249
+ export { ColorPalette, ColorPicker, ColorPickerAlpha, ColorPickerArea, ColorPickerEyedropper, ColorPickerHue, ColorPickerInput };
@@ -1,4 +1,8 @@
1
1
  import ColorPalette from "./ColorPalette.torp";
2
+ import ColorPickerAlpha from "./ColorPickerAlpha.torp";
3
+ import ColorPickerArea from "./ColorPickerArea.torp";
4
+ import ColorPickerEyedropper from "./ColorPickerEyedropper.torp";
5
+ import ColorPickerHue from "./ColorPickerHue.torp";
2
6
  import ColorPicker from "./ColorPicker.torp";
3
7
  import ColorPickerInput from "./ColorPickerInput.torp";
4
- export { ColorPalette, ColorPicker, ColorPickerInput };
8
+ export { ColorPalette, ColorPicker, ColorPickerAlpha, ColorPickerArea, ColorPickerEyedropper, ColorPickerHue, ColorPickerInput };
@@ -21,8 +21,11 @@ interface ComboBoxProps {
21
21
  style?: StyleValue;
22
22
  /** The name of the input's form data field */
23
23
  name?: string;
24
- /** The data value selected by the user, or an array of values if multiple is set */
25
- value: Bindable<any>;
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
  /**
@@ -76,14 +79,20 @@ interface ComboBoxProps {
76
79
  */
77
80
  export default function ComboBox($props: ComboBoxProps | undefined) {
78
81
  // Wire up the enclosing Form and Field, if any
82
+ const fieldContext = $context[FieldContextName] as FieldContext | undefined;
79
83
  const form = createFormField(
80
- $props?.name,
84
+ () => $props?.name,
81
85
  $context[FormContextName] as FormContext | undefined,
82
- $context[FieldContextName] as FieldContext | undefined,
86
+ fieldContext,
83
87
  );
88
+
89
+ // The list inside is part of this input, not a separate field: hide the
90
+ // enclosing Field's context so it doesn't resolve the Field's name and
91
+ // submit its own copy of the value
92
+ $context[FieldContextName] = undefined;
84
93
  let $state: ComboBoxState = $watch({
85
94
  visible: false,
86
- value: $props?.value,
95
+ value: $props?.value ?? fieldContext?.state.value,
87
96
  contentId: undefined,
88
97
  triggerId: undefined,
89
98
  contentRole: undefined,
@@ -93,6 +102,32 @@ export default function ComboBox($props: ComboBoxProps | undefined) {
93
102
 
94
103
  $bind($state, $props, "visible", "value");
95
104
 
105
+ // Point the enclosing Field's Label at the trigger once it registers
106
+ $run(() => {
107
+ if (fieldContext && $state.triggerId) {
108
+ fieldContext.state.inputId = $state.triggerId;
109
+ }
110
+ });
111
+
112
+ // With no value prop, use the enclosing Field's value as the source and
113
+ // destination, so only the Field needs binding. The initial undefined is
114
+ // skipped so an empty Field doesn't clear a default.
115
+ let firstFromField = true;
116
+ $run(() => {
117
+ const value = fieldContext?.state.value;
118
+ const skip = firstFromField && value === undefined;
119
+ firstFromField = false;
120
+ if (!fieldContext || $props?.value !== undefined || skip) return;
121
+ if (value !== $state.value) {
122
+ $state.value = value;
123
+ }
124
+ });
125
+ $run(() => {
126
+ if ($props?.value === undefined && fieldContext) {
127
+ fieldContext.state.value = $state.value;
128
+ }
129
+ });
130
+
96
131
  if ($props?.load !== undefined && typeof $props.load !== "function") {
97
132
  throw new Error("ComboBox: `load` must be a function");
98
133
  }
@@ -10,8 +10,11 @@ interface ComboBoxProps {
10
10
  style?: StyleValue;
11
11
  /** The name of the input's form data field */
12
12
  name?: string;
13
- /** The data value selected by the user, or an array of values if multiple is set */
14
- value: Bindable<any>;
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
  /**
@@ -1,6 +1,5 @@
1
- import { n as normalizeLoadResult, t as createItemLoader } from "../loader-DEeG5vFY.js";
2
1
  import ComboBox from "./ComboBox.torp";
3
2
  import ComboBoxContent from "./ComboBoxContent.torp";
4
3
  import ComboBoxInput from "./ComboBoxInput.torp";
5
4
  import ComboBoxTrigger from "./ComboBoxTrigger.torp";
6
- export { ComboBox, ComboBoxContent, ComboBoxInput, ComboBoxTrigger, createItemLoader, normalizeLoadResult };
5
+ export { ComboBox, ComboBoxContent, ComboBoxInput, ComboBoxTrigger };
@@ -1,12 +1,6 @@
1
1
  import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
2
- import $handle from "../utils/$handle";
3
- import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
4
- import {
5
- type ContextualContext,
6
- ContextualContextName,
7
- type ContextualState,
8
- type Point,
9
- } from "./ContextualTypes";
2
+ import Popover from "../Popover/Popover.torp";
3
+ import type { Point } from "../Popover/PopoverTypes";
10
4
 
11
5
  interface ContextualProps {
12
6
  /** An ID for the root element */
@@ -15,13 +9,13 @@ interface ContextualProps {
15
9
  class?: ClassValue;
16
10
  /** Styles for the root element */
17
11
  style?: StyleValue;
18
- /** Whether the contextual is modal. If true, an overlay should be supplied to obscure outside content, and only the context content will be visible to screen readers */
12
+ /** Whether the contextual is modal */
19
13
  modal?: boolean;
20
- /** Whether the contextual is visible */
14
+ /** Whether the contextual is visible */
21
15
  visible: Bindable<boolean | undefined>;
22
- /** The element to anchor this contextual to, as an alternative to supplying a ContextualTrigger */
16
+ /** The element to anchor this contextual to, as an alternative to supplying a ContextualTrigger */
23
17
  anchor?: HTMLElement;
24
- /** The position to display this contextual at */
18
+ /** The position to display this contextual at */
25
19
  position?: Point;
26
20
  /** Raised when the contextual has opened */
27
21
  onopen?: () => void;
@@ -32,6 +26,9 @@ interface ContextualProps {
32
26
  /**
33
27
  * A contextual window that is shown to the user at the cursor's location.
34
28
  *
29
+ * Contextual is Popover in contextual mode: the same root, trigger and
30
+ * content machinery, positioned at a point instead of at a side.
31
+ *
35
32
  * The structure of a Contextual is:
36
33
  *
37
34
  * ```
@@ -42,75 +39,26 @@ interface ContextualProps {
42
39
  * ```
43
40
  */
44
41
  export default function Contextual($props: ContextualProps | undefined) {
45
- let $state: ContextualState = $watch({
46
- visible: false,
47
- position: { x: 0, y: 0 },
48
- contentId: undefined,
49
- triggerId: undefined,
50
- contentRole: undefined,
42
+ // Forward the visible binding through to the Popover
43
+ let $state = $watch({
44
+ visible: $props?.visible as boolean | undefined,
51
45
  });
52
-
53
46
  $bind($state, $props, "visible");
54
- $run(() => {
55
- $state.position = $props?.position ?? { x: 0, y: 0 };
56
- });
57
-
58
- let result: any;
59
-
60
- // Set the context to pass down to items
61
- let context: ContextualContext = {
62
- handleButton,
63
- handleClickOutside,
64
- state: $state,
65
- //modal: $props?.modal,
66
- anchorElement: $props?.anchor ? $unwrap($props.anchor) : undefined,
67
- };
68
- $context[ContextualContextName] = context;
69
-
70
- // Set the context to pass down to items
71
- let popoutContext: PopoutContext = context;
72
- $context[PopoutContextName] = popoutContext;
73
-
74
- // Dispatch the open/close events when the contextual is opened or closed
75
- $handle((first) => {
76
- const visible = $state.visible;
77
- if (first) return;
78
- if (visible) {
79
- $props?.onopen?.();
80
- } else {
81
- $props?.onclose?.(result);
82
- }
83
- });
84
-
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 contextual
103
- $state.visible = false;
104
- }
105
-
106
- function handleClickOutside(e: MouseEvent | KeyboardEvent) {
107
- e.preventDefault();
108
- $state.visible = false;
109
- }
110
47
 
111
48
  @render {
112
- <div {$props?.id} class={["torp-context", $props?.class]} {$props?.style}>
49
+ <Popover
50
+ {$props?.id}
51
+ class={$props?.class}
52
+ {$props?.style}
53
+ contextual
54
+ modal={$props?.modal}
55
+ &visible={$state.visible}
56
+ anchor={$props?.anchor}
57
+ position={$props?.position}
58
+ onopen={$props?.onopen}
59
+ onclose={$props?.onclose}
60
+ >
113
61
  <slot />
114
- </div>
62
+ </Popover>
115
63
  }
116
64
  }