@@ -3,16 +3,26 @@ import { escapeHtml } from "/js/utils.js"
33const eventDispatcher = TPEN . eventDispatcher
44import CheckPermissions from "../check-permissions/checkPermissions.js"
55import { onProjectReady } from "../../utilities/projectReady.js"
6+ import { CleanupRegistry } from '../../utilities/CleanupRegistry.js'
67import "./quicktype-editor-dialog.js"
78
9+ /**
10+ * QuickTypeTool - Provides keyboard shortcut buttons for inserting special characters.
11+ * Requires PROJECT CONTENT edit access for shortcuts, PROJECT OPTIONS edit access for editing.
12+ * @element tpen-quicktype-tool
13+ */
814class QuickTypeTool extends HTMLElement {
15+ /** @type {CleanupRegistry } Registry for cleanup handlers */
16+ cleanup = new CleanupRegistry ( )
17+
918 constructor ( ) {
1019 super ( )
1120 this . attachShadow ( { mode : "open" } )
1221 this . _invalidToastShown = false
1322 }
1423
1524 connectedCallback ( ) {
25+ TPEN . attachAuthentication ( this )
1626 this . _unsubProject = onProjectReady ( this , ( ) => {
1727 this . render ( )
1828 this . addEventListeners ( )
@@ -22,7 +32,7 @@ class QuickTypeTool extends HTMLElement {
2232
2333 disconnectedCallback ( ) {
2434 try { this . _unsubProject ?. ( ) } catch { }
25- try { this . _unsubEditorSaved ?. ( ) } catch { }
35+ this . cleanup . run ( )
2636 }
2737
2838 initializeDialog ( ) {
@@ -33,7 +43,7 @@ class QuickTypeTool extends HTMLElement {
3343 }
3444
3545 // Listen for save events to refresh the panel
36- this . _unsubEditorSaved = eventDispatcher . on ( "quicktype-editor-saved" , ( event ) => {
46+ this . cleanup . onEvent ( eventDispatcher , "quicktype-editor-saved" , ( event ) => {
3747 // Refresh the tool panel with updated shortcuts
3848 TPEN . activeProject . interfaces . quicktype = event . detail . quicktype
3949 this . render ( )
@@ -42,19 +52,20 @@ class QuickTypeTool extends HTMLElement {
4252 }
4353
4454 addEventListeners ( ) {
45- const charPanel = this . shadowRoot . querySelector ( '.char-panel' )
4655 const editCharBtn = this . shadowRoot . querySelector ( '.edit-char-btn' )
4756
48- editCharBtn . addEventListener ( 'click' , ( ) => {
49- const dialog = document . querySelector ( 'tpen-quicktype-editor-dialog' )
50- if ( dialog ) {
51- const quicktype = TPEN . activeProject ?. interfaces ?. quicktype ?? [ ]
52- dialog . open ( quicktype )
53- }
54- } )
57+ if ( editCharBtn ) {
58+ this . cleanup . onElement ( editCharBtn , 'click' , ( ) => {
59+ const dialog = document . querySelector ( 'tpen-quicktype-editor-dialog' )
60+ if ( dialog ) {
61+ const quicktype = TPEN . activeProject ?. interfaces ?. quicktype ?? [ ]
62+ dialog . open ( quicktype )
63+ }
64+ } )
65+ }
5566
5667 this . shadowRoot . querySelectorAll ( '.char-button' ) . forEach ( btn => {
57- btn . addEventListener ( 'click' , ( ) => {
68+ this . cleanup . onElement ( btn , 'click' , ( ) => {
5869 const char = btn . textContent
5970 const iface = document . querySelector ( '[data-interface-type="transcription"]' )
6071 const block = iface ?. shadowRoot ?. querySelector ( 'tpen-transcription-block' ) ?. shadowRoot
@@ -283,14 +294,23 @@ class QuickTypeTool extends HTMLElement {
283294
284295customElements . define ( 'tpen-quicktype-tool' , QuickTypeTool )
285296
297+ /**
298+ * QuickTypeToolButton - Toggle button for the QuickType panel.
299+ * Requires TOOL ANY view access.
300+ * @element tpen-quicktype-tool-button
301+ */
286302class QuickTypeToolButton extends HTMLElement {
303+ /** @type {CleanupRegistry } Registry for cleanup handlers */
304+ cleanup = new CleanupRegistry ( )
305+
287306 constructor ( ) {
288307 super ( )
289308 this . attachShadow ( { mode : "open" } )
290309 }
291310
292311 connectedCallback ( ) {
293- this . _unsubProject = onProjectReady ( this , this . authgate )
312+ TPEN . attachAuthentication ( this )
313+ this . _unsubProject = onProjectReady ( this , this . authgate . bind ( this ) )
294314 }
295315
296316 authgate ( ) {
@@ -304,12 +324,13 @@ class QuickTypeToolButton extends HTMLElement {
304324
305325 disconnectedCallback ( ) {
306326 try { this . _unsubProject ?. ( ) } catch { }
327+ this . cleanup . run ( )
307328 }
308329
309330 addEventListeners ( ) {
310331 const quicktypeBtn = this . shadowRoot . querySelector ( '.quicktype-btn' )
311332
312- quicktypeBtn . addEventListener ( 'click' , ( ) => {
333+ this . cleanup . onElement ( quicktypeBtn , 'click' , ( ) => {
313334 const iface = document . querySelector ( '[data-interface-type="transcription"]' )
314335 const charPanel = iface ?. shadowRoot
315336 ?. querySelector ( 'tpen-workspace-tools' ) ?. shadowRoot
0 commit comments