@mostfeatured/dbi 0.2.35 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAgB,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAQ7G,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAcpJ,MAAM,MAAM,2BAA2B,CAAC,UAAU,SAAS,cAAc,IAAI,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,sBAAsB,GAAG,gBAAgB,GAAG,cAAc,CAAC,GAAG;IAC/P;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,8BAA8B,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;CACvE,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAA;AAED,MAAM,WAAW,+BAA+B;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAA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AC,UAAU,CAAC,EAAE,IAAI,EAAE,2BAA2B,CAAC,UAAU,CAAC;YAuCjE,oBAAoB;YAMpB,cAAc;IA6C5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA2H3B;;OAEG;YACW,sBAAsB;IAoHpC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAQ;IAEtC,MAAM,CAAC,GAAG,GAAE,8BAAmC,GAAG,OAAO,CAAC,GAAG,CAAC;IA+B7E;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,GAAE,+BAAoC,GAAG,OAAO,CAAC,8BAA8B,CAAC;IA4H/G;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO;IAsBzD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,mBAAmB;IA2B3B;;OAEG;IACH,OAAO,CAAC,uCAAuC;IAwB/C;;OAEG;IACH,OAAO,CAAC,4BAA4B;IA+DpC;;;;;OAKG;IACH,UAAU,IAAI,MAAM;IAapB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAM;CACvB"}
|
|
@@ -109,7 +109,7 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
if (handlerInfo) {
|
|
112
|
-
this._executeElementHandler(ctx, handlerInfo, handlerData);
|
|
112
|
+
await this._executeElementHandler(ctx, handlerInfo, handlerData);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -219,7 +219,7 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
|
|
|
219
219
|
/**
|
|
220
220
|
* Execute an element handler (button, select, etc.)
|
|
221
221
|
*/
|
|
222
|
-
_executeElementHandler(ctx, handlerInfo, handlerData) {
|
|
222
|
+
async _executeElementHandler(ctx, handlerInfo, handlerData) {
|
|
223
223
|
// Extract current state from handlerData (refs that were passed)
|
|
224
224
|
// The second element in data array contains the current state
|
|
225
225
|
const currentState = handlerData[0] || {};
|
|
@@ -272,7 +272,23 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
|
|
|
272
272
|
// Bind 'this' to the DBIHTMLComponentsV2 instance so handlers can use this.toJSON()
|
|
273
273
|
// Pass wrappedCtx so handlers use the proxy-wrapped ctx that tracks interaction calls
|
|
274
274
|
// This ensures __asyncInteractionCalled__ flag is set when handler calls ctx.interaction.reply() etc.
|
|
275
|
-
handlerFn.call(this, handlerContext.wrappedCtx, ...handlerData.slice(1));
|
|
275
|
+
const result = handlerFn.call(this, handlerContext.wrappedCtx, ...handlerData.slice(1));
|
|
276
|
+
// If handler returns a Promise (async handler), we need to handle it specially
|
|
277
|
+
if (result && typeof result.then === 'function') {
|
|
278
|
+
// Async handler detected - defer the interaction if not already deferred
|
|
279
|
+
// This prevents "interaction already acknowledged" errors for long-running handlers
|
|
280
|
+
const interaction = ctx.interaction;
|
|
281
|
+
if (interaction && !interaction.deferred && !interaction.replied) {
|
|
282
|
+
try {
|
|
283
|
+
await interaction.deferUpdate();
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
// Ignore if defer fails (might already be deferred)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// Now await the async handler
|
|
290
|
+
await result;
|
|
291
|
+
}
|
|
276
292
|
}
|
|
277
293
|
finally {
|
|
278
294
|
// Always reset handler execution flag
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/index.ts"],"names":[],"mappings":";;;;AAEA,mDAA6G;AAC7G,qCAAiD;AACjD,qDAA4G;AAC5G,iDAAkG;AAClG,+CAAoJ;AACpJ,oDAAoB;AAEpB,oDAAoD;AACpD,6CAAoJ;AA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DBI } from \"../../../DBI\";\r\nimport { DBIBaseInteraction, DBIRateLimit, IDBIBaseExecuteCtx, TDBIReferencedData } from \"../../Interaction\";\r\nimport { parseHTMLComponentsV2 } from \"./parser\";\r\nimport { renderSvelteComponent, renderSvelteComponentFromFile, SvelteRenderResult } from \"./svelteRenderer\";\r\nimport { parseSvelteComponent, createHandlerContext, HandlerContextResult } from \"./svelteParser\";\r\nimport { createEnhancedError, isComponentValidationError, parseDiscordComponentError, ComponentErrorInfo, ParsedDiscordError } from \"./errorParser\";\r\nimport fs from \"fs\";\r\n\r\n// Re-export error parser utilities for external use\r\nexport { createEnhancedError, isComponentValidationError, parseDiscordComponentError, ComponentErrorInfo, ParsedDiscordError } from \"./errorParser\";\r\n\r\n/**\r\n * Parse Discord API error and provide helpful context about which HTML element caused the error\r\n * Uses the enhanced error parser for detailed, developer-friendly messages\r\n */\r\nfunction parseDiscordAPIError(error: any, source?: string, componentName?: string, components?: any[]): Error {\r\n // Use the new enhanced error parser\r\n if (isComponentValidationError(error)) {\r\n return createEnhancedError(error, components, source, componentName);\r\n }\r\n return error;\r\n}\r\n\r\nexport type TDBIHTMLComponentsV2Omitted<TNamespace extends NamespaceEnums> = Omit<DBIHTMLComponentsV2<TNamespace>, \"type\" | \"dbi\" | \"toJSON\" | \"description\" | \"send\" | \"destroy\" | \"destroyAll\" | \"__lastRenderModals__\" | \"_pendingModals\" | \"_initPromise\"> & {\r\n /**\r\n * Use 'svelte' for Svelte 5 components, 'eta' for Eta templates (default)\r\n */\r\n mode?: 'svelte' | 'eta';\r\n /**\r\n * Callback executed when the component interaction is triggered\r\n */\r\n onExecute?: (ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) => void;\r\n};\r\n\r\nexport type TDBIHTMLComponentsV2ToJSONArgs = {\r\n data?: Record<string, any>;\r\n}\r\n\r\nexport interface TDBIHTMLComponentsV2SendOptions {\r\n data?: Record<string, any>;\r\n flags?: string[];\r\n content?: string;\r\n ephemeral?: boolean;\r\n /** If true, uses interaction.reply(). If false or unset, auto-detects based on target type */\r\n reply?: boolean;\r\n /** If true, uses interaction.followUp() instead of reply() */\r\n followUp?: boolean;\r\n}\r\n\r\n/**\r\n * Result object returned by send() method\r\n * Includes the Discord message and a render() method for manual re-rendering\r\n */\r\nexport interface TDBIHTMLComponentsV2SendResult {\r\n /** The Discord message object returned from send/reply/followUp */\r\n message: any;\r\n /** The data object with reactive state (includes $ref) */\r\n data: Record<string, any>;\r\n /** Manually trigger a re-render of the component */\r\n render: () => Promise<void>;\r\n /** Destroy this component instance (clears intervals, timers, removes ref) */\r\n destroy: () => boolean;\r\n}\r\n\r\nexport interface IDBIHTMLComponentsV2ExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {\r\n data: TDBIReferencedData[];\r\n}\r\n\r\nexport class DBIHTMLComponentsV2<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {\r\n template?: string;\r\n file?: string;\r\n mode: 'svelte' | 'eta' = 'eta';\r\n private svelteComponentInfo: any = null;\r\n private _userOnExecute?: (ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) => void;\r\n /** The directory of the source file (used for resolving relative imports) */\r\n private _sourceDir?: string;\r\n\r\n // Store handler contexts per ref for lifecycle management\r\n // Key: ref id, Value: handlerContext with lifecycle hooks\r\n private _activeContexts: Map<string, any> = new Map();\r\n\r\n // Store pending modal promises for await showModal() support\r\n // Key: modal customId, Value: { resolve, reject, originalMessage, data } \r\n _pendingModals: Map<string, {\r\n resolve: (result: any) => void;\r\n reject: (error: any) => void;\r\n originalMessage?: any;\r\n data?: any;\r\n }> = new Map();\r\n\r\n // Track initialization promise\r\n private _initPromise: Promise<void> | null = null;\r\n\r\n constructor(dbi: DBI<TNamespace>, args: TDBIHTMLComponentsV2Omitted<TNamespace>) {\r\n // Store user's onExecute callback before passing to super\r\n const userOnExecute = (args as any).onExecute;\r\n\r\n // Remove onExecute from args so it doesn't override the class method\r\n const argsWithoutOnExecute = { ...args };\r\n delete (argsWithoutOnExecute as any).onExecute;\r\n\r\n super(dbi, {\r\n ...(argsWithoutOnExecute as any),\r\n type: \"HTMLComponentsV2\",\r\n });\r\n this.template = args.template || (args.file ? fs.readFileSync(args.file, \"utf-8\") : undefined);\r\n this.file = args.file;\r\n this.name = args.name;\r\n this.handlers = args.handlers || [];\r\n this.mode = args.mode || 'eta';\r\n\r\n // Store source directory for resolving relative imports in Svelte components\r\n if (this.file) {\r\n const path = require(\"path\");\r\n this._sourceDir = path.dirname(path.resolve(this.file));\r\n }\r\n\r\n // Store user's onExecute callback if provided\r\n if (userOnExecute) {\r\n this._userOnExecute = userOnExecute;\r\n }\r\n\r\n // Pre-extract Svelte handlers at registration time (lazy loaded)\r\n if (this.mode === 'svelte' && this.template) {\r\n // Store the promise so we can await it in _handleExecute\r\n this._initPromise = this._initSvelteComponent();\r\n }\r\n\r\n // Re-assign onExecute method after super() call because parent class sets it to undefined\r\n this.onExecute = this._handleExecute.bind(this);\r\n }\r\n\r\n private async _initSvelteComponent() {\r\n if (this.template && !this.svelteComponentInfo) {\r\n this.svelteComponentInfo = await parseSvelteComponent(this.template);\r\n }\r\n }\r\n\r\n private async _handleExecute(ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) {\r\n // Wait for Svelte component initialization if not yet completed\r\n if (this._initPromise) {\r\n await this._initPromise;\r\n }\r\n\r\n // Call user's onExecute callback first if provided\r\n if (this._userOnExecute) {\r\n this._userOnExecute(ctx);\r\n }\r\n\r\n // If using Svelte mode, find and execute the handler\r\n if (this.mode === 'svelte' && this.svelteComponentInfo) {\r\n const [elementName, ...handlerData] = ctx.data;\r\n\r\n if (typeof elementName === 'string') {\r\n // Check if this is a modal submit (elementName is the modal id)\r\n const modalHandlerInfo = this.svelteComponentInfo.modalHandlers.get(elementName);\r\n\r\n if (modalHandlerInfo) {\r\n // This is a modal submit - execute the onsubmit handler (or just resolve promise if no handler)\r\n this._executeModalSubmit(ctx, elementName, modalHandlerInfo.onsubmitHandler, handlerData);\r\n return;\r\n }\r\n\r\n // Find the handler info for this element (button, select, etc.)\r\n let handlerInfo = this.svelteComponentInfo.handlers.get(elementName);\r\n\r\n // If not found by exact match, try prefix matching for dynamic names (from {#each})\r\n if (!handlerInfo) {\r\n for (const [key, info] of this.svelteComponentInfo.handlers) {\r\n if (info.isDynamicName && elementName.startsWith(key + '_')) {\r\n handlerInfo = info;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (handlerInfo) {\r\n this._executeElementHandler(ctx, handlerInfo, handlerData);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Execute a modal submit handler\r\n */\r\n private _executeModalSubmit(\r\n ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>,\r\n modalId: string,\r\n handlerName: string | undefined,\r\n handlerData: any[]\r\n ) {\r\n // Extract current state from handlerData (refs that were passed)\r\n const currentState = handlerData[0] || {} as Record<string, any>;\r\n\r\n // Get ref id for lifecycle tracking (if available)\r\n const refId = (currentState as any)?.$ref || null;\r\n\r\n // Extract all field values from modal interaction (text inputs, selects, file uploads, etc.)\r\n const modalInteraction = ctx.interaction as any;\r\n const fields = this._extractModalFields(modalInteraction);\r\n\r\n // Check if there's a pending promise for this modal (from await showModal())\r\n // Use the modal's customId to find the pending promise\r\n const pendingKey = modalInteraction.customId;\r\n const pendingModal = this._pendingModals.get(pendingKey);\r\n\r\n if (pendingModal) {\r\n // Get the original message that was stored when showModal was called\r\n const originalMessage = pendingModal.originalMessage;\r\n const storedData = pendingModal.data || currentState;\r\n\r\n // Create a rerender function that can update the original message after modal submit\r\n const component = this;\r\n const rerender = async () => {\r\n // Re-render the component with current data\r\n const components = await component.toJSON({ data: storedData });\r\n\r\n // For ephemeral messages, we need to use the modal interaction's editReply\r\n // For non-ephemeral, we can use message.edit directly\r\n try {\r\n // First try using modal interaction's editReply (works for ephemeral)\r\n if (modalInteraction.deferred || modalInteraction.replied) {\r\n await modalInteraction.editReply({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n return;\r\n }\r\n } catch (err: any) {\r\n // If editReply fails, fall back to message.edit\r\n console.warn('[DBI-Svelte] editReply failed, trying message.edit:', err.message);\r\n }\r\n\r\n // Fall back to original message edit (non-ephemeral)\r\n if (originalMessage && originalMessage.edit) {\r\n try {\r\n await originalMessage.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n } catch (err: any) {\r\n console.warn('[DBI-Svelte] Failed to rerender after modal:', err.message || err);\r\n }\r\n } else {\r\n console.warn('[DBI-Svelte] Cannot rerender: No valid method available');\r\n }\r\n };\r\n\r\n // Resolve the promise with fields, interaction, ctx, and rerender function\r\n pendingModal.resolve({\r\n fields,\r\n interaction: modalInteraction,\r\n ctx: ctx,\r\n rerender\r\n });\r\n this._pendingModals.delete(pendingKey);\r\n }\r\n\r\n // If no onsubmit handler defined, just return (promise-based usage)\r\n if (!handlerName) {\r\n return;\r\n }\r\n\r\n // Create handler context for modal submit\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo!.scriptContent,\r\n typeof currentState === 'object' ? currentState : {},\r\n this,\r\n ctx,\r\n this._sourceDir,\r\n this.svelteComponentInfo!.inlineHandlers\r\n );\r\n\r\n const handlerFn = handlerContext.handlers[handlerName];\r\n\r\n if (handlerFn && typeof handlerFn === 'function') {\r\n try {\r\n // Store context for lifecycle management\r\n if (refId) {\r\n const existingContext = this._activeContexts.get(refId);\r\n if (existingContext && existingContext.destroyCallbacks) {\r\n handlerContext.destroyCallbacks.push(...existingContext.destroyCallbacks);\r\n }\r\n this._activeContexts.set(refId, handlerContext);\r\n }\r\n\r\n handlerContext.setInHandler(true);\r\n\r\n try {\r\n // Call handler with ctx and fields object\r\n handlerFn.call(this, handlerContext.wrappedCtx, fields, ...handlerData.slice(1));\r\n } finally {\r\n handlerContext.setInHandler(false);\r\n }\r\n\r\n handlerContext.runEffects();\r\n\r\n if (handlerContext.hasPendingRender()) {\r\n handlerContext.flushRender();\r\n }\r\n } catch (error) {\r\n // Re-throw the error so it's visible to the developer\r\n console.error(`[DBI-Svelte] Modal handler \"${handlerName}\" failed:`, error);\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Execute an element handler (button, select, etc.)\r\n */\r\n private _executeElementHandler(\r\n ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>,\r\n handlerInfo: any,\r\n handlerData: any[]\r\n ) {\r\n // Extract current state from handlerData (refs that were passed)\r\n // The second element in data array contains the current state\r\n const currentState = handlerData[0] || {} as Record<string, any>;\r\n\r\n // Get ref id for lifecycle tracking (if available)\r\n const refId = (currentState as any)?.$ref || null;\r\n\r\n // Check if this is first execution for this ref\r\n const isFirstExecution = refId && !this._activeContexts.has(refId);\r\n\r\n // Get existing context if any (to preserve lifecycle callbacks like intervals)\r\n const existingContext = refId ? this._activeContexts.get(refId) : null;\r\n\r\n // Create a NEW handler context for each execution with the current state\r\n // This ensures each interaction has its own isolated state\r\n // Pass 'this' so handlers can access component methods like toJSON()\r\n // Pass ctx so handlers can access ctx.interaction, ctx.data, ctx.locale, etc.\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo!.scriptContent,\r\n typeof currentState === 'object' ? currentState : {},\r\n this,\r\n ctx,\r\n this._sourceDir,\r\n this.svelteComponentInfo!.inlineHandlers\r\n );\r\n\r\n const handlerFn = handlerContext.handlers[handlerInfo.handlerName];\r\n\r\n if (handlerFn && typeof handlerFn === 'function') {\r\n try {\r\n // Store context for lifecycle management\r\n if (refId) {\r\n // If there's an existing context, transfer its destroy callbacks to the new context\r\n // This preserves intervals/timers created in onMount\r\n if (existingContext && existingContext.destroyCallbacks) {\r\n // Merge existing destroy callbacks (don't run them!)\r\n handlerContext.destroyCallbacks.push(...existingContext.destroyCallbacks);\r\n }\r\n\r\n this._activeContexts.set(refId, handlerContext);\r\n\r\n // Wrap $unRef to call onDestroy when ref is deleted (only wrap once)\r\n const stateObj = currentState as any;\r\n if (stateObj.$unRef && !stateObj.__unRefWrapped__) {\r\n const originalUnRef = stateObj.$unRef.bind(stateObj);\r\n stateObj.$unRef = () => {\r\n // Run destroy callbacks before unref\r\n const ctx = this._activeContexts.get(refId);\r\n if (ctx && ctx.runDestroy) {\r\n ctx.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n return originalUnRef();\r\n };\r\n stateObj.__unRefWrapped__ = true;\r\n }\r\n }\r\n\r\n // Run onMount callbacks only on first execution\r\n if (isFirstExecution && handlerContext.runMount) {\r\n handlerContext.runMount();\r\n }\r\n\r\n // Mark that we're inside handler execution (prevents auto-render during handler)\r\n handlerContext.setInHandler(true);\r\n\r\n try {\r\n // Bind 'this' to the DBIHTMLComponentsV2 instance so handlers can use this.toJSON()\r\n // Pass wrappedCtx so handlers use the proxy-wrapped ctx that tracks interaction calls\r\n // This ensures __asyncInteractionCalled__ flag is set when handler calls ctx.interaction.reply() etc.\r\n handlerFn.call(this, handlerContext.wrappedCtx, ...handlerData.slice(1));\r\n } finally {\r\n // Always reset handler execution flag\r\n handlerContext.setInHandler(false);\r\n }\r\n\r\n // Run effects after handler execution (state may have changed)\r\n handlerContext.runEffects();\r\n\r\n // If there are pending data changes and no interaction method was called,\r\n // flush the render now (synchronously uses interaction.update)\r\n if (handlerContext.hasPendingRender()) {\r\n handlerContext.flushRender();\r\n }\r\n } catch (error) {\r\n // Re-throw the error so it's visible to the developer\r\n console.error(`[DBI-Svelte] Handler \"${handlerInfo.handlerName}\" failed:`, error);\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n // Store last render's modals for showModal() to access\r\n // Note: Used internally by handler context, not truly private\r\n __lastRenderModals__: Map<string, any> | null = null;\r\n\r\n override async toJSON(arg: TDBIHTMLComponentsV2ToJSONArgs = {}): Promise<any> {\r\n if (this.mode === 'svelte' && this.template) {\r\n // Render Svelte component\r\n const result = await renderSvelteComponent(\r\n this.dbi as any,\r\n this.template,\r\n this.name,\r\n {\r\n data: arg.data,\r\n ttl: this.ttl\r\n }\r\n );\r\n\r\n // Store modals for showModal() to access\r\n this.__lastRenderModals__ = result.modals;\r\n\r\n return result.components;\r\n } else {\r\n // Use Eta template parsing (default)\r\n return parseHTMLComponentsV2(\r\n this.dbi as any,\r\n this.template!,\r\n this.name,\r\n {\r\n data: arg.data,\r\n ttl: this.ttl\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Send the component to an interaction or channel and initialize lifecycle hooks (onMount)\r\n * This is the recommended way to send Svelte components with intervals/timers\r\n * \r\n * @param target - Discord interaction or channel to send to\r\n * @param options - Send options including data, flags, content\r\n * \r\n * @example\r\n * ```ts\r\n * const showcase = dbi.interaction(\"product-showcase\");\r\n * \r\n * // Send as interaction reply\r\n * await showcase.send(interaction, { data: { count: 0 } });\r\n * \r\n * // Send to a channel directly\r\n * const result = await showcase.send(channel, { data: { count: 0 } });\r\n * \r\n * // Send as followUp (if already replied)\r\n * const result = await showcase.send(interaction, { data: { count: 0 }, followUp: true });\r\n * \r\n * // Manual re-render from outside\r\n * await result.render();\r\n * ```\r\n */\r\n async send(target: any, options: TDBIHTMLComponentsV2SendOptions = {}): Promise<TDBIHTMLComponentsV2SendResult> {\r\n // Wait for Svelte component initialization if not yet completed\r\n if (this._initPromise) {\r\n await this._initPromise;\r\n }\r\n\r\n const { data = {}, flags = [\"IsComponentsV2\"], content, ephemeral, reply, followUp } = options;\r\n\r\n // Render components (toJSON is async) - this also creates $ref in data if not present\r\n const components = await this.toJSON({ data });\r\n\r\n // Build message options\r\n const messageOptions: any = { components, flags };\r\n if (content) messageOptions.content = content;\r\n if (ephemeral) messageOptions.flags = [...flags, \"Ephemeral\"];\r\n\r\n // Detect target type and send accordingly\r\n let message: any;\r\n const isInteraction = target.reply && target.user; // Interactions have both reply method and user property\r\n const isChannel = target.send && !target.user; // Channels have send but no user\r\n\r\n try {\r\n if (isInteraction) {\r\n if (followUp) {\r\n message = await target.followUp(messageOptions);\r\n } else {\r\n message = await target.reply(messageOptions);\r\n }\r\n } else if (isChannel) {\r\n message = await target.send(messageOptions);\r\n } else {\r\n throw new Error(\"Invalid target: must be an interaction or channel\");\r\n }\r\n } catch (error: any) {\r\n // Check if it's a Discord API error and enhance it with helpful context\r\n if (error.code || error.rawError || (error.message && error.message.includes('Invalid Form Body'))) {\r\n const source = this.file ? fs.readFileSync(this.file, 'utf-8') : this.template;\r\n throw parseDiscordAPIError(error, source, this.name, components);\r\n }\r\n throw error;\r\n }\r\n\r\n // If Svelte mode, create initial handler context and run onMount\r\n // After toJSON, data.$ref is guaranteed to exist (created in renderSvelteComponent)\r\n if (this.mode === 'svelte' && this.svelteComponentInfo && data.$ref) {\r\n const refId = data.$ref;\r\n\r\n // Create handler context with a fake ctx that has the message\r\n const fakeCtx = {\r\n interaction: {\r\n replied: true,\r\n deferred: false,\r\n message: message,\r\n }\r\n };\r\n\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo.scriptContent,\r\n data,\r\n this,\r\n fakeCtx,\r\n this._sourceDir,\r\n this.svelteComponentInfo.inlineHandlers\r\n );\r\n\r\n // Store the context for lifecycle management\r\n this._activeContexts.set(refId, handlerContext);\r\n\r\n // Wrap $unRef to call onDestroy when ref is deleted\r\n if (data.$unRef) {\r\n const originalUnRef = data.$unRef.bind(data);\r\n data.$unRef = () => {\r\n if (handlerContext.runDestroy) {\r\n handlerContext.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n return originalUnRef();\r\n };\r\n }\r\n\r\n // Run onMount callbacks\r\n handlerContext.runMount();\r\n\r\n // Run initial effects\r\n handlerContext.runEffects();\r\n\r\n // Return result object with render() method for manual re-rendering\r\n const component = this;\r\n return {\r\n message,\r\n data,\r\n render: async () => {\r\n // Run pre-render callbacks (async)\r\n await handlerContext.runPreRender();\r\n\r\n // Re-render the component\r\n const components = await component.toJSON({ data });\r\n await message.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n\r\n // Run after-render callbacks\r\n handlerContext.runAfterRender();\r\n },\r\n destroy: () => component.destroy(data)\r\n } as TDBIHTMLComponentsV2SendResult;\r\n }\r\n\r\n // For non-Svelte mode, return simple result object\r\n return {\r\n message,\r\n data,\r\n render: async () => {\r\n const components = await this.toJSON({ data });\r\n await message.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n },\r\n destroy: () => this.destroy(data)\r\n } as TDBIHTMLComponentsV2SendResult;\r\n }\r\n\r\n /**\r\n * Destroy a component instance by ref ID or data object\r\n * This runs onDestroy callbacks (clears intervals/timers) and removes the ref\r\n * \r\n * @param refOrData - Either a ref ID string or the data object with $ref\r\n * @returns true if destroyed, false if not found\r\n * \r\n * @example\r\n * ```ts\r\n * // Destroy by data object\r\n * showcase.destroy(data);\r\n * \r\n * // Destroy by ref ID\r\n * showcase.destroy(data.$ref);\r\n * \r\n * // Destroy all active instances of this component\r\n * showcase.destroyAll();\r\n * ```\r\n */\r\n destroy(refOrData: string | Record<string, any>): boolean {\r\n const refId = typeof refOrData === 'string' ? refOrData : refOrData?.$ref;\r\n\r\n if (!refId) {\r\n return false;\r\n }\r\n\r\n const context = this._activeContexts.get(refId);\r\n if (context) {\r\n // Run destroy callbacks (clears intervals, timers, etc.)\r\n if (context.runDestroy) {\r\n context.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n }\r\n\r\n // Also delete from DBI refs store\r\n this.dbi.data.refs.delete(refId);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Extract all field values from a modal interaction\r\n * Supports text inputs, select menus (string, user, role, mentionable, channel), and file uploads\r\n * \r\n * Returns an object where keys are the custom_id of each component and values are:\r\n * - For text inputs: string value\r\n * - For string selects: string[] of selected values\r\n * - For user selects: string[] of user IDs\r\n * - For role selects: string[] of role IDs\r\n * - For mentionable selects: { users: string[], roles: string[] }\r\n * - For channel selects: string[] of channel IDs\r\n * - For file uploads: attachment objects array\r\n */\r\n private _extractModalFields(modalInteraction: any): Record<string, any> {\r\n const fields: Record<string, any> = {};\r\n\r\n // Handle classic text input fields via ModalSubmitFields\r\n if (modalInteraction.fields && modalInteraction.fields.fields) {\r\n for (const [customId, field] of modalInteraction.fields.fields) {\r\n // Text input - field.value is the string\r\n // For select menus, value might be an array\r\n fields[customId] = field.values || field.value;\r\n }\r\n }\r\n\r\n // Handle new modal components from interaction.data.components\r\n // The new modal structure uses Label wrappers with nested components\r\n const data = modalInteraction.data || (modalInteraction as any).data;\r\n if (data && data.components) {\r\n this._extractFieldsFromComponents(data.components, fields);\r\n }\r\n\r\n // Also check for components directly on the interaction (some Discord.js versions)\r\n if (modalInteraction.components && Array.isArray(modalInteraction.components)) {\r\n this._extractFieldsFromInteractionComponents(modalInteraction.components, fields);\r\n }\r\n\r\n return fields;\r\n }\r\n\r\n /**\r\n * Extract fields from Discord.js style interaction components (ActionRow objects)\r\n */\r\n private _extractFieldsFromInteractionComponents(components: any[], fields: Record<string, any>) {\r\n for (const row of components) {\r\n // ActionRow has components property\r\n const rowComponents = row.components || [];\r\n for (const component of rowComponents) {\r\n const customId = component.customId || component.custom_id || component.id;\r\n if (!customId) continue;\r\n\r\n // Check component type\r\n const type = component.type;\r\n\r\n // Text Input (type 4)\r\n if (type === 4 || component.value !== undefined) {\r\n fields[customId] = component.value || '';\r\n }\r\n\r\n // Select menus (types 3, 5, 6, 7, 8) - check for values array\r\n if (component.values !== undefined) {\r\n fields[customId] = component.values;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Recursively extract field values from component structure\r\n */\r\n private _extractFieldsFromComponents(components: any[], fields: Record<string, any>) {\r\n for (const component of components) {\r\n const type = component.type;\r\n // Support both custom_id and id for backward compatibility\r\n const customId = component.custom_id || component.id;\r\n\r\n // Type 18 = Label/Field - can have nested component or components\r\n if (type === 18) {\r\n if (component.component) {\r\n this._extractFieldsFromComponents([component.component], fields);\r\n }\r\n if (component.components) {\r\n this._extractFieldsFromComponents(component.components, fields);\r\n }\r\n continue;\r\n }\r\n\r\n // Type 1 = Action Row - has nested components array\r\n if (type === 1 && component.components) {\r\n this._extractFieldsFromComponents(component.components, fields);\r\n continue;\r\n }\r\n\r\n if (!customId) continue;\r\n\r\n switch (type) {\r\n case 4: // Text Input\r\n fields[customId] = component.value || '';\r\n break;\r\n\r\n case 3: // String Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 5: // User Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 6: // Role Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 7: // Mentionable Select - can have both users and roles\r\n // Discord returns resolved data for mentionables\r\n fields[customId] = {\r\n values: component.values || [],\r\n users: component.resolved?.users ? Object.keys(component.resolved.users) : [],\r\n roles: component.resolved?.roles ? Object.keys(component.resolved.roles) : []\r\n };\r\n break;\r\n\r\n case 8: // Channel Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 19: // File Upload\r\n // File uploads come through as attachments\r\n fields[customId] = component.attachments || [];\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Destroy all active instances of this component\r\n * Useful for cleanup when the bot shuts down or component is unloaded\r\n * \r\n * @returns Number of instances destroyed\r\n */\r\n destroyAll(): number {\r\n let count = 0;\r\n for (const [refId, context] of this._activeContexts) {\r\n if (context.runDestroy) {\r\n context.runDestroy();\r\n }\r\n this.dbi.data.refs.delete(refId);\r\n count++;\r\n }\r\n this._activeContexts.clear();\r\n return count;\r\n }\r\n\r\n handlers?: any[] = [];\r\n}"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/index.ts"],"names":[],"mappings":";;;;AAEA,mDAA6G;AAC7G,qCAAiD;AACjD,qDAA4G;AAC5G,iDAAkG;AAClG,+CAAoJ;AACpJ,oDAAoB;AAEpB,oDAAoD;AACpD,6CAAoJ;AAA3I,kHAAA,mBAAmB,OAAA;AAAE,yHAAA,0BAA0B,OAAA;AAAE,yHAAA,0BAA0B,OAAA;AAEpF;;;GAGG;AACH,SAAS,oBAAoB,CAAC,KAAU,EAAE,MAAe,EAAE,aAAsB,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AAC,UAAU,EAAE,CAAC;YACvB,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,KAAK,EAAE,CAAC;QACV,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,QAAQ,GAAW,EAAE,CAAC;CACvB;AA/tBD,kDA+tBC","sourcesContent":["import { NamespaceEnums } from \"../../../../generated/namespaceData\";\r\nimport { DBI } from \"../../../DBI\";\r\nimport { DBIBaseInteraction, DBIRateLimit, IDBIBaseExecuteCtx, TDBIReferencedData } from \"../../Interaction\";\r\nimport { parseHTMLComponentsV2 } from \"./parser\";\r\nimport { renderSvelteComponent, renderSvelteComponentFromFile, SvelteRenderResult } from \"./svelteRenderer\";\r\nimport { parseSvelteComponent, createHandlerContext, HandlerContextResult } from \"./svelteParser\";\r\nimport { createEnhancedError, isComponentValidationError, parseDiscordComponentError, ComponentErrorInfo, ParsedDiscordError } from \"./errorParser\";\r\nimport fs from \"fs\";\r\n\r\n// Re-export error parser utilities for external use\r\nexport { createEnhancedError, isComponentValidationError, parseDiscordComponentError, ComponentErrorInfo, ParsedDiscordError } from \"./errorParser\";\r\n\r\n/**\r\n * Parse Discord API error and provide helpful context about which HTML element caused the error\r\n * Uses the enhanced error parser for detailed, developer-friendly messages\r\n */\r\nfunction parseDiscordAPIError(error: any, source?: string, componentName?: string, components?: any[]): Error {\r\n // Use the new enhanced error parser\r\n if (isComponentValidationError(error)) {\r\n return createEnhancedError(error, components, source, componentName);\r\n }\r\n return error;\r\n}\r\n\r\nexport type TDBIHTMLComponentsV2Omitted<TNamespace extends NamespaceEnums> = Omit<DBIHTMLComponentsV2<TNamespace>, \"type\" | \"dbi\" | \"toJSON\" | \"description\" | \"send\" | \"destroy\" | \"destroyAll\" | \"__lastRenderModals__\" | \"_pendingModals\" | \"_initPromise\"> & {\r\n /**\r\n * Use 'svelte' for Svelte 5 components, 'eta' for Eta templates (default)\r\n */\r\n mode?: 'svelte' | 'eta';\r\n /**\r\n * Callback executed when the component interaction is triggered\r\n */\r\n onExecute?: (ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) => void;\r\n};\r\n\r\nexport type TDBIHTMLComponentsV2ToJSONArgs = {\r\n data?: Record<string, any>;\r\n}\r\n\r\nexport interface TDBIHTMLComponentsV2SendOptions {\r\n data?: Record<string, any>;\r\n flags?: string[];\r\n content?: string;\r\n ephemeral?: boolean;\r\n /** If true, uses interaction.reply(). If false or unset, auto-detects based on target type */\r\n reply?: boolean;\r\n /** If true, uses interaction.followUp() instead of reply() */\r\n followUp?: boolean;\r\n}\r\n\r\n/**\r\n * Result object returned by send() method\r\n * Includes the Discord message and a render() method for manual re-rendering\r\n */\r\nexport interface TDBIHTMLComponentsV2SendResult {\r\n /** The Discord message object returned from send/reply/followUp */\r\n message: any;\r\n /** The data object with reactive state (includes $ref) */\r\n data: Record<string, any>;\r\n /** Manually trigger a re-render of the component */\r\n render: () => Promise<void>;\r\n /** Destroy this component instance (clears intervals, timers, removes ref) */\r\n destroy: () => boolean;\r\n}\r\n\r\nexport interface IDBIHTMLComponentsV2ExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {\r\n data: TDBIReferencedData[];\r\n}\r\n\r\nexport class DBIHTMLComponentsV2<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {\r\n template?: string;\r\n file?: string;\r\n mode: 'svelte' | 'eta' = 'eta';\r\n private svelteComponentInfo: any = null;\r\n private _userOnExecute?: (ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) => void;\r\n /** The directory of the source file (used for resolving relative imports) */\r\n private _sourceDir?: string;\r\n\r\n // Store handler contexts per ref for lifecycle management\r\n // Key: ref id, Value: handlerContext with lifecycle hooks\r\n private _activeContexts: Map<string, any> = new Map();\r\n\r\n // Store pending modal promises for await showModal() support\r\n // Key: modal customId, Value: { resolve, reject, originalMessage, data } \r\n _pendingModals: Map<string, {\r\n resolve: (result: any) => void;\r\n reject: (error: any) => void;\r\n originalMessage?: any;\r\n data?: any;\r\n }> = new Map();\r\n\r\n // Track initialization promise\r\n private _initPromise: Promise<void> | null = null;\r\n\r\n constructor(dbi: DBI<TNamespace>, args: TDBIHTMLComponentsV2Omitted<TNamespace>) {\r\n // Store user's onExecute callback before passing to super\r\n const userOnExecute = (args as any).onExecute;\r\n\r\n // Remove onExecute from args so it doesn't override the class method\r\n const argsWithoutOnExecute = { ...args };\r\n delete (argsWithoutOnExecute as any).onExecute;\r\n\r\n super(dbi, {\r\n ...(argsWithoutOnExecute as any),\r\n type: \"HTMLComponentsV2\",\r\n });\r\n this.template = args.template || (args.file ? fs.readFileSync(args.file, \"utf-8\") : undefined);\r\n this.file = args.file;\r\n this.name = args.name;\r\n this.handlers = args.handlers || [];\r\n this.mode = args.mode || 'eta';\r\n\r\n // Store source directory for resolving relative imports in Svelte components\r\n if (this.file) {\r\n const path = require(\"path\");\r\n this._sourceDir = path.dirname(path.resolve(this.file));\r\n }\r\n\r\n // Store user's onExecute callback if provided\r\n if (userOnExecute) {\r\n this._userOnExecute = userOnExecute;\r\n }\r\n\r\n // Pre-extract Svelte handlers at registration time (lazy loaded)\r\n if (this.mode === 'svelte' && this.template) {\r\n // Store the promise so we can await it in _handleExecute\r\n this._initPromise = this._initSvelteComponent();\r\n }\r\n\r\n // Re-assign onExecute method after super() call because parent class sets it to undefined\r\n this.onExecute = this._handleExecute.bind(this);\r\n }\r\n\r\n private async _initSvelteComponent() {\r\n if (this.template && !this.svelteComponentInfo) {\r\n this.svelteComponentInfo = await parseSvelteComponent(this.template);\r\n }\r\n }\r\n\r\n private async _handleExecute(ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>) {\r\n // Wait for Svelte component initialization if not yet completed\r\n if (this._initPromise) {\r\n await this._initPromise;\r\n }\r\n\r\n // Call user's onExecute callback first if provided\r\n if (this._userOnExecute) {\r\n this._userOnExecute(ctx);\r\n }\r\n\r\n // If using Svelte mode, find and execute the handler\r\n if (this.mode === 'svelte' && this.svelteComponentInfo) {\r\n const [elementName, ...handlerData] = ctx.data;\r\n\r\n if (typeof elementName === 'string') {\r\n // Check if this is a modal submit (elementName is the modal id)\r\n const modalHandlerInfo = this.svelteComponentInfo.modalHandlers.get(elementName);\r\n\r\n if (modalHandlerInfo) {\r\n // This is a modal submit - execute the onsubmit handler (or just resolve promise if no handler)\r\n this._executeModalSubmit(ctx, elementName, modalHandlerInfo.onsubmitHandler, handlerData);\r\n return;\r\n }\r\n\r\n // Find the handler info for this element (button, select, etc.)\r\n let handlerInfo = this.svelteComponentInfo.handlers.get(elementName);\r\n\r\n // If not found by exact match, try prefix matching for dynamic names (from {#each})\r\n if (!handlerInfo) {\r\n for (const [key, info] of this.svelteComponentInfo.handlers) {\r\n if (info.isDynamicName && elementName.startsWith(key + '_')) {\r\n handlerInfo = info;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (handlerInfo) {\r\n await this._executeElementHandler(ctx, handlerInfo, handlerData);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Execute a modal submit handler\r\n */\r\n private _executeModalSubmit(\r\n ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>,\r\n modalId: string,\r\n handlerName: string | undefined,\r\n handlerData: any[]\r\n ) {\r\n // Extract current state from handlerData (refs that were passed)\r\n const currentState = handlerData[0] || {} as Record<string, any>;\r\n\r\n // Get ref id for lifecycle tracking (if available)\r\n const refId = (currentState as any)?.$ref || null;\r\n\r\n // Extract all field values from modal interaction (text inputs, selects, file uploads, etc.)\r\n const modalInteraction = ctx.interaction as any;\r\n const fields = this._extractModalFields(modalInteraction);\r\n\r\n // Check if there's a pending promise for this modal (from await showModal())\r\n // Use the modal's customId to find the pending promise\r\n const pendingKey = modalInteraction.customId;\r\n const pendingModal = this._pendingModals.get(pendingKey);\r\n\r\n if (pendingModal) {\r\n // Get the original message that was stored when showModal was called\r\n const originalMessage = pendingModal.originalMessage;\r\n const storedData = pendingModal.data || currentState;\r\n\r\n // Create a rerender function that can update the original message after modal submit\r\n const component = this;\r\n const rerender = async () => {\r\n // Re-render the component with current data\r\n const components = await component.toJSON({ data: storedData });\r\n\r\n // For ephemeral messages, we need to use the modal interaction's editReply\r\n // For non-ephemeral, we can use message.edit directly\r\n try {\r\n // First try using modal interaction's editReply (works for ephemeral)\r\n if (modalInteraction.deferred || modalInteraction.replied) {\r\n await modalInteraction.editReply({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n return;\r\n }\r\n } catch (err: any) {\r\n // If editReply fails, fall back to message.edit\r\n console.warn('[DBI-Svelte] editReply failed, trying message.edit:', err.message);\r\n }\r\n\r\n // Fall back to original message edit (non-ephemeral)\r\n if (originalMessage && originalMessage.edit) {\r\n try {\r\n await originalMessage.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n } catch (err: any) {\r\n console.warn('[DBI-Svelte] Failed to rerender after modal:', err.message || err);\r\n }\r\n } else {\r\n console.warn('[DBI-Svelte] Cannot rerender: No valid method available');\r\n }\r\n };\r\n\r\n // Resolve the promise with fields, interaction, ctx, and rerender function\r\n pendingModal.resolve({\r\n fields,\r\n interaction: modalInteraction,\r\n ctx: ctx,\r\n rerender\r\n });\r\n this._pendingModals.delete(pendingKey);\r\n }\r\n\r\n // If no onsubmit handler defined, just return (promise-based usage)\r\n if (!handlerName) {\r\n return;\r\n }\r\n\r\n // Create handler context for modal submit\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo!.scriptContent,\r\n typeof currentState === 'object' ? currentState : {},\r\n this,\r\n ctx,\r\n this._sourceDir,\r\n this.svelteComponentInfo!.inlineHandlers\r\n );\r\n\r\n const handlerFn = handlerContext.handlers[handlerName];\r\n\r\n if (handlerFn && typeof handlerFn === 'function') {\r\n try {\r\n // Store context for lifecycle management\r\n if (refId) {\r\n const existingContext = this._activeContexts.get(refId);\r\n if (existingContext && existingContext.destroyCallbacks) {\r\n handlerContext.destroyCallbacks.push(...existingContext.destroyCallbacks);\r\n }\r\n this._activeContexts.set(refId, handlerContext);\r\n }\r\n\r\n handlerContext.setInHandler(true);\r\n\r\n try {\r\n // Call handler with ctx and fields object\r\n handlerFn.call(this, handlerContext.wrappedCtx, fields, ...handlerData.slice(1));\r\n } finally {\r\n handlerContext.setInHandler(false);\r\n }\r\n\r\n handlerContext.runEffects();\r\n\r\n if (handlerContext.hasPendingRender()) {\r\n handlerContext.flushRender();\r\n }\r\n } catch (error) {\r\n // Re-throw the error so it's visible to the developer\r\n console.error(`[DBI-Svelte] Modal handler \"${handlerName}\" failed:`, error);\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Execute an element handler (button, select, etc.)\r\n */\r\n private async _executeElementHandler(\r\n ctx: IDBIHTMLComponentsV2ExecuteCtx<TNamespace>,\r\n handlerInfo: any,\r\n handlerData: any[]\r\n ) {\r\n // Extract current state from handlerData (refs that were passed)\r\n // The second element in data array contains the current state\r\n const currentState = handlerData[0] || {} as Record<string, any>;\r\n\r\n // Get ref id for lifecycle tracking (if available)\r\n const refId = (currentState as any)?.$ref || null;\r\n\r\n // Check if this is first execution for this ref\r\n const isFirstExecution = refId && !this._activeContexts.has(refId);\r\n\r\n // Get existing context if any (to preserve lifecycle callbacks like intervals)\r\n const existingContext = refId ? this._activeContexts.get(refId) : null;\r\n\r\n // Create a NEW handler context for each execution with the current state\r\n // This ensures each interaction has its own isolated state\r\n // Pass 'this' so handlers can access component methods like toJSON()\r\n // Pass ctx so handlers can access ctx.interaction, ctx.data, ctx.locale, etc.\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo!.scriptContent,\r\n typeof currentState === 'object' ? currentState : {},\r\n this,\r\n ctx,\r\n this._sourceDir,\r\n this.svelteComponentInfo!.inlineHandlers\r\n );\r\n\r\n const handlerFn = handlerContext.handlers[handlerInfo.handlerName];\r\n\r\n if (handlerFn && typeof handlerFn === 'function') {\r\n try {\r\n // Store context for lifecycle management\r\n if (refId) {\r\n // If there's an existing context, transfer its destroy callbacks to the new context\r\n // This preserves intervals/timers created in onMount\r\n if (existingContext && existingContext.destroyCallbacks) {\r\n // Merge existing destroy callbacks (don't run them!)\r\n handlerContext.destroyCallbacks.push(...existingContext.destroyCallbacks);\r\n }\r\n\r\n this._activeContexts.set(refId, handlerContext);\r\n\r\n // Wrap $unRef to call onDestroy when ref is deleted (only wrap once)\r\n const stateObj = currentState as any;\r\n if (stateObj.$unRef && !stateObj.__unRefWrapped__) {\r\n const originalUnRef = stateObj.$unRef.bind(stateObj);\r\n stateObj.$unRef = () => {\r\n // Run destroy callbacks before unref\r\n const ctx = this._activeContexts.get(refId);\r\n if (ctx && ctx.runDestroy) {\r\n ctx.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n return originalUnRef();\r\n };\r\n stateObj.__unRefWrapped__ = true;\r\n }\r\n }\r\n\r\n // Run onMount callbacks only on first execution\r\n if (isFirstExecution && handlerContext.runMount) {\r\n handlerContext.runMount();\r\n }\r\n\r\n // Mark that we're inside handler execution (prevents auto-render during handler)\r\n handlerContext.setInHandler(true);\r\n\r\n try {\r\n // Bind 'this' to the DBIHTMLComponentsV2 instance so handlers can use this.toJSON()\r\n // Pass wrappedCtx so handlers use the proxy-wrapped ctx that tracks interaction calls\r\n // This ensures __asyncInteractionCalled__ flag is set when handler calls ctx.interaction.reply() etc.\r\n const result = handlerFn.call(this, handlerContext.wrappedCtx, ...handlerData.slice(1));\r\n \r\n // If handler returns a Promise (async handler), we need to handle it specially\r\n if (result && typeof result.then === 'function') {\r\n // Async handler detected - defer the interaction if not already deferred\r\n // This prevents \"interaction already acknowledged\" errors for long-running handlers\r\n const interaction = ctx.interaction as any;\r\n if (interaction && !interaction.deferred && !interaction.replied) {\r\n try {\r\n await interaction.deferUpdate();\r\n } catch (e) {\r\n // Ignore if defer fails (might already be deferred)\r\n }\r\n }\r\n \r\n // Now await the async handler\r\n await result;\r\n }\r\n } finally {\r\n // Always reset handler execution flag\r\n handlerContext.setInHandler(false);\r\n }\r\n\r\n // Run effects after handler execution (state may have changed)\r\n handlerContext.runEffects();\r\n\r\n // If there are pending data changes and no interaction method was called,\r\n // flush the render now (synchronously uses interaction.update)\r\n if (handlerContext.hasPendingRender()) {\r\n handlerContext.flushRender();\r\n }\r\n } catch (error) {\r\n // Re-throw the error so it's visible to the developer\r\n console.error(`[DBI-Svelte] Handler \"${handlerInfo.handlerName}\" failed:`, error);\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n // Store last render's modals for showModal() to access\r\n // Note: Used internally by handler context, not truly private\r\n __lastRenderModals__: Map<string, any> | null = null;\r\n\r\n override async toJSON(arg: TDBIHTMLComponentsV2ToJSONArgs = {}): Promise<any> {\r\n if (this.mode === 'svelte' && this.template) {\r\n // Render Svelte component\r\n const result = await renderSvelteComponent(\r\n this.dbi as any,\r\n this.template,\r\n this.name,\r\n {\r\n data: arg.data,\r\n ttl: this.ttl\r\n }\r\n );\r\n\r\n // Store modals for showModal() to access\r\n this.__lastRenderModals__ = result.modals;\r\n\r\n return result.components;\r\n } else {\r\n // Use Eta template parsing (default)\r\n return parseHTMLComponentsV2(\r\n this.dbi as any,\r\n this.template!,\r\n this.name,\r\n {\r\n data: arg.data,\r\n ttl: this.ttl\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Send the component to an interaction or channel and initialize lifecycle hooks (onMount)\r\n * This is the recommended way to send Svelte components with intervals/timers\r\n * \r\n * @param target - Discord interaction or channel to send to\r\n * @param options - Send options including data, flags, content\r\n * \r\n * @example\r\n * ```ts\r\n * const showcase = dbi.interaction(\"product-showcase\");\r\n * \r\n * // Send as interaction reply\r\n * await showcase.send(interaction, { data: { count: 0 } });\r\n * \r\n * // Send to a channel directly\r\n * const result = await showcase.send(channel, { data: { count: 0 } });\r\n * \r\n * // Send as followUp (if already replied)\r\n * const result = await showcase.send(interaction, { data: { count: 0 }, followUp: true });\r\n * \r\n * // Manual re-render from outside\r\n * await result.render();\r\n * ```\r\n */\r\n async send(target: any, options: TDBIHTMLComponentsV2SendOptions = {}): Promise<TDBIHTMLComponentsV2SendResult> {\r\n // Wait for Svelte component initialization if not yet completed\r\n if (this._initPromise) {\r\n await this._initPromise;\r\n }\r\n\r\n const { data = {}, flags = [\"IsComponentsV2\"], content, ephemeral, reply, followUp } = options;\r\n\r\n // Render components (toJSON is async) - this also creates $ref in data if not present\r\n const components = await this.toJSON({ data });\r\n\r\n // Build message options\r\n const messageOptions: any = { components, flags };\r\n if (content) messageOptions.content = content;\r\n if (ephemeral) messageOptions.flags = [...flags, \"Ephemeral\"];\r\n\r\n // Detect target type and send accordingly\r\n let message: any;\r\n const isInteraction = target.reply && target.user; // Interactions have both reply method and user property\r\n const isChannel = target.send && !target.user; // Channels have send but no user\r\n\r\n try {\r\n if (isInteraction) {\r\n if (followUp) {\r\n message = await target.followUp(messageOptions);\r\n } else {\r\n message = await target.reply(messageOptions);\r\n }\r\n } else if (isChannel) {\r\n message = await target.send(messageOptions);\r\n } else {\r\n throw new Error(\"Invalid target: must be an interaction or channel\");\r\n }\r\n } catch (error: any) {\r\n // Check if it's a Discord API error and enhance it with helpful context\r\n if (error.code || error.rawError || (error.message && error.message.includes('Invalid Form Body'))) {\r\n const source = this.file ? fs.readFileSync(this.file, 'utf-8') : this.template;\r\n throw parseDiscordAPIError(error, source, this.name, components);\r\n }\r\n throw error;\r\n }\r\n\r\n // If Svelte mode, create initial handler context and run onMount\r\n // After toJSON, data.$ref is guaranteed to exist (created in renderSvelteComponent)\r\n if (this.mode === 'svelte' && this.svelteComponentInfo && data.$ref) {\r\n const refId = data.$ref;\r\n\r\n // Create handler context with a fake ctx that has the message\r\n const fakeCtx = {\r\n interaction: {\r\n replied: true,\r\n deferred: false,\r\n message: message,\r\n }\r\n };\r\n\r\n const handlerContext = createHandlerContext(\r\n this.svelteComponentInfo.scriptContent,\r\n data,\r\n this,\r\n fakeCtx,\r\n this._sourceDir,\r\n this.svelteComponentInfo.inlineHandlers\r\n );\r\n\r\n // Store the context for lifecycle management\r\n this._activeContexts.set(refId, handlerContext);\r\n\r\n // Wrap $unRef to call onDestroy when ref is deleted\r\n if (data.$unRef) {\r\n const originalUnRef = data.$unRef.bind(data);\r\n data.$unRef = () => {\r\n if (handlerContext.runDestroy) {\r\n handlerContext.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n return originalUnRef();\r\n };\r\n }\r\n\r\n // Run onMount callbacks\r\n handlerContext.runMount();\r\n\r\n // Run initial effects\r\n handlerContext.runEffects();\r\n\r\n // Return result object with render() method for manual re-rendering\r\n const component = this;\r\n return {\r\n message,\r\n data,\r\n render: async () => {\r\n // Run pre-render callbacks (async)\r\n await handlerContext.runPreRender();\r\n\r\n // Re-render the component\r\n const components = await component.toJSON({ data });\r\n await message.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n\r\n // Run after-render callbacks\r\n handlerContext.runAfterRender();\r\n },\r\n destroy: () => component.destroy(data)\r\n } as TDBIHTMLComponentsV2SendResult;\r\n }\r\n\r\n // For non-Svelte mode, return simple result object\r\n return {\r\n message,\r\n data,\r\n render: async () => {\r\n const components = await this.toJSON({ data });\r\n await message.edit({\r\n components,\r\n flags: [\"IsComponentsV2\"],\r\n });\r\n },\r\n destroy: () => this.destroy(data)\r\n } as TDBIHTMLComponentsV2SendResult;\r\n }\r\n\r\n /**\r\n * Destroy a component instance by ref ID or data object\r\n * This runs onDestroy callbacks (clears intervals/timers) and removes the ref\r\n * \r\n * @param refOrData - Either a ref ID string or the data object with $ref\r\n * @returns true if destroyed, false if not found\r\n * \r\n * @example\r\n * ```ts\r\n * // Destroy by data object\r\n * showcase.destroy(data);\r\n * \r\n * // Destroy by ref ID\r\n * showcase.destroy(data.$ref);\r\n * \r\n * // Destroy all active instances of this component\r\n * showcase.destroyAll();\r\n * ```\r\n */\r\n destroy(refOrData: string | Record<string, any>): boolean {\r\n const refId = typeof refOrData === 'string' ? refOrData : refOrData?.$ref;\r\n\r\n if (!refId) {\r\n return false;\r\n }\r\n\r\n const context = this._activeContexts.get(refId);\r\n if (context) {\r\n // Run destroy callbacks (clears intervals, timers, etc.)\r\n if (context.runDestroy) {\r\n context.runDestroy();\r\n }\r\n this._activeContexts.delete(refId);\r\n }\r\n\r\n // Also delete from DBI refs store\r\n this.dbi.data.refs.delete(refId);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Extract all field values from a modal interaction\r\n * Supports text inputs, select menus (string, user, role, mentionable, channel), and file uploads\r\n * \r\n * Returns an object where keys are the custom_id of each component and values are:\r\n * - For text inputs: string value\r\n * - For string selects: string[] of selected values\r\n * - For user selects: string[] of user IDs\r\n * - For role selects: string[] of role IDs\r\n * - For mentionable selects: { users: string[], roles: string[] }\r\n * - For channel selects: string[] of channel IDs\r\n * - For file uploads: attachment objects array\r\n */\r\n private _extractModalFields(modalInteraction: any): Record<string, any> {\r\n const fields: Record<string, any> = {};\r\n\r\n // Handle classic text input fields via ModalSubmitFields\r\n if (modalInteraction.fields && modalInteraction.fields.fields) {\r\n for (const [customId, field] of modalInteraction.fields.fields) {\r\n // Text input - field.value is the string\r\n // For select menus, value might be an array\r\n fields[customId] = field.values || field.value;\r\n }\r\n }\r\n\r\n // Handle new modal components from interaction.data.components\r\n // The new modal structure uses Label wrappers with nested components\r\n const data = modalInteraction.data || (modalInteraction as any).data;\r\n if (data && data.components) {\r\n this._extractFieldsFromComponents(data.components, fields);\r\n }\r\n\r\n // Also check for components directly on the interaction (some Discord.js versions)\r\n if (modalInteraction.components && Array.isArray(modalInteraction.components)) {\r\n this._extractFieldsFromInteractionComponents(modalInteraction.components, fields);\r\n }\r\n\r\n return fields;\r\n }\r\n\r\n /**\r\n * Extract fields from Discord.js style interaction components (ActionRow objects)\r\n */\r\n private _extractFieldsFromInteractionComponents(components: any[], fields: Record<string, any>) {\r\n for (const row of components) {\r\n // ActionRow has components property\r\n const rowComponents = row.components || [];\r\n for (const component of rowComponents) {\r\n const customId = component.customId || component.custom_id || component.id;\r\n if (!customId) continue;\r\n\r\n // Check component type\r\n const type = component.type;\r\n\r\n // Text Input (type 4)\r\n if (type === 4 || component.value !== undefined) {\r\n fields[customId] = component.value || '';\r\n }\r\n\r\n // Select menus (types 3, 5, 6, 7, 8) - check for values array\r\n if (component.values !== undefined) {\r\n fields[customId] = component.values;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Recursively extract field values from component structure\r\n */\r\n private _extractFieldsFromComponents(components: any[], fields: Record<string, any>) {\r\n for (const component of components) {\r\n const type = component.type;\r\n // Support both custom_id and id for backward compatibility\r\n const customId = component.custom_id || component.id;\r\n\r\n // Type 18 = Label/Field - can have nested component or components\r\n if (type === 18) {\r\n if (component.component) {\r\n this._extractFieldsFromComponents([component.component], fields);\r\n }\r\n if (component.components) {\r\n this._extractFieldsFromComponents(component.components, fields);\r\n }\r\n continue;\r\n }\r\n\r\n // Type 1 = Action Row - has nested components array\r\n if (type === 1 && component.components) {\r\n this._extractFieldsFromComponents(component.components, fields);\r\n continue;\r\n }\r\n\r\n if (!customId) continue;\r\n\r\n switch (type) {\r\n case 4: // Text Input\r\n fields[customId] = component.value || '';\r\n break;\r\n\r\n case 3: // String Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 5: // User Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 6: // Role Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 7: // Mentionable Select - can have both users and roles\r\n // Discord returns resolved data for mentionables\r\n fields[customId] = {\r\n values: component.values || [],\r\n users: component.resolved?.users ? Object.keys(component.resolved.users) : [],\r\n roles: component.resolved?.roles ? Object.keys(component.resolved.roles) : []\r\n };\r\n break;\r\n\r\n case 8: // Channel Select\r\n fields[customId] = component.values || [];\r\n break;\r\n\r\n case 19: // File Upload\r\n // File uploads come through as attachments\r\n fields[customId] = component.attachments || [];\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Destroy all active instances of this component\r\n * Useful for cleanup when the bot shuts down or component is unloaded\r\n * \r\n * @returns Number of instances destroyed\r\n */\r\n destroyAll(): number {\r\n let count = 0;\r\n for (const [refId, context] of this._activeContexts) {\r\n if (context.runDestroy) {\r\n context.runDestroy();\r\n }\r\n this.dbi.data.refs.delete(refId);\r\n count++;\r\n }\r\n this._activeContexts.clear();\r\n return count;\r\n }\r\n\r\n handlers?: any[] = [];\r\n}"]}
|