@mostfeatured/dbi 0.2.15 → 0.2.16

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.
@@ -33,6 +33,8 @@ export declare class DBIHTMLComponentsV2<TNamespace extends NamespaceEnums> exte
33
33
  mode: 'svelte' | 'eta';
34
34
  private svelteComponentInfo;
35
35
  private _userOnExecute?;
36
+ /** The directory of the source file (used for resolving relative imports) */
37
+ private _sourceDir?;
36
38
  private _activeContexts;
37
39
  _pendingModals: Map<string, {
38
40
  resolve: (result: any) => void;
@@ -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;AAsJ7G,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,EAA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sBAAsB;IAgG9B,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAQ;IAEtC,MAAM,CAAC,GAAG,GAAE,8BAAmC,GAAG,OAAO,CAAC,GAAG,CAAC;IA+B7E;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,GAAE,+BAAoC,GAAG,OAAO,CAAC,GAAG,CAAC;IAyFpF;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO;IAsBzD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,mBAAmB;IAqB3B;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAyDpC;;;;;OAKG;IACH,UAAU,IAAI,MAAM;IAapB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAM;CACvB"}
@@ -158,6 +158,8 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
158
158
  mode = 'eta';
159
159
  svelteComponentInfo = null;
160
160
  _userOnExecute;
161
+ /** The directory of the source file (used for resolving relative imports) */
162
+ _sourceDir;
161
163
  // Store handler contexts per ref for lifecycle management
162
164
  // Key: ref id, Value: handlerContext with lifecycle hooks
163
165
  _activeContexts = new Map();
@@ -181,6 +183,11 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
181
183
  this.name = args.name;
182
184
  this.handlers = args.handlers || [];
183
185
  this.mode = args.mode || 'eta';
186
+ // Store source directory for resolving relative imports in Svelte components
187
+ if (this.file) {
188
+ const path = require("path");
189
+ this._sourceDir = path.dirname(path.resolve(this.file));
190
+ }
184
191
  // Store user's onExecute callback if provided
185
192
  if (userOnExecute) {
186
193
  this._userOnExecute = userOnExecute;
@@ -255,7 +262,7 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
255
262
  return;
256
263
  }
257
264
  // Create handler context for modal submit
258
- const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, typeof currentState === 'object' ? currentState : {}, this, ctx);
265
+ const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, typeof currentState === 'object' ? currentState : {}, this, ctx, this._sourceDir);
259
266
  const handlerFn = handlerContext.handlers[handlerName];
260
267
  if (handlerFn && typeof handlerFn === 'function') {
261
268
  try {
@@ -302,7 +309,7 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
302
309
  // This ensures each interaction has its own isolated state
303
310
  // Pass 'this' so handlers can access component methods like toJSON()
304
311
  // Pass ctx so handlers can access ctx.interaction, ctx.data, ctx.locale, etc.
305
- const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, typeof currentState === 'object' ? currentState : {}, this, ctx);
312
+ const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, typeof currentState === 'object' ? currentState : {}, this, ctx, this._sourceDir);
306
313
  const handlerFn = handlerContext.handlers[handlerInfo.handlerName];
307
314
  if (handlerFn && typeof handlerFn === 'function') {
308
315
  try {
@@ -457,7 +464,7 @@ class DBIHTMLComponentsV2 extends Interaction_1.DBIBaseInteraction {
457
464
  message: message,
458
465
  }
459
466
  };
460
- const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, data, this, fakeCtx);
467
+ const handlerContext = (0, svelteParser_1.createHandlerContext)(this.svelteComponentInfo.scriptContent, data, this, fakeCtx, this._sourceDir);
461
468
  // Store the context for lifecycle management
462
469
  this._activeContexts.set(refId, handlerContext);
463
470
  // Wrap $unRef to call onDestroy when ref is deleted
@@ -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,iDAAk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CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;wBAC7E,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;qBAC9E,CAAC;oBACF,MAAM;gBAER,KAAK,CAAC,EAAE,iBAAiB;oBACvB,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;oBAC1C,MAAM;gBAER,KAAK,EAAE,EAAE,cAAc;oBACrB,2CAA2C;oBAC3C,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,WAAW,IAAI,EAAE,CAAC;oBAC/C,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,UAAU;QACR,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACpD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,OAAO,CAAC,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;AAvjBD,kDAujBC","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 fs from \"fs\";\r\n\r\n/**\r\n * Parse Discord API error and provide helpful context about which HTML element caused the error\r\n */\r\nfunction parseDiscordAPIError(error: any, source?: string, componentName?: string): Error {\r\n // Check if it's a Discord API error with form body issues\r\n const message = error.message || '';\r\n const rawError = error.rawError || error;\r\n\r\n // Extract the path from error message like \"data.components[0].components[0].accessory.media.url\"\r\n const pathMatch = message.match(/data\\.components(\\[[^\\]]+\\](?:\\.[^\\[\\s\\[]+|\\[[^\\]]+\\])*)/);\r\n\r\n if (!pathMatch) {\r\n return error; // Not a parseable Discord API error\r\n }\r\n\r\n const errorPath = pathMatch[1];\r\n const errorCode = message.match(/\\[([A-Z_]+)\\]/)?.[1] || 'UNKNOWN';\r\n\r\n // Parse the path to understand the component structure\r\n // e.g., \"[0].components[0].accessory.media.url\" -> component index 0, child 0, accessory.media.url\r\n const parts = errorPath.split(/\\.|\\[|\\]/).filter(Boolean);\r\n\r\n // Build a human-readable path description\r\n let description = '';\r\n let elementHint = '';\r\n let currentPath = [];\r\n\r\n for (let i = 0; i < parts.length; i++) {\r\n const part = parts[i];\r\n if (!isNaN(Number(part))) {\r\n currentPath.push(`[${part}]`);\r\n } else {\r\n currentPath.push(part);\r\n\r\n // Provide hints based on known Discord component structure\r\n if (part === 'accessory') {\r\n elementHint = '<section> element\\'s accessory (thumbnail/button)';\r\n } else if (part === 'media') {\r\n elementHint = '<thumbnail> or <media-gallery> element';\r\n } else if (part === 'url') {\r\n elementHint = 'media URL attribute';\r\n } else if (part === 'components') {\r\n // Skip, it's container\r\n } else if (part === 'content') {\r\n elementHint = 'text content of a <text-display> element';\r\n } else if (part === 'label') {\r\n elementHint = 'label attribute of a <button> or <option>';\r\n } else if (part === 'custom_id') {\r\n elementHint = 'name attribute of an interactive element';\r\n } else if (part === 'placeholder') {\r\n elementHint = 'placeholder attribute of a select menu';\r\n } else if (part === 'title') {\r\n elementHint = 'title attribute of a <modal> or <section>';\r\n } else if (part === 'options') {\r\n elementHint = '<option> elements inside a <string-select>';\r\n } else if (part === 'value') {\r\n elementHint = 'value attribute of an <option> or <text-input>';\r\n } else if (part === 'description') {\r\n elementHint = 'description attribute of an <option>';\r\n }\r\n }\r\n }\r\n\r\n // Map error codes to helpful messages\r\n const errorMessages: Record<string, string> = {\r\n 'BASE_TYPE_REQUIRED': 'This field is required but was empty or undefined',\r\n 'STRING_TYPE_REQUIRED': 'This field must be a string',\r\n 'NUMBER_TYPE_REQUIRED': 'This field must be a number',\r\n 'BOOLEAN_TYPE_REQUIRED': 'This field must be a boolean',\r\n 'INVALID_URL': 'The URL provided is not valid',\r\n 'MAX_LENGTH': 'The value exceeds the maximum allowed length',\r\n 'MIN_LENGTH': 'The value is shorter than the minimum required length',\r\n 'CHOICE_NOT_FOUND': 'The selected value is not in the list of options',\r\n };\r\n\r\n const errorExplanation = errorMessages[errorCode] || `Error code: ${errorCode}`;\r\n\r\n // Build the enhanced error message\r\n let enhancedMessage = `\r\n╔══════════════════════════════════════════════════════════════╗\r\n║ Discord API Error - Invalid Component Data ║\r\n╚══════════════════════════════════════════════════════════════╝\r\n\r\n📍 Component: ${componentName || 'unknown'}\r\n📍 Error Path: data.components${errorPath}\r\n📍 Error Code: ${errorCode}\r\n\r\n❌ ${errorExplanation}\r\n${elementHint ? `\\n💡 This error is likely in: ${elementHint}` : ''}\r\n\r\n🔍 What to check:\r\n`;\r\n\r\n // Add specific suggestions based on error type\r\n if (errorPath.includes('media.url')) {\r\n enhancedMessage += ` • Make sure the image/media URL is provided and valid\r\n • Check that the data property used for the image exists\r\n • Example: <thumbnail media={product?.image}> - is product.image defined?\r\n`;\r\n } else if (errorPath.includes('accessory')) {\r\n enhancedMessage += ` • The <section> element requires valid content in its accessory\r\n • If using <thumbnail>, ensure the media URL is valid\r\n`;\r\n } else if (errorPath.includes('content')) {\r\n enhancedMessage += ` • Text content cannot be empty or undefined\r\n • Check your template expressions like {variable?.property}\r\n`;\r\n } else if (errorPath.includes('options')) {\r\n enhancedMessage += ` • Select menu options must have valid value and label\r\n • Each <option> needs: value=\"...\" and text content\r\n`;\r\n } else if (errorPath.includes('label') || errorPath.includes('custom_id')) {\r\n enhancedMessage += ` • Interactive elements (buttons, selects) need valid labels/names\r\n • Check that text content and name attributes are not empty\r\n`;\r\n }\r\n\r\n // If we have source, try to highlight relevant section\r\n if (source && elementHint) {\r\n const elementType = elementHint.match(/<(\\w+-?\\w*)>/)?.[1];\r\n if (elementType) {\r\n const elementRegex = new RegExp(`<${elementType}[^>]*>`, 'g');\r\n const matches = source.match(elementRegex);\r\n if (matches && matches.length > 0) {\r\n enhancedMessage += `\\n📝 Found ${matches.length} <${elementType}> element(s) in template:`;\r\n matches.slice(0, 3).forEach((m, i) => {\r\n enhancedMessage += `\\n ${i + 1}. ${m.substring(0, 80)}${m.length > 80 ? '...' : ''}`;\r\n });\r\n if (matches.length > 3) {\r\n enhancedMessage += `\\n ... and ${matches.length - 3} more`;\r\n }\r\n }\r\n }\r\n }\r\n\r\n const enhancedError = new Error(enhancedMessage);\r\n (enhancedError as any).originalError = error;\r\n (enhancedError as any).type = 'discord-api-error';\r\n (enhancedError as any).path = errorPath;\r\n (enhancedError as any).code = errorCode;\r\n\r\n return enhancedError;\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\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\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 } functions\r\n _pendingModals: Map<string, { resolve: (result: any) => void; reject: (error: any) => void }> = 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 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 const handlerInfo = this.svelteComponentInfo.handlers.get(elementName);\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 // Resolve the promise with fields and interaction\r\n pendingModal.resolve({\r\n fields,\r\n interaction: modalInteraction,\r\n ctx: ctx\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 );\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 // Modal handler execution failed\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 );\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 // Handler execution failed\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 * await showcase.send(channel, { data: { count: 0 } });\r\n * \r\n * // Send as followUp (if already replied)\r\n * await showcase.send(interaction, { data: { count: 0 }, followUp: true });\r\n * ```\r\n */\r\n async send(target: any, options: TDBIHTMLComponentsV2SendOptions = {}): Promise<any> {\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);\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 );\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\r\n return message;\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 fields[customId] = 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 return fields;\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 const customId = component.custom_id;\r\n\r\n // Type 18 = Label - has nested component\r\n if (type === 18 && component.component) {\r\n this._extractFieldsFromComponents([component.component], fields);\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,oDAAoB;AAEpB;;GAEG;AACH,SAAS,oBAAoB,CAAC,KAAU,EAAE,MAAe,EAAE,aAAsB;IAC/E,0DAA0D;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;IAEzC,kGAAkG;IAClG,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAE5F,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC,CAAC,oCAAoC;IACpD,CAAC;IAED,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;I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AAC,CAAC,EAAE;wBAC7E,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;qBAC9E,CAAC;oBACF,MAAM;gBAER,KAAK,CAAC,EAAE,iBAAiB;oBACvB,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;oBAC1C,MAAM;gBAER,KAAK,EAAE,EAAE,cAAc;oBACrB,2CAA2C;oBAC3C,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,WAAW,IAAI,EAAE,CAAC;oBAC/C,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,UAAU;QACR,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACpD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,OAAO,CAAC,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;AAlkBD,kDAkkBC","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 fs from \"fs\";\r\n\r\n/**\r\n * Parse Discord API error and provide helpful context about which HTML element caused the error\r\n */\r\nfunction parseDiscordAPIError(error: any, source?: string, componentName?: string): Error {\r\n // Check if it's a Discord API error with form body issues\r\n const message = error.message || '';\r\n const rawError = error.rawError || error;\r\n\r\n // Extract the path from error message like \"data.components[0].components[0].accessory.media.url\"\r\n const pathMatch = message.match(/data\\.components(\\[[^\\]]+\\](?:\\.[^\\[\\s\\[]+|\\[[^\\]]+\\])*)/);\r\n\r\n if (!pathMatch) {\r\n return error; // Not a parseable Discord API error\r\n }\r\n\r\n const errorPath = pathMatch[1];\r\n const errorCode = message.match(/\\[([A-Z_]+)\\]/)?.[1] || 'UNKNOWN';\r\n\r\n // Parse the path to understand the component structure\r\n // e.g., \"[0].components[0].accessory.media.url\" -> component index 0, child 0, accessory.media.url\r\n const parts = errorPath.split(/\\.|\\[|\\]/).filter(Boolean);\r\n\r\n // Build a human-readable path description\r\n let description = '';\r\n let elementHint = '';\r\n let currentPath = [];\r\n\r\n for (let i = 0; i < parts.length; i++) {\r\n const part = parts[i];\r\n if (!isNaN(Number(part))) {\r\n currentPath.push(`[${part}]`);\r\n } else {\r\n currentPath.push(part);\r\n\r\n // Provide hints based on known Discord component structure\r\n if (part === 'accessory') {\r\n elementHint = '<section> element\\'s accessory (thumbnail/button)';\r\n } else if (part === 'media') {\r\n elementHint = '<thumbnail> or <media-gallery> element';\r\n } else if (part === 'url') {\r\n elementHint = 'media URL attribute';\r\n } else if (part === 'components') {\r\n // Skip, it's container\r\n } else if (part === 'content') {\r\n elementHint = 'text content of a <text-display> element';\r\n } else if (part === 'label') {\r\n elementHint = 'label attribute of a <button> or <option>';\r\n } else if (part === 'custom_id') {\r\n elementHint = 'name attribute of an interactive element';\r\n } else if (part === 'placeholder') {\r\n elementHint = 'placeholder attribute of a select menu';\r\n } else if (part === 'title') {\r\n elementHint = 'title attribute of a <modal> or <section>';\r\n } else if (part === 'options') {\r\n elementHint = '<option> elements inside a <string-select>';\r\n } else if (part === 'value') {\r\n elementHint = 'value attribute of an <option> or <text-input>';\r\n } else if (part === 'description') {\r\n elementHint = 'description attribute of an <option>';\r\n }\r\n }\r\n }\r\n\r\n // Map error codes to helpful messages\r\n const errorMessages: Record<string, string> = {\r\n 'BASE_TYPE_REQUIRED': 'This field is required but was empty or undefined',\r\n 'STRING_TYPE_REQUIRED': 'This field must be a string',\r\n 'NUMBER_TYPE_REQUIRED': 'This field must be a number',\r\n 'BOOLEAN_TYPE_REQUIRED': 'This field must be a boolean',\r\n 'INVALID_URL': 'The URL provided is not valid',\r\n 'MAX_LENGTH': 'The value exceeds the maximum allowed length',\r\n 'MIN_LENGTH': 'The value is shorter than the minimum required length',\r\n 'CHOICE_NOT_FOUND': 'The selected value is not in the list of options',\r\n };\r\n\r\n const errorExplanation = errorMessages[errorCode] || `Error code: ${errorCode}`;\r\n\r\n // Build the enhanced error message\r\n let enhancedMessage = `\r\n╔══════════════════════════════════════════════════════════════╗\r\n║ Discord API Error - Invalid Component Data ║\r\n╚══════════════════════════════════════════════════════════════╝\r\n\r\n📍 Component: ${componentName || 'unknown'}\r\n📍 Error Path: data.components${errorPath}\r\n📍 Error Code: ${errorCode}\r\n\r\n❌ ${errorExplanation}\r\n${elementHint ? `\\n💡 This error is likely in: ${elementHint}` : ''}\r\n\r\n🔍 What to check:\r\n`;\r\n\r\n // Add specific suggestions based on error type\r\n if (errorPath.includes('media.url')) {\r\n enhancedMessage += ` • Make sure the image/media URL is provided and valid\r\n • Check that the data property used for the image exists\r\n • Example: <thumbnail media={product?.image}> - is product.image defined?\r\n`;\r\n } else if (errorPath.includes('accessory')) {\r\n enhancedMessage += ` • The <section> element requires valid content in its accessory\r\n • If using <thumbnail>, ensure the media URL is valid\r\n`;\r\n } else if (errorPath.includes('content')) {\r\n enhancedMessage += ` • Text content cannot be empty or undefined\r\n • Check your template expressions like {variable?.property}\r\n`;\r\n } else if (errorPath.includes('options')) {\r\n enhancedMessage += ` • Select menu options must have valid value and label\r\n • Each <option> needs: value=\"...\" and text content\r\n`;\r\n } else if (errorPath.includes('label') || errorPath.includes('custom_id')) {\r\n enhancedMessage += ` • Interactive elements (buttons, selects) need valid labels/names\r\n • Check that text content and name attributes are not empty\r\n`;\r\n }\r\n\r\n // If we have source, try to highlight relevant section\r\n if (source && elementHint) {\r\n const elementType = elementHint.match(/<(\\w+-?\\w*)>/)?.[1];\r\n if (elementType) {\r\n const elementRegex = new RegExp(`<${elementType}[^>]*>`, 'g');\r\n const matches = source.match(elementRegex);\r\n if (matches && matches.length > 0) {\r\n enhancedMessage += `\\n📝 Found ${matches.length} <${elementType}> element(s) in template:`;\r\n matches.slice(0, 3).forEach((m, i) => {\r\n enhancedMessage += `\\n ${i + 1}. ${m.substring(0, 80)}${m.length > 80 ? '...' : ''}`;\r\n });\r\n if (matches.length > 3) {\r\n enhancedMessage += `\\n ... and ${matches.length - 3} more`;\r\n }\r\n }\r\n }\r\n }\r\n\r\n const enhancedError = new Error(enhancedMessage);\r\n (enhancedError as any).originalError = error;\r\n (enhancedError as any).type = 'discord-api-error';\r\n (enhancedError as any).path = errorPath;\r\n (enhancedError as any).code = errorCode;\r\n\r\n return enhancedError;\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\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 } functions\r\n _pendingModals: Map<string, { resolve: (result: any) => void; reject: (error: any) => void }> = 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 const handlerInfo = this.svelteComponentInfo.handlers.get(elementName);\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 // Resolve the promise with fields and interaction\r\n pendingModal.resolve({\r\n fields,\r\n interaction: modalInteraction,\r\n ctx: ctx\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 );\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 // Modal handler execution failed\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 );\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 // Handler execution failed\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 * await showcase.send(channel, { data: { count: 0 } });\r\n * \r\n * // Send as followUp (if already replied)\r\n * await showcase.send(interaction, { data: { count: 0 }, followUp: true });\r\n * ```\r\n */\r\n async send(target: any, options: TDBIHTMLComponentsV2SendOptions = {}): Promise<any> {\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);\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 );\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\r\n return message;\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 fields[customId] = 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 return fields;\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 const customId = component.custom_id;\r\n\r\n // Type 18 = Label - has nested component\r\n if (type === 18 && component.component) {\r\n this._extractFieldsFromComponents([component.component], fields);\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}"]}
@@ -56,6 +56,7 @@ export interface HandlerContextResult {
56
56
  /**
57
57
  * Create a handler context from script content
58
58
  * This evaluates the Svelte script and returns the handler functions and effects
59
+ * @param sourceDir - The directory of the source file (used for resolving relative imports)
59
60
  */
60
- export declare function createHandlerContext(scriptContent: string, initialData?: Record<string, any>, component?: any, ctx?: any): HandlerContextResult;
61
+ export declare function createHandlerContext(scriptContent: string, initialData?: Record<string, any>, component?: any, ctx?: any, sourceDir?: string): HandlerContextResult;
61
62
  //# sourceMappingURL=svelteParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelteParser.d.ts","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/svelteParser.ts"],"names":[],"mappings":"AA+DA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EA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AK,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AA2GD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAosBvK"}
@@ -591,13 +591,18 @@ function parseImports(script) {
591
591
  /**
592
592
  * Load modules and create injection variables
593
593
  */
594
- function loadModules(imports) {
594
+ function loadModules(imports, sourceDir) {
595
595
  const modules = {};
596
596
  const declarations = [];
597
+ const path = require("path");
597
598
  for (const importInfo of imports) {
598
599
  try {
600
+ // Resolve relative paths from source file directory
601
+ const resolvedPath = importInfo.moduleName.startsWith('.') && sourceDir
602
+ ? path.resolve(sourceDir, importInfo.moduleName)
603
+ : importInfo.moduleName;
599
604
  // Try to require the module
600
- const mod = require(importInfo.moduleName);
605
+ const mod = require(resolvedPath);
601
606
  if (importInfo.isDefault && importInfo.defaultName) {
602
607
  // Default or namespace import
603
608
  modules[importInfo.defaultName] = mod.default || mod;
@@ -619,14 +624,15 @@ function loadModules(imports) {
619
624
  /**
620
625
  * Create a handler context from script content
621
626
  * This evaluates the Svelte script and returns the handler functions and effects
627
+ * @param sourceDir - The directory of the source file (used for resolving relative imports)
622
628
  */
623
- function createHandlerContext(scriptContent, initialData = {}, component, ctx) {
629
+ function createHandlerContext(scriptContent, initialData = {}, component, ctx, sourceDir) {
624
630
  const handlers = {};
625
631
  const effects = [];
626
632
  try {
627
633
  // Parse and extract imports first
628
634
  const { imports, cleanedScript } = parseImports(scriptContent);
629
- const { modules, varDeclarations } = loadModules(imports);
635
+ const { modules, varDeclarations } = loadModules(imports, sourceDir);
630
636
  // Extract only function declarations from the script
631
637
  const functionNames = extractFunctionNames(cleanedScript);
632
638
  // Extract $effect calls and convert them to collectable functions