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