meowtail 0.2.0-alpha.1 → 0.2.0-alpha.2
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 +24 -8
- package/dist/src/chat/assistant-composer.js +58 -98
- package/dist/src/chat/assistant-content.d.ts +1 -3
- package/dist/src/chat/assistant-content.js +36 -44
- package/dist/src/chat/assistant-markdown.js +4 -8
- package/dist/src/chat/assistant-question.js +13 -14
- package/dist/src/chat/assistant.js +27 -26
- package/dist/src/chat/attachments.d.ts +3 -2
- package/dist/src/chat/attachments.js +39 -34
- package/dist/src/chat/composer-panel.d.ts +2 -3
- package/dist/src/chat/composer-panel.js +3 -4
- package/dist/src/chat/composer.d.ts +5 -3
- package/dist/src/chat/composer.js +67 -21
- package/dist/src/chat/task.js +9 -15
- package/dist/src/chat/tool-call.js +1 -8
- package/dist/src/components/accordion.d.ts +24 -0
- package/dist/src/components/accordion.js +50 -0
- package/dist/src/components/avatar.d.ts +22 -0
- package/dist/src/components/avatar.js +44 -0
- package/dist/src/components/checkbox.d.ts +6 -2
- package/dist/src/components/checkbox.js +36 -8
- package/dist/src/components/choice-group.d.ts +1 -0
- package/dist/src/components/choice-group.js +12 -17
- package/dist/src/components/choice-select.d.ts +3 -1
- package/dist/src/components/choice-select.js +56 -54
- package/dist/src/components/code-block.d.ts +3 -3
- package/dist/src/components/code-block.js +27 -23
- package/dist/src/components/context-menu.d.ts +16 -0
- package/dist/src/components/context-menu.js +49 -0
- package/dist/src/components/disclosure.d.ts +2 -2
- package/dist/src/components/disclosure.js +1 -1
- package/dist/src/components/index.d.ts +9 -0
- package/dist/src/components/index.js +9 -0
- package/dist/src/components/link.d.ts +13 -0
- package/dist/src/components/link.js +9 -0
- package/dist/src/components/menu-button.d.ts +13 -0
- package/dist/src/components/menu-button.js +10 -0
- package/dist/src/components/menu.d.ts +4 -0
- package/dist/src/components/menu.js +3 -3
- package/dist/src/components/meta-row.d.ts +5 -4
- package/dist/src/components/meta-row.js +34 -18
- package/dist/src/components/nav-item.js +2 -5
- package/dist/src/components/number-input.d.ts +29 -0
- package/dist/src/components/number-input.js +137 -0
- package/dist/src/components/output-block.js +1 -8
- package/dist/src/components/path-picker.js +5 -10
- package/dist/src/components/pill.js +2 -5
- package/dist/src/components/popover.js +4 -4
- package/dist/src/components/progress.d.ts +15 -0
- package/dist/src/components/progress.js +12 -0
- package/dist/src/components/risk-confirmation.js +2 -5
- package/dist/src/components/segmented-control.js +3 -3
- package/dist/src/components/skeleton-boundary.js +4 -7
- package/dist/src/components/slider.d.ts +22 -0
- package/dist/src/components/slider.js +49 -0
- package/dist/src/components/table.d.ts +41 -0
- package/dist/src/components/table.js +146 -0
- package/dist/src/components/tabs.d.ts +1 -1
- package/dist/src/components/tabs.js +11 -20
- package/dist/src/components/text-shimmer.js +2 -5
- package/dist/src/registry/index.d.ts +62 -3
- package/dist/src/registry/index.js +18 -2
- package/dist/src/theme/chat/composer-panel.styles.js +4 -1
- package/dist/src/theme/chat/composer.styles.js +45 -67
- package/dist/src/theme/chat/task.styles.js +5 -6
- package/dist/src/theme/components/accordion.styles.d.ts +1 -0
- package/dist/src/theme/components/accordion.styles.js +63 -0
- package/dist/src/theme/components/avatar.styles.d.ts +1 -0
- package/dist/src/theme/components/avatar.styles.js +52 -0
- package/dist/src/theme/components/button.styles.js +9 -0
- package/dist/src/theme/components/card.styles.js +2 -0
- package/dist/src/theme/components/context-menu.styles.d.ts +1 -0
- package/dist/src/theme/components/context-menu.styles.js +14 -0
- package/dist/src/theme/components/link.styles.d.ts +1 -0
- package/dist/src/theme/components/link.styles.js +33 -0
- package/dist/src/theme/components/menu.styles.js +9 -3
- package/dist/src/theme/components/number-input.styles.d.ts +1 -0
- package/dist/src/theme/components/number-input.styles.js +106 -0
- package/dist/src/theme/components/progress.styles.d.ts +1 -0
- package/dist/src/theme/components/progress.styles.js +71 -0
- package/dist/src/theme/components/slider.styles.d.ts +1 -0
- package/dist/src/theme/components/slider.styles.js +129 -0
- package/dist/src/theme/components/table.styles.d.ts +1 -0
- package/dist/src/theme/components/table.styles.js +156 -0
- package/dist/src/theme/components/toggle.styles.js +10 -0
- package/dist/src/theme/index.d.ts +1 -1
- package/dist/src/theme/index.js +16 -0
- package/package.json +3 -3
|
@@ -6,13 +6,17 @@ export declare const checkboxContract: {
|
|
|
6
6
|
interface NativeToggleProps extends Props {
|
|
7
7
|
checked?: MaybeSignal<boolean>;
|
|
8
8
|
defaultChecked?: boolean;
|
|
9
|
+
/** Native indeterminate property. Assistive technology reads `aria-checked="mixed"`. */
|
|
10
|
+
indeterminate?: MaybeSignal<boolean>;
|
|
9
11
|
onChange?: (event: Event) => void;
|
|
10
12
|
}
|
|
11
13
|
export interface CheckboxProps extends NativeToggleProps {
|
|
12
|
-
label: string
|
|
14
|
+
label: MaybeSignal<string>;
|
|
15
|
+
/** Keep the accessible name while hiding the visible label, for compact tables. */
|
|
16
|
+
labelHidden?: boolean;
|
|
13
17
|
className?: string;
|
|
14
18
|
}
|
|
15
19
|
/** Native state owns uncontrolled toggles; controlled callers retain the final say. */
|
|
16
|
-
export declare function nativeToggleBindings({ checked, defaultChecked, onChange, ref, ...props }: NativeToggleProps): Props;
|
|
20
|
+
export declare function nativeToggleBindings({ checked, defaultChecked, indeterminate, onChange, ref, ...props }: NativeToggleProps): Props;
|
|
17
21
|
export declare const Checkbox: import("meowjsx").Component<CheckboxProps, "checkbox", "input" | "label" | "root">;
|
|
18
22
|
export {};
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import { defineComponent, unwrap, } from "meowjsx";
|
|
1
|
+
import { defineComponent, isSignal, mapSignal, unwrap, } from "meowjsx";
|
|
2
2
|
export const checkboxContract = {
|
|
3
3
|
name: "checkbox",
|
|
4
4
|
parts: ["root", "input", "label"],
|
|
5
5
|
};
|
|
6
|
+
function mixedValue(indeterminate) {
|
|
7
|
+
return Boolean(indeterminate !== undefined && unwrap(indeterminate));
|
|
8
|
+
}
|
|
6
9
|
/** Native state owns uncontrolled toggles; controlled callers retain the final say. */
|
|
7
|
-
export function nativeToggleBindings({ checked, defaultChecked = false, onChange, ref, ...props }) {
|
|
10
|
+
export function nativeToggleBindings({ checked, defaultChecked = false, indeterminate, onChange, ref, ...props }) {
|
|
11
|
+
const mixedAttr = indeterminate === undefined
|
|
12
|
+
? undefined
|
|
13
|
+
: isSignal(indeterminate)
|
|
14
|
+
? mapSignal(indeterminate, (value) => (value ? "mixed" : undefined))
|
|
15
|
+
: unwrap(indeterminate)
|
|
16
|
+
? "mixed"
|
|
17
|
+
: undefined;
|
|
18
|
+
const apply = (input) => {
|
|
19
|
+
input.defaultChecked = defaultChecked;
|
|
20
|
+
input.checked = checked === undefined ? defaultChecked : unwrap(checked);
|
|
21
|
+
input.indeterminate = mixedValue(indeterminate);
|
|
22
|
+
};
|
|
8
23
|
return {
|
|
9
24
|
...props,
|
|
10
25
|
type: "checkbox",
|
|
11
|
-
checked: checked
|
|
26
|
+
checked: checked !== undefined ? checked : defaultChecked,
|
|
27
|
+
"aria-checked": mixedAttr,
|
|
12
28
|
ref: (input) => {
|
|
13
|
-
input
|
|
14
|
-
input.checked = checked === undefined ? defaultChecked : unwrap(checked);
|
|
29
|
+
apply(input);
|
|
15
30
|
const cleanup = typeof ref === "function" ? ref(input) : undefined;
|
|
16
31
|
let disposed = false;
|
|
17
32
|
let timer;
|
|
@@ -21,14 +36,24 @@ export function nativeToggleBindings({ checked, defaultChecked = false, onChange
|
|
|
21
36
|
clearTimeout(timer);
|
|
22
37
|
timer = setTimeout(() => {
|
|
23
38
|
if (!disposed && !event.defaultPrevented)
|
|
24
|
-
input
|
|
39
|
+
apply(input);
|
|
25
40
|
}, 0);
|
|
26
41
|
};
|
|
42
|
+
const refresh = () => {
|
|
43
|
+
if (!disposed)
|
|
44
|
+
apply(input);
|
|
45
|
+
};
|
|
46
|
+
const unsubIndeterminate = isSignal(indeterminate)
|
|
47
|
+
? indeterminate.subscribe(refresh)
|
|
48
|
+
: undefined;
|
|
49
|
+
const unsubChecked = isSignal(checked) ? checked.subscribe(refresh) : undefined;
|
|
27
50
|
// The native form owner may change through the form attribute after mount.
|
|
28
51
|
input.ownerDocument.addEventListener("reset", reset, true);
|
|
29
52
|
return () => {
|
|
30
53
|
disposed = true;
|
|
31
54
|
clearTimeout(timer);
|
|
55
|
+
unsubIndeterminate?.();
|
|
56
|
+
unsubChecked?.();
|
|
32
57
|
input.ownerDocument.removeEventListener("reset", reset, true);
|
|
33
58
|
if (typeof cleanup === "function")
|
|
34
59
|
cleanup();
|
|
@@ -36,9 +61,12 @@ export function nativeToggleBindings({ checked, defaultChecked = false, onChange
|
|
|
36
61
|
},
|
|
37
62
|
onChange: (event) => {
|
|
38
63
|
onChange?.(event);
|
|
64
|
+
const input = event.currentTarget;
|
|
39
65
|
if (checked !== undefined)
|
|
40
|
-
|
|
66
|
+
input.checked = unwrap(checked);
|
|
67
|
+
if (indeterminate !== undefined)
|
|
68
|
+
input.indeterminate = unwrap(indeterminate);
|
|
41
69
|
},
|
|
42
70
|
};
|
|
43
71
|
}
|
|
44
|
-
export const Checkbox = defineComponent(checkboxContract, ({ label, className, ...props }, context) => context.part("root", "label", { className }, context.part("input", "input", nativeToggleBindings(props)), context.part("label", "span",
|
|
72
|
+
export const Checkbox = defineComponent(checkboxContract, ({ label, labelHidden, className, ...props }, context) => context.part("root", "label", { className, "data-label-hidden": labelHidden ? "true" : undefined }, context.part("input", "input", nativeToggleBindings(props)), context.part("label", "span", { "data-label-hidden": labelHidden ? "true" : undefined }, label)));
|
|
@@ -10,6 +10,7 @@ export declare const choiceGroupContract: {
|
|
|
10
10
|
readonly parts: readonly ["root", "legend", "options", "option", "input", "content", "label", "description"];
|
|
11
11
|
};
|
|
12
12
|
export interface ChoiceGroupProps extends Props {
|
|
13
|
+
/** Options are fixed for the mount. */
|
|
13
14
|
options: readonly ChoiceGroupOption[];
|
|
14
15
|
label: string;
|
|
15
16
|
hideLabel?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, unwrap, } from "meowjsx";
|
|
1
|
+
import { defineComponent, derived, unwrap, } from "meowjsx";
|
|
2
2
|
export const choiceGroupContract = {
|
|
3
3
|
name: "choice-group",
|
|
4
4
|
parts: ["root", "legend", "options", "option", "input", "content", "label", "description"],
|
|
@@ -6,18 +6,17 @@ export const choiceGroupContract = {
|
|
|
6
6
|
let nextChoiceGroupId = 0;
|
|
7
7
|
/** Visible single choices with native radio keyboard, validation and form semantics. */
|
|
8
8
|
export const ChoiceGroup = defineComponent(choiceGroupContract, ({ options, label, hideLabel = false, id = `choice-group-${++nextChoiceGroupId}`, name = id, form, value, defaultValue = "", onValueChange, disabled = false, required = false, className, ...props }, context) => {
|
|
9
|
-
const
|
|
9
|
+
const local = context.signal(defaultValue);
|
|
10
|
+
const current = value !== undefined ? value : local;
|
|
11
|
+
const readValue = () => unwrap(current);
|
|
10
12
|
const inputs = new Map();
|
|
11
13
|
let disposed = false;
|
|
14
|
+
// A rejected change and form reset flip the native radio before the owner signal does.
|
|
12
15
|
const reconcile = () => {
|
|
16
|
+
const selected = readValue();
|
|
13
17
|
for (const [optionValue, input] of inputs)
|
|
14
|
-
input.checked = selected
|
|
18
|
+
input.checked = selected === optionValue;
|
|
15
19
|
};
|
|
16
|
-
context.effect(() => {
|
|
17
|
-
if (value !== undefined)
|
|
18
|
-
selected.value = unwrap(value);
|
|
19
|
-
reconcile();
|
|
20
|
-
});
|
|
21
20
|
context.onCleanup(() => {
|
|
22
21
|
disposed = true;
|
|
23
22
|
});
|
|
@@ -34,7 +33,8 @@ export const ChoiceGroup = defineComponent(choiceGroupContract, ({ options, labe
|
|
|
34
33
|
timer = setTimeout(() => {
|
|
35
34
|
if (disposed || event.defaultPrevented)
|
|
36
35
|
return;
|
|
37
|
-
|
|
36
|
+
if (value === undefined)
|
|
37
|
+
local.value = defaultValue;
|
|
38
38
|
reconcile();
|
|
39
39
|
}, 0);
|
|
40
40
|
};
|
|
@@ -46,10 +46,7 @@ export const ChoiceGroup = defineComponent(choiceGroupContract, ({ options, labe
|
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
return context.part("root", "fieldset", { ...props, id, form, disabled, className, ref: rootRef }, context.part("legend", "legend", { "data-hidden": hideLabel ? "true" : undefined }, label), context.part("options", "div", null, ...options.map((option, index) => {
|
|
49
|
-
const checked =
|
|
50
|
-
context.effect(() => {
|
|
51
|
-
checked.value = selected.value === option.value;
|
|
52
|
-
});
|
|
49
|
+
const checked = derived(() => readValue() === option.value);
|
|
53
50
|
const descriptionId = option.description ? `${id}-description-${index}` : undefined;
|
|
54
51
|
return context.part("option", "label", null, context.part("input", "input", {
|
|
55
52
|
type: "radio",
|
|
@@ -63,19 +60,17 @@ export const ChoiceGroup = defineComponent(choiceGroupContract, ({ options, labe
|
|
|
63
60
|
ref: (input) => {
|
|
64
61
|
inputs.set(option.value, input);
|
|
65
62
|
input.defaultChecked = defaultValue === option.value;
|
|
66
|
-
input.checked =
|
|
63
|
+
input.checked = readValue() === option.value;
|
|
67
64
|
},
|
|
68
65
|
onChange: (event) => {
|
|
69
66
|
const input = event.currentTarget;
|
|
70
67
|
if (disabled || option.disabled || !input.checked)
|
|
71
68
|
return;
|
|
72
69
|
if (value === undefined)
|
|
73
|
-
|
|
70
|
+
local.value = option.value;
|
|
74
71
|
onValueChange?.(option.value);
|
|
75
72
|
// Native selection happens before change. Controlled callers retain
|
|
76
73
|
// ownership even when they reject the proposed value.
|
|
77
|
-
if (value !== undefined)
|
|
78
|
-
selected.value = unwrap(value);
|
|
79
74
|
reconcile();
|
|
80
75
|
},
|
|
81
76
|
}), context.part("content", "span", null, context.part("label", "span", null, option.label), option.description
|
|
@@ -10,7 +10,9 @@ export declare const choiceSelectContract: {
|
|
|
10
10
|
readonly parts: readonly ["root", "trigger", "value", "indicator", "list", "group", "option", "native", "validation", "search", "empty"];
|
|
11
11
|
};
|
|
12
12
|
export interface ChoiceSelectProps extends Props {
|
|
13
|
-
|
|
13
|
+
/** Plain arrays are fixed for the mount. A signal keeps the open list mounted. */
|
|
14
|
+
options: MaybeSignal<readonly ChoiceOption[]>;
|
|
15
|
+
hidden?: MaybeSignal<boolean>;
|
|
14
16
|
value?: MaybeSignal<string>;
|
|
15
17
|
defaultValue?: string;
|
|
16
18
|
onValueChange?: (value: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, unwrap, } from "meowjsx";
|
|
1
|
+
import { defineComponent, derived, h, keyed, unwrap, } from "meowjsx";
|
|
2
2
|
import { Popover } from "./popover.js";
|
|
3
3
|
import { Icon } from "../icons/icon.js";
|
|
4
4
|
import { elementByIdInRoot } from "../shared/dom-root.js";
|
|
@@ -20,14 +20,15 @@ export const choiceSelectContract = {
|
|
|
20
20
|
};
|
|
21
21
|
let nextChoiceId = 0;
|
|
22
22
|
/** Single-choice listbox. Form participation remains native; data fetching belongs to callers. */
|
|
23
|
-
export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, value, defaultValue = "", onValueChange, name, id = `choice-${++nextChoiceId}`, disabled = false, required = false, placeholder = "Select an option", searchable = false, searchPlaceholder = "Search options", emptyMessage = "No matching options", className, placement = "bottom", align = "start", matchTriggerWidth = true, ...props }, context) => {
|
|
24
|
-
const
|
|
23
|
+
export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, hidden, value, defaultValue = "", onValueChange, name, id = `choice-${++nextChoiceId}`, disabled = false, required = false, placeholder = "Select an option", searchable = false, searchPlaceholder = "Search options", emptyMessage = "No matching options", className, placement = "bottom", align = "start", matchTriggerWidth = true, ...props }, context) => {
|
|
24
|
+
const local = context.signal(defaultValue);
|
|
25
|
+
const current = value !== undefined ? value : local;
|
|
26
|
+
const readValue = () => unwrap(current);
|
|
27
|
+
const readOptions = () => unwrap(options);
|
|
25
28
|
const open = context.signal(false);
|
|
26
|
-
const caption = context.signal(placeholder);
|
|
27
29
|
const invalid = context.signal(undefined);
|
|
28
30
|
const validation = context.signal("");
|
|
29
31
|
const query = context.signal("");
|
|
30
|
-
const hasResults = context.signal(true);
|
|
31
32
|
let searchElement = null;
|
|
32
33
|
let triggerElement = null;
|
|
33
34
|
let nativeElement = null;
|
|
@@ -38,20 +39,11 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
38
39
|
const matches = (option) => `${option.label} ${option.value}`
|
|
39
40
|
.toLocaleLowerCase()
|
|
40
41
|
.includes(query.value.trim().toLocaleLowerCase());
|
|
41
|
-
const
|
|
42
|
+
const hasResults = derived(() => readOptions().some(matches));
|
|
43
|
+
const caption = derived(() => readOptions().find((option) => option.value === readValue())?.label ?? placeholder);
|
|
44
|
+
const enabledOptions = () => readOptions()
|
|
42
45
|
.map((option, index) => (option.disabled || !matches(option) ? -1 : index))
|
|
43
46
|
.filter((index) => index >= 0);
|
|
44
|
-
context.effect(() => {
|
|
45
|
-
hasResults.value = options.some(matches);
|
|
46
|
-
});
|
|
47
|
-
context.effect(() => {
|
|
48
|
-
if (value !== undefined)
|
|
49
|
-
selected.value = unwrap(value);
|
|
50
|
-
});
|
|
51
|
-
context.effect(() => {
|
|
52
|
-
caption.value =
|
|
53
|
-
options.find((option) => option.value === selected.value)?.label ?? placeholder;
|
|
54
|
-
});
|
|
55
47
|
const trigger = () => triggerElement;
|
|
56
48
|
const panel = () => (triggerElement ? elementByIdInRoot(triggerElement, panelId) : null);
|
|
57
49
|
const focusOption = (index) => {
|
|
@@ -63,7 +55,7 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
63
55
|
};
|
|
64
56
|
const initialIndex = (last = false) => {
|
|
65
57
|
const enabled = enabledOptions();
|
|
66
|
-
const index =
|
|
58
|
+
const index = readOptions().findIndex((option) => option.value === readValue() && !option.disabled);
|
|
67
59
|
return index >= 0 ? index : (enabled[last ? enabled.length - 1 : 0] ?? -1);
|
|
68
60
|
};
|
|
69
61
|
const close = (restore = true) => {
|
|
@@ -73,16 +65,16 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
73
65
|
trigger()?.focus();
|
|
74
66
|
};
|
|
75
67
|
const choose = (index) => {
|
|
76
|
-
const option =
|
|
68
|
+
const option = readOptions()[index];
|
|
77
69
|
if (disabled || !option || option.disabled)
|
|
78
70
|
return;
|
|
79
71
|
if (value === undefined)
|
|
80
|
-
|
|
72
|
+
local.value = option.value;
|
|
81
73
|
invalid.value = undefined;
|
|
82
74
|
validation.value = "";
|
|
83
75
|
onValueChange?.(option.value);
|
|
84
76
|
if (nativeElement)
|
|
85
|
-
nativeElement.value =
|
|
77
|
+
nativeElement.value = readValue();
|
|
86
78
|
close();
|
|
87
79
|
};
|
|
88
80
|
const search = (key, active) => {
|
|
@@ -94,7 +86,7 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
94
86
|
const start = enabled.indexOf(active);
|
|
95
87
|
for (let step = 1; step <= enabled.length; step++) {
|
|
96
88
|
const index = enabled[(start + step) % enabled.length];
|
|
97
|
-
if (
|
|
89
|
+
if (readOptions()[index].label.toLocaleLowerCase().startsWith(query.toLocaleLowerCase())) {
|
|
98
90
|
focusOption(index);
|
|
99
91
|
break;
|
|
100
92
|
}
|
|
@@ -198,7 +190,7 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
198
190
|
// Native reset restores defaultSelected, not the live value property.
|
|
199
191
|
for (const option of native.options)
|
|
200
192
|
option.defaultSelected = option.value === defaultValue;
|
|
201
|
-
native.value =
|
|
193
|
+
native.value = readValue();
|
|
202
194
|
const form = native?.form;
|
|
203
195
|
if (!form)
|
|
204
196
|
return;
|
|
@@ -211,8 +203,8 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
211
203
|
if (disposed || event.defaultPrevented)
|
|
212
204
|
return;
|
|
213
205
|
if (value === undefined)
|
|
214
|
-
|
|
215
|
-
native.value =
|
|
206
|
+
local.value = defaultValue;
|
|
207
|
+
native.value = readValue();
|
|
216
208
|
invalid.value = undefined;
|
|
217
209
|
validation.value = "";
|
|
218
210
|
open.value = false;
|
|
@@ -228,7 +220,17 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
228
220
|
context.onCleanup(() => {
|
|
229
221
|
disposed = true;
|
|
230
222
|
});
|
|
231
|
-
|
|
223
|
+
const rows = derived(() => {
|
|
224
|
+
const items = readOptions();
|
|
225
|
+
const next = [];
|
|
226
|
+
items.forEach((option, index) => {
|
|
227
|
+
if (option.group && option.group !== items[index - 1]?.group)
|
|
228
|
+
next.push({ kind: "group", key: `group:${option.group}:${index}`, label: option.group });
|
|
229
|
+
next.push({ kind: "option", key: `option:${option.value}`, option, index });
|
|
230
|
+
});
|
|
231
|
+
return next;
|
|
232
|
+
});
|
|
233
|
+
return context.part("root", "div", { className, hidden }, h(Popover, {
|
|
232
234
|
id: `${id}-panel`,
|
|
233
235
|
triggerId: id,
|
|
234
236
|
open,
|
|
@@ -295,34 +297,30 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
295
297
|
id: `${id}-list`,
|
|
296
298
|
role: searchable ? "listbox" : undefined,
|
|
297
299
|
"aria-labelledby": searchable ? id : undefined,
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
300
|
+
}, keyed(rows, (row) => row.key, (row) => {
|
|
301
|
+
if (row.value.kind === "group") {
|
|
302
|
+
return context.part("group", "div", {
|
|
303
|
+
role: "presentation",
|
|
304
|
+
hidden: derived(() => {
|
|
305
|
+
const label = row.value.kind === "group" ? row.value.label : "";
|
|
306
|
+
return !readOptions().some((candidate) => candidate.group === label && matches(candidate));
|
|
307
|
+
}),
|
|
308
|
+
}, derived(() => (row.value.kind === "group" ? row.value.label : "")));
|
|
309
|
+
}
|
|
310
|
+
return context.part("option", "button", {
|
|
306
311
|
type: "button",
|
|
307
312
|
role: "option",
|
|
308
313
|
tabIndex: -1,
|
|
309
|
-
disabled: option.disabled,
|
|
310
|
-
hidden,
|
|
311
|
-
"aria-disabled": option.disabled ? "true" : undefined,
|
|
312
|
-
"aria-selected":
|
|
313
|
-
"data-choice-index": index,
|
|
314
|
-
onClick: () =>
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
});
|
|
320
|
-
return option.group && option.group !== options[index - 1]?.group
|
|
321
|
-
? [
|
|
322
|
-
context.part("group", "div", { role: "presentation", hidden: groupHidden }, option.group),
|
|
323
|
-
item,
|
|
324
|
-
]
|
|
325
|
-
: [item];
|
|
314
|
+
disabled: derived(() => row.value.kind === "option" && Boolean(row.value.option.disabled)),
|
|
315
|
+
hidden: derived(() => row.value.kind === "option" ? !matches(row.value.option) : true),
|
|
316
|
+
"aria-disabled": derived(() => row.value.kind === "option" && row.value.option.disabled ? "true" : undefined),
|
|
317
|
+
"aria-selected": derived(() => String(row.value.kind === "option" && readValue() === row.value.option.value)),
|
|
318
|
+
"data-choice-index": derived(() => row.value.kind === "option" ? row.value.index : -1),
|
|
319
|
+
onClick: () => {
|
|
320
|
+
if (row.value.kind === "option")
|
|
321
|
+
choose(row.value.index);
|
|
322
|
+
},
|
|
323
|
+
}, derived(() => (row.value.kind === "option" ? row.value.option.label : "")));
|
|
326
324
|
})),
|
|
327
325
|
searchable
|
|
328
326
|
? context.part("empty", "p", { hidden: hasResults, role: "status" }, emptyMessage)
|
|
@@ -332,7 +330,7 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
332
330
|
id: `${id}-native`,
|
|
333
331
|
name,
|
|
334
332
|
form: props.form,
|
|
335
|
-
value:
|
|
333
|
+
value: derived(() => readValue()),
|
|
336
334
|
required,
|
|
337
335
|
disabled,
|
|
338
336
|
tabIndex: -1,
|
|
@@ -341,7 +339,7 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
341
339
|
"aria-labelledby": id,
|
|
342
340
|
onChange: (event) => {
|
|
343
341
|
const next = event.currentTarget.value;
|
|
344
|
-
choose(
|
|
342
|
+
choose(readOptions().findIndex((option) => option.value === next));
|
|
345
343
|
},
|
|
346
344
|
onInvalid: (event) => {
|
|
347
345
|
event.preventDefault();
|
|
@@ -349,5 +347,9 @@ export const ChoiceSelect = defineComponent(choiceSelectContract, ({ options, va
|
|
|
349
347
|
validation.value = event.currentTarget.validationMessage;
|
|
350
348
|
trigger()?.focus();
|
|
351
349
|
},
|
|
352
|
-
}, h("option", { value: "" }, placeholder),
|
|
350
|
+
}, h("option", { value: "" }, placeholder), keyed(derived(() => readOptions()), (option) => option.value, (option) => h("option", {
|
|
351
|
+
value: derived(() => option.value.value),
|
|
352
|
+
disabled: derived(() => Boolean(option.value.disabled)),
|
|
353
|
+
defaultSelected: option.value.value === defaultValue,
|
|
354
|
+
}, derived(() => option.value.label)))), context.part("validation", "span", { id: `${id}-validation`, role: "alert" }, validation));
|
|
353
355
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Props } from "meowjsx";
|
|
1
|
+
import { type MaybeSignal, type Props } from "meowjsx";
|
|
2
2
|
export declare const codeBlockContract: {
|
|
3
3
|
readonly name: "code-block";
|
|
4
4
|
readonly parts: readonly ["root", "header", "language", "actions", "content", "code", "feedback"];
|
|
5
5
|
};
|
|
6
6
|
export interface CodeBlockProps extends Props {
|
|
7
|
-
code: string
|
|
8
|
-
language?: string
|
|
7
|
+
code: MaybeSignal<string>;
|
|
8
|
+
language?: MaybeSignal<string | undefined>;
|
|
9
9
|
defaultWrap?: boolean;
|
|
10
10
|
/** Hosts may supply a clipboard implementation; the default uses the browser clipboard. */
|
|
11
11
|
onCopy?: (code: string) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h } from "meowjsx";
|
|
1
|
+
import { defineComponent, derived, h, unwrap, } from "meowjsx";
|
|
2
2
|
import { Button } from "./button.js";
|
|
3
3
|
import { copyTextToClipboard } from "../clipboard.js";
|
|
4
4
|
import { highlightCode } from "../syntax-highlight.js";
|
|
@@ -11,21 +11,42 @@ export const CodeBlock = defineComponent(codeBlockContract, ({ code, language, d
|
|
|
11
11
|
const wrap = context.signal(defaultWrap ? "true" : "false");
|
|
12
12
|
const copying = context.signal(false);
|
|
13
13
|
const feedback = context.signal("");
|
|
14
|
-
const highlighted = context.signal(code);
|
|
14
|
+
const highlighted = context.signal(unwrap(code));
|
|
15
|
+
const languageLabel = derived(() => unwrap(language)?.trim() || "Code");
|
|
15
16
|
let disposed = false;
|
|
16
17
|
context.onCleanup(() => {
|
|
17
18
|
disposed = true;
|
|
18
19
|
});
|
|
20
|
+
context.effect(() => {
|
|
21
|
+
const currentCode = unwrap(code);
|
|
22
|
+
const currentLanguage = unwrap(language);
|
|
23
|
+
highlighted.value = currentCode;
|
|
24
|
+
let active = true;
|
|
25
|
+
void highlightCode(currentCode, currentLanguage).then((spans) => {
|
|
26
|
+
if (!active || disposed || !spans)
|
|
27
|
+
return;
|
|
28
|
+
highlighted.value = spans.map((span) => (h("span", { style: {
|
|
29
|
+
color: span.color,
|
|
30
|
+
fontStyle: (span.fontStyle ?? 0) & 1 ? "italic" : undefined,
|
|
31
|
+
fontWeight: (span.fontStyle ?? 0) & 2 ? "bold" : undefined,
|
|
32
|
+
textDecoration: (span.fontStyle ?? 0) & 4 ? "underline" : undefined,
|
|
33
|
+
} }, span.text)));
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
active = false;
|
|
37
|
+
};
|
|
38
|
+
});
|
|
19
39
|
const copy = async () => {
|
|
20
40
|
if (copying.value)
|
|
21
41
|
return;
|
|
22
42
|
copying.value = true;
|
|
23
43
|
feedback.value = "";
|
|
44
|
+
const text = unwrap(code);
|
|
24
45
|
try {
|
|
25
46
|
if (onCopy)
|
|
26
|
-
await onCopy(
|
|
47
|
+
await onCopy(text);
|
|
27
48
|
else
|
|
28
|
-
await copyTextToClipboard(
|
|
49
|
+
await copyTextToClipboard(text);
|
|
29
50
|
if (!disposed)
|
|
30
51
|
feedback.value = "Copied";
|
|
31
52
|
}
|
|
@@ -40,7 +61,7 @@ export const CodeBlock = defineComponent(codeBlockContract, ({ code, language, d
|
|
|
40
61
|
};
|
|
41
62
|
return context.part("root", "figure", props, [
|
|
42
63
|
context.part("header", "figcaption", {}, [
|
|
43
|
-
context.part("language", "span", {},
|
|
64
|
+
context.part("language", "span", {}, languageLabel),
|
|
44
65
|
context.part("actions", "div", {}, [
|
|
45
66
|
h(Button, { variant: "quiet", size: "small", "aria-pressed": wrap, onClick: () => {
|
|
46
67
|
wrap.value = wrap.value === "true" ? "false" : "true";
|
|
@@ -48,24 +69,7 @@ export const CodeBlock = defineComponent(codeBlockContract, ({ code, language, d
|
|
|
48
69
|
h(Button, { variant: "quiet", size: "small", disabled: copying, onClick: copy }, "Copy code"),
|
|
49
70
|
]),
|
|
50
71
|
]),
|
|
51
|
-
context.part("content", "pre", { tabIndex: 0, "aria-label": "Code content", "data-wrap": wrap }, context.part("code", "code",
|
|
52
|
-
ref: () => {
|
|
53
|
-
let active = true;
|
|
54
|
-
void highlightCode(code, language).then((spans) => {
|
|
55
|
-
if (!active || disposed || !spans)
|
|
56
|
-
return;
|
|
57
|
-
highlighted.value = spans.map((span) => (h("span", { style: {
|
|
58
|
-
color: span.color,
|
|
59
|
-
fontStyle: (span.fontStyle ?? 0) & 1 ? "italic" : undefined,
|
|
60
|
-
fontWeight: (span.fontStyle ?? 0) & 2 ? "bold" : undefined,
|
|
61
|
-
textDecoration: (span.fontStyle ?? 0) & 4 ? "underline" : undefined,
|
|
62
|
-
} }, span.text)));
|
|
63
|
-
});
|
|
64
|
-
return () => {
|
|
65
|
-
active = false;
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
}, highlighted)),
|
|
72
|
+
context.part("content", "pre", { tabIndex: 0, "aria-label": "Code content", "data-wrap": wrap }, context.part("code", "code", null, highlighted)),
|
|
69
73
|
context.part("feedback", "span", { role: "status", "aria-live": "polite" }, feedback),
|
|
70
74
|
]);
|
|
71
75
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Child, type MaybeSignal, type Props } from "meowjsx";
|
|
2
|
+
import { type MenuEntry } from "./menu.js";
|
|
3
|
+
export declare const contextMenuContract: {
|
|
4
|
+
readonly name: "context-menu";
|
|
5
|
+
readonly parts: readonly ["root"];
|
|
6
|
+
};
|
|
7
|
+
export interface ContextMenuProps extends Props {
|
|
8
|
+
id: string;
|
|
9
|
+
items: readonly MenuEntry[];
|
|
10
|
+
open?: MaybeSignal<boolean>;
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
className?: string;
|
|
13
|
+
children?: Child;
|
|
14
|
+
}
|
|
15
|
+
/** Right-click or Shift+F10 opens the existing Menu, including nested items. */
|
|
16
|
+
export declare const ContextMenu: import("meowjsx").Component<ContextMenuProps, "context-menu", "root">;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineComponent, h, unwrap, } from "meowjsx";
|
|
2
|
+
import { Menu } from "./menu.js";
|
|
3
|
+
export const contextMenuContract = {
|
|
4
|
+
name: "context-menu",
|
|
5
|
+
parts: ["root"],
|
|
6
|
+
};
|
|
7
|
+
/** Right-click or Shift+F10 opens the existing Menu, including nested items. */
|
|
8
|
+
export const ContextMenu = defineComponent(contextMenuContract, ({ id, items, open, onOpenChange, className, children, ...props }, context) => {
|
|
9
|
+
const local = context.signal(false);
|
|
10
|
+
const state = open !== undefined ? open : local;
|
|
11
|
+
let point = { x: 0, y: 0 };
|
|
12
|
+
const request = (next) => {
|
|
13
|
+
if (open === undefined)
|
|
14
|
+
local.value = next;
|
|
15
|
+
onOpenChange?.(next);
|
|
16
|
+
};
|
|
17
|
+
const openAt = (x, y) => {
|
|
18
|
+
const reopen = unwrap(state);
|
|
19
|
+
point = { x, y };
|
|
20
|
+
if (reopen) {
|
|
21
|
+
request(false);
|
|
22
|
+
queueMicrotask(() => request(true));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
request(true);
|
|
26
|
+
};
|
|
27
|
+
return (h(Menu, { id: id, items: items, open: state, onOpenChange: request, anchorRect: () => new DOMRect(point.x, point.y, 0, 0), trigger: (bindings) => context.part("root", "div", {
|
|
28
|
+
...props,
|
|
29
|
+
id: bindings.id,
|
|
30
|
+
"aria-controls": bindings["aria-controls"],
|
|
31
|
+
"aria-expanded": bindings["aria-expanded"],
|
|
32
|
+
"aria-haspopup": bindings["aria-haspopup"],
|
|
33
|
+
className,
|
|
34
|
+
tabIndex: -1,
|
|
35
|
+
onContextMenu: (event) => {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
openAt(event.clientX, event.clientY);
|
|
38
|
+
},
|
|
39
|
+
onKeyDown: (event) => {
|
|
40
|
+
if (event.isComposing || event.altKey || event.ctrlKey || event.metaKey)
|
|
41
|
+
return;
|
|
42
|
+
if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
45
|
+
openAt(box.left, box.bottom);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
}, children) }));
|
|
49
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Child, type Props } from "meowjsx";
|
|
1
|
+
import { type Child, type MaybeSignal, type Props } from "meowjsx";
|
|
2
2
|
export declare const disclosureContract: {
|
|
3
3
|
readonly name: "disclosure";
|
|
4
4
|
readonly parts: readonly ["root", "summary", "icon", "content"];
|
|
5
5
|
};
|
|
6
6
|
export interface DisclosureProps extends Props {
|
|
7
7
|
summary: Child;
|
|
8
|
-
open?: boolean
|
|
8
|
+
open?: MaybeSignal<boolean>;
|
|
9
9
|
onToggle?: (event: Event) => void;
|
|
10
10
|
className?: string;
|
|
11
11
|
summaryClassName?: string;
|
|
@@ -20,7 +20,12 @@ export { Toolbar, type ToolbarProps, toolbarContract } from "./toolbar.js";
|
|
|
20
20
|
export { ActionRail, type ActionRailProps, actionRailContract } from "./action-rail.js";
|
|
21
21
|
export { MetaRow, type MetaItem, type MetaRowProps, metaRowContract, metaRowOptions, } from "./meta-row.js";
|
|
22
22
|
export { Input, type InputProps, inputContract } from "./input.js";
|
|
23
|
+
export { NumberInput, type NumberInputProps, numberInputContract, clampNumber, formatNumber, numberPrecision, } from "./number-input.js";
|
|
23
24
|
export { Checkbox, type CheckboxProps, checkboxContract } from "./checkbox.js";
|
|
25
|
+
export { Slider, type SliderProps, sliderContract } from "./slider.js";
|
|
26
|
+
export { Progress, type ProgressProps, progressContract } from "./progress.js";
|
|
27
|
+
export { Avatar, type AvatarProps, avatarContract, avatarOptions, initialsFromName, } from "./avatar.js";
|
|
28
|
+
export { Link, type LinkProps, linkContract } from "./link.js";
|
|
24
29
|
export { Switch, type SwitchProps, switchContract } from "./switch.js";
|
|
25
30
|
export { Select, type SelectProps, selectContract } from "./select.js";
|
|
26
31
|
export { ChoiceSelect, type ChoiceSelectProps, type ChoiceOption, choiceSelectContract, } from "./choice-select.js";
|
|
@@ -28,6 +33,8 @@ export { Popover, type PopoverProps, type PopoverTriggerBindings, popoverContrac
|
|
|
28
33
|
export { SearchInput, type SearchInputProps, searchInputContract } from "./search-input.js";
|
|
29
34
|
export { PathPicker, type PathPickerProps, pathPickerContract } from "./path-picker.js";
|
|
30
35
|
export { Disclosure, type DisclosureProps, disclosureContract } from "./disclosure.js";
|
|
36
|
+
export { Accordion, type AccordionProps, type AccordionItem, type AccordionType, type AccordionValue, accordionContract, } from "./accordion.js";
|
|
37
|
+
export { Table, type TableProps, type TableColumn, type TableRow, type TableSort, type TableSortDirection, tableContract, } from "./table.js";
|
|
31
38
|
export { NavItem, type NavItemProps, navItemContract } from "./nav-item.js";
|
|
32
39
|
export { Separator, type SeparatorProps, separatorContract } from "./separator.js";
|
|
33
40
|
export { Textarea, type TextareaProps, textareaContract } from "./textarea.js";
|
|
@@ -63,6 +70,8 @@ export { PathLabel, pathLabelContract } from "./path-label.js";
|
|
|
63
70
|
export { StateDot, stateDotContract } from "./state-dot.js";
|
|
64
71
|
export { HoverCard, hoverCardContract } from "./hover-card.js";
|
|
65
72
|
export { Menu, menuContract, type MenuProps, type MenuEntry, type MenuAction, type MenuTriggerBindings, } from "./menu.js";
|
|
73
|
+
export { MenuButton, type MenuButtonProps } from "./menu-button.js";
|
|
74
|
+
export { ContextMenu, type ContextMenuProps, contextMenuContract } from "./context-menu.js";
|
|
66
75
|
export { Toast, toastContract, type ToastProps } from "./toast.js";
|
|
67
76
|
export { TerminalBlock, terminalBlockContract, type TerminalBlockProps } from "./terminal-block.js";
|
|
68
77
|
export { ReadBlock, readBlockContract, type ReadBlockProps, type ReadBlockLine, } from "./read-block.js";
|