meowtail 0.4.0-alpha.0 → 0.4.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 (147) hide show
  1. package/ASSISTANT.md +2 -2
  2. package/AUTHORING.md +268 -0
  3. package/CHANGELOG.md +116 -0
  4. package/COMPONENTS.md +182 -140
  5. package/README.md +145 -34
  6. package/dist/src/chat/assistant-content.js +3 -1
  7. package/dist/src/chat/assistant-markdown.d.ts +8 -5
  8. package/dist/src/chat/assistant-markdown.js +11 -26
  9. package/dist/src/components/autocomplete.d.ts +47 -0
  10. package/dist/src/components/autocomplete.js +169 -0
  11. package/dist/src/components/card-title.d.ts +1 -0
  12. package/dist/src/components/card-title.js +2 -1
  13. package/dist/src/components/chart-scale.d.ts +46 -0
  14. package/dist/src/components/chart-scale.js +118 -0
  15. package/dist/src/components/chart.d.ts +38 -0
  16. package/dist/src/components/chart.js +210 -0
  17. package/dist/src/components/choice-group.js +2 -2
  18. package/dist/src/components/choice-select.js +2 -2
  19. package/dist/src/components/code-block.d.ts +3 -1
  20. package/dist/src/components/code-block.js +75 -16
  21. package/dist/src/components/command-palette.d.ts +44 -0
  22. package/dist/src/components/command-palette.js +198 -0
  23. package/dist/src/components/context-menu.d.ts +2 -1
  24. package/dist/src/components/context-menu.js +2 -1
  25. package/dist/src/components/credential-source.d.ts +2 -1
  26. package/dist/src/components/credential-source.js +2 -1
  27. package/dist/src/components/detail-section.d.ts +2 -1
  28. package/dist/src/components/detail-section.js +8 -3
  29. package/dist/src/components/dialog.d.ts +4 -1
  30. package/dist/src/components/dialog.js +7 -2
  31. package/dist/src/components/entry.d.ts +45 -0
  32. package/dist/src/components/entry.js +38 -0
  33. package/dist/src/components/entry.options.d.ts +4 -0
  34. package/dist/src/components/entry.options.js +3 -0
  35. package/dist/src/components/field-group.js +2 -2
  36. package/dist/src/components/field.d.ts +4 -0
  37. package/dist/src/components/field.js +15 -3
  38. package/dist/src/components/form.d.ts +34 -0
  39. package/dist/src/components/form.js +58 -0
  40. package/dist/src/components/heading-level.d.ts +9 -0
  41. package/dist/src/components/heading-level.js +12 -0
  42. package/dist/src/components/hover-card.d.ts +3 -2
  43. package/dist/src/components/hover-card.js +50 -15
  44. package/dist/src/components/index.d.ts +11 -1
  45. package/dist/src/components/index.js +11 -1
  46. package/dist/src/components/markdown-blocks.d.ts +27 -0
  47. package/dist/src/components/markdown-blocks.js +141 -0
  48. package/dist/src/components/markdown.d.ts +35 -0
  49. package/dist/src/components/markdown.js +35 -0
  50. package/dist/src/components/menu-button.d.ts +2 -1
  51. package/dist/src/components/menu.d.ts +2 -1
  52. package/dist/src/components/menu.js +2 -1
  53. package/dist/src/components/modal.js +2 -2
  54. package/dist/src/components/page.js +1 -1
  55. package/dist/src/components/pagination.d.ts +52 -0
  56. package/dist/src/components/pagination.js +89 -0
  57. package/dist/src/components/path-label.js +5 -27
  58. package/dist/src/components/popover.d.ts +2 -1
  59. package/dist/src/components/popover.js +33 -6
  60. package/dist/src/components/resource-card.d.ts +4 -1
  61. package/dist/src/components/resource-card.js +7 -2
  62. package/dist/src/components/risk-confirmation.d.ts +2 -1
  63. package/dist/src/components/risk-confirmation.js +2 -1
  64. package/dist/src/components/section.d.ts +1 -7
  65. package/dist/src/components/section.js +3 -8
  66. package/dist/src/components/segmented-control.d.ts +2 -1
  67. package/dist/src/components/segmented-control.js +2 -1
  68. package/dist/src/components/tabs.d.ts +2 -1
  69. package/dist/src/components/tabs.js +2 -1
  70. package/dist/src/components/token-field.d.ts +45 -0
  71. package/dist/src/components/token-field.js +175 -0
  72. package/dist/src/components/tooltip.d.ts +2 -1
  73. package/dist/src/components/tooltip.js +2 -1
  74. package/dist/src/components/tree-view.d.ts +39 -0
  75. package/dist/src/components/tree-view.js +244 -0
  76. package/dist/src/components/tree-view.options.d.ts +2 -0
  77. package/dist/src/components/tree-view.options.js +3 -0
  78. package/dist/src/icons/README.md +11 -10
  79. package/dist/src/icons/icon.d.ts +1 -0
  80. package/dist/src/icons/icon.js +2 -1
  81. package/dist/src/icons/index.d.ts +0 -1
  82. package/dist/src/icons/index.js +0 -1
  83. package/dist/src/registry/index.d.ts +41 -1
  84. package/dist/src/registry/index.js +20 -0
  85. package/dist/src/shared/element-id.d.ts +6 -0
  86. package/dist/src/shared/element-id.js +10 -0
  87. package/dist/src/shared/page-attribute.d.ts +5 -0
  88. package/dist/src/shared/page-attribute.js +5 -0
  89. package/dist/src/theme/base.styles.d.ts +2 -0
  90. package/dist/src/theme/base.styles.js +41 -4
  91. package/dist/src/theme/chat/assistant.styles.js +21 -1
  92. package/dist/src/theme/chat/attachments.styles.js +35 -6
  93. package/dist/src/theme/chat/composer.styles.js +30 -3
  94. package/dist/src/theme/chat/conversation.styles.js +13 -1
  95. package/dist/src/theme/chat/records.styles.js +10 -5
  96. package/dist/src/theme/components/autocomplete.styles.d.ts +1 -0
  97. package/dist/src/theme/components/autocomplete.styles.js +68 -0
  98. package/dist/src/theme/components/button.styles.js +0 -1
  99. package/dist/src/theme/components/card.styles.js +2 -1
  100. package/dist/src/theme/components/chart.styles.d.ts +1 -0
  101. package/dist/src/theme/components/chart.styles.js +173 -0
  102. package/dist/src/theme/components/code-block.styles.js +79 -38
  103. package/dist/src/theme/components/command-palette.styles.d.ts +1 -0
  104. package/dist/src/theme/components/command-palette.styles.js +143 -0
  105. package/dist/src/theme/components/dialog.styles.js +2 -1
  106. package/dist/src/theme/components/empty-state.styles.js +2 -1
  107. package/dist/src/theme/components/entry.styles.d.ts +1 -0
  108. package/dist/src/theme/components/entry.styles.js +86 -0
  109. package/dist/src/theme/components/form.styles.d.ts +1 -0
  110. package/dist/src/theme/components/form.styles.js +32 -0
  111. package/dist/src/theme/components/hover-card.styles.js +57 -12
  112. package/dist/src/theme/components/image-preview.styles.js +25 -0
  113. package/dist/src/theme/components/layout.styles.js +6 -0
  114. package/dist/src/theme/components/markdown.styles.d.ts +1 -0
  115. package/dist/src/theme/components/markdown.styles.js +10 -0
  116. package/dist/src/theme/components/nav-list.styles.js +6 -7
  117. package/dist/src/theme/components/pagination.styles.d.ts +1 -0
  118. package/dist/src/theme/components/pagination.styles.js +103 -0
  119. package/dist/src/theme/components/path-label.styles.js +19 -6
  120. package/dist/src/theme/components/resource-card.styles.js +2 -1
  121. package/dist/src/theme/components/search-input.styles.js +23 -0
  122. package/dist/src/theme/components/slider.styles.js +4 -0
  123. package/dist/src/theme/components/token-field.styles.d.ts +1 -0
  124. package/dist/src/theme/components/token-field.styles.js +109 -0
  125. package/dist/src/theme/components/tree-view.styles.d.ts +1 -0
  126. package/dist/src/theme/components/tree-view.styles.js +104 -0
  127. package/dist/src/theme/icons/icons.styles.js +0 -18
  128. package/dist/src/theme/index.d.ts +446 -9
  129. package/dist/src/theme/index.js +58 -1
  130. package/dist/src/theme/journal.tokens.d.ts +389 -0
  131. package/dist/src/theme/journal.tokens.js +181 -0
  132. package/dist/src/theme/meow.tokens.d.ts +362 -0
  133. package/dist/src/theme/meow.tokens.js +91 -0
  134. package/dist/src/theme/shared/field-surface.styles.js +11 -7
  135. package/dist/src/theme/shared/prose.styles.js +12 -4
  136. package/dist/src/theme/tokens.d.ts +286 -7
  137. package/dist/src/theme/tokens.js +15 -2
  138. package/dist/src/theme/utilities.js +4 -4
  139. package/dist/src/web/focus-modality.d.ts +20 -0
  140. package/dist/src/web/focus-modality.js +72 -0
  141. package/dist/src/web/index.d.ts +2 -0
  142. package/dist/src/web/index.js +2 -0
  143. package/dist/src/web/theme-plugin.d.ts +33 -0
  144. package/dist/src/web/theme-plugin.js +93 -0
  145. package/package.json +14 -6
  146. package/dist/src/icons/doodle-cat.d.ts +0 -5
  147. package/dist/src/icons/doodle-cat.js +0 -8
@@ -1,7 +1,13 @@
1
1
  import { h } from "meowjsx";
2
2
  import { derived, isSignal, mapSignal, unwrap } from "meowjsx/signal";
3
+ import { elementId } from "../shared/element-id.js";
3
4
  /** A labelled form control with optional help text and an error message. */
4
5
  export function Field({ label, description, error, htmlFor, descriptionId, errorId, invalid, children, className, ref, ...props }, context) {
6
+ // Field takes over the control id only when the host supplies none; a live id stays the host's.
7
+ const ownControl = htmlFor === undefined ? soleControl(children) : undefined;
8
+ const ownControlId = ownControl?.props.id;
9
+ const generatedId = ownControl && ownControlId === undefined ? elementId("field") : undefined;
10
+ const controlId = htmlFor ?? (typeof ownControlId === "string" ? ownControlId : generatedId);
5
11
  const hasDescription = isSignal(description)
6
12
  ? mapSignal(description, hasMessage)
7
13
  : hasMessage(description);
@@ -9,10 +15,10 @@ export function Field({ label, description, error, htmlFor, descriptionId, error
9
15
  const mountDescription = isSignal(description) || hasDescription;
10
16
  const mountError = isSignal(error) || hasError;
11
17
  const resolvedDescriptionId = mountDescription
12
- ? (descriptionId ?? (htmlFor ? `${htmlFor}-description` : undefined))
18
+ ? (descriptionId ?? (controlId ? `${controlId}-description` : undefined))
13
19
  : undefined;
14
20
  const resolvedErrorId = mountError
15
- ? (errorId ?? (htmlFor ? `${htmlFor}-error` : undefined))
21
+ ? (errorId ?? (controlId ? `${controlId}-error` : undefined))
16
22
  : undefined;
17
23
  const readDescribedBy = () => [
18
24
  unwrap(hasDescription) ? resolvedDescriptionId : undefined,
@@ -26,13 +32,14 @@ export function Field({ label, description, error, htmlFor, descriptionId, error
26
32
  describedBy,
27
33
  invalid: invalidState,
28
34
  setInvalid: invalid !== undefined || error !== undefined,
35
+ id: generatedId,
29
36
  });
30
37
  return (h("div", { ...props, className: className, "data-invalid": isSignal(invalidState)
31
38
  ? mapSignal(invalidState, (value) => (value ? "true" : undefined))
32
39
  : invalidState
33
40
  ? "true"
34
41
  : undefined, ref: [context.parts.root, ref] },
35
- h("label", { htmlFor: htmlFor, ref: context.parts.label }, label),
42
+ h("label", { htmlFor: controlId, ref: context.parts.label }, label),
36
43
  mountDescription ? (h("span", { id: resolvedDescriptionId, hidden: isSignal(hasDescription)
37
44
  ? mapSignal(hasDescription, (value) => !value)
38
45
  : !hasDescription, ref: context.parts.description }, description)) : null,
@@ -60,6 +67,8 @@ function enhanceControl(children, options) {
60
67
  ? derived(readDescribedBy)
61
68
  : readDescribedBy();
62
69
  const props = { ...children.props };
70
+ if (options.id !== undefined)
71
+ props.id = options.id;
63
72
  if (describedBy)
64
73
  props["aria-describedby"] = describedBy;
65
74
  if (options.setInvalid)
@@ -70,6 +79,9 @@ function enhanceControl(children, options) {
70
79
  : "false";
71
80
  return { ...children, props };
72
81
  }
82
+ function soleControl(children) {
83
+ return children && !Array.isArray(children) && isVNode(children) ? children : undefined;
84
+ }
73
85
  function hasMessage(value) {
74
86
  return value !== undefined && value !== null && value !== false && value !== "";
75
87
  }
@@ -0,0 +1,34 @@
1
+ import { type Child, type Context, type Props } from "meowjsx";
2
+ import { type MaybeSignal } from "meowjsx/signal";
3
+ export interface FormProps extends Props {
4
+ /**
5
+ * Called only after native constraint validation passes, with the form's data including the
6
+ * submitter. The browser's own submission is prevented; the native onSubmit is not forwarded.
7
+ */
8
+ onSubmit: (data: FormData, event: SubmitEvent) => void;
9
+ /** The host is saving: the form reports busy and a submit in the meantime is not reported. */
10
+ busy?: MaybeSignal<boolean>;
11
+ /** A host failure for the whole form, shown above the actions as an alert. */
12
+ error?: MaybeSignal<string | undefined>;
13
+ /** A polite receipt, such as "Saved", shown above the actions. */
14
+ status?: MaybeSignal<string | undefined>;
15
+ submitLabel?: string;
16
+ busyLabel?: string;
17
+ /** Adds a Cancel action; the host decides what cancelling keeps. */
18
+ onCancel?: () => void;
19
+ cancelLabel?: string;
20
+ /** Replaces the Save and Cancel actions; place them in the order Cancel, then the primary. */
21
+ actions?: Child;
22
+ className?: Props["className"];
23
+ }
24
+ /**
25
+ * A native form for a settings or connection task: validation stays native, values stay in the
26
+ * host's controls, and submission, busy state and results belong to the host.
27
+ */
28
+ export declare function Form({ onSubmit, busy, error, status, submitLabel, busyLabel, onCancel, cancelLabel, actions, className, children, ref, ...props }: FormProps, context: Context<typeof Form>): import("meowjsx").VNode;
29
+ export declare namespace Form {
30
+ var meta: {
31
+ readonly name: "form";
32
+ readonly parts: readonly ["root", "body", "error", "status", "actions"];
33
+ };
34
+ }
@@ -0,0 +1,58 @@
1
+ import { h } from "meowjsx";
2
+ import { derived, signal, unwrap } from "meowjsx/signal";
3
+ import { ActionRow } from "./action-row.js";
4
+ import { Alert } from "./alert.js";
5
+ import { Button } from "./button.js";
6
+ function labelOf(element) {
7
+ const labels = element.labels;
8
+ return labels?.[0]?.textContent?.trim() ?? "";
9
+ }
10
+ /**
11
+ * A native form for a settings or connection task: validation stays native, values stay in the
12
+ * host's controls, and submission, busy state and results belong to the host.
13
+ */
14
+ export function Form({ onSubmit, busy = false, error, status, submitLabel = "Save", busyLabel = "Saving…", onCancel, cancelLabel = "Cancel", actions, className, children, ref, ...props }, context) {
15
+ // The first invalid control's native message, shown only when the host gives no error.
16
+ const invalidMessage = signal(undefined);
17
+ const message = derived(() => unwrap(error) ?? invalidMessage.value);
18
+ const receipt = derived(() => unwrap(status));
19
+ const submit = (event) => {
20
+ event.preventDefault();
21
+ const form = event.currentTarget;
22
+ if (unwrap(busy))
23
+ return;
24
+ // checkValidity also fires each control's invalid event, so components show their own state.
25
+ if (!form.checkValidity()) {
26
+ const invalid = [...form.elements].find((element) => !element.validity?.valid);
27
+ if (invalid) {
28
+ // A hidden native carrier (such as ChoiceSelect's select) names its visible control.
29
+ const visible = invalid.getAttribute("aria-hidden") === "true"
30
+ ? form.ownerDocument.getElementById(invalid.getAttribute("aria-labelledby") ?? "")
31
+ : invalid;
32
+ (visible ?? invalid).focus();
33
+ const label = labelOf(visible ?? invalid) || labelOf(invalid);
34
+ const text = invalid.validationMessage;
35
+ invalidMessage.value = label ? `${label}: ${text}` : text;
36
+ }
37
+ return;
38
+ }
39
+ invalidMessage.value = undefined;
40
+ onSubmit(new FormData(form, event.submitter), event);
41
+ };
42
+ return (h("form", { ...props, noValidate: true, className: className, "aria-busy": derived(() => (unwrap(busy) ? "true" : undefined)), onSubmit: submit, onInput: () => {
43
+ invalidMessage.value = undefined;
44
+ }, ref: [context.parts.root, ref] },
45
+ h("div", { ref: context.parts.body }, children),
46
+ h("div", { hidden: derived(() => !message.value), ref: context.parts.error },
47
+ h(Alert, { tone: "danger", role: "alert" }, derived(() => message.value ?? ""))),
48
+ h("p", { role: "status", hidden: derived(() => !receipt.value), ref: context.parts.status }, derived(() => receipt.value ?? "")),
49
+ h("div", { ref: context.parts.actions },
50
+ h(ActionRow, null, actions ?? [
51
+ onCancel ? (h(Button, { type: "button", variant: "outline", onClick: () => onCancel() }, cancelLabel)) : null,
52
+ h(Button, { type: "submit", "aria-disabled": derived(() => (unwrap(busy) ? "true" : undefined)) }, derived(() => (unwrap(busy) ? busyLabel : submitLabel))),
53
+ ]))));
54
+ }
55
+ Form.meta = {
56
+ name: "form",
57
+ parts: ["root", "body", "error", "status", "actions"],
58
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The authoring region's heading depth. `Page` provides 1, so a direct `Section`
3
+ * with a title renders h2; each titled `Section` provides the level it rendered,
4
+ * so a nested one renders h3. A title-less grouping section passes the level
5
+ * through unchanged, and a section mounted outside a page falls back to 1.
6
+ */
7
+ export declare const sectionLevelContext: import("meowjsx").ContextValue<number>;
8
+ /** The level for a heading one step below the surrounding region; read during setup. */
9
+ export declare function nestedHeadingLevel(): number;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from "meowjsx";
2
+ /**
3
+ * The authoring region's heading depth. `Page` provides 1, so a direct `Section`
4
+ * with a title renders h2; each titled `Section` provides the level it rendered,
5
+ * so a nested one renders h3. A title-less grouping section passes the level
6
+ * through unchanged, and a section mounted outside a page falls back to 1.
7
+ */
8
+ export const sectionLevelContext = createContext(1);
9
+ /** The level for a heading one step below the surrounding region; read during setup. */
10
+ export function nestedHeadingLevel() {
11
+ return Math.min(useContext(sectionLevelContext) + 1, 6);
12
+ }
@@ -1,7 +1,8 @@
1
1
  import { type Child, type Props, type Context } from "meowjsx";
2
2
  import { type PopoverTriggerBindings } from "./popover.js";
3
3
  export interface HoverCardProps extends Props {
4
- id: string;
4
+ /** Base id for the ARIA references this component wires; generated when omitted. */
5
+ id?: string;
5
6
  trigger: (bindings: PopoverTriggerBindings) => Child;
6
7
  content: Child;
7
8
  openDelay?: number;
@@ -22,6 +23,6 @@ export declare function HoverCard({ id, trigger, content, openDelay, disabled, c
22
23
  export declare namespace HoverCard {
23
24
  var meta: {
24
25
  readonly name: "hover-card";
25
- readonly parts: readonly ["root", "content", "feedback"];
26
+ readonly parts: readonly ["root", "content", "body", "hint", "feedback"];
26
27
  };
27
28
  }
@@ -1,23 +1,30 @@
1
1
  import { h } from "meowjsx";
2
- import { signal } from "meowjsx/signal";
2
+ import { mapSignal, signal } from "meowjsx/signal";
3
3
  import { Popover } from "./popover.js";
4
4
  import { copyTextToClipboard } from "../clipboard.js";
5
+ import { Icon } from "../icons/icon.js";
6
+ import { elementId } from "../shared/element-id.js";
5
7
  /**
6
8
  * A preview card that opens while a trigger is hovered or focused; its text stays selectable.
7
9
  * Popover owns positioning, Escape, outside dismissal and focus.
8
10
  */
9
- export function HoverCard({ id, trigger, content, openDelay = 500, disabled = false, className, variant = "compact", widthAnchor, copyText, copyLabel = "Copy", copiedLabel = "Copied", onCopy, }, context) {
11
+ export function HoverCard({ id = elementId("hover-card"), trigger, content, openDelay = 500, disabled = false, className, variant = "compact", widthAnchor, copyText, copyLabel = "Copy", copiedLabel = "Copied", onCopy, }, context) {
10
12
  const open = signal(false);
11
13
  let timer;
12
14
  let hovered = false;
13
15
  let focused = false;
14
16
  let dismissed = false;
17
+ // Open state when the latest touch began; undefined after a mouse or pen press.
18
+ let touchStartedOpen;
15
19
  let root;
16
20
  let alive = true;
17
21
  let copying = false;
18
22
  let copySession = {};
19
23
  let feedbackTimer;
20
24
  const feedback = signal("");
25
+ // The cue turns into the result in place; a failure stays until the next attempt or close.
26
+ const copyState = signal("idle");
27
+ const cueLabel = mapSignal(copyState, (state) => (state === "copied" ? copiedLabel : copyLabel));
21
28
  const clear = () => {
22
29
  if (timer !== undefined)
23
30
  clearTimeout(timer);
@@ -29,6 +36,7 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
29
36
  copySession = {};
30
37
  clearTimeout(feedbackTimer);
31
38
  feedback.value = "";
39
+ copyState.value = "idle";
32
40
  };
33
41
  context.onCleanup(clear);
34
42
  context.onCleanup(() => {
@@ -46,24 +54,33 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
46
54
  }
47
55
  copying = true;
48
56
  const session = copySession;
57
+ clearTimeout(feedbackTimer);
58
+ feedback.value = "";
59
+ copyState.value = "idle";
49
60
  try {
50
61
  await (onCopy ?? copyTextToClipboard)(copyText);
51
- if (alive && open.value && session === copySession)
62
+ if (alive && open.value && session === copySession) {
52
63
  feedback.value = copiedLabel;
64
+ copyState.value = "copied";
65
+ feedbackTimer = setTimeout(() => {
66
+ feedback.value = "";
67
+ copyState.value = "idle";
68
+ }, 1500);
69
+ }
53
70
  }
54
71
  catch {
55
- if (alive && open.value && session === copySession)
72
+ if (alive && open.value && session === copySession) {
56
73
  feedback.value = "Copy failed; select the text and try again.";
74
+ copyState.value = "failed";
75
+ }
57
76
  }
58
77
  finally {
59
78
  copying = false;
60
- if (alive && session === copySession)
61
- feedbackTimer = setTimeout(() => {
62
- feedback.value = "";
63
- }, 1000);
64
79
  }
65
80
  };
66
- return (h("span", { className: className, "data-variant": variant, onPointerEnter: (event) => {
81
+ return (h("span", { className: className, "data-variant": variant, onPointerDown: (event) => {
82
+ touchStartedOpen = event.pointerType === "touch" ? open.value : undefined;
83
+ }, onPointerEnter: (event) => {
67
84
  if (event.pointerType === "touch")
68
85
  return;
69
86
  hovered = true;
@@ -72,7 +89,10 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
72
89
  timer = setTimeout(() => {
73
90
  open.value = true;
74
91
  }, Math.max(0, openDelay));
75
- }, onPointerLeave: () => {
92
+ }, onPointerLeave: (event) => {
93
+ // A lifted finger leaves at once; touch cards close by tap, outside tap or Escape.
94
+ if (event.pointerType === "touch")
95
+ return;
76
96
  hovered = false;
77
97
  dismissed = false;
78
98
  clear();
@@ -104,7 +124,9 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
104
124
  .getElementById(`${id}-trigger`)
105
125
  .getBoundingClientRect();
106
126
  const wide = (widthAnchor?.() ?? root).getBoundingClientRect();
107
- return new DOMRect(wide.left + 24, triggerRect.top, Math.max(0, wide.width - 48), triggerRect.height);
127
+ // A narrow host has no room to spare, so the card lines up with its edges.
128
+ const inset = wide.width < 480 ? 0 : 24;
129
+ return new DOMRect(wide.left + inset, triggerRect.top, Math.max(0, wide.width - inset * 2), triggerRect.height);
108
130
  }
109
131
  : undefined, onOpenChange: (next) => {
110
132
  if (!next) {
@@ -116,8 +138,14 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
116
138
  }, trigger: (bindings) => trigger({
117
139
  ...bindings,
118
140
  onClick: () => {
119
- if (!disabled)
141
+ if (disabled)
142
+ return;
143
+ // A tap toggles; the state at touch start ignores a focus that opened it mid-tap.
144
+ if (touchStartedOpen)
145
+ close();
146
+ else
120
147
  open.value = true;
148
+ touchStartedOpen = undefined;
121
149
  },
122
150
  }) }, h("div", { "data-variant": variant, role: copyText === undefined ? undefined : "button", tabIndex: copyText === undefined ? undefined : 0, "aria-label": copyText === undefined ? undefined : `${copyLabel}: ${copyText}`, onClick: copyText === undefined
123
151
  ? undefined
@@ -131,8 +159,15 @@ export function HoverCard({ id, trigger, content, openDelay = 500, disabled = fa
131
159
  return;
132
160
  event.preventDefault();
133
161
  void copy(event);
134
- }, ref: [context.parts.content] },
135
- content,
162
+ }, "data-copy-state": copyText === undefined ? undefined : copyState, ref: [context.parts.content] },
163
+ copyText === undefined ? content : h("div", { ref: [context.parts.body] }, content),
164
+ copyText === undefined ? null : (h("span", { "aria-hidden": "true", ref: [context.parts.hint] },
165
+ h(Icon, { name: "copy" }),
166
+ h(Icon, { name: "check" }),
167
+ cueLabel)),
136
168
  h("span", { role: "status", "aria-live": "polite", ref: [context.parts.feedback] }, feedback)))));
137
169
  }
138
- HoverCard.meta = { name: "hover-card", parts: ["root", "content", "feedback"] };
170
+ HoverCard.meta = {
171
+ name: "hover-card",
172
+ parts: ["root", "content", "body", "hint", "feedback"],
173
+ };
@@ -55,12 +55,20 @@ export { Grid, type GridProps, gridOptions } from "./grid.js";
55
55
  export { Container, type ContainerProps, containerOptions } from "./container.js";
56
56
  export { Tabs, type TabsProps, type TabItem, tabsCount, tabsIndex } from "./tabs.js";
57
57
  export { Breadcrumb, type BreadcrumbProps, type BreadcrumbItem } from "./breadcrumb.js";
58
+ export { Pagination, paginationEntries, type PaginationProps, type PaginationEntry, } from "./pagination.js";
59
+ export { Markdown, markdownBlocks, renderMarkdown, repairMarkdownTail, safeMarkdownLink, type MarkdownProps, type MarkdownBlock, type MarkdownCodeBlock, } from "./markdown.js";
60
+ export { Chart, admitSeries, chartSeriesLimit, niceTicks, type ChartProps, type ChartSeries, } from "./chart.js";
61
+ export { Form, type FormProps } from "./form.js";
62
+ export { CommandPalette, commandMatches, type CommandPaletteProps, type CommandPaletteCommand, } from "./command-palette.js";
63
+ export { TreeView, treeViewLevel, type TreeViewProps, type TreeViewItem } from "./tree-view.js";
64
+ export { TokenField, type TokenFieldProps, type TokenFieldToken } from "./token-field.js";
65
+ export { Autocomplete, type AutocompleteProps, type AutocompleteSuggestion } from "./autocomplete.js";
58
66
  export { Alert, type AlertProps, alertOptions } from "./alert.js";
59
67
  export { Skeleton, type SkeletonProps, skeletonOptions } from "./skeleton.js";
60
68
  export { Spinner, type SpinnerProps } from "./spinner.js";
61
69
  export { Item, type ItemProps, itemOptions } from "./item.js";
62
70
  export { ChoiceGroup, type ChoiceGroupProps, type ChoiceGroupOption } from "./choice-group.js";
63
- export { CodeBlock, type CodeBlockProps } from "./code-block.js";
71
+ export { CodeBlock, codeLanguageName, type CodeBlockProps } from "./code-block.js";
64
72
  export { MermaidDiagram, type MermaidDiagramLimits, type MermaidDiagramProps, } from "./mermaid-diagram.js";
65
73
  export { layoutOptions } from "./layout-types.js";
66
74
  export { SegmentedControl, type SegmentedControlProps, type SegmentedControlOption, } from "./segmented-control.js";
@@ -96,6 +104,8 @@ export { RailSection, type RailSectionProps } from "./rail-section.js";
96
104
  export { DetailSection, type DetailSectionProps } from "./detail-section.js";
97
105
  export { Timeline, type TimelineProps } from "./timeline.js";
98
106
  export { TimelineItem, type TimelineItemProps } from "./timeline.js";
107
+ export { Entry, EntryList, type EntryProps, type EntryListProps } from "./entry.js";
108
+ export { entryOptions } from "./entry.options.js";
99
109
  export { ResourceLink, type ResourceLinkProps } from "./resource-link.js";
100
110
  export { Page, type PageProps, type PageWidth } from "./page.js";
101
111
  export { PageHeader, type PageHeaderProps } from "./page-header.js";
@@ -54,12 +54,20 @@ export { Grid, gridOptions } from "./grid.js";
54
54
  export { Container, containerOptions } from "./container.js";
55
55
  export { Tabs, tabsCount, tabsIndex } from "./tabs.js";
56
56
  export { Breadcrumb } from "./breadcrumb.js";
57
+ export { Pagination, paginationEntries, } from "./pagination.js";
58
+ export { Markdown, markdownBlocks, renderMarkdown, repairMarkdownTail, safeMarkdownLink, } from "./markdown.js";
59
+ export { Chart, admitSeries, chartSeriesLimit, niceTicks, } from "./chart.js";
60
+ export { Form } from "./form.js";
61
+ export { CommandPalette, commandMatches, } from "./command-palette.js";
62
+ export { TreeView, treeViewLevel } from "./tree-view.js";
63
+ export { TokenField } from "./token-field.js";
64
+ export { Autocomplete } from "./autocomplete.js";
57
65
  export { Alert, alertOptions } from "./alert.js";
58
66
  export { Skeleton, skeletonOptions } from "./skeleton.js";
59
67
  export { Spinner } from "./spinner.js";
60
68
  export { Item, itemOptions } from "./item.js";
61
69
  export { ChoiceGroup } from "./choice-group.js";
62
- export { CodeBlock } from "./code-block.js";
70
+ export { CodeBlock, codeLanguageName } from "./code-block.js";
63
71
  export { MermaidDiagram, } from "./mermaid-diagram.js";
64
72
  export { layoutOptions } from "./layout-types.js";
65
73
  export { SegmentedControl, } from "./segmented-control.js";
@@ -95,6 +103,8 @@ export { RailSection } from "./rail-section.js";
95
103
  export { DetailSection } from "./detail-section.js";
96
104
  export { Timeline } from "./timeline.js";
97
105
  export { TimelineItem } from "./timeline.js";
106
+ export { Entry, EntryList } from "./entry.js";
107
+ export { entryOptions } from "./entry.options.js";
98
108
  export { ResourceLink } from "./resource-link.js";
99
109
  export { Page } from "./page.js";
100
110
  export { PageHeader } from "./page-header.js";
@@ -0,0 +1,27 @@
1
+ /** Only explicit external and mail links navigate; everything else stays text. */
2
+ export declare function safeMarkdownLink(href: string): string | undefined;
3
+ /** Raw HTML and images are text. Only explicit safe external links become navigation. */
4
+ export declare function renderMarkdown(text: string): string;
5
+ /**
6
+ * Complete the open tail of streamed Markdown so incomplete syntax does not flash as raw markers:
7
+ * close an unclosed code span, `**`, `~~` or `*` in the last paragraph, and show a half-typed link
8
+ * as its text. Text inside an open fence, an indented code block, a code span or a URL is left
9
+ * alone; `_` and `__` are not repaired, so snake_case never gains a marker.
10
+ */
11
+ export declare function repairMarkdownTail(text: string): string;
12
+ export interface MarkdownBlock {
13
+ /** Stable while the block keeps its position and element. */
14
+ key: string;
15
+ /** The block's own element; its attributes come from the token, never from parsed HTML. */
16
+ tag: "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "ul" | "ol" | "pre" | "blockquote" | "hr" | "table";
17
+ start?: number;
18
+ /** Safe inner HTML from the shared renderer. */
19
+ html: string;
20
+ /** Set for fenced and indented code, so a host can draw it itself. */
21
+ code?: {
22
+ code: string;
23
+ language: string | undefined;
24
+ };
25
+ }
26
+ /** Top-level blocks of the text; link definitions anywhere apply to every block. */
27
+ export declare function markdownBlocks(text: string): readonly MarkdownBlock[];
@@ -0,0 +1,141 @@
1
+ import { Marked, Renderer } from "marked";
2
+ const escape = (text) => text.replace(/[&<>"']/g, (value) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[value]);
3
+ /** Only explicit external and mail links navigate; everything else stays text. */
4
+ export function safeMarkdownLink(href) {
5
+ try {
6
+ const url = new URL(href);
7
+ return ["http:", "https:", "mailto:"].includes(url.protocol) ? url.href : undefined;
8
+ }
9
+ catch {
10
+ return undefined;
11
+ }
12
+ }
13
+ const renderer = new Renderer();
14
+ renderer.html = ({ text }) => escape(text);
15
+ renderer.image = ({ text }) => escape(text);
16
+ renderer.link = function ({ href, title, tokens }) {
17
+ const label = this.parser.parseInline(tokens);
18
+ const link = safeMarkdownLink(href);
19
+ return link
20
+ ? `<a href="${escape(link)}" target="_blank" rel="noreferrer"${title ? ` title="${escape(title)}"` : ""}>${label}</a>`
21
+ : label;
22
+ };
23
+ const markdown = new Marked({ renderer, gfm: true, breaks: true });
24
+ /** Raw HTML and images are text. Only explicit safe external links become navigation. */
25
+ export function renderMarkdown(text) {
26
+ return markdown.parse(text, { async: false });
27
+ }
28
+ /** Replace a match with spaces, so positions in the rest of the string stay put. */
29
+ function blank(text, pattern) {
30
+ return text.replace(pattern, (match) => " ".repeat(match.length));
31
+ }
32
+ /**
33
+ * Complete the open tail of streamed Markdown so incomplete syntax does not flash as raw markers:
34
+ * close an unclosed code span, `**`, `~~` or `*` in the last paragraph, and show a half-typed link
35
+ * as its text. Text inside an open fence, an indented code block, a code span or a URL is left
36
+ * alone; `_` and `__` are not repaired, so snake_case never gains a marker.
37
+ */
38
+ export function repairMarkdownTail(text) {
39
+ const fences = text.match(/^ {0,3}(?:```|~~~)/gm)?.length ?? 0;
40
+ if (fences % 2 === 1)
41
+ return text;
42
+ const split = text.lastIndexOf("\n\n");
43
+ const head = split < 0 ? "" : text.slice(0, split + 2);
44
+ let tail = split < 0 ? text : text.slice(split + 2);
45
+ if (/^(?: {4}|\t)/.test(tail))
46
+ return text;
47
+ // A link whose target is still arriving reads as its text until it closes. Only `](` marks a
48
+ // link; `[1]`, `[ ]` and `array[0` are ordinary text.
49
+ tail = tail.replace(/!?\[([^\]\n]*)\]\([^)\n]*$/, "$1");
50
+ // Close an open code span first; markers inside code are not emphasis.
51
+ const ticks = (tail.match(/`/g) ?? []).length;
52
+ if (ticks % 2 === 1)
53
+ return head + tail + "`";
54
+ let scan = blank(tail, /`[^`]*`/g);
55
+ // Markers inside URLs and autolinks are part of the address.
56
+ scan = blank(scan, /<[^>\s]*>|\b(?:https?:\/\/|mailto:)\S*/g);
57
+ // Bullets, spaced operators ("5 * 3") and escapes are not emphasis.
58
+ scan = blank(scan, /^[ \t]*[*+-][ \t]/gm);
59
+ scan = blank(scan, /\\[*~`_]/g);
60
+ scan = blank(scan, /(?<=\s)(?:\*\*|\*|~~)(?=\s)/g);
61
+ const open = [];
62
+ for (const marker of ["**", "~~"]) {
63
+ const count = scan.split(marker).length - 1;
64
+ if (count % 2 === 1)
65
+ open.push({ marker, at: scan.lastIndexOf(marker) });
66
+ scan = blank(scan, new RegExp(marker.replace(/[*~]/g, "\\$&"), "g"));
67
+ }
68
+ const singles = (scan.match(/\*/g) ?? []).length;
69
+ if (singles % 2 === 1)
70
+ open.push({ marker: "*", at: scan.lastIndexOf("*") });
71
+ if (open.length === 0)
72
+ return head + tail;
73
+ // Close the innermost opener first; a closing marker cannot follow a space.
74
+ open.sort((left, right) => right.at - left.at);
75
+ const content = tail.trimEnd();
76
+ // An opener with nothing after it yet is dropped rather than closed around nothing.
77
+ if (open.some((entry) => entry.at + entry.marker.length >= content.length))
78
+ return repairMarkdownTail(head + content.slice(0, open[0].at).trimEnd());
79
+ return head + content + open.map((entry) => entry.marker).join("");
80
+ }
81
+ function tagFor(token) {
82
+ switch (token.type) {
83
+ case "paragraph":
84
+ case "text":
85
+ case "html":
86
+ return "p";
87
+ case "heading":
88
+ return `h${Math.min(6, Math.max(1, token.depth))}`;
89
+ case "list":
90
+ return token.ordered ? "ol" : "ul";
91
+ case "code":
92
+ return "pre";
93
+ case "blockquote":
94
+ return "blockquote";
95
+ case "hr":
96
+ return "hr";
97
+ case "table":
98
+ return "table";
99
+ default:
100
+ return undefined;
101
+ }
102
+ }
103
+ /** Strip the one element the renderer wrapped the block in, keeping its safe content. */
104
+ function innerOf(html, tag) {
105
+ const trimmed = html.trim();
106
+ if (tag === "hr")
107
+ return "";
108
+ const open = new RegExp(`^<${tag}(?:\\s[^>]*)?>`);
109
+ const close = `</${tag}>`;
110
+ if (open.test(trimmed) && trimmed.endsWith(close))
111
+ return trimmed.replace(open, "").slice(0, -close.length);
112
+ // A block the renderer did not wrap (escaped raw HTML) is its own text.
113
+ return trimmed;
114
+ }
115
+ /** Top-level blocks of the text; link definitions anywhere apply to every block. */
116
+ export function markdownBlocks(text) {
117
+ const tokens = markdown.lexer(text);
118
+ const blocks = [];
119
+ for (const token of tokens) {
120
+ const tag = tagFor(token);
121
+ if (!tag)
122
+ continue;
123
+ const single = Object.assign([token], { links: tokens.links });
124
+ const html = innerOf(markdown.parser(single), tag);
125
+ const index = blocks.length;
126
+ const start = tag === "ol" && typeof token.start === "number"
127
+ ? token.start
128
+ : undefined;
129
+ const code = token.type === "code"
130
+ ? { code: token.text, language: token.lang || undefined }
131
+ : undefined;
132
+ blocks.push({
133
+ key: `${index}:${tag}${start === undefined || start === 1 ? "" : `:${start}`}`,
134
+ tag,
135
+ ...(start === undefined || start === 1 ? {} : { start }),
136
+ html,
137
+ ...(code ? { code } : {}),
138
+ });
139
+ }
140
+ return blocks;
141
+ }
@@ -0,0 +1,35 @@
1
+ import { type Child, type Context, type Props } from "meowjsx";
2
+ import { type MaybeSignal, type ReadableSignal } from "meowjsx/signal";
3
+ export { markdownBlocks, renderMarkdown, repairMarkdownTail, safeMarkdownLink, type MarkdownBlock, } from "./markdown-blocks.js";
4
+ export interface MarkdownCodeBlock {
5
+ code: string;
6
+ language: string | undefined;
7
+ }
8
+ export interface MarkdownProps extends Props {
9
+ /** Markdown source; a Signal keeps it live while it streams. */
10
+ text: MaybeSignal<string>;
11
+ /** The text is still arriving: the open tail is completed so markers do not flash. */
12
+ streaming?: MaybeSignal<boolean>;
13
+ /**
14
+ * Draws a fenced or indented code block, for example with CodeBlock. The Signal follows the
15
+ * block while it streams. Without it, code is a themed `pre`.
16
+ */
17
+ renderCode?: (block: ReadableSignal<MarkdownCodeBlock>) => Child;
18
+ className?: Props["className"];
19
+ }
20
+ /**
21
+ * Renders Markdown blocks, each block keyed by its position and element. Hosts call it inside
22
+ * their own component; `part` names the carrier of each block.
23
+ */
24
+ export declare function markdownBlockChildren(text: MaybeSignal<string>, streaming: MaybeSignal<boolean>, renderCode: MarkdownProps["renderCode"], part: Props["ref"]): Child;
25
+ /**
26
+ * Agent or document text as safe Markdown: raw HTML and images stay text and only explicit
27
+ * external links navigate. Streaming text keeps finished blocks untouched.
28
+ */
29
+ export declare function Markdown({ text, streaming, renderCode, className, ref, ...props }: MarkdownProps, context: Context<typeof Markdown>): import("meowjsx").VNode;
30
+ export declare namespace Markdown {
31
+ var meta: {
32
+ readonly name: "markdown";
33
+ readonly parts: readonly ["root", "block"];
34
+ };
35
+ }
@@ -0,0 +1,35 @@
1
+ import { h, keyed } from "meowjsx";
2
+ import { derived, mapSignal, unwrap } from "meowjsx/signal";
3
+ import { markdownBlocks, repairMarkdownTail } from "./markdown-blocks.js";
4
+ export { markdownBlocks, renderMarkdown, repairMarkdownTail, safeMarkdownLink, } from "./markdown-blocks.js";
5
+ /**
6
+ * Renders Markdown blocks, each block keyed by its position and element. Hosts call it inside
7
+ * their own component; `part` names the carrier of each block.
8
+ */
9
+ export function markdownBlockChildren(text, streaming, renderCode, part) {
10
+ const blocks = derived(() => {
11
+ const source = unwrap(text);
12
+ return markdownBlocks(unwrap(streaming) ? repairMarkdownTail(source) : source);
13
+ });
14
+ return keyed(blocks, (block) => (renderCode && block.code ? `${block.key}:custom` : block.key), (block) => {
15
+ const first = block.value;
16
+ if (renderCode && first.code)
17
+ return renderCode(derived(() => block.value.code ?? { code: "", language: undefined }));
18
+ // Only this block's own output is written, so selections in other blocks survive.
19
+ // The string is compared first: an unchanged block is never rewritten.
20
+ const html = mapSignal(derived(() => block.value.html), (value) => ({ __html: value }));
21
+ return h(first.tag, {
22
+ ...(first.start === undefined ? {} : { start: first.start }),
23
+ ...(first.tag === "hr" ? {} : { dangerouslySetInnerHTML: html }),
24
+ ref: part,
25
+ });
26
+ });
27
+ }
28
+ /**
29
+ * Agent or document text as safe Markdown: raw HTML and images stay text and only explicit
30
+ * external links navigate. Streaming text keeps finished blocks untouched.
31
+ */
32
+ export function Markdown({ text, streaming = false, renderCode, className, ref, ...props }, context) {
33
+ return (h("div", { ...props, className: className, "aria-busy": derived(() => (unwrap(streaming) ? "true" : undefined)), ref: [context.parts.root, ref] }, markdownBlockChildren(text, streaming, renderCode, context.parts.block)));
34
+ }
35
+ Markdown.meta = { name: "markdown", parts: ["root", "block"] };
@@ -3,7 +3,8 @@ import { type MaybeSignal } from "meowjsx/signal";
3
3
  import { type ButtonProps } from "./button.js";
4
4
  import { type MenuEntry } from "./menu.js";
5
5
  export interface MenuButtonProps extends Omit<ButtonProps, "id" | "onClick"> {
6
- id: string;
6
+ /** Base id for the ARIA references this component wires; generated when omitted. */
7
+ id?: string;
7
8
  items: readonly MenuEntry[];
8
9
  open?: MaybeSignal<boolean>;
9
10
  onOpenChange?: (open: boolean) => void;