-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { IEditServiceProvider } from '../server/Server' | ||
import { IEditService } from '../service/editorService' | ||
export abstract class DataEditor { | ||
import { IEditService, IServiceMediator } from '../service/editorService' | ||
import { DataEditorUI } from './dataEditorUI' | ||
export abstract class DataEditor implements IServiceMediator { | ||
protected abstract fileToEdit: string | ||
protected abstract ui: DataEditorUI | undefined | ||
|
||
protected editService: IEditService | undefined = undefined | ||
async initialize(provider: IEditServiceProvider) { | ||
|
||
abstract initializeUI(ui: DataEditorUI): void | ||
abstract notify(notification: { id: string; data: any }): void | ||
protected abstract getFile(): Promise<void> | ||
|
||
filePath() { | ||
return this.fileToEdit | ||
} | ||
async getServiceFrom(provider: IEditServiceProvider) { | ||
await this.getFile() | ||
this.editService = await provider.getService(this.fileToEdit) | ||
this.editService = await provider.getService(this, this.fileToEdit) | ||
} | ||
protected abstract getFile(): Promise<void> | ||
} | ||
export interface DataEditorUI { | ||
show(): Promise<void> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface DataEditorUI { | ||
show(): Promise<void> | ||
sendMessage(msg: any): void | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
ALL_EVENTS, | ||
CreateSessionResponse, | ||
EditorClient, | ||
EventSubscriptionRequest, | ||
ViewportDataResponse, | ||
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)
Check failure on line 6 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)
|
||
ViewportEvent, | ||
ViewportEventKind, | ||
createViewport, | ||
getByteOrderMark, | ||
getClient, | ||
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)
Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)
|
||
getContentType, | ||
getLanguage, | ||
} from '@omega-edit/client' | ||
import EventEmitter from 'events' | ||
import { Viewport } from './Viewport' | ||
|
||
/* OmegaEditService Implementation */ | ||
const SessionMetadata = { | ||
byteOrderMark: '', | ||
changeCount: 0, | ||
computedFileSize: 0, | ||
diskFileSize: 0, | ||
fileName: '', | ||
language: '', | ||
type: '', | ||
undoCount: 0, | ||
} | ||
export class Session { | ||
readonly id: string | ||
|
||
private metadata = SessionMetadata | ||
private metadataEventEmitter = new EventEmitter() | ||
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)
Check failure on line 33 in src/dataEditor/include/omegaEdit/Session.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)
|
||
private viewports: Map<string, Viewport> = new Map() | ||
|
||
constructor( | ||
response: CreateSessionResponse, | ||
public onMetadataUpdate: (data: typeof SessionMetadata) => void | ||
) { | ||
this.id = response.getSessionId() | ||
if (response.hasFileSize()) { | ||
this.metadata.diskFileSize = this.metadata.computedFileSize = | ||
response.getFileSize()! | ||
} | ||
this.populateAsyncMetadata().then(() => { | ||
this.onMetadataUpdate(this.metadata) | ||
}) | ||
} | ||
async createViewport( | ||
client: EditorClient, | ||
offset: number, | ||
capacity: number, | ||
onDataEvent: (event: Viewport) => void | ||
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
createViewport(undefined, this.id, offset, capacity) | ||
.then((response) => { | ||
this.viewports.set( | ||
response.getViewportId(), | ||
new Viewport(response.getData_asU8(), capacity) | ||
) | ||
client | ||
.subscribeToViewportEvents( | ||
new EventSubscriptionRequest() | ||
.setId(response.getViewportId()) | ||
.setInterest( | ||
ALL_EVENTS & ~ViewportEventKind.VIEWPORT_EVT_MODIFY | ||
) | ||
) | ||
.on('data', async (event: ViewportEvent) => { | ||
onDataEvent(new Viewport(event.getData_asU8(), 1024)) | ||
}) | ||
resolve() | ||
}) | ||
.catch((err) => { | ||
reject(err) | ||
}) | ||
}) | ||
} | ||
info() { | ||
return { ...this.metadata } | ||
} | ||
private async populateAsyncMetadata() { | ||
const contentTypeResponse = await getContentType( | ||
this.id, | ||
0, | ||
Math.min(1024, this.metadata.computedFileSize) | ||
) | ||
this.metadata.type = contentTypeResponse.getContentType() | ||
|
||
const byteOrderMarkResponse = await getByteOrderMark(this.id, 0) | ||
this.metadata.byteOrderMark = byteOrderMarkResponse.getByteOrderMark() | ||
|
||
const languageResponse = await getLanguage( | ||
this.id, | ||
0, | ||
Math.min(1024, this.metadata.computedFileSize), | ||
this.metadata.byteOrderMark | ||
) | ||
this.metadata.language = languageResponse.getLanguage() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ViewportDataResponse } from '@omega-edit/client' | ||
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)
Check failure on line 1 in src/dataEditor/include/omegaEdit/Viewport.ts GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)
|
||
|
||
export class Viewport { | ||
constructor( | ||
protected data: Uint8Array, | ||
protected capacity: number | ||
) {} | ||
length() { | ||
return this.data.length | ||
} | ||
} |