Skip to content

Commit

Permalink
Pull request #241: fix(Editor) when websocket session cannot be found…
Browse files Browse the repository at this point in the history
… anymore, import after export gives an error - IIC-1202

Merge in WS/iink-ts from IIC-1202 to master

* commit '8950dae563e9271d6bd7be5829f1f77986d019be':
  fix(Editor) when websocket session cannot be found anymore, import after export gives an error - IIC-1202
  • Loading branch information
leJsboureau committed Aug 27, 2024
2 parents 8d9c032 + ba6c7fc commit b1c6eed
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
13 changes: 5 additions & 8 deletions src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,19 @@ export class Editor
{
this.#messageContainer = document.createElement("div")
this.#messageContainer.classList.add("message-container")
this.#messageContainer.style.display = "none"

this.#messageOverlay = document.createElement("div")
this.#messageOverlay.classList.add("message-overlay")
this.#messageOverlay.style.display = "none"
this.#messageContainer.appendChild(this.#messageOverlay)

this.#messageModal = document.createElement("div")
this.#messageModal.classList.add("message-modal")

const closeBtn = document.createElement("button")
closeBtn.classList.add("ms-button", "close")
closeBtn.addEventListener("pointerup", this.closeMessageModal.bind(this))
closeBtn.addEventListener("pointerup", () => this.closeMessageModal())
this.#messageModal.appendChild(closeBtn)
this.#messageModal.style.display = "none"

this.#messageText = document.createElement("p")
this.#messageModal.appendChild(this.#messageText)
Expand Down Expand Up @@ -345,8 +344,7 @@ export class Editor

async closeMessageModal(): Promise<void>
{
this.#messageModal.style.display = "none"
this.#messageOverlay.style.display = "none"
this.#messageContainer.style.display = "none"
this.#messageText.innerText = ""
if (this.#messageModal.classList.contains("error-msg")) {
this.#messageModal.classList.remove("error-msg")
Expand All @@ -359,16 +357,15 @@ export class Editor
{
this.#messageModal.classList.add("error-msg")
this.#messageModal.classList.remove("info-msg")
this.#messageModal.style.display = "initial"
this.#messageOverlay.style.display = "initial"
this.#messageContainer.style.display = "block"
this.#messageText.innerText = typeof err === "string" ? err : err.message
}

showNotif(notif: { message: string, timeout?: number })
{
this.#messageModal.style.display = "initial"
this.#messageModal.classList.add("info-msg")
this.#messageModal.classList.remove("error-msg")
this.#messageContainer.style.display = "block"
this.#messageText.innerText = notif.message
setTimeout(() =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/behaviors/OIBehaviors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,8 @@ export class OIBehaviors implements IBehaviors
this.renderer.destroy()
this.menu.destroy()
this.recognizer.destroy()
this.model.clear()
this.history.clear()
return Promise.resolve()
}
}
6 changes: 6 additions & 0 deletions src/history/OIHistoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ export class OIHistoryManager implements IHistoryManager
this.#logger.debug("redo", nextStackItem)
return nextStackItem
}

clear(): void
{
this.context = getInitialUndoRedoContext()
this.stack = []
}
}
4 changes: 1 addition & 3 deletions src/iink.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .16);
}


.ms-editor.draw {
cursor: url('data:image/svg+xml,<svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M14.3632 5.65156L15.8431 4.17157C16.6242 3.39052 17.8905 3.39052 18.6716 4.17157L20.0858 5.58579C20.8668 6.36683 20.8668 7.63316 20.0858 8.41421L18.6058 9.8942M14.3632 5.65156L4.74749 15.2672C4.41542 15.5993 4.21079 16.0376 4.16947 16.5054L3.92738 19.2459C3.87261 19.8659 4.39148 20.3848 5.0115 20.33L7.75191 20.0879C8.21972 20.0466 8.65806 19.8419 8.99013 19.5099L18.6058 9.8942M14.3632 5.65156L18.6058 9.8942" stroke="%23000000" fill="white" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" ></path></svg>') 5 20, pointer;
}
Expand Down Expand Up @@ -109,8 +108,8 @@
user-select: none;
}
.ms-editor .ms-layer-infos > * {
pointer-events: all;
cursor: auto;
pointer-events: all;
user-select: none;
}
/** loader **/
Expand Down Expand Up @@ -165,7 +164,6 @@
position: absolute;
width: 100%;
height: 100%;
pointer-events: none;
}
.ms-editor .message-overlay {
z-index: 99;
Expand Down
4 changes: 2 additions & 2 deletions src/recognizer/OIRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class OIRecognizer

if (this.currentErrorCode === "no.activity") {
this.rejectDeferredPending(message)
this.internalEvent.emitNotif({ message: RecognizerError.NO_ACTIVITY, timeout: Infinity})
this.internalEvent.emitNotif({ message: RecognizerError.NO_ACTIVITY, timeout: Infinity })
}
else {
switch (this.currentErrorCode) {
Expand Down Expand Up @@ -433,7 +433,7 @@ export class OIRecognizer
this.socket.send(JSON.stringify(message))
return Promise.resolve()
}
else {
else if (this.currentErrorCode !== "restore.session.not.found") {
if (this.socket.readyState != this.socket.CONNECTING && this.serverConfiguration.websocket.autoReconnect) {
this.reconnectionCount++
await this.initialized?.promise
Expand Down
9 changes: 5 additions & 4 deletions test/unit/Editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ describe("Editor.ts", () =>
wrapperHTML.style.width = "100px"
const editor = new Editor(wrapperHTML, DefaultBehaviorsOptions)
editor.behaviors.init = jest.fn(() => Promise.reject(new Error("pouet")))
const messageElement = wrapperHTML.querySelector(".message-modal") as HTMLElement
const messageContainer = wrapperHTML.querySelector(".message-container") as HTMLElement
const messageElement = messageContainer.querySelector(".message-modal p") as HTMLElement
try {
expect(messageElement!.style.display).toEqual("none")
expect(messageContainer!.style.display).toEqual("none")
await editor.initialize()
} catch (error) {
expect(messageElement!.style.display).toEqual("initial")
expect(messageElement!.querySelector("p")!.innerText).toEqual("pouet")
expect(messageContainer.style.display).toEqual("block")
expect(messageElement.innerText).toEqual("pouet")
}
})
})
Expand Down

0 comments on commit b1c6eed

Please sign in to comment.