@carbon/ai-chat-components 1.14.0 → 1.15.0-rc.0
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.
- package/custom-elements.json +8737 -8823
- package/es/components/audio-player/src/transcript.js +1 -1
- package/es/components/carousel/src/carousel.d.ts +1 -1
- package/es/components/carousel/src/carousel.js +1 -1
- package/es/components/carousel/src/carousel.js.map +1 -1
- package/es/components/chat-history/src/history-panel-item.d.ts +8 -0
- package/es/components/chat-history/src/history-panel-item.js +44 -1
- package/es/components/chat-history/src/history-panel-item.js.map +1 -1
- package/es/components/code-snippet/src/code-snippet.d.ts +4 -0
- package/es/components/code-snippet/src/code-snippet.js +12 -0
- package/es/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es/components/feedback/src/feedback.js +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +16 -17
- package/es/components/file-uploads/src/file-upload-item.js +98 -58
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +20 -0
- package/es/components/file-uploads/src/file-uploads.js +55 -1
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es/components/markdown/index.js +1 -2
- package/es/components/markdown/index.js.map +1 -1
- package/es/components/markdown/src/inline-markdown.d.ts +2 -2
- package/es/components/markdown/src/inline-markdown.js +8 -2
- package/es/components/markdown/src/inline-markdown.js.map +1 -1
- package/es/components/markdown/src/inline-markdown.scss.js +2 -2
- package/es/components/markdown/src/markdown-renderer-types.d.ts +2 -0
- package/es/components/markdown/src/markdown-renderer.js +3 -1
- package/es/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es/components/markdown/src/markdown.d.ts +4 -0
- package/es/components/markdown/src/markdown.js +14 -0
- package/es/components/markdown/src/markdown.js.map +1 -1
- package/es/components/markdown/src/utils/inline-run-projection.js +3 -17
- package/es/components/markdown/src/utils/inline-run-projection.js.map +1 -1
- package/es/components/message-item-shell/index.d.ts +11 -0
- package/es/components/message-item-shell/index.js +9 -0
- package/es/components/message-item-shell/index.js.map +1 -0
- package/es/components/message-item-shell/src/message-item-shell.d.ts +48 -0
- package/es/components/message-item-shell/src/message-item-shell.js +91 -0
- package/es/components/message-item-shell/src/message-item-shell.js.map +1 -0
- package/es/components/message-item-shell/src/message-item-shell.scss.js +13 -0
- package/es/components/message-item-shell/src/message-item-shell.scss.js.map +1 -0
- package/es/components/prompt-line/src/prompt-line-controller.d.ts +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +19 -2
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +9 -4
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.d.ts +17 -7
- package/es/components/prompt-line/src/prompt-line.js +39 -0
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.scss.js +1 -1
- package/es/components/prompt-line/src/tiptap/chat-enter.d.ts +2 -2
- package/es/components/prompt-line/src/tiptap/chat-enter.js +2 -2
- package/es/components/prompt-line/src/tiptap/chat-enter.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/editor-styles.js +1 -1
- package/es/components/prompt-line/src/tiptap/editor-styles.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/types.d.ts +3 -4
- package/es/components/shared/root-styles.d.ts +30 -0
- package/es/components/shared/root-styles.js +72 -0
- package/es/components/shared/root-styles.js.map +1 -0
- package/es/components/toolbar/src/toolbar.d.ts +14 -4
- package/es/components/toolbar/src/toolbar.js +29 -6
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/user-avatar/index.d.ts +10 -0
- package/es/components/user-avatar/index.js +9 -0
- package/es/components/user-avatar/index.js.map +1 -0
- package/es/components/user-avatar/src/user-avatar.d.ts +46 -0
- package/es/components/user-avatar/src/user-avatar.js +153 -0
- package/es/components/user-avatar/src/user-avatar.js.map +1 -0
- package/es/components/user-avatar/src/user-avatar.scss.js +13 -0
- package/es/components/user-avatar/src/user-avatar.scss.js.map +1 -0
- package/es/globals/utils/iconTransform.js +1 -0
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/chat-header.js +4 -2
- package/es/react/chat-header.js.map +1 -1
- package/es/react/code-snippet.d.ts +4 -1
- package/es/react/code-snippet.js +3 -1
- package/es/react/code-snippet.js.map +1 -1
- package/es/react/message-item-shell.d.ts +3 -0
- package/es/react/message-item-shell.js +30 -0
- package/es/react/message-item-shell.js.map +1 -0
- package/es/react/toolbar.d.ts +1 -1
- package/es/react/toolbar.js +3 -1
- package/es/react/toolbar.js.map +1 -1
- package/es/react/user-avatar.d.ts +3 -0
- package/es/react/user-avatar.js +29 -0
- package/es/react/user-avatar.js.map +1 -0
- package/es-custom/components/audio-player/src/transcript.js +1 -1
- package/es-custom/components/carousel/src/carousel.d.ts +1 -1
- package/es-custom/components/carousel/src/carousel.js +1 -1
- package/es-custom/components/carousel/src/carousel.js.map +1 -1
- package/es-custom/components/chat-history/src/history-panel-item.d.ts +8 -0
- package/es-custom/components/chat-history/src/history-panel-item.js +44 -1
- package/es-custom/components/chat-history/src/history-panel-item.js.map +1 -1
- package/es-custom/components/code-snippet/src/code-snippet.d.ts +4 -0
- package/es-custom/components/code-snippet/src/code-snippet.js +12 -0
- package/es-custom/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es-custom/components/feedback/src/feedback.js +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +16 -17
- package/es-custom/components/file-uploads/src/file-upload-item.js +98 -58
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +20 -0
- package/es-custom/components/file-uploads/src/file-uploads.js +55 -1
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es-custom/components/markdown/index.js +1 -2
- package/es-custom/components/markdown/index.js.map +1 -1
- package/es-custom/components/markdown/src/inline-markdown.d.ts +2 -2
- package/es-custom/components/markdown/src/inline-markdown.js +8 -2
- package/es-custom/components/markdown/src/inline-markdown.js.map +1 -1
- package/es-custom/components/markdown/src/inline-markdown.scss.js +2 -2
- package/es-custom/components/markdown/src/markdown-renderer-types.d.ts +2 -0
- package/es-custom/components/markdown/src/markdown-renderer.js +3 -1
- package/es-custom/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es-custom/components/markdown/src/markdown.d.ts +4 -0
- package/es-custom/components/markdown/src/markdown.js +14 -0
- package/es-custom/components/markdown/src/markdown.js.map +1 -1
- package/es-custom/components/markdown/src/utils/inline-run-projection.js +3 -17
- package/es-custom/components/markdown/src/utils/inline-run-projection.js.map +1 -1
- package/es-custom/components/message-item-shell/index.d.ts +11 -0
- package/es-custom/components/message-item-shell/index.js +9 -0
- package/es-custom/components/message-item-shell/index.js.map +1 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.d.ts +48 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.js +91 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.js.map +1 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.scss.js +13 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.scss.js.map +1 -0
- package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +19 -2
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +9 -4
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.d.ts +17 -7
- package/es-custom/components/prompt-line/src/prompt-line.js +39 -0
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.scss.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.d.ts +2 -2
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.js +2 -2
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/editor-styles.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/editor-styles.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +3 -4
- package/es-custom/components/shared/root-styles.d.ts +30 -0
- package/es-custom/components/shared/root-styles.js +72 -0
- package/es-custom/components/shared/root-styles.js.map +1 -0
- package/es-custom/components/toolbar/src/toolbar.d.ts +14 -4
- package/es-custom/components/toolbar/src/toolbar.js +29 -6
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/user-avatar/index.d.ts +10 -0
- package/es-custom/components/user-avatar/index.js +9 -0
- package/es-custom/components/user-avatar/index.js.map +1 -0
- package/es-custom/components/user-avatar/src/user-avatar.d.ts +46 -0
- package/es-custom/components/user-avatar/src/user-avatar.js +153 -0
- package/es-custom/components/user-avatar/src/user-avatar.js.map +1 -0
- package/es-custom/components/user-avatar/src/user-avatar.scss.js +13 -0
- package/es-custom/components/user-avatar/src/user-avatar.scss.js.map +1 -0
- package/es-custom/globals/utils/iconTransform.js +1 -0
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/chat-header.js +4 -2
- package/es-custom/react/chat-header.js.map +1 -1
- package/es-custom/react/code-snippet.d.ts +4 -1
- package/es-custom/react/code-snippet.js +3 -1
- package/es-custom/react/code-snippet.js.map +1 -1
- package/es-custom/react/message-item-shell.d.ts +3 -0
- package/es-custom/react/message-item-shell.js +30 -0
- package/es-custom/react/message-item-shell.js.map +1 -0
- package/es-custom/react/toolbar.d.ts +1 -1
- package/es-custom/react/toolbar.js +3 -1
- package/es-custom/react/toolbar.js.map +1 -1
- package/es-custom/react/user-avatar.d.ts +3 -0
- package/es-custom/react/user-avatar.js +29 -0
- package/es-custom/react/user-avatar.js.map +1 -0
- package/package.json +8 -6
- package/telemetry.yml +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iconTransform.js","sources":["../../../src/globals/utils/iconTransform.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Icon Transformation Utility\n *\n * This module provides utilities to transform React icon components from @carbon/icons-react\n * into the CarbonIcon descriptor format used by @carbon/icons. This enables React developers\n * to use their familiar React icon components while maintaining compatibility with web components\n * that expect the plain JavaScript CarbonIcon format.\n *\n * Key features:\n * - Automatic transformation of React icon components to CarbonIcon descriptors\n * - No-op pass-through for CarbonIcon objects (already in correct format)\n * - Global caching to prevent redundant transformations\n * - Type guards for runtime icon format detection\n * - Support for forwardRef and memo-wrapped components\n *\n * Usage:\n * ```tsx\n * import { Add } from '@carbon/icons-react';\n * import { transformReactIconToCarbonIcon } from './iconTransform';\n *\n * const carbonIcon = transformReactIconToCarbonIcon(Add);\n * // carbonIcon is now in CarbonIcon format, ready for web components\n * ```\n */\n\nimport React, { FunctionComponent } from 'react';\nimport {\n CarbonIcon,\n CarbonIconDescriptor,\n} from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\n\ntype CarbonIconProps = React.SVGProps<SVGSVGElement> & {\n slot?: string;\n [key: string]: unknown;\n};\n\n// Global cache for transformed icons using WeakMap to key by component reference\nconst iconCache = new WeakMap<\n React.ComponentType<any>,\n Map<number, CarbonIcon>\n>();\n\n/**\n * Type guard to detect if icon is already a CarbonIcon descriptor.\n * If true, the icon should be passed through unchanged (no-op).\n */\nexport function isCarbonIcon(icon: any): icon is CarbonIcon {\n return Boolean(\n icon &&\n typeof icon === 'object' &&\n 'elem' in icon &&\n 'attrs' in icon &&\n 'content' in icon &&\n icon.elem === 'svg'\n );\n}\n\n/**\n * Transforms a React icon component to CarbonIcon format.\n * Returns the icon unchanged if it's already a CarbonIcon (no-op).\n * Caches results to avoid repeated transformations.\n */\nexport function transformReactIconToCarbonIcon(\n icon: CarbonIcon | React.ComponentType<any>,\n size = 16\n): CarbonIcon {\n // No-op: If already a CarbonIcon, return unchanged\n if (isCarbonIcon(icon)) {\n return icon;\n }\n\n const ReactIcon = icon as React.ComponentType<any>;\n\n // Get or create size map for this component\n let sizeMap = iconCache.get(ReactIcon);\n if (!sizeMap) {\n sizeMap = new Map<number, CarbonIcon>();\n iconCache.set(ReactIcon, sizeMap);\n }\n\n // Return cached result if available for this size\n const cached = sizeMap.get(size);\n if (cached) {\n return cached;\n }\n\n try {\n // Call the React component to get the React element\n const element = React.createElement(ReactIcon, { size });\n\n // Extract CarbonIcon descriptor from React element\n const descriptor = extractCarbonIconFromReactElement(element, size);\n\n // Validate descriptor\n if (!isValidCarbonIcon(descriptor)) {\n throw new Error('Generated descriptor is invalid');\n }\n\n // Cache and return\n sizeMap.set(size, descriptor);\n return descriptor;\n } catch (error) {\n const iconName = ReactIcon.displayName || ReactIcon.name || 'Unknown';\n throw new Error(\n `Failed to transform React icon \"${iconName}\": ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Extracts CarbonIcon descriptor from a React element tree\n */\nfunction extractCarbonIconFromReactElement(\n element: React.ReactElement,\n size: number\n): CarbonIcon {\n // The element should be an SVG or Icon component\n // Navigate through forwardRef and other wrappers if needed\n let currentElement = element;\n\n // Handle forwardRef wrapper\n if (\n typeof currentElement.type === 'object' &&\n 'render' in currentElement.type\n ) {\n // This is a forwardRef, call the render function\n const renderFn = (currentElement.type as any).render;\n currentElement = renderFn(currentElement.props, null);\n }\n\n // Now we should have the actual Icon element\n const props = currentElement.props as any;\n\n if (!props) {\n throw new Error('Unable to extract props from React element');\n }\n\n // Extract SVG attributes from props\n const attrs: Record<string, string | number> = {\n xmlns: props.xmlns || 'http://www.w3.org/2000/svg',\n viewBox: props.viewBox || '0 0 32 32',\n fill: props.fill || 'currentColor',\n width: size,\n height: size,\n };\n\n // Extract children (paths, circles, etc.)\n const content: any[] = [];\n const children = React.Children.toArray(props.children);\n\n children.forEach((child) => {\n if (React.isValidElement(child)) {\n const childElement = child as React.ReactElement;\n const contentItem: any = {\n elem:\n typeof childElement.type === 'string' ? childElement.type : 'path',\n attrs: {},\n };\n\n // Copy all props as attributes\n if (childElement.props) {\n Object.entries(childElement.props).forEach(([key, value]) => {\n // Skip children and other React-specific props\n if (key !== 'children' && value !== undefined && value !== null) {\n contentItem.attrs[key] = value;\n }\n });\n }\n\n content.push(contentItem);\n }\n });\n\n return {\n elem: 'svg',\n attrs,\n content,\n name: extractIconName(props),\n size,\n };\n}\n\n/**\n * Validates that a descriptor has all required CarbonIcon fields\n */\nfunction isValidCarbonIcon(descriptor: any): descriptor is CarbonIcon {\n return (\n descriptor &&\n descriptor.elem === 'svg' &&\n descriptor.attrs &&\n typeof descriptor.attrs === 'object' &&\n Array.isArray(descriptor.content) &&\n descriptor.content.length > 0 &&\n typeof descriptor.name === 'string' &&\n typeof descriptor.size === 'number'\n );\n}\n\n/**\n * Attempts to extract icon name from props\n */\nfunction extractIconName(props: any): string {\n // Try various properties that might contain the icon name\n return props['data-icon-name'] || props['aria-label'] || props.name || 'icon';\n}\n\n/**\n * Creates a React component from a `CarbonIconDescriptor` (a raw `@carbon/icons` import).\n *\n * @example\n * import Launch16 from '@carbon/icons/es/launch/16';\n * const LaunchIcon = carbonIconToReact(Launch16);\n * <LaunchIcon aria-label=\"Launch\" className=\"icon\" />\n */\nexport function carbonIconToReact(\n icon: CarbonIconDescriptor\n): FunctionComponent<CarbonIconProps> {\n return function IconComponent(props: CarbonIconProps = {}) {\n return React.createElement(\n 'svg',\n {\n ...icon.attrs,\n width: icon.attrs.width || 16,\n height: icon.attrs.height || 16,\n fill: icon.attrs.fill || 'currentColor',\n focusable: 'false',\n style: { pointerEvents: 'none' },\n ...props,\n },\n icon.content.map((child, i) =>\n React.createElement(child.elem, { key: i, ...(child.attrs || {}) })\n )\n );\n };\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AAaH;AACA,MAAM,SAAS,GAAG,IAAI,OAAO,EAG1B;AAEH;;;AAGG;AACG,SAAU,YAAY,CAAC,IAAS,EAAA;IACpC,OAAO,OAAO,CACZ,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;AACxB,QAAA,MAAM,IAAI,IAAI;AACd,QAAA,OAAO,IAAI,IAAI;AACf,QAAA,SAAS,IAAI,IAAI;AACjB,QAAA,IAAI,CAAC,IAAI,KAAK,KAAK,CACpB;AACH;AAEA;;;;AAIG;SACa,8BAA8B,CAC5C,IAA2C,EAC3C,IAAI,GAAG,EAAE,EAAA;;AAGT,IAAA,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE;AACtB,QAAA,OAAO,IAAI;IACb;IAEA,MAAM,SAAS,GAAG,IAAgC;;IAGlD,IAAI,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE;AACZ,QAAA,OAAO,GAAG,IAAI,GAAG,EAAsB;AACvC,QAAA,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;IACnC;;IAGA,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;IAChC,IAAI,MAAM,EAAE;AACV,QAAA,OAAO,MAAM;IACf;AAEA,IAAA,IAAI;;AAEF,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC;;QAGxD,MAAM,UAAU,GAAG,iCAAiC,CAAC,OAAO,EAAE,IAAI,CAAC;;AAGnE,QAAA,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AAA,UAAU,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;AAC7B,QAAA,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ;AACnC,QAAA,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ;AAEvC;AAEA;;AAEG;AACH,SAAS,eAAe,CAAC,KAAU,EAAA;;AAEjC,IAAA,OAAO,KAAK,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,MAAM;AAC/E;AAEA;;;;;;;AAOG;AACG,SAAU,iBAAiB,CAC/B,IAA0B,EAAA;AAE1B,IAAA,OAAO,SAAS,aAAa,CAAC,KAAA,GAAyB,EAAE,EAAA;AACvD,QAAA,OAAO,KAAK,CAAC,aAAa,CACxB,KAAK,EACL;YACE,GAAG,IAAI,CAAC,KAAK;AACb,YAAA,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE;AAC/B,YAAA,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,cAAc;AACvC,YAAA,SAAS,EAAE,OAAO;AAClB,YAAA,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE;AAChC,YAAA,GAAG,KAAK;AACT,SAAA,EACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KACxB,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,CACpE,CACF;AACH,IAAA,CAAC;AACH;;"}
|
|
1
|
+
{"version":3,"file":"iconTransform.js","sources":["../../../src/globals/utils/iconTransform.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\n/**\n * Icon Transformation Utility\n *\n * This module provides utilities to transform React icon components from @carbon/icons-react\n * into the CarbonIcon descriptor format used by @carbon/icons. This enables React developers\n * to use their familiar React icon components while maintaining compatibility with web components\n * that expect the plain JavaScript CarbonIcon format.\n *\n * Key features:\n * - Automatic transformation of React icon components to CarbonIcon descriptors\n * - No-op pass-through for CarbonIcon objects (already in correct format)\n * - Global caching to prevent redundant transformations\n * - Type guards for runtime icon format detection\n * - Support for forwardRef and memo-wrapped components\n *\n * Usage:\n * ```tsx\n * import { Add } from '@carbon/icons-react';\n * import { transformReactIconToCarbonIcon } from './iconTransform';\n *\n * const carbonIcon = transformReactIconToCarbonIcon(Add);\n * // carbonIcon is now in CarbonIcon format, ready for web components\n * ```\n */\n\nimport React, { FunctionComponent } from 'react';\nimport {\n CarbonIcon,\n CarbonIconDescriptor,\n} from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\n\ntype CarbonIconProps = React.SVGProps<SVGSVGElement> & {\n slot?: string;\n [key: string]: unknown;\n};\n\n// Global cache for transformed icons using WeakMap to key by component reference\nconst iconCache = new WeakMap<\n React.ComponentType<any>,\n Map<number, CarbonIcon>\n>();\n\n/**\n * Type guard to detect if icon is already a CarbonIcon descriptor.\n * If true, the icon should be passed through unchanged (no-op).\n */\nexport function isCarbonIcon(icon: any): icon is CarbonIcon {\n return Boolean(\n icon &&\n typeof icon === 'object' &&\n 'elem' in icon &&\n 'attrs' in icon &&\n 'content' in icon &&\n icon.elem === 'svg'\n );\n}\n\n/**\n * Transforms a React icon component to CarbonIcon format.\n * Returns the icon unchanged if it's already a CarbonIcon (no-op).\n * Caches results to avoid repeated transformations.\n */\nexport function transformReactIconToCarbonIcon(\n icon: CarbonIcon | React.ComponentType<any>,\n size = 16\n): CarbonIcon {\n // No-op: If already a CarbonIcon, return unchanged\n if (isCarbonIcon(icon)) {\n return icon;\n }\n\n const ReactIcon = icon as React.ComponentType<any>;\n\n // Get or create size map for this component\n let sizeMap = iconCache.get(ReactIcon);\n if (!sizeMap) {\n sizeMap = new Map<number, CarbonIcon>();\n iconCache.set(ReactIcon, sizeMap);\n }\n\n // Return cached result if available for this size\n const cached = sizeMap.get(size);\n if (cached) {\n return cached;\n }\n\n try {\n // Call the React component to get the React element\n const element = React.createElement(ReactIcon, { size });\n\n // Extract CarbonIcon descriptor from React element\n const descriptor = extractCarbonIconFromReactElement(element, size);\n\n // Validate descriptor\n if (!isValidCarbonIcon(descriptor)) {\n throw new Error('Generated descriptor is invalid');\n }\n\n // Cache and return\n sizeMap.set(size, descriptor);\n return descriptor;\n } catch (error) {\n const iconName = ReactIcon.displayName || ReactIcon.name || 'Unknown';\n throw new Error(\n `Failed to transform React icon \"${iconName}\": ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Extracts CarbonIcon descriptor from a React element tree\n */\nfunction extractCarbonIconFromReactElement(\n element: React.ReactElement,\n size: number\n): CarbonIcon {\n // The element should be an SVG or Icon component\n // Navigate through forwardRef and other wrappers if needed\n let currentElement = element;\n\n // Handle forwardRef wrapper\n if (\n typeof currentElement.type === 'object' &&\n 'render' in currentElement.type\n ) {\n // This is a forwardRef, call the render function\n const renderFn = (currentElement.type as any).render;\n currentElement = renderFn(currentElement.props, null);\n }\n\n // Now we should have the actual Icon element\n const props = currentElement.props as any;\n\n if (!props) {\n throw new Error('Unable to extract props from React element');\n }\n\n // Extract SVG attributes from props\n const attrs: Record<string, string | number> = {\n xmlns: props.xmlns || 'http://www.w3.org/2000/svg',\n viewBox: props.viewBox || '0 0 32 32',\n fill: props.fill || 'currentColor',\n width: size,\n height: size,\n };\n\n // Extract children (paths, circles, etc.)\n const content: any[] = [];\n const children = React.Children.toArray(props.children);\n\n children.forEach((child) => {\n if (React.isValidElement(child)) {\n const childElement = child as React.ReactElement;\n const contentItem: any = {\n elem:\n typeof childElement.type === 'string' ? childElement.type : 'path',\n attrs: {},\n };\n\n // Copy all props as attributes\n if (childElement.props) {\n Object.entries(childElement.props).forEach(([key, value]) => {\n // Skip children and other React-specific props\n if (key !== 'children' && value !== undefined && value !== null) {\n contentItem.attrs[key] = value;\n }\n });\n }\n\n content.push(contentItem);\n }\n });\n\n return {\n elem: 'svg',\n attrs,\n content,\n name: extractIconName(props),\n size,\n };\n}\n\n/**\n * Validates that a descriptor has all required CarbonIcon fields\n */\nfunction isValidCarbonIcon(descriptor: any): descriptor is CarbonIcon {\n return (\n descriptor &&\n descriptor.elem === 'svg' &&\n descriptor.attrs &&\n typeof descriptor.attrs === 'object' &&\n Array.isArray(descriptor.content) &&\n descriptor.content.length > 0 &&\n typeof descriptor.name === 'string' &&\n typeof descriptor.size === 'number'\n );\n}\n\n/**\n * Attempts to extract icon name from props\n */\nfunction extractIconName(props: any): string {\n // Try various properties that might contain the icon name\n return props['data-icon-name'] || props['aria-label'] || props.name || 'icon';\n}\n\n/**\n * Creates a React component from a `CarbonIconDescriptor` (a raw `@carbon/icons` import).\n *\n * @example\n * import Launch16 from '@carbon/icons/es/launch/16';\n * const LaunchIcon = carbonIconToReact(Launch16);\n * <LaunchIcon aria-label=\"Launch\" className=\"icon\" />\n */\nexport function carbonIconToReact(\n icon: CarbonIconDescriptor\n): FunctionComponent<CarbonIconProps> {\n return function IconComponent(props: CarbonIconProps = {}) {\n return React.createElement(\n 'svg',\n {\n ...icon.attrs,\n width: icon.attrs.width || 16,\n height: icon.attrs.height || 16,\n fill: icon.attrs.fill || 'currentColor',\n focusable: 'false',\n tabIndex: -1,\n style: { pointerEvents: 'none' },\n ...props,\n },\n icon.content.map((child, i) =>\n React.createElement(child.elem, { key: i, ...(child.attrs || {}) })\n )\n );\n };\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AAaH;AACA,MAAM,SAAS,GAAG,IAAI,OAAO,EAG1B;AAEH;;;AAGG;AACG,SAAU,YAAY,CAAC,IAAS,EAAA;IACpC,OAAO,OAA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iB,CAC/B,IAA0B,EAAA;AAE1B,IAAA,OAAO,SAAS,aAAa,CAAC,KAAA,GAAyB,EAAE,EAAA;AACvD,QAAA,OAAO,KAAK,CAAC,aAAa,CACxB,KAAK,EACL;YACE,GAAG,IAAI,CAAC,KAAK;AACb,YAAA,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE;AAC/B,YAAA,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,cAAc;AACvC,YAAA,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE,EAAE;AACZ,YAAA,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE;AAChC,YAAA,GAAG,KAAK;AACT,SAAA,EACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KACxB,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,CACpE,CACF;AACH,IAAA,CAAC;AACH;;"}
|
|
@@ -40,11 +40,13 @@ const ChatHeader = React.forwardRef((props, ref) => {
|
|
|
40
40
|
// Transform action icons if actions are provided
|
|
41
41
|
const transformedActions = React.useMemo(() => {
|
|
42
42
|
if (!actions) {
|
|
43
|
-
return
|
|
43
|
+
return [];
|
|
44
44
|
}
|
|
45
45
|
return actions.map((action) => ({
|
|
46
46
|
...action,
|
|
47
|
-
icon:
|
|
47
|
+
icon: action.icon
|
|
48
|
+
? transformReactIconToCarbonIcon(action.icon, 16)
|
|
49
|
+
: undefined,
|
|
48
50
|
}));
|
|
49
51
|
}, [actions]);
|
|
50
52
|
return (jsx(BaseChatHeader, { ref: ref, navigationBackIcon: transformedNavigationBackIcon, navigationOverflowIcon: transformedNavigationOverflowIcon, actions: transformedActions, ...restProps }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-header.js","sources":["../../src/react/chat-header.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport CdsAiChatChatHeader from '../components/chat-shell/src/chat-header.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\nimport type { ToolbarAction } from './toolbar.js';\n\nexport interface ChatHeaderProps {\n /** Array of actions that can overflow into a menu when space is limited. */\n actions?: ToolbarAction[];\n\n /** Enable overflow behavior for actions. */\n overflow?: boolean;\n\n /** Optional header title text to display. */\n headerTitle?: string;\n\n /** Optional name text to display after the title. */\n headerName?: string;\n\n /** Type of navigation to display: 'back', 'overflow', or 'none'. */\n navigationType?: 'back' | 'overflow' | 'none';\n\n /** Icon for the back button (CarbonIcon object). */\n navigationBackIcon?: any;\n\n /** Label/tooltip text for the back button. */\n navigationBackLabel?: string;\n\n /** Click handler for the back button. */\n navigationBackOnClick?: () => void;\n\n /** Array of overflow menu items with text and onClick handlers. */\n navigationOverflowItems?: Array<{\n text: string;\n onClick?: () => void;\n href?: string;\n target?: string;\n disabled?: boolean;\n testId?: string;\n }>;\n\n /** Label/tooltip text for the overflow menu button. */\n navigationOverflowLabel?: string;\n\n /** ARIA label for the overflow menu. */\n navigationOverflowAriaLabel?: string;\n\n /** Click handler for when the overflow menu button is clicked (menu opened). */\n navigationOverflowOnClick?: () => void;\n}\n\n/**\n * Extended interface that includes the imperative handle methods.\n * Use with React.useRef<ChatHeaderHandle>() to access focus management.\n *\n * @example\n * ```tsx\n * const headerRef = useRef<ChatHeaderHandle>(null);\n *\n * const handleFocusRequest = () => {\n * const focused = headerRef.current?.requestFocus();\n * if (!focused) {\n * // Try focusing somewhere else, like the input field\n * inputRef.current?.focus();\n * }\n * };\n * ```\n */\nexport interface ChatHeaderHandle {\n /**\n * Requests focus on the best available focusable element within the component.\n * Returns true if focus was successfully set, false otherwise.\n *\n * Priority order:\n * 1. First enabled button in fixed-actions slot (usually close button)\n * 2. First enabled button in navigation slot (back button or overflow menu)\n * 3. First enabled action button from actions array\n * 4. Any other focusable element\n */\n requestFocus(): boolean;\n}\n\n// Base chat header component from @lit/react\nconst BaseChatHeader = withWebComponentBridge(\n createComponent({\n tagName: 'cds-custom-aichat-chat-header',\n elementClass: CdsAiChatChatHeader,\n react: React,\n })\n);\n\n/**\n * ChatHeader component with automatic icon transformation support.\n *\n * Accepts navigation icons as either CarbonIcon objects or React icon components from @carbon/icons-react.\n * React icons are automatically transformed to the CarbonIcon format expected by the web component.\n */\nconst ChatHeader = React.forwardRef<any, any>((props, ref) => {\n const { navigationBackIcon, navigationOverflowIcon, actions, ...restProps } =\n props;\n\n // Transform navigation icons if they're React components\n const transformedNavigationBackIcon = React.useMemo(() => {\n return navigationBackIcon\n ? transformReactIconToCarbonIcon(navigationBackIcon, 16)\n : undefined;\n }, [navigationBackIcon]);\n\n const transformedNavigationOverflowIcon = React.useMemo(() => {\n return navigationOverflowIcon\n ? transformReactIconToCarbonIcon(navigationOverflowIcon, 16)\n : undefined;\n }, [navigationOverflowIcon]);\n\n // Transform action icons if actions are provided\n const transformedActions = React.useMemo(() => {\n if (!actions) {\n return
|
|
1
|
+
{"version":3,"file":"chat-header.js","sources":["../../src/react/chat-header.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport CdsAiChatChatHeader from '../components/chat-shell/src/chat-header.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\nimport type { ToolbarAction } from './toolbar.js';\n\nexport interface ChatHeaderProps {\n /** Array of actions that can overflow into a menu when space is limited. */\n actions?: ToolbarAction[];\n\n /** Enable overflow behavior for actions. */\n overflow?: boolean;\n\n /** Optional header title text to display. */\n headerTitle?: string;\n\n /** Optional name text to display after the title. */\n headerName?: string;\n\n /** Type of navigation to display: 'back', 'overflow', or 'none'. */\n navigationType?: 'back' | 'overflow' | 'none';\n\n /** Icon for the back button (CarbonIcon object). */\n navigationBackIcon?: any;\n\n /** Label/tooltip text for the back button. */\n navigationBackLabel?: string;\n\n /** Click handler for the back button. */\n navigationBackOnClick?: () => void;\n\n /** Array of overflow menu items with text and onClick handlers. */\n navigationOverflowItems?: Array<{\n text: string;\n onClick?: () => void;\n href?: string;\n target?: string;\n disabled?: boolean;\n testId?: string;\n }>;\n\n /** Label/tooltip text for the overflow menu button. */\n navigationOverflowLabel?: string;\n\n /** ARIA label for the overflow menu. */\n navigationOverflowAriaLabel?: string;\n\n /** Click handler for when the overflow menu button is clicked (menu opened). */\n navigationOverflowOnClick?: () => void;\n}\n\n/**\n * Extended interface that includes the imperative handle methods.\n * Use with React.useRef<ChatHeaderHandle>() to access focus management.\n *\n * @example\n * ```tsx\n * const headerRef = useRef<ChatHeaderHandle>(null);\n *\n * const handleFocusRequest = () => {\n * const focused = headerRef.current?.requestFocus();\n * if (!focused) {\n * // Try focusing somewhere else, like the input field\n * inputRef.current?.focus();\n * }\n * };\n * ```\n */\nexport interface ChatHeaderHandle {\n /**\n * Requests focus on the best available focusable element within the component.\n * Returns true if focus was successfully set, false otherwise.\n *\n * Priority order:\n * 1. First enabled button in fixed-actions slot (usually close button)\n * 2. First enabled button in navigation slot (back button or overflow menu)\n * 3. First enabled action button from actions array\n * 4. Any other focusable element\n */\n requestFocus(): boolean;\n}\n\n// Base chat header component from @lit/react\nconst BaseChatHeader = withWebComponentBridge(\n createComponent({\n tagName: 'cds-custom-aichat-chat-header',\n elementClass: CdsAiChatChatHeader,\n react: React,\n })\n);\n\n/**\n * ChatHeader component with automatic icon transformation support.\n *\n * Accepts navigation icons as either CarbonIcon objects or React icon components from @carbon/icons-react.\n * React icons are automatically transformed to the CarbonIcon format expected by the web component.\n */\nconst ChatHeader = React.forwardRef<any, any>((props, ref) => {\n const { navigationBackIcon, navigationOverflowIcon, actions, ...restProps } =\n props;\n\n // Transform navigation icons if they're React components\n const transformedNavigationBackIcon = React.useMemo(() => {\n return navigationBackIcon\n ? transformReactIconToCarbonIcon(navigationBackIcon, 16)\n : undefined;\n }, [navigationBackIcon]);\n\n const transformedNavigationOverflowIcon = React.useMemo(() => {\n return navigationOverflowIcon\n ? transformReactIconToCarbonIcon(navigationOverflowIcon, 16)\n : undefined;\n }, [navigationOverflowIcon]);\n\n // Transform action icons if actions are provided\n const transformedActions = React.useMemo(() => {\n if (!actions) {\n return [];\n }\n\n return actions.map((action: ToolbarAction) => ({\n ...action,\n icon: action.icon\n ? transformReactIconToCarbonIcon(action.icon, 16)\n : undefined,\n }));\n }, [actions]);\n\n return (\n <BaseChatHeader\n ref={ref}\n navigationBackIcon={transformedNavigationBackIcon}\n navigationOverflowIcon={transformedNavigationOverflowIcon}\n actions={transformedActions}\n {...restProps}\n />\n );\n});\n\nChatHeader.displayName = 'ChatHeader';\n\nexport default ChatHeader;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;AA4FA;AACA,MAAM,cAAc,GAAG,sBAAsB,CAC3C,eAAe,CAAC;AACd,IAAA,OAAO,EAAE,wBAAwB;AACjC,IAAA,YAAY,EAAE,mBAAmB;AACjC,IAAA,KAAK,EAAE,KAAK;AACb,CAAA,CAAC,CACH;AAED;;;;;AAKG;AACH,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAW,CAAC,KAAK,EAAE,GAAG,KAAI;AAC3D,IAAA,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GACzE,KAAK;;AAGP,IAAA,MAAM,6BAA6B,GAAG,KAAK,CAAC,OAAO,CAAC,MAAK;AACvD,QAAA,OAAO;AACL,cAAE,8BAA8B,CAAC,kBAAkB,EAAE,EAAE;cACrD,SAAS;AACf,IAAA,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC;AAExB,IAAA,MAAM,iCAAiC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAK;AAC3D,QAAA,OAAO;AACL,cAAE,8BAA8B,CAAC,sBAAsB,EAAE,EAAE;cACzD,SAAS;AACf,IAAA,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC;;AAG5B,IAAA,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,MAAK;QAC5C,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,EAAE;QACX;QAEA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAqB,MAAM;AAC7C,YAAA,GAAG,MAAM;YACT,IAAI,EAAE,MAAM,CAAC;kBACT,8BAA8B,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;AAChD,kBAAE,SAAS;AACd,SAAA,CAAC,CAAC;AACL,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEb,QACEA,IAAC,cAAc,EAAA,EACb,GAAG,EAAE,GAAG,EACR,kBAAkB,EAAE,6BAA6B,EACjD,sBAAsB,EAAE,iCAAiC,EACzD,OAAO,EAAE,kBAAkB,EAAA,GACvB,SAAS,EAAA,CACb;AAEN,CAAC;AAED,UAAU,CAAC,WAAW,GAAG,YAAY;;"}
|
|
@@ -8,9 +8,12 @@ export type { Action } from '../components/code-snippet/src/code-snippet.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface ReactAction {
|
|
10
10
|
text: string;
|
|
11
|
-
icon
|
|
11
|
+
icon?: CarbonIcon | React.ComponentType<any>;
|
|
12
12
|
size?: BUTTON_SIZE;
|
|
13
13
|
fixed?: boolean;
|
|
14
|
+
isSelected?: boolean;
|
|
15
|
+
feedback?: string;
|
|
16
|
+
feedbackTimeout?: number;
|
|
14
17
|
onClick: () => void;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
@@ -50,7 +50,9 @@ const CodeSnippet = React.forwardRef((props, ref) => {
|
|
|
50
50
|
}
|
|
51
51
|
return actions.map((action) => ({
|
|
52
52
|
...action,
|
|
53
|
-
icon:
|
|
53
|
+
icon: action.icon
|
|
54
|
+
? transformReactIconToCarbonIcon(action.icon, 16)
|
|
55
|
+
: undefined,
|
|
54
56
|
}));
|
|
55
57
|
}, [actions]);
|
|
56
58
|
// Separate slotted children from default content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-snippet.js","sources":["../../src/react/code-snippet.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport { CarbonIcon } from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\nimport { BUTTON_SIZE } from '@carbon/web-components/es-custom/components/button/defs.js';\n\n// Export the actual class for the component that will *directly* be wrapped with React.\nimport CDSAIChatCodeSnippet from '../components/code-snippet/src/code-snippet.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\n\n// Re-export the Action interface from the web component\nexport type { Action } from '../components/code-snippet/src/code-snippet.js';\n\n/**\n * React-specific Action interface that accepts both CarbonIcon and React icon components.\n * This allows React developers to use @carbon/icons-react directly.\n */\nexport interface ReactAction {\n text: string;\n icon
|
|
1
|
+
{"version":3,"file":"code-snippet.js","sources":["../../src/react/code-snippet.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport { CarbonIcon } from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\nimport { BUTTON_SIZE } from '@carbon/web-components/es-custom/components/button/defs.js';\n\n// Export the actual class for the component that will *directly* be wrapped with React.\nimport CDSAIChatCodeSnippet from '../components/code-snippet/src/code-snippet.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\n\n// Re-export the Action interface from the web component\nexport type { Action } from '../components/code-snippet/src/code-snippet.js';\n\n/**\n * React-specific Action interface that accepts both CarbonIcon and React icon components.\n * This allows React developers to use @carbon/icons-react directly.\n */\nexport interface ReactAction {\n text: string;\n icon?: CarbonIcon | React.ComponentType<any>;\n size?: BUTTON_SIZE;\n fixed?: boolean;\n isSelected?: boolean;\n feedback?: string;\n feedbackTimeout?: number;\n onClick: () => void;\n}\n\n// Base code snippet component from @lit/react\nconst BaseCodeSnippet = withWebComponentBridge(\n createComponent({\n tagName: 'cds-custom-aichat-code-snippet',\n elementClass: CDSAIChatCodeSnippet,\n react: React,\n events: {\n onChange: 'content-change',\n },\n })\n);\n\n/**\n * CodeSnippet component with automatic icon transformation support.\n *\n * Accepts actions with either CarbonIcon objects or React icon components from @carbon/icons-react.\n * React icons are automatically transformed to the CarbonIcon format expected by the web component.\n *\n * @example\n * ```tsx\n * import { Download } from '@carbon/icons-react';\n * import CodeSnippet from '@carbon/ai-chat-components/es/react/code-snippet.js';\n *\n * const actions = [\n * { text: 'Download', icon: Download, onClick: () => console.log('Download') }\n * ];\n *\n * <CodeSnippet language=\"typescript\" highlight actions={actions} overflow>\n * {code}\n * </CodeSnippet>\n * ```\n */\nconst CodeSnippet = React.forwardRef<any, any>((props, ref) => {\n const { actions, children, ...restProps } = props;\n\n // Transform action icons if actions are provided\n const transformedActions = React.useMemo(() => {\n if (!actions || !Array.isArray(actions)) {\n return [];\n }\n\n return actions.map((action: ReactAction) => ({\n ...action,\n icon: action.icon\n ? transformReactIconToCarbonIcon(action.icon, 16)\n : undefined,\n }));\n }, [actions]);\n\n // Separate slotted children from default content\n const { slottedChildren, defaultChildren } = React.useMemo(() => {\n const slotted: Record<string, React.ReactNode[]> = {};\n const defaultContent: React.ReactNode[] = [];\n\n React.Children.forEach(children, (child) => {\n if (React.isValidElement(child)) {\n const childProps = child.props as any;\n if (childProps.slot) {\n const slotName = childProps.slot as string;\n if (!slotted[slotName]) {\n slotted[slotName] = [];\n }\n // Clone the element without the slot prop to avoid React warnings\n const { slot: _slot, ...restChildProps } = childProps;\n slotted[slotName].push(React.cloneElement(child, restChildProps));\n } else {\n defaultContent.push(child);\n }\n } else {\n defaultContent.push(child);\n }\n });\n\n return { slottedChildren: slotted, defaultChildren: defaultContent };\n }, [children]);\n\n return (\n <BaseCodeSnippet ref={ref} actions={transformedActions} {...restProps}>\n {Object.entries(slottedChildren).map(([slotName, nodes]) => (\n <div key={slotName} slot={slotName}>\n {nodes}\n </div>\n ))}\n {defaultChildren}\n </BaseCodeSnippet>\n );\n});\n\nCodeSnippet.displayName = 'CodeSnippet';\n\nexport default CodeSnippet;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;AAqCA;AACA,MAAM,eAAe,GAAG,sBAAsB,CAC5C,eAAe,CAAC;AACd,IAAA,OAAO,EAAE,yBAAyB;AAClC,IAAA,YAAY,EAAE,oBAAoB;AAClC,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,MAAM,EAAE;AACN,QAAA,QAAQ,EAAE,gBAAgB;AAC3B,KAAA;AACF,CAAA,CAAC,CACH;AAED;;;;;;;;;;;;;;;;;;;AAmBG;AACH,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAW,CAAC,KAAK,EAAE,GAAG,KAAI;IAC5D,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK;;AAGjD,IAAA,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,MAAK;QAC5C,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;AACvC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AAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEd,QACEA,KAAC,eAAe,EAAA,EAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,KAAM,SAAS,EAAA,QAAA,EAAA,CAClE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,MACrDC,GAAA,CAAA,KAAA,EAAA,EAAoB,IAAI,EAAE,QAAQ,YAC/B,KAAK,EAAA,EADE,QAAQ,CAEZ,CACP,CAAC,EACD,eAAe,CAAA,EAAA,CACA;AAEtB,CAAC;AAED,WAAW,CAAC,WAAW,GAAG,aAAa;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createComponent } from '@lit/react';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import prefix from '../globals/settings.js';
|
|
11
|
+
import CDSAIChatMessageItemShell from '../components/message-item-shell/src/message-item-shell.js';
|
|
12
|
+
import { withWebComponentBridge } from './utils/withWebComponentBridge.js';
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Copyright IBM Corp. 2026
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
* @license
|
|
21
|
+
*/
|
|
22
|
+
const MessageItemShell = withWebComponentBridge(createComponent({
|
|
23
|
+
tagName: `${prefix}-message-item-shell`,
|
|
24
|
+
elementClass: CDSAIChatMessageItemShell,
|
|
25
|
+
react: React,
|
|
26
|
+
events: {},
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
export { MessageItemShell as default };
|
|
30
|
+
//# sourceMappingURL=message-item-shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-item-shell.js","sources":["../../src/react/message-item-shell.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport prefix from '../globals/settings.js';\nimport CDSAIChatMessageItemShell from '../components/message-item-shell/src/message-item-shell.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\n\nconst MessageItemShell = withWebComponentBridge(\n createComponent({\n tagName: `${prefix}-message-item-shell`,\n elementClass: CDSAIChatMessageItemShell,\n react: React,\n events: {},\n })\n);\n\nexport default MessageItemShell;\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAQH,MAAM,gBAAgB,GAAG,sBAAsB,CAC7C,eAAe,CAAC;IACd,OAAO,EAAE,CAAA,EAAG,MAAM,CAAA,mBAAA,CAAqB;AACvC,IAAA,YAAY,EAAE,yBAAyB;AACvC,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,MAAM,EAAE,EAAE;AACX,CAAA,CAAC;;"}
|
|
@@ -13,7 +13,7 @@ export interface ToolbarAction extends Omit<Action, 'icon'> {
|
|
|
13
13
|
/**
|
|
14
14
|
* Either an icon from `@carbon/icons` or from `@carbon/icons-react`.
|
|
15
15
|
*/
|
|
16
|
-
icon
|
|
16
|
+
icon?: CarbonIcon | ComponentType<any>;
|
|
17
17
|
}
|
|
18
18
|
declare const Toolbar: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
|
|
19
19
|
export type { Action };
|
|
@@ -67,7 +67,9 @@ const Toolbar = React.forwardRef((props, ref) => {
|
|
|
67
67
|
}
|
|
68
68
|
return actions.map((action) => ({
|
|
69
69
|
...action,
|
|
70
|
-
icon:
|
|
70
|
+
icon: action.icon
|
|
71
|
+
? transformReactIconToCarbonIcon(action.icon, getSizeInPixels(action.size))
|
|
72
|
+
: undefined,
|
|
71
73
|
// Preserve testId if provided
|
|
72
74
|
testId: action.testId,
|
|
73
75
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","sources":["../../src/react/toolbar.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React, { ComponentType } from 'react';\nimport { CarbonIcon } from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\n\n// Export the actual class for the component that will *directly* be wrapped with React.\nimport CDSAIChatToolbar, { Action } from '../components/toolbar/src/toolbar.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\n\n/**\n * Toolbar action interface that accepts both CarbonIcon and React icon components.\n * This allows developers to use either:\n * - @carbon/icons-react (React components)\n * - @carbon/web-components icons (CarbonIcon objects)\n *\n * Works with both React and web component implementations.\n */\nexport interface ToolbarAction extends Omit<Action, 'icon'> {\n /**\n * Either an icon from `@carbon/icons` or from `@carbon/icons-react`.\n */\n icon
|
|
1
|
+
{"version":3,"file":"toolbar.js","sources":["../../src/react/toolbar.tsx"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React, { ComponentType } from 'react';\nimport { CarbonIcon } from '@carbon/web-components/es-custom/globals/internal/icon-loader-utils.js';\n\n// Export the actual class for the component that will *directly* be wrapped with React.\nimport CDSAIChatToolbar, { Action } from '../components/toolbar/src/toolbar.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\nimport { transformReactIconToCarbonIcon } from '../globals/utils/iconTransform.js';\n\n/**\n * Toolbar action interface that accepts both CarbonIcon and React icon components.\n * This allows developers to use either:\n * - @carbon/icons-react (React components)\n * - @carbon/web-components icons (CarbonIcon objects)\n *\n * Works with both React and web component implementations.\n */\nexport interface ToolbarAction extends Omit<Action, 'icon'> {\n /**\n * Either an icon from `@carbon/icons` or from `@carbon/icons-react`.\n */\n icon?: CarbonIcon | ComponentType<any>;\n}\n\n// Base toolbar component from @lit/react\nconst BaseToolbar = withWebComponentBridge(\n createComponent({\n tagName: 'cds-custom-aichat-toolbar',\n elementClass: CDSAIChatToolbar,\n react: React,\n })\n);\n\n/**\n * Toolbar component with automatic icon transformation support.\n *\n * Accepts actions with either CarbonIcon objects or React icon components from @carbon/icons-react.\n * React icons are automatically transformed to the CarbonIcon format expected by the web component.\n *\n * @example\n * ```tsx\n * import { Add, Edit } from '@carbon/icons-react';\n * import Toolbar from '@carbon/ai-chat-components/es/react/toolbar.js';\n *\n * const actions = [\n * { text: 'Add', icon: Add, onClick: () => console.log('Add') },\n * { text: 'Edit', icon: Edit, onClick: () => console.log('Edit') }\n * ];\n *\n * <Toolbar actions={actions} overflow />\n * ```\n */\n/**\n * Converts size string to numeric pixel value\n */\nfunction getSizeInPixels(size?: string): number {\n if (!size) {\n return 16;\n }\n\n // If it's already a number string, parse it\n const parsed = parseInt(size, 10);\n if (!isNaN(parsed)) {\n return parsed;\n }\n\n // Map size names to pixel values (Carbon Design System standard sizes)\n const sizeMap: Record<string, number> = {\n sm: 16,\n md: 20,\n lg: 24,\n xl: 32,\n };\n\n return sizeMap[size.toLowerCase()] || 16;\n}\n\nconst Toolbar = React.forwardRef<any, any>((props, ref) => {\n const { actions, ...restProps } = props;\n\n // Transform React icons to CarbonIcon format\n const transformedActions = React.useMemo(() => {\n if (!actions) {\n return [];\n }\n\n return actions.map((action: ToolbarAction) => ({\n ...action,\n icon: action.icon\n ? transformReactIconToCarbonIcon(\n action.icon,\n getSizeInPixels(action.size)\n )\n : undefined,\n // Preserve testId if provided\n testId: action.testId,\n }));\n }, [actions]);\n\n return <BaseToolbar ref={ref} actions={transformedActions} {...restProps} />;\n});\n\nToolbar.displayName = 'Toolbar';\n\nexport type { Action };\n\nexport default Toolbar;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;AAiCA;AACA,MAAM,WAAW,GAAG,sBAAsB,CACxC,eAAe,CAAC;AACd,IAAA,OAAO,EAAE,oBAAoB;AAC7B,IAAA,YAAY,EAAE,gBAAgB;AAC9B,IAAA,KAAK,EAAE,KAAK;AACb,CAAA,CAAC,CACH;AAED;;;;;;;;;;;;;;;;;;AAkBG;AACH;;AAEG;AACH,SAAS,eAAe,CAAC,IAAa,EAAA;IACpC,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,EAAE;IACX;;IAGA,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;AACjC,IAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AAClB,QAAA,OAAO,MAAM;IACf;;AAGA,IAAA,MAAM,OAAO,GAA2B;AACtC,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,EAAE,EAAE,EAAE;KACP;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;AAC1C;AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAW,CAAC,KAAK,EAAE,GAAG,KAAI;IACxD,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK;;AAGvC,IAAA,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,MAAK;QAC5C,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,EAAE;QACX;QAEA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAqB,MAAM;AAC7C,YAAA,GAAG,MAAM;YACT,IAAI,EAAE,MAAM,CAAC;AACX,kBAAE,8BAA8B,CAC5B,MAAM,CAAC,IAAI,EACX,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC;AAEhC,kBAAE,SAAS;;YAEb,MAAM,EAAE,MAAM,CAAC,MAAM;AACtB,SAAA,CAAC,CAAC;AACL,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAEb,IAAA,OAAOA,GAAA,CAAC,WAAW,EAAA,EAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,EAAA,GAAM,SAAS,GAAI;AAC9E,CAAC;AAED,OAAO,CAAC,WAAW,GAAG,SAAS;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createComponent } from '@lit/react';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import prefix from '../globals/settings.js';
|
|
11
|
+
import CDSAIChatUserAvatar from '../components/user-avatar/src/user-avatar.js';
|
|
12
|
+
import { withWebComponentBridge } from './utils/withWebComponentBridge.js';
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Copyright IBM Corp. 2026
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
* @license
|
|
21
|
+
*/
|
|
22
|
+
const UserAvatar = withWebComponentBridge(createComponent({
|
|
23
|
+
tagName: `${prefix}-user-avatar`,
|
|
24
|
+
elementClass: CDSAIChatUserAvatar,
|
|
25
|
+
react: React,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
export { UserAvatar as default };
|
|
29
|
+
//# sourceMappingURL=user-avatar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-avatar.js","sources":["../../src/react/user-avatar.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { createComponent } from '@lit/react';\nimport React from 'react';\nimport prefix from '../globals/settings.js';\nimport CDSAIChatUserAvatar from '../components/user-avatar/src/user-avatar.js';\nimport { withWebComponentBridge } from './utils/withWebComponentBridge.js';\n\nconst UserAvatar = withWebComponentBridge(\n createComponent({\n tagName: `${prefix}-user-avatar`,\n elementClass: CDSAIChatUserAvatar,\n react: React,\n })\n);\n\nexport default UserAvatar;\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAQH,MAAM,UAAU,GAAG,sBAAsB,CACvC,eAAe,CAAC;IACd,OAAO,EAAE,CAAA,EAAG,MAAM,CAAA,YAAA,CAAc;AAChC,IAAA,YAAY,EAAE,mBAAmB;AACjC,IAAA,KAAK,EAAE,KAAK;AACb,CAAA,CAAC;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/ai-chat-components",
|
|
3
3
|
"description": "AI Chat Components",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.15.0-rc.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "npm run clean && node tasks/build.js && node tasks/build-dist.js && npm run custom-elements",
|
|
34
|
-
"clean": "rimraf es es-custom dist storybook-static",
|
|
34
|
+
"clean": "rimraf es es-custom dist storybook-static custom-elements.json",
|
|
35
35
|
"custom-elements": "cem analyze --config ./custom-elements-manifest.config.js",
|
|
36
36
|
"postinstall": "ibmtelemetry --config=telemetry.yml",
|
|
37
37
|
"start": "concurrently --names storybook,storybook-react,build --prefix-colors cyan,magenta,yellow --restart-tries Infinity --restart-after 2000 \"npm run storybook\" \"npm run storybook:react\" \"node tasks/build.js --watch\"",
|
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
"storybook:react": "storybook dev -p 7007 -c .storybook-react",
|
|
41
41
|
"storybook:react:build": "storybook build -c .storybook-react -o storybook-react-static",
|
|
42
42
|
"telemetry:config": "npx -y @ibm/telemetry-js-config-generator generate --id 62aa153d-8a70-4d12-9e8d-069511e80e65 --endpoint https://www-api.ibm.com/ibm-telemetry/v1/metrics --files ./src/components --wc",
|
|
43
|
-
"test": "npm run test:web-components && npm run test:react",
|
|
43
|
+
"test": "npm run test:manifest && npm run test:web-components && npm run test:react",
|
|
44
44
|
"test:react": "jest",
|
|
45
|
-
"test:updateSnapshot": "web-test-runner \"src/components/**/*.test.ts\" --node-resolve --update-snapshots",
|
|
46
|
-
"test:web-components": "web-test-runner \"src/components/**/*.test.ts\" --node-resolve"
|
|
45
|
+
"test:updateSnapshot": "web-test-runner \"src/components/**/*.test.ts\" \"src/globals/utils/__tests__/aria-announcer-manager.test.ts\" --node-resolve --update-snapshots",
|
|
46
|
+
"test:web-components": "web-test-runner \"src/components/**/*.test.ts\" \"src/globals/utils/__tests__/aria-announcer-manager.test.ts\" --node-resolve",
|
|
47
|
+
"test:manifest": "node --test \"tasks/__tests__/*.test.js\""
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"react": ">=17.0.0 <20.0.0"
|
|
@@ -158,5 +159,6 @@
|
|
|
158
159
|
"vite": "^8.0.16",
|
|
159
160
|
"web-dev-server-plugin-lit-css": "^4.0.0"
|
|
160
161
|
},
|
|
161
|
-
"
|
|
162
|
+
"customElements": "./custom-elements.json",
|
|
163
|
+
"gitHead": "186aee6f33ae33dadcad14ba6523f3297c62c1e4"
|
|
162
164
|
}
|
package/telemetry.yml
CHANGED
|
@@ -116,6 +116,8 @@ collect:
|
|
|
116
116
|
- default-language
|
|
117
117
|
- detect-language
|
|
118
118
|
- editable
|
|
119
|
+
- feedback
|
|
120
|
+
- feedback-timeout
|
|
119
121
|
- fold-collapse-label
|
|
120
122
|
- fold-expand-label
|
|
121
123
|
- hide-copy-button
|
|
@@ -168,6 +170,7 @@ collect:
|
|
|
168
170
|
- onfeedback-buttons-click
|
|
169
171
|
- positive-label
|
|
170
172
|
# cds-aichat-file-upload-item
|
|
173
|
+
- error-description
|
|
171
174
|
- fallback-label
|
|
172
175
|
- read-only
|
|
173
176
|
- remove-file-named-label
|
|
@@ -239,6 +242,8 @@ collect:
|
|
|
239
242
|
- code-snippet-aria-label-editable
|
|
240
243
|
- code-snippet-aria-label-readonly
|
|
241
244
|
- code-snippet-copy-button-tooltip-content
|
|
245
|
+
- code-snippet-feedback
|
|
246
|
+
- code-snippet-feedback-timeout
|
|
242
247
|
- code-snippet-highlight
|
|
243
248
|
- code-snippet-show-less-text
|
|
244
249
|
- code-snippet-show-more-text
|
|
@@ -255,6 +260,10 @@ collect:
|
|
|
255
260
|
- table-locale
|
|
256
261
|
- table-next-page-text
|
|
257
262
|
- table-previous-page-text
|
|
263
|
+
# cds-aichat-message-item-shell
|
|
264
|
+
- full-width
|
|
265
|
+
- hide-avatar
|
|
266
|
+
- row-type
|
|
258
267
|
# cds-aichat-messages-shell
|
|
259
268
|
- bottom-handle-label
|
|
260
269
|
- oncds-aichat-messages-shell-scroll
|
|
@@ -301,6 +310,10 @@ collect:
|
|
|
301
310
|
- oncds-aichat-transcript-toggle
|
|
302
311
|
- show-label
|
|
303
312
|
- text
|
|
313
|
+
# cds-aichat-user-avatar
|
|
314
|
+
- height
|
|
315
|
+
- image
|
|
316
|
+
- width
|
|
304
317
|
# cds-aichat-video-player
|
|
305
318
|
- aspect-ratio-percentage
|
|
306
319
|
- oncds-aichat-video-player-error
|
|
@@ -336,6 +349,9 @@ collect:
|
|
|
336
349
|
- top
|
|
337
350
|
- top-left
|
|
338
351
|
- top-right
|
|
352
|
+
# cds-aichat-message-item-shell - row-type
|
|
353
|
+
- request
|
|
354
|
+
- response
|
|
339
355
|
npm:
|
|
340
356
|
dependencies: null
|
|
341
357
|
js:
|