@ephia/dova-sdk 1.0.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/README.md +89 -0
- package/dist/EphiaBinding-BvRmlqqC.d.ts +36 -0
- package/dist/EphiaFloatingButton-CxiF86VW.d.ts +65 -0
- package/dist/EphiaTextarea-B4_CAVUg.d.ts +183 -0
- package/dist/NativeBinding-ChG0GeSz.d.ts +53 -0
- package/dist/TargetBinding-BKGQwUMc.d.ts +89 -0
- package/dist/TiptapBinding-B-agfV2H.d.ts +45 -0
- package/dist/Transport-zdeA4Pou.d.ts +63 -0
- package/dist/audio-state-kZ3KSvux.d.ts +39 -0
- package/dist/chunk-35AJK2IO.js +1 -0
- package/dist/chunk-35AJK2IO.js.map +1 -0
- package/dist/chunk-3LXZODL4.js +886 -0
- package/dist/chunk-3LXZODL4.js.map +1 -0
- package/dist/chunk-5IK5TLSK.js +67 -0
- package/dist/chunk-5IK5TLSK.js.map +1 -0
- package/dist/chunk-7E43RY75.js +9 -0
- package/dist/chunk-7E43RY75.js.map +1 -0
- package/dist/chunk-A5UEXJ5R.js +183 -0
- package/dist/chunk-A5UEXJ5R.js.map +1 -0
- package/dist/chunk-AEE554FT.js +51 -0
- package/dist/chunk-AEE554FT.js.map +1 -0
- package/dist/chunk-DIEWY3IT.js +1332 -0
- package/dist/chunk-DIEWY3IT.js.map +1 -0
- package/dist/chunk-EGIAN7FH.js +18 -0
- package/dist/chunk-EGIAN7FH.js.map +1 -0
- package/dist/chunk-EMOEAPVU.js +486 -0
- package/dist/chunk-EMOEAPVU.js.map +1 -0
- package/dist/chunk-IDC7FHIZ.js +40 -0
- package/dist/chunk-IDC7FHIZ.js.map +1 -0
- package/dist/chunk-ITJFN3VM.js +601 -0
- package/dist/chunk-ITJFN3VM.js.map +1 -0
- package/dist/chunk-K24GNU27.js +22 -0
- package/dist/chunk-K24GNU27.js.map +1 -0
- package/dist/chunk-LXMCRXXF.js +778 -0
- package/dist/chunk-LXMCRXXF.js.map +1 -0
- package/dist/chunk-MJCEOOLW.js +122 -0
- package/dist/chunk-MJCEOOLW.js.map +1 -0
- package/dist/chunk-N7U5M3VZ.js +33 -0
- package/dist/chunk-N7U5M3VZ.js.map +1 -0
- package/dist/chunk-PSYX674B.js +27 -0
- package/dist/chunk-PSYX674B.js.map +1 -0
- package/dist/chunk-RFQRV7ML.js +33 -0
- package/dist/chunk-RFQRV7ML.js.map +1 -0
- package/dist/chunk-THNHRV2B.js +18 -0
- package/dist/chunk-THNHRV2B.js.map +1 -0
- package/dist/chunk-VSLGR64U.js +62 -0
- package/dist/chunk-VSLGR64U.js.map +1 -0
- package/dist/chunk-W2ZP674X.js +346 -0
- package/dist/chunk-W2ZP674X.js.map +1 -0
- package/dist/chunk-YWZUMUYE.js +695 -0
- package/dist/chunk-YWZUMUYE.js.map +1 -0
- package/dist/client-options-Uo6jXO8k.d.ts +64 -0
- package/dist/connection-state-Bk33YprE.d.ts +32 -0
- package/dist/core/bindings/index.d.ts +24 -0
- package/dist/core/bindings/index.js +1025 -0
- package/dist/core/bindings/index.js.map +1 -0
- package/dist/core/index.d.ts +383 -0
- package/dist/core/index.js +1284 -0
- package/dist/core/index.js.map +1 -0
- package/dist/createEphiaClient-BhdZ183V.d.ts +69 -0
- package/dist/devices/speechmike/index.d.ts +148 -0
- package/dist/devices/speechmike/index.js +40 -0
- package/dist/devices/speechmike/index.js.map +1 -0
- package/dist/headless/index.d.ts +10 -0
- package/dist/headless/index.js +25 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +38 -0
- package/dist/react/index.js +70 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rich-editor/index.d.ts +46 -0
- package/dist/rich-editor/index.js +13 -0
- package/dist/rich-editor/index.js.map +1 -0
- package/dist/schema-B2ycPlNB.d.ts +87 -0
- package/dist/session-APaXR48R.d.ts +12 -0
- package/dist/shared/index.d.ts +16 -0
- package/dist/shared/index.js +30 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/style.css +1093 -0
- package/dist/testing/index.d.ts +84 -0
- package/dist/testing/index.js +36 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-D5SXPSwR.d.ts +32 -0
- package/dist/ui/index.d.ts +30 -0
- package/dist/ui/index.js +34 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/useEphiaSpeechMike-CjD7DWnh.d.ts +64 -0
- package/package.json +110 -0
- package/src/core/audio/audio-worklet-source.ts +30 -0
- package/src/core/audio/index.ts +3 -0
- package/src/core/audio/voice-level-meter.test.ts +27 -0
- package/src/core/audio/voice-level-meter.ts +270 -0
- package/src/core/bindings/EphiaBinding.ts +41 -0
- package/src/core/bindings/SegmentBindingBridge.test.ts +422 -0
- package/src/core/bindings/SegmentBindingBridge.ts +377 -0
- package/src/core/bindings/TargetBinding.ts +142 -0
- package/src/core/bindings/adapters/NativeAdapter.test.ts +85 -0
- package/src/core/bindings/adapters/NativeAdapter.ts +216 -0
- package/src/core/bindings/adapters/ProseMirrorAdapter.ts +231 -0
- package/src/core/bindings/adapters/index.ts +2 -0
- package/src/core/bindings/binding-factory.ts +78 -0
- package/src/core/bindings/detect-editor-type.ts +87 -0
- package/src/core/bindings/index.ts +13 -0
- package/src/core/bindings/insertion-boundary.test.ts +38 -0
- package/src/core/bindings/insertion-boundary.ts +26 -0
- package/src/core/bindings/native/NativeBinding.test.ts +277 -0
- package/src/core/bindings/native/NativeBinding.ts +239 -0
- package/src/core/bindings/resolver.ts +18 -0
- package/src/core/bindings/targets/codemirror.binding.ts +293 -0
- package/src/core/bindings/targets/contenteditable.binding.ts +452 -0
- package/src/core/bindings/targets/index.ts +10 -0
- package/src/core/bindings/targets/monaco.binding.ts +315 -0
- package/src/core/bindings/targets/tiptap.binding.test.ts +417 -0
- package/src/core/bindings/targets/tiptap.binding.ts +1192 -0
- package/src/core/bindings/tiptap/TiptapBinding.test.ts +63 -0
- package/src/core/bindings/tiptap/TiptapBinding.ts +464 -0
- package/src/core/bindings/types.ts +41 -0
- package/src/core/client/EphiaAudioClient.ts +654 -0
- package/src/core/client/audio-capture.ts +263 -0
- package/src/core/client/client-options.ts +39 -0
- package/src/core/client/client-state.ts +18 -0
- package/src/core/client/constants.ts +23 -0
- package/src/core/client/session-api.ts +415 -0
- package/src/core/connection/connection-state.ts +78 -0
- package/src/core/connection/index.ts +6 -0
- package/src/core/index.ts +47 -0
- package/src/core/operations/textToDocumentOperations.test.ts +69 -0
- package/src/core/operations/textToDocumentOperations.ts +92 -0
- package/src/core/runtime/DictationRuntime.test.ts +578 -0
- package/src/core/runtime/DictationRuntime.ts +434 -0
- package/src/core/runtime/TranscriptApplier.test.ts +355 -0
- package/src/core/runtime/TranscriptApplier.ts +229 -0
- package/src/core/runtime/index.ts +18 -0
- package/src/core/session/index.ts +2 -0
- package/src/core/session/session-machine.test.ts +16 -0
- package/src/core/session/session-machine.ts +59 -0
- package/src/core/targets/EditorContextCollector.ts +71 -0
- package/src/core/targets/TargetManager.test.ts +194 -0
- package/src/core/targets/TargetManager.ts +194 -0
- package/src/core/targets/index.ts +10 -0
- package/src/core/text-processing/index.ts +11 -0
- package/src/core/text-processing/overlap.test.ts +35 -0
- package/src/core/text-processing/overlap.ts +101 -0
- package/src/core/text-processing/voice-formatting.normalizer.test.ts +132 -0
- package/src/core/text-processing/voice-formatting.normalizer.ts +284 -0
- package/src/core/transcript/client-transcript.reducer.ts +366 -0
- package/src/core/transcript/client-transcript.state.ts +25 -0
- package/src/core/transcript/index.ts +19 -0
- package/src/core/transcript/transcript.assembler.test.ts +205 -0
- package/src/core/transcript/transcript.assembler.ts +152 -0
- package/src/core/transcript/transcript.reducer.test.ts +199 -0
- package/src/core/transcript/transcript.reducer.ts +771 -0
- package/src/core/transcript/transcript.state.ts +123 -0
- package/src/core/transport/LiveKitTransport.publish.test.ts +226 -0
- package/src/core/transport/LiveKitTransport.ts +459 -0
- package/src/core/transport/MockTransport.ts +231 -0
- package/src/core/transport/Transport.ts +82 -0
- package/src/debug/sdk-debug-collector.ts +79 -0
- package/src/devices/index.ts +2 -0
- package/src/devices/speechmike/__tests__/EphiaSpeechMikeProvider.test.tsx +99 -0
- package/src/devices/speechmike/__tests__/speechmike-audio-resolver.test.ts +96 -0
- package/src/devices/speechmike/__tests__/speechmike-button-router.test.ts +66 -0
- package/src/devices/speechmike/__tests__/speechmike-device-manager.test.ts +201 -0
- package/src/devices/speechmike/__tests__/speechmike-led-controller.test.ts +68 -0
- package/src/devices/speechmike/browser.ts +80 -0
- package/src/devices/speechmike/constants.ts +74 -0
- package/src/devices/speechmike/dictation-support-loader.ts +81 -0
- package/src/devices/speechmike/index.ts +11 -0
- package/src/devices/speechmike/react/EphiaSpeechMikeContext.ts +34 -0
- package/src/devices/speechmike/react/EphiaSpeechMikeProvider.tsx +287 -0
- package/src/devices/speechmike/react/useEphiaSpeechMike.ts +26 -0
- package/src/devices/speechmike/speechmike-audio-resolver.ts +58 -0
- package/src/devices/speechmike/speechmike-button-router.ts +73 -0
- package/src/devices/speechmike/speechmike-device-manager.ts +461 -0
- package/src/devices/speechmike/speechmike-led-controller.ts +78 -0
- package/src/devices/speechmike/types.ts +96 -0
- package/src/dictation_support.d.ts +31 -0
- package/src/global.d.ts +10 -0
- package/src/headless/createEphiaClient.ts +220 -0
- package/src/headless/index.ts +18 -0
- package/src/index.ts +89 -0
- package/src/react/EphiaAuto.tsx +87 -0
- package/src/react/components/EphiaDictationButton.tsx +88 -0
- package/src/react/components/EphiaStatusBar.tsx +59 -0
- package/src/react/components/EphiaTextarea.tsx +295 -0
- package/src/react/ephia-react.css +318 -0
- package/src/react/hooks/targets/index.ts +3 -0
- package/src/react/hooks/targets/useEphiaCodemirror.ts +35 -0
- package/src/react/hooks/targets/useEphiaMonaco.ts +35 -0
- package/src/react/hooks/targets/useEphiaTiptap.ts +23 -0
- package/src/react/hooks/useEphia.lifecycle.test.tsx +389 -0
- package/src/react/hooks/useEphia.ts +367 -0
- package/src/react/hooks/useEphiaDiscardTarget.ts +53 -0
- package/src/react/hooks/useEphiaServerEvent.ts +33 -0
- package/src/react/hooks/useEphiaTarget.ts +47 -0
- package/src/react/hooks/useEphiaTranscript.ts +22 -0
- package/src/react/index.ts +58 -0
- package/src/react/provider/EphiaContext.ts +63 -0
- package/src/react/provider/EphiaInternalContext.ts +32 -0
- package/src/react/provider/EphiaProvider.tsx +373 -0
- package/src/react/registry/binding-factory.ts +7 -0
- package/src/react/registry/detect-editor-type.ts +2 -0
- package/src/react/registry/events.ts +37 -0
- package/src/react/registry/registries/CodeMirrorInstanceRegistry.ts +24 -0
- package/src/react/registry/registries/MonacoInstanceRegistry.ts +23 -0
- package/src/react/registry/registries/TargetRegistry.ts +327 -0
- package/src/react/registry/registries/TiptapInstanceRegistry.ts +43 -0
- package/src/react/registry/registries/index.ts +5 -0
- package/src/react/store/create-ephia-store.ts +36 -0
- package/src/react/store/types.ts +41 -0
- package/src/react/utils/flash-range.ts +24 -0
- package/src/react/utils/index.ts +1 -0
- package/src/rich-editor/adapters/tiptap.test.ts +86 -0
- package/src/rich-editor/adapters/tiptap.ts +23 -0
- package/src/rich-editor/index.ts +3 -0
- package/src/rich-editor/types.ts +24 -0
- package/src/rich-editor/use-ephia-rich-editor.test.tsx +202 -0
- package/src/rich-editor/use-ephia-rich-editor.ts +47 -0
- package/src/shared/config/endpoint.test.ts +45 -0
- package/src/shared/config/endpoint.ts +39 -0
- package/src/shared/config/schema.ts +32 -0
- package/src/shared/effective-text.ts +13 -0
- package/src/shared/errors/EphiaSdkError.ts +54 -0
- package/src/shared/errors/messages.ts +40 -0
- package/src/shared/index.ts +27 -0
- package/src/shared/state/audio-state.ts +45 -0
- package/src/shared/state/index.ts +2 -0
- package/src/shared/store/document-store.ts +32 -0
- package/src/shared/store/index.ts +2 -0
- package/src/shared/types/editors.ts +28 -0
- package/src/shared/types/session.ts +12 -0
- package/src/style.css +2 -0
- package/src/testing/index.tsx +60 -0
- package/src/ui/assets/ephia-logo.svg +4 -0
- package/src/ui/components/EphiaLogo.tsx +77 -0
- package/src/ui/index.ts +24 -0
- package/src/ui/primitives/Button.tsx +53 -0
- package/src/ui/primitives/Spinner.tsx +21 -0
- package/src/ui/primitives/index.ts +5 -0
- package/src/ui/recorder/EphiaFloatingButton.tsx +489 -0
- package/src/ui/recorder/MinimalProcessingBars.tsx +122 -0
- package/src/ui/recorder/StandardIntensityVisualizer.tsx +148 -0
- package/src/ui/recorder/appearance.ts +9 -0
- package/src/ui/recorder/index.ts +8 -0
- package/src/ui/theme.css +775 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import type { MonacoEditorInstance } from "../../../shared/types/editors";
|
|
2
|
+
import type {
|
|
3
|
+
BeginSessionOptions,
|
|
4
|
+
SessionAnchor,
|
|
5
|
+
TargetBinding,
|
|
6
|
+
} from "../TargetBinding";
|
|
7
|
+
import { pickJoiner } from "../TargetBinding";
|
|
8
|
+
import type { DocumentOperation } from "ephia-protocol";
|
|
9
|
+
|
|
10
|
+
interface SessionSegment {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
revision: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PendingPartial {
|
|
17
|
+
segmentId: string;
|
|
18
|
+
text: string;
|
|
19
|
+
insertAt: number;
|
|
20
|
+
revision: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type MonacoRange = { startLineNumber: number; startColumn: number; endLineNumber: number; endColumn: number };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Binding Monaco Editor. Prend une instance duck-typée (IStandaloneCodeEditor).
|
|
27
|
+
*
|
|
28
|
+
* Même stratégie que le binding CM6 : les partials restent en mémoire et sont
|
|
29
|
+
* émis sur le DOM container. Seuls les finals s'appliquent via `model.applyEdits`.
|
|
30
|
+
*/
|
|
31
|
+
export function createMonacoBinding(editor: MonacoEditorInstance): TargetBinding {
|
|
32
|
+
let anchor: SessionAnchor | null = null;
|
|
33
|
+
let segments = new Map<string, SessionSegment>();
|
|
34
|
+
let pendingPartial: PendingPartial | null = null;
|
|
35
|
+
|
|
36
|
+
const getContainer = (): HTMLElement | null => editor.getDomNode();
|
|
37
|
+
|
|
38
|
+
const dispatchPartialEvent = (text: string | null, insertAt: number) => {
|
|
39
|
+
const el = getContainer();
|
|
40
|
+
if (!el) return;
|
|
41
|
+
el.dispatchEvent(
|
|
42
|
+
new CustomEvent(text === null ? "ephia:partial-cleared" : "ephia:partial", {
|
|
43
|
+
bubbles: false,
|
|
44
|
+
detail: text === null ? undefined : { text, insertAt },
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getOffset = (pos: { lineNumber: number; column: number } | null): number => {
|
|
50
|
+
if (!pos) return editor.getValue().length;
|
|
51
|
+
return editor.getModel()?.getOffsetAt(pos) ?? editor.getValue().length;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const posFromOffset = (offset: number): { lineNumber: number; column: number } => {
|
|
55
|
+
return editor.getModel()?.getPositionAt(offset) ?? { lineNumber: 1, column: 1 };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const applyEdit = (startOffset: number, endOffset: number, text: string): void => {
|
|
59
|
+
const model = editor.getModel();
|
|
60
|
+
if (!model) return;
|
|
61
|
+
const startPos = posFromOffset(startOffset);
|
|
62
|
+
const endPos = posFromOffset(endOffset);
|
|
63
|
+
const range: MonacoRange = {
|
|
64
|
+
startLineNumber: startPos.lineNumber,
|
|
65
|
+
startColumn: startPos.column,
|
|
66
|
+
endLineNumber: endPos.lineNumber,
|
|
67
|
+
endColumn: endPos.column,
|
|
68
|
+
};
|
|
69
|
+
model.applyEdits([{ range, text }]);
|
|
70
|
+
editor.setPosition(posFromOffset(startOffset + text.length));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
kind: "monaco",
|
|
75
|
+
|
|
76
|
+
attach(): void {},
|
|
77
|
+
|
|
78
|
+
detach(): void {
|
|
79
|
+
segments.clear();
|
|
80
|
+
pendingPartial = null;
|
|
81
|
+
anchor = null;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
// ─── Session lifecycle ─────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
beginSession(opts: BeginSessionOptions = {}): SessionAnchor {
|
|
87
|
+
const replaceSelection = opts.replaceSelection ?? true;
|
|
88
|
+
const sel = editor.getSelection();
|
|
89
|
+
const isFocused = !!(document.activeElement && getContainer()?.contains(document.activeElement));
|
|
90
|
+
|
|
91
|
+
let from: number;
|
|
92
|
+
let to: number;
|
|
93
|
+
let hadSelection = false;
|
|
94
|
+
|
|
95
|
+
if (sel && !sel.isEmpty() && isFocused) {
|
|
96
|
+
from = getOffset({ lineNumber: sel.startLineNumber, column: sel.startColumn });
|
|
97
|
+
to = getOffset({ lineNumber: sel.endLineNumber, column: sel.endColumn });
|
|
98
|
+
hadSelection = true;
|
|
99
|
+
} else if (isFocused) {
|
|
100
|
+
from = getOffset(editor.getPosition());
|
|
101
|
+
to = from;
|
|
102
|
+
} else {
|
|
103
|
+
from = editor.getValue().length;
|
|
104
|
+
to = from;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Ne pas supprimer la sélection ici — la suppression est différée
|
|
108
|
+
// au premier insert pour que l'user voie encore le texte pendant la connexion.
|
|
109
|
+
|
|
110
|
+
anchor = {
|
|
111
|
+
initialStart: from,
|
|
112
|
+
initialEnd: to, // conserver la vraie fin de sélection
|
|
113
|
+
hadSelection,
|
|
114
|
+
end: from, // point d'insertion = début de sélection
|
|
115
|
+
selectionPendingDelete: hadSelection && replaceSelection,
|
|
116
|
+
};
|
|
117
|
+
segments.clear();
|
|
118
|
+
pendingPartial = null;
|
|
119
|
+
return anchor;
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
endSession(): void {
|
|
123
|
+
if (pendingPartial) dispatchPartialEvent(null, 0);
|
|
124
|
+
anchor = null;
|
|
125
|
+
segments.clear();
|
|
126
|
+
pendingPartial = null;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
getSessionAnchor(): SessionAnchor | null {
|
|
130
|
+
return anchor;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
getRangeRect(start: number, end: number): DOMRect | null {
|
|
134
|
+
try {
|
|
135
|
+
const model = editor.getModel();
|
|
136
|
+
if (!model) return null;
|
|
137
|
+
const startPos = model.getPositionAt(start);
|
|
138
|
+
const endPos = model.getPositionAt(end);
|
|
139
|
+
const startCoords = editor.getScrolledVisiblePosition(startPos);
|
|
140
|
+
const endCoords = editor.getScrolledVisiblePosition(endPos);
|
|
141
|
+
if (!startCoords || !endCoords) return null;
|
|
142
|
+
const containerRect = getContainer()?.getBoundingClientRect();
|
|
143
|
+
if (!containerRect) return null;
|
|
144
|
+
const top = Math.min(startCoords.top, endCoords.top) + containerRect.top;
|
|
145
|
+
const bottom = Math.max(startCoords.top + startCoords.height, endCoords.top + endCoords.height) + containerRect.top;
|
|
146
|
+
const left = Math.min(startCoords.left, endCoords.left) + containerRect.left;
|
|
147
|
+
const right = Math.max(startCoords.left, endCoords.left) + containerRect.left;
|
|
148
|
+
return new DOMRect(left, top, Math.max(2, right - left), bottom - top);
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
getCursorRect(): DOMRect | null {
|
|
155
|
+
return getContainer()?.getBoundingClientRect() ?? null;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// ─── Streaming ─────────────────────────────────────────────────────────────
|
|
159
|
+
|
|
160
|
+
insertPartial(segmentId: string, text: string, revision: number): void {
|
|
161
|
+
if (!anchor) {
|
|
162
|
+
const pos = getOffset(editor.getPosition());
|
|
163
|
+
anchor = { initialStart: pos, initialEnd: pos, hadSelection: false, end: pos, selectionPendingDelete: false };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (pendingPartial?.segmentId === segmentId) {
|
|
167
|
+
if (revision < pendingPartial.revision) return;
|
|
168
|
+
pendingPartial.text = text;
|
|
169
|
+
pendingPartial.revision = revision;
|
|
170
|
+
} else {
|
|
171
|
+
pendingPartial = { segmentId, text, insertAt: anchor.end, revision };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
dispatchPartialEvent(text, pendingPartial.insertAt);
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
commitFinal(segmentId: string, text: string): void {
|
|
178
|
+
const currentText = editor.getValue();
|
|
179
|
+
|
|
180
|
+
if (!anchor) {
|
|
181
|
+
const pos = getOffset(editor.getPosition());
|
|
182
|
+
const before = currentText.slice(0, pos);
|
|
183
|
+
const joiner = pickJoiner(before, text);
|
|
184
|
+
applyEdit(pos, pos, joiner + text);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Suppression lazy de la sélection au premier commit
|
|
189
|
+
if (anchor.selectionPendingDelete && anchor.initialEnd > anchor.initialStart) {
|
|
190
|
+
applyEdit(anchor.initialStart, anchor.initialEnd, "");
|
|
191
|
+
anchor.end = anchor.initialStart;
|
|
192
|
+
anchor.selectionPendingDelete = false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (pendingPartial?.segmentId === segmentId) {
|
|
196
|
+
const insertAt = pendingPartial.insertAt;
|
|
197
|
+
const before = editor.getValue().slice(0, insertAt);
|
|
198
|
+
const joiner = pickJoiner(before, text);
|
|
199
|
+
const full = joiner + text;
|
|
200
|
+
|
|
201
|
+
dispatchPartialEvent(null, 0);
|
|
202
|
+
applyEdit(insertAt, insertAt, full);
|
|
203
|
+
|
|
204
|
+
segments.set(segmentId, { start: insertAt + joiner.length, end: insertAt + full.length, revision: 0 });
|
|
205
|
+
anchor.end = insertAt + full.length;
|
|
206
|
+
pendingPartial = null;
|
|
207
|
+
} else {
|
|
208
|
+
const existing = segments.get(segmentId);
|
|
209
|
+
if (existing) {
|
|
210
|
+
const oldLen = existing.end - existing.start;
|
|
211
|
+
applyEdit(existing.start, existing.end, text);
|
|
212
|
+
existing.end = existing.start + text.length;
|
|
213
|
+
existing.revision += 1;
|
|
214
|
+
anchor.end += text.length - oldLen;
|
|
215
|
+
} else {
|
|
216
|
+
const before = editor.getValue().slice(0, anchor.end);
|
|
217
|
+
const joiner = pickJoiner(before, text);
|
|
218
|
+
const full = joiner + text;
|
|
219
|
+
applyEdit(anchor.end, anchor.end, full);
|
|
220
|
+
segments.set(segmentId, { start: anchor.end + joiner.length, end: anchor.end + full.length, revision: 0 });
|
|
221
|
+
anchor.end += full.length;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
clearPartial(segmentId: string): void {
|
|
227
|
+
if (pendingPartial?.segmentId === segmentId) {
|
|
228
|
+
pendingPartial = null;
|
|
229
|
+
dispatchPartialEvent(null, 0);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
clearAll(): void {
|
|
234
|
+
if (pendingPartial) {
|
|
235
|
+
pendingPartial = null;
|
|
236
|
+
dispatchPartialEvent(null, 0);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
getSegmentRange(segmentId: string): { start: number; end: number } | null {
|
|
241
|
+
const seg = segments.get(segmentId);
|
|
242
|
+
return seg ? { start: seg.start, end: seg.end } : null;
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
getText(): string {
|
|
246
|
+
return editor.getValue();
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
getCursorOffset(): number | null {
|
|
250
|
+
return getOffset(editor.getPosition());
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
getSelection() {
|
|
254
|
+
const sel = editor.getSelection();
|
|
255
|
+
if (!sel || sel.isEmpty()) return null;
|
|
256
|
+
const from = getOffset({ lineNumber: sel.startLineNumber, column: sel.startColumn });
|
|
257
|
+
const to = getOffset({ lineNumber: sel.endLineNumber, column: sel.endColumn });
|
|
258
|
+
return {
|
|
259
|
+
text: editor.getValue().slice(from, to),
|
|
260
|
+
range: { start: from, end: to },
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
applyOperation(operation: DocumentOperation): void {
|
|
265
|
+
const text = editor.getValue();
|
|
266
|
+
switch (operation.type) {
|
|
267
|
+
case "replace": {
|
|
268
|
+
let start: number, end: number;
|
|
269
|
+
if (operation.range) {
|
|
270
|
+
start = operation.range.start; end = operation.range.end;
|
|
271
|
+
} else if (operation.targetText) {
|
|
272
|
+
const idx = text.indexOf(operation.targetText);
|
|
273
|
+
if (idx === -1) return;
|
|
274
|
+
start = idx; end = idx + operation.targetText.length;
|
|
275
|
+
} else return;
|
|
276
|
+
applyEdit(start, end, operation.replacement);
|
|
277
|
+
if (anchor) anchor.end += operation.replacement.length - (end - start);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case "insert": {
|
|
281
|
+
let pos = getOffset(editor.getPosition());
|
|
282
|
+
if (typeof operation.position === "number") pos = operation.position;
|
|
283
|
+
else if (operation.position === "end") pos = text.length;
|
|
284
|
+
else if (operation.position === "start") pos = 0;
|
|
285
|
+
applyEdit(pos, pos, operation.text);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "delete": {
|
|
289
|
+
let start: number, end: number;
|
|
290
|
+
if (operation.range) {
|
|
291
|
+
start = operation.range.start; end = operation.range.end;
|
|
292
|
+
} else if (operation.targetText) {
|
|
293
|
+
const idx = text.indexOf(operation.targetText);
|
|
294
|
+
if (idx === -1) return;
|
|
295
|
+
start = idx; end = idx + operation.targetText.length;
|
|
296
|
+
} else return;
|
|
297
|
+
applyEdit(start, end, "");
|
|
298
|
+
if (anchor) anchor.end -= (end - start);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case "replace_all": {
|
|
302
|
+
const model = editor.getModel();
|
|
303
|
+
if (!model) break;
|
|
304
|
+
const len = text.length;
|
|
305
|
+
applyEdit(0, len, operation.replacement);
|
|
306
|
+
segments.clear();
|
|
307
|
+
if (anchor) anchor.end = operation.replacement.length;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
default:
|
|
311
|
+
console.warn("[monacoBinding] Operation not supported:", operation.type);
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|