@mostfeatured/dbi 0.2.13 → 0.2.15

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.
Files changed (45) hide show
  1. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts +33 -1
  2. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts.map +1 -1
  3. package/dist/src/types/Components/HTMLComponentsV2/index.js +408 -82
  4. package/dist/src/types/Components/HTMLComponentsV2/index.js.map +1 -1
  5. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts +52 -0
  6. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts.map +1 -1
  7. package/dist/src/types/Components/HTMLComponentsV2/parser.js +275 -0
  8. package/dist/src/types/Components/HTMLComponentsV2/parser.js.map +1 -1
  9. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts +26 -0
  10. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts.map +1 -1
  11. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js +509 -34
  12. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js.map +1 -1
  13. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts +10 -0
  14. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts.map +1 -1
  15. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js +76 -11
  16. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js.map +1 -1
  17. package/dist/test/index.js +76 -3
  18. package/dist/test/index.js.map +1 -1
  19. package/docs/ADVANCED_FEATURES.md +4 -0
  20. package/docs/API_REFERENCE.md +4 -0
  21. package/docs/CHAT_INPUT.md +4 -0
  22. package/docs/COMPONENTS.md +4 -0
  23. package/docs/EVENTS.md +4 -0
  24. package/docs/GETTING_STARTED.md +4 -0
  25. package/docs/LOCALIZATION.md +4 -0
  26. package/docs/README.md +4 -0
  27. package/docs/SVELTE_COMPONENTS.md +162 -6
  28. package/docs/llm/ADVANCED_FEATURES.txt +521 -0
  29. package/docs/llm/API_REFERENCE.txt +659 -0
  30. package/docs/llm/CHAT_INPUT.txt +514 -0
  31. package/docs/llm/COMPONENTS.txt +595 -0
  32. package/docs/llm/EVENTS.txt +449 -0
  33. package/docs/llm/GETTING_STARTED.txt +296 -0
  34. package/docs/llm/LOCALIZATION.txt +501 -0
  35. package/docs/llm/README.txt +193 -0
  36. package/docs/llm/SVELTE_COMPONENTS.txt +566 -0
  37. package/generated/svelte-dbi.d.ts +122 -0
  38. package/package.json +1 -1
  39. package/src/types/Components/HTMLComponentsV2/index.ts +466 -94
  40. package/src/types/Components/HTMLComponentsV2/parser.ts +317 -0
  41. package/src/types/Components/HTMLComponentsV2/svelteParser.ts +567 -35
  42. package/src/types/Components/HTMLComponentsV2/svelteRenderer.ts +91 -13
  43. package/test/index.ts +76 -3
  44. package/test/product-showcase.svelte +380 -24
  45. package/llm.txt +0 -1088
@@ -1 +1 @@
1
- {"version":3,"file":"svelteRenderer.js","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/svelteRenderer.ts"],"names":[],"mappings":";;AAsBA,sDA4GC;AA+KD,sEASC;;AA1TD,8CAA0C;AAG1C,qCAAiD;AACjD,iDAAuH;AACvH,uDAAiC;AACjC,+CAAyB;AAazB;;GAEG;AACI,KAAK,UAAU,qBAAqB,CACzC,GAAwB,EACxB,MAAc,EACd,OAAe,EACf,UAA+B,EAAE;IAEjC,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAEvC,iDAAiD;IACjD,8EAA8E;IAC9E,MAAM,aAAa,GAAG,MAAM,IAAA,mCAAoB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/D,gEAAgE;IAChE,MAAM,eAAe,GAAG,aAAa,CAAC,eAAe,CAAC;IAEtD,kDAAkD;IAClD,MAAM,QAAQ,GAAG,IAAA,kBAAO,EAAC,eAAe,EAAE;QACxC,QAAQ,EAAE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GAEG;AACI,KAAK,UAAU,6BAA6B,CACjD,GAAwB,EACxB,QAAgB,EAChB,OAAe,EACf,UAA+B,EAAE;IAEjC,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,MAAM,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { compile } from \"svelte/compiler\";\r\nimport { DBI } from \"../../../DBI\";\r\nimport { NamespaceEnums } from \"../../../../generated/namespaceData\";\r\nimport { parseHTMLComponentsV2 } from \"./parser\";\r\nimport { parseSvelteComponent, createHandlerContext, SvelteComponentInfo, HandlerContextResult } from \"./svelteParser\";\r\nimport * as stuffs from \"stuffs\";\r\nimport * as vm from \"vm\";\r\n\r\nexport interface SvelteRenderOptions {\r\n data?: Record<string, any>;\r\n ttl?: number;\r\n}\r\n\r\nexport interface SvelteRenderResult {\r\n components: any[];\r\n handlers: Map<string, { handlerFn: Function, context: any }>;\r\n componentInfo: SvelteComponentInfo;\r\n}\r\n\r\n/**\r\n * Compile and render a Svelte component to Discord components\r\n */\r\nexport async function renderSvelteComponent(\r\n dbi: DBI<NamespaceEnums>,\r\n source: string,\r\n dbiName: string,\r\n options: SvelteRenderOptions = {}\r\n): Promise<SvelteRenderResult> {\r\n const { data = {}, ttl = 0 } = options;\r\n\r\n // Parse the Svelte component to extract handlers\r\n // This also injects auto-generated names into elements without name attribute\r\n const componentInfo = await parseSvelteComponent(source, data);\r\n\r\n // Use the processed source (with auto-generated names injected)\r\n const processedSource = componentInfo.processedSource;\r\n\r\n // Compile the Svelte component for SSR (Svelte 5)\r\n const compiled = compile(processedSource, {\r\n generate: \"server\",\r\n css: \"injected\",\r\n dev: false,\r\n } as any);\r\n\r\n // Create a module context for the compiled code\r\n let html = \"\";\r\n try {\r\n const moduleContext = createModuleContext(dbi, data, ttl);\r\n const Component = evaluateCompiledComponent(compiled.js.code, moduleContext);\r\n\r\n // Svelte 5 SSR: Use render from svelte/server\r\n const { render } = require(\"svelte/server\");\r\n // Pass data properties as top-level props (Svelte 5 expects flat props object)\r\n const renderResult = render(Component, { props: data });\r\n html = renderResult.body || \"\";\r\n } catch (error) {\r\n throw error;\r\n }\r\n\r\n // For Svelte mode, inject state into interactive elements as a ref\r\n // Reuse existing ref if data already has one, otherwise create new\r\n if (data && Object.keys(data).length > 0) {\r\n let stateRefId: string;\r\n\r\n // Check if data already has a $ref (from previous render)\r\n if (data.$ref && typeof data.$ref === 'string') {\r\n stateRefId = data.$ref;\r\n // Update the existing ref's value with new data\r\n const existingRef = dbi.data.refs.get(stateRefId);\r\n if (existingRef) {\r\n existingRef.value = data;\r\n existingRef.at = Date.now(); // Refresh timestamp\r\n } else {\r\n // Ref expired or was deleted, create new one with same ID\r\n dbi.data.refs.set(stateRefId, { at: Date.now(), value: data, ttl });\r\n }\r\n } else {\r\n // Create a new ref for the state\r\n stateRefId = stuffs.randomString(8);\r\n data.$ref = stateRefId; // Store ref ID in data for future updates\r\n dbi.data.refs.set(stateRefId, { at: Date.now(), value: data, ttl });\r\n }\r\n\r\n // Add state ref to all elements with name attribute (buttons, selects)\r\n // This includes both manual names and auto-generated names from svelteParser\r\n html = html.replace(/<button([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, attrs) => {\r\n // Check if it already has data attributes\r\n if (attrs.includes('data-1:')) return match;\r\n return `<button${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n // Also handle select elements (with optional -menu suffix for Svelte compatibility)\r\n // Supports: string-select, user-select, role-select, channel-select, mentionable-select\r\n // Both with and without -menu suffix (e.g., string-select-menu or string-select)\r\n html = html.replace(/<(string-select(?:-menu)?|user-select(?:-menu)?|role-select(?:-menu)?|channel-select(?:-menu)?|mentionable-select(?:-menu)?)([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, tag, attrs) => {\r\n if (attrs.includes('data-1:')) return match;\r\n return `<${tag}${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n // Handle modal elements with name attribute\r\n html = html.replace(/<modal([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, attrs) => {\r\n if (attrs.includes('data-1:')) return match;\r\n return `<modal${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n }\r\n\r\n // Parse the rendered HTML to Discord components\r\n const components = parseHTMLComponentsV2(dbi, html, dbiName, { data, ttl });\r\n\r\n // Create handler context (also captures $effect callbacks)\r\n const handlerContext = createHandlerContext(componentInfo.scriptContent, data);\r\n const handlers = new Map<string, { handlerFn: Function, context: any }>();\r\n\r\n // Run effects on initial render\r\n handlerContext.runEffects();\r\n\r\n // Map handlers to component names\r\n componentInfo.handlers.forEach((handlerInfo, componentName) => {\r\n const handlerFn = handlerContext.handlers[handlerInfo.handlerName];\r\n if (handlerFn && typeof handlerFn === \"function\") {\r\n handlers.set(componentName, {\r\n handlerFn,\r\n context: data\r\n });\r\n }\r\n });\r\n\r\n return {\r\n components,\r\n handlers,\r\n componentInfo\r\n };\r\n}\r\n\r\n/**\r\n * Create a module context for evaluating the compiled Svelte component\r\n */\r\nfunction createModuleContext(dbi: DBI<NamespaceEnums>, data: Record<string, any>, ttl: number) {\r\n return {\r\n // Store objects in refs for later retrieval in handlers\r\n // This is used internally by the parser when converting to Discord components\r\n __storeRef: (obj: any) => {\r\n let id = stuffs.randomString(8);\r\n dbi.data.refs.set(id, { at: Date.now(), value: obj, ttl });\r\n return id;\r\n },\r\n\r\n // DBI instance for advanced usage\r\n __dbi: dbi,\r\n\r\n // All data context available\r\n ...data,\r\n data, // Also expose as 'data' prop\r\n };\r\n}\r\n\r\n/**\r\n * Evaluate the compiled Svelte component code\r\n */\r\nfunction evaluateCompiledComponent(code: string, context: Record<string, any>): any {\r\n try {\r\n // Load Svelte 5 internal runtime\r\n const svelteInternal = require(\"svelte/internal/server\");\r\n\r\n // Process the code to work in our context\r\n let processedCode = code;\r\n\r\n // Collect external modules to inject into sandbox\r\n const externalModules: Record<string, any> = {};\r\n\r\n // Replace svelte internal imports\r\n processedCode = processedCode.replace(\r\n /import\\s*\\*\\s*as\\s*(\\w+)\\s*from\\s*[\"']svelte\\/internal\\/server[\"'];?/g,\r\n 'const $1 = __svelteInternal;'\r\n );\r\n processedCode = processedCode.replace(\r\n /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']svelte\\/internal\\/server[\"'];?/g,\r\n (match, imports) => {\r\n const importList = imports.split(',').map((i: string) => i.trim());\r\n return `const { ${importList.join(', ')} } = __svelteInternal;`;\r\n }\r\n );\r\n\r\n // Handle external module imports (default imports)\r\n processedCode = processedCode.replace(\r\n /import\\s+(\\w+)\\s+from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, varName, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n externalModules[varName] = mod.default || mod;\r\n return `const ${varName} = __externalModules.${varName};`;\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Handle named imports from external modules\r\n processedCode = processedCode.replace(\r\n /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, imports, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n const importList = imports.split(',').map((i: string) => i.trim());\r\n importList.forEach((importName: string) => {\r\n const [name, alias] = importName.split(' as ').map(s => s.trim());\r\n externalModules[alias || name] = mod[name] || mod.default?.[name];\r\n });\r\n return importList.map((importName: string) => {\r\n const [name, alias] = importName.split(' as ').map(s => s.trim());\r\n return `const ${alias || name} = __externalModules.${alias || name};`;\r\n }).join('\\n');\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Handle namespace imports from external modules\r\n processedCode = processedCode.replace(\r\n /import\\s*\\*\\s*as\\s*(\\w+)\\s*from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, varName, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n externalModules[varName] = mod;\r\n return `const ${varName} = __externalModules.${varName};`;\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Remove any remaining import statements\r\n processedCode = processedCode\r\n .split('\\n')\r\n .filter(line => !line.trim().startsWith('import '))\r\n .join('\\n');\r\n\r\n // Replace 'export default' with assignment\r\n processedCode = processedCode.replace(/export\\s+default\\s+/g, '__exports.default = ');\r\n // Replace 'export function' with assignment\r\n processedCode = processedCode.replace(/export\\s+function\\s+(\\w+)/g, '__exports.$1 = function $1');\r\n // Replace 'export const' with assignment\r\n processedCode = processedCode.replace(/export\\s+const\\s+(\\w+)/g, '__exports.$1 = ');\r\n // Replace 'export let' with assignment \r\n processedCode = processedCode.replace(/export\\s+let\\s+(\\w+)/g, '__exports.$1 = ');\r\n\r\n // Create the sandbox context\r\n const __exports: any = {};\r\n // Svelte lifecycle functions - no-ops for SSR\r\n const svelteLifecycle = {\r\n onMount: () => () => { }, // Returns cleanup function\r\n onDestroy: () => { },\r\n beforeUpdate: () => { },\r\n afterUpdate: () => { },\r\n tick: () => Promise.resolve(),\r\n untrack: (fn: () => any) => fn(),\r\n createEventDispatcher: () => () => { },\r\n };\r\n\r\n // Note: Svelte 5 runes ($state, $derived, etc.) are compile-time features\r\n // The compiler transforms them, so we don't need runtime implementations.\r\n // The `$` variable is used by compiled code as the svelte/internal/server namespace.\r\n\r\n const sandbox = {\r\n __svelteInternal: svelteInternal,\r\n __externalModules: externalModules,\r\n $: svelteInternal, // Direct alias for compiled Svelte code that uses `$`\r\n __exports,\r\n console,\r\n ...svelteLifecycle,\r\n ...context,\r\n };\r\n\r\n // Wrap code in IIFE\r\n const wrappedCode = `\r\n (function() {\r\n ${processedCode}\r\n })();\r\n `;\r\n\r\n // Run in VM context for better isolation\r\n vm.createContext(sandbox);\r\n vm.runInContext(wrappedCode, sandbox);\r\n\r\n // Return the component\r\n const Component = sandbox.__exports.default;\r\n\r\n if (!Component) {\r\n throw new Error(\"Svelte component did not export a default component\");\r\n }\r\n\r\n return Component;\r\n } catch (error) {\r\n throw error;\r\n }\r\n}\r\n\r\n/**\r\n * Render a Svelte component from a file\r\n */\r\nexport async function renderSvelteComponentFromFile(\r\n dbi: DBI<NamespaceEnums>,\r\n filePath: string,\r\n dbiName: string,\r\n options: SvelteRenderOptions = {}\r\n): Promise<SvelteRenderResult> {\r\n const fs = require(\"fs\");\r\n const source = fs.readFileSync(filePath, \"utf-8\");\r\n return await renderSvelteComponent(dbi, source, dbiName, options);\r\n}\r\n"]}
1
+ {"version":3,"file":"svelteRenderer.js","sourceRoot":"","sources":["../../../../../src/types/Components/HTMLComponentsV2/svelteRenderer.ts"],"names":[],"mappings":";;AAiCA,sDA+KC;AA+KD,sEASC;;AAxYD,8CAA0C;AAG1C,qCAA6E;AAC7E,iDAAuK;AACvK,uDAAiC;AACjC,+CAAyB;AAwBzB;;GAEG;AACI,KAAK,UAAU,qBAAqB,CACzC,GAAwB,EACxB,MAAc,EACd,OAAe,EACf,UAA+B,EAAE;IAEjC,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,CAAC,EAAE,cAAc,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE/D,iDAAiD;IACjD,8EAA8E;IAC9E,MAAM,aAAa,GAAG,MAAM,IAAA,mCAAoB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/D,iFAAiF;IACjF,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAA,sCAAuB,EAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,IAAA,oCAAqB,EAAC,QAAQ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BAAuB;QACvB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;QAE5C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,6BAA6B,CACjD,GAAwB,EACxB,QAAgB,EAChB,OAAe,EACf,UAA+B,EAAE;IAEjC,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,MAAM,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { compile } from \"svelte/compiler\";\r\nimport { DBI } from \"../../../DBI\";\r\nimport { NamespaceEnums } from \"../../../../generated/namespaceData\";\r\nimport { parseHTMLComponentsV2, parseHTMLComponentsV2Multi } from \"./parser\";\r\nimport { parseSvelteComponent, createHandlerContext, SvelteComponentInfo, HandlerContextResult, validateSvelteComponent, logValidationWarnings } from \"./svelteParser\";\r\nimport * as stuffs from \"stuffs\";\r\nimport * as vm from \"vm\";\r\n\r\nexport interface SvelteRenderOptions {\r\n data?: Record<string, any>;\r\n ttl?: number;\r\n /** If true, skips validation warnings (useful for production) */\r\n skipValidation?: boolean;\r\n}\r\n\r\nexport interface ModalDefinition {\r\n title: string;\r\n customId: string;\r\n components: any[];\r\n modalId: string;\r\n}\r\n\r\nexport interface SvelteRenderResult {\r\n components: any[];\r\n handlers: Map<string, { handlerFn: Function, context: any }>;\r\n componentInfo: SvelteComponentInfo;\r\n /** Modal definitions parsed from <components type=\"modal\"> elements */\r\n modals: Map<string, ModalDefinition>;\r\n}\r\n\r\n/**\r\n * Compile and render a Svelte component to Discord components\r\n */\r\nexport async function renderSvelteComponent(\r\n dbi: DBI<NamespaceEnums>,\r\n source: string,\r\n dbiName: string,\r\n options: SvelteRenderOptions = {}\r\n): Promise<SvelteRenderResult> {\r\n const { data = {}, ttl = 0, skipValidation = false } = options;\r\n\r\n // Parse the Svelte component to extract handlers\r\n // This also injects auto-generated names into elements without name attribute\r\n const componentInfo = await parseSvelteComponent(source, data);\r\n\r\n // Validate the component and log warnings (only on first render, not re-renders)\r\n if (!skipValidation && !data.$ref) {\r\n const warnings = validateSvelteComponent(componentInfo, data, dbiName);\r\n if (warnings.length > 0) {\r\n logValidationWarnings(warnings);\r\n }\r\n }\r\n\r\n // Use the processed source (with auto-generated names injected)\r\n const processedSource = componentInfo.processedSource;\r\n\r\n // Compile the Svelte component for SSR (Svelte 5)\r\n let compiled;\r\n try {\r\n compiled = compile(processedSource, {\r\n generate: \"server\",\r\n css: \"injected\",\r\n dev: false,\r\n } as any);\r\n } catch (compileError: any) {\r\n // Format Svelte compile error with helpful details\r\n const errorMessage = compileError.message || 'Unknown compile error';\r\n const location = compileError.start || compileError.loc || compileError.position;\r\n let details = errorMessage;\r\n\r\n if (location) {\r\n const lines = processedSource.split('\\n');\r\n const lineNum = location.line || 1;\r\n const column = location.column || 0;\r\n const errorLine = lines[lineNum - 1] || '';\r\n const prevLine = lines[lineNum - 2] || '';\r\n const nextLine = lines[lineNum] || '';\r\n\r\n details = `\r\nSvelte Compile Error at line ${lineNum}, column ${column}:\r\n${errorMessage}\r\n\r\n${lineNum > 1 ? `${lineNum - 1} | ${prevLine}\\n` : ''}${lineNum} | ${errorLine}\r\n${' '.repeat(String(lineNum).length + 3 + column)}^\r\n${nextLine ? `${lineNum + 1} | ${nextLine}` : ''}\r\n`.trim();\r\n }\r\n\r\n // Check for common mistakes and add hints\r\n let hint = '';\r\n if (errorMessage.includes('Unexpected token')) {\r\n hint = '\\n\\n💡 Hint: Check for missing closing tags, unclosed braces, or invalid JavaScript syntax.';\r\n } else if (errorMessage.includes('is not defined')) {\r\n hint = '\\n\\n💡 Hint: Make sure all variables are declared in $props() or as local variables.';\r\n } else if (errorMessage.includes('Expected')) {\r\n hint = '\\n\\n💡 Hint: There might be a syntax error in your template or script.';\r\n }\r\n\r\n const enhancedError = new Error(`[DBI-Svelte] Failed to compile component \"${dbiName}\":\\n${details}${hint}`);\r\n (enhancedError as any).originalError = compileError;\r\n (enhancedError as any).type = 'svelte-compile-error';\r\n throw enhancedError;\r\n }\r\n\r\n // Create a module context for the compiled code\r\n let html = \"\";\r\n try {\r\n const moduleContext = createModuleContext(dbi, data, ttl);\r\n const Component = evaluateCompiledComponent(compiled.js.code, moduleContext);\r\n\r\n // Svelte 5 SSR: Use render from svelte/server\r\n const { render } = require(\"svelte/server\");\r\n // Pass data properties as top-level props (Svelte 5 expects flat props object)\r\n const renderResult = render(Component, { props: data });\r\n html = renderResult.body || \"\";\r\n } catch (runtimeError: any) {\r\n // Format runtime error with helpful details\r\n const errorMessage = runtimeError.message || 'Unknown runtime error';\r\n let hint = '';\r\n\r\n if (errorMessage.includes('is not a function')) {\r\n hint = '\\n\\n💡 Hint: A function you are trying to call is undefined. Check handler names.';\r\n } else if (errorMessage.includes('Cannot read properties of undefined') || errorMessage.includes('undefined is not an object')) {\r\n hint = '\\n\\n💡 Hint: You are trying to access a property of an undefined value. Check your data object.';\r\n } else if (errorMessage.includes('is not defined')) {\r\n hint = '\\n\\n💡 Hint: A variable is used but not declared. Make sure it is in $props() or declared locally.';\r\n }\r\n\r\n const enhancedError = new Error(`[DBI-Svelte] Runtime error in component \"${dbiName}\":\\n${errorMessage}${hint}`);\r\n (enhancedError as any).originalError = runtimeError;\r\n (enhancedError as any).type = 'svelte-runtime-error';\r\n throw enhancedError;\r\n }\r\n\r\n // For Svelte mode, inject state into interactive elements as a ref\r\n // Reuse existing ref if data already has one, otherwise create new\r\n if (data && Object.keys(data).length > 0) {\r\n let stateRefId: string;\r\n\r\n // Check if data already has a $ref (from previous render)\r\n if (data.$ref && typeof data.$ref === 'string') {\r\n stateRefId = data.$ref;\r\n // Update the existing ref's value with new data\r\n const existingRef = dbi.data.refs.get(stateRefId);\r\n if (existingRef) {\r\n existingRef.value = data;\r\n existingRef.at = Date.now(); // Refresh timestamp\r\n } else {\r\n // Ref expired or was deleted, create new one with same ID\r\n dbi.data.refs.set(stateRefId, { at: Date.now(), value: data, ttl });\r\n }\r\n } else {\r\n // Create a new ref for the state\r\n stateRefId = stuffs.randomString(8);\r\n data.$ref = stateRefId; // Store ref ID in data for future updates\r\n dbi.data.refs.set(stateRefId, { at: Date.now(), value: data, ttl });\r\n }\r\n\r\n // Add state ref to all elements with name attribute (buttons, selects)\r\n // This includes both manual names and auto-generated names from svelteParser\r\n html = html.replace(/<button([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, attrs) => {\r\n // Check if it already has data attributes\r\n if (attrs.includes('data-1:')) return match;\r\n return `<button${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n // Also handle select elements (with optional -menu suffix for Svelte compatibility)\r\n // Supports: string-select, user-select, role-select, channel-select, mentionable-select\r\n // Both with and without -menu suffix (e.g., string-select-menu or string-select)\r\n html = html.replace(/<(string-select(?:-menu)?|user-select(?:-menu)?|role-select(?:-menu)?|channel-select(?:-menu)?|mentionable-select(?:-menu)?)([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, tag, attrs) => {\r\n if (attrs.includes('data-1:')) return match;\r\n return `<${tag}${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n // Handle modal elements with name attribute\r\n html = html.replace(/<modal([^>]*name=\"[^\"]*\"[^>]*)>/g, (match, attrs) => {\r\n if (attrs.includes('data-1:')) return match;\r\n return `<modal${attrs} data-1:ref=\"${stateRefId}\">`;\r\n });\r\n }\r\n\r\n // Parse the rendered HTML to Discord components (with modal support)\r\n const parseResult = parseHTMLComponentsV2Multi(dbi, html, dbiName, { data, ttl });\r\n const components = parseResult.components;\r\n const modals = parseResult.modals;\r\n\r\n // Create handler context (also captures $effect callbacks)\r\n const handlerContext = createHandlerContext(componentInfo.scriptContent, data);\r\n const handlers = new Map<string, { handlerFn: Function, context: any }>();\r\n\r\n // Run effects on initial render\r\n handlerContext.runEffects();\r\n\r\n // Map handlers to component names\r\n componentInfo.handlers.forEach((handlerInfo, componentName) => {\r\n const handlerFn = handlerContext.handlers[handlerInfo.handlerName];\r\n if (handlerFn && typeof handlerFn === \"function\") {\r\n handlers.set(componentName, {\r\n handlerFn,\r\n context: data\r\n });\r\n }\r\n });\r\n\r\n return {\r\n components,\r\n handlers,\r\n componentInfo,\r\n modals\r\n };\r\n}\r\n\r\n/**\r\n * Create a module context for evaluating the compiled Svelte component\r\n */\r\nfunction createModuleContext(dbi: DBI<NamespaceEnums>, data: Record<string, any>, ttl: number) {\r\n return {\r\n // Store objects in refs for later retrieval in handlers\r\n // This is used internally by the parser when converting to Discord components\r\n __storeRef: (obj: any) => {\r\n let id = stuffs.randomString(8);\r\n dbi.data.refs.set(id, { at: Date.now(), value: obj, ttl });\r\n return id;\r\n },\r\n\r\n // DBI instance for advanced usage\r\n __dbi: dbi,\r\n\r\n // All data context available\r\n ...data,\r\n data, // Also expose as 'data' prop\r\n };\r\n}\r\n\r\n/**\r\n * Evaluate the compiled Svelte component code\r\n */\r\nfunction evaluateCompiledComponent(code: string, context: Record<string, any>): any {\r\n try {\r\n // Load Svelte 5 internal runtime\r\n const svelteInternal = require(\"svelte/internal/server\");\r\n\r\n // Process the code to work in our context\r\n let processedCode = code;\r\n\r\n // Collect external modules to inject into sandbox\r\n const externalModules: Record<string, any> = {};\r\n\r\n // Replace svelte internal imports\r\n processedCode = processedCode.replace(\r\n /import\\s*\\*\\s*as\\s*(\\w+)\\s*from\\s*[\"']svelte\\/internal\\/server[\"'];?/g,\r\n 'const $1 = __svelteInternal;'\r\n );\r\n processedCode = processedCode.replace(\r\n /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']svelte\\/internal\\/server[\"'];?/g,\r\n (match, imports) => {\r\n const importList = imports.split(',').map((i: string) => i.trim());\r\n return `const { ${importList.join(', ')} } = __svelteInternal;`;\r\n }\r\n );\r\n\r\n // Handle external module imports (default imports)\r\n processedCode = processedCode.replace(\r\n /import\\s+(\\w+)\\s+from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, varName, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n externalModules[varName] = mod.default || mod;\r\n return `const ${varName} = __externalModules.${varName};`;\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Handle named imports from external modules\r\n processedCode = processedCode.replace(\r\n /import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, imports, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n const importList = imports.split(',').map((i: string) => i.trim());\r\n importList.forEach((importName: string) => {\r\n const [name, alias] = importName.split(' as ').map(s => s.trim());\r\n externalModules[alias || name] = mod[name] || mod.default?.[name];\r\n });\r\n return importList.map((importName: string) => {\r\n const [name, alias] = importName.split(' as ').map(s => s.trim());\r\n return `const ${alias || name} = __externalModules.${alias || name};`;\r\n }).join('\\n');\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Handle namespace imports from external modules\r\n processedCode = processedCode.replace(\r\n /import\\s*\\*\\s*as\\s*(\\w+)\\s*from\\s*[\"']([^\"']+)[\"'];?/g,\r\n (match, varName, modulePath) => {\r\n // Skip svelte imports\r\n if (modulePath.startsWith('svelte')) return '';\r\n try {\r\n const mod = require(modulePath);\r\n externalModules[varName] = mod;\r\n return `const ${varName} = __externalModules.${varName};`;\r\n } catch (e) {\r\n return '';\r\n }\r\n }\r\n );\r\n\r\n // Remove any remaining import statements\r\n processedCode = processedCode\r\n .split('\\n')\r\n .filter(line => !line.trim().startsWith('import '))\r\n .join('\\n');\r\n\r\n // Replace 'export default' with assignment\r\n processedCode = processedCode.replace(/export\\s+default\\s+/g, '__exports.default = ');\r\n // Replace 'export function' with assignment\r\n processedCode = processedCode.replace(/export\\s+function\\s+(\\w+)/g, '__exports.$1 = function $1');\r\n // Replace 'export const' with assignment\r\n processedCode = processedCode.replace(/export\\s+const\\s+(\\w+)/g, '__exports.$1 = ');\r\n // Replace 'export let' with assignment \r\n processedCode = processedCode.replace(/export\\s+let\\s+(\\w+)/g, '__exports.$1 = ');\r\n\r\n // Create the sandbox context\r\n const __exports: any = {};\r\n // Svelte lifecycle functions - no-ops for SSR\r\n const svelteLifecycle = {\r\n onMount: () => () => { }, // Returns cleanup function\r\n onDestroy: () => { },\r\n beforeUpdate: () => { },\r\n afterUpdate: () => { },\r\n tick: () => Promise.resolve(),\r\n untrack: (fn: () => any) => fn(),\r\n createEventDispatcher: () => () => { },\r\n };\r\n\r\n // Note: Svelte 5 runes ($state, $derived, etc.) are compile-time features\r\n // The compiler transforms them, so we don't need runtime implementations.\r\n // The `$` variable is used by compiled code as the svelte/internal/server namespace.\r\n\r\n const sandbox = {\r\n __svelteInternal: svelteInternal,\r\n __externalModules: externalModules,\r\n $: svelteInternal, // Direct alias for compiled Svelte code that uses `$`\r\n __exports,\r\n console,\r\n ...svelteLifecycle,\r\n ...context,\r\n };\r\n\r\n // Wrap code in IIFE\r\n const wrappedCode = `\r\n (function() {\r\n ${processedCode}\r\n })();\r\n `;\r\n\r\n // Run in VM context for better isolation\r\n vm.createContext(sandbox);\r\n vm.runInContext(wrappedCode, sandbox);\r\n\r\n // Return the component\r\n const Component = sandbox.__exports.default;\r\n\r\n if (!Component) {\r\n throw new Error(\"Svelte component did not export a default component\");\r\n }\r\n\r\n return Component;\r\n } catch (error) {\r\n throw error;\r\n }\r\n}\r\n\r\n/**\r\n * Render a Svelte component from a file\r\n */\r\nexport async function renderSvelteComponentFromFile(\r\n dbi: DBI<NamespaceEnums>,\r\n filePath: string,\r\n dbiName: string,\r\n options: SvelteRenderOptions = {}\r\n): Promise<SvelteRenderResult> {\r\n const fs = require(\"fs\");\r\n const source = fs.readFileSync(filePath, \"utf-8\");\r\n return await renderSvelteComponent(dbi, source, dbiName, options);\r\n}\r\n"]}
@@ -27,8 +27,7 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
27
27
  HTMLComponentsV2({
28
28
  name: "product-showcase",
29
29
  mode: 'svelte',
30
- file: path_1.default.join(__dirname, "product-showcase.svelte"),
31
- onExecute(ctx) { }
30
+ file: path_1.default.join(__dirname, "product-showcase.svelte")
32
31
  });
33
32
  // Test command
34
33
  ChatInput({
@@ -72,6 +71,78 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
72
71
  category: "Furniture",
73
72
  rating: 4.6,
74
73
  stock: 31
74
+ },
75
+ {
76
+ name: "Webcam 4K",
77
+ description: "Ultra HD webcam with autofocus and noise-canceling mic",
78
+ price: 129,
79
+ image: "https://cdn.discordapp.com/embed/avatars/4.png",
80
+ category: "Electronics",
81
+ rating: 4.7,
82
+ stock: 15
83
+ },
84
+ {
85
+ name: "Desk Lamp",
86
+ description: "LED desk lamp with adjustable brightness and color temperature",
87
+ price: 45,
88
+ image: "https://cdn.discordapp.com/embed/avatars/0.png",
89
+ category: "Furniture",
90
+ rating: 4.4,
91
+ stock: 60
92
+ },
93
+ {
94
+ name: "Headphone Stand",
95
+ description: "Aluminum headphone stand with cable holder",
96
+ price: 35,
97
+ image: "https://cdn.discordapp.com/embed/avatars/1.png",
98
+ category: "Accessories",
99
+ rating: 4.2,
100
+ stock: 28
101
+ },
102
+ {
103
+ name: "Gaming Headset",
104
+ description: "7.1 surround sound gaming headset with RGB lighting",
105
+ price: 99,
106
+ image: "https://cdn.discordapp.com/embed/avatars/2.png",
107
+ category: "Electronics",
108
+ rating: 4.6,
109
+ stock: 35
110
+ },
111
+ {
112
+ name: "Mouse Pad XL",
113
+ description: "Extended mouse pad with stitched edges, 900x400mm",
114
+ price: 25,
115
+ image: "https://cdn.discordapp.com/embed/avatars/3.png",
116
+ category: "Accessories",
117
+ rating: 4.8,
118
+ stock: 100
119
+ },
120
+ {
121
+ name: "Ergonomic Chair",
122
+ description: "Mesh office chair with lumbar support and adjustable armrests",
123
+ price: 299,
124
+ image: "https://cdn.discordapp.com/embed/avatars/4.png",
125
+ category: "Furniture",
126
+ rating: 4.9,
127
+ stock: 8
128
+ },
129
+ {
130
+ name: "Cable Management Kit",
131
+ description: "Complete kit with cable clips, ties, and sleeve",
132
+ price: 19,
133
+ image: "https://cdn.discordapp.com/embed/avatars/0.png",
134
+ category: "Accessories",
135
+ rating: 4.1,
136
+ stock: 75
137
+ },
138
+ {
139
+ name: "Portable SSD 1TB",
140
+ description: "Ultra-fast portable SSD with USB 3.2 Gen 2",
141
+ price: 109,
142
+ image: "https://cdn.discordapp.com/embed/avatars/1.png",
143
+ category: "Electronics",
144
+ rating: 4.7,
145
+ stock: 22
75
146
  }
76
147
  ];
77
148
  // Use send() method - this sends the message AND initializes lifecycle hooks (onMount)
@@ -82,7 +153,9 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
82
153
  currentIndex: 0,
83
154
  cart: [],
84
155
  view: 'browse',
85
- elapsedTime: 0
156
+ elapsedTime: 0,
157
+ reviews: [],
158
+ editingProduct: null
86
159
  }
87
160
  });
88
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../test/index.ts"],"names":[],"mappings":";;;AAAA,gCAAmC;AACnC,wDAAwB;AAExB,MAAM,GAAG,GAAG,IAAA,eAAS,EAAC,QAAQ,EAAE;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;QACtC,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,eAAe;gBACf,QAAQ;gBACR,gBAAgB;gBAChB,uBAAuB;aACxB;SACF;KACF;IACD,UAAU,EAAE;QACV,SAAS,EAAE;YACT,GAAG,EA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E,eAAe;oBACrB,WAAW,EAAE,gDAAgD;oBAC7D,KAAK,EAAE,EAAE;oBACT,KAAK,EAAE,gDAAgD;oBACvD,QAAQ,EAAE,WAAW;oBACrB,MAAM,EAAE,GAAG;oBACX,KAAK,EAAE,EAAE;iBACV;aACF,CAAC;YAEF,uFAAuF;YACvF,2EAA2E;YAC3E,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;gBAC/B,IAAI,EAAE;oBACJ,QAAQ;oBACR,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,CAAC;iBACf;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC9B,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QACnB,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;QAC3C,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3B,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EAAE,GAAG,CAAC,CAAC","sourcesContent":["import { createDBI } from \"../src\";\r\nimport path from \"path\";\r\n\r\nconst dbi = createDBI(\"svelte\", {\r\n discord: {\r\n token: process.env.DISCORD_TOKEN || \"\",\r\n options: {\r\n intents: [\r\n \"GuildMessages\",\r\n \"Guilds\",\r\n \"MessageContent\",\r\n \"GuildMessageReactions\"\r\n ],\r\n }\r\n },\r\n references: {\r\n autoClear: {\r\n ttl: 60000 * 60, // 60 minutes\r\n check: 60000 // every 60 seconds\r\n }\r\n }\r\n});\r\n\r\ndbi.register(({ ChatInput, HTMLComponentsV2 }) => {\r\n // Svelte product showcase with Components V2\r\n HTMLComponentsV2({\r\n name: \"product-showcase\",\r\n mode: 'svelte',\r\n file: path.join(__dirname, \"product-showcase.svelte\"),\r\n onExecute(ctx) {}\r\n });\r\n\r\n // Test command\r\n ChatInput({\r\n name: \"test-svelte\",\r\n description: \"Test Svelte product showcase\",\r\n async onExecute({ interaction, dbi }) {\r\n const showcase = dbi.interaction(\"product-showcase\") as any;\r\n\r\n const products = [\r\n {\r\n name: \"Gaming Keyboard\",\r\n description: \"RGB mechanical keyboard with Cherry MX switches\",\r\n price: 149,\r\n image: \"https://cdn.discordapp.com/embed/avatars/0.png\",\r\n category: \"Electronics\",\r\n rating: 4.8,\r\n stock: 25\r\n },\r\n {\r\n name: \"Wireless Mouse\",\r\n description: \"Ergonomic wireless mouse with 16000 DPI sensor\",\r\n price: 79,\r\n image: \"https://cdn.discordapp.com/embed/avatars/1.png\",\r\n category: \"Electronics\",\r\n rating: 4.5,\r\n stock: 42\r\n },\r\n {\r\n name: \"USB-C Hub\",\r\n description: \"7-in-1 USB-C hub with HDMI, USB 3.0, and SD card reader\",\r\n price: 59,\r\n image: \"https://cdn.discordapp.com/embed/avatars/2.png\",\r\n category: \"Accessories\",\r\n rating: 4.3,\r\n stock: 18\r\n },\r\n {\r\n name: \"Monitor Stand\",\r\n description: \"Adjustable monitor stand with cable management\",\r\n price: 89,\r\n image: \"https://cdn.discordapp.com/embed/avatars/3.png\",\r\n category: \"Furniture\",\r\n rating: 4.6,\r\n stock: 31\r\n }\r\n ];\r\n\r\n // Use send() method - this sends the message AND initializes lifecycle hooks (onMount)\r\n // The interval in onMount will start immediately after the message is sent\r\n await showcase.send(interaction, {\r\n data: {\r\n products,\r\n currentIndex: 0,\r\n cart: [],\r\n view: 'browse',\r\n elapsedTime: 0\r\n }\r\n });\r\n }\r\n });\r\n});\r\n\r\nsetTimeout(() => {\r\n console.log(\"Loading DBI...\");\r\n dbi.load().then(() => {\r\n dbi.publish(\"Guild\", \"1341841733511806978\")\r\n console.log(\"DBI loaded.\");\r\n dbi.login().then(() => {\r\n console.log(\"Bot is running with Svelte components!\");\r\n });\r\n });\r\n}, 100);"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../test/index.ts"],"names":[],"mappings":";;;AAAA,gCAAmC;AACnC,wDAAwB;AAExB,MAAM,GAAG,GAAG,IAAA,eAAS,EAAC,QAAQ,EAAE;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;QACtC,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,eAAe;gBACf,QAAQ;gBACR,gBAAgB;gBAChB,uBAAuB;aACxB;SACF;KACF;IACD,UAAU,EAAE;QACV,SAAS,EAAE;YACT,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,aAAa;YAC9B,KAAK,EAAE,KAAK,CAAC,mBAAmB;SACjC;KACF;CACF,CAAC,CAAC;AAEH,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE;IAC/C,6CAA6C;IAC7C,gBAAgB,CAAC;QACf,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC;KACtD,CAAC,CAAC;IAEH,eAAe;IACf,SAAS,CAAC;QACR,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,8BAA8B;QAC3C,KAAK,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE;YAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAQ,CAAC;YAE5D,MAAM,QAAQ,GAAG;gBACf;oBACE,IAAI,EAAE,iBAAiB;oBACvB,WAAW,EAAE,iDAAiD;oBAC9D,KAAK,EAAE,GAAG;oBACV,KAAK,EAAE,gDAAgD;oBACvD,QAAQ,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iBACrB;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC9B,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QACnB,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;QAC3C,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3B,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EAAE,GAAG,CAAC,CAAC","sourcesContent":["import { createDBI } from \"../src\";\r\nimport path from \"path\";\r\n\r\nconst dbi = createDBI(\"svelte\", {\r\n discord: {\r\n token: process.env.DISCORD_TOKEN || \"\",\r\n options: {\r\n intents: [\r\n \"GuildMessages\",\r\n \"Guilds\",\r\n \"MessageContent\",\r\n \"GuildMessageReactions\"\r\n ],\r\n }\r\n },\r\n references: {\r\n autoClear: {\r\n ttl: 60000 * 60, // 60 minutes\r\n check: 60000 // every 60 seconds\r\n }\r\n }\r\n});\r\n\r\ndbi.register(({ ChatInput, HTMLComponentsV2 }) => {\r\n // Svelte product showcase with Components V2\r\n HTMLComponentsV2({\r\n name: \"product-showcase\",\r\n mode: 'svelte',\r\n file: path.join(__dirname, \"product-showcase.svelte\")\r\n });\r\n\r\n // Test command\r\n ChatInput({\r\n name: \"test-svelte\",\r\n description: \"Test Svelte product showcase\",\r\n async onExecute({ interaction, dbi }) {\r\n const showcase = dbi.interaction(\"product-showcase\") as any;\r\n\r\n const products = [\r\n {\r\n name: \"Gaming Keyboard\",\r\n description: \"RGB mechanical keyboard with Cherry MX switches\",\r\n price: 149,\r\n image: \"https://cdn.discordapp.com/embed/avatars/0.png\",\r\n category: \"Electronics\",\r\n rating: 4.8,\r\n stock: 25\r\n },\r\n {\r\n name: \"Wireless Mouse\",\r\n description: \"Ergonomic wireless mouse with 16000 DPI sensor\",\r\n price: 79,\r\n image: \"https://cdn.discordapp.com/embed/avatars/1.png\",\r\n category: \"Electronics\",\r\n rating: 4.5,\r\n stock: 42\r\n },\r\n {\r\n name: \"USB-C Hub\",\r\n description: \"7-in-1 USB-C hub with HDMI, USB 3.0, and SD card reader\",\r\n price: 59,\r\n image: \"https://cdn.discordapp.com/embed/avatars/2.png\",\r\n category: \"Accessories\",\r\n rating: 4.3,\r\n stock: 18\r\n },\r\n {\r\n name: \"Monitor Stand\",\r\n description: \"Adjustable monitor stand with cable management\",\r\n price: 89,\r\n image: \"https://cdn.discordapp.com/embed/avatars/3.png\",\r\n category: \"Furniture\",\r\n rating: 4.6,\r\n stock: 31\r\n },\r\n {\r\n name: \"Webcam 4K\",\r\n description: \"Ultra HD webcam with autofocus and noise-canceling mic\",\r\n price: 129,\r\n image: \"https://cdn.discordapp.com/embed/avatars/4.png\",\r\n category: \"Electronics\",\r\n rating: 4.7,\r\n stock: 15\r\n },\r\n {\r\n name: \"Desk Lamp\",\r\n description: \"LED desk lamp with adjustable brightness and color temperature\",\r\n price: 45,\r\n image: \"https://cdn.discordapp.com/embed/avatars/0.png\",\r\n category: \"Furniture\",\r\n rating: 4.4,\r\n stock: 60\r\n },\r\n {\r\n name: \"Headphone Stand\",\r\n description: \"Aluminum headphone stand with cable holder\",\r\n price: 35,\r\n image: \"https://cdn.discordapp.com/embed/avatars/1.png\",\r\n category: \"Accessories\",\r\n rating: 4.2,\r\n stock: 28\r\n },\r\n {\r\n name: \"Gaming Headset\",\r\n description: \"7.1 surround sound gaming headset with RGB lighting\",\r\n price: 99,\r\n image: \"https://cdn.discordapp.com/embed/avatars/2.png\",\r\n category: \"Electronics\",\r\n rating: 4.6,\r\n stock: 35\r\n },\r\n {\r\n name: \"Mouse Pad XL\",\r\n description: \"Extended mouse pad with stitched edges, 900x400mm\",\r\n price: 25,\r\n image: \"https://cdn.discordapp.com/embed/avatars/3.png\",\r\n category: \"Accessories\",\r\n rating: 4.8,\r\n stock: 100\r\n },\r\n {\r\n name: \"Ergonomic Chair\",\r\n description: \"Mesh office chair with lumbar support and adjustable armrests\",\r\n price: 299,\r\n image: \"https://cdn.discordapp.com/embed/avatars/4.png\",\r\n category: \"Furniture\",\r\n rating: 4.9,\r\n stock: 8\r\n },\r\n {\r\n name: \"Cable Management Kit\",\r\n description: \"Complete kit with cable clips, ties, and sleeve\",\r\n price: 19,\r\n image: \"https://cdn.discordapp.com/embed/avatars/0.png\",\r\n category: \"Accessories\",\r\n rating: 4.1,\r\n stock: 75\r\n },\r\n {\r\n name: \"Portable SSD 1TB\",\r\n description: \"Ultra-fast portable SSD with USB 3.2 Gen 2\",\r\n price: 109,\r\n image: \"https://cdn.discordapp.com/embed/avatars/1.png\",\r\n category: \"Electronics\",\r\n rating: 4.7,\r\n stock: 22\r\n }\r\n ];\r\n\r\n // Use send() method - this sends the message AND initializes lifecycle hooks (onMount)\r\n // The interval in onMount will start immediately after the message is sent\r\n await showcase.send(interaction, {\r\n data: {\r\n products,\r\n currentIndex: 0,\r\n cart: [],\r\n view: 'browse',\r\n elapsedTime: 0,\r\n reviews: [],\r\n editingProduct: null\r\n }\r\n });\r\n }\r\n });\r\n});\r\n\r\nsetTimeout(() => {\r\n console.log(\"Loading DBI...\");\r\n dbi.load().then(() => {\r\n dbi.publish(\"Guild\", \"1341841733511806978\")\r\n console.log(\"DBI loaded.\");\r\n dbi.login().then(() => {\r\n console.log(\"Bot is running with Svelte components!\");\r\n });\r\n });\r\n}, 100);"]}
@@ -834,3 +834,7 @@ Without strict mode:
834
834
 
835
835
  - [Svelte Components](./SVELTE_COMPONENTS.md) - Build reactive Discord UIs
836
836
  - [API Reference](./API_REFERENCE.md) - Complete API documentation
837
+
838
+ ---
839
+
840
+ > 📄 **LLM-optimized version:** [llm/ADVANCED_FEATURES.txt](./llm/ADVANCED_FEATURES.txt)
@@ -923,3 +923,7 @@ interface HandlerContext {
923
923
  - [Localization](./LOCALIZATION.md)
924
924
  - [Svelte Components](./SVELTE_COMPONENTS.md)
925
925
  - [Advanced Features](./ADVANCED_FEATURES.md)
926
+
927
+ ---
928
+
929
+ > 📄 **LLM-optimized version:** [llm/API_REFERENCE.txt](./llm/API_REFERENCE.txt)
@@ -805,3 +805,7 @@ await dbi.load();
805
805
  - [Components](./COMPONENTS.md) - Add interactive buttons and menus
806
806
  - [Localization](./LOCALIZATION.md) - Support multiple languages
807
807
  - [Advanced Features](./ADVANCED_FEATURES.md) - Rate limiting, references, and more
808
+
809
+ ---
810
+
811
+ > 📄 **LLM-optimized version:** [llm/CHAT_INPUT.txt](./llm/CHAT_INPUT.txt)
@@ -1033,3 +1033,7 @@ dbi.register(({ Button }) => {
1033
1033
  - [Events](./EVENTS.md) - Handle Discord events
1034
1034
  - [Svelte Components](./SVELTE_COMPONENTS.md) - Build reactive UIs
1035
1035
  - [Advanced Features](./ADVANCED_FEATURES.md) - Rate limiting and more
1036
+
1037
+ ---
1038
+
1039
+ > 📄 **LLM-optimized version:** [llm/COMPONENTS.txt](./llm/COMPONENTS.txt)
package/docs/EVENTS.md CHANGED
@@ -562,3 +562,7 @@ dbi.register(({ Event }) => {
562
562
  - [Localization](./LOCALIZATION.md) - Multi-language support
563
563
  - [Advanced Features](./ADVANCED_FEATURES.md) - Message commands, multi-client
564
564
  - [API Reference](./API_REFERENCE.md) - Complete API documentation
565
+
566
+ ---
567
+
568
+ > 📄 **LLM-optimized version:** [llm/EVENTS.txt](./llm/EVENTS.txt)
@@ -392,3 +392,7 @@ Now that you have a basic bot running, explore these guides:
392
392
  - Check the [documentation](./README.md)
393
393
  - Review the [examples](../test/)
394
394
  - Report issues on GitHub
395
+
396
+ ---
397
+
398
+ > 📄 **LLM-optimized version:** [llm/GETTING_STARTED.txt](./llm/GETTING_STARTED.txt)
@@ -771,3 +771,7 @@ dbi.register(({ ChatInput }) => {
771
771
  - [Advanced Features](./ADVANCED_FEATURES.md) - Message commands, multi-client
772
772
  - [Svelte Components](./SVELTE_COMPONENTS.md) - Reactive UI components
773
773
  - [API Reference](./API_REFERENCE.md) - Complete API documentation
774
+
775
+ ---
776
+
777
+ > 📄 **LLM-optimized version:** [llm/LOCALIZATION.txt](./llm/LOCALIZATION.txt)
package/docs/README.md CHANGED
@@ -339,3 +339,7 @@ GPL-3.0 License - See [LICENSE](../LICENSE) for details.
339
339
  **Made with ❤️ by [TheArmagan](https://github.com/TheArmagan) and the MostFeatured team**
340
340
 
341
341
  </div>
342
+
343
+ ---
344
+
345
+ > 📄 **LLM-optimized version:** [llm/README.txt](./llm/README.txt)
@@ -347,6 +347,28 @@ Set minimum interval between renders:
347
347
  </script>
348
348
  ```
349
349
 
350
+ ### lowPriorityUpdate(callback)
351
+
352
+ Low-priority update for background tasks. If a user interaction handler is running, the callback executes but rendering is skipped (the handler's render will include the changes).
353
+
354
+ Use this to prevent interval/timeout updates from conflicting with button clicks:
355
+
356
+ ```svelte
357
+ <script>
358
+ onMount(() => {
359
+ const interval = setInterval(() => {
360
+ // If user clicks a button during this interval tick,
361
+ // this update won't trigger a conflicting render
362
+ lowPriorityUpdate(() => {
363
+ data.elapsedTime += 1;
364
+ });
365
+ }, 1000);
366
+
367
+ return () => clearInterval(interval);
368
+ });
369
+ </script>
370
+ ```
371
+
350
372
  ---
351
373
 
352
374
  ## HTML Elements Reference
@@ -534,25 +556,72 @@ File attachment display.
534
556
 
535
557
  ### Modal Components
536
558
 
559
+ Discord modals now support many interactive components beyond text inputs. Use the `<field>` wrapper component for the new structure.
560
+
561
+ #### `<components type="modal">`
562
+
563
+ Define a modal form that can be shown to users.
564
+
565
+ ```svelte
566
+ <components
567
+ type="modal"
568
+ id="feedback-modal"
569
+ title="Submit Feedback"
570
+ >
571
+ <!-- New Field wrapper structure (recommended) -->
572
+ <field label="Rating" description="How would you rate our service?">
573
+ <string-select id="rating" placeholder="Select rating">
574
+ <option value="5">⭐⭐⭐⭐⭐ Excellent</option>
575
+ <option value="4">⭐⭐⭐⭐ Great</option>
576
+ <option value="3">⭐⭐⭐ Good</option>
577
+ <option value="2">⭐⭐ Fair</option>
578
+ <option value="1">⭐ Poor</option>
579
+ </string-select>
580
+ </field>
581
+ <field label="Comments" description="Tell us more about your experience">
582
+ <text-input id="comments" style="Paragraph" placeholder="Your feedback..." />
583
+ </field>
584
+ </components>
585
+ ```
586
+
587
+ #### `<field>`
588
+
589
+ Wrapper component for modal inputs (Discord's Label component, type 18). **Required for new modal structure.**
590
+
591
+ | Attribute | Type | Description |
592
+ |-----------|------|-------------|
593
+ | `label` | string | Label text shown above component |
594
+ | `description` | string | Optional description text |
595
+
537
596
  #### `<text-input>`
597
+
538
598
  Text input for modal forms.
539
599
 
540
600
  ```svelte
601
+ <field label="Username" description="Enter your display name">
602
+ <text-input
603
+ id="username"
604
+ placeholder="Enter your username"
605
+ style="Short"
606
+ min-length="3"
607
+ max-length="32"
608
+ required
609
+ />
610
+ </field>
611
+
612
+ <!-- Legacy format still supported -->
541
613
  <text-input
542
614
  id="username"
543
615
  label="Username"
544
616
  placeholder="Enter your username"
545
617
  style="Short"
546
- min-length="3"
547
- max-length="32"
548
- required
549
- >Default value</text-input>
618
+ />
550
619
  ```
551
620
 
552
621
  | Attribute | Type | Description |
553
622
  |-----------|------|-------------|
554
- | `id` / `custom-id` | string | Input identifier |
555
- | `label` | string | Label above input |
623
+ | `id` / `custom-id` / `name` | string | Input identifier |
624
+ | `label` | string | Label (legacy format only) |
556
625
  | `placeholder` | string | Placeholder text |
557
626
  | `style` | "Short" \| "Paragraph" | Input style |
558
627
  | `min-length` | number | Minimum characters |
@@ -560,6 +629,89 @@ Text input for modal forms.
560
629
  | `required` | boolean | Is required |
561
630
  | `value` | string | Default value |
562
631
 
632
+ #### `<string-select>` (in modals)
633
+
634
+ Dropdown select menu in modals. Returns an **array** of selected values.
635
+
636
+ ```svelte
637
+ <field label="Choose Bug Type" description="Select the bug category">
638
+ <string-select id="bug-type" placeholder="Select bug type">
639
+ <option value="ant" emoji="🐜">Ant</option>
640
+ <option value="beetle" emoji="🪲">Beetle</option>
641
+ <option value="spider" emoji="🕷️">Spider</option>
642
+ </string-select>
643
+ </field>
644
+ ```
645
+
646
+ #### `<user-select>`, `<role-select>`, `<mentionable-select>`, `<channel-select>` (in modals)
647
+
648
+ Auto-populated select menus for modals. Returns an **array** of IDs.
649
+
650
+ ```svelte
651
+ <field label="Assign To" description="Select team members">
652
+ <user-select id="assignees" placeholder="Choose users" max-values="3" />
653
+ </field>
654
+
655
+ <field label="Notification Channel" description="Where to post updates">
656
+ <channel-select id="channel" placeholder="Select channel" channel-types="0,5" />
657
+ </field>
658
+ ```
659
+
660
+ #### `<file-upload>` (in modals)
661
+
662
+ File upload component for modals. Returns attachment objects.
663
+
664
+ ```svelte
665
+ <field label="Attachments" description="Upload relevant files">
666
+ <file-upload id="files" min-values="0" max-values="5" />
667
+ </field>
668
+ ```
669
+
670
+ #### `<text-display>` (in modals)
671
+
672
+ Show static text content in modals.
673
+
674
+ ```svelte
675
+ <text-display>Please fill out all required fields below.</text-display>
676
+ ```
677
+
678
+ ### Using Modals with `showModal()`
679
+
680
+ The `showModal()` function opens a modal and returns a Promise with the submitted values:
681
+
682
+ ```svelte
683
+ <script>
684
+ async function openFeedbackModal(ctx) {
685
+ // Show modal and wait for submission
686
+ const { fields, interaction } = await showModal("feedback-modal");
687
+
688
+ // Extract values
689
+ const rating = fields.rating[0]; // string-select returns array
690
+ const comments = fields.comments; // text-input returns string
691
+
692
+ // Respond to the submission
693
+ interaction.reply({
694
+ content: `Thanks for your ${rating}-star feedback!`,
695
+ flags: ["Ephemeral"]
696
+ });
697
+ }
698
+ </script>
699
+ ```
700
+
701
+ ### Modal Field Types
702
+
703
+ Different modal components return different value types:
704
+
705
+ | Component | Return Type | Example |
706
+ |-----------|-------------|---------|
707
+ | `text-input` | `string` | `"Hello world"` |
708
+ | `string-select` | `string[]` | `["option1", "option2"]` |
709
+ | `user-select` | `string[]` | `["123456789"]` (user IDs) |
710
+ | `role-select` | `string[]` | `["987654321"]` (role IDs) |
711
+ | `channel-select` | `string[]` | `["111222333"]` (channel IDs) |
712
+ | `mentionable-select` | `{ values, users, roles }` | IDs with separated types |
713
+ | `file-upload` | `Attachment[]` | Uploaded file objects |
714
+
563
715
  ---
564
716
 
565
717
  ## Handler Functions
@@ -953,3 +1105,7 @@ interface SendOptions {
953
1105
  ### IDE not showing autocomplete?
954
1106
  - Add `/// <reference types="@mostfeatured/dbi/svelte" />` at top of script
955
1107
  - Make sure `@mostfeatured/dbi` is installed
1108
+
1109
+ ---
1110
+
1111
+ > 📄 **LLM-optimized version:** [llm/SVELTE_COMPONENTS.txt](./llm/SVELTE_COMPONENTS.txt)