@gemboss/ui 0.63.0 → 0.65.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.
- package/CHANGELOG.md +98 -0
- package/README.md +98 -4
- package/catalog/editor.html +1 -1
- package/catalog/index.html +23 -20
- package/gemboss-ui.css +2 -2
- package/package.json +9 -1
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/assistant/chat.tsx +67 -4
- package/src/assistant/dictation.ts +292 -0
- package/src/assistant/index.ts +4 -1
- package/src/audiences-table.css +1 -0
- package/src/audiences-table.tsx +167 -0
- package/src/chat-voice.css +1 -0
- package/src/editor/color-choices.ts +9 -0
- package/src/editor/controls.tsx +5 -2
- package/src/editor/field-control.tsx +453 -0
- package/src/editor/field-frame.tsx +182 -0
- package/src/editor/field-spec.ts +345 -0
- package/src/editor/index.ts +16 -0
- package/src/editor.css +1 -1
- package/src/email-editor/editor.tsx +462 -0
- package/src/email-editor/index.ts +16 -0
- package/src/email-editor/model.ts +361 -0
- package/src/email-editor/preview.tsx +208 -0
- package/src/email-editor.css +1 -0
- package/src/gem-at-work.css +1 -1
- package/src/gem-at-work.ts +273 -15
- package/src/index.ts +2 -1
- package/src/list-page.tsx +87 -4
- package/src/skill-feedback.css +1 -1
- package/src/skill-feedback.tsx +5 -1
- package/src/skill-history.tsx +2 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SPEAKING INSTEAD OF TYPING: the browser's own speech to text (the Web Speech API), into a text box the seller can still edit.
|
|
5
|
+
* Moved here from the admin (apps/admin lib/dictation.ts + lib/use-dictation.ts, 19/10/2026, #4581) on 08/11/2026 (UI book
|
|
6
|
+
* B15-voice, Chris 07/11: "Browser speech"), so the chat composer draws the microphone ONCE (ChatComposer `voice`) and every other
|
|
7
|
+
* box that takes speech (the admin's Composer dialog, Tell Gem) listens through the same hook.
|
|
8
|
+
*
|
|
9
|
+
* WHERE THE AUDIO GOES. The browser listens and writes it down: Chrome sends the audio to Google's speech service, Edge to
|
|
10
|
+
* Microsoft's, Safari to Apple's or does it on the device. The page gets text, the same text the seller could have typed. Nothing
|
|
11
|
+
* here records, stores or sends audio, and nothing is sent anywhere until the seller presses Send. No paid transcription
|
|
12
|
+
* (Gems/CLAUDE.md §11). The note the seller reads says so in one line (DICTATION_NOTE): one honest line for every browser, since
|
|
13
|
+
* which service a browser uses cannot be told apart from the page.
|
|
14
|
+
*
|
|
15
|
+
* WHAT IT DOES, each one a case in chat-voice-browser.test.tsx:
|
|
16
|
+
* - what is said shows in the box AS IT IS SAID (interim results), after whatever was typed, and stays editable;
|
|
17
|
+
* - pressing the mic again stops, and so does a pause (`silenceMs` after the last words, `firstWordsMs` before any);
|
|
18
|
+
* - the seller typing, sending or clearing while it listens stops it, and what is in the box stays as they left it;
|
|
19
|
+
* - a failure (blocked microphone, no speech, no network) is one line saying what to do; the text is never touched;
|
|
20
|
+
* - where the browser has no recognition, or the page's frame may not use the microphone, `supported` is false and there is
|
|
21
|
+
* no button at all (not a disabled one).
|
|
22
|
+
* No dependency but React, and no CSS: the admin imports it from `@gemboss/ui/assistant/dictation` on screens with no chat.
|
|
23
|
+
*/
|
|
24
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
25
|
+
|
|
26
|
+
/** The one line every microphone shows: what turns the voice into text, and where it goes. */
|
|
27
|
+
export const DICTATION_NOTE = "Your browser turns your voice into text. In Chrome this goes through Google.";
|
|
28
|
+
/** A pause this long after the last words ends listening; before any words, the browser's own no-speech (or `firstWordsMs`). */
|
|
29
|
+
export const DICTATION_SILENCE_MS = 6000;
|
|
30
|
+
export const DICTATION_FIRST_WORDS_MS = 10000;
|
|
31
|
+
/** A stop the browser has not ended in this long is ended here (Safari, a dropped speech service: no `end` ever comes). */
|
|
32
|
+
export const DICTATION_STOP_GRACE_MS = 2000;
|
|
33
|
+
|
|
34
|
+
interface SpeechAlternativeLike { readonly transcript: string }
|
|
35
|
+
interface SpeechResultLike { readonly isFinal: boolean; readonly length: number; readonly [i: number]: SpeechAlternativeLike }
|
|
36
|
+
interface SpeechResultEventLike { readonly resultIndex: number; readonly results: ArrayLike<SpeechResultLike> }
|
|
37
|
+
/** The part of the Web Speech API's SpeechRecognition used here (lib.dom does not type it). */
|
|
38
|
+
export interface SpeechRecognitionLike {
|
|
39
|
+
lang: string;
|
|
40
|
+
continuous: boolean;
|
|
41
|
+
interimResults: boolean;
|
|
42
|
+
maxAlternatives: number;
|
|
43
|
+
start(): void;
|
|
44
|
+
stop(): void;
|
|
45
|
+
abort(): void;
|
|
46
|
+
onresult: ((e: SpeechResultEventLike) => void) | null;
|
|
47
|
+
onerror: ((e: { error: string }) => void) | null;
|
|
48
|
+
onend: (() => void) | null;
|
|
49
|
+
}
|
|
50
|
+
type RecognitionCtor = new () => SpeechRecognitionLike;
|
|
51
|
+
interface PolicyLike { allowsFeature(feature: string): boolean }
|
|
52
|
+
/** What `canDictate` reads from a window: the constructor (prefixed in Chrome and Safari) and the frame's permissions policy. */
|
|
53
|
+
export interface DictationWindow {
|
|
54
|
+
SpeechRecognition?: RecognitionCtor;
|
|
55
|
+
webkitSpeechRecognition?: RecognitionCtor;
|
|
56
|
+
document?: { permissionsPolicy?: PolicyLike; featurePolicy?: PolicyLike };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const here = (): DictationWindow | undefined => (typeof window === "undefined" ? undefined : (window as unknown as DictationWindow));
|
|
60
|
+
|
|
61
|
+
export function speechRecognitionIn(win: DictationWindow | undefined = here()): RecognitionCtor | null {
|
|
62
|
+
return win?.SpeechRecognition ?? win?.webkitSpeechRecognition ?? null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The browser can listen here. False without the API (Firefox), and false where the page sits in a frame that may not use the
|
|
67
|
+
* microphone (the Shopify admin's embed when it grants none): a button there could only ever fail, so there is none.
|
|
68
|
+
*/
|
|
69
|
+
export function canDictate(win: DictationWindow | undefined = here()): boolean {
|
|
70
|
+
if (!speechRecognitionIn(win)) return false;
|
|
71
|
+
const policy = win?.document?.permissionsPolicy ?? win?.document?.featurePolicy;
|
|
72
|
+
try {
|
|
73
|
+
if (policy && typeof policy.allowsFeature === "function" && !policy.allowsFeature("microphone")) return false;
|
|
74
|
+
} catch { /* a policy object that throws says nothing either way */ }
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `canDictate`, as a hook: false on the server and the first paint, then what the browser says (a screen that only offers the
|
|
79
|
+
* microphone, and hands the listening to another, shows the button only where it can work). */
|
|
80
|
+
export function useCanDictate(): boolean {
|
|
81
|
+
const [can, setCan] = useState(false);
|
|
82
|
+
useEffect(() => { setCan(canDictate()); }, []);
|
|
83
|
+
return can;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* What was said, after what is already in the box: one space between, nothing doubled, nothing lost. A recognizer writes each
|
|
88
|
+
* phrase in lower case, so one that starts a sentence (the box is empty, or ends on . ! ? …) gets its capital.
|
|
89
|
+
*/
|
|
90
|
+
export function appendDictated(prev: string, said: string): string {
|
|
91
|
+
const s = said.trim();
|
|
92
|
+
if (!s) return prev;
|
|
93
|
+
const p = prev.replace(/\s+$/, "");
|
|
94
|
+
const startsSentence = !p || /[.!?…]$/.test(p);
|
|
95
|
+
const phrase = startsSentence ? s.charAt(0).toLocaleUpperCase() + s.slice(1) : s;
|
|
96
|
+
return p ? `${p} ${phrase}` : phrase;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Everything heard this time, final and interim, as one phrase (in continuous mode `results` holds the whole session). */
|
|
100
|
+
export function heardSoFar(results: ArrayLike<SpeechResultLike>): string {
|
|
101
|
+
const parts: string[] = [];
|
|
102
|
+
for (let i = 0; i < results.length; i++) {
|
|
103
|
+
const t = results[i]?.[0]?.transcript?.trim();
|
|
104
|
+
if (t) parts.push(t);
|
|
105
|
+
}
|
|
106
|
+
return parts.join(" ");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The line a seller reads when speaking did not work, by the browser's error code (a stop this side made says nothing: the hook
|
|
111
|
+
* never asks). Each says what to do next; a blocked microphone says where the browser keeps the switch.
|
|
112
|
+
*/
|
|
113
|
+
export function dictationProblemText(code: string, lang?: string): string {
|
|
114
|
+
switch (code) {
|
|
115
|
+
case "not-allowed":
|
|
116
|
+
return "Your browser blocked the microphone for this site. To allow it, click the icon at the left of the address bar, turn on Microphone, then press the mic again.";
|
|
117
|
+
case "service-not-allowed":
|
|
118
|
+
return "Your browser does not let this site turn speech into text. Allow the microphone in the site settings (the icon at the left of the address bar), or type instead.";
|
|
119
|
+
case "no-speech": return "No speech was heard. Press the mic and speak, or type instead.";
|
|
120
|
+
case "audio-capture": return "No microphone was found. Connect one or check your sound settings, then press the mic again.";
|
|
121
|
+
case "network": return "Your browser could not reach its speech service. Check your connection and press the mic again. What you said so far is still in the box.";
|
|
122
|
+
case "language-not-supported": return `Your browser cannot turn ${lang ? `${lang} ` : ""}speech into text. Type instead.`;
|
|
123
|
+
case "aborted": return "Listening stopped. What you said so far is still in the box.";
|
|
124
|
+
default: return "Speech to text stopped working. What you said so far is still in the box. Press the mic to try again.";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const LANG_DEFAULT_REGION: Record<string, string> = { en: "en-US", vi: "vi-VN", zh: "zh-CN", es: "es-ES", fr: "fr-FR", de: "de-DE", ja: "ja-JP", ko: "ko-KR", th: "th-TH", id: "id-ID", pt: "pt-BR" };
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The language to listen for. A language the app knows for sure wins (`preferred`: "vi" or "vi-VN"); a bare code takes the
|
|
132
|
+
* browser's own variant of it when it has one ("en" → "en-GB" for a British browser). A language the app only guesses
|
|
133
|
+
* (`likely`: a conversation stamped "en", which is also what every language that is not Vietnamese is stamped) wins only where
|
|
134
|
+
* the browser lists it (a Vietnamese Chrome lists English too; a Spanish one does not). Otherwise: the person's first language
|
|
135
|
+
* as their browser names it, not the admin's (English).
|
|
136
|
+
*/
|
|
137
|
+
export function dictationLanguage(nav: { language?: string; languages?: readonly string[] } | undefined, preferred?: string | null, likely?: string | null): string {
|
|
138
|
+
const mine = [...(nav?.languages ?? []), ...(nav?.language ? [nav.language] : [])].filter(Boolean);
|
|
139
|
+
const variant = (code: string) => mine.find((l) => l.toLowerCase() === code || l.toLowerCase().startsWith(`${code}-`));
|
|
140
|
+
const want = preferred?.trim();
|
|
141
|
+
if (want) {
|
|
142
|
+
if (want.includes("-")) return want;
|
|
143
|
+
const code = want.toLowerCase();
|
|
144
|
+
return variant(code) ?? LANG_DEFAULT_REGION[code] ?? code;
|
|
145
|
+
}
|
|
146
|
+
const guess = likely?.trim().toLowerCase().split("-")[0];
|
|
147
|
+
const listed = guess ? variant(guess) : undefined;
|
|
148
|
+
if (listed) return listed;
|
|
149
|
+
return mine[0] || "en-US";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface DictationOptions {
|
|
153
|
+
/**
|
|
154
|
+
* The box's text and its setter: what is heard is written into it (after what was there), as it is heard. The HOST calls
|
|
155
|
+
* `cancel()` on the seller's own edits (its field's onChange, a Clear): the hook sees only the text, and an edit back to words
|
|
156
|
+
* it wrote looks like its own write. A change to the text it did not write stops it too (a send that clears, a starter).
|
|
157
|
+
*/
|
|
158
|
+
text: string;
|
|
159
|
+
onText: (next: string) => void;
|
|
160
|
+
/** Off: the host draws no microphone (`supported` is false), and a session that is running stops. Default on. */
|
|
161
|
+
enabled?: boolean;
|
|
162
|
+
/** See `dictationLanguage`: a language known for sure, and one only guessed (used where the browser lists it). */
|
|
163
|
+
lang?: string | null;
|
|
164
|
+
likelyLang?: string | null;
|
|
165
|
+
/** The box's own limit: what is heard is cut to it before it is written, so the box never holds more than it takes. */
|
|
166
|
+
maxLength?: number;
|
|
167
|
+
silenceMs?: number;
|
|
168
|
+
firstWordsMs?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface Dictation {
|
|
172
|
+
/** The browser can listen here (known only after mount: false on the server and on the first paint). */
|
|
173
|
+
supported: boolean;
|
|
174
|
+
listening: boolean;
|
|
175
|
+
/** What went wrong, as a sentence, until the next press. */
|
|
176
|
+
problem: string | null;
|
|
177
|
+
start: () => void;
|
|
178
|
+
/** Stop listening and keep what was heard (the browser still writes its last words). */
|
|
179
|
+
stop: () => void;
|
|
180
|
+
/** Stop at once: nothing more is written (the box was sent, cleared, typed in or turned off). */
|
|
181
|
+
cancel: () => void;
|
|
182
|
+
toggle: () => void;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The hook. Hosts: ChatComposer (`voice`), and the admin's Composer dialog and Tell Gem card. */
|
|
186
|
+
export function useDictation(o: DictationOptions): Dictation {
|
|
187
|
+
const enabled = o.enabled !== false;
|
|
188
|
+
// Known only in the browser, so it starts false and the server and the first paint agree.
|
|
189
|
+
const supported = useCanDictate();
|
|
190
|
+
const [listening, setListening] = useState(false);
|
|
191
|
+
const [problem, setProblem] = useState<string | null>(null);
|
|
192
|
+
// The session that may write into the box. Null once it ended, or the moment it is cancelled (its late events are dropped).
|
|
193
|
+
const rec = useRef<SpeechRecognitionLike | null>(null);
|
|
194
|
+
// Sessions this side ended (a press, a pause, an edit, a send): the browser's "aborted" for them says nothing.
|
|
195
|
+
const ours = useRef(new WeakSet<SpeechRecognitionLike>());
|
|
196
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
197
|
+
// The text when it started, and the last values written: the box holding anything else means the seller changed it.
|
|
198
|
+
const base = useRef("");
|
|
199
|
+
const written = useRef<string[]>([]);
|
|
200
|
+
const latest = useRef(o);
|
|
201
|
+
useEffect(() => { latest.current = o; });
|
|
202
|
+
|
|
203
|
+
const clearTimer = useCallback(() => { if (timer.current) { clearTimeout(timer.current); timer.current = null; } }, []);
|
|
204
|
+
const end = useCallback((how: "stop" | "cancel") => {
|
|
205
|
+
const r = rec.current;
|
|
206
|
+
if (!r) return;
|
|
207
|
+
// Already stopping (a second press while the browser finishes): the seller insists, so it ends now.
|
|
208
|
+
const stopping = ours.current.has(r);
|
|
209
|
+
ours.current.add(r);
|
|
210
|
+
clearTimer();
|
|
211
|
+
const drop = () => {
|
|
212
|
+
rec.current = null;
|
|
213
|
+
setListening(false);
|
|
214
|
+
try { r.abort(); } catch { /* already ended */ }
|
|
215
|
+
};
|
|
216
|
+
if (how === "cancel" || stopping) { drop(); return; }
|
|
217
|
+
try { r.stop(); } catch { /* already ended */ }
|
|
218
|
+
// The browser writes its last words and ends; one that never ends would leave the mic pressed and every press a no-op. Ended
|
|
219
|
+
// here, it says so: its last words may not have come.
|
|
220
|
+
timer.current = setTimeout(() => {
|
|
221
|
+
if (rec.current !== r) return;
|
|
222
|
+
drop();
|
|
223
|
+
setProblem(dictationProblemText("aborted"));
|
|
224
|
+
}, DICTATION_STOP_GRACE_MS);
|
|
225
|
+
}, [clearTimer]);
|
|
226
|
+
const cancel = useCallback(() => end("cancel"), [end]);
|
|
227
|
+
const stop = useCallback(() => end("stop"), [end]);
|
|
228
|
+
|
|
229
|
+
// Leaving the screen, or the feature turning off, stops the microphone: a box the seller left must not keep listening.
|
|
230
|
+
useEffect(() => cancel, [cancel]);
|
|
231
|
+
useEffect(() => { if (!enabled) cancel(); }, [enabled, cancel]);
|
|
232
|
+
// The seller typed, sent or cleared while it listened: stop, and leave the box exactly as they made it.
|
|
233
|
+
useEffect(() => { if (rec.current && !written.current.includes(o.text)) cancel(); }, [o.text, cancel]);
|
|
234
|
+
|
|
235
|
+
const start = useCallback(() => {
|
|
236
|
+
const Ctor = speechRecognitionIn();
|
|
237
|
+
const opts = latest.current;
|
|
238
|
+
if (!Ctor || rec.current || opts.enabled === false) return;
|
|
239
|
+
const r = new Ctor();
|
|
240
|
+
const lang = dictationLanguage(typeof navigator === "undefined" ? undefined : navigator, opts.lang, opts.likelyLang);
|
|
241
|
+
r.lang = lang;
|
|
242
|
+
r.continuous = true;
|
|
243
|
+
r.interimResults = true;
|
|
244
|
+
r.maxAlternatives = 1;
|
|
245
|
+
let heard = false;
|
|
246
|
+
const arm = (ms: number) => {
|
|
247
|
+
clearTimer();
|
|
248
|
+
timer.current = setTimeout(() => {
|
|
249
|
+
if (rec.current !== r) return;
|
|
250
|
+
// A pause after words ends it quietly; nothing at all said is the browser's no-speech, said the same way.
|
|
251
|
+
if (!heard) setProblem(dictationProblemText("no-speech", lang));
|
|
252
|
+
end("stop");
|
|
253
|
+
}, ms);
|
|
254
|
+
};
|
|
255
|
+
r.onresult = (e) => {
|
|
256
|
+
if (rec.current !== r) return;
|
|
257
|
+
heard = true;
|
|
258
|
+
const { onText, maxLength } = latest.current;
|
|
259
|
+
let next = appendDictated(base.current, heardSoFar(e.results));
|
|
260
|
+
if (maxLength != null && maxLength >= 0) next = next.slice(0, maxLength);
|
|
261
|
+
// This write and the one before it: two results may land before the box re-renders with the first.
|
|
262
|
+
written.current = [written.current[written.current.length - 1] ?? base.current, next];
|
|
263
|
+
onText(next);
|
|
264
|
+
if (!ours.current.has(r)) arm(latest.current.silenceMs ?? DICTATION_SILENCE_MS);
|
|
265
|
+
};
|
|
266
|
+
r.onerror = (e) => {
|
|
267
|
+
if (ours.current.has(r) || rec.current !== r) return;
|
|
268
|
+
setProblem(dictationProblemText(e.error, lang));
|
|
269
|
+
};
|
|
270
|
+
r.onend = () => {
|
|
271
|
+
if (rec.current !== r) return;
|
|
272
|
+
clearTimer();
|
|
273
|
+
rec.current = null;
|
|
274
|
+
setListening(false);
|
|
275
|
+
};
|
|
276
|
+
setProblem(null);
|
|
277
|
+
base.current = opts.text;
|
|
278
|
+
written.current = [opts.text];
|
|
279
|
+
try {
|
|
280
|
+
r.start();
|
|
281
|
+
rec.current = r;
|
|
282
|
+
setListening(true);
|
|
283
|
+
arm(opts.firstWordsMs ?? DICTATION_FIRST_WORDS_MS);
|
|
284
|
+
} catch {
|
|
285
|
+
setProblem(dictationProblemText("start_failed", lang));
|
|
286
|
+
}
|
|
287
|
+
}, [end, clearTimer]);
|
|
288
|
+
|
|
289
|
+
const toggle = useCallback(() => { if (rec.current) stop(); else start(); }, [start, stop]);
|
|
290
|
+
|
|
291
|
+
return { supported: supported && enabled, listening, problem, start, stop, cancel, toggle };
|
|
292
|
+
}
|
package/src/assistant/index.ts
CHANGED
|
@@ -9,7 +9,10 @@ export { BRIDGE_TONE, BridgeNotice, ENGINE_PICKER_EN, EnginePicker, engineChipNa
|
|
|
9
9
|
// (`onOpenSettings`), the section draws it.
|
|
10
10
|
export { EngineSettings, EngineSettingsSection, type EngineSettingsProps } from "./engine-settings";
|
|
11
11
|
// 0.29.0: the chat BODY as components (the surface hands in messages and actions), its markdown, and each engine's mark.
|
|
12
|
-
export { AssistantChat, ChatAttach, ChatBubble, ChatComposer, ChatError, ChatLabelsProvider, ChatMarkdown, ChatMessage, ChatMeta, ChatNote, ChatPending, ChatStarters, ChatSteps, ChatThread, CHAT_EN, PaperclipIcon, firstBlank, selectBlank, useComposerDensity, useFullChromeRoom, type AssistantChatProps, type ChatComposerProps, type ChatFix, type ChatLabels, type ChatMarkdownProps, type ChatMessageData, type ChatStarter, type ChatStep, type ComposerDensity } from "./chat";
|
|
12
|
+
export { AssistantChat, ChatAttach, ChatBubble, ChatComposer, ChatError, ChatLabelsProvider, ChatMarkdown, ChatMessage, ChatMeta, ChatNote, ChatPending, ChatStarters, ChatSteps, ChatThread, CHAT_EN, PaperclipIcon, firstBlank, selectBlank, useComposerDensity, useFullChromeRoom, type AssistantChatProps, type ChatComposerProps, type ChatComposerVoice, type ChatFix, type ChatLabels, type ChatMarkdownProps, type ChatMessageData, type ChatStarter, type ChatStep, type ComposerDensity } from "./chat";
|
|
13
|
+
// Speaking instead of typing (B15-voice, 08/11/2026): the hook ChatComposer's `voice` runs on, for a box that is not a chat. Also
|
|
14
|
+
// its own entry, `@gemboss/ui/assistant/dictation` (no CSS on the way).
|
|
15
|
+
export { DICTATION_NOTE, appendDictated, canDictate, dictationLanguage, dictationProblemText, useCanDictate, useDictation, type Dictation, type DictationOptions } from "./dictation";
|
|
13
16
|
export { bareUrl, CODE_FOLD_LINES, FLEET_IMAGE_HOSTS, imageSource, linkTarget, parseBlocks, parseInline, type Block, type ImageHost, type Inline, type InlineOptions } from "./chat-markdown";
|
|
14
17
|
export { ENGINE_MARK_ART, ENGINE_MARK_FILL_RULE, EngineMark, isEngineMarkId, type EngineMarkArt, type EngineMarkId } from "./engine-mark";
|
|
15
18
|
export { atBridge, BRIDGE_GONE, bridgeTurnError, PAIRING_REJECTED, useChatTurns, type ChatTurns, type TurnError } from "./chat-turns";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-audiences__meta{display:inline-flex;align-items:center;gap:6px;min-width:0}.ui-audiences__src{flex:none;padding:0 6px;border-radius:5px;font-size:12px;font-weight:600;line-height:16px}.ui-audiences__src--site{background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent-strong, #3a44de)}.ui-audiences__src--email{background:var(--gemboss-active-bg, #f0f1f4);color:var(--gemboss-text, #1b1c1e)}.ui-audiences__src--imported{background:var(--gemboss-warning-soft, #fff8e0);color:var(--gemboss-warning, #9a6700)}.ui-audiences__src--gemcare{background:var(--gemboss-success-soft, #e3f1df);color:var(--gemboss-success-strong, #0a6a4c)}.ui-audiences__strong{color:var(--gemboss-text, #1b1c1e);font-weight:600}.ui-audiences__delta{white-space:nowrap}.ui-audiences__delta--up{color:var(--gemboss-success-strong, #0a6a4c)}.ui-audiences__delta--down{color:var(--gemboss-danger-strong, #b42318)}.ui-audiences__delta--flat,.ui-audiences__used{color:var(--gemboss-text-muted, #686b71)}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/**
|
|
3
|
+
* AudiencesTable — @gemboss/ui, unreleased (05/11/2026, board GroupsTable on the canvas "Một lõi, ba cửa"; Chris: one word and one list,
|
|
4
|
+
* Audiences). The list of a store's audiences as GemBoss › Reach › Audiences draws it, and GemReach's own admin will reuse it with
|
|
5
|
+
* other words (`labels`): who is in an audience, how many can be emailed, how it moved in a week and what uses it.
|
|
6
|
+
*
|
|
7
|
+
* Columns, as the board draws them: Audience (the name, then its source as a chip and how fresh it is), On site (a dash for what has
|
|
8
|
+
* no count on site), Can email (the figure that matters, in ink), 7 days (green up, red down, muted when there is no change to say)
|
|
9
|
+
* and Used by. Built on the kit's IndexTable, so the whole row opens the audience, a row folds into a list below 768 of its container,
|
|
10
|
+
* and the loading and empty states are the table's own.
|
|
11
|
+
*
|
|
12
|
+
* Every prop is data: a server component can render it. Numbers are numbers, written here with grouped thousands; the week's change is
|
|
13
|
+
* the caller's words ("+40%", "+4", "−3%", "—"), toned by its sign (`audienceDeltaTone`) unless `deltaTone` says otherwise.
|
|
14
|
+
*/
|
|
15
|
+
import "./audiences-table.css";
|
|
16
|
+
import React from "react";
|
|
17
|
+
import { IndexTable, type IndexTableProps, type IndexTableRow } from "./index-table";
|
|
18
|
+
import type { CollectionColumn } from "./collections";
|
|
19
|
+
|
|
20
|
+
/** Where an audience comes from: `site` the store's own Audiences, also on site; `email` email-only rules; an imported list; GemCare's push. */
|
|
21
|
+
export type AudienceSource = "site" | "email" | "imported" | "gemcare";
|
|
22
|
+
export type AudienceDeltaTone = "up" | "down" | "flat";
|
|
23
|
+
|
|
24
|
+
export interface AudiencesTableRow {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
source: AudienceSource;
|
|
28
|
+
/** How fresh it is, in words: "synced 4 min ago", "updated each minute", "list, 12 Oct". */
|
|
29
|
+
sync?: string;
|
|
30
|
+
/** People counted on site. Null: it has no count there, drawn as a dash. */
|
|
31
|
+
onSite: number | null;
|
|
32
|
+
/** People who left an email and agreed to marketing. Null: not known, or not on email yet, drawn as a dash. */
|
|
33
|
+
canEmail: number | null;
|
|
34
|
+
/** The change over 7 days, in the caller's words. Absent or "—": nothing to say. */
|
|
35
|
+
delta?: string;
|
|
36
|
+
deltaTone?: AudienceDeltaTone;
|
|
37
|
+
/** What uses it: "Flow: Quiz result · Campaign: Dry skin bundle". Absent: "—". */
|
|
38
|
+
usedBy?: string;
|
|
39
|
+
/** Where the row opens. Without it the row is not a link. */
|
|
40
|
+
href?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AudiencesTableLabels {
|
|
44
|
+
table: string;
|
|
45
|
+
audience: string;
|
|
46
|
+
onSite: string;
|
|
47
|
+
canEmail: string;
|
|
48
|
+
week: string;
|
|
49
|
+
usedBy: string;
|
|
50
|
+
none: string;
|
|
51
|
+
source: Record<AudienceSource, string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const AUDIENCES_TABLE_LABELS: AudiencesTableLabels = {
|
|
55
|
+
table: "Audiences",
|
|
56
|
+
audience: "Audience",
|
|
57
|
+
onSite: "On site",
|
|
58
|
+
canEmail: "Can email",
|
|
59
|
+
week: "7 days",
|
|
60
|
+
usedBy: "Used by",
|
|
61
|
+
none: "—",
|
|
62
|
+
source: { site: "On site + email", email: "Email only", imported: "Imported", gemcare: "GemCare" },
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Whole class names, never built from a template: a class written out is one grep finds.
|
|
66
|
+
const SOURCE_CLASS: Record<AudienceSource, string> = {
|
|
67
|
+
site: "ui-audiences__src ui-audiences__src--site",
|
|
68
|
+
email: "ui-audiences__src ui-audiences__src--email",
|
|
69
|
+
imported: "ui-audiences__src ui-audiences__src--imported",
|
|
70
|
+
gemcare: "ui-audiences__src ui-audiences__src--gemcare",
|
|
71
|
+
};
|
|
72
|
+
/** An audience's source as a chip: the table's, and the one on the audience's own page. */
|
|
73
|
+
export function AudienceSourceChip({ source, labels }: { source: AudienceSource; labels?: Partial<Record<AudienceSource, string>> }) {
|
|
74
|
+
return <span className={SOURCE_CLASS[source]}>{labels?.[source] ?? AUDIENCES_TABLE_LABELS.source[source]}</span>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const DELTA_CLASS: Record<AudienceDeltaTone, string> = {
|
|
78
|
+
up: "ui-audiences__delta ui-audiences__delta--up",
|
|
79
|
+
down: "ui-audiences__delta ui-audiences__delta--down",
|
|
80
|
+
flat: "ui-audiences__delta ui-audiences__delta--flat",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const COUNT = new Intl.NumberFormat("en-US");
|
|
84
|
+
|
|
85
|
+
/** A count with grouped thousands ("3,412"); not a number: the label for none. */
|
|
86
|
+
export function audienceCount(n: number | null | undefined, none = AUDIENCES_TABLE_LABELS.none): string {
|
|
87
|
+
return typeof n === "number" && Number.isFinite(n) ? COUNT.format(n) : none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The tone of a week's change, read off its sign: a minus (−, the typographic one, or a hyphen) is down, a plus or a bare figure is
|
|
92
|
+
* up, and nothing, a dash or a zero is flat.
|
|
93
|
+
*/
|
|
94
|
+
export function audienceDeltaTone(delta: string | null | undefined): AudienceDeltaTone {
|
|
95
|
+
const t = (delta ?? "").trim();
|
|
96
|
+
if (!t || t === "—" || t === "–" || /^[+−-]?0+(?:[.,]0+)?%?$/.test(t)) return "flat";
|
|
97
|
+
if (t.startsWith("−") || t.startsWith("-")) return "down";
|
|
98
|
+
return "up";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The table's columns, in the board's order. */
|
|
102
|
+
export function audiencesTableColumns(labels: AudiencesTableLabels = AUDIENCES_TABLE_LABELS): CollectionColumn[] {
|
|
103
|
+
return [
|
|
104
|
+
{ key: "audience", header: labels.audience },
|
|
105
|
+
{ key: "onSite", header: labels.onSite, numeric: true, label: labels.onSite },
|
|
106
|
+
{ key: "canEmail", header: labels.canEmail, numeric: true, label: labels.canEmail },
|
|
107
|
+
{ key: "week", header: labels.week, numeric: true, label: labels.week },
|
|
108
|
+
{ key: "usedBy", header: labels.usedBy, truncate: 220, condensed: "hide" },
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The rows as IndexTable takes them: plain data in, cells out. */
|
|
113
|
+
export function audiencesTableRows(rows: readonly AudiencesTableRow[], labels: AudiencesTableLabels = AUDIENCES_TABLE_LABELS): IndexTableRow[] {
|
|
114
|
+
return rows.map((r) => {
|
|
115
|
+
const delta = (r.delta ?? "").trim() || labels.none;
|
|
116
|
+
const tone = r.deltaTone ?? audienceDeltaTone(delta);
|
|
117
|
+
const used = (r.usedBy ?? "").trim() || labels.none;
|
|
118
|
+
return {
|
|
119
|
+
id: r.id,
|
|
120
|
+
title: r.name,
|
|
121
|
+
titleText: r.name,
|
|
122
|
+
...(r.href ? { href: r.href } : {}),
|
|
123
|
+
sub: (
|
|
124
|
+
<span className="ui-audiences__meta">
|
|
125
|
+
<AudienceSourceChip source={r.source} labels={labels.source} />
|
|
126
|
+
{r.sync ? <span>{r.sync}</span> : null}
|
|
127
|
+
</span>
|
|
128
|
+
),
|
|
129
|
+
cells: {
|
|
130
|
+
onSite: audienceCount(r.onSite, labels.none),
|
|
131
|
+
canEmail: <span className="ui-audiences__strong">{audienceCount(r.canEmail, labels.none)}</span>,
|
|
132
|
+
week: <span className={DELTA_CLASS[tone]}>{delta}</span>,
|
|
133
|
+
usedBy: <span className="ui-audiences__used" title={used === labels.none ? undefined : used}>{used}</span>,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface AudiencesTableProps {
|
|
140
|
+
rows: readonly AudiencesTableRow[];
|
|
141
|
+
labels?: Partial<Omit<AudiencesTableLabels, "source">> & { source?: Partial<Record<AudienceSource, string>> };
|
|
142
|
+
/** The app's link (Next's Link), as IndexTable takes it. */
|
|
143
|
+
linkAs?: React.ElementType;
|
|
144
|
+
/** Inside a card that is already the frame (a ListPage card): no border of its own. */
|
|
145
|
+
flush?: boolean;
|
|
146
|
+
state?: IndexTableProps["state"];
|
|
147
|
+
stateSlot?: React.ReactNode;
|
|
148
|
+
loadingRows?: number;
|
|
149
|
+
className?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function AudiencesTable({ rows, labels, linkAs, flush, state, stateSlot, loadingRows, className }: AudiencesTableProps) {
|
|
153
|
+
const words: AudiencesTableLabels = { ...AUDIENCES_TABLE_LABELS, ...labels, source: { ...AUDIENCES_TABLE_LABELS.source, ...labels?.source } };
|
|
154
|
+
return (
|
|
155
|
+
<IndexTable
|
|
156
|
+
label={words.table}
|
|
157
|
+
columns={audiencesTableColumns(words)}
|
|
158
|
+
rows={audiencesTableRows(rows, words)}
|
|
159
|
+
linkAs={linkAs}
|
|
160
|
+
flush={flush}
|
|
161
|
+
state={state}
|
|
162
|
+
stateSlot={stateSlot}
|
|
163
|
+
loadingRows={loadingRows}
|
|
164
|
+
className={className}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.gemboss-ec-input .gemboss-ec-mic{flex:0 0 auto;position:relative;width:44px;height:44px;min-width:44px;padding:0;border:0;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background-color:transparent;color:var(--gemboss-text-muted);cursor:pointer}.gemboss-ec-input .gemboss-ec-mic svg{width:22px;height:22px}.gemboss-ec-input .gemboss-ec-mic:hover:not(:disabled){background-color:var(--gemboss-hover);color:var(--gemboss-text)}.gemboss-ec-input .gemboss-ec-mic:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px}.gemboss-ec-input .gemboss-ec-mic:disabled{opacity:.5;cursor:default}.gemboss-ec-input .gemboss-ec-mic[aria-pressed=true],.gemboss-ec-input .gemboss-ec-mic[aria-pressed=true]:hover:not(:disabled){background-color:var(--gemboss-danger-soft);color:var(--gemboss-danger-strong)}.gemboss-ec-input .gemboss-ec-mic[aria-pressed=true]:after{content:"";position:absolute;inset:0;border-radius:50%;border:2px solid var(--gemboss-danger-strong);pointer-events:none;animation:gemboss-ec-mic-ring 1.6s ease-out infinite}@keyframes gemboss-ec-mic-ring{0%{opacity:1;transform:scale(1)}to{opacity:.25;transform:scale(1.12)}}@media (prefers-reduced-motion: reduce){.gemboss-ec-input .gemboss-ec-mic[aria-pressed=true]:after{animation:none}}@media (pointer: coarse){.gemboss-ec-input .gemboss-ec-mic{width:44px;height:44px;min-width:44px}}.gemboss-ec-voice{flex:1 0 100%;box-sizing:border-box;margin:0;padding:0 8px;border:solid transparent;border-width:0 1px;font-size:var(--gemboss-fs-caption);line-height:1.4;color:var(--gemboss-text-muted)}.gemboss-ec-voice:empty{position:absolute;width:1px;height:1px;padding:0;border-width:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.gemboss-ec-input:has(>.gemboss-ec-voice:not(:empty)):has(>.gemboss-ec-toolbar>.gemboss-ec-toolbar-lead:empty){flex-wrap:wrap}.gemboss-ec-voice-on{font-weight:600;color:var(--gemboss-danger-strong)}.gemboss-ec-voice-on:before{content:"";display:inline-block;width:8px;height:8px;margin-right:6px;border-radius:50%;vertical-align:1px;background-color:currentColor}.gemboss-ec-voice-problem{color:var(--gemboss-text)}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// THE COLOURS A COLOUR FIELD OFFERS AS CHIPS (A4b, 21/10/2026; moved from the admin's lib/color-choices.ts with FieldControl, 08/11/2026):
|
|
2
|
+
// the context a host fills (the admin's element panel: the theme's colours by role, then the ones used lately on the store) and every
|
|
3
|
+
// colour field of a form reads. Null: no chips (the theme inspector has no page). Its own module, no JSX, so a node test reads it.
|
|
4
|
+
import { createContext } from "react";
|
|
5
|
+
import type { ColorChoice } from "./controls";
|
|
6
|
+
|
|
7
|
+
export type ColorChoices = { choices: ColorChoice[]; remember: (color: string) => void };
|
|
8
|
+
/** What a colour field offers (null: no chips). */
|
|
9
|
+
export const ColorChoicesContext = createContext<ColorChoices | null>(null);
|
package/src/editor/controls.tsx
CHANGED
|
@@ -471,10 +471,13 @@ export const ChipButton = forwardRef<HTMLButtonElement, {
|
|
|
471
471
|
disabled?: boolean;
|
|
472
472
|
/** `aria-expanded`, for a chip that opens something under it (the Library grid). */
|
|
473
473
|
expanded?: boolean;
|
|
474
|
+
/** Its name for a screen reader when its words alone are one of many alike ("All settings" in each element's group: "All settings
|
|
475
|
+
* for Row"); absent, its words are its name. */
|
|
476
|
+
label?: string;
|
|
474
477
|
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
475
478
|
children: React.ReactNode;
|
|
476
|
-
}>(function ChipButton({ disabled, expanded, onClick, children }, ref) {
|
|
477
|
-
return <button ref={ref} type="button" className="ui-btn" disabled={disabled} aria-expanded={expanded} onClick={onClick}>{children}</button>;
|
|
479
|
+
}>(function ChipButton({ disabled, expanded, label, onClick, children }, ref) {
|
|
480
|
+
return <button ref={ref} type="button" className="ui-btn" disabled={disabled} aria-expanded={expanded} aria-label={label} onClick={onClick}>{children}</button>;
|
|
478
481
|
});
|
|
479
482
|
|
|
480
483
|
export interface ImageControlProps {
|