@fldr/ui 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -448
- package/ai/component-registry.json +25 -13
- package/ai/component-registry.md +2 -2
- package/dist/.build-complete +1 -1
- package/dist/blocks-source/auth-card/auth-card.test.tsx +20 -14
- package/dist/blocks-source/auth-card/auth-card.tsx +73 -55
- package/dist/blocks-source/file-table/file-table.tsx +197 -150
- package/dist/blocks-source/share-dialog/share-dialog.test.tsx +9 -3
- package/dist/blocks-source/share-dialog/share-dialog.tsx +50 -35
- package/dist/blocks.d.ts +21 -4
- package/dist/blocks.js +246 -195
- package/dist/{button-DzavLWXm.d.ts → button-CS82eT0x.d.ts} +1 -1
- package/dist/chunks/{checkbox-eifiwbw34xwsikvf.js → checkbox-d5epe4dl78bzy4f8.js} +8 -8
- package/dist/chunks/highlighter-kb7huz24pcziin6d.js +57 -0
- package/dist/chunks/{layer-dialog-m8qb0wzfg3k7406a.js → layer-dialog-mnaw06pxom8q771w.js} +3 -2
- package/dist/chunks/{table-ngl1b5yc8mcur662.js → table-bdye068ekayq3u1n.js} +1 -1
- package/dist/chunks/table-f8vl74hdx3bzqqbf.js +448 -0
- package/dist/code/server.js +1 -1
- package/dist/code.js +4 -131
- package/dist/components/banner.d.ts +1 -1
- package/dist/components/button.d.ts +2 -2
- package/dist/components/checkbox.d.ts +1 -1
- package/dist/components/checkbox.js +1 -1
- package/dist/components/input-group.d.ts +2 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/layer-dialog.js +1 -1
- package/dist/components/link.d.ts +2 -67
- package/dist/components/sidebar.d.ts +2 -1
- package/dist/components/table.d.ts +1 -1
- package/dist/components/table.js +1 -1
- package/dist/components/toast.d.ts +1 -1
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/form.d.ts +207 -0
- package/dist/form.js +317 -0
- package/dist/hotkeys.d.ts +135 -0
- package/dist/hotkeys.js +206 -0
- package/dist/index-9LwQy84o.d.ts +1 -0
- package/dist/index-B7iG0qDU.d.ts +1 -0
- package/dist/{index-B6JNUfG9.d.ts → index-BMXHK-3k.d.ts} +2 -2
- package/dist/{index-B6Wo_iiN.d.ts → index-B_ug9XY7.d.ts} +1 -1
- package/dist/{index-RP_rt8vB.d.ts → index-Bh9kuAvN.d.ts} +1 -1
- package/dist/{index-DjSGDESy.d.ts → index-CAUjUp2G.d.ts} +1 -1
- package/dist/{index-NnHba-T1.d.ts → index-DK28YxxP.d.ts} +2 -2
- package/dist/{index-aahL-0Zw.d.ts → index-DOVlARA6.d.ts} +2 -2
- package/dist/index-DTj6M6kA.d.ts +1 -0
- package/dist/index.d.ts +14 -12
- package/dist/index.js +3 -4
- package/dist/{input-group-8gEtPiKw.d.ts → input-group-Swzit45o.d.ts} +1 -1
- package/dist/link-CoVXE5W2.d.ts +68 -0
- package/dist/query.d.ts +156 -0
- package/dist/query.js +204 -0
- package/dist/router.d.ts +95 -0
- package/dist/router.js +146 -0
- package/dist/skeleton.d.ts +3 -0
- package/dist/skeleton.js +4 -0
- package/dist/styles/kumo-binding.css +10 -0
- package/dist/styles/kumo-standalone.css +1 -1
- package/dist/styles/theme-fldr.css +18 -18
- package/dist/table.d.ts +245 -0
- package/dist/table.js +3 -0
- package/dist/theming.d.ts +4 -4
- package/dist/theming.js +2 -2
- package/package.json +41 -1
- package/dist/chunks/highlighter-mouttug0tu8xg1i8.js +0 -1364
- package/dist/index-DL1-uSuH.d.ts +0 -1
- /package/dist/{index-BkTAB4wj.d.ts → sidebar-BkTAB4wj.d.ts} +0 -0
package/dist/form.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as cn } from "./chunks/vendor-styling-gs32v7xt5znc8kg0.js";
|
|
3
|
+
import { t as Button } from "./chunks/button-hzvowfkbathmx8yg.js";
|
|
4
|
+
import { t as Banner } from "./chunks/banner-mo1xl9ww734kgsqh.js";
|
|
5
|
+
import { t as Checkbox } from "./chunks/checkbox-d5epe4dl78bzy4f8.js";
|
|
6
|
+
import { t as Field } from "./chunks/field-fowmq5smvp17pnqe.js";
|
|
7
|
+
import { n as KUMO_INPUT_VARIANTS, t as Input } from "./chunks/input-kfi46426y22ocoo4.js";
|
|
8
|
+
import { t as InputArea } from "./chunks/input-m2tfec2viezoz9hh.js";
|
|
9
|
+
import { t as Select } from "./chunks/select-h2pejw38n5z3l59r.js";
|
|
10
|
+
import { r as Switch } from "./chunks/switch-nc8thi7ogd51m3gi.js";
|
|
11
|
+
import { r as Radio } from "./chunks/radio-nf717i5ypsga9zdh.js";
|
|
12
|
+
import { useId } from "react";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { WarningCircleIcon } from "@phosphor-icons/react";
|
|
15
|
+
import { createFormHook, createFormHookContexts, useSelector } from "@tanstack/react-form";
|
|
16
|
+
//#region src/form/form.tsx
|
|
17
|
+
const { fieldContext, formContext, useFieldContext, useFormContext } = createFormHookContexts();
|
|
18
|
+
/** Returns the first readable message from TanStack Form errors (strings, Standard Schema issues, or nested arrays). */
|
|
19
|
+
function firstErrorMessage(errors) {
|
|
20
|
+
for (const error of errors) {
|
|
21
|
+
if (typeof error === "string" && error) return error;
|
|
22
|
+
if (Array.isArray(error)) {
|
|
23
|
+
const nested = firstErrorMessage(error);
|
|
24
|
+
if (nested) return nested;
|
|
25
|
+
} else if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return error.message;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Field error message, shown only once the field was blurred or the form was submitted. */
|
|
29
|
+
function useFieldError() {
|
|
30
|
+
const field = useFieldContext();
|
|
31
|
+
const submitted = useSelector(field.form.store, (s) => s.submissionAttempts > 0);
|
|
32
|
+
const { isBlurred, errors } = field.state.meta;
|
|
33
|
+
return isBlurred || submitted ? firstErrorMessage(errors) : void 0;
|
|
34
|
+
}
|
|
35
|
+
/** Description / error line for controls without a built-in Field wrapper. */
|
|
36
|
+
function FieldMessage({ id, error, description }) {
|
|
37
|
+
if (!error && !description) return null;
|
|
38
|
+
return /* @__PURE__ */ jsx("p", {
|
|
39
|
+
id,
|
|
40
|
+
className: cn("text-sm leading-snug", error ? "text-kumo-danger" : "text-kumo-subtle"),
|
|
41
|
+
children: error ?? description
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Input wrapped in a Field that is always rendered, so toggling the error
|
|
46
|
+
* never remounts the input (Kumo's Input only wraps itself when it has a
|
|
47
|
+
* label, description or error).
|
|
48
|
+
*/
|
|
49
|
+
function BoundInput({ label, labelTooltip, description, className, error, ...props }) {
|
|
50
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
51
|
+
label,
|
|
52
|
+
labelTooltip,
|
|
53
|
+
required: props.required,
|
|
54
|
+
description,
|
|
55
|
+
error: error ? {
|
|
56
|
+
message: error,
|
|
57
|
+
match: true
|
|
58
|
+
} : void 0,
|
|
59
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
60
|
+
...props,
|
|
61
|
+
className: cn(error && KUMO_INPUT_VARIANTS.variant.error.classes, className),
|
|
62
|
+
"aria-invalid": error ? true : void 0
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Text input bound to the surrounding `form.AppField`. Pass `type` / `autoComplete` through;
|
|
68
|
+
* `className` applies to the input.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* <form.AppField name="email">
|
|
73
|
+
* {(field) => <field.TextField label="Email" type="email" autoComplete="email" />}
|
|
74
|
+
* </form.AppField>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
function TextField(props) {
|
|
78
|
+
const field = useFieldContext();
|
|
79
|
+
return /* @__PURE__ */ jsx(BoundInput, {
|
|
80
|
+
...props,
|
|
81
|
+
name: field.name,
|
|
82
|
+
value: field.state.value ?? "",
|
|
83
|
+
onChange: (event) => field.handleChange(event.target.value),
|
|
84
|
+
onBlur: field.handleBlur,
|
|
85
|
+
error: useFieldError()
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Number input; an empty input stores `undefined`. */
|
|
89
|
+
function NumberField(props) {
|
|
90
|
+
const field = useFieldContext();
|
|
91
|
+
return /* @__PURE__ */ jsx(BoundInput, {
|
|
92
|
+
inputMode: "decimal",
|
|
93
|
+
...props,
|
|
94
|
+
type: "number",
|
|
95
|
+
name: field.name,
|
|
96
|
+
value: field.state.value ?? "",
|
|
97
|
+
onChange: (event) => field.handleChange(event.target.value === "" ? void 0 : event.target.valueAsNumber),
|
|
98
|
+
onBlur: field.handleBlur,
|
|
99
|
+
error: useFieldError()
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** Multi-line text input bound to the surrounding field. Give it a `label` (or `description`) so the error can appear without remounting the textarea. */
|
|
103
|
+
function TextareaField(props) {
|
|
104
|
+
const field = useFieldContext();
|
|
105
|
+
const error = useFieldError();
|
|
106
|
+
return /* @__PURE__ */ jsx(InputArea, {
|
|
107
|
+
...props,
|
|
108
|
+
name: field.name,
|
|
109
|
+
value: field.state.value ?? "",
|
|
110
|
+
onValueChange: field.handleChange,
|
|
111
|
+
onBlur: field.handleBlur,
|
|
112
|
+
error,
|
|
113
|
+
"aria-invalid": error ? true : void 0
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Select bound to a string field. Pass `items` (`{ key: "Label" }`) or `Select.Option` children.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* <form.AppField name="role">
|
|
122
|
+
* {(field) => <field.SelectField label="Role" items={{ viewer: "Viewer", editor: "Editor" }} />}
|
|
123
|
+
* </form.AppField>
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
function SelectField({ onOpenChange, ...props }) {
|
|
127
|
+
const field = useFieldContext();
|
|
128
|
+
const error = useFieldError();
|
|
129
|
+
return /* @__PURE__ */ jsx(Select, {
|
|
130
|
+
...props,
|
|
131
|
+
name: field.name,
|
|
132
|
+
value: field.state.value,
|
|
133
|
+
onValueChange: (value) => field.handleChange(value ?? ""),
|
|
134
|
+
onOpenChange: (open, details) => {
|
|
135
|
+
if (!open) field.handleBlur();
|
|
136
|
+
onOpenChange?.(open, details);
|
|
137
|
+
},
|
|
138
|
+
error
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** Checkbox bound to a boolean field. */
|
|
142
|
+
function CheckboxField({ description, ...props }) {
|
|
143
|
+
const field = useFieldContext();
|
|
144
|
+
const error = useFieldError();
|
|
145
|
+
const id = useId();
|
|
146
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
147
|
+
className: "flex flex-col gap-1",
|
|
148
|
+
onBlur: field.handleBlur,
|
|
149
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
150
|
+
variant: error ? "error" : props.variant,
|
|
151
|
+
...props,
|
|
152
|
+
name: field.name,
|
|
153
|
+
checked: field.state.value ?? false,
|
|
154
|
+
onCheckedChange: (checked) => field.handleChange(checked),
|
|
155
|
+
"aria-invalid": error ? true : void 0,
|
|
156
|
+
"aria-describedby": error || description ? id : void 0
|
|
157
|
+
}), /* @__PURE__ */ jsx(FieldMessage, {
|
|
158
|
+
id,
|
|
159
|
+
error,
|
|
160
|
+
description
|
|
161
|
+
})]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Switch bound to a boolean field. */
|
|
165
|
+
function SwitchField({ description, ...props }) {
|
|
166
|
+
const field = useFieldContext();
|
|
167
|
+
const error = useFieldError();
|
|
168
|
+
const id = useId();
|
|
169
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
170
|
+
className: "flex flex-col gap-1",
|
|
171
|
+
children: [/* @__PURE__ */ jsx(Switch, {
|
|
172
|
+
...props,
|
|
173
|
+
name: field.name,
|
|
174
|
+
checked: field.state.value ?? false,
|
|
175
|
+
onCheckedChange: field.handleChange,
|
|
176
|
+
onBlur: field.handleBlur,
|
|
177
|
+
"aria-invalid": error ? true : void 0,
|
|
178
|
+
"aria-describedby": error || description ? id : void 0
|
|
179
|
+
}), /* @__PURE__ */ jsx(FieldMessage, {
|
|
180
|
+
id,
|
|
181
|
+
error,
|
|
182
|
+
description
|
|
183
|
+
})]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/** Radio group bound to a string field. */
|
|
187
|
+
function RadioField({ items, children, ...props }) {
|
|
188
|
+
const field = useFieldContext();
|
|
189
|
+
const error = useFieldError();
|
|
190
|
+
return /* @__PURE__ */ jsx("div", {
|
|
191
|
+
className: "contents",
|
|
192
|
+
onBlur: field.handleBlur,
|
|
193
|
+
children: /* @__PURE__ */ jsx(Radio, {
|
|
194
|
+
...props,
|
|
195
|
+
name: field.name,
|
|
196
|
+
value: field.state.value,
|
|
197
|
+
onValueChange: (value) => field.handleChange(value),
|
|
198
|
+
error,
|
|
199
|
+
children: children ?? items?.map((item) => /* @__PURE__ */ jsx(Radio.Item, { ...item }, item.value))
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* `<form>` that prevents the native submit and calls `form.handleSubmit()`.
|
|
205
|
+
* Render inside `form.AppForm`, or use `form.Form`.
|
|
206
|
+
*/
|
|
207
|
+
function Form({ noValidate = true, ...props }) {
|
|
208
|
+
const form = useFormContext();
|
|
209
|
+
return /* @__PURE__ */ jsx("form", {
|
|
210
|
+
noValidate,
|
|
211
|
+
...props,
|
|
212
|
+
onSubmit: (event) => {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
form.handleSubmit();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** Submit button; disabled while the form is invalid or submitting, shows a spinner while submitting. */
|
|
220
|
+
function SubmitButton({ variant = "primary", disabled, loading, ...props }) {
|
|
221
|
+
const form = useFormContext();
|
|
222
|
+
const [canSubmit, isSubmitting] = useSelector(form.store, (s) => [s.canSubmit, s.isSubmitting], { compare: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
223
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
224
|
+
...props,
|
|
225
|
+
type: "submit",
|
|
226
|
+
variant,
|
|
227
|
+
loading: loading || isSubmitting,
|
|
228
|
+
disabled: disabled || !canSubmit
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/** Resets the form to its default values. */
|
|
232
|
+
function ResetButton({ variant = "secondary", ...props }) {
|
|
233
|
+
const form = useFormContext();
|
|
234
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
235
|
+
...props,
|
|
236
|
+
type: "button",
|
|
237
|
+
variant,
|
|
238
|
+
onClick: () => form.reset()
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/** Shows `error` or the first form-level validation error in an error Banner. */
|
|
242
|
+
function FormErrorBanner({ error, className }) {
|
|
243
|
+
const form = useFormContext();
|
|
244
|
+
const formError = useSelector(form.store, (s) => firstErrorMessage(s.errors));
|
|
245
|
+
const message = error ?? formError;
|
|
246
|
+
if (!message) return null;
|
|
247
|
+
return /* @__PURE__ */ jsx("div", {
|
|
248
|
+
role: "alert",
|
|
249
|
+
className,
|
|
250
|
+
children: /* @__PURE__ */ jsx(Banner, {
|
|
251
|
+
variant: "error",
|
|
252
|
+
size: "sm",
|
|
253
|
+
icon: /* @__PURE__ */ jsx(WarningCircleIcon, {}),
|
|
254
|
+
description: message
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* fldr form hook: TanStack Form's `useForm` pre-wired with fldr field and form components.
|
|
260
|
+
* Validators accept functions or any Standard Schema (e.g. zod v4) directly.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```tsx
|
|
264
|
+
* const form = useAppForm({
|
|
265
|
+
* defaultValues: { email: "" },
|
|
266
|
+
* validators: { onChange: z.object({ email: z.email() }) },
|
|
267
|
+
* onSubmit: ({ value }) => save(value),
|
|
268
|
+
* });
|
|
269
|
+
* return (
|
|
270
|
+
* <form.AppForm>
|
|
271
|
+
* <form.Form className="flex flex-col gap-3">
|
|
272
|
+
* <form.AppField name="email">{(f) => <f.TextField label="Email" />}</form.AppField>
|
|
273
|
+
* <form.SubmitButton>Save</form.SubmitButton>
|
|
274
|
+
* </form.Form>
|
|
275
|
+
* </form.AppForm>
|
|
276
|
+
* );
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
const { useAppForm, withForm, withFieldGroup } = createFormHook({
|
|
280
|
+
fieldContext,
|
|
281
|
+
formContext,
|
|
282
|
+
fieldComponents: {
|
|
283
|
+
TextField,
|
|
284
|
+
NumberField,
|
|
285
|
+
TextareaField,
|
|
286
|
+
SelectField,
|
|
287
|
+
CheckboxField,
|
|
288
|
+
SwitchField,
|
|
289
|
+
RadioField
|
|
290
|
+
},
|
|
291
|
+
formComponents: {
|
|
292
|
+
Form,
|
|
293
|
+
SubmitButton,
|
|
294
|
+
ResetButton,
|
|
295
|
+
FormErrorBanner
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
/** Field-level validator: fails on empty / whitespace-only strings, `false` or nullish values. */
|
|
299
|
+
function required(message = "Required") {
|
|
300
|
+
return ({ value }) => value == null || value === false || typeof value === "string" && !value.trim() ? message : void 0;
|
|
301
|
+
}
|
|
302
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
303
|
+
/** Field-level validator: fails when a non-empty string is not an email address. Combine with `required` for mandatory fields. */
|
|
304
|
+
function email(message = "Enter a valid email") {
|
|
305
|
+
return ({ value }) => value.trim() && !EMAIL_RE.test(value.trim()) ? message : void 0;
|
|
306
|
+
}
|
|
307
|
+
/** Runs validators in order and returns the first error. */
|
|
308
|
+
function compose(...validators) {
|
|
309
|
+
return (arg) => {
|
|
310
|
+
for (const validate of validators) {
|
|
311
|
+
const error = validate(arg);
|
|
312
|
+
if (error) return error;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
export { CheckboxField, Form, FormErrorBanner, NumberField, RadioField, ResetButton, SelectField, SubmitButton, SwitchField, TextField, TextareaField, compose, email, fieldContext, firstErrorMessage, formContext, required, useAppForm, useFieldContext, useFormContext, withFieldGroup, withForm };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { DisplayHotkey, HotkeyCallback, HotkeyCallbackContextFor, HotkeyPlatform, RegisterableHotkey, UseHotkeyCommonOptions, UseHotkeyOptionsFor } from "@tanstack/react-hotkeys";
|
|
3
|
+
export * from "@tanstack/react-hotkeys";
|
|
4
|
+
//#region src/hotkeys/kbd.d.ts
|
|
5
|
+
interface KbdProps extends Omit<ComponentPropsWithoutRef<"kbd">, "children"> {
|
|
6
|
+
/** A key, chord (`"Mod+K"`) or sequence (`["G", "H"]`). */
|
|
7
|
+
keys: DisplayHotkey;
|
|
8
|
+
/** Force a platform instead of the provider's or the detected one. */
|
|
9
|
+
platform?: HotkeyPlatform;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders a key, chord or sequence as small flat keycaps. `Mod` reads ⌘ on
|
|
13
|
+
* Mac and Ctrl elsewhere, following `HotkeysProvider`'s `platform`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <Button>Upload <Kbd keys="Mod+U" /></Button>
|
|
18
|
+
* <Kbd keys={["G", "H"]} />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function Kbd({ keys, platform, className, ...props }: KbdProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/hotkeys/shortcut.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Registers a hotkey while mounted and returns a `Kbd` showing it.
|
|
26
|
+
* Give it `meta: { name, group }` to list it in `ShortcutsDialog`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const kbd = useShortcut("Mod+U", upload, { meta: { name: "Upload" } });
|
|
31
|
+
* return <Button onClick={upload}>Upload {kbd}</Button>;
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function useShortcut<const T extends RegisterableHotkey>(hotkey: T, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: UseHotkeyOptionsFor<T>): ReactElement;
|
|
35
|
+
type ShortcutHintProps<T extends RegisterableHotkey> = Omit<KbdProps, "keys"> & {
|
|
36
|
+
/** The hotkey to register and display. */
|
|
37
|
+
keys: T;
|
|
38
|
+
/** Runs when the hotkey is pressed. */
|
|
39
|
+
onTrigger: HotkeyCallback<HotkeyCallbackContextFor<T>>;
|
|
40
|
+
/** TanStack hotkey options such as `enabled`, `meta` or `ignoreInputs`. */
|
|
41
|
+
options?: UseHotkeyOptionsFor<T>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Component form of `useShortcut`: registers `keys` and renders its `Kbd`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <Button onClick={upload}>
|
|
49
|
+
* Upload <ShortcutHint keys="Mod+U" onTrigger={upload} />
|
|
50
|
+
* </Button>
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function ShortcutHint<const T extends RegisterableHotkey>({ keys, onTrigger, options, ...props }: ShortcutHintProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
type MenuShortcutProps = KbdProps;
|
|
55
|
+
/**
|
|
56
|
+
* A `Kbd` in `DropdownMenu.Shortcut`'s trailing slot. Display only: menu
|
|
57
|
+
* items unmount when the menu closes, so register the hotkey higher up with
|
|
58
|
+
* `useHotkey` or `useShortcut`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <DropdownMenu.Item onClick={upload}>
|
|
63
|
+
* Upload <MenuShortcut keys="Mod+U" />
|
|
64
|
+
* </DropdownMenu.Item>
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function MenuShortcut(props: MenuShortcutProps): import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/hotkeys/command-palette-trigger.d.ts
|
|
70
|
+
/**
|
|
71
|
+
* Toggles a command palette with `keys` (⌘K / Ctrl+K by default), including
|
|
72
|
+
* while its search input has focus. Returns the `Kbd` hint.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* const [open, setOpen] = useState(false);
|
|
77
|
+
* useCommandPaletteHotkey(open, setOpen);
|
|
78
|
+
* return <CommandPalette.Root open={open} onOpenChange={setOpen} ... />;
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function useCommandPaletteHotkey(open: boolean, setOpen: (open: boolean) => void, keys?: RegisterableHotkey, options?: UseHotkeyCommonOptions): ReactElement;
|
|
82
|
+
interface CommandPaletteTriggerProps {
|
|
83
|
+
/** Whether the palette is open. */
|
|
84
|
+
open: boolean;
|
|
85
|
+
/** Called with the next open state on click or hotkey. */
|
|
86
|
+
onOpenChange: (open: boolean) => void;
|
|
87
|
+
/** @default "Mod+K" */
|
|
88
|
+
keys?: RegisterableHotkey;
|
|
89
|
+
/** Options for the hotkey, e.g. `meta: { name: "Recherche" }`. */
|
|
90
|
+
options?: UseHotkeyCommonOptions;
|
|
91
|
+
/** Button label. @default "Search" */
|
|
92
|
+
children?: ReactNode;
|
|
93
|
+
className?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A search button that opens the command palette on click or ⌘K, with the
|
|
97
|
+
* hint shown inline.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* <CommandPaletteTrigger open={open} onOpenChange={setOpen} />
|
|
102
|
+
* <CommandPalette.Root open={open} onOpenChange={setOpen} ... />
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function CommandPaletteTrigger({ open, onOpenChange, keys, options, children, className }: CommandPaletteTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/hotkeys/shortcuts-dialog.d.ts
|
|
108
|
+
interface ShortcutsDialogProps {
|
|
109
|
+
/** Controlled open state. Uncontrolled when omitted. */
|
|
110
|
+
open?: boolean;
|
|
111
|
+
onOpenChange?: (open: boolean) => void;
|
|
112
|
+
/** Hotkey that opens the dialog; `null` to disable. @default "?" */
|
|
113
|
+
keys?: RegisterableHotkey | null;
|
|
114
|
+
/** @default "Keyboard shortcuts" */
|
|
115
|
+
title?: string;
|
|
116
|
+
/** Name of the opening hotkey in the list. @default "Show keyboard shortcuts" */
|
|
117
|
+
name?: string;
|
|
118
|
+
/** Section for shortcuts without `meta.group`. @default "General" */
|
|
119
|
+
defaultGroup?: string;
|
|
120
|
+
/** Shown when no named shortcuts are registered. @default "No shortcuts" */
|
|
121
|
+
emptyLabel?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Lists every mounted hotkey that has `meta.name`, grouped by `meta.group`.
|
|
125
|
+
* Opens with `?` by default.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* useHotkey("Mod+S", save, { meta: { name: "Save", group: "File" } });
|
|
130
|
+
* <ShortcutsDialog />
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function ShortcutsDialog({ open: openProp, onOpenChange, keys, title, name, defaultGroup, emptyLabel }: ShortcutsDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
134
|
+
//#endregion
|
|
135
|
+
export type { CommandPaletteTriggerProps, KbdProps, MenuShortcutProps, ShortcutHintProps, ShortcutsDialogProps };
|
package/dist/hotkeys.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as cn } from "./chunks/vendor-styling-gs32v7xt5znc8kg0.js";
|
|
3
|
+
import { t as Button } from "./chunks/button-hzvowfkbathmx8yg.js";
|
|
4
|
+
import { t as DropdownMenu } from "./chunks/dropdown-e5zk0ez21busnt0b.js";
|
|
5
|
+
import { t as LayerDialog } from "./chunks/layer-dialog-mnaw06pxom8q771w.js";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { MagnifyingGlassIcon } from "@phosphor-icons/react";
|
|
9
|
+
import { useFormatForDisplay, useHotkey, useHotkeyRegistrations } from "@tanstack/react-hotkeys";
|
|
10
|
+
export * from "@tanstack/react-hotkeys";
|
|
11
|
+
//#region src/hotkeys/kbd.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Renders a key, chord or sequence as small flat keycaps. `Mod` reads ⌘ on
|
|
14
|
+
* Mac and Ctrl elsewhere, following `HotkeysProvider`'s `platform`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <Button>Upload <Kbd keys="Mod+U" /></Button>
|
|
19
|
+
* <Kbd keys={["G", "H"]} />
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function Kbd({ keys, platform, className, ...props }) {
|
|
23
|
+
const format = useFormatForDisplay();
|
|
24
|
+
const label = format(keys, { platform });
|
|
25
|
+
const steps = isSequence(keys) ? format(keys, {
|
|
26
|
+
platform,
|
|
27
|
+
parts: true
|
|
28
|
+
}) : [format(keys, {
|
|
29
|
+
platform,
|
|
30
|
+
parts: true
|
|
31
|
+
})];
|
|
32
|
+
return /* @__PURE__ */ jsx("kbd", {
|
|
33
|
+
"aria-label": label,
|
|
34
|
+
className: cn("inline-flex shrink-0 items-center gap-1 align-middle font-sans", className),
|
|
35
|
+
...props,
|
|
36
|
+
children: steps.map((step, i) => /* @__PURE__ */ jsx("span", {
|
|
37
|
+
"aria-hidden": true,
|
|
38
|
+
className: "inline-flex items-center gap-0.5",
|
|
39
|
+
children: step.map((key, j) => /* @__PURE__ */ jsx("kbd", {
|
|
40
|
+
className: "inline-flex h-4.5 min-w-4.5 items-center justify-center rounded bg-kumo-recessed px-1 font-mono text-[11px] leading-none text-kumo-subtle",
|
|
41
|
+
children: key
|
|
42
|
+
}, j))
|
|
43
|
+
}, i))
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function isSequence(keys) {
|
|
47
|
+
return Array.isArray(keys);
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/hotkeys/shortcut.tsx
|
|
51
|
+
/**
|
|
52
|
+
* Registers a hotkey while mounted and returns a `Kbd` showing it.
|
|
53
|
+
* Give it `meta: { name, group }` to list it in `ShortcutsDialog`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const kbd = useShortcut("Mod+U", upload, { meta: { name: "Upload" } });
|
|
58
|
+
* return <Button onClick={upload}>Upload {kbd}</Button>;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function useShortcut(hotkey, callback, options) {
|
|
62
|
+
useHotkey(hotkey, callback, options);
|
|
63
|
+
return /* @__PURE__ */ jsx(Kbd, { keys: hotkey });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Component form of `useShortcut`: registers `keys` and renders its `Kbd`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <Button onClick={upload}>
|
|
71
|
+
* Upload <ShortcutHint keys="Mod+U" onTrigger={upload} />
|
|
72
|
+
* </Button>
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function ShortcutHint({ keys, onTrigger, options, ...props }) {
|
|
76
|
+
useHotkey(keys, onTrigger, options);
|
|
77
|
+
return /* @__PURE__ */ jsx(Kbd, {
|
|
78
|
+
keys,
|
|
79
|
+
...props
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A `Kbd` in `DropdownMenu.Shortcut`'s trailing slot. Display only: menu
|
|
84
|
+
* items unmount when the menu closes, so register the hotkey higher up with
|
|
85
|
+
* `useHotkey` or `useShortcut`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* <DropdownMenu.Item onClick={upload}>
|
|
90
|
+
* Upload <MenuShortcut keys="Mod+U" />
|
|
91
|
+
* </DropdownMenu.Item>
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function MenuShortcut(props) {
|
|
95
|
+
return /* @__PURE__ */ jsx(DropdownMenu.Shortcut, {
|
|
96
|
+
className: "tracking-normal opacity-100",
|
|
97
|
+
children: /* @__PURE__ */ jsx(Kbd, { ...props })
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/hotkeys/command-palette-trigger.tsx
|
|
102
|
+
/**
|
|
103
|
+
* Toggles a command palette with `keys` (⌘K / Ctrl+K by default), including
|
|
104
|
+
* while its search input has focus. Returns the `Kbd` hint.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* const [open, setOpen] = useState(false);
|
|
109
|
+
* useCommandPaletteHotkey(open, setOpen);
|
|
110
|
+
* return <CommandPalette.Root open={open} onOpenChange={setOpen} ... />;
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function useCommandPaletteHotkey(open, setOpen, keys = "Mod+K", options) {
|
|
114
|
+
useHotkey(keys, () => setOpen(!open), {
|
|
115
|
+
ignoreInputs: false,
|
|
116
|
+
meta: { name: "Command palette" },
|
|
117
|
+
...options
|
|
118
|
+
});
|
|
119
|
+
return /* @__PURE__ */ jsx(Kbd, { keys });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A search button that opens the command palette on click or ⌘K, with the
|
|
123
|
+
* hint shown inline.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```tsx
|
|
127
|
+
* <CommandPaletteTrigger open={open} onOpenChange={setOpen} />
|
|
128
|
+
* <CommandPalette.Root open={open} onOpenChange={setOpen} ... />
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
function CommandPaletteTrigger({ open, onOpenChange, keys, options, children = "Search", className }) {
|
|
132
|
+
const kbd = useCommandPaletteHotkey(open, onOpenChange, keys, options);
|
|
133
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
134
|
+
variant: "secondary",
|
|
135
|
+
icon: MagnifyingGlassIcon,
|
|
136
|
+
"aria-haspopup": "dialog",
|
|
137
|
+
"aria-expanded": open,
|
|
138
|
+
className: cn("gap-2 text-kumo-subtle", className),
|
|
139
|
+
onClick: () => onOpenChange(!open),
|
|
140
|
+
children: [children, kbd]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/hotkeys/shortcuts-dialog.tsx
|
|
145
|
+
/**
|
|
146
|
+
* Lists every mounted hotkey that has `meta.name`, grouped by `meta.group`.
|
|
147
|
+
* Opens with `?` by default.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* useHotkey("Mod+S", save, { meta: { name: "Save", group: "File" } });
|
|
152
|
+
* <ShortcutsDialog />
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
function ShortcutsDialog({ open: openProp, onOpenChange, keys = "?", title = "Keyboard shortcuts", name = "Show keyboard shortcuts", defaultGroup = "General", emptyLabel = "No shortcuts" }) {
|
|
156
|
+
const [openState, setOpenState] = useState(false);
|
|
157
|
+
const open = openProp ?? openState;
|
|
158
|
+
const setOpen = (next) => {
|
|
159
|
+
setOpenState(next);
|
|
160
|
+
onOpenChange?.(next);
|
|
161
|
+
};
|
|
162
|
+
useHotkey(keys, () => setOpen(!open), { meta: { name } });
|
|
163
|
+
const groups = groupRegistrations(useHotkeyRegistrations(), defaultGroup);
|
|
164
|
+
return /* @__PURE__ */ jsx(LayerDialog.Root, {
|
|
165
|
+
open,
|
|
166
|
+
onOpenChange: setOpen,
|
|
167
|
+
children: /* @__PURE__ */ jsxs(LayerDialog.Content, { children: [/* @__PURE__ */ jsx(LayerDialog.Title, { children: title }), /* @__PURE__ */ jsx(LayerDialog.Body, { children: groups.size === 0 ? /* @__PURE__ */ jsx("p", {
|
|
168
|
+
className: "text-sm text-kumo-subtle",
|
|
169
|
+
children: emptyLabel
|
|
170
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
171
|
+
className: "flex flex-col gap-4",
|
|
172
|
+
children: [...groups].map(([group, rows]) => /* @__PURE__ */ jsxs("section", {
|
|
173
|
+
className: "flex flex-col gap-1",
|
|
174
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
175
|
+
className: "text-xs font-medium text-kumo-subtle",
|
|
176
|
+
children: group
|
|
177
|
+
}), /* @__PURE__ */ jsx("dl", {
|
|
178
|
+
className: "flex flex-col",
|
|
179
|
+
children: rows.map((row) => /* @__PURE__ */ jsxs("div", {
|
|
180
|
+
className: "flex items-center justify-between gap-4 py-1 text-sm",
|
|
181
|
+
children: [/* @__PURE__ */ jsx("dt", {
|
|
182
|
+
className: "text-kumo-default",
|
|
183
|
+
children: row.options.meta?.name
|
|
184
|
+
}), /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(Kbd, { keys: row.hotkey }) })]
|
|
185
|
+
}, row.id))
|
|
186
|
+
})]
|
|
187
|
+
}, group))
|
|
188
|
+
}) })] })
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function groupRegistrations(registrations, defaultGroup) {
|
|
192
|
+
const groups = /* @__PURE__ */ new Map();
|
|
193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
194
|
+
for (const reg of registrations) {
|
|
195
|
+
const meta = reg.options.meta;
|
|
196
|
+
if (!meta?.name || reg.status === "disabled") continue;
|
|
197
|
+
const key = `${meta.name}\u0000${String(reg.hotkey)}`;
|
|
198
|
+
if (seen.has(key)) continue;
|
|
199
|
+
seen.add(key);
|
|
200
|
+
const group = meta.group ?? defaultGroup;
|
|
201
|
+
groups.set(group, [...groups.get(group) ?? [], reg]);
|
|
202
|
+
}
|
|
203
|
+
return groups;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
export { CommandPaletteTrigger, Kbd, MenuShortcut, ShortcutHint, ShortcutsDialog, useCommandPaletteHotkey, useShortcut };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./button-CS82eT0x.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./input-group-Swzit45o.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as ButtonProps } from "./button-
|
|
2
|
-
import "./index-
|
|
1
|
+
import { n as ButtonProps } from "./button-CS82eT0x.js";
|
|
2
|
+
import "./index-9LwQy84o.js";
|
|
3
3
|
import { n as PortalContainer } from "./portal-provider-BAqPpq_a.js";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { Toast, ToastManagerAddOptions, ToastManagerUpdateOptions, ToastObject } from "@base-ui/react/toast";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as FieldErrorMatch } from "./field-DIjlHM8W.js";
|
|
2
2
|
import "./input-BeWEb-jD.js";
|
|
3
|
-
import "./
|
|
3
|
+
import "./index-B7iG0qDU.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { ReactNode } from "react";
|
|
6
6
|
//#region src/components/input/input-area.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CheckboxChangeEventDetails } from "./index-
|
|
1
|
+
import { n as CheckboxChangeEventDetails } from "./index-CAUjUp2G.js";
|
|
2
2
|
//#region src/components/table/table.d.ts
|
|
3
3
|
/** Table layout and row variant definitions mapping names to their Tailwind classes. */
|
|
4
4
|
declare const KUMO_TABLE_VARIANTS: {
|