imio.omnia.tinymce 1.0__py3-none-any.whl
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.
- imio/omnia/tinymce/__init__.py +6 -0
- imio/omnia/tinymce/browser/__init__.py +0 -0
- imio/omnia/tinymce/browser/action.py +6 -0
- imio/omnia/tinymce/browser/configure.zcml +40 -0
- imio/omnia/tinymce/browser/controlpanel.py +93 -0
- imio/omnia/tinymce/browser/npm/package-lock.json +125 -0
- imio/omnia/tinymce/browser/npm/package.json +8 -0
- imio/omnia/tinymce/browser/overrides/.gitkeep +0 -0
- imio/omnia/tinymce/browser/resources/.env.example +13 -0
- imio/omnia/tinymce/browser/resources/.git +1 -0
- imio/omnia/tinymce/browser/resources/.gitignore +26 -0
- imio/omnia/tinymce/browser/resources/.gitlab-ci.yml +77 -0
- imio/omnia/tinymce/browser/resources/.storybook/main.js +124 -0
- imio/omnia/tinymce/browser/resources/.storybook/preview.js +8 -0
- imio/omnia/tinymce/browser/resources/CHANGELOG.md +19 -0
- imio/omnia/tinymce/browser/resources/CLAUDE.md +62 -0
- imio/omnia/tinymce/browser/resources/Makefile +28 -0
- imio/omnia/tinymce/browser/resources/README.md +327 -0
- imio/omnia/tinymce/browser/resources/dev/index.html +41 -0
- imio/omnia/tinymce/browser/resources/dev/vite.config.js +78 -0
- imio/omnia/tinymce/browser/resources/docs/images/example1.png +0 -0
- imio/omnia/tinymce/browser/resources/eslint.config.js +36 -0
- imio/omnia/tinymce/browser/resources/package-lock.json +4913 -0
- imio/omnia/tinymce/browser/resources/package.json +61 -0
- imio/omnia/tinymce/browser/resources/src/assets/ia-icon.svg +5 -0
- imio/omnia/tinymce/browser/resources/src/assets/omnia-icon.svg +10 -0
- imio/omnia/tinymce/browser/resources/src/client.js +239 -0
- imio/omnia/tinymce/browser/resources/src/config.js +220 -0
- imio/omnia/tinymce/browser/resources/src/plugin.js +158 -0
- imio/omnia/tinymce/browser/resources/src/shortcuts.js +92 -0
- imio/omnia/tinymce/browser/resources/src/ui/App.jsx +75 -0
- imio/omnia/tinymce/browser/resources/src/ui/FloatingPanel.jsx +375 -0
- imio/omnia/tinymce/browser/resources/src/ui/PanelHeader.jsx +15 -0
- imio/omnia/tinymce/browser/resources/src/ui/SidePanel.jsx +284 -0
- imio/omnia/tinymce/browser/resources/src/ui/StreamingText.jsx +143 -0
- imio/omnia/tinymce/browser/resources/src/ui/components.jsx +70 -0
- imio/omnia/tinymce/browser/resources/src/ui/mount.jsx +35 -0
- imio/omnia/tinymce/browser/resources/src/ui/omnia.css +35 -0
- imio/omnia/tinymce/browser/resources/src/utils.js +56 -0
- imio/omnia/tinymce/browser/resources/stories/FloatingPanel.stories.jsx +66 -0
- imio/omnia/tinymce/browser/resources/stories/SidePanel.stories.jsx +31 -0
- imio/omnia/tinymce/browser/resources/stories/StreamingText.stories.jsx +85 -0
- imio/omnia/tinymce/browser/resources/stories/TinyMCEEditor.stories.js +228 -0
- imio/omnia/tinymce/browser/resources/stories/TypingDots.stories.jsx +31 -0
- imio/omnia/tinymce/browser/resources/stories/mocks/editor.js +66 -0
- imio/omnia/tinymce/browser/resources/stories/mocks/omnia-client.js +99 -0
- imio/omnia/tinymce/browser/resources/stories/presets/accessibilite-reglement.html +49 -0
- imio/omnia/tinymce/browser/resources/stories/presets/ameliorer-communication.html +36 -0
- imio/omnia/tinymce/browser/resources/stories/presets/corriger-bulletin.html +186 -0
- imio/omnia/tinymce/browser/resources/stories/presets/long-cdld.html +12389 -0
- imio/omnia/tinymce/browser/resources/stories/presets/reduire-deliberation.html +87 -0
- imio/omnia/tinymce/browser/resources/stories/presets/traduire-guide.html +234 -0
- imio/omnia/tinymce/browser/resources/vite.config.js +27 -0
- imio/omnia/tinymce/browser/static/omnia-tinymce.css +1 -0
- imio/omnia/tinymce/browser/static/omnia-tinymce.js +22 -0
- imio/omnia/tinymce/browser/templates/omnia_config.pt +10 -0
- imio/omnia/tinymce/browser/viewlets.py +57 -0
- imio/omnia/tinymce/configure.zcml +42 -0
- imio/omnia/tinymce/interfaces.py +7 -0
- imio/omnia/tinymce/locales/README.rst +37 -0
- imio/omnia/tinymce/locales/__init__.py +0 -0
- imio/omnia/tinymce/locales/en/LC_MESSAGES/imio.omnia.tinymce.po +83 -0
- imio/omnia/tinymce/locales/fr/LC_MESSAGES/imio.omnia.tinymce.po +83 -0
- imio/omnia/tinymce/locales/imio.omnia.tinymce.pot +86 -0
- imio/omnia/tinymce/locales/update.py +74 -0
- imio/omnia/tinymce/locales/update.sh +12 -0
- imio/omnia/tinymce/permissions.zcml +10 -0
- imio/omnia/tinymce/profiles/default/actions.xml +13 -0
- imio/omnia/tinymce/profiles/default/browserlayer.xml +7 -0
- imio/omnia/tinymce/profiles/default/catalog.xml +4 -0
- imio/omnia/tinymce/profiles/default/metadata.xml +7 -0
- imio/omnia/tinymce/profiles/default/registry/main.xml +35 -0
- imio/omnia/tinymce/profiles/default/rolemap.xml +7 -0
- imio/omnia/tinymce/profiles/uninstall/browserlayer.xml +7 -0
- imio/omnia/tinymce/setuphandlers.py +45 -0
- imio/omnia/tinymce/testing.py +48 -0
- imio/omnia/tinymce/tests/__init__.py +0 -0
- imio/omnia/tinymce/tests/robot/test_example.robot +66 -0
- imio/omnia/tinymce/tests/test_robot.py +28 -0
- imio/omnia/tinymce/tests/test_setup.py +68 -0
- imio/omnia/tinymce/tests/test_viewlet.py +99 -0
- imio.omnia.tinymce-1.0-py3.12-nspkg.pth +2 -0
- imio_omnia_tinymce-1.0.dist-info/METADATA +294 -0
- imio_omnia_tinymce-1.0.dist-info/RECORD +90 -0
- imio_omnia_tinymce-1.0.dist-info/WHEEL +5 -0
- imio_omnia_tinymce-1.0.dist-info/entry_points.txt +5 -0
- imio_omnia_tinymce-1.0.dist-info/licenses/LICENSE.GPL +339 -0
- imio_omnia_tinymce-1.0.dist-info/licenses/LICENSE.rst +15 -0
- imio_omnia_tinymce-1.0.dist-info/namespace_packages.txt +2 -0
- imio_omnia_tinymce-1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import OmniaIcon from '../assets/omnia-icon.svg?react';
|
|
2
|
+
|
|
3
|
+
export function PanelHeader({ title }) {
|
|
4
|
+
return (
|
|
5
|
+
<div class="om:flex om:items-center om:gap-2">
|
|
6
|
+
<span class="om:w-8 om:h-8 om:flex-shrink-0">
|
|
7
|
+
<OmniaIcon className="om:h-8 om:w-8 om:pt-0.5" />
|
|
8
|
+
</span>
|
|
9
|
+
<div class="om:flex om:flex-col om:ml-2">
|
|
10
|
+
<span class="om:text-[14px] om:text-gray-700">Omnia – L'assistant IA d'iMio</span>
|
|
11
|
+
<span class="om:text-[14px] om:font-bold om:leading-none">{title}</span>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'preact/hooks';
|
|
2
|
+
import { motion, AnimatePresence } from 'motion/react';
|
|
3
|
+
import { StreamingText } from './StreamingText';
|
|
4
|
+
import { PanelHeader } from './PanelHeader';
|
|
5
|
+
import { Button, INPUT_CLASS, AIDisclaimer } from './components';
|
|
6
|
+
|
|
7
|
+
const TONE_OPTIONS = [
|
|
8
|
+
{ value: '', label: 'Aucun (par défaut)' },
|
|
9
|
+
{ value: 'formal', label: 'Formel' },
|
|
10
|
+
{ value: 'casual', label: 'Informel' },
|
|
11
|
+
{ value: 'bullet_points', label: 'Points clés' },
|
|
12
|
+
{ value: 'concise', label: 'Concis' },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Docked side panel for content generation.
|
|
17
|
+
*
|
|
18
|
+
* @param {{
|
|
19
|
+
* editor: object,
|
|
20
|
+
* client: object,
|
|
21
|
+
* visible: boolean,
|
|
22
|
+
* onClose: () => void,
|
|
23
|
+
* }} props
|
|
24
|
+
*/
|
|
25
|
+
export function SidePanel({ editor, client, config = {}, visible, onClose }) {
|
|
26
|
+
const [prompt, setPrompt] = useState('');
|
|
27
|
+
const [tone, setTone] = useState('');
|
|
28
|
+
const [status, setStatus] = useState('idle');
|
|
29
|
+
const [stream, setStream] = useState(null);
|
|
30
|
+
const [result, setResult] = useState('');
|
|
31
|
+
const [error, setError] = useState(null);
|
|
32
|
+
const [history, setHistory] = useState([]);
|
|
33
|
+
const [viewingIndex, setViewingIndex] = useState(null);
|
|
34
|
+
|
|
35
|
+
const abortRef = useRef(null);
|
|
36
|
+
const textareaRef = useRef(null);
|
|
37
|
+
const insertRef = useRef(null);
|
|
38
|
+
|
|
39
|
+
function handleGenerate() {
|
|
40
|
+
if (!prompt.trim()) return;
|
|
41
|
+
|
|
42
|
+
abortRef.current?.abort();
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
abortRef.current = controller;
|
|
45
|
+
|
|
46
|
+
setStatus('streaming');
|
|
47
|
+
setError(null);
|
|
48
|
+
setResult('');
|
|
49
|
+
setViewingIndex(null);
|
|
50
|
+
|
|
51
|
+
const options = { signal: controller.signal };
|
|
52
|
+
if (tone) options.tone = tone;
|
|
53
|
+
|
|
54
|
+
const iter = client.generate(prompt, options);
|
|
55
|
+
setStream(iter);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function handleStreamComplete(text) {
|
|
59
|
+
setResult(text);
|
|
60
|
+
setStatus('done');
|
|
61
|
+
setHistory((prev) => [{ prompt, result: text, tone }, ...prev].slice(0, config.historyLimit ?? 10));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleStreamError(err) {
|
|
65
|
+
if (err.name !== 'AbortError') {
|
|
66
|
+
setError(err.message);
|
|
67
|
+
setStatus('error');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function handleInsert() {
|
|
72
|
+
const text = viewingIndex != null ? history[viewingIndex].result : result;
|
|
73
|
+
if (text && editor) {
|
|
74
|
+
editor.insertContent(text);
|
|
75
|
+
editor.selection.collapse(false);
|
|
76
|
+
editor.focus();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function handleCopy() {
|
|
81
|
+
const text = viewingIndex != null ? history[viewingIndex].result : result;
|
|
82
|
+
if (text) {
|
|
83
|
+
navigator.clipboard.writeText(text).catch(() => {});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handleStop() {
|
|
88
|
+
abortRef.current?.abort();
|
|
89
|
+
setStatus('idle');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function viewHistoryItem(index) {
|
|
93
|
+
setViewingIndex(index);
|
|
94
|
+
setResult(history[index].result);
|
|
95
|
+
setStream(null);
|
|
96
|
+
setStatus('done');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const isViewing = viewingIndex != null;
|
|
100
|
+
const displayResult = isViewing ? history[viewingIndex]?.result : result;
|
|
101
|
+
|
|
102
|
+
// Keyboard: Escape to close, Enter to insert when done
|
|
103
|
+
const keyRef = useRef(null);
|
|
104
|
+
keyRef.current = (e) => {
|
|
105
|
+
if (e.key === 'Escape') {
|
|
106
|
+
onClose();
|
|
107
|
+
}
|
|
108
|
+
if (e.key === 'Enter' && status === 'done') {
|
|
109
|
+
const tag = e.target?.tagName;
|
|
110
|
+
if (tag !== 'TEXTAREA' && tag !== 'INPUT' && tag !== 'SELECT') {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
handleInsert();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!visible) return;
|
|
119
|
+
const onKey = (e) => keyRef.current?.(e);
|
|
120
|
+
document.addEventListener('keydown', onKey);
|
|
121
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
122
|
+
}, [visible]);
|
|
123
|
+
|
|
124
|
+
// Auto-focus textarea on open, focus insert button when done
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (visible) {
|
|
127
|
+
requestAnimationFrame(() => textareaRef.current?.focus());
|
|
128
|
+
}
|
|
129
|
+
}, [visible]);
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (status === 'done' && !isViewing) {
|
|
133
|
+
insertRef.current?.focus();
|
|
134
|
+
}
|
|
135
|
+
}, [status]);
|
|
136
|
+
|
|
137
|
+
if (config.enabledFeatures && !config.enabledFeatures.includes('generate')) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<AnimatePresence>
|
|
143
|
+
{visible && (
|
|
144
|
+
<motion.div
|
|
145
|
+
className="omnia-side-panel omnia-panel om:fixed om:top-0 om:right-0 om:w-[340px] om:max-w-full om:h-screen om:z-[10000] om:rounded-none om:border-l om:border-gray-200 om:flex om:flex-col om:font-sans om:text-sm om:leading-relaxed om:text-gray-800 om:bg-white om:shadow-lg om:box-border"
|
|
146
|
+
data-omnia
|
|
147
|
+
initial={{ x: '100%' }}
|
|
148
|
+
animate={{ x: 0 }}
|
|
149
|
+
exit={{ x: '100%' }}
|
|
150
|
+
transition={{ type: 'spring', damping: 25, stiffness: 300 }}
|
|
151
|
+
>
|
|
152
|
+
<div class="omnia-panel__header om:flex om:items-center om:justify-between om:px-3 om:py-2.5 om:border-b om:border-gray-100">
|
|
153
|
+
<PanelHeader title="Générer du texte" />
|
|
154
|
+
<Button variant="icon" onClick={onClose} aria-label="Close">✕</Button>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<div class="omnia-panel__body omnia-side-panel__body om:p-3 om:flex-1 om:overflow-y-auto om:flex om:flex-col om:gap-3">
|
|
158
|
+
{/* Prompt area */}
|
|
159
|
+
<div class="omnia-side-panel__prompt-area om:flex om:flex-col om:gap-2">
|
|
160
|
+
<textarea
|
|
161
|
+
ref={textareaRef}
|
|
162
|
+
class={`omnia-textarea ${INPUT_CLASS} om:resize-y om:min-h-[60px]`}
|
|
163
|
+
placeholder="Décrivez le contenu à générer…"
|
|
164
|
+
value={prompt}
|
|
165
|
+
onInput={(e) => setPrompt(e.target.value)}
|
|
166
|
+
disabled={status === 'streaming'}
|
|
167
|
+
rows={3}
|
|
168
|
+
onKeyDown={(e) => {
|
|
169
|
+
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) handleGenerate();
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
|
|
173
|
+
<div class="omnia-side-panel__options om:flex om:gap-1.5">
|
|
174
|
+
<select
|
|
175
|
+
class={`omnia-select om:flex-1 ${INPUT_CLASS}`}
|
|
176
|
+
value={tone}
|
|
177
|
+
onChange={(e) => setTone(e.target.value)}
|
|
178
|
+
disabled={status === 'streaming'}
|
|
179
|
+
>
|
|
180
|
+
{TONE_OPTIONS.map((t) => (
|
|
181
|
+
<option key={t.value} value={t.value}>
|
|
182
|
+
{t.label}
|
|
183
|
+
</option>
|
|
184
|
+
))}
|
|
185
|
+
</select>
|
|
186
|
+
|
|
187
|
+
{status === 'streaming' ? (
|
|
188
|
+
<Button onClick={handleStop}>Stop</Button>
|
|
189
|
+
) : (
|
|
190
|
+
<Button variant="primary" onClick={handleGenerate} disabled={!prompt.trim()}>
|
|
191
|
+
Générer
|
|
192
|
+
</Button>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
{/* Stream / result area */}
|
|
198
|
+
{status !== 'idle' && !isViewing && (
|
|
199
|
+
<div class="omnia-side-panel__result om:border om:border-gray-100 om:rounded-md om:overflow-hidden">
|
|
200
|
+
<StreamingText
|
|
201
|
+
stream={stream}
|
|
202
|
+
status={status}
|
|
203
|
+
error={error}
|
|
204
|
+
onComplete={handleStreamComplete}
|
|
205
|
+
onError={handleStreamError}
|
|
206
|
+
onRetry={handleGenerate}
|
|
207
|
+
/>
|
|
208
|
+
<AnimatePresence>
|
|
209
|
+
{status === 'done' && (
|
|
210
|
+
<motion.div
|
|
211
|
+
className="omnia-side-panel__result-actions om:flex om:gap-1.5 om:p-2 om:border-t om:border-gray-100"
|
|
212
|
+
initial={{ opacity: 0, y: 8 }}
|
|
213
|
+
animate={{ opacity: 1, y: 0 }}
|
|
214
|
+
exit={{ opacity: 0, y: 8 }}
|
|
215
|
+
transition={{ duration: 0.15 }}
|
|
216
|
+
>
|
|
217
|
+
<Button ref={insertRef} variant="primary" size="sm" onClick={handleInsert}>
|
|
218
|
+
Insérer
|
|
219
|
+
</Button>
|
|
220
|
+
<Button variant="secondary" size="sm" onClick={handleCopy}>
|
|
221
|
+
Copier
|
|
222
|
+
</Button>
|
|
223
|
+
</motion.div>
|
|
224
|
+
)}
|
|
225
|
+
</AnimatePresence>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
|
|
229
|
+
{/* Viewing a history item */}
|
|
230
|
+
{isViewing && (
|
|
231
|
+
<div class="omnia-side-panel__result om:border om:border-gray-100 om:rounded-md om:overflow-hidden">
|
|
232
|
+
<div class="omnia-stream-preview om:font-sans om:text-sm om:leading-relaxed om:text-gray-800 om:max-h-[300px] om:overflow-y-auto om:p-2 om:break-words">
|
|
233
|
+
<div class="omnia-stream-preview__text" dangerouslySetInnerHTML={{ __html: displayResult }} />
|
|
234
|
+
</div>
|
|
235
|
+
<div class="omnia-side-panel__result-actions om:flex om:gap-1.5 om:p-2 om:border-t om:border-gray-100">
|
|
236
|
+
<Button variant="primary" size="sm" onClick={handleInsert}>
|
|
237
|
+
Insérer
|
|
238
|
+
</Button>
|
|
239
|
+
<Button variant="secondary" size="sm" onClick={handleCopy}>
|
|
240
|
+
Copier
|
|
241
|
+
</Button>
|
|
242
|
+
<Button variant="secondary" size="sm" onClick={() => setViewingIndex(null)}>
|
|
243
|
+
Retour
|
|
244
|
+
</Button>
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
)}
|
|
248
|
+
|
|
249
|
+
{/* History */}
|
|
250
|
+
{history.length > 0 && (
|
|
251
|
+
<div class="omnia-side-panel__history om:mt-auto om:border-t om:border-gray-100 om:pt-2">
|
|
252
|
+
<div class="omnia-side-panel__history-title om:text-[11px] om:font-semibold om:uppercase om:tracking-wide om:text-gray-400 om:mb-1.5">
|
|
253
|
+
Historique
|
|
254
|
+
</div>
|
|
255
|
+
{history.map((item, i) => (
|
|
256
|
+
<button
|
|
257
|
+
key={i}
|
|
258
|
+
class={`omnia-side-panel__history-item om:block om:w-full om:text-left om:px-2 om:py-1.5 om:border om:rounded om:bg-transparent om:cursor-pointer om:font-[inherit] om:text-xs om:leading-snug om:text-gray-600 om:mb-0.5 om:hover:bg-[#E6007E]/5 om:hover:border-[#E6007E]/20 ${
|
|
259
|
+
viewingIndex === i
|
|
260
|
+
? 'omnia-side-panel__history-item--active om:bg-[#E6007E]/5 om:border-[#E6007E]/30'
|
|
261
|
+
: 'om:border-transparent'
|
|
262
|
+
}`}
|
|
263
|
+
onClick={() => viewHistoryItem(i)}
|
|
264
|
+
>
|
|
265
|
+
<div class="omnia-side-panel__history-prompt om:font-medium om:text-gray-800 om:whitespace-nowrap om:overflow-hidden om:text-ellipsis">
|
|
266
|
+
{item.prompt}
|
|
267
|
+
</div>
|
|
268
|
+
<div class="omnia-side-panel__history-preview om:text-gray-400 om:whitespace-nowrap om:overflow-hidden om:text-ellipsis">
|
|
269
|
+
{(() => { const t = item.result.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim(); return t.length > 80 ? t.slice(0, 80) + '…' : t; })()}
|
|
270
|
+
</div>
|
|
271
|
+
</button>
|
|
272
|
+
))}
|
|
273
|
+
</div>
|
|
274
|
+
)}
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
<div class="omnia-panel__footer om:shrink-0">
|
|
278
|
+
<AIDisclaimer />
|
|
279
|
+
</div>
|
|
280
|
+
</motion.div>
|
|
281
|
+
)}
|
|
282
|
+
</AnimatePresence>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'preact/hooks';
|
|
2
|
+
import { motion } from 'motion/react';
|
|
3
|
+
import { Button } from './components';
|
|
4
|
+
|
|
5
|
+
/** Invisible inline marker injected at the end of the HTML to track cursor position.
|
|
6
|
+
* It inherits the surrounding font-size/line-height so its rect matches the text line. */
|
|
7
|
+
const MARKER_HTML = '<span data-omnia-cursor-marker style="display:inline;width:0;overflow:hidden;"></span>';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Displays streaming AI output chunk by chunk with a fade-in effect.
|
|
11
|
+
*
|
|
12
|
+
* @param {{ stream: AsyncIterable|null, status: string, error: string|null, onComplete: (text: string) => void, onError: (err: Error) => void, onRetry: () => void }} props
|
|
13
|
+
* status: 'idle' | 'streaming' | 'done' | 'error'
|
|
14
|
+
*/
|
|
15
|
+
export function StreamingText({ stream, status, error, onComplete, onError, onRetry }) {
|
|
16
|
+
const [settled, setSettled] = useState('');
|
|
17
|
+
const [fresh, setFresh] = useState('');
|
|
18
|
+
const containerRef = useRef(null);
|
|
19
|
+
const textRef = useRef(null);
|
|
20
|
+
const timerRef = useRef(null);
|
|
21
|
+
const [cursorPos, setCursorPos] = useState(null);
|
|
22
|
+
|
|
23
|
+
// Consume the stream when it changes
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!stream) return;
|
|
26
|
+
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
setSettled('');
|
|
29
|
+
setFresh('');
|
|
30
|
+
setCursorPos(null);
|
|
31
|
+
|
|
32
|
+
(async () => {
|
|
33
|
+
let full = '';
|
|
34
|
+
try {
|
|
35
|
+
for await (const chunk of stream) {
|
|
36
|
+
if (cancelled) break;
|
|
37
|
+
|
|
38
|
+
// Promote previous fresh chunk to settled, set new fresh
|
|
39
|
+
setSettled(full);
|
|
40
|
+
setFresh(chunk);
|
|
41
|
+
full += chunk;
|
|
42
|
+
|
|
43
|
+
// After animation ends, fold fresh into settled
|
|
44
|
+
clearTimeout(timerRef.current);
|
|
45
|
+
timerRef.current = setTimeout(() => {
|
|
46
|
+
if (!cancelled) {
|
|
47
|
+
setSettled(full);
|
|
48
|
+
setFresh('');
|
|
49
|
+
}
|
|
50
|
+
}, 320);
|
|
51
|
+
}
|
|
52
|
+
if (!cancelled) {
|
|
53
|
+
setSettled(full);
|
|
54
|
+
setFresh('');
|
|
55
|
+
onComplete?.(full);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (!cancelled) {
|
|
59
|
+
setSettled(full);
|
|
60
|
+
setFresh('');
|
|
61
|
+
onError?.(err);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
|
|
66
|
+
return () => {
|
|
67
|
+
cancelled = true;
|
|
68
|
+
clearTimeout(timerRef.current);
|
|
69
|
+
};
|
|
70
|
+
}, [stream]);
|
|
71
|
+
|
|
72
|
+
const text = settled + fresh;
|
|
73
|
+
|
|
74
|
+
// Auto-scroll to bottom while streaming + measure cursor position
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const container = containerRef.current;
|
|
77
|
+
const textEl = textRef.current;
|
|
78
|
+
if (!container || !textEl) return;
|
|
79
|
+
|
|
80
|
+
if (status === 'streaming') {
|
|
81
|
+
container.scrollTop = container.scrollHeight;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Measure marker position in content coordinates (accounting for scroll)
|
|
85
|
+
if (status === 'streaming') {
|
|
86
|
+
const marker = textEl.querySelector('[data-omnia-cursor-marker]');
|
|
87
|
+
if (marker) {
|
|
88
|
+
const containerRect = container.getBoundingClientRect();
|
|
89
|
+
const markerRect = marker.getBoundingClientRect();
|
|
90
|
+
setCursorPos({
|
|
91
|
+
x: markerRect.left - containerRect.left + container.scrollLeft,
|
|
92
|
+
y: markerRect.top - containerRect.top + container.scrollTop,
|
|
93
|
+
h: markerRect.height,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, [text, status]);
|
|
98
|
+
|
|
99
|
+
if (status === 'idle') {
|
|
100
|
+
return <div class="omnia-stream-preview omnia-stream-preview--idle" />;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const markerSuffix = status === 'streaming' ? MARKER_HTML : '';
|
|
104
|
+
const html = fresh
|
|
105
|
+
? settled + '<span class="omnia-stream-preview__new">' + fresh + '</span>' + markerSuffix
|
|
106
|
+
: settled + markerSuffix;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div
|
|
110
|
+
class="omnia-stream-preview om:relative om:font-sans om:text-sm om:leading-relaxed om:text-gray-800 om:max-h-[300px] om:overflow-y-auto om:p-2 om:break-words"
|
|
111
|
+
ref={containerRef}
|
|
112
|
+
>
|
|
113
|
+
{(text || status === 'streaming') && (
|
|
114
|
+
<div
|
|
115
|
+
ref={textRef}
|
|
116
|
+
class="omnia-stream-preview__text"
|
|
117
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
{status === 'streaming' && cursorPos && (
|
|
122
|
+
<motion.span
|
|
123
|
+
class="omnia-stream-preview__cursor om:inline-block om:w-[3px] om:bg-[#E6007E] om:animate-[omnia-blink_0.8s_step-end_infinite]"
|
|
124
|
+
aria-label="Chargement…"
|
|
125
|
+
style={{ position: 'absolute', top: 0, left: 0, height: cursorPos.h }}
|
|
126
|
+
animate={{ x: cursorPos.x, y: cursorPos.y }}
|
|
127
|
+
transition={{ type: 'tween', duration: 0.08, ease: 'easeOut' }}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
|
|
131
|
+
{status === 'error' && (
|
|
132
|
+
<div class="omnia-stream-preview__error om:flex om:items-center om:gap-2 om:text-red-600 om:text-[13px] om:mt-2">
|
|
133
|
+
<span>{error || 'An error occurred'}</span>
|
|
134
|
+
{onRetry && (
|
|
135
|
+
<Button variant="secondary" size="sm" onClick={onRetry}>
|
|
136
|
+
Réessayer
|
|
137
|
+
</Button>
|
|
138
|
+
)}
|
|
139
|
+
</div>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { forwardRef } from 'preact/compat';
|
|
2
|
+
|
|
3
|
+
/** HTML string for the blinking cursor — used to inject inline within innerHTML content. */
|
|
4
|
+
export const CURSOR_HTML =
|
|
5
|
+
'<span class="omnia-stream-preview__cursor om:inline-block om:w-[3px] om:h-[1.3em] om:bg-[#E6007E] om:ml-[5px] om:mb-[1px] om:align-text-bottom om:animate-[omnia-blink_0.8s_step-end_infinite]" aria-label="Chargement…"></span>';
|
|
6
|
+
|
|
7
|
+
/** Blinking cursor shown during streaming / loading. */
|
|
8
|
+
export function Cursor() {
|
|
9
|
+
return (
|
|
10
|
+
<span
|
|
11
|
+
class="omnia-stream-preview__cursor om:inline-block om:w-[3px] om:h-[1.3em] om:bg-[#E6007E] om:ml-[5px] om:mb-[1px] om:align-text-bottom om:animate-[omnia-blink_0.8s_step-end_infinite]"
|
|
12
|
+
aria-label="Chargement…"
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Three-dot typing animation shown while waiting for a non-streaming API response. */
|
|
18
|
+
export function TypingDots() {
|
|
19
|
+
const dot = 'om:w-1.5 om:h-1.5 om:rounded-full om:bg-[#E6007E] om:opacity-30 om:animate-[omnia-typing_1.1s_ease-in-out_infinite]';
|
|
20
|
+
return (
|
|
21
|
+
<span class="omnia-typing om:inline-flex om:gap-1.5" aria-label="Chargement…">
|
|
22
|
+
<span class={dot} />
|
|
23
|
+
<span class={`${dot} om:[animation-delay:0.15s]`} />
|
|
24
|
+
<span class={`${dot} om:[animation-delay:0.3s]`} />
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Disclaimer shown below AI-generated content. */
|
|
30
|
+
export function AIDisclaimer() {
|
|
31
|
+
return (
|
|
32
|
+
<p class="omnia-ai-disclaimer om:border-t-1 om:border-gray-100 om:bg-gray-100 om:text-[10px] om:leading-snug om:text-gray-600 om:text-center om:px-3 om:py-1 om:mb-0 om:mt-3">
|
|
33
|
+
L'intelligence artificielle peut commettre des erreurs, vérifiez les informations importantes.
|
|
34
|
+
</p>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Shared class string for text inputs, textareas and selects. */
|
|
39
|
+
export const INPUT_CLASS =
|
|
40
|
+
'om:block om:w-full om:px-2.5 om:py-1.5 om:border om:border-gray-300 om:rounded om:text-[13px] om:leading-normal om:text-gray-800 om:bg-white om:font-[inherit] om:focus:outline-none om:focus:border-[#E6007E] om:focus:ring-2 om:focus:ring-[#E6007E]/15';
|
|
41
|
+
|
|
42
|
+
const BTN_BASE =
|
|
43
|
+
'omnia-btn om:inline-flex om:items-center om:justify-center om:cursor-pointer om:transition-colors om:focus:outline-none om:disabled:opacity-50 om:disabled:cursor-not-allowed';
|
|
44
|
+
|
|
45
|
+
const BTN_VARIANTS = {
|
|
46
|
+
primary: {
|
|
47
|
+
md: 'omnia-btn--primary om:gap-1 om:px-3.5 om:py-1.5 om:border om:border-[#E6007E] om:rounded om:bg-[#E6007E] om:text-white om:text-[13px] om:leading-snug om:whitespace-nowrap om:hover:bg-[#CF0071] om:hover:border-[#CF0071] om:focus-visible:ring-2 om:focus-visible:ring-[#E6007E] om:focus-visible:ring-offset-2',
|
|
48
|
+
sm: 'omnia-btn--primary omnia-btn--small om:gap-1 om:px-2 om:py-0.5 om:border om:border-[#E6007E] om:rounded om:bg-[#E6007E] om:text-white om:text-xs om:leading-snug om:whitespace-nowrap om:hover:bg-[#CF0071] om:hover:border-[#CF0071] om:focus-visible:ring-2 om:focus-visible:ring-[#E6007E] om:focus-visible:ring-offset-2',
|
|
49
|
+
},
|
|
50
|
+
secondary: {
|
|
51
|
+
md: 'om:gap-1 om:px-3.5 om:py-1.5 om:border om:border-gray-300 om:rounded om:bg-white om:text-gray-700 om:text-[13px] om:leading-snug om:whitespace-nowrap om:hover:bg-gray-50 om:hover:border-gray-400 om:focus-visible:ring-2 om:focus-visible:ring-gray-400 om:focus-visible:ring-offset-2',
|
|
52
|
+
sm: 'omnia-btn--small om:gap-1 om:px-2 om:py-0.5 om:border om:border-gray-300 om:rounded om:bg-white om:text-gray-700 om:text-xs om:leading-snug om:whitespace-nowrap om:hover:bg-gray-50 om:hover:border-gray-400 om:focus-visible:ring-2 om:focus-visible:ring-gray-400 om:focus-visible:ring-offset-2',
|
|
53
|
+
},
|
|
54
|
+
icon: 'omnia-btn--icon om:p-1 om:border-none om:bg-transparent om:text-gray-500 om:hover:text-gray-800 om:hover:bg-black/5',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {{ variant?: 'primary'|'secondary'|'icon', size?: 'md'|'sm' }} props
|
|
59
|
+
*/
|
|
60
|
+
export const Button = forwardRef(function Button(
|
|
61
|
+
{ variant = 'secondary', size = 'md', class: className, children, ...props },
|
|
62
|
+
ref,
|
|
63
|
+
) {
|
|
64
|
+
const v = variant === 'icon' ? BTN_VARIANTS.icon : BTN_VARIANTS[variant]?.[size] ?? BTN_VARIANTS.secondary.md;
|
|
65
|
+
return (
|
|
66
|
+
<button ref={ref} class={`${BTN_BASE} ${v}${className ? ` ${className}` : ''}`} {...props}>
|
|
67
|
+
{children}
|
|
68
|
+
</button>
|
|
69
|
+
);
|
|
70
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { render, createRef } from 'preact';
|
|
2
|
+
import { App } from './App';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mount the Omnia UI next to a TinyMCE editor.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} editor - TinyMCE editor instance
|
|
8
|
+
* @param {import('../client').OmniaClient} client - OmniaClient instance
|
|
9
|
+
* @param {object} config - Normalized Omnia config
|
|
10
|
+
* @returns {{ appRef: { current: object }, destroy: () => void }}
|
|
11
|
+
*/
|
|
12
|
+
export function mountOmniaUI(editor, client, config) {
|
|
13
|
+
const editorId = editor.id || 'default';
|
|
14
|
+
const rootId = `omnia-root-${editorId}`;
|
|
15
|
+
|
|
16
|
+
// Prevent double-mount
|
|
17
|
+
let root = document.getElementById(rootId);
|
|
18
|
+
if (!root) {
|
|
19
|
+
root = document.createElement('div');
|
|
20
|
+
root.id = rootId;
|
|
21
|
+
document.body.appendChild(root);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const appRef = createRef();
|
|
25
|
+
|
|
26
|
+
render(<App ref={appRef} editor={editor} client={client} config={config} />, root);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
appRef,
|
|
30
|
+
destroy() {
|
|
31
|
+
render(null, root);
|
|
32
|
+
root.remove();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@import "tailwindcss/theme" prefix(om);
|
|
2
|
+
@import "tailwindcss/utilities" prefix(om);
|
|
3
|
+
|
|
4
|
+
/* Scoped box-sizing reset (no preflight — we're a plugin, must not affect host page) */
|
|
5
|
+
[data-omnia] *,
|
|
6
|
+
[data-omnia] *::before,
|
|
7
|
+
[data-omnia] *::after {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* Blinking cursor — not expressible as a Tailwind utility */
|
|
12
|
+
@keyframes omnia-blink {
|
|
13
|
+
50% { opacity: 0; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Typing dots loader */
|
|
17
|
+
@keyframes omnia-typing {
|
|
18
|
+
0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
|
|
19
|
+
40% { opacity: 1; transform: translateY(-4px); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Fade-in for newly streamed content */
|
|
23
|
+
@keyframes omnia-chunk-in {
|
|
24
|
+
from { opacity: 0; }
|
|
25
|
+
to { opacity: 1; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.omnia-stream-preview__new {
|
|
29
|
+
animation: omnia-chunk-in 0.3s ease-out both;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
.tox-editor-container .tox-promotion {
|
|
34
|
+
display: none !important;
|
|
35
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse an SSE stream from a fetch Response into an async iterable of text chunks.
|
|
3
|
+
*
|
|
4
|
+
* @param {Response} response - Fetch response with an SSE body
|
|
5
|
+
* @param {AbortSignal} [signal] - Optional abort signal
|
|
6
|
+
* @returns {AsyncGenerator<string>}
|
|
7
|
+
*/
|
|
8
|
+
export async function* parseSSE(response, signal) {
|
|
9
|
+
const reader = response.body.getReader();
|
|
10
|
+
const decoder = new TextDecoder();
|
|
11
|
+
let buffer = '';
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
while (true) {
|
|
15
|
+
if (signal?.aborted) break;
|
|
16
|
+
|
|
17
|
+
const { done, value } = await reader.read();
|
|
18
|
+
if (done) break;
|
|
19
|
+
|
|
20
|
+
buffer += decoder.decode(value, { stream: true });
|
|
21
|
+
|
|
22
|
+
// SSE frames are separated by double newlines
|
|
23
|
+
const frames = buffer.split('\n\n');
|
|
24
|
+
// Keep the last (possibly incomplete) frame in the buffer
|
|
25
|
+
buffer = frames.pop() || '';
|
|
26
|
+
|
|
27
|
+
for (const frame of frames) {
|
|
28
|
+
for (const line of frame.split('\n')) {
|
|
29
|
+
if (line.startsWith('data: ')) {
|
|
30
|
+
const data = line.slice(6);
|
|
31
|
+
if (data === '[DONE]') return;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(data);
|
|
35
|
+
if (parsed.chunk != null) {
|
|
36
|
+
yield parsed.chunk;
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
// If not JSON, yield the raw data as a text chunk
|
|
40
|
+
if (data.trim()) yield data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} finally {
|
|
47
|
+
reader.releaseLock();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generate a unique ID string.
|
|
53
|
+
*/
|
|
54
|
+
export function uid() {
|
|
55
|
+
return Math.random().toString(36).slice(2, 10);
|
|
56
|
+
}
|