@firetail/finchly-ux 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +267 -2
  2. package/dist/components/action-button.d.ts +12 -0
  3. package/dist/components/action-button.js +34 -0
  4. package/dist/components/action-button.js.map +1 -0
  5. package/dist/components/app-shell.d.ts +18 -0
  6. package/dist/components/app-shell.js +56 -0
  7. package/dist/components/app-shell.js.map +1 -0
  8. package/dist/components/ask.d.ts +37 -0
  9. package/dist/components/ask.js +73 -0
  10. package/dist/components/ask.js.map +1 -0
  11. package/dist/components/bar.d.ts +11 -0
  12. package/dist/components/bar.js +187 -0
  13. package/dist/components/bar.js.map +1 -0
  14. package/dist/components/choosing.d.ts +18 -0
  15. package/dist/components/choosing.js +68 -0
  16. package/dist/components/choosing.js.map +1 -0
  17. package/dist/components/column-chart.d.ts +50 -0
  18. package/dist/components/column-chart.js +181 -0
  19. package/dist/components/column-chart.js.map +1 -0
  20. package/dist/components/composing.d.ts +40 -0
  21. package/dist/components/composing.js +101 -0
  22. package/dist/components/composing.js.map +1 -0
  23. package/dist/components/conversation.d.ts +50 -0
  24. package/dist/components/conversation.js +116 -0
  25. package/dist/components/conversation.js.map +1 -0
  26. package/dist/components/data-table.d.ts +43 -0
  27. package/dist/components/data-table.js +212 -0
  28. package/dist/components/data-table.js.map +1 -0
  29. package/dist/components/fields.d.ts +61 -0
  30. package/dist/components/fields.js +144 -0
  31. package/dist/components/fields.js.map +1 -0
  32. package/dist/components/file-button.d.ts +16 -0
  33. package/dist/components/file-button.js +39 -0
  34. package/dist/components/file-button.js.map +1 -0
  35. package/dist/components/form-dialog.d.ts +51 -0
  36. package/dist/components/form-dialog.js +113 -0
  37. package/dist/components/form-dialog.js.map +1 -0
  38. package/dist/components/link-button.d.ts +5 -0
  39. package/dist/components/link-button.js +24 -0
  40. package/dist/components/link-button.js.map +1 -0
  41. package/dist/components/link-tabs.d.ts +13 -0
  42. package/dist/components/link-tabs.js +26 -0
  43. package/dist/components/link-tabs.js.map +1 -0
  44. package/dist/components/markdown.d.ts +13 -0
  45. package/dist/components/markdown.js +132 -0
  46. package/dist/components/markdown.js.map +1 -0
  47. package/dist/components/page.d.ts +18 -0
  48. package/dist/components/page.js +45 -0
  49. package/dist/components/page.js.map +1 -0
  50. package/dist/components/palette.d.ts +16 -0
  51. package/dist/components/palette.js +27 -0
  52. package/dist/components/palette.js.map +1 -0
  53. package/dist/components/panel.d.ts +12 -0
  54. package/dist/components/panel.js +30 -0
  55. package/dist/components/panel.js.map +1 -0
  56. package/dist/components/pick-tile.d.ts +21 -0
  57. package/dist/components/pick-tile.js +40 -0
  58. package/dist/components/pick-tile.js.map +1 -0
  59. package/dist/components/provider-mark.d.ts +33 -0
  60. package/dist/components/provider-mark.js +58 -0
  61. package/dist/components/provider-mark.js.map +1 -0
  62. package/dist/components/provider.d.ts +17 -0
  63. package/dist/components/provider.js +39 -0
  64. package/dist/components/provider.js.map +1 -0
  65. package/dist/components/rows.d.ts +48 -0
  66. package/dist/components/rows.js +112 -0
  67. package/dist/components/rows.js.map +1 -0
  68. package/dist/components/side-nav.d.ts +23 -0
  69. package/dist/components/side-nav.js +41 -0
  70. package/dist/components/side-nav.js.map +1 -0
  71. package/dist/components/states.d.ts +19 -0
  72. package/dist/components/states.js +45 -0
  73. package/dist/components/states.js.map +1 -0
  74. package/dist/components/suggest-field.d.ts +19 -0
  75. package/dist/components/suggest-field.js +124 -0
  76. package/dist/components/suggest-field.js.map +1 -0
  77. package/dist/components/tag.d.ts +27 -0
  78. package/dist/components/tag.js +38 -0
  79. package/dist/components/tag.js.map +1 -0
  80. package/dist/components/text.d.ts +41 -0
  81. package/dist/components/text.js +97 -0
  82. package/dist/components/text.js.map +1 -0
  83. package/dist/components/tile.d.ts +30 -0
  84. package/dist/components/tile.js +68 -0
  85. package/dist/components/tile.js.map +1 -0
  86. package/dist/components/toast.d.ts +10 -0
  87. package/dist/components/toast.js +38 -0
  88. package/dist/components/toast.js.map +1 -0
  89. package/dist/components/ui/alert-dialog.d.ts +18 -0
  90. package/dist/components/ui/alert.d.ts +10 -0
  91. package/dist/components/ui/badge.d.ts +7 -0
  92. package/dist/components/ui/button.d.ts +8 -0
  93. package/dist/components/ui/button.js +45 -0
  94. package/dist/components/ui/button.js.map +1 -0
  95. package/dist/components/ui/card.d.ts +11 -0
  96. package/dist/components/ui/card.js +57 -0
  97. package/dist/components/ui/card.js.map +1 -0
  98. package/dist/components/ui/checkbox.d.ts +3 -0
  99. package/dist/components/ui/checkbox.js +20 -0
  100. package/dist/components/ui/checkbox.js.map +1 -0
  101. package/dist/components/ui/collapsible.d.ts +5 -0
  102. package/dist/components/ui/collapsible.js +24 -0
  103. package/dist/components/ui/collapsible.js.map +1 -0
  104. package/dist/components/ui/dialog.d.ts +17 -0
  105. package/dist/components/ui/dialog.js +92 -0
  106. package/dist/components/ui/dialog.js.map +1 -0
  107. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  108. package/dist/components/ui/dropdown-menu.js +65 -0
  109. package/dist/components/ui/dropdown-menu.js.map +1 -0
  110. package/dist/components/ui/empty.d.ts +11 -0
  111. package/dist/components/ui/field.d.ts +24 -0
  112. package/dist/components/ui/field.js +89 -0
  113. package/dist/components/ui/field.js.map +1 -0
  114. package/dist/components/ui/input.d.ts +3 -0
  115. package/dist/components/ui/input.js +16 -0
  116. package/dist/components/ui/input.js.map +1 -0
  117. package/dist/components/ui/label.d.ts +3 -0
  118. package/dist/components/ui/label.js +14 -0
  119. package/dist/components/ui/label.js.map +1 -0
  120. package/dist/components/ui/native-select.d.ts +8 -0
  121. package/dist/components/ui/native-select.js +39 -0
  122. package/dist/components/ui/native-select.js.map +1 -0
  123. package/dist/components/ui/radio-group.d.ts +5 -0
  124. package/dist/components/ui/radio-group.js +27 -0
  125. package/dist/components/ui/radio-group.js.map +1 -0
  126. package/dist/components/ui/separator.d.ts +3 -0
  127. package/dist/components/ui/separator.js +15 -0
  128. package/dist/components/ui/separator.js.map +1 -0
  129. package/dist/components/ui/skeleton.d.ts +2 -0
  130. package/dist/components/ui/skeleton.js +13 -0
  131. package/dist/components/ui/skeleton.js.map +1 -0
  132. package/dist/components/ui/spinner.d.ts +2 -0
  133. package/dist/components/ui/spinner.js +16 -0
  134. package/dist/components/ui/spinner.js.map +1 -0
  135. package/dist/components/ui/table.d.ts +10 -0
  136. package/dist/components/ui/table.js +53 -0
  137. package/dist/components/ui/table.js.map +1 -0
  138. package/dist/components/ui/textarea.d.ts +3 -0
  139. package/dist/components/ui/textarea.js +14 -0
  140. package/dist/components/ui/textarea.js.map +1 -0
  141. package/dist/components/ui/tooltip.d.ts +6 -0
  142. package/dist/components/ui/tooltip.js +41 -0
  143. package/dist/components/ui/tooltip.js.map +1 -0
  144. package/dist/icons.d.ts +1 -0
  145. package/dist/icons.js +1 -0
  146. package/dist/index.d.ts +55 -0
  147. package/dist/index.js +56 -0
  148. package/dist/lib/api.d.ts +49 -0
  149. package/dist/lib/api.js +80 -0
  150. package/dist/lib/api.js.map +1 -0
  151. package/dist/lib/chart.d.ts +35 -0
  152. package/dist/lib/chart.js +86 -0
  153. package/dist/lib/chart.js.map +1 -0
  154. package/dist/lib/cn.d.ts +3 -0
  155. package/dist/lib/cn.js +10 -0
  156. package/dist/lib/cn.js.map +1 -0
  157. package/dist/lib/events.d.ts +34 -0
  158. package/dist/lib/events.js +72 -0
  159. package/dist/lib/events.js.map +1 -0
  160. package/dist/lib/format.d.ts +16 -0
  161. package/dist/lib/format.js +71 -0
  162. package/dist/lib/format.js.map +1 -0
  163. package/dist/lib/hash.d.ts +2 -0
  164. package/dist/lib/hash.js +13 -0
  165. package/dist/lib/hash.js.map +1 -0
  166. package/dist/lib/launcher.d.ts +54 -0
  167. package/dist/lib/launcher.js +46 -0
  168. package/dist/lib/launcher.js.map +1 -0
  169. package/dist/lib/markdown-inline.d.ts +18 -0
  170. package/dist/lib/markdown-inline.js +155 -0
  171. package/dist/lib/markdown-inline.js.map +1 -0
  172. package/dist/lib/markdown.d.ts +40 -0
  173. package/dist/lib/markdown.js +198 -0
  174. package/dist/lib/markdown.js.map +1 -0
  175. package/dist/lib/marks.d.ts +17 -0
  176. package/dist/lib/marks.js +54 -0
  177. package/dist/lib/marks.js.map +1 -0
  178. package/dist/lib/over.d.ts +26 -0
  179. package/dist/lib/over.js +38 -0
  180. package/dist/lib/over.js.map +1 -0
  181. package/dist/lib/route.d.ts +15 -0
  182. package/dist/lib/route.js +29 -0
  183. package/dist/lib/route.js.map +1 -0
  184. package/dist/lib/table.d.ts +43 -0
  185. package/dist/lib/table.js +86 -0
  186. package/dist/lib/table.js.map +1 -0
  187. package/dist/lib/theme.d.ts +12 -0
  188. package/dist/lib/theme.js +42 -0
  189. package/dist/lib/theme.js.map +1 -0
  190. package/eslint/index.d.ts +8 -0
  191. package/eslint/index.js +135 -0
  192. package/eslint/page-imports.js +46 -0
  193. package/package.json +91 -4
  194. package/styles/styles.css +221 -0
  195. package/styles/tokens.css +99 -0
  196. package/tsconfig.app.json +21 -0
  197. package/vite/index.d.ts +16 -0
  198. package/vite/index.js +84 -0
@@ -0,0 +1,144 @@
1
+ import { Checkbox } from "./ui/checkbox.js";
2
+ import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from "./ui/field.js";
3
+ import { Input } from "./ui/input.js";
4
+ import { Textarea } from "./ui/textarea.js";
5
+ import { NativeSelect, NativeSelectOption } from "./ui/native-select.js";
6
+ import { RadioGroup, RadioGroupItem } from "./ui/radio-group.js";
7
+ import { useId } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ // src/components/fields.tsx
10
+ /** A labelled input. `hint` is said below it. Its value is read by name, from the form it is in. */
11
+ function TextField({ label, hint, ...input }) {
12
+ const id = useId();
13
+ return /* @__PURE__ */ jsxs(Field, { children: [
14
+ /* @__PURE__ */ jsx(FieldLabel, {
15
+ htmlFor: id,
16
+ children: label
17
+ }),
18
+ /* @__PURE__ */ jsx(Input, {
19
+ id,
20
+ autoComplete: "off",
21
+ ...input
22
+ }),
23
+ hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null
24
+ ] });
25
+ }
26
+ /** A labelled choice of one from a few. `options` are pairs of a value and what it is called. */
27
+ function SelectField({ label, hint, options, ...select }) {
28
+ const id = useId();
29
+ return /* @__PURE__ */ jsxs(Field, { children: [
30
+ /* @__PURE__ */ jsx(FieldLabel, {
31
+ htmlFor: id,
32
+ children: label
33
+ }),
34
+ /* @__PURE__ */ jsx(NativeSelect, {
35
+ id,
36
+ ...select,
37
+ children: options.map(([value, name]) => /* @__PURE__ */ jsx(NativeSelectOption, {
38
+ value,
39
+ children: name
40
+ }, value))
41
+ }),
42
+ hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null
43
+ ] });
44
+ }
45
+ /** A labelled box for several lines. */
46
+ function TextareaField({ label, hint, ...textarea }) {
47
+ const id = useId();
48
+ return /* @__PURE__ */ jsxs(Field, { children: [
49
+ /* @__PURE__ */ jsx(FieldLabel, {
50
+ htmlFor: id,
51
+ children: label
52
+ }),
53
+ /* @__PURE__ */ jsx(Textarea, {
54
+ id,
55
+ ...textarea
56
+ }),
57
+ hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null
58
+ ] });
59
+ }
60
+ /** Something that is so or is not, with its label beside it. */
61
+ function CheckboxField({ label, hint, ...checkbox }) {
62
+ const id = useId();
63
+ return /* @__PURE__ */ jsxs(Field, {
64
+ orientation: "horizontal",
65
+ children: [/* @__PURE__ */ jsx(Checkbox, {
66
+ id,
67
+ ...checkbox
68
+ }), /* @__PURE__ */ jsxs(FieldContent, { children: [/* @__PURE__ */ jsx(FieldLabel, {
69
+ htmlFor: id,
70
+ children: label
71
+ }), hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null] })]
72
+ });
73
+ }
74
+ /**
75
+ * A labelled choice of any number from a list, all in sight. `value` is
76
+ * what is chosen, kept by the page.
77
+ *
78
+ * @param rows how many are in sight at once
79
+ */
80
+ function MultiSelectField({ label, hint, options, value, onChange, rows = 4, disabled = false }) {
81
+ const id = useId();
82
+ return /* @__PURE__ */ jsxs(Field, { children: [
83
+ /* @__PURE__ */ jsx(FieldLabel, {
84
+ htmlFor: id,
85
+ children: label
86
+ }),
87
+ /* @__PURE__ */ jsx("select", {
88
+ id,
89
+ multiple: true,
90
+ size: rows,
91
+ disabled,
92
+ value,
93
+ onChange: (event) => onChange([...event.target.selectedOptions].map((option) => option.value)),
94
+ className: "w-full min-w-0 rounded-lg border border-input bg-transparent px-1 py-1 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50",
95
+ children: options.map(([option, name]) => /* @__PURE__ */ jsx("option", {
96
+ value: option,
97
+ className: "rounded-sm px-1.5 py-0.5",
98
+ children: name
99
+ }, option))
100
+ }),
101
+ hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null
102
+ ] });
103
+ }
104
+ /**
105
+ * A labelled choice of one from a few, all in sight, each with a line
106
+ * about it (`about`). One that cannot be chosen is still shown, so that
107
+ * it can say why. `value` is what is chosen, kept by the page.
108
+ */
109
+ function RadioField({ label, hint, options, value, onChange, disabled = false }) {
110
+ const id = useId();
111
+ return /* @__PURE__ */ jsxs(FieldSet, {
112
+ className: "grid gap-1.5",
113
+ children: [
114
+ /* @__PURE__ */ jsx(FieldLegend, {
115
+ id,
116
+ variant: "label",
117
+ children: label
118
+ }),
119
+ /* @__PURE__ */ jsx(RadioGroup, {
120
+ "aria-labelledby": id,
121
+ value,
122
+ disabled,
123
+ onValueChange: (next) => onChange(next),
124
+ children: options.map((option) => /* @__PURE__ */ jsxs(Field, {
125
+ orientation: "horizontal",
126
+ "data-disabled": option.disabled || void 0,
127
+ children: [/* @__PURE__ */ jsx(RadioGroupItem, {
128
+ id: `${id}-${option.value}`,
129
+ value: option.value,
130
+ disabled: option.disabled
131
+ }), /* @__PURE__ */ jsxs(FieldContent, { children: [/* @__PURE__ */ jsx(FieldLabel, {
132
+ htmlFor: `${id}-${option.value}`,
133
+ className: "font-normal",
134
+ children: option.label
135
+ }), option.about ? /* @__PURE__ */ jsx(FieldDescription, { children: option.about }) : null] })]
136
+ }, option.value))
137
+ }),
138
+ hint ? /* @__PURE__ */ jsx(FieldDescription, { children: hint }) : null
139
+ ]
140
+ });
141
+ }
142
+ export { CheckboxField, MultiSelectField, RadioField, SelectField, TextField, TextareaField };
143
+
144
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.js","names":[],"sources":["../../src/components/fields.tsx"],"sourcesContent":["import { useId, type ComponentProps, type ReactNode } from \"react\";\nimport { Checkbox } from \"./ui/checkbox\";\nimport { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from \"./ui/field\";\nimport { Input } from \"./ui/input\";\nimport { Textarea } from \"./ui/textarea\";\nimport { NativeSelect, NativeSelectOption } from \"./ui/native-select\";\nimport { RadioGroup, RadioGroupItem } from \"./ui/radio-group\";\n\n/** A labelled input. `hint` is said below it. Its value is read by name, from the form it is in. */\nexport function TextField({ label, hint, ...input }: { label: string; hint?: ReactNode; name: string } & Omit<ComponentProps<typeof Input>, \"name\">) {\n const id = useId();\n return (\n <Field>\n <FieldLabel htmlFor={id}>{label}</FieldLabel>\n <Input id={id} autoComplete=\"off\" {...input} />\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </Field>\n );\n}\n\n/** A labelled choice of one from a few. `options` are pairs of a value and what it is called. */\nexport function SelectField({ label, hint, options, ...select }: { label: string; hint?: ReactNode; name: string; options: Array<[value: string, label: string]> } & Omit<ComponentProps<typeof NativeSelect>, \"name\" | \"children\">) {\n const id = useId();\n return (\n <Field>\n <FieldLabel htmlFor={id}>{label}</FieldLabel>\n <NativeSelect id={id} {...select}>\n {options.map(([value, name]) => (\n <NativeSelectOption key={value} value={value}>\n {name}\n </NativeSelectOption>\n ))}\n </NativeSelect>\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </Field>\n );\n}\n\n/** A labelled box for several lines. */\nexport function TextareaField({ label, hint, ...textarea }: { label: string; hint?: ReactNode } & ComponentProps<typeof Textarea>) {\n const id = useId();\n return (\n <Field>\n <FieldLabel htmlFor={id}>{label}</FieldLabel>\n <Textarea id={id} {...textarea} />\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </Field>\n );\n}\n\n/** Something that is so or is not, with its label beside it. */\nexport function CheckboxField({ label, hint, ...checkbox }: { label: string; hint?: ReactNode } & ComponentProps<typeof Checkbox>) {\n const id = useId();\n return (\n <Field orientation=\"horizontal\">\n <Checkbox id={id} {...checkbox} />\n <FieldContent>\n <FieldLabel htmlFor={id}>{label}</FieldLabel>\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </FieldContent>\n </Field>\n );\n}\n\n/**\n * A labelled choice of any number from a list, all in sight. `value` is\n * what is chosen, kept by the page.\n *\n * @param rows how many are in sight at once\n */\nexport function MultiSelectField({ label, hint, options, value, onChange, rows = 4, disabled = false }: { label: string; hint?: ReactNode; options: Array<[value: string, label: string]>; value: string[]; onChange: (value: string[]) => void; rows?: number; disabled?: boolean }) {\n const id = useId();\n return (\n <Field>\n <FieldLabel htmlFor={id}>{label}</FieldLabel>\n <select id={id} multiple size={rows} disabled={disabled} value={value} onChange={(event) => onChange([...event.target.selectedOptions].map((option) => option.value))} className=\"w-full min-w-0 rounded-lg border border-input bg-transparent px-1 py-1 text-sm outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50\">\n {options.map(([option, name]) => (\n <option key={option} value={option} className=\"rounded-sm px-1.5 py-0.5\">\n {name}\n </option>\n ))}\n </select>\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </Field>\n );\n}\n\n/**\n * A labelled choice of one from a few, all in sight, each with a line\n * about it (`about`). One that cannot be chosen is still shown, so that\n * it can say why. `value` is what is chosen, kept by the page.\n */\nexport function RadioField<Value extends string>({ label, hint, options, value, onChange, disabled = false }: { label: string; hint?: ReactNode; options: Array<{ value: Value; label: string; about?: ReactNode; disabled?: boolean }>; value: Value; onChange: (value: Value) => void; disabled?: boolean }) {\n const id = useId();\n return (\n <FieldSet className=\"grid gap-1.5\">\n <FieldLegend id={id} variant=\"label\">\n {label}\n </FieldLegend>\n <RadioGroup aria-labelledby={id} value={value} disabled={disabled} onValueChange={(next) => onChange(next as Value)}>\n {options.map((option) => (\n <Field key={option.value} orientation=\"horizontal\" data-disabled={option.disabled || undefined}>\n <RadioGroupItem id={`${id}-${option.value}`} value={option.value} disabled={option.disabled} />\n <FieldContent>\n <FieldLabel htmlFor={`${id}-${option.value}`} className=\"font-normal\">\n {option.label}\n </FieldLabel>\n {option.about ? <FieldDescription>{option.about}</FieldDescription> : null}\n </FieldContent>\n </Field>\n ))}\n </RadioGroup>\n {hint ? <FieldDescription>{hint}</FieldDescription> : null}\n </FieldSet>\n );\n}\n"],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ import { type ComponentProps } from "react";
2
+ import { Button } from "./ui/button";
3
+ /**
4
+ * A button that chooses a file from the person's own device. The page is
5
+ * given the file, and decides what it is and what to do with it: nothing
6
+ * is sent anywhere by choosing.
7
+ *
8
+ * @param accept the kinds of file offered: types, as a file input takes them (`image/png,image/svg+xml`)
9
+ * @param onFile called with the file chosen. The same file can be chosen again straight after
10
+ * @param onFiles for a page that takes several at once: called with all that were chosen, in place of `onFile`
11
+ */
12
+ export declare function FileButton({ accept, onFile, onFiles, children, ...button }: {
13
+ accept?: string;
14
+ onFile?: (file: File) => void;
15
+ onFiles?: (files: File[]) => void;
16
+ } & Omit<ComponentProps<typeof Button>, "onClick">): import("react").JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { Button } from "./ui/button.js";
2
+ import { useRef } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/components/file-button.tsx
5
+ /**
6
+ * A button that chooses a file from the person's own device. The page is
7
+ * given the file, and decides what it is and what to do with it: nothing
8
+ * is sent anywhere by choosing.
9
+ *
10
+ * @param accept the kinds of file offered: types, as a file input takes them (`image/png,image/svg+xml`)
11
+ * @param onFile called with the file chosen. The same file can be chosen again straight after
12
+ * @param onFiles for a page that takes several at once: called with all that were chosen, in place of `onFile`
13
+ */
14
+ function FileButton({ accept, onFile, onFiles, children, ...button }) {
15
+ const picker = useRef(null);
16
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
17
+ ref: picker,
18
+ type: "file",
19
+ accept,
20
+ multiple: onFiles !== void 0,
21
+ hidden: true,
22
+ tabIndex: -1,
23
+ "aria-hidden": "true",
24
+ onChange: (event) => {
25
+ const files = [...event.target.files ?? []];
26
+ event.target.value = "";
27
+ if (files.length === 0) return;
28
+ if (onFiles) onFiles(files);
29
+ else if (files[0]) onFile?.(files[0]);
30
+ }
31
+ }), /* @__PURE__ */ jsx(Button, {
32
+ ...button,
33
+ onClick: () => picker.current?.click(),
34
+ children
35
+ })] });
36
+ }
37
+ export { FileButton };
38
+
39
+ //# sourceMappingURL=file-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-button.js","names":["_Fragment"],"sources":["../../src/components/file-button.tsx"],"sourcesContent":["import { useRef, type ComponentProps } from \"react\";\nimport { Button } from \"./ui/button\";\n\n/**\n * A button that chooses a file from the person's own device. The page is\n * given the file, and decides what it is and what to do with it: nothing\n * is sent anywhere by choosing.\n *\n * @param accept the kinds of file offered: types, as a file input takes them (`image/png,image/svg+xml`)\n * @param onFile called with the file chosen. The same file can be chosen again straight after\n * @param onFiles for a page that takes several at once: called with all that were chosen, in place of `onFile`\n */\nexport function FileButton({ accept, onFile, onFiles, children, ...button }: { accept?: string; onFile?: (file: File) => void; onFiles?: (files: File[]) => void } & Omit<ComponentProps<typeof Button>, \"onClick\">) {\n const picker = useRef<HTMLInputElement>(null);\n return (\n <>\n <input\n ref={picker}\n type=\"file\"\n accept={accept}\n multiple={onFiles !== undefined}\n hidden\n // Not for a screen reader, or to be tabbed to: the button is what is pressed.\n tabIndex={-1}\n aria-hidden=\"true\"\n onChange={(event) => {\n const files = [...(event.target.files ?? [])];\n event.target.value = \"\";\n if (files.length === 0) return;\n if (onFiles) onFiles(files);\n else if (files[0]) onFile?.(files[0]);\n }}\n />\n <Button {...button} onClick={() => picker.current?.click()}>\n {children}\n </Button>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,WAAW,EAAE,QAAQ,QAAQ,SAAS,UAAU,GAAG,UAAkJ;CACnN,MAAM,SAAS,OAAyB,IAAI;CAC5C,OACE,qBAAAA,UAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EACE,KAAK;EACL,MAAK;EACG;EACR,UAAU,YAAY,KAAA;EACtB,QAAA;EAEA,UAAU;EACV,eAAY;EACZ,WAAW,UAAU;GACnB,MAAM,QAAQ,CAAC,GAAI,MAAM,OAAO,SAAS,CAAC,CAAE;GAC5C,MAAM,OAAO,QAAQ;GACrB,IAAI,MAAM,WAAW,GAAG;GACxB,IAAI,SAAS,QAAQ,KAAK;QACrB,IAAI,MAAM,IAAI,SAAS,MAAM,EAAE;EACtC;CACD,CAAA,GACD,oBAAC,QAAD;EAAQ,GAAI;EAAQ,eAAe,OAAO,SAAS,MAAM;EACtD;CACK,CAAA,CACR,EAAA,CAAA;AAEN"}
@@ -0,0 +1,51 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ /** What a form's fields held when it was sent, by name. Text is trimmed. */
3
+ export type FormValues = Record<string, string>;
4
+ /**
5
+ * What a dialog holds between its title and its buttons. What does not
6
+ * fit is scrolled here, so that the title and the buttons stay in sight.
7
+ * FormDialog has one: a dialog a page lays out itself uses this.
8
+ */
9
+ export declare function DialogBody({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
10
+ interface FormDialogProps<Result> {
11
+ open: boolean;
12
+ /** The person backed out, or it was done. */
13
+ onClose: () => void;
14
+ title: string;
15
+ description?: ReactNode;
16
+ /** The label of the button that goes ahead. */
17
+ action?: string;
18
+ /** What that button says while it is being done: "Saving…". */
19
+ busyAction?: string;
20
+ /** Whether going ahead cannot be undone. */
21
+ danger?: boolean;
22
+ /** `lg` for a form with a good deal in it. What does not fit is scrolled, between the title and the buttons. */
23
+ size?: "default" | "lg";
24
+ /**
25
+ * Called when the person goes ahead. What it rejects with is shown in
26
+ * the dialog, which stays open. Left out, the dialog only shows
27
+ * something, and has one button that closes it.
28
+ */
29
+ submit?: (values: FormValues) => Promise<Result>;
30
+ /** Called with what `submit` resolved with, once the dialog has closed. */
31
+ onDone?: (result: Result) => void;
32
+ children?: ReactNode;
33
+ }
34
+ /**
35
+ * Ask the person something in a dialog: fields to fill in, or something
36
+ * to confirm. This is the one way a page asks. While what was asked for
37
+ * is being done, the dialog cannot be left: it closes when it is done,
38
+ * or says what went wrong.
39
+ */
40
+ export declare function FormDialog<Result = unknown>({ open, onClose, size, ...rest }: FormDialogProps<Result>): import("react").JSX.Element;
41
+ /** Ask before something that cannot be undone. `children` say what will happen, in a sentence. */
42
+ export declare function ConfirmDialog({ open, onClose, title, action, run, onDone, children }: {
43
+ open: boolean;
44
+ onClose: () => void;
45
+ title: string;
46
+ action: string;
47
+ run: () => Promise<unknown>;
48
+ onDone?: () => void;
49
+ children: ReactNode;
50
+ }): import("react").JSX.Element;
51
+ export {};
@@ -0,0 +1,113 @@
1
+ import { explain } from "../lib/api.js";
2
+ import { cn } from "../lib/cn.js";
3
+ import { Button } from "./ui/button.js";
4
+ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "./ui/dialog.js";
5
+ import { useRef, useState } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // src/components/form-dialog.tsx
8
+ /**
9
+ * What a dialog holds between its title and its buttons. What does not
10
+ * fit is scrolled here, so that the title and the buttons stay in sight.
11
+ * FormDialog has one: a dialog a page lays out itself uses this.
12
+ */
13
+ function DialogBody({ className, ...props }) {
14
+ return /* @__PURE__ */ jsx("div", {
15
+ "data-slot": "dialog-body",
16
+ className: cn("-mx-1 grid max-h-[70dvh] min-h-0 content-start gap-3 overflow-y-auto px-1 py-0.5", className),
17
+ ...props
18
+ });
19
+ }
20
+ /**
21
+ * Ask the person something in a dialog: fields to fill in, or something
22
+ * to confirm. This is the one way a page asks. While what was asked for
23
+ * is being done, the dialog cannot be left: it closes when it is done,
24
+ * or says what went wrong.
25
+ */
26
+ function FormDialog({ open, onClose, size = "default", ...rest }) {
27
+ const busy = useRef(false);
28
+ return /* @__PURE__ */ jsx(Dialog, {
29
+ open,
30
+ onOpenChange: (next) => {
31
+ if (!next && !busy.current) onClose();
32
+ },
33
+ children: /* @__PURE__ */ jsx(DialogContent, {
34
+ showCloseButton: false,
35
+ className: size === "lg" ? "sm:max-w-2xl" : "sm:max-w-md",
36
+ children: /* @__PURE__ */ jsx(Asking, {
37
+ onClose,
38
+ busyRef: busy,
39
+ ...rest
40
+ })
41
+ })
42
+ });
43
+ }
44
+ function Asking({ onClose, busyRef, title, description, action = "Save", busyAction, danger = false, submit, onDone, children }) {
45
+ const [busy, setBusy] = useState(false);
46
+ const [error, setError] = useState(null);
47
+ const failed = useRef(null);
48
+ const working = (now) => {
49
+ busyRef.current = now;
50
+ setBusy(now);
51
+ };
52
+ const send = async (event) => {
53
+ event.preventDefault();
54
+ if (!submit) return onClose();
55
+ if (busy) return;
56
+ const values = {};
57
+ for (const [name, value] of new FormData(event.currentTarget)) if (typeof value === "string") values[name] = value.trim();
58
+ working(true);
59
+ setError(null);
60
+ try {
61
+ const result = await submit(values);
62
+ busyRef.current = false;
63
+ onClose();
64
+ onDone?.(result);
65
+ } catch (err) {
66
+ setError(explain(err));
67
+ working(false);
68
+ requestAnimationFrame(() => failed.current?.scrollIntoView?.({ block: "nearest" }));
69
+ }
70
+ };
71
+ return /* @__PURE__ */ jsxs("form", {
72
+ onSubmit: send,
73
+ "aria-busy": busy,
74
+ className: "grid min-h-0 gap-4",
75
+ children: [
76
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: title }), description ? /* @__PURE__ */ jsx(DialogDescription, { children: description }) : null] }),
77
+ children || error ? /* @__PURE__ */ jsxs(DialogBody, { children: [children, error ? /* @__PURE__ */ jsx("p", {
78
+ ref: failed,
79
+ role: "alert",
80
+ className: "text-sm text-destructive",
81
+ children: error
82
+ }) : null] }) : null,
83
+ /* @__PURE__ */ jsxs(DialogFooter, { children: [/* @__PURE__ */ jsx(Button, {
84
+ type: "button",
85
+ variant: "outline",
86
+ disabled: busy,
87
+ onClick: onClose,
88
+ children: submit ? "Cancel" : "Close"
89
+ }), submit ? /* @__PURE__ */ jsx(Button, {
90
+ type: "submit",
91
+ variant: danger ? "destructive" : "default",
92
+ disabled: busy,
93
+ children: busy ? busyAction ?? action : action
94
+ }) : null] })
95
+ ]
96
+ });
97
+ }
98
+ /** Ask before something that cannot be undone. `children` say what will happen, in a sentence. */
99
+ function ConfirmDialog({ open, onClose, title, action, run, onDone, children }) {
100
+ return /* @__PURE__ */ jsx(FormDialog, {
101
+ open,
102
+ onClose,
103
+ title,
104
+ description: children,
105
+ action,
106
+ danger: true,
107
+ submit: run,
108
+ onDone: onDone ? () => onDone() : void 0
109
+ });
110
+ }
111
+ export { ConfirmDialog, DialogBody, FormDialog };
112
+
113
+ //# sourceMappingURL=form-dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-dialog.js","names":[],"sources":["../../src/components/form-dialog.tsx"],"sourcesContent":["import { useRef, useState, type ComponentProps, type FormEvent, type ReactNode, type RefObject } from \"react\";\nimport { explain } from \"../lib/api\";\nimport { cn } from \"../lib/cn\";\nimport { Button } from \"./ui/button\";\nimport { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from \"./ui/dialog\";\n\n/** What a form's fields held when it was sent, by name. Text is trimmed. */\nexport type FormValues = Record<string, string>;\n\n/**\n * What a dialog holds between its title and its buttons. What does not\n * fit is scrolled here, so that the title and the buttons stay in sight.\n * FormDialog has one: a dialog a page lays out itself uses this.\n */\nexport function DialogBody({ className, ...props }: ComponentProps<\"div\">) {\n return <div data-slot=\"dialog-body\" className={cn(\"-mx-1 grid max-h-[70dvh] min-h-0 content-start gap-3 overflow-y-auto px-1 py-0.5\", className)} {...props} />;\n}\n\ninterface FormDialogProps<Result> {\n open: boolean;\n /** The person backed out, or it was done. */\n onClose: () => void;\n title: string;\n description?: ReactNode;\n /** The label of the button that goes ahead. */\n action?: string;\n /** What that button says while it is being done: \"Saving…\". */\n busyAction?: string;\n /** Whether going ahead cannot be undone. */\n danger?: boolean;\n /** `lg` for a form with a good deal in it. What does not fit is scrolled, between the title and the buttons. */\n size?: \"default\" | \"lg\";\n /**\n * Called when the person goes ahead. What it rejects with is shown in\n * the dialog, which stays open. Left out, the dialog only shows\n * something, and has one button that closes it.\n */\n submit?: (values: FormValues) => Promise<Result>;\n /** Called with what `submit` resolved with, once the dialog has closed. */\n onDone?: (result: Result) => void;\n children?: ReactNode;\n}\n\n/**\n * Ask the person something in a dialog: fields to fill in, or something\n * to confirm. This is the one way a page asks. While what was asked for\n * is being done, the dialog cannot be left: it closes when it is done,\n * or says what went wrong.\n */\nexport function FormDialog<Result = unknown>({ open, onClose, size = \"default\", ...rest }: FormDialogProps<Result>) {\n const busy = useRef(false);\n return (\n <Dialog\n open={open}\n onOpenChange={(next) => {\n if (!next && !busy.current) onClose();\n }}\n >\n <DialogContent showCloseButton={false} className={size === \"lg\" ? \"sm:max-w-2xl\" : \"sm:max-w-md\"}>\n {/* Inside the content, which is there only while the dialog is open: what went wrong last time is not kept. */}\n <Asking onClose={onClose} busyRef={busy} {...rest} />\n </DialogContent>\n </Dialog>\n );\n}\n\nfunction Asking<Result>({ onClose, busyRef, title, description, action = \"Save\", busyAction, danger = false, submit, onDone, children }: Omit<FormDialogProps<Result>, \"open\" | \"size\"> & { busyRef: RefObject<boolean> }) {\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const failed = useRef<HTMLParagraphElement>(null);\n const working = (now: boolean) => {\n busyRef.current = now;\n setBusy(now);\n };\n\n const send = async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n if (!submit) return onClose();\n if (busy) return;\n const values: FormValues = {};\n for (const [name, value] of new FormData(event.currentTarget)) if (typeof value === \"string\") values[name] = value.trim();\n working(true);\n setError(null);\n try {\n const result = await submit(values);\n busyRef.current = false;\n onClose();\n onDone?.(result);\n } catch (err) {\n setError(explain(err));\n working(false);\n // In a long form, what went wrong is brought into sight.\n requestAnimationFrame(() => failed.current?.scrollIntoView?.({ block: \"nearest\" }));\n }\n };\n\n return (\n <form onSubmit={send} aria-busy={busy} className=\"grid min-h-0 gap-4\">\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n {description ? <DialogDescription>{description}</DialogDescription> : null}\n </DialogHeader>\n {children || error ? (\n <DialogBody>\n {children}\n {error ? (\n <p ref={failed} role=\"alert\" className=\"text-sm text-destructive\">\n {error}\n </p>\n ) : null}\n </DialogBody>\n ) : null}\n <DialogFooter>\n <Button type=\"button\" variant=\"outline\" disabled={busy} onClick={onClose}>\n {submit ? \"Cancel\" : \"Close\"}\n </Button>\n {submit ? (\n <Button type=\"submit\" variant={danger ? \"destructive\" : \"default\"} disabled={busy}>\n {busy ? (busyAction ?? action) : action}\n </Button>\n ) : null}\n </DialogFooter>\n </form>\n );\n}\n\n/** Ask before something that cannot be undone. `children` say what will happen, in a sentence. */\nexport function ConfirmDialog({ open, onClose, title, action, run, onDone, children }: { open: boolean; onClose: () => void; title: string; action: string; run: () => Promise<unknown>; onDone?: () => void; children: ReactNode }) {\n return (\n <FormDialog open={open} onClose={onClose} title={title} description={children} action={action} danger submit={run} onDone={onDone ? () => onDone() : undefined} />\n );\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,WAAW,EAAE,WAAW,GAAG,SAAgC;CACzE,OAAO,oBAAC,OAAD;EAAK,aAAU;EAAc,WAAW,GAAG,oFAAoF,SAAS;EAAG,GAAI;CAAQ,CAAA;AAChK;;;;;;;AAiCA,SAAgB,WAA6B,EAAE,MAAM,SAAS,OAAO,WAAW,GAAG,QAAiC;CAClH,MAAM,OAAO,OAAO,KAAK;CACzB,OACE,oBAAC,QAAD;EACQ;EACN,eAAe,SAAS;GACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,QAAQ;EACtC;EAEA,UAAA,oBAAC,eAAD;GAAe,iBAAiB;GAAO,WAAW,SAAS,OAAO,iBAAiB;GAEjF,UAAA,oBAAC,QAAD;IAAiB;IAAS,SAAS;IAAM,GAAI;GAAO,CAAA;EACvC,CAAA;CACT,CAAA;AAEZ;AAEA,SAAS,OAAe,EAAE,SAAS,SAAS,OAAO,aAAa,SAAS,QAAQ,YAAY,SAAS,OAAO,QAAQ,QAAQ,YAA8F;CACzN,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CACtD,MAAM,SAAS,OAA6B,IAAI;CAChD,MAAM,WAAW,QAAiB;EAChC,QAAQ,UAAU;EAClB,QAAQ,GAAG;CACb;CAEA,MAAM,OAAO,OAAO,UAAsC;EACxD,MAAM,eAAe;EACrB,IAAI,CAAC,QAAQ,OAAO,QAAQ;EAC5B,IAAI,MAAM;EACV,MAAM,SAAqB,CAAC;EAC5B,KAAK,MAAM,CAAC,MAAM,UAAU,IAAI,SAAS,MAAM,aAAa,GAAG,IAAI,OAAO,UAAU,UAAU,OAAO,QAAQ,MAAM,KAAK;EACxH,QAAQ,IAAI;EACZ,SAAS,IAAI;EACb,IAAI;GACF,MAAM,SAAS,MAAM,OAAO,MAAM;GAClC,QAAQ,UAAU;GAClB,QAAQ;GACR,SAAS,MAAM;EACjB,SAAS,KAAK;GACZ,SAAS,QAAQ,GAAG,CAAC;GACrB,QAAQ,KAAK;GAEb,4BAA4B,OAAO,SAAS,iBAAiB,EAAE,OAAO,UAAU,CAAC,CAAC;EACpF;CACF;CAEA,OACE,qBAAC,QAAD;EAAM,UAAU;EAAM,aAAW;EAAM,WAAU;EAAjD,UAAA;GACE,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,aAAD,EAAA,UAAc,MAAmB,CAAA,GAChC,cAAc,oBAAC,mBAAD,EAAA,UAAoB,YAA+B,CAAA,IAAI,IAC1D,EAAA,CAAA;GACb,YAAY,QACX,qBAAC,YAAD,EAAA,UAAA,CACG,UACA,QACC,oBAAC,KAAD;IAAG,KAAK;IAAQ,MAAK;IAAQ,WAAU;IACpC,UAAA;GACA,CAAA,IACD,IACM,EAAA,CAAA,IACV;GACJ,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,QAAD;IAAQ,MAAK;IAAS,SAAQ;IAAU,UAAU;IAAM,SAAS;IAC9D,UAAA,SAAS,WAAW;GACf,CAAA,GACP,SACC,oBAAC,QAAD;IAAQ,MAAK;IAAS,SAAS,SAAS,gBAAgB;IAAW,UAAU;IAC1E,UAAA,OAAQ,cAAc,SAAU;GAC3B,CAAA,IACN,IACQ,EAAA,CAAA;EACV;;AAEV;;AAGA,SAAgB,cAAc,EAAE,MAAM,SAAS,OAAO,QAAQ,KAAK,QAAQ,YAA0J;CACnO,OACE,oBAAC,YAAD;EAAkB;EAAe;EAAgB;EAAO,aAAa;EAAkB;EAAQ,QAAA;EAAO,QAAQ;EAAK,QAAQ,eAAe,OAAO,IAAI,KAAA;CAAY,CAAA;AAErK"}
@@ -0,0 +1,5 @@
1
+ import type { ComponentProps } from "react";
2
+ import type { VariantProps } from "class-variance-authority";
3
+ import { buttonVariants } from "./ui/button";
4
+ /** A link that looks like a button: for going somewhere, where a Button is for doing something. */
5
+ export declare function LinkButton({ className, variant, size, ...props }: ComponentProps<"a"> & VariantProps<typeof buttonVariants>): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { cn } from "../lib/cn.js";
2
+ import { buttonVariants } from "./ui/button.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/components/link-button.tsx
5
+ /** A link is drawn in the accent unless told otherwise. One that looks like a button is drawn as that button is. */
6
+ var INK = {
7
+ outline: "text-foreground",
8
+ secondary: "text-secondary-foreground",
9
+ ghost: "text-muted-foreground"
10
+ };
11
+ /** A link that looks like a button: for going somewhere, where a Button is for doing something. */
12
+ function LinkButton({ className, variant = "outline", size = "default", ...props }) {
13
+ const drawn = variant ?? "outline";
14
+ return /* @__PURE__ */ jsx("a", {
15
+ className: cn(buttonVariants({
16
+ variant: drawn,
17
+ size
18
+ }), "no-underline", INK[drawn], className),
19
+ ...props
20
+ });
21
+ }
22
+ export { LinkButton };
23
+
24
+ //# sourceMappingURL=link-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-button.js","names":[],"sources":["../../src/components/link-button.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\";\nimport type { VariantProps } from \"class-variance-authority\";\nimport { cn } from \"../lib/cn\";\nimport { buttonVariants } from \"./ui/button\";\n\ntype Variant = NonNullable<VariantProps<typeof buttonVariants>[\"variant\"]>;\n\n/** A link is drawn in the accent unless told otherwise. One that looks like a button is drawn as that button is. */\nconst INK: Partial<Record<Variant, string>> = {\n outline: \"text-foreground\",\n secondary: \"text-secondary-foreground\",\n ghost: \"text-muted-foreground\",\n};\n\n/** A link that looks like a button: for going somewhere, where a Button is for doing something. */\nexport function LinkButton({ className, variant = \"outline\", size = \"default\", ...props }: ComponentProps<\"a\"> & VariantProps<typeof buttonVariants>) {\n const drawn = variant ?? \"outline\";\n return <a className={cn(buttonVariants({ variant: drawn, size }), \"no-underline\", INK[drawn], className)} {...props} />;\n}\n"],"mappings":";;;;;AAQA,IAAM,MAAwC;CAC5C,SAAS;CACT,WAAW;CACX,OAAO;AACT;;AAGA,SAAgB,WAAW,EAAE,WAAW,UAAU,WAAW,OAAO,WAAW,GAAG,SAAoE;CACpJ,MAAM,QAAQ,WAAW;CACzB,OAAO,oBAAC,KAAD;EAAG,WAAW,GAAG,eAAe;GAAE,SAAS;GAAO;EAAK,CAAC,GAAG,gBAAgB,IAAI,QAAQ,SAAS;EAAG,GAAI;CAAQ,CAAA;AACxH"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The parts of a page, as links: each has an address of its own
3
+ * (`#delivery`), so that it can be linked to and gone back to. Which is
4
+ * shown is read from the address with useHash().
5
+ *
6
+ * @param tabs pairs of what follows the `#` and what the part is called. A third thing is where the part is, where
7
+ * that is not `#` and its name: a part another page shows, while a page is replaced a part at a time
8
+ */
9
+ export declare function LinkTabs({ label, tabs, current }: {
10
+ label: string;
11
+ tabs: Array<[id: string, label: string, href?: string]>;
12
+ current: string;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { cn } from "../lib/cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/components/link-tabs.tsx
4
+ /**
5
+ * The parts of a page, as links: each has an address of its own
6
+ * (`#delivery`), so that it can be linked to and gone back to. Which is
7
+ * shown is read from the address with useHash().
8
+ *
9
+ * @param tabs pairs of what follows the `#` and what the part is called. A third thing is where the part is, where
10
+ * that is not `#` and its name: a part another page shows, while a page is replaced a part at a time
11
+ */
12
+ function LinkTabs({ label, tabs, current }) {
13
+ return /* @__PURE__ */ jsx("nav", {
14
+ "aria-label": label,
15
+ className: "flex gap-1 overflow-x-auto border-b",
16
+ children: tabs.map(([id, name, href]) => /* @__PURE__ */ jsx("a", {
17
+ href: href ?? `#${id}`,
18
+ "aria-current": id === current ? "page" : void 0,
19
+ className: cn("-mb-px border-b-2 border-transparent px-3 py-2 font-medium whitespace-nowrap text-muted-foreground no-underline hover:text-foreground", "aria-[current=page]:border-primary aria-[current=page]:text-primary"),
20
+ children: name
21
+ }, id))
22
+ });
23
+ }
24
+ export { LinkTabs };
25
+
26
+ //# sourceMappingURL=link-tabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-tabs.js","names":[],"sources":["../../src/components/link-tabs.tsx"],"sourcesContent":["import { cn } from \"../lib/cn\";\n\n/**\n * The parts of a page, as links: each has an address of its own\n * (`#delivery`), so that it can be linked to and gone back to. Which is\n * shown is read from the address with useHash().\n *\n * @param tabs pairs of what follows the `#` and what the part is called. A third thing is where the part is, where\n * that is not `#` and its name: a part another page shows, while a page is replaced a part at a time\n */\nexport function LinkTabs({ label, tabs, current }: { label: string; tabs: Array<[id: string, label: string, href?: string]>; current: string }) {\n return (\n <nav aria-label={label} className=\"flex gap-1 overflow-x-auto border-b\">\n {tabs.map(([id, name, href]) => (\n <a key={id} href={href ?? `#${id}`} aria-current={id === current ? \"page\" : undefined} className={cn(\"-mb-px border-b-2 border-transparent px-3 py-2 font-medium whitespace-nowrap text-muted-foreground no-underline hover:text-foreground\", \"aria-[current=page]:border-primary aria-[current=page]:text-primary\")}>\n {name}\n </a>\n ))}\n </nav>\n );\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,SAAS,EAAE,OAAO,MAAM,WAAwG;CAC9I,OACE,oBAAC,OAAD;EAAK,cAAY;EAAO,WAAU;EAC/B,UAAA,KAAK,KAAK,CAAC,IAAI,MAAM,UACpB,oBAAC,KAAD;GAAY,MAAM,QAAQ,IAAI;GAAM,gBAAc,OAAO,UAAU,SAAS,KAAA;GAAW,WAAW,GAAG,yIAAyI,qEAAqE;GAChT,UAAA;EACA,GAFK,EAEL,CACJ;CACE,CAAA;AAET"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Markdown, as a model writes it, shown as a page shows text: headings,
3
+ * lists, tables, code and links. Nothing of it is ever treated as HTML.
4
+ * A link leads only to the web or to a letter, and a picture is never
5
+ * fetched: it is shown as a link to it.
6
+ *
7
+ * It can be given again with more of an answer as it arrives: what is
8
+ * half written is drawn as far as it goes, and what was drawn before
9
+ * stays as it is, so that reading or selecting it is not disturbed.
10
+ */
11
+ export declare const Markdown: import("react").NamedExoticComponent<{
12
+ children: string | null | undefined;
13
+ }>;
@@ -0,0 +1,132 @@
1
+ import { cn } from "../lib/cn.js";
2
+ import { parseMarkdown } from "../lib/markdown.js";
3
+ import { memo, useMemo } from "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/components/markdown.tsx
6
+ /** What marks words, drawn. A link opens somewhere else, and is told nothing of where it was followed from. */
7
+ function Marked({ nodes }) {
8
+ return nodes.map((node, place) => {
9
+ if (typeof node === "string") return node;
10
+ if (node.type === "break") return /* @__PURE__ */ jsx("br", {}, place);
11
+ if (node.type === "code") return /* @__PURE__ */ jsx("code", {
12
+ className: "rounded-sm bg-muted px-1 py-0.5 font-mono text-[0.9em]",
13
+ children: node.text
14
+ }, place);
15
+ if (node.type === "link") return /* @__PURE__ */ jsx("a", {
16
+ href: node.href,
17
+ target: "_blank",
18
+ rel: "noopener noreferrer",
19
+ className: "underline underline-offset-2",
20
+ children: /* @__PURE__ */ jsx(Marked, { nodes: node.children })
21
+ }, place);
22
+ const Mark = node.type;
23
+ return /* @__PURE__ */ jsx(Mark, { children: /* @__PURE__ */ jsx(Marked, { nodes: node.children }) }, place);
24
+ });
25
+ }
26
+ var HEADINGS = [
27
+ "h3",
28
+ "h4",
29
+ "h5",
30
+ "h6",
31
+ "h6",
32
+ "h6"
33
+ ];
34
+ var SIZES = [
35
+ "text-xl",
36
+ "text-lg",
37
+ "text-base",
38
+ "text-base",
39
+ "text-base",
40
+ "text-base"
41
+ ];
42
+ var ALIGNED = {
43
+ left: "text-left",
44
+ right: "text-right",
45
+ center: "text-center"
46
+ };
47
+ /** Blocks, one under another. */
48
+ function Blocks({ blocks }) {
49
+ return blocks.map((block, place) => /* @__PURE__ */ jsx(Drawn, { block }, place));
50
+ }
51
+ /** One block, as the element it is. */
52
+ function Drawn({ block }) {
53
+ if (block.type === "paragraph") return /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(Marked, { nodes: block.inline }) });
54
+ if (block.type === "heading") {
55
+ const Heading = HEADINGS[block.level - 1] ?? "h6";
56
+ return /* @__PURE__ */ jsx(Heading, {
57
+ className: cn("leading-snug font-semibold not-first:mt-1.5", SIZES[block.level - 1]),
58
+ children: /* @__PURE__ */ jsx(Marked, { nodes: block.inline })
59
+ });
60
+ }
61
+ if (block.type === "rule") return /* @__PURE__ */ jsx("hr", { className: "border-t" });
62
+ if (block.type === "code") return /* @__PURE__ */ jsx("pre", {
63
+ tabIndex: 0,
64
+ "data-language": block.language ? block.language.slice(0, 40) : void 0,
65
+ className: "overflow-x-auto rounded-lg border border-input bg-muted px-3 py-2.5 text-sm leading-normal wrap-normal whitespace-pre",
66
+ children: /* @__PURE__ */ jsx("code", { children: block.text })
67
+ });
68
+ if (block.type === "quote") return /* @__PURE__ */ jsx("blockquote", {
69
+ className: "grid gap-3 border-l-4 border-input py-0.5 pl-3 text-muted-foreground *:min-w-0",
70
+ children: /* @__PURE__ */ jsx(Blocks, { blocks: block.blocks })
71
+ });
72
+ if (block.type === "list") {
73
+ const List = block.ordered ? "ol" : "ul";
74
+ return /* @__PURE__ */ jsx(List, {
75
+ start: block.ordered && block.start !== 1 && block.start !== null ? block.start : void 0,
76
+ className: cn("grid gap-1 pl-6 *:min-w-0", block.ordered ? "list-decimal" : "list-disc"),
77
+ children: block.items.map((item, place) => {
78
+ const [first, ...rest] = item.blocks;
79
+ return /* @__PURE__ */ jsxs("li", {
80
+ className: cn(item.checked !== null && "-ml-5 list-none", rest.length > 0 && "*:not-first:mt-1.5"),
81
+ children: [
82
+ item.checked === null ? null : /* @__PURE__ */ jsx("input", {
83
+ type: "checkbox",
84
+ disabled: true,
85
+ checked: item.checked,
86
+ "aria-label": item.checked ? "Done" : "Not done",
87
+ className: "mr-2 align-middle"
88
+ }),
89
+ first?.type === "paragraph" ? /* @__PURE__ */ jsx(Marked, { nodes: first.inline }) : first ? /* @__PURE__ */ jsx(Drawn, { block: first }) : null,
90
+ /* @__PURE__ */ jsx(Blocks, { blocks: rest })
91
+ ]
92
+ }, place);
93
+ })
94
+ });
95
+ }
96
+ const cell = (Cell, nodes, column) => {
97
+ const align = block.align[column];
98
+ return /* @__PURE__ */ jsx(Cell, {
99
+ className: cn("border px-2.5 py-1.5 align-top wrap-normal", Cell === "th" && "bg-muted font-semibold", align ? ALIGNED[align] : "text-left"),
100
+ children: /* @__PURE__ */ jsx(Marked, { nodes })
101
+ }, column);
102
+ };
103
+ return /* @__PURE__ */ jsx("div", {
104
+ tabIndex: 0,
105
+ className: "overflow-x-auto",
106
+ children: /* @__PURE__ */ jsxs("table", {
107
+ className: "border-collapse text-sm",
108
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: block.head.map((nodes, column) => cell("th", nodes, column)) }) }), /* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, place) => /* @__PURE__ */ jsx("tr", { children: row.map((nodes, column) => cell("td", nodes, column)) }, place)) })]
109
+ })
110
+ });
111
+ }
112
+ /**
113
+ * Markdown, as a model writes it, shown as a page shows text: headings,
114
+ * lists, tables, code and links. Nothing of it is ever treated as HTML.
115
+ * A link leads only to the web or to a letter, and a picture is never
116
+ * fetched: it is shown as a link to it.
117
+ *
118
+ * It can be given again with more of an answer as it arrives: what is
119
+ * half written is drawn as far as it goes, and what was drawn before
120
+ * stays as it is, so that reading or selecting it is not disturbed.
121
+ */
122
+ var Markdown = memo(function Markdown({ children }) {
123
+ const blocks = useMemo(() => parseMarkdown(children), [children]);
124
+ return /* @__PURE__ */ jsx("div", {
125
+ "data-slot": "markdown",
126
+ className: "grid min-w-0 gap-3 leading-relaxed wrap-anywhere whitespace-normal *:min-w-0",
127
+ children: /* @__PURE__ */ jsx(Blocks, { blocks })
128
+ });
129
+ });
130
+ export { Markdown };
131
+
132
+ //# sourceMappingURL=markdown.js.map