Add typing for QR API global
| @@ -1,6 +1,7 @@ | |||
| 1 | import libs from './lib'; | 1 | import libs from './lib'; |
| 2 | import getContext from './scripts/st-context'; | 2 | import getContext from './scripts/st-context'; |
| 3 | import { power_user } from './scripts/power-user'; | 3 | import { power_user } from './scripts/power-user'; |
| 4 | import { QuickReplyApi } from './scripts/extensions/quick-reply/api/QuickReplyApi'; | ||
| 4 | 5 | ||
| 5 | declare global { | 6 | declare global { |
| 6 | // Custom types | 7 | // Custom types |
| @@ -13,6 +14,7 @@ declare global { | |||
| 13 | 14 | ||
| 14 | declare var pdfjsLib; | 15 | declare var pdfjsLib; |
| 15 | declare var ePub; | 16 | declare var ePub; |
| 17 | declare var quickReplyApi: QuickReplyApi; | ||
| 16 | 18 | ||
| 17 | declare var SillyTavern: { | 19 | declare var SillyTavern: { |
| 18 | getContext(): typeof getContext; | 20 | getContext(): typeof getContext; |
| @@ -181,7 +181,7 @@ const init = async () => { | |||
| 181 | 181 | ||
| 182 | eventSource.on(event_types.APP_READY, async()=>await finalizeInit()); | 182 | eventSource.on(event_types.APP_READY, async()=>await finalizeInit()); |
| 183 | 183 | ||
| 184 | window['quickReplyApi'] = quickReplyApi; | 184 | globalThis.quickReplyApi = quickReplyApi; |
| 185 | }; | 185 | }; |
| 186 | const finalizeInit = async () => { | 186 | const finalizeInit = async () => { |
| 187 | debug('executing startup'); | 187 | debug('executing startup'); |
| @@ -516,12 +516,14 @@ export class SlashCommandParser { | |||
| 516 | ?? [] | 516 | ?? [] |
| 517 | ; | 517 | ; |
| 518 | try { | 518 | try { |
| 519 | const qrApi = (await import('../extensions/quick-reply/index.js')).quickReplyApi; | 519 | if ('quickReplyApi' in globalThis) { |
| 520 | const qrApi = globalThis.quickReplyApi; | ||
| 520 | options.push(...qrApi.listSets() | 521 | options.push(...qrApi.listSets() |
| 521 | .map(set=>qrApi.listQuickReplies(set).map(qr=>`${set}.${qr}`)) | 522 | .map(set=>qrApi.listQuickReplies(set).map(qr=>`${set}.${qr}`)) |
| 522 | .flat() | 523 | .flat() |
| 523 | .map(qr=>new SlashCommandQuickReplyAutoCompleteOption(qr)), | 524 | .map(qr=>new SlashCommandQuickReplyAutoCompleteOption(qr)), |
| 524 | ); | 525 | ); |
| 526 | } | ||
| 525 | } catch { /* empty */ } | 527 | } catch { /* empty */ } |
| 526 | const result = new AutoCompleteNameResult( | 528 | const result = new AutoCompleteNameResult( |
| 527 | executor.unnamedArgumentList[0]?.value.toString(), | 529 | executor.unnamedArgumentList[0]?.value.toString(), |
| @@ -3433,9 +3433,8 @@ function getAutomationIdCallback(data) { | |||
| 3433 | } | 3433 | } |
| 3434 | } | 3434 | } |
| 3435 | 3435 | ||
| 3436 | if ('quickReplyApi' in window) { | 3436 | if ('quickReplyApi' in globalThis) { |
| 3437 | // @ts-ignore | 3437 | for (const automationId of globalThis.quickReplyApi.listAutomationIds()) { |
| 3438 | for (const automationId of window['quickReplyApi'].listAutomationIds()) { | ||
| 3439 | ids.add(String(automationId)); | 3438 | ids.add(String(automationId)); |
| 3440 | } | 3439 | } |
| 3441 | } | 3440 | } |