@shapediver/viewer.shared.services
Advanced tools
Comparing version 3.2.6 to 3.2.7
@@ -17,4 +17,6 @@ import { IDomEventListener } from './IDomEventListener'; | ||
private _onPointerUp; | ||
private _restrictedListenerTokens; | ||
constructor(canvas: HTMLCanvasElement); | ||
addDomEventListener(listener: IDomEventListener): string; | ||
addRestrictedListenerToken(token: string): void; | ||
/** | ||
@@ -43,2 +45,3 @@ * Allow / disallow events. | ||
removeDomEventListener(id: string): boolean; | ||
removeRestrictedListenerToken(token: string): void; | ||
private addEventListeners; | ||
@@ -45,0 +48,0 @@ private onContextMenu; |
@@ -6,6 +6,6 @@ "use strict"; | ||
class DomEventEngine { | ||
// #endregion Properties (14) | ||
// #endregion Properties (15) | ||
// #region Constructors (1) | ||
constructor(canvas) { | ||
// #region Properties (14) | ||
// #region Properties (15) | ||
this._domEventListeners = {}; | ||
@@ -24,2 +24,3 @@ this._uuidGenerator = UuidGenerator_1.UuidGenerator.instance; | ||
this._currentPointerPosition = { x: 0, y: 0 }; | ||
this._restrictedListenerTokens = []; | ||
this._canvas = canvas; | ||
@@ -38,3 +39,3 @@ this._onMouseWheel = this.onMouseWheel.bind(this); | ||
// #endregion Constructors (1) | ||
// #region Public Methods (5) | ||
// #region Public Methods (7) | ||
addDomEventListener(listener) { | ||
@@ -45,2 +46,7 @@ const id = this._uuidGenerator.create(); | ||
} | ||
addRestrictedListenerToken(token) { | ||
if (this._restrictedListenerTokens.includes(token)) | ||
return; | ||
this._restrictedListenerTokens.push(token); | ||
} | ||
/** | ||
@@ -142,2 +148,3 @@ * Allow / disallow events. | ||
delete this._domEventListeners[id]; | ||
this._restrictedListenerTokens = []; | ||
} | ||
@@ -147,2 +154,3 @@ removeDomEventListener(id) { | ||
delete this._domEventListeners[id]; | ||
this._restrictedListenerTokens = this._restrictedListenerTokens.filter(t => t !== id); | ||
return true; | ||
@@ -152,3 +160,8 @@ } | ||
} | ||
// #endregion Public Methods (5) | ||
removeRestrictedListenerToken(token) { | ||
const index = this._restrictedListenerTokens.indexOf(token); | ||
if (index !== -1) | ||
this._restrictedListenerTokens.splice(index, 1); | ||
} | ||
// #endregion Public Methods (7) | ||
// #region Private Methods (11) | ||
@@ -174,4 +187,9 @@ addEventListeners() { | ||
onKeyDown(event) { | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) | ||
Object.values(this._domEventListeners).forEach(e => e.onKeyDown(event)); | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) { | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onKeyDown(event); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -182,4 +200,9 @@ onKeyDownPointerPositionHelper(event) { | ||
onKeyUp(event) { | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) | ||
Object.values(this._domEventListeners).forEach(e => e.onKeyUp(event)); | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) { | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onKeyUp(event); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -189,21 +212,41 @@ onMouseWheel(event) { | ||
event.stopPropagation(); | ||
Object.values(this._domEventListeners).forEach(e => e.onMouseWheel(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onMouseWheel(event); | ||
} | ||
}); | ||
} | ||
onPointerDown(event) { | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerDown(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerDown(event); | ||
} | ||
}); | ||
} | ||
onPointerMove(event) { | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerMove(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerMove(event); | ||
} | ||
}); | ||
} | ||
onPointerOut(event) { | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerOut(event)); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerEnd(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerOut(event); | ||
listener.onPointerEnd(event); | ||
} | ||
}); | ||
} | ||
onPointerUp(event) { | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerUp(event)); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerEnd(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerUp(event); | ||
listener.onPointerEnd(event); | ||
} | ||
}); | ||
} | ||
@@ -210,0 +253,0 @@ removeEventListeners() { |
{ | ||
"name": "@shapediver/viewer.shared.services", | ||
"version": "3.2.6", | ||
"version": "3.2.7", | ||
"description": "", | ||
@@ -45,3 +45,3 @@ "keywords": [], | ||
"@shapediver/viewer.settings": "1.0.2", | ||
"@shapediver/viewer.shared.build-data": "3.2.6", | ||
"@shapediver/viewer.shared.build-data": "3.2.7", | ||
"@types/dompurify": "^2.3.1", | ||
@@ -56,3 +56,3 @@ "@types/ua-parser-js": "^0.7.36", | ||
}, | ||
"gitHead": "f4ca645ecf64020080a1c5fa2c2aaf9f891b1445" | ||
"gitHead": "d21783f03fd4f64b1e44708998c55c1685f76701" | ||
} |
@@ -5,3 +5,3 @@ import { IDomEventListener } from './IDomEventListener'; | ||
export class DomEventEngine { | ||
// #region Properties (14) | ||
// #region Properties (15) | ||
@@ -34,4 +34,5 @@ private readonly _domEventListeners: { | ||
private _onPointerUp: (event: PointerEvent) => void; | ||
private _restrictedListenerTokens: string[] = []; | ||
// #endregion Properties (14) | ||
// #endregion Properties (15) | ||
@@ -57,3 +58,3 @@ // #region Constructors (1) | ||
// #region Public Methods (5) | ||
// #region Public Methods (7) | ||
@@ -66,2 +67,7 @@ public addDomEventListener(listener: IDomEventListener): string { | ||
public addRestrictedListenerToken(token: string): void { | ||
if(this._restrictedListenerTokens.includes(token)) return; | ||
this._restrictedListenerTokens.push(token); | ||
} | ||
/** | ||
@@ -173,2 +179,4 @@ * Allow / disallow events. | ||
delete this._domEventListeners[id]; | ||
this._restrictedListenerTokens = []; | ||
} | ||
@@ -179,2 +187,3 @@ | ||
delete this._domEventListeners[id]; | ||
this._restrictedListenerTokens = this._restrictedListenerTokens.filter(t => t !== id); | ||
return true; | ||
@@ -185,4 +194,9 @@ } | ||
// #endregion Public Methods (5) | ||
public removeRestrictedListenerToken(token: string): void { | ||
const index = this._restrictedListenerTokens.indexOf(token); | ||
if (index !== -1) this._restrictedListenerTokens.splice(index, 1); | ||
} | ||
// #endregion Public Methods (7) | ||
// #region Private Methods (11) | ||
@@ -214,4 +228,9 @@ | ||
private onKeyDown(event: KeyboardEvent): void { | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) | ||
Object.values(this._domEventListeners).forEach(e => e.onKeyDown(event)); | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) { | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onKeyDown(event); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -224,4 +243,9 @@ | ||
private onKeyUp(event: KeyboardEvent): void { | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) | ||
Object.values(this._domEventListeners).forEach(e => e.onKeyUp(event)); | ||
if (this._canvas === document.elementFromPoint(this._currentPointerPosition.x, this._currentPointerPosition.y)) { | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onKeyUp(event); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -232,3 +256,7 @@ | ||
event.stopPropagation(); | ||
Object.values(this._domEventListeners).forEach(e => e.onMouseWheel(<WheelEvent>event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onMouseWheel(<WheelEvent>event); | ||
} | ||
}); | ||
} | ||
@@ -238,3 +266,7 @@ | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerDown(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerDown(event); | ||
} | ||
}); | ||
} | ||
@@ -244,3 +276,7 @@ | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerMove(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerMove(event); | ||
} | ||
}); | ||
} | ||
@@ -250,4 +286,8 @@ | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerOut(event)); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerEnd(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerOut(event); | ||
listener.onPointerEnd(event); | ||
} | ||
}); | ||
} | ||
@@ -257,4 +297,8 @@ | ||
event.preventDefault(); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerUp(event)); | ||
Object.values(this._domEventListeners).forEach(e => e.onPointerEnd(event)); | ||
Object.entries(this._domEventListeners).forEach(([key, listener]) => { | ||
if (this._restrictedListenerTokens.length === 0 || this._restrictedListenerTokens.includes(key)) { | ||
listener.onPointerUp(event); | ||
listener.onPointerEnd(event); | ||
} | ||
}); | ||
} | ||
@@ -261,0 +305,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
390539
6289
+ Added@shapediver/viewer.shared.build-data@3.2.7(transitive)
- Removed@shapediver/viewer.shared.build-data@3.2.6(transitive)