@particle-academy/react-fancy 5.33.0 → 5.35.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 (70) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/dist/activity-light.cjs +13 -0
  3. package/dist/activity-light.cjs.map +1 -0
  4. package/dist/activity-light.d.cts +64 -0
  5. package/dist/activity-light.d.ts +64 -0
  6. package/dist/activity-light.js +4 -0
  7. package/dist/activity-light.js.map +1 -0
  8. package/dist/button.cjs +4 -4
  9. package/dist/button.js +2 -2
  10. package/dist/{chunk-ZYVWKYPO.js → chunk-2OMB3OOR.js} +3 -3
  11. package/dist/{chunk-ZYVWKYPO.js.map → chunk-2OMB3OOR.js.map} +1 -1
  12. package/dist/{chunk-G6VMNSCM.js → chunk-46IPQEUP.js} +3 -3
  13. package/dist/{chunk-G6VMNSCM.js.map → chunk-46IPQEUP.js.map} +1 -1
  14. package/dist/{chunk-H6PXIB35.cjs → chunk-5Q7EQQTT.cjs} +4 -4
  15. package/dist/{chunk-H6PXIB35.cjs.map → chunk-5Q7EQQTT.cjs.map} +1 -1
  16. package/dist/{chunk-BQ77ZWFM.js → chunk-6ASZUE4T.js} +4 -4
  17. package/dist/{chunk-BQ77ZWFM.js.map → chunk-6ASZUE4T.js.map} +1 -1
  18. package/dist/{chunk-WEKQD4BQ.js → chunk-DCDW3LW6.js} +3 -3
  19. package/dist/{chunk-WEKQD4BQ.js.map → chunk-DCDW3LW6.js.map} +1 -1
  20. package/dist/{chunk-VRJTPXJ7.cjs → chunk-DNV7MUEE.cjs} +81 -20
  21. package/dist/chunk-DNV7MUEE.cjs.map +1 -0
  22. package/dist/{chunk-YMU3SS6D.cjs → chunk-E2SZBIAV.cjs} +16 -16
  23. package/dist/{chunk-YMU3SS6D.cjs.map → chunk-E2SZBIAV.cjs.map} +1 -1
  24. package/dist/chunk-EHNMKQ4O.cjs +71 -0
  25. package/dist/chunk-EHNMKQ4O.cjs.map +1 -0
  26. package/dist/chunk-IR6JSQ4O.cjs +233 -0
  27. package/dist/chunk-IR6JSQ4O.cjs.map +1 -0
  28. package/dist/{chunk-5TUZENNJ.cjs → chunk-MTUH2X3W.cjs} +4 -4
  29. package/dist/{chunk-5TUZENNJ.cjs.map → chunk-MTUH2X3W.cjs.map} +1 -1
  30. package/dist/{chunk-B4PFNSX7.js → chunk-O3WEV562.js} +79 -21
  31. package/dist/chunk-O3WEV562.js.map +1 -0
  32. package/dist/chunk-PZTA6NCD.js +69 -0
  33. package/dist/chunk-PZTA6NCD.js.map +1 -0
  34. package/dist/{chunk-UWL6U3L7.cjs → chunk-RMJGF7MN.cjs} +3 -3
  35. package/dist/{chunk-UWL6U3L7.cjs.map → chunk-RMJGF7MN.cjs.map} +1 -1
  36. package/dist/{chunk-EIUS2K72.js → chunk-TX6VUYBC.js} +3 -3
  37. package/dist/{chunk-EIUS2K72.js.map → chunk-TX6VUYBC.js.map} +1 -1
  38. package/dist/{chunk-LQFQ2UKU.cjs → chunk-WWUKTXPX.cjs} +3 -3
  39. package/dist/{chunk-LQFQ2UKU.cjs.map → chunk-WWUKTXPX.cjs.map} +1 -1
  40. package/dist/chunk-Z4CW3U6C.js +231 -0
  41. package/dist/chunk-Z4CW3U6C.js.map +1 -0
  42. package/dist/editor.cjs +4 -4
  43. package/dist/editor.js +2 -2
  44. package/dist/index-DXUAAZzE.d.cts +157 -0
  45. package/dist/index-DXUAAZzE.d.ts +157 -0
  46. package/dist/index.cjs +160 -138
  47. package/dist/index.d.cts +3 -1
  48. package/dist/index.d.ts +3 -1
  49. package/dist/index.js +27 -25
  50. package/dist/inputs.cjs +9 -9
  51. package/dist/inputs.js +3 -3
  52. package/dist/json-editor.cjs +15 -15
  53. package/dist/json-editor.js +4 -4
  54. package/dist/magic-wand.cjs +4 -4
  55. package/dist/magic-wand.js +3 -3
  56. package/dist/prompt-input.cjs +5 -4
  57. package/dist/prompt-input.d.cts +2 -77
  58. package/dist/prompt-input.d.ts +2 -77
  59. package/dist/prompt-input.js +4 -3
  60. package/dist/reason-tag.cjs +4 -4
  61. package/dist/reason-tag.js +3 -3
  62. package/dist/virtual-list.cjs +13 -0
  63. package/dist/virtual-list.cjs.map +1 -0
  64. package/dist/virtual-list.d.cts +125 -0
  65. package/dist/virtual-list.d.ts +125 -0
  66. package/dist/virtual-list.js +4 -0
  67. package/dist/virtual-list.js.map +1 -0
  68. package/package.json +23 -2
  69. package/dist/chunk-B4PFNSX7.js.map +0 -1
  70. package/dist/chunk-VRJTPXJ7.cjs.map +0 -1
@@ -0,0 +1,157 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode } from 'react';
3
+
4
+ /**
5
+ * Which modifier key the user actually has.
6
+ *
7
+ * This exists because a keyboard hint is a CLAIM about the reader's hardware.
8
+ * `⌘ + Enter to send` on Windows or Linux names a key that is not on the
9
+ * keyboard, and a reader who cannot act on a hint learns to ignore hints — so
10
+ * the cost is not one wrong glyph, it is the credibility of every hint beside
11
+ * it. (Reported from a real Electron app running on Linux, where the glyph had
12
+ * no font behind it either and rendered as tofu.)
13
+ *
14
+ * Two deliberate choices:
15
+ *
16
+ * 1. **The platform is an ARGUMENT, never a global read.** `detectPlatform`
17
+ * takes the hints; `modifierKeyLabel` takes the verdict. Both branches are
18
+ * therefore reachable from one machine, which is the only way a test can
19
+ * cover the platform you are not sitting at. A function that reads
20
+ * `navigator` internally can only ever be tested on the developer's own OS.
21
+ * 2. **`generic` is the fallback, and that is not arbitrary.** Every Fancy
22
+ * surface that submits on a modifier accepts `metaKey || ctrlKey`, so
23
+ * `Ctrl` is a TRUE label on an Apple keyboard while `⌘` is a FALSE one
24
+ * everywhere else. The honest default is the one that is pressable on all
25
+ * of them.
26
+ */
27
+ type FancyPlatform = "apple" | "generic";
28
+ /**
29
+ * The parts of `navigator` the detection reads — nothing more, so a caller can
30
+ * hand it a literal (a test, an Electron main process forwarding `process.platform`,
31
+ * a server with a stored preference).
32
+ */
33
+ interface PlatformHints {
34
+ /** `navigator.userAgentData` — the modern, non-spoofed answer where it exists. */
35
+ userAgentData?: {
36
+ platform?: string;
37
+ } | null;
38
+ /** `navigator.platform` — deprecated, still the most reliable legacy signal. */
39
+ platform?: string | null;
40
+ /** `navigator.userAgent` — last resort. */
41
+ userAgent?: string | null;
42
+ }
43
+ /** Resolve a platform from navigator-shaped hints. Unknown or absent ⇒ `generic`. */
44
+ declare function detectPlatform(hints?: PlatformHints | null): FancyPlatform;
45
+ /**
46
+ * The modifier key to NAME for a platform.
47
+ *
48
+ * `⌘` is emitted for `apple` and nothing else. A test enumerates the platform
49
+ * values and counts that no other one can produce it, because a hint that names
50
+ * the wrong key is worse than no hint.
51
+ */
52
+ declare function modifierKeyLabel(platform: FancyPlatform): "⌘" | "Ctrl";
53
+ /** SSR-safe read of the live browser hints. `null` off a browser. */
54
+ declare function browserPlatformHints(): PlatformHints | null;
55
+
56
+ /**
57
+ * PromptInput — the chat composer every AI app rebuilds. Auto-growing
58
+ * multi-line input with:
59
+ *
60
+ * • slash-command picker (`/` triggers a filtered command palette,
61
+ * ↑/↓ navigate, Enter inserts)
62
+ * • mention picker (`@` triggers, filtered against `mentions`)
63
+ * • drop-to-attach (drag files anywhere on the surface), paste-to-attach
64
+ * (a pasted screenshot becomes an attachment) + chip bar
65
+ * • submit on ⌘/Ctrl+Enter (plain Enter inserts a newline)
66
+ * • live token-budget meter (green → amber → red as headroom drops)
67
+ *
68
+ * Wire it up:
69
+ *
70
+ * <PromptInput
71
+ * budgetTokens={32000}
72
+ * commands={[{ name: "/rewrite", hint: "rewrite the selection" }]}
73
+ * mentions={[{ id: "ada", name: "Ada", kind: "person" }]}
74
+ * onSubmit={(text, attachments) => sendToAgent(text, attachments)}
75
+ * />
76
+ */
77
+ type PromptCmd = {
78
+ name: string;
79
+ hint: string;
80
+ };
81
+ type PromptMention = {
82
+ id: string;
83
+ name: string;
84
+ kind: "agent" | "file" | "person" | string;
85
+ };
86
+ type PromptAttachment = {
87
+ id: string;
88
+ name: string;
89
+ bytes: number;
90
+ /**
91
+ * The file the user actually attached.
92
+ *
93
+ * Optional because an attachment restored from a server has no File — but for
94
+ * anything the user dropped or picked it is always present. Without it a host
95
+ * can render a chip and nothing else: no POST, no FormData, no send-to-model.
96
+ */
97
+ file?: File;
98
+ /** MIME type. Hosts branch on this to decide whether a file can be sent as-is. */
99
+ type?: string;
100
+ };
101
+ /**
102
+ * `...rest` reaches the root surface, so a consumer or a bridge can tag the
103
+ * composer with its own `data-*` handle. The component named every prop it
104
+ * used and had no rest spread, which means a `data-handle` put on it was
105
+ * DROPPED — silently, since React discards unknown props and the component
106
+ * still renders perfectly. That is issue #22 all over again, and the contract
107
+ * calls it out: "Each interactive element has a stable identity. Agents never
108
+ * guess DOM."
109
+ */
110
+ interface PromptInputProps extends Omit<HTMLAttributes<HTMLDivElement>, "onSubmit" | "className"> {
111
+ /** Extra classes on the root surface. MERGED, never replaced. */
112
+ className?: string;
113
+ /** Token budget for the meter. */
114
+ budgetTokens: number;
115
+ /** Slash-commands. Names must start with `/`. */
116
+ commands?: PromptCmd[];
117
+ /** @-mentions. */
118
+ mentions?: PromptMention[];
119
+ /** Show the keyboard hint ("Ctrl + Enter to send", "⌘ + Enter" on a Mac). */
120
+ showHint?: boolean;
121
+ /**
122
+ * Which modifier the hint and the default placeholder NAME. Omit it and the
123
+ * component reads the platform after mount, which is the right answer for an
124
+ * ordinary web app.
125
+ *
126
+ * Pass it when the host knows better than `navigator` does — an Electron
127
+ * renderer forwarding `process.platform`, a remote session where the
128
+ * keyboard is not the one running the browser, or a test that needs the
129
+ * branch it is not sitting on. The pressed keys are unaffected either way:
130
+ * submit is `⌘/Ctrl+Enter` on every platform, so this only decides which
131
+ * true key gets named.
132
+ */
133
+ platform?: FancyPlatform;
134
+ /** Called on ⌘/Ctrl+Enter or send button. */
135
+ onSubmit: (text: string, attachments: PromptAttachment[]) => void;
136
+ /**
137
+ * Placeholder text. Defaults to a hint naming the modifier THIS platform
138
+ * actually has, so leaving it unset is the better option — a hardcoded
139
+ * placeholder is the other place a `⌘` ends up in front of a Windows user.
140
+ */
141
+ placeholder?: string;
142
+ /** Rough estimator: chars-per-token. Defaults to 4. */
143
+ charsPerToken?: number;
144
+ /** Color → CSS chip mapping for mention kinds. */
145
+ mentionColor?: Record<string, string>;
146
+ /** Optional max textarea height in px. Defaults to 280. */
147
+ maxHeight?: number;
148
+ /**
149
+ * Rendered INSIDE the rounded shell, ABOVE the attachments bar and
150
+ * textarea. Use this slot for a drawer of tools/files/prompts/etc. so
151
+ * the drawer and composer share one visual panel. See {@link ChatDrawer}.
152
+ */
153
+ aboveInput?: ReactNode;
154
+ }
155
+ declare function PromptInput({ budgetTokens, commands, mentions, showHint, platform, onSubmit, placeholder, charsPerToken, mentionColor, maxHeight, aboveInput, className, ...rest }: PromptInputProps): react.JSX.Element;
156
+
157
+ export { type FancyPlatform as F, type PlatformHints as P, type PromptAttachment as a, type PromptCmd as b, PromptInput as c, type PromptInputProps as d, type PromptMention as e, browserPlatformHints as f, detectPlatform as g, modifierKeyLabel as m };