meowtail 0.2.0-alpha.0 → 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.
Files changed (163) hide show
  1. package/AGENT-COMPONENTS.md +65 -65
  2. package/ASSISTANT.md +35 -35
  3. package/JSON.md +11 -11
  4. package/README.md +413 -385
  5. package/THIRD_PARTY_NOTICES.md +8 -0
  6. package/dist/src/chat/assistant-composer.js +58 -98
  7. package/dist/src/chat/assistant-content.d.ts +1 -3
  8. package/dist/src/chat/assistant-content.js +36 -44
  9. package/dist/src/chat/assistant-markdown.js +4 -8
  10. package/dist/src/chat/assistant-question.js +13 -14
  11. package/dist/src/chat/assistant.js +27 -26
  12. package/dist/src/chat/attachments.d.ts +3 -2
  13. package/dist/src/chat/attachments.js +43 -34
  14. package/dist/src/chat/composer-panel.d.ts +16 -0
  15. package/dist/src/chat/composer-panel.js +11 -0
  16. package/dist/src/chat/composer.d.ts +7 -3
  17. package/dist/src/chat/composer.js +71 -22
  18. package/dist/src/chat/conversation.js +2 -2
  19. package/dist/src/chat/index.d.ts +1 -0
  20. package/dist/src/chat/index.js +1 -0
  21. package/dist/src/chat/message-list.js +1 -1
  22. package/dist/src/chat/message.js +3 -3
  23. package/dist/src/chat/question.js +1 -1
  24. package/dist/src/chat/sources.js +1 -1
  25. package/dist/src/chat/task.js +9 -15
  26. package/dist/src/chat/tool-call.js +7 -14
  27. package/dist/src/components/accordion.d.ts +24 -0
  28. package/dist/src/components/accordion.js +50 -0
  29. package/dist/src/components/action-rail.d.ts +19 -0
  30. package/dist/src/components/action-rail.js +13 -0
  31. package/dist/src/components/add-button.js +1 -1
  32. package/dist/src/components/alert.d.ts +2 -0
  33. package/dist/src/components/alert.js +2 -1
  34. package/dist/src/components/app-bar.d.ts +17 -0
  35. package/dist/src/components/app-bar.js +10 -0
  36. package/dist/src/components/avatar.d.ts +22 -0
  37. package/dist/src/components/avatar.js +44 -0
  38. package/dist/src/components/breadcrumb.js +1 -1
  39. package/dist/src/components/checkbox.d.ts +6 -2
  40. package/dist/src/components/checkbox.js +36 -8
  41. package/dist/src/components/choice-group.d.ts +1 -0
  42. package/dist/src/components/choice-group.js +12 -17
  43. package/dist/src/components/choice-select.d.ts +3 -1
  44. package/dist/src/components/choice-select.js +56 -54
  45. package/dist/src/components/code-block.d.ts +3 -3
  46. package/dist/src/components/code-block.js +31 -27
  47. package/dist/src/components/context-menu.d.ts +16 -0
  48. package/dist/src/components/context-menu.js +49 -0
  49. package/dist/src/components/credential-source.js +12 -12
  50. package/dist/src/components/diff-block.js +1 -1
  51. package/dist/src/components/disclosure.d.ts +2 -2
  52. package/dist/src/components/disclosure.js +1 -1
  53. package/dist/src/components/hover-card.js +2 -2
  54. package/dist/src/components/image-lightbox.js +3 -3
  55. package/dist/src/components/image-preview.js +1 -1
  56. package/dist/src/components/index.d.ts +12 -0
  57. package/dist/src/components/index.js +12 -0
  58. package/dist/src/components/json-block.js +2 -2
  59. package/dist/src/components/json-tree.js +3 -3
  60. package/dist/src/components/link.d.ts +13 -0
  61. package/dist/src/components/link.js +9 -0
  62. package/dist/src/components/list-group.d.ts +1 -1
  63. package/dist/src/components/menu-button.d.ts +13 -0
  64. package/dist/src/components/menu-button.js +10 -0
  65. package/dist/src/components/menu.d.ts +4 -0
  66. package/dist/src/components/menu.js +3 -3
  67. package/dist/src/components/meta-row.d.ts +34 -0
  68. package/dist/src/components/meta-row.js +61 -0
  69. package/dist/src/components/nav-item.js +2 -5
  70. package/dist/src/components/number-input.d.ts +29 -0
  71. package/dist/src/components/number-input.js +137 -0
  72. package/dist/src/components/output-block.js +8 -15
  73. package/dist/src/components/page-frame.d.ts +6 -2
  74. package/dist/src/components/page-frame.js +2 -2
  75. package/dist/src/components/path-picker.js +9 -14
  76. package/dist/src/components/pill.js +2 -5
  77. package/dist/src/components/popover.js +4 -4
  78. package/dist/src/components/process-group.d.ts +2 -2
  79. package/dist/src/components/progress.d.ts +15 -0
  80. package/dist/src/components/progress.js +12 -0
  81. package/dist/src/components/rail-item.d.ts +2 -2
  82. package/dist/src/components/rail-section.d.ts +1 -1
  83. package/dist/src/components/read-block.js +2 -2
  84. package/dist/src/components/resource-card.d.ts +1 -1
  85. package/dist/src/components/resource-link.d.ts +1 -1
  86. package/dist/src/components/risk-confirmation.js +2 -5
  87. package/dist/src/components/search-block.js +2 -3
  88. package/dist/src/components/segmented-control.js +3 -3
  89. package/dist/src/components/skeleton-boundary.js +4 -7
  90. package/dist/src/components/slider.d.ts +22 -0
  91. package/dist/src/components/slider.js +49 -0
  92. package/dist/src/components/table.d.ts +41 -0
  93. package/dist/src/components/table.js +146 -0
  94. package/dist/src/components/tabs.d.ts +1 -1
  95. package/dist/src/components/tabs.js +11 -20
  96. package/dist/src/components/terminal-block.js +6 -6
  97. package/dist/src/components/text-shimmer.js +2 -5
  98. package/dist/src/components/web-block.js +3 -3
  99. package/dist/src/components/work-card.d.ts +2 -2
  100. package/dist/src/components/work-card.js +1 -1
  101. package/dist/src/icons/README.md +13 -2
  102. package/dist/src/icons/icon-frame.d.ts +11 -0
  103. package/dist/src/icons/icon-frame.js +4 -0
  104. package/dist/src/icons/icon-source.d.ts +17 -0
  105. package/dist/src/icons/icon-source.js +6 -0
  106. package/dist/src/icons/icon.d.ts +44 -37
  107. package/dist/src/icons/icon.js +55 -128
  108. package/dist/src/icons/index.d.ts +1 -0
  109. package/dist/src/icons/index.js +1 -0
  110. package/dist/src/icons/lucide.d.ts +1 -0
  111. package/dist/src/icons/lucide.js +4 -0
  112. package/dist/src/registry/index.d.ts +99 -5
  113. package/dist/src/registry/index.js +28 -3
  114. package/dist/src/shared/execution-state.js +7 -7
  115. package/dist/src/theme/chat/composer-panel.styles.d.ts +1 -0
  116. package/dist/src/theme/chat/composer-panel.styles.js +47 -0
  117. package/dist/src/theme/chat/composer.styles.js +69 -60
  118. package/dist/src/theme/chat/task.styles.js +5 -6
  119. package/dist/src/theme/components/accordion.styles.d.ts +1 -0
  120. package/dist/src/theme/components/accordion.styles.js +63 -0
  121. package/dist/src/theme/components/action-rail.styles.d.ts +1 -0
  122. package/dist/src/theme/components/action-rail.styles.js +47 -0
  123. package/dist/src/theme/components/alert.styles.js +42 -1
  124. package/dist/src/theme/components/app-bar.styles.d.ts +1 -0
  125. package/dist/src/theme/components/app-bar.styles.js +48 -0
  126. package/dist/src/theme/components/avatar.styles.d.ts +1 -0
  127. package/dist/src/theme/components/avatar.styles.js +52 -0
  128. package/dist/src/theme/components/button.styles.js +9 -0
  129. package/dist/src/theme/components/card.styles.js +2 -0
  130. package/dist/src/theme/components/code-block.styles.js +7 -0
  131. package/dist/src/theme/components/context-menu.styles.d.ts +1 -0
  132. package/dist/src/theme/components/context-menu.styles.js +14 -0
  133. package/dist/src/theme/components/dialog.styles.js +7 -0
  134. package/dist/src/theme/components/link.styles.d.ts +1 -0
  135. package/dist/src/theme/components/link.styles.js +33 -0
  136. package/dist/src/theme/components/list-group.styles.js +1 -0
  137. package/dist/src/theme/components/menu.styles.js +9 -3
  138. package/dist/src/theme/components/meta-row.styles.d.ts +1 -0
  139. package/dist/src/theme/components/meta-row.styles.js +66 -0
  140. package/dist/src/theme/components/number-input.styles.d.ts +1 -0
  141. package/dist/src/theme/components/number-input.styles.js +106 -0
  142. package/dist/src/theme/components/output-block.styles.js +9 -0
  143. package/dist/src/theme/components/page-frame.styles.js +7 -1
  144. package/dist/src/theme/components/page-header.styles.js +7 -0
  145. package/dist/src/theme/components/progress.styles.d.ts +1 -0
  146. package/dist/src/theme/components/progress.styles.js +71 -0
  147. package/dist/src/theme/components/resource-card.styles.js +7 -0
  148. package/dist/src/theme/components/slider.styles.d.ts +1 -0
  149. package/dist/src/theme/components/slider.styles.js +129 -0
  150. package/dist/src/theme/components/table.styles.d.ts +1 -0
  151. package/dist/src/theme/components/table.styles.js +156 -0
  152. package/dist/src/theme/components/tag.styles.js +3 -3
  153. package/dist/src/theme/components/toggle.styles.js +10 -0
  154. package/dist/src/theme/components/toolbar.styles.js +7 -0
  155. package/dist/src/theme/index.d.ts +15 -15
  156. package/dist/src/theme/index.js +24 -0
  157. package/dist/src/theme/palette.d.ts +1 -1
  158. package/dist/src/theme/palette.js +1 -1
  159. package/dist/src/theme/shared/code-highlight.tokens.d.ts +6 -6
  160. package/dist/src/theme/shared/code-highlight.tokens.js +6 -6
  161. package/dist/src/theme/tokens.d.ts +7 -7
  162. package/dist/src/theme/tokens.js +14 -8
  163. package/package.json +9 -4
@@ -0,0 +1,50 @@
1
+ import { defineComponent, derived, h, unwrap, } from "meowjsx";
2
+ import { Disclosure } from "./disclosure.js";
3
+ export const accordionContract = {
4
+ name: "accordion",
5
+ parts: ["root", "item"],
6
+ };
7
+ function asList(value, type) {
8
+ if (value === undefined)
9
+ return [];
10
+ if (typeof value === "string")
11
+ return type === "single" && value === "" ? [] : [value];
12
+ return [...value];
13
+ }
14
+ function isOpen(value, type, id) {
15
+ return asList(value, type).includes(id);
16
+ }
17
+ function nextValue(current, type, id, open) {
18
+ if (type === "single") {
19
+ if (open)
20
+ return id;
21
+ const currentId = asList(current, type)[0] ?? "";
22
+ return currentId === id ? "" : currentId;
23
+ }
24
+ const list = new Set(asList(current, type));
25
+ if (open)
26
+ list.add(id);
27
+ else
28
+ list.delete(id);
29
+ return [...list];
30
+ }
31
+ /** Grouped disclosures. Items are fixed for the mount. Expansion is handed to the caller when `value` is set. */
32
+ export const Accordion = defineComponent(accordionContract, ({ items, type = "single", value, defaultValue, onValueChange, label, className, ...props }, context) => {
33
+ const local = context.signal(defaultValue ?? (type === "single" ? "" : []));
34
+ const current = value !== undefined ? value : local;
35
+ const readValue = () => unwrap(current);
36
+ const opened = items.map((item) => derived(() => isOpen(readValue(), type, item.id)));
37
+ const request = (id, open) => {
38
+ const next = nextValue(readValue(), type, id, open);
39
+ if (value === undefined)
40
+ local.value = next;
41
+ onValueChange?.(next);
42
+ };
43
+ return context.part("root", "div", {
44
+ ...props,
45
+ className,
46
+ "aria-label": label,
47
+ }, ...items.map((item, index) => context.part("item", "div", { "data-accordion-id": item.id }, h(Disclosure, { summary: item.summary, open: opened[index], name: type === "single" ? props.id : undefined, onToggle: (event) => {
48
+ request(item.id, event.currentTarget.open);
49
+ } }, item.content))));
50
+ });
@@ -0,0 +1,19 @@
1
+ import { type Child, type Props } from "meowjsx";
2
+ export declare const actionRailContract: {
3
+ readonly name: "action-rail";
4
+ readonly parts: readonly ["root", "leading", "trailing", "submit"];
5
+ };
6
+ export interface ActionRailProps extends Props {
7
+ /** Actions anchored to the start of the row. */
8
+ leading?: Child;
9
+ /** Selection or secondary actions that stay together before the submit action. */
10
+ trailing?: Child;
11
+ /** The final action; flexible leading and trailing actions wrap to keep it visible. */
12
+ submit?: Child;
13
+ className?: string;
14
+ }
15
+ /**
16
+ * An action row with wrapping groups. The rail owns order, start/end anchoring, the gap between
17
+ * groups and the rule that the submit action stays visible; callers pass actions.
18
+ */
19
+ export declare const ActionRail: import("meowjsx").Component<ActionRailProps, "action-rail", "leading" | "root" | "submit" | "trailing">;
@@ -0,0 +1,13 @@
1
+ import { defineComponent } from "meowjsx";
2
+ export const actionRailContract = {
3
+ name: "action-rail",
4
+ parts: ["root", "leading", "trailing", "submit"],
5
+ };
6
+ /**
7
+ * An action row with wrapping groups. The rail owns order, start/end anchoring, the gap between
8
+ * groups and the rule that the submit action stays visible; callers pass actions.
9
+ */
10
+ export const ActionRail = defineComponent(actionRailContract, ({ leading, trailing, submit, children, className, ...props }, context) => {
11
+ void children;
12
+ return context.part("root", "div", { ...props, className }, context.part("leading", "div", null, leading), context.part("trailing", "div", null, trailing), context.part("submit", "div", null, submit));
13
+ });
@@ -4,5 +4,5 @@ import { PlusIcon } from "../icons/plus.js";
4
4
  export function AddButton(props) {
5
5
  return (h(Button, { ...props },
6
6
  h(PlusIcon, null),
7
- props.children ?? "添加"));
7
+ props.children ?? "Add"));
8
8
  }
@@ -2,12 +2,14 @@ import { type Child, type Props } from "meowjsx";
2
2
  import { type ThemedProps } from "meowcss/meowjsx";
3
3
  export declare const alertOptions: import("meowcss").Options<{
4
4
  readonly tone: readonly ["info", "success", "warning", "danger"];
5
+ readonly layout: readonly ["block", "bar"];
5
6
  }>;
6
7
  export declare const alertContract: {
7
8
  readonly name: "alert";
8
9
  readonly parts: readonly ["root", "title", "body", "actions"];
9
10
  readonly styleProps: import("meowcss/meowjsx").StylePropsBinding<import("meowcss").Options<{
10
11
  readonly tone: readonly ["info", "success", "warning", "danger"];
12
+ readonly layout: readonly ["block", "bar"];
11
13
  }>>;
12
14
  };
13
15
  export interface AlertProps extends Props, ThemedProps<typeof alertOptions> {
@@ -3,12 +3,13 @@ import { defineOptions } from "meowcss";
3
3
  import { defineStyleProps } from "meowcss/meowjsx";
4
4
  export const alertOptions = defineOptions("alert", {
5
5
  tone: ["info", "success", "warning", "danger"],
6
+ layout: ["block", "bar"],
6
7
  });
7
8
  export const alertContract = {
8
9
  name: "alert",
9
10
  parts: ["root", "title", "body", "actions"],
10
11
  styleProps: defineStyleProps(alertOptions, {
11
- defaults: { tone: "info" },
12
+ defaults: { tone: "info", layout: "block" },
12
13
  parts: ["root", "title"],
13
14
  }),
14
15
  };
@@ -0,0 +1,17 @@
1
+ import { type Child, type Props } from "meowjsx";
2
+ export declare const appBarContract: {
3
+ readonly name: "app-bar";
4
+ readonly parts: readonly ["root", "identity", "title", "status", "actions"];
5
+ };
6
+ export interface AppBarProps extends Props {
7
+ title: Child;
8
+ /** A short status line under the title, typically ChatStatus. */
9
+ status?: Child;
10
+ actions?: Child;
11
+ className?: string;
12
+ }
13
+ /**
14
+ * Compact application chrome: one title, one optional status line, and the
15
+ * actions that belong to the whole screen. The page body keeps its own scroll.
16
+ */
17
+ export declare const AppBar: import("meowjsx").Component<AppBarProps, "app-bar", "actions" | "identity" | "root" | "status" | "title">;
@@ -0,0 +1,10 @@
1
+ import { defineComponent } from "meowjsx";
2
+ export const appBarContract = {
3
+ name: "app-bar",
4
+ parts: ["root", "identity", "title", "status", "actions"],
5
+ };
6
+ /**
7
+ * Compact application chrome: one title, one optional status line, and the
8
+ * actions that belong to the whole screen. The page body keeps its own scroll.
9
+ */
10
+ export const AppBar = defineComponent(appBarContract, ({ title, status, actions, className, ...props }, context) => context.part("root", "header", { ...props, className }, context.part("identity", "div", null, context.part("title", "h1", null, title), status !== undefined && status !== null ? context.part("status", "div", null, status) : null), actions ? context.part("actions", "div", null, actions) : null));
@@ -0,0 +1,22 @@
1
+ import { type ThemedProps } from "meowcss/meowjsx";
2
+ import { type Props } from "meowjsx";
3
+ export declare const avatarOptions: import("meowcss").Options<{
4
+ readonly size: readonly ["small", "default", "large"];
5
+ }>;
6
+ export declare const avatarContract: {
7
+ readonly name: "avatar";
8
+ readonly parts: readonly ["root", "image", "initials"];
9
+ readonly styleProps: import("meowcss/meowjsx").StylePropsBinding<import("meowcss").Options<{
10
+ readonly size: readonly ["small", "default", "large"];
11
+ }>>;
12
+ };
13
+ export interface AvatarProps extends Props, ThemedProps<typeof avatarOptions> {
14
+ /** Used for initials and the accessible name. */
15
+ name: string;
16
+ src?: string;
17
+ alt?: string;
18
+ className?: string;
19
+ }
20
+ export declare function initialsFromName(name: string): string;
21
+ /** A face or the initials that remain when the image is missing. */
22
+ export declare const Avatar: import("meowjsx").Component<AvatarProps, "avatar", "image" | "initials" | "root">;
@@ -0,0 +1,44 @@
1
+ import { defineOptions } from "meowcss";
2
+ import { defineStyleProps } from "meowcss/meowjsx";
3
+ import { defineComponent } from "meowjsx";
4
+ export const avatarOptions = defineOptions("avatar", {
5
+ size: ["small", "default", "large"],
6
+ });
7
+ export const avatarContract = {
8
+ name: "avatar",
9
+ parts: ["root", "image", "initials"],
10
+ styleProps: defineStyleProps(avatarOptions, { defaults: { size: "default" } }),
11
+ };
12
+ export function initialsFromName(name) {
13
+ const parts = name.trim().split(/\s+/).filter(Boolean);
14
+ if (parts.length === 0)
15
+ return "?";
16
+ if (parts.length === 1) {
17
+ const word = parts[0];
18
+ const first = Array.from(word);
19
+ return first.slice(0, 2).join("").toUpperCase();
20
+ }
21
+ const leading = Array.from(parts[0])[0];
22
+ const next = Array.from(parts[1])[0];
23
+ return `${leading ?? ""}${next ?? ""}`.toUpperCase() || "?";
24
+ }
25
+ /** A face or the initials that remain when the image is missing. */
26
+ export const Avatar = defineComponent(avatarContract, ({ name, src, alt, className, ...props }, context) => {
27
+ const failed = context.signal(false);
28
+ return context.part("root", "span", {
29
+ ...props,
30
+ className,
31
+ role: "img",
32
+ "aria-label": name,
33
+ }, context.part("initials", "span", { "aria-hidden": "true" }, initialsFromName(name)), src
34
+ ? context.part("image", "img", {
35
+ src,
36
+ alt: alt ?? "",
37
+ hidden: failed,
38
+ referrerPolicy: "no-referrer",
39
+ onError: () => {
40
+ failed.value = true;
41
+ },
42
+ })
43
+ : null);
44
+ });
@@ -3,7 +3,7 @@ export const breadcrumbContract = {
3
3
  name: "breadcrumb",
4
4
  parts: ["root", "list", "item", "link", "current", "separator"],
5
5
  };
6
- export const Breadcrumb = defineComponent(breadcrumbContract, ({ items, label = "当前位置", className, ...props }, context) => context.part("root", "nav", { ...props, className, "aria-label": label }, context.part("list", "ol", null, items.map((item, index) => context.part("item", "li", null, index ? context.part("separator", "span", { "aria-hidden": "true" }, "/") : null, index === items.length - 1
6
+ export const Breadcrumb = defineComponent(breadcrumbContract, ({ items, label = "Current location", className, ...props }, context) => context.part("root", "nav", { ...props, className, "aria-label": label }, context.part("list", "ol", null, items.map((item, index) => context.part("item", "li", null, index ? context.part("separator", "span", { "aria-hidden": "true" }, "/") : null, index === items.length - 1
7
7
  ? context.part("current", "span", { "aria-current": "page" }, item.label)
8
8
  : item.href
9
9
  ? context.part("link", "a", { href: item.href }, item.label)
@@ -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 ?? defaultChecked,
26
+ checked: checked !== undefined ? checked : defaultChecked,
27
+ "aria-checked": mixedAttr,
12
28
  ref: (input) => {
13
- input.defaultChecked = defaultChecked;
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.checked = unwrap(checked);
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
- event.currentTarget.checked = unwrap(checked);
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", null, label)));
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 selected = context.signal(value === undefined ? defaultValue : unwrap(value));
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.value === optionValue;
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
- selected.value = value === undefined ? defaultValue : unwrap(value);
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 = context.signal(selected.value === option.value);
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 = selected.value === option.value;
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
- selected.value = option.value;
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
- options: readonly ChoiceOption[];
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 = "请选择", searchable = false, searchPlaceholder = "搜索选项", emptyMessage = "没有匹配的选项", className, placement = "bottom", align = "start", matchTriggerWidth = true, ...props }, context) => {
24
- const selected = context.signal(value === undefined ? defaultValue : unwrap(value));
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 enabledOptions = () => options
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 = options.findIndex((option) => option.value === selected.value && !option.disabled);
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 = options[index];
68
+ const option = readOptions()[index];
77
69
  if (disabled || !option || option.disabled)
78
70
  return;
79
71
  if (value === undefined)
80
- selected.value = option.value;
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 = selected.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 (options[index].label.toLocaleLowerCase().startsWith(query.toLocaleLowerCase())) {
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 = selected.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
- selected.value = defaultValue;
215
- native.value = selected.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
- return context.part("root", "div", { className }, h(Popover, {
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
- }, ...options.flatMap((option, index) => {
299
- const isSelected = context.signal("false");
300
- const hidden = context.signal(false);
301
- context.effect(() => {
302
- isSelected.value = String(selected.value === option.value);
303
- hidden.value = !matches(option);
304
- });
305
- const item = context.part("option", "button", {
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": isSelected,
313
- "data-choice-index": index,
314
- onClick: () => choose(index),
315
- }, option.label);
316
- const groupHidden = context.signal(false);
317
- context.effect(() => {
318
- groupHidden.value = !options.some((candidate) => candidate.group === option.group && matches(candidate));
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: selected,
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(options.findIndex((option) => option.value === next));
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), ...options.map((option) => h("option", { value: option.value, disabled: option.disabled }, option.label))), context.part("validation", "span", { id: `${id}-validation`, role: "alert" }, validation));
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
  });