@alulore/kumiko 0.17.2 → 0.18.1

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 (95) hide show
  1. package/dist/avatar/avatar-name.d.ts +12 -0
  2. package/dist/avatar/avatar-name.js +42 -0
  3. package/dist/avatar/avatar.css +274 -0
  4. package/dist/avatar/avatar.d.ts +72 -0
  5. package/dist/avatar/avatar.js +45 -0
  6. package/dist/avatar/index.d.ts +3 -0
  7. package/dist/avatar/index.js +3 -0
  8. package/dist/board/board-api.d.ts +1 -0
  9. package/dist/board/board-selection.d.ts +1 -0
  10. package/dist/board/board-slots.d.ts +7 -0
  11. package/dist/board/board-slots.js +2 -1
  12. package/dist/board/refused-home.js +26 -1
  13. package/dist/dialog/dialog.d.ts +9 -0
  14. package/dist/dialog/dialog.js +20 -0
  15. package/dist/dialog/index.d.ts +4 -3
  16. package/dist/dialog/index.js +4 -3
  17. package/dist/drawer/drawer.css +514 -0
  18. package/dist/drawer/drawer.d.ts +55 -0
  19. package/dist/drawer/drawer.js +43 -0
  20. package/dist/drawer/index.d.ts +2 -0
  21. package/dist/drawer/index.js +2 -0
  22. package/dist/file-input/file-dropzone.d.ts +67 -0
  23. package/dist/file-input/file-dropzone.js +97 -0
  24. package/dist/file-input/file-input.css +505 -0
  25. package/dist/file-input/file-input.d.ts +29 -0
  26. package/dist/file-input/file-input.js +21 -0
  27. package/dist/file-input/file-preview.d.ts +15 -0
  28. package/dist/file-input/file-preview.js +41 -0
  29. package/dist/file-input/index.d.ts +4 -0
  30. package/dist/file-input/index.js +4 -0
  31. package/dist/hover-card/hover-card.js +2 -0
  32. package/dist/media-viewer/index.d.ts +1 -0
  33. package/dist/media-viewer/index.js +1 -0
  34. package/dist/media-viewer/labels.d.ts +27 -0
  35. package/dist/media-viewer/labels.js +23 -0
  36. package/dist/media-viewer/media-viewer.d.ts +3 -0
  37. package/dist/media-viewer/media-viewer.js +6 -3
  38. package/dist/media-viewer/video-controls.js +4 -2
  39. package/dist/media-viewer/viewer-chrome.js +11 -5
  40. package/dist/menu/menu.js +2 -0
  41. package/dist/motion/settle-close.d.ts +5 -0
  42. package/dist/motion/settle-close.js +78 -0
  43. package/dist/otp-input/index.d.ts +2 -0
  44. package/dist/otp-input/index.js +2 -0
  45. package/dist/otp-input/otp-input.css +336 -0
  46. package/dist/otp-input/otp-input.d.ts +56 -0
  47. package/dist/otp-input/otp-input.js +44 -0
  48. package/dist/popover/index.d.ts +2 -1
  49. package/dist/popover/index.js +2 -1
  50. package/dist/popover/popover.d.ts +3 -0
  51. package/dist/popover/popover.js +8 -0
  52. package/dist/server-render.test.d.ts +1 -0
  53. package/dist/server-render.test.js +57 -0
  54. package/dist/shortcuts/bindings.d.ts +23 -3
  55. package/dist/shortcuts/bindings.js +15 -9
  56. package/dist/shortcuts/bound.d.ts +15 -0
  57. package/dist/shortcuts/bound.js +55 -0
  58. package/dist/shortcuts/help.d.ts +7 -1
  59. package/dist/shortcuts/help.js +2 -2
  60. package/dist/shortcuts/index.d.ts +2 -1
  61. package/dist/shortcuts/index.js +1 -0
  62. package/dist/shortcuts/judge.d.ts +3 -0
  63. package/dist/shortcuts/judge.js +9 -1
  64. package/dist/shortcuts/list.d.ts +6 -1
  65. package/dist/shortcuts/list.js +6 -5
  66. package/dist/shortcuts/notes.d.ts +4 -0
  67. package/dist/shortcuts/notes.js +6 -0
  68. package/dist/shortcuts/provider.d.ts +8 -1
  69. package/dist/shortcuts/provider.js +47 -11
  70. package/dist/shortcuts/registration.d.ts +3 -1
  71. package/dist/shortcuts/registration.js +10 -2
  72. package/dist/shortcuts/shortcuts.css +5 -0
  73. package/dist/skeleton/index.d.ts +1 -0
  74. package/dist/skeleton/index.js +1 -0
  75. package/dist/skeleton/skeleton.css +143 -0
  76. package/dist/skeleton/skeleton.d.ts +44 -0
  77. package/dist/skeleton/skeleton.js +22 -0
  78. package/dist/smooth-caret/smooth-caret.css +4 -2
  79. package/dist/tabs/index.d.ts +2 -0
  80. package/dist/tabs/index.js +2 -0
  81. package/dist/tabs/tabs.css +616 -0
  82. package/dist/tabs/tabs.d.ts +51 -0
  83. package/dist/tabs/tabs.js +20 -0
  84. package/dist/titlebar/index.d.ts +1 -1
  85. package/dist/titlebar/index.js +1 -1
  86. package/dist/titlebar/titlebar.d.ts +15 -2
  87. package/dist/titlebar/titlebar.js +18 -9
  88. package/dist/toast/index.d.ts +2 -1
  89. package/dist/toast/index.js +2 -1
  90. package/dist/tooltip/tooltip.js +2 -0
  91. package/dist/undo/index.d.ts +1 -1
  92. package/dist/undo/index.js +1 -1
  93. package/dist/undo/undo-keys.d.ts +7 -0
  94. package/dist/undo/undo-keys.js +18 -7
  95. package/package.json +59 -5
@@ -0,0 +1,336 @@
1
+ @import "../motion/motion.css";
2
+
3
+ /*
4
+ * Styles ui-sdk's one-time code input. One invisible native input lies over the slots and takes every press, key,
5
+ * paste and autofill; the slots only show the code. The colours fall back to the text input's.
6
+ */
7
+ @layer kumiko {
8
+ :where(:root) {
9
+ --kumiko-otp-slot-width-sm: 2.25rem;
10
+ --kumiko-otp-slot-width: 2.75rem;
11
+ --kumiko-otp-slot-width-lg: 3.25rem;
12
+ --kumiko-otp-slot-height-sm: 2.5rem;
13
+ --kumiko-otp-slot-height: 3rem;
14
+ --kumiko-otp-slot-height-lg: 3.75rem;
15
+ --kumiko-otp-font-size-sm: 1rem;
16
+ --kumiko-otp-font-size: 1.25rem;
17
+ --kumiko-otp-font-size-lg: 1.625rem;
18
+ --kumiko-otp-font-family: inherit;
19
+ --kumiko-otp-font-weight: 500;
20
+ --kumiko-otp-gap: 0.5rem;
21
+ --kumiko-otp-group-gap: 0.75rem;
22
+ --kumiko-otp-radius: 0.625rem;
23
+ --kumiko-otp-border-width: 1px;
24
+ --kumiko-otp-fg: currentColor;
25
+ --kumiko-otp-bg: color-mix(in oklab, currentColor 5%, transparent);
26
+ --kumiko-otp-border: color-mix(in oklab, currentColor 18%, transparent);
27
+ --kumiko-otp-border-hover: color-mix(in oklab, currentColor 30%, transparent);
28
+ --kumiko-otp-filled-border: color-mix(in oklab, currentColor 30%, transparent);
29
+ --kumiko-otp-ring-width: 3px;
30
+ --kumiko-otp-separator: color-mix(in oklab, currentColor 40%, transparent);
31
+ --kumiko-otp-caret-width: 2px;
32
+ --kumiko-otp-shake-distance: 6px;
33
+ }
34
+
35
+ /*
36
+ * The tokens that fall back to the input's resolve on each part, not on the root, so an input token set on any
37
+ * container reaches the code inside it.
38
+ */
39
+ :where([data-slot^="otp-input"]) {
40
+ --_otp-accent: var(--kumiko-otp-accent, var(--kumiko-input-accent, Highlight));
41
+ --_otp-invalid: var(
42
+ --kumiko-otp-invalid,
43
+ var(--kumiko-input-invalid, light-dark(oklch(0.55 0.19 25), oklch(0.72 0.15 25)))
44
+ );
45
+ --_otp-caret-blink-duration: var(
46
+ --kumiko-otp-caret-blink-duration,
47
+ var(--kumiko-smooth-caret-blink-duration, 1.1s)
48
+ );
49
+ --_otp-disabled-opacity: var(
50
+ --kumiko-otp-disabled-opacity,
51
+ var(--kumiko-input-disabled-opacity, 0.5)
52
+ );
53
+ --_otp-readonly-border: var(
54
+ --kumiko-otp-readonly-border,
55
+ var(--kumiko-input-readonly-border, color-mix(in oklab, currentColor 16%, transparent))
56
+ );
57
+ }
58
+
59
+ :where([data-slot="otp-input"]) {
60
+ --_otp-w: var(--kumiko-otp-slot-width);
61
+ --_otp-h: var(--kumiko-otp-slot-height);
62
+ --_otp-fs: var(--kumiko-otp-font-size);
63
+ --_otp-ring: color-mix(in oklab, var(--_otp-accent) 28%, transparent);
64
+
65
+ display: inline-flex;
66
+ gap: var(--kumiko-otp-group-gap);
67
+ align-items: center;
68
+ color: var(--kumiko-otp-fg);
69
+ cursor: text;
70
+
71
+ /* A code is digits and Latin letters, read left to right on any page, so "123" never shows as "321". */
72
+ direction: ltr;
73
+ unicode-bidi: isolate;
74
+ }
75
+
76
+ :where([data-slot="otp-input"][data-size="sm"]) {
77
+ --_otp-w: var(--kumiko-otp-slot-width-sm);
78
+ --_otp-h: var(--kumiko-otp-slot-height-sm);
79
+ --_otp-fs: var(--kumiko-otp-font-size-sm);
80
+ }
81
+
82
+ :where([data-slot="otp-input"][data-size="lg"]) {
83
+ --_otp-w: var(--kumiko-otp-slot-width-lg);
84
+ --_otp-h: var(--kumiko-otp-slot-height-lg);
85
+ --_otp-fs: var(--kumiko-otp-font-size-lg);
86
+ }
87
+
88
+ :where([data-slot="otp-input-group"]) {
89
+ display: flex;
90
+ gap: var(--kumiko-otp-gap);
91
+ }
92
+
93
+ :where([data-slot="otp-input-slot"]) {
94
+ position: relative;
95
+ display: grid;
96
+ box-sizing: border-box;
97
+ inline-size: var(--_otp-w);
98
+ block-size: var(--_otp-h);
99
+ border: var(--kumiko-otp-border-width) solid var(--kumiko-otp-border);
100
+ border-radius: var(--kumiko-otp-radius);
101
+ background: var(--kumiko-otp-bg);
102
+ font-family: var(--kumiko-otp-font-family);
103
+ font-size: var(--_otp-fs);
104
+ font-weight: var(--kumiko-otp-font-weight);
105
+ font-variant-numeric: tabular-nums;
106
+ line-height: 1;
107
+ place-items: center;
108
+ transition:
109
+ border-color var(--kumiko-fade-duration) var(--kumiko-fade-ease),
110
+ box-shadow var(--kumiko-fade-duration) var(--kumiko-fade-ease);
111
+ }
112
+
113
+ :where([data-slot="otp-input-slot"][data-filled]) {
114
+ border-color: var(--kumiko-otp-filled-border);
115
+ }
116
+
117
+ @media (hover: hover) and (pointer: fine) {
118
+ :where(
119
+ [data-slot="otp-input"]:not([data-disabled]):not(:has(input[readonly])):hover
120
+ [data-slot="otp-input-slot"]:not([data-active])
121
+ ) {
122
+ border-color: var(--kumiko-otp-border-hover);
123
+ }
124
+ }
125
+
126
+ /* The slot typing goes to: the accent edge and a soft ring, as a focused text field has. */
127
+ :where([data-slot="otp-input-slot"][data-active]) {
128
+ z-index: 1;
129
+ border-color: var(--_otp-accent);
130
+ box-shadow: 0 0 0 var(--kumiko-otp-ring-width) var(--_otp-ring);
131
+ }
132
+
133
+ /* The caret: the input's own is hidden, so an empty active slot draws one, blinking. */
134
+ :where([data-slot="otp-input-slot"][data-fake-caret])::after {
135
+ inline-size: var(--kumiko-otp-caret-width);
136
+ block-size: 1.1em;
137
+ border-radius: var(--kumiko-otp-caret-width);
138
+ background: var(--_otp-accent);
139
+ content: "";
140
+ animation: kumiko-otp-caret var(--_otp-caret-blink-duration) ease-in-out infinite;
141
+ }
142
+
143
+ @keyframes kumiko-otp-caret {
144
+ 0%,
145
+ 30% {
146
+ opacity: 1;
147
+ }
148
+
149
+ 65% {
150
+ opacity: 0;
151
+ }
152
+
153
+ 100% {
154
+ opacity: 1;
155
+ }
156
+ }
157
+
158
+ /* A typed character pops in from a little smaller, on the pop tokens, which reduced and still motion zero. */
159
+ :where([data-slot="otp-input-char"]) {
160
+ animation: kumiko-otp-pop var(--kumiko-pop-duration) var(--kumiko-pop-ease);
161
+ }
162
+
163
+ :where(
164
+ [data-slot="otp-input"]:is(
165
+ [data-pop="false"],
166
+ :not([data-pop]):is([data-kumiko-otp~="no-pop"] *)
167
+ )
168
+ [data-slot="otp-input-char"]
169
+ ) {
170
+ animation: none;
171
+ }
172
+
173
+ @keyframes kumiko-otp-pop {
174
+ from {
175
+ scale: var(--kumiko-pop-scale);
176
+ opacity: 0;
177
+ }
178
+ }
179
+
180
+ /* The separator: a short dash unless the app draws its own. */
181
+ :where([data-slot="otp-input-separator"]) {
182
+ display: flex;
183
+ align-items: center;
184
+ color: var(--kumiko-otp-separator);
185
+ }
186
+
187
+ :where([data-slot="otp-input-separator"]:empty)::before {
188
+ inline-size: calc(var(--_otp-fs) * 0.5);
189
+ block-size: 2px;
190
+ border-radius: 2px;
191
+ background: currentColor;
192
+ content: "";
193
+ }
194
+
195
+ /* Joined: the slots of a group share their edges and round only the group's ends. */
196
+ :where(
197
+ [data-slot="otp-input"]:is(
198
+ [data-look="joined"],
199
+ :not([data-look]):is([data-kumiko-otp~="joined"] *)
200
+ )
201
+ ) {
202
+ & [data-slot="otp-input-group"] {
203
+ gap: 0;
204
+ }
205
+
206
+ & [data-slot="otp-input-slot"] {
207
+ border-radius: 0;
208
+ }
209
+
210
+ & [data-slot="otp-input-slot"] + [data-slot="otp-input-slot"] {
211
+ margin-inline-start: calc(-1 * var(--kumiko-otp-border-width));
212
+ }
213
+
214
+ & [data-slot="otp-input-slot"]:first-child {
215
+ border-start-start-radius: var(--kumiko-otp-radius);
216
+ border-end-start-radius: var(--kumiko-otp-radius);
217
+ }
218
+
219
+ & [data-slot="otp-input-slot"]:last-child {
220
+ border-start-end-radius: var(--kumiko-otp-radius);
221
+ border-end-end-radius: var(--kumiko-otp-radius);
222
+ }
223
+ }
224
+
225
+ /* Underline: no box, a line under each character that takes the accent where typing goes. */
226
+ :where(
227
+ [data-slot="otp-input"]:is(
228
+ [data-look="underline"],
229
+ :not([data-look]):is([data-kumiko-otp~="underline"] *)
230
+ )
231
+ ) {
232
+ & [data-slot="otp-input-slot"] {
233
+ border-width: 0 0 calc(var(--kumiko-otp-border-width) * 2);
234
+ border-radius: 0;
235
+ background: transparent;
236
+ }
237
+
238
+ & [data-slot="otp-input-slot"][data-active] {
239
+ box-shadow: 0 var(--kumiko-otp-ring-width) 0 -1px var(--_otp-ring);
240
+ }
241
+ }
242
+
243
+ /* An invalid code: the error colour, and one shake as it turns invalid. */
244
+ :where([data-slot="otp-input"]:has(input[aria-invalid="true"])) {
245
+ --_otp-ring: color-mix(in oklab, var(--_otp-invalid) 28%, transparent);
246
+
247
+ & [data-slot="otp-input-slot"],
248
+ & [data-slot="otp-input-slot"][data-active] {
249
+ border-color: var(--_otp-invalid);
250
+ }
251
+
252
+ & [data-slot="otp-input-slot"][data-fake-caret]::after {
253
+ background: var(--_otp-invalid);
254
+ }
255
+ }
256
+
257
+ /*
258
+ * The shake starts when the code turns invalid and plays once. Its length comes from the move tokens, so
259
+ * reduced and still motion, which zero them, leave it out.
260
+ */
261
+ :where(
262
+ [data-slot="otp-input"]:not([data-shake="false"]):not(
263
+ :not([data-shake]):is([data-kumiko-otp~="no-shake"] *)
264
+ ):has(input[aria-invalid="true"])
265
+ [data-slot="otp-input-group"]
266
+ ) {
267
+ animation: kumiko-otp-shake calc(var(--kumiko-move-duration) * 1.5) var(--kumiko-move-ease);
268
+ }
269
+
270
+ @keyframes kumiko-otp-shake {
271
+ 20% {
272
+ translate: calc(-1 * var(--kumiko-otp-shake-distance)) 0;
273
+ }
274
+
275
+ 40% {
276
+ translate: var(--kumiko-otp-shake-distance) 0;
277
+ }
278
+
279
+ 60% {
280
+ translate: calc(-0.5 * var(--kumiko-otp-shake-distance)) 0;
281
+ }
282
+
283
+ 80% {
284
+ translate: calc(0.5 * var(--kumiko-otp-shake-distance)) 0;
285
+ }
286
+ }
287
+
288
+ /* Read-only shows the code without inviting typing: no fill, a quiet edge and no caret. */
289
+ :where([data-slot="otp-input"]:has(input[readonly])) {
290
+ cursor: default;
291
+
292
+ & [data-slot="otp-input-slot"] {
293
+ border-color: var(--_otp-readonly-border);
294
+ background: transparent;
295
+ }
296
+
297
+ & [data-slot="otp-input-slot"][data-active] {
298
+ box-shadow: none;
299
+ }
300
+
301
+ & [data-slot="otp-input-slot"][data-fake-caret]::after {
302
+ content: none;
303
+ }
304
+ }
305
+
306
+ :where([data-slot="otp-input"][data-disabled]) {
307
+ cursor: not-allowed;
308
+ opacity: var(--_otp-disabled-opacity);
309
+ }
310
+
311
+ /* A steady caret for anyone who asked for less motion. */
312
+ @media (prefers-reduced-motion: reduce) {
313
+ :where([data-slot="otp-input-slot"][data-fake-caret])::after {
314
+ animation: none;
315
+ }
316
+ }
317
+
318
+ :where([data-kumiko-motion="still"] [data-slot="otp-input-slot"][data-fake-caret])::after {
319
+ animation: none;
320
+ }
321
+
322
+ @media (forced-colors: active) {
323
+ :where([data-slot="otp-input-slot"]) {
324
+ border-color: CanvasText;
325
+ }
326
+
327
+ :where([data-slot="otp-input-slot"][data-active]) {
328
+ border-color: Highlight;
329
+ outline: 2px solid Highlight;
330
+ }
331
+
332
+ :where([data-slot="otp-input-slot"][data-fake-caret])::after {
333
+ background: CanvasText;
334
+ }
335
+ }
336
+ }
@@ -0,0 +1,56 @@
1
+ import { OTPInput as SdkOTPInput, OTPInputSlot as SdkOTPInputSlot } from "@ui-sdk/react/otp-input";
2
+ /** How the slots look: separate boxes, boxes joined into one field per group, or a line under each character. */
3
+ export type OTPInputLook = "boxes" | "joined" | "underline";
4
+ /** How big the slots are. */
5
+ export type OTPInputSize = "sm" | "md" | "lg";
6
+ type SdkProps = Parameters<typeof SdkOTPInput>[0];
7
+ export type OTPInputProps = SdkProps & {
8
+ /**
9
+ * How the slots look. Without it, `data-kumiko-otp="joined"` or `"underline"` on any container picks.
10
+ * @defaultValue "boxes"
11
+ */
12
+ look?: OTPInputLook;
13
+ /** @defaultValue "md" */
14
+ size?: OTPInputSize;
15
+ /**
16
+ * Shows this character, or "•" for `true`, in every filled slot instead of the code, as for a PIN. The value and
17
+ * what the form submits stay the real code.
18
+ */
19
+ mask?: boolean | string;
20
+ /**
21
+ * Whether a typed character pops in. Without it, `data-kumiko-otp="no-pop"` on any container turns it off.
22
+ * Reduced and still motion leave it out.
23
+ * @defaultValue true
24
+ */
25
+ pop?: boolean;
26
+ /**
27
+ * Whether the slots shake once when the code turns invalid. Without it, `data-kumiko-otp="no-shake"` on any
28
+ * container turns it off. Reduced and still motion leave the shake out and keep the error colour.
29
+ * @defaultValue true
30
+ */
31
+ shake?: boolean;
32
+ /**
33
+ * How the slots are split when you give no children, like `[3, 3]` for "123-456". Left out, the slots form one
34
+ * group of `maxLength`.
35
+ */
36
+ groups?: number[];
37
+ /** @defaultValue 6 */
38
+ maxLength?: number;
39
+ };
40
+ /**
41
+ * Ui-sdk's one-time code input with Kumiko's slots. Without children it draws its own slots, split by `groups`;
42
+ * with children, lay them out with `OTPInputSlots`, or with `OTPInputGroup`, `OTPInputSlot` and `OTPInputSeparator`.
43
+ */
44
+ export declare function OTPInput({ look, size, mask, pop, shake, groups, maxLength, children, ...props }: OTPInputProps): React.JSX.Element;
45
+ export type OTPInputSlotProps = Parameters<typeof SdkOTPInputSlot>[0];
46
+ /** One character of the code. Without children it shows the character, masked when the input says so. */
47
+ export declare function OTPInputSlot({ children, ...props }: OTPInputSlotProps): React.JSX.Element | null;
48
+ export interface OTPInputSlotsProps {
49
+ /** How many slots each group holds, in order, like `[3, 3]`. */
50
+ groups: number[];
51
+ /** Drawn between groups. Left out, a short dash. */
52
+ separator?: React.ReactNode;
53
+ }
54
+ /** The slots and separators for a code split into groups, so you don't write each slot out. */
55
+ export declare function OTPInputSlots({ groups, separator }: OTPInputSlotsProps): React.JSX.Element;
56
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { OTPInput as SdkOTPInput, OTPInputGroup, OTPInputSeparator, OTPInputSlot as SdkOTPInputSlot } from "@ui-sdk/react/otp-input";
3
+ import { createContext, Fragment, useContext } from "react";
4
+ /** The character a masked slot shows, or none when the code shows as typed. */
5
+ const MaskContext = createContext(null);
6
+ function onOff(on) {
7
+ return on === undefined ? undefined : String(on);
8
+ }
9
+ function maskOf(mask) {
10
+ if (mask === true) {
11
+ return "•";
12
+ }
13
+ return typeof mask === "string" && mask !== "" ? mask : null;
14
+ }
15
+ /**
16
+ * Ui-sdk's one-time code input with Kumiko's slots. Without children it draws its own slots, split by `groups`;
17
+ * with children, lay them out with `OTPInputSlots`, or with `OTPInputGroup`, `OTPInputSlot` and `OTPInputSeparator`.
18
+ */
19
+ export function OTPInput({ look, size = "md", mask, pop, shake, groups, maxLength = 6, children, ...props }) {
20
+ const slots = children ?? _jsx(OTPInputSlots, { groups: groups ?? [maxLength] });
21
+ return (_jsx(MaskContext.Provider, { value: maskOf(mask), children: _jsx(SdkOTPInput, { maxLength: maxLength, "data-look": look, "data-size": size, "data-pop": onOff(pop), "data-shake": onOff(shake), ...props, children: slots }) }));
22
+ }
23
+ function SlotChar({ state }) {
24
+ const mask = useContext(MaskContext);
25
+ if (state.char === null) {
26
+ return null;
27
+ }
28
+ /* Keyed by the character, so a new one mounts afresh and pops in again. */
29
+ return (_jsx("span", { "data-slot": "otp-input-char", children: mask ?? state.char }, `${state.index}:${state.char}`));
30
+ }
31
+ /** One character of the code. Without children it shows the character, masked when the input says so. */
32
+ export function OTPInputSlot({ children, ...props }) {
33
+ return (_jsx(SdkOTPInputSlot, { ...props, children: children ?? ((state) => _jsx(SlotChar, { state: state })) }));
34
+ }
35
+ function startOf(groups, at) {
36
+ return groups.slice(0, at).reduce((sum, count) => sum + count, 0);
37
+ }
38
+ /** The slots and separators for a code split into groups, so you don't write each slot out. */
39
+ export function OTPInputSlots({ groups, separator }) {
40
+ return (_jsx(_Fragment, { children: groups.map((count, at) => {
41
+ const start = startOf(groups, at);
42
+ return (_jsxs(Fragment, { children: [at > 0 ? _jsx(OTPInputSeparator, { children: separator }) : null, _jsx(OTPInputGroup, { children: Array.from({ length: count }, (_, offset) => (_jsx(OTPInputSlot, { index: start + offset }, start + offset))) })] }, start));
43
+ }) }));
44
+ }
@@ -1 +1,2 @@
1
- export { createPopoverController, Popover, PopoverArrow, PopoverClose, PopoverContent, PopoverDescription, PopoverShortcut, PopoverTitle, PopoverTrigger, type PopoverApi, type PopoverContentProps, type PopoverContentState, type PopoverController, type PopoverDismissReason, type PopoverFinalFocus, type PopoverInitialFocus, type PopoverOpenChangeReason, type PopoverOptions, type PopoverPayloadChangeReason, type PopoverProps, type PopoverTriggerProps, type PopoverTriggerState } from "@ui-sdk/react/popover";
1
+ export { createPopoverController, PopoverArrow, PopoverClose, PopoverContent, PopoverDescription, PopoverShortcut, PopoverTitle, PopoverTrigger, type PopoverApi, type PopoverContentProps, type PopoverContentState, type PopoverController, type PopoverDismissReason, type PopoverFinalFocus, type PopoverInitialFocus, type PopoverOpenChangeReason, type PopoverOptions, type PopoverPayloadChangeReason, type PopoverProps, type PopoverTriggerProps, type PopoverTriggerState } from "@ui-sdk/react/popover";
2
+ export { Popover } from "./popover";
@@ -1 +1,2 @@
1
- export { createPopoverController, Popover, PopoverArrow, PopoverClose, PopoverContent, PopoverDescription, PopoverShortcut, PopoverTitle, PopoverTrigger } from "@ui-sdk/react/popover";
1
+ export { createPopoverController, PopoverArrow, PopoverClose, PopoverContent, PopoverDescription, PopoverShortcut, PopoverTitle, PopoverTrigger } from "@ui-sdk/react/popover";
2
+ export { Popover } from "./popover";
@@ -0,0 +1,3 @@
1
+ import { type PopoverProps } from "@ui-sdk/react/popover";
2
+ /** The ui-sdk popover, whose close isn't stretched by infinite animations inside it. */
3
+ export declare function Popover(props: PopoverProps): React.JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Popover as SdkPopover } from "@ui-sdk/react/popover";
3
+ import { useSettledClose } from "../motion/settle-close";
4
+ /** The ui-sdk popover, whose close isn't stretched by infinite animations inside it. */
5
+ export function Popover(props) {
6
+ useSettledClose();
7
+ return _jsx(SdkPopover, { ...props });
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { describe, expect, it } from "bun:test";
3
+ import { renderToString } from "react-dom/server";
4
+ import { Avatar } from "./avatar";
5
+ import { Drawer, DrawerContent, DrawerTitle, DrawerTrigger } from "./drawer";
6
+ import { FileDropzone, FilePreview } from "./file-input";
7
+ import { OTPInput } from "./otp-input";
8
+ import { Skeleton, SkeletonGroup, SkeletonText } from "./skeleton";
9
+ import { Tabs, TabsList, TabsPanel, TabsTab } from "./tabs";
10
+ /*
11
+ * Bun runs these with no DOM, as a server does: a component that reads `window` or `document`, or makes a
12
+ * browser-only value, while it renders fails here before it fails an app's server.
13
+ */
14
+ function tabsShowTheChosenTab() {
15
+ const html = renderToString(_jsxs(Tabs, { defaultValue: "screens", children: [_jsxs(TabsList, { "aria-label": "Sections", children: [_jsx(TabsTab, { value: "screens", children: "Screens" }), _jsx(TabsTab, { value: "campaigns", children: "Campaigns" })] }), _jsx(TabsPanel, { value: "screens", children: "Twelve screens" }), _jsx(TabsPanel, { value: "campaigns", children: "Three campaigns" })] }));
16
+ expect(html).toMatch(/aria-selected="true"[^>]*>Screens</u);
17
+ expect(html).toContain("Twelve screens");
18
+ }
19
+ function aClosedDrawerIsItsTrigger() {
20
+ const html = renderToString(_jsxs(Drawer, { children: [_jsx(DrawerTrigger, { children: "Basket" }), _jsx(DrawerContent, { children: _jsx(DrawerTitle, { children: "Your basket" }) })] }));
21
+ expect(html).toContain(">Basket</button>");
22
+ expect(html).not.toContain("Your basket");
23
+ }
24
+ function aCodeHasASlotPerCharacter() {
25
+ const html = renderToString(_jsx(OTPInput, { "aria-label": "Code", maxLength: 6 }));
26
+ expect(html.match(/data-slot="otp-input-slot"/gu)).toHaveLength(6);
27
+ }
28
+ function anAvatarIsItsInitials() {
29
+ const html = renderToString(_jsx(Avatar, { name: "Ana Maria Silva", src: "/ana.jpg" }));
30
+ expect(html).toContain('aria-label="Ana Maria Silva"');
31
+ expect(html).toContain(">AS<");
32
+ }
33
+ function aLoadingGroupHasItsStatus() {
34
+ const html = renderToString(_jsxs(SkeletonGroup, { label: "Loading the profile", children: [_jsx(Skeleton, { shape: "circle", width: 48 }), _jsx(SkeletonText, { lines: 2 })] }));
35
+ expect(html).toMatch(/role="status"[^>]*>Loading the profile</u);
36
+ expect(html.match(/data-slot="skeleton"/gu)).toHaveLength(3);
37
+ }
38
+ function aDropZoneHasItsWordsAndButton() {
39
+ const html = renderToString(_jsx(FileDropzone, { multiple: true, title: "Drop your ads here" }));
40
+ expect(html).toContain("Drop your ads here");
41
+ expect(html).toMatch(/data-slot="file-input-trigger"[^>]*>Browse files</u);
42
+ }
43
+ function aPictureIsItsBadge() {
44
+ const picture = new File(["a"], "storefront.png", { type: "image/png" });
45
+ const html = renderToString(_jsx(FilePreview, { file: picture }));
46
+ expect(html).toContain(">PNG<");
47
+ expect(html).not.toContain("blob:");
48
+ }
49
+ describe("server render", () => {
50
+ it("renders tabs with the chosen tab selected and its panel", tabsShowTheChosenTab);
51
+ it("renders a closed drawer as its trigger alone", aClosedDrawerIsItsTrigger);
52
+ it("renders a code input with a slot for each character", aCodeHasASlotPerCharacter);
53
+ it("renders an avatar as its initials, named for the person", anAvatarIsItsInitials);
54
+ it("renders a loading group with its status and placeholders", aLoadingGroupHasItsStatus);
55
+ it("renders a drop zone with its words and button", aDropZoneHasItsWordsAndButton);
56
+ it("renders a picture's preview as its badge, with no object URL", aPictureIsItsBadge);
57
+ });
@@ -8,8 +8,12 @@ export interface ShortcutAction {
8
8
  section: string;
9
9
  /** The keys that run it by default: one, or several. Written like `"mod+k"`. */
10
10
  keys: string | readonly string[];
11
- /** Runs when one of its keys is pressed, or when a control calls it. */
12
- run: (event?: KeyboardEvent) => void;
11
+ /**
12
+ * Runs when one of its keys is pressed, or when a control calls it. Leave it out to declare the action here
13
+ * and bind it from a component with `useShortcutAction`; until one is mounted the action is listed and
14
+ * rebindable but does nothing.
15
+ */
16
+ run?: (event?: KeyboardEvent) => void;
13
17
  /** Checked on every key press: the action runs only while it returns true. */
14
18
  when?: () => boolean;
15
19
  /** Whether it also runs while focus is in a text field. Keys with Ctrl, Cmd or Alt always do. */
@@ -20,7 +24,17 @@ export interface ShortcutAction {
20
24
  * @defaultValue false
21
25
  */
22
26
  overDialogs?: boolean;
27
+ /**
28
+ * Whether the help sheet lists it only while it could run when the sheet opened, or always. An action that
29
+ * needs focus somewhere (a card) is gone as soon as the sheet's own button takes focus, so "always" keeps it.
30
+ * @defaultValue "available"
31
+ */
32
+ listed?: "available" | "always";
23
33
  }
34
+ /** An action with the code that runs it, as a component gives it to `useShortcutAction`. */
35
+ export type BoundShortcutAction = ShortcutAction & {
36
+ run: NonNullable<ShortcutAction["run"]>;
37
+ };
24
38
  /** The keys people changed, by action id. An action that is not in here uses its defaults. */
25
39
  export type Overrides = Readonly<Record<string, readonly string[]>>;
26
40
  /** How many keys one action can hold. */
@@ -29,8 +43,14 @@ export declare function defaultKeys(action: ShortcutAction): string[];
29
43
  export declare function keysOf(action: ShortcutAction, overrides: Overrides): string[];
30
44
  /** Whether saved bindings have the right shape: an object of action ids to lists of key strings. */
31
45
  export declare function isOverrides(value: unknown): value is Overrides;
32
- /** Keeps what applies to these actions: known ids only, keys written one way, at most `maxKeysPerAction` each. */
46
+ /**
47
+ * Writes the keys of these actions one way and caps them at `maxKeysPerAction`. An id that is not in the list
48
+ * is left exactly as saved: it may belong to an action that is not declared right now, and what a person
49
+ * chose is never dropped because of what happens to be mounted.
50
+ */
33
51
  export declare function sanitizeOverrides(saved: Overrides, actions: readonly ShortcutAction[]): Overrides;
52
+ /** The saved keys of the actions in this list only, for what a reset of everything on screen clears. */
53
+ export declare function withoutActions(overrides: Overrides, actions: readonly ShortcutAction[]): Overrides;
34
54
  /** Who has these keys now, other than `exceptId`. */
35
55
  export declare function ownerOf(actions: readonly ShortcutAction[], overrides: Overrides, keys: string, exceptId: string): ShortcutAction | undefined;
36
56
  export type Resolution = "plain" | "swap" | "replace";
@@ -15,16 +15,22 @@ export function isOverrides(value) {
15
15
  !Array.isArray(value) &&
16
16
  Object.values(value).every((keys) => Array.isArray(keys) && keys.every((key) => typeof key === "string")));
17
17
  }
18
- /** Keeps what applies to these actions: known ids only, keys written one way, at most `maxKeysPerAction` each. */
18
+ /**
19
+ * Writes the keys of these actions one way and caps them at `maxKeysPerAction`. An id that is not in the list
20
+ * is left exactly as saved: it may belong to an action that is not declared right now, and what a person
21
+ * chose is never dropped because of what happens to be mounted.
22
+ */
19
23
  export function sanitizeOverrides(saved, actions) {
20
- const result = {};
21
- for (const action of actions) {
22
- const keys = Object.entries(saved).find(([id]) => id === action.id)?.[1];
23
- if (keys) {
24
- result[action.id] = keys.slice(0, maxKeysPerAction).map((key) => canonicalKeys(key));
25
- }
26
- }
27
- return result;
24
+ const known = new Set(actions.map((action) => action.id));
25
+ return Object.fromEntries(Object.entries(saved).map(([id, keys]) => [
26
+ id,
27
+ known.has(id) ? keys.slice(0, maxKeysPerAction).map((key) => canonicalKeys(key)) : keys
28
+ ]));
29
+ }
30
+ /** The saved keys of the actions in this list only, for what a reset of everything on screen clears. */
31
+ export function withoutActions(overrides, actions) {
32
+ const known = new Set(actions.map((action) => action.id));
33
+ return Object.fromEntries(Object.entries(overrides).filter(([id]) => !known.has(id)));
28
34
  }
29
35
  /** Who has these keys now, other than `exceptId`. */
30
36
  export function ownerOf(actions, overrides, keys, exceptId) {
@@ -0,0 +1,15 @@
1
+ import { type BoundShortcutAction } from "./bindings";
2
+ /**
3
+ * Gives an action the code that runs it, from wherever that code lives in the tree.
4
+ *
5
+ * When the nearest `ShortcutsProvider` declares the same `id`, this binds `run` and `when` to that declaration:
6
+ * the provider's keys, saved changes, section and description win, and its `allowInInput`, `overDialogs` and
7
+ * pause rules apply. The binding goes when the component unmounts. With two bindings for one id, the one
8
+ * mounted last runs, and the other takes over again when it goes. The latest `run` and `when` are read on every
9
+ * key press, so they need not be stable.
10
+ *
11
+ * Without a provider, or when the provider does not declare the id, the action's own default keys are
12
+ * registered plainly, as a shortcut that is not listed and cannot be rebound. A hook can serve an app with
13
+ * a provider and one without.
14
+ */
15
+ export declare function useShortcutAction(action: BoundShortcutAction): void;