Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRT-2119 feat: allow setting the config in runtime #170

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IaraEditorStyleManager } from "./style";

export interface IaraEditorConfig {
darkMode: boolean;
enableSpeechRecognition: boolean;
font?: {
availableFamilies: string[];
availableSizes: number[];
Expand All @@ -26,7 +27,6 @@ export abstract class EditorAdapter {
template: unknown,
metadata: unknown
) => Promise<void>;
public iaraRecognizes = true;
public selectedField: {
content: string;
title: string;
Expand All @@ -37,6 +37,7 @@ export abstract class EditorAdapter {
protected abstract _navigationFieldManager: IaraEditorNavigationFieldManager;
protected static DefaultConfig: IaraEditorConfig = {
darkMode: false,
enableSpeechRecognition: true,
saveReport: true,
zoomFactor: "100%",
language: "pt-BR",
Expand All @@ -48,42 +49,46 @@ export abstract class EditorAdapter {
{
key: "iaraSpeechRecognitionResult",
callback: (event?: CustomEvent<IaraSpeechRecognitionDetail>) => {
if (event?.detail && this.iaraRecognizes)
this.insertInference(event.detail);
if (!event?.detail || !this.config.enableSpeechRecognition) return;
this.insertInference(event.detail);
},
},
{
key: "iaraSpeechRecognitionStart",
callback: () => {
if (!this.config.enableSpeechRecognition) return;
this.blockEditorWhileSpeaking(true);
},
},

{
key: "iaraSpeechRecognitionStop",
callback: () => {
if (!this.config.enableSpeechRecognition) return;
this.blockEditorWhileSpeaking(false);
},
},
{
key: "iaraSpeechRecognitionVADVoiceStart",
callback: () => {
if (!this.config.enableSpeechRecognition) return;
this.blockEditorWhileSpeaking(true);
},
},
{
key: "iaraSpeechRecognitionVADVoiceStop",
callback: () => {
if (!this.config.enableSpeechRecognition) return;
this.blockEditorWhileSpeaking(false);
},
},
];

constructor(
protected _recognition: IaraSpeechRecognition,
protected _config: IaraEditorConfig = EditorAdapter.DefaultConfig
public config: IaraEditorConfig = EditorAdapter.DefaultConfig
) {
switch (this._config.language) {
switch (this.config.language) {
case "es":
this._locale = Locales["es"];
break;
Expand All @@ -106,12 +111,12 @@ export abstract class EditorAdapter {
abstract print(): void;

async beginReport(): Promise<string | void> {
if (!this._config.saveReport) return;
if (!this.config.saveReport) return;
return this._recognition.report.begin("", "");
}

async finishReport(): Promise<void> {
if (!this._config.saveReport) return;
if (!this.config.saveReport) return;
const content = await this.copyReport();
this.clearReport();
await this._recognition.report.finish(content[0], content[1]);
Expand Down Expand Up @@ -239,7 +244,7 @@ export abstract class EditorAdapter {
}

protected async _beginReport(): Promise<void> {
if (this._config.saveReport && !this._recognition.report["_key"]) {
if (this.config.saveReport && !this._recognition.report["_key"]) {
if (this._recognition.ready) {
this._recognition.report["_key"] = await this.beginReport();
} else {
Expand Down
30 changes: 15 additions & 15 deletions src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export class IaraSyncfusionAdapter
constructor(
_editorInstance: DocumentEditorContainer | DocumentEditor,
protected _recognition: IaraSpeechRecognition,
protected _config: IaraSyncfusionConfig = IaraSyncfusionAdapter.DefaultConfig
public config: IaraSyncfusionConfig = IaraSyncfusionAdapter.DefaultConfig
) {
super(_recognition, _config);
super(_recognition, config);

IaraSyncfusionAdapter.IARA_API_URL =
this._recognition.internal.initParams.region === "europe"
Expand All @@ -83,26 +83,26 @@ export class IaraSyncfusionAdapter
this._editorContainer = _editorInstance;
this._documentEditor = _editorInstance.documentEditor;
this._editorContainer.documentEditorSettings.showBookmarks =
this._config.showBookmarks;
this.config.showBookmarks;
} else {
this._documentEditor = _editorInstance;
}

this._languageManager = new IaraSyncfusionLanguageManager(this._config);
this._languageManager = new IaraSyncfusionLanguageManager(this.config);

this._contentManager = new IaraSyncfusionEditorContentManager(
this._documentEditor,
() => (this._config.saveReport ? this._debouncedSaveReport() : undefined)
() => (this.config.saveReport ? this._debouncedSaveReport() : undefined)
);

this._styleManager = new IaraSyncfusionStyleManager(
this._documentEditor,
this._config
this.config
);

this._navigationFieldManager = new IaraSyncfusionNavigationFieldManager(
this._documentEditor,
this._config,
this.config,
this._recognition,
this._languageManager
);
Expand All @@ -113,10 +113,10 @@ export class IaraSyncfusionAdapter
this._recognition
);

if (this._config.replaceToolbar && this._editorContainer) {
if (this.config.replaceToolbar && this._editorContainer) {
this._toolbarManager = new IaraSyncfusionToolbarManager(
this._editorContainer,
this._config,
this.config,
this._navigationFieldManager,
this._languageManager
);
Expand Down Expand Up @@ -334,7 +334,7 @@ export class IaraSyncfusionAdapter
this._styleManager.setEditorDefaultFont({
fontFamily: this._documentEditor.selection.characterFormat.fontFamily,
fontSize: this._documentEditor.selection.characterFormat.fontSize,
fontColor: this._config.darkMode ? "#fff" : "#000",
fontColor: this.config.darkMode ? "#fff" : "#000",
});

this._navigationFieldManager.getBookmarks();
Expand Down Expand Up @@ -486,9 +486,9 @@ export class IaraSyncfusionAdapter
}

print(): void {
if (this._config.darkMode) this._styleManager.setEditorFontColor("#000");
if (this.config.darkMode) this._styleManager.setEditorFontColor("#000");
this._documentEditor.print();
if (this._config.darkMode) this._styleManager.setEditorFontColor("#fff");
if (this.config.darkMode) this._styleManager.setEditorFontColor("#fff");
}

replaceParagraph(
Expand Down Expand Up @@ -516,7 +516,7 @@ export class IaraSyncfusionAdapter
if (event.button === 1) {
this._cursorSelection = new IaraSyncfusionSelectionManager(
this._documentEditor,
this._config
this.config
);
}
});
Expand Down Expand Up @@ -558,12 +558,12 @@ export class IaraSyncfusionAdapter

this._selectionManager = new IaraSyncfusionSelectionManager(
this._documentEditor,
this._config,
this.config,
inference.inferenceId
? `inferenceId_${inference.inferenceId}`
: undefined,
true,
this._config.highlightInference
this.config.highlightInference
);

this._inferenceBookmarksManager.addBookmark(
Expand Down
4 changes: 2 additions & 2 deletions src/tinymce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class IaraTinyMCEAdapter extends EditorAdapter implements EditorAdapter {
constructor(
protected _editor: Editor,
protected _recognition: IaraSpeechRecognition,
protected _config: IaraEditorConfig
public config: IaraEditorConfig
) {
super(_recognition, _config);
super(_recognition, config);
this._inferenceFormatter = new IaraEditorInferenceFormatter();
this._styleManager = new IaraTinyMceStyleManager();
this._navigationFieldManager = new IaraTinyMceNavigationFieldManager(
Expand Down