@neo4j-ndl/react 5.1.2 → 5.1.3

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 (36) hide show
  1. package/lib/cjs/ai/response/Response.js +127 -3
  2. package/lib/cjs/ai/response/Response.js.map +1 -1
  3. package/lib/cjs/ai/response/safe-href.js +108 -0
  4. package/lib/cjs/ai/response/safe-href.js.map +1 -0
  5. package/lib/cjs/ai/response/stories/response-all-components.story.js +10 -3
  6. package/lib/cjs/ai/response/stories/response-all-components.story.js.map +1 -1
  7. package/lib/cjs/ai/response/stories/response-lists.story.js +6 -1
  8. package/lib/cjs/ai/response/stories/response-lists.story.js.map +1 -1
  9. package/lib/cjs/dropzone/Dropzone.js +2 -6
  10. package/lib/cjs/dropzone/Dropzone.js.map +1 -1
  11. package/lib/cjs/toast/Toast.js +4 -4
  12. package/lib/cjs/toast/Toast.js.map +1 -1
  13. package/lib/esm/ai/response/Response.js +127 -3
  14. package/lib/esm/ai/response/Response.js.map +1 -1
  15. package/lib/esm/ai/response/safe-href.js +104 -0
  16. package/lib/esm/ai/response/safe-href.js.map +1 -0
  17. package/lib/esm/ai/response/stories/response-all-components.story.js +10 -3
  18. package/lib/esm/ai/response/stories/response-all-components.story.js.map +1 -1
  19. package/lib/esm/ai/response/stories/response-lists.story.js +6 -1
  20. package/lib/esm/ai/response/stories/response-lists.story.js.map +1 -1
  21. package/lib/esm/dropzone/Dropzone.js +2 -6
  22. package/lib/esm/dropzone/Dropzone.js.map +1 -1
  23. package/lib/esm/toast/Toast.js +4 -4
  24. package/lib/esm/toast/Toast.js.map +1 -1
  25. package/lib/types/ai/response/Response.d.ts +15 -1
  26. package/lib/types/ai/response/Response.d.ts.map +1 -1
  27. package/lib/types/ai/response/safe-href.d.ts +26 -0
  28. package/lib/types/ai/response/safe-href.d.ts.map +1 -0
  29. package/lib/types/ai/response/stories/response-all-components.story.d.ts.map +1 -1
  30. package/lib/types/ai/response/stories/response-lists.story.d.ts.map +1 -1
  31. package/lib/types/dropzone/Dropzone.d.ts +1 -1
  32. package/lib/types/dropzone/Dropzone.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/skills/ndl-react/SKILL.md +2 -2
  35. package/skills/ndl-react/components/ai/response.md +36 -5
  36. package/skills/ndl-react/components/dropzone.md +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Dropzone.js","sourceRoot":"","sources":["../../../src/dropzone/Dropzone.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAAkD;AAClD,4DAAoC;AACpC,mDAAwC;AACxC,iCAAkE;AAClE,mDAKwB;AACxB,6CAAgD;AAGhD,sCAAmC;AACnC,wGAAqG;AACrG,oGAAiG;AACjG,oFAAiF;AACjF,kDAA8C;AAC9C,8CAA2C;AAyC3C;;;;;;GAMG;AAEH,MAAM,OAAO,GAAG,IAAA,uBAAM,GAAE,CAAC;AAEzB,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,QAAQ,CAAC;AAE5C,MAAM,iBAAiB,GAAG,CAAC,EAYS,EAAE,EAAE;QAZb,EACzB,eAAe,EACf,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,KAAK,EACL,SAAS,EACT,GAAG,OAE+B,EAD/B,SAAS,cAXa,sKAY1B,CADa;IAEZ;;;;;;OAMG;IACH,SAAS,iBAAiB,CACxB,aAAkB,EAClB,cAA+B,EAC/B,KAAgB;;QAEhB,IAAI,sBAAsB,IAAI,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChE,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;gBACjC,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;oBAC3D,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ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AS,EAAC,0CAA0C,EACpD,OAAO,EAAC,aAAa,YACrB,IAAI,iBAAiB,gBAAgB,GAAc,CACtD,IACG,EACN,uBAAC,0BAAW,kBACV,SAAS,EAAE,IAAA,oBAAU,EAAC,mCAAmC,EAAE,SAAS,CAAC,EACrE,KAAK,EAAE,qBAAqB,EAC5B,IAAI,EAAC,OAAO,EACZ,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,IACR,SAAS,EACb,IACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;IAChD,kBAAkB,EAAE,mCAAmC;CACxD,CAAC,CAAC;AAEM,4BAAQ","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { detect } from 'detect-browser';\nimport { type RefObject, useMemo, useRef, useState } from 'react';\nimport {\n type DropEvent,\n type DropzoneOptions,\n type FileRejection,\n useDropzone,\n} from 'react-dropzone';\nimport { useResizeObserver } from 'usehooks-ts';\n\nimport { type CommonProps } from '../_common/types';\nimport { Banner } from '../banner';\nimport { DocumentArrowUpIconOutline } from '../icons/generated/heroIcons/DocumentArrowUpIconOutline';\nimport { DocumentArrowUpIconSolid } from '../icons/generated/heroIcons/DocumentArrowUpIconSolid';\nimport { XCircleIconSolid } from '../icons/generated/heroIcons/XCircleIconSolid';\nimport { ProgressBar } from '../progress-bar';\nimport { Typography } from '../typography';\n\n/**\n *\n *\n * Types\n *\n *\n */\n/**\n * @remarks\n * Where `DropzoneOptions` is the props for the `react-dropzone` library. For more information, see the [react-dropzone documentation](https://react-dropzone.js.org/#src).\n */\ntype DropzoneProps = {\n /** Props for the underlying `react-dropzone` component. Don't use `accept`. If using custom file extensions as this option is broken. Instead use the `acceptedFileExtensions` property. */\n dropZoneOptions: DropzoneOptions;\n\n /** Informational text that highlights the supported file types, will be displayed in the footer. */\n supportedFilesDescription?: React.ReactNode;\n\n /** Element to display when uploading the file. */\n loadingElement?: React.ReactNode;\n\n /** Use when wanting a custom heading. */\n heading?: React.ReactNode;\n\n /** Message to be shown when file is rejected. */\n rejectedText?: React.ReactNode;\n\n /** The accepted file extensions for the Drag-and-Drop. */\n acceptedFileExtensions?: string[];\n};\n\ntype DropzoneLoadingProgressBarProps = {\n /** The percentage of the progress bar. */\n progressBarPrecentage: number;\n\n /** The time in minute left to upload the file. */\n progressBarMinute?: number;\n};\n\n/**\n *\n *\n * Helpers\n *\n *\n */\n\nconst browser = detect();\n\nconst isSafari = browser?.name === 'safari';\n\nconst DropzoneComponent = ({\n dropZoneOptions,\n supportedFilesDescription,\n loadingElement,\n heading,\n rejectedText,\n acceptedFileExtensions,\n htmlAttributes,\n style,\n className,\n ref,\n ...restProps\n}: CommonProps<'div', DropzoneProps>) => {\n /**\n * We intercept the onDrop function in order to enforce\n * custom file extensions. Before calling the onDrop props we check\n * if the custom file extensions is acceptable. If the extension\n * conforms to acceptedFileExtensions, we call onDrop. Otherwise, we\n * present an error message.\n */\n function onDropInterceptor<T extends File>(\n acceptedFiles: T[],\n fileRejections: FileRejection[],\n event: DropEvent,\n ) {\n if (acceptedFileExtensions && acceptedFileExtensions.length > 0) {\n for (const file of acceptedFiles) {\n const isAccepted = acceptedFileExtensions.some((extension) => {\n if (file.name.endsWith(extension)) {\n return true;\n }\n });\n if (!isAccepted) {\n setIsRejected(true);\n return;\n }\n }\n }\n setIsRejected(false);\n dropZoneOptions.onDrop?.(acceptedFiles, fileRejections, event);\n }\n\n const [isRejected, setIsRejected] = useState(false);\n const dropZoneRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs([dropZoneRef, ref]);\n const isDisabled = dropZoneOptions?.disabled || Boolean(loadingElement);\n\n const {\n getRootProps,\n getInputProps,\n isDragActive,\n isDragAccept,\n isDragReject,\n open,\n } = useDropzone({\n ...dropZoneOptions,\n disabled: isDisabled,\n noClick: true,\n onDrop: onDropInterceptor,\n });\n\n const { width } = useResizeObserver({\n ref: dropZoneRef as RefObject<HTMLElement>,\n });\n\n const isUploading = Boolean(loadingElement);\n\n const titleText =\n isDragActive && isDragReject\n ? 'Format not supported'\n : isDragActive && !isDragReject\n ? 'Drop file'\n : null;\n\n const computedFileImage =\n (isDragActive && isDragAccept) || isUploading ? (\n <DocumentArrowUpIconSolid className=\"ndl-dropzone-drag-icon ndl-accepted\" />\n ) : (\n <XCircleIconSolid className=\"ndl-dropzone-drag-icon ndl-rejected\" />\n );\n\n const wrapperClasses = classNames('ndl-dropzone', className, {\n 'ndl-drag-active': isDragActive,\n 'ndl-drag-disabled': dropZoneOptions?.disabled,\n 'ndl-file-invalid': isDragActive && isDragReject,\n });\n\n useMemo(() => {\n if (isDragActive && isRejected) {\n setIsRejected(false);\n }\n }, [isDragActive, isRejected]);\n\n return (\n <>\n {isRejected && (\n <Banner className=\"ndl-dropzone-error-alert\" variant=\"danger\">\n <Banner.Header>Error</Banner.Header>\n <Banner.Description>\n {Boolean(rejectedText) || 'File extension not supported.'}\n </Banner.Description>\n </Banner>\n )}\n <div\n ref={mergedRef}\n className={wrapperClasses}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-dropzone-inner-wrapper\" {...getRootProps()}>\n <input aria-label=\"Drag and drop area\" {...getInputProps()} />\n <div className=\"ndl-dropzone-inner\">\n {/* Illustration should be visible only after arbitrary width */}\n {width !== undefined && width > 230 && (\n <>\n {isDragActive && !isSafari ? (\n computedFileImage\n ) : (\n <DocumentArrowUpIconOutline className=\"ndl-dropzone-upload-icon\" />\n )}\n </>\n )}\n {!isUploading && (\n <div className=\"ndl-dnd-title-container\">\n <Typography variant=\"subheading-medium\">\n {titleText ||\n (heading ?? (\n <>\n Drag <span className=\"ndl-dnd-title-ampersand\">&</span>{' '}\n Drop\n </>\n ))}\n </Typography>\n {!isDragReject && (\n <div className=\"ndl-dnd-subtitle\">\n <Typography variant=\"body-medium\">or</Typography>{' '}\n <button\n className=\"ndl-dnd-browse-link\"\n onClick={() => open()}\n disabled={isDisabled}\n type=\"button\"\n >\n Browse\n </button>\n </div>\n )}\n </div>\n )}\n <div className=\"ndl-dropzone-footer\">\n {isUploading && <>{loadingElement}</>}\n {!isUploading && (\n <div className=\"ndl-file-support-text\">\n {supportedFilesDescription}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n </>\n );\n};\n\nconst DropzoneLoadingProgressBarComponent = ({\n progressBarPrecentage,\n progressBarMinute,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'div', DropzoneLoadingProgressBarProps>) => {\n return (\n <div className=\"ndl-dropzone-loading-progress-bar-wrapper\">\n <div className=\"ndl-dropzone-loading-progress-bar-indicators\">\n <Typography\n className=\"ndl-dropzone-loading-progress-bar-precentage\"\n variant=\"subheading-small\"\n >\n {`${progressBarPrecentage}%`}\n </Typography>\n {Boolean(progressBarMinute) && (\n <Typography\n className=\"ndl-dropzone-loading-progress-bar-minute\"\n variant=\"body-medium\"\n >{`(${progressBarMinute} minutes left)`}</Typography>\n )}\n </div>\n <ProgressBar\n className={classNames('ndl-dropzone-loading-progress-bar', className)}\n value={progressBarPrecentage}\n size=\"large\"\n htmlAttributes={htmlAttributes}\n ref={ref}\n style={style}\n {...restProps}\n />\n </div>\n );\n};\n\nconst Dropzone = Object.assign(DropzoneComponent, {\n LoadingProgressBar: DropzoneLoadingProgressBarComponent,\n});\n\nexport { Dropzone };\n"]}
1
+ {"version":3,"file":"Dropzone.js","sourceRoot":"","sources":["../../../src/dropzone/Dropzone.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAAkD;AAClD,4DAAoC;AACpC,mDAAwC;AACxC,iCAAkE;AAClE,mDAKwB;AACxB,6CAAgD;AAGhD,sCAAmC;AACnC,wGAAqG;AACrG,oGAAiG;AACjG,oFAAiF;AACjF,kDAA8C;AAC9C,8CAA2C;AAyC3C;;;;;;GAMG;AAEH,MAAM,OAAO,GAAG,IAAA,uBAAM,GAAE,CAAC;AAEzB,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,QAAQ,CAAC;AAE5C,MAAM,iBAAiB,GAAG,CAAC,EAYS,EAAE,EAAE;QAZb,EACzB,eAAe,EACf,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,KAAK,EACL,SAAS,EACT,GAAG,OAE+B,EAD/B,SAAS,cAXa,sKAY1B,CADa;IAEZ;;;;;;OAMG;IACH,SAAS,iBAAiB,CACxB,aAAkB,EAClB,cAA+B,EAC/B,KAAgB;;QAEhB,IAAI,sBAAsB,IAAI,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChE,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;gBACjC,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC3D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC9B,CAAC;gBACF,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,aAAa,CAAC,IAAI,CAAC,CAAC;oBACpB,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;QACD,aAAa,CAAC,KAAK,CAAC,CAAC;QACrB,MA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AC9B,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,IACR,SAAS,EACb,IACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;IAChD,kBAAkB,EAAE,mCAAmC;CACxD,CAAC,CAAC;AAEM,4BAAQ","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useMergeRefs } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { detect } from 'detect-browser';\nimport { type RefObject, useMemo, useRef, useState } from 'react';\nimport {\n type DropEvent,\n type DropzoneOptions,\n type FileRejection,\n useDropzone,\n} from 'react-dropzone';\nimport { useResizeObserver } from 'usehooks-ts';\n\nimport { type CommonProps } from '../_common/types';\nimport { Banner } from '../banner';\nimport { DocumentArrowUpIconOutline } from '../icons/generated/heroIcons/DocumentArrowUpIconOutline';\nimport { DocumentArrowUpIconSolid } from '../icons/generated/heroIcons/DocumentArrowUpIconSolid';\nimport { XCircleIconSolid } from '../icons/generated/heroIcons/XCircleIconSolid';\nimport { ProgressBar } from '../progress-bar';\nimport { Typography } from '../typography';\n\n/**\n *\n *\n * Types\n *\n *\n */\n/**\n * @remarks\n * Where `DropzoneOptions` is the props for the `react-dropzone` library. For more information, see the [react-dropzone documentation](https://react-dropzone.js.org/#src).\n */\ntype DropzoneProps = {\n /** Props for the underlying `react-dropzone` component. Don't use `accept`. If using custom file extensions as this option is broken. Instead use the `acceptedFileExtensions` property. */\n dropZoneOptions: DropzoneOptions;\n\n /** Informational text that highlights the supported file types, will be displayed in the footer. */\n supportedFilesDescription?: React.ReactNode;\n\n /** Element to display when uploading the file. */\n loadingElement?: React.ReactNode;\n\n /** Use when wanting a custom heading. */\n heading?: React.ReactNode;\n\n /** Message shown when a file is rejected. Defaults to \"File extension not supported.\" when omitted. */\n rejectedText?: React.ReactNode;\n\n /** The accepted file extensions for the Drag-and-Drop. */\n acceptedFileExtensions?: string[];\n};\n\ntype DropzoneLoadingProgressBarProps = {\n /** The percentage of the progress bar. */\n progressBarPrecentage: number;\n\n /** The time in minute left to upload the file. */\n progressBarMinute?: number;\n};\n\n/**\n *\n *\n * Helpers\n *\n *\n */\n\nconst browser = detect();\n\nconst isSafari = browser?.name === 'safari';\n\nconst DropzoneComponent = ({\n dropZoneOptions,\n supportedFilesDescription,\n loadingElement,\n heading,\n rejectedText,\n acceptedFileExtensions,\n htmlAttributes,\n style,\n className,\n ref,\n ...restProps\n}: CommonProps<'div', DropzoneProps>) => {\n /**\n * We intercept the onDrop function in order to enforce\n * custom file extensions. Before calling the onDrop props we check\n * if the custom file extensions is acceptable. If the extension\n * conforms to acceptedFileExtensions, we call onDrop. Otherwise, we\n * present an error message.\n */\n function onDropInterceptor<T extends File>(\n acceptedFiles: T[],\n fileRejections: FileRejection[],\n event: DropEvent,\n ) {\n if (acceptedFileExtensions && acceptedFileExtensions.length > 0) {\n for (const file of acceptedFiles) {\n const isAccepted = acceptedFileExtensions.some((extension) =>\n file.name.endsWith(extension),\n );\n if (!isAccepted) {\n setIsRejected(true);\n return;\n }\n }\n }\n setIsRejected(false);\n dropZoneOptions.onDrop?.(acceptedFiles, fileRejections, event);\n }\n\n const [isRejected, setIsRejected] = useState(false);\n const dropZoneRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMergeRefs([dropZoneRef, ref]);\n const isDisabled = dropZoneOptions?.disabled || Boolean(loadingElement);\n\n const {\n getRootProps,\n getInputProps,\n isDragActive,\n isDragAccept,\n isDragReject,\n open,\n } = useDropzone({\n ...dropZoneOptions,\n disabled: isDisabled,\n noClick: true,\n onDrop: onDropInterceptor,\n });\n\n const { width } = useResizeObserver({\n ref: dropZoneRef as RefObject<HTMLElement>,\n });\n\n const isUploading = Boolean(loadingElement);\n\n const titleText =\n isDragActive && isDragReject\n ? 'Format not supported'\n : isDragActive && !isDragReject\n ? 'Drop file'\n : null;\n\n const computedFileImage =\n (isDragActive && isDragAccept) || isUploading ? (\n <DocumentArrowUpIconSolid className=\"ndl-dropzone-drag-icon ndl-accepted\" />\n ) : (\n <XCircleIconSolid className=\"ndl-dropzone-drag-icon ndl-rejected\" />\n );\n\n const wrapperClasses = classNames('ndl-dropzone', className, {\n 'ndl-drag-active': isDragActive,\n 'ndl-drag-disabled': dropZoneOptions?.disabled,\n 'ndl-file-invalid': isDragActive && isDragReject,\n });\n\n useMemo(() => {\n if (isDragActive && isRejected) {\n setIsRejected(false);\n }\n }, [isDragActive, isRejected]);\n\n return (\n <>\n {isRejected && (\n <Banner className=\"ndl-dropzone-error-alert\" variant=\"danger\">\n <Banner.Header>Error</Banner.Header>\n <Banner.Description>\n {rejectedText ?? 'File extension not supported.'}\n </Banner.Description>\n </Banner>\n )}\n <div\n ref={mergedRef}\n className={wrapperClasses}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-dropzone-inner-wrapper\" {...getRootProps()}>\n <input aria-label=\"Drag and drop area\" {...getInputProps()} />\n <div className=\"ndl-dropzone-inner\">\n {/* Illustration should be visible only after arbitrary width */}\n {width !== undefined && width > 230 && (\n <>\n {isDragActive && !isSafari ? (\n computedFileImage\n ) : (\n <DocumentArrowUpIconOutline className=\"ndl-dropzone-upload-icon\" />\n )}\n </>\n )}\n {!isUploading && (\n <div className=\"ndl-dnd-title-container\">\n <Typography variant=\"subheading-medium\">\n {titleText ||\n (heading ?? (\n <>\n Drag <span className=\"ndl-dnd-title-ampersand\">&</span>{' '}\n Drop\n </>\n ))}\n </Typography>\n {!isDragReject && (\n <div className=\"ndl-dnd-subtitle\">\n <Typography variant=\"body-medium\">or</Typography>{' '}\n <button\n className=\"ndl-dnd-browse-link\"\n onClick={() => open()}\n disabled={isDisabled}\n type=\"button\"\n >\n Browse\n </button>\n </div>\n )}\n </div>\n )}\n <div className=\"ndl-dropzone-footer\">\n {isUploading && <>{loadingElement}</>}\n {!isUploading && (\n <div className=\"ndl-file-support-text\">\n {supportedFilesDescription}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n </>\n );\n};\n\nconst DropzoneLoadingProgressBarComponent = ({\n progressBarPrecentage,\n progressBarMinute,\n htmlAttributes,\n className,\n style,\n ref,\n ...restProps\n}: CommonProps<'div', DropzoneLoadingProgressBarProps>) => {\n return (\n <div className=\"ndl-dropzone-loading-progress-bar-wrapper\">\n <div className=\"ndl-dropzone-loading-progress-bar-indicators\">\n <Typography\n className=\"ndl-dropzone-loading-progress-bar-precentage\"\n variant=\"subheading-small\"\n >\n {`${progressBarPrecentage}%`}\n </Typography>\n {Boolean(progressBarMinute) && (\n <Typography\n className=\"ndl-dropzone-loading-progress-bar-minute\"\n variant=\"body-medium\"\n >{`(${progressBarMinute} minutes left)`}</Typography>\n )}\n </div>\n <ProgressBar\n className={classNames('ndl-dropzone-loading-progress-bar', className)}\n value={progressBarPrecentage}\n size=\"large\"\n htmlAttributes={htmlAttributes}\n ref={ref}\n style={style}\n {...restProps}\n />\n </div>\n );\n};\n\nconst Dropzone = Object.assign(DropzoneComponent, {\n LoadingProgressBar: DropzoneLoadingProgressBarComponent,\n});\n\nexport { Dropzone };\n"]}
@@ -84,13 +84,13 @@ const Toast = (_a) => {
84
84
  function getProps(onClose, shouldAutoClose, onAutoClose, onAction, sonnerToastProps, variant) {
85
85
  const isProgressBar = variant === 'progress-bar';
86
86
  // https://sonner.emilkowal.ski/toast#api-reference
87
- return Object.assign({ duration: !isProgressBar && shouldAutoClose ? (!onAction ? 5000 : 8000) : Infinity, unstyled: true, onDismiss: (toast) => {
88
- onCloseCallback(onClose, toast.id);
89
- }, onAutoClose: (toast) => {
87
+ return Object.assign({ duration: !isProgressBar && shouldAutoClose ? (!onAction ? 5000 : 8000) : Infinity, onAutoClose: (toast) => {
90
88
  if (onAutoClose) {
91
89
  return onAutoClose(toast.id);
92
90
  }
93
- } }, sonnerToastProps);
91
+ }, onDismiss: (toast) => {
92
+ onCloseCallback(onClose, toast.id);
93
+ }, unstyled: true }, sonnerToastProps);
94
94
  }
95
95
  function createToast(text, props, variant, icon) {
96
96
  const { ref, sonnerToastProps = {}, onClose, shouldAutoClose, onAutoClose, onAction } = props, restProps = __rest(props, ["ref", "sonnerToastProps", "onClose", "shouldAutoClose", "onAutoClose", "onAction"]);
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.js","sourceRoot":"","sources":["../../../src/toast/Toast.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAEpC,mCAMgB;AAGhB,4DAAuD;AACvD,4FAAyF;AACzF,wGAAqG;AACrG,oFAAiF;AACjF,wDAAoD;AACpD,kDAA8C;AA6D9C,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;IACtC,MAAM,EACJ,QAAQ,GAAG,aAAa,EACxB,aAAa,GAAG,CAAC,EACjB,SAAS,EACT,kBAAkB,GACnB,GAAG,KAAK,CAAC;IAEV,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IAE7D,OAAO,CACL,uBAAC,gBAAa,kBACZ,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,IACxB,kBAAkB,EACtB,CACH,CAAC;AACJ,CAAC,CAAC;AA2PO,0BAAO;AApPhB,SAAS,eAAe,CACtB,QAA6C,EAC7C,EAAW;IAEX,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,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GAAG,GAAG,KAAK,GAAG,CAAC;QAC/B,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAmB,CAAC;QAE3E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,2BAA2B,GAAG,YAAY,CAAC,aAAa,CAC5D,6BAA6B,CACZ,CAAC;QACpB,2BAA2B,CAAC,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,kBAAkB,GAAG,2BAA2B,CAAC,aAAa,CAClE,mBAAmB,CACF,CAAC;QAEpB,IAAI,CAAC,2BAA2B,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC,EAAE,gDAAgD;CACpD,CAAC;AAEgB,sBAAK","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { type ReactNode } from 'react';\nimport {\n type ExternalToast as SonnerExternalToast,\n toast as sonnerToast,\n Toaster as SonnerToaster,\n type ToasterProps as SonnerToasterProps,\n type ToastT as SonnerToastT,\n} from 'sonner';\n\nimport { type CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { CheckCircleIconSolid } from '../icons/generated/heroIcons/CheckCircleIconSolid';\nimport { ExclamationCircleIconSolid } from '../icons/generated/heroIcons/ExclamationCircleIconSolid';\nimport { XMarkIconOutline } from '../icons/generated/heroIcons/XMarkIconOutline';\nimport { OutlinedButton } from '../outlined-button';\nimport { ProgressBar } from '../progress-bar';\n\ntype ToastVariants = 'neutral' | 'success' | 'danger' | 'progress-bar';\n\ntype ToastCommandVariants = 'neutral' | 'success' | 'danger' | 'progressBar';\n\ntype ToastId = string | number;\n\ntype BaseToastProps = CommonProps<\n 'div',\n {\n /** If `true` a close button will be displayed in the toast. */\n isCloseable?: boolean;\n /** If `true` the toast will close when the action button is triggered. */\n shouldCloseOnAction?: boolean;\n /** Function that will be called when the toast is closed. */\n onClose?: (id: ToastId) => void;\n /** If true the toast will close automatically after a certain time. */\n shouldAutoClose?: boolean;\n /** Function that will be called when the toast is automatically closed. */\n onAutoClose?: (id: ToastId) => void;\n /** If set an action button will be displayed. The value here will be displayed\n * in the action button. If this is set the toast property `shouldAutoClose` will\n * automatically be set to `false` unless overridden. */\n actionLabel?: string;\n /** Function that will be called when the action button is clicked. */\n onAction?: (id: ToastId) => void;\n /** If a dev wishes to set the underlying framework props (Sonner Toast).\n * https://sonner.emilkowal.ski/toast#api-reference */\n sonnerToastProps?: SonnerExternalToast;\n /** If true the toast is controlled by the parent. */\n isControlled?: boolean;\n }\n>;\n\ninterface ToastNeutralProps extends BaseToastProps {\n icon?: ReactNode;\n}\n// oxlint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface ToastSuccessProps extends BaseToastProps {}\n// oxlint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface ToastDangerProps extends BaseToastProps {}\n\ninterface ToastProgressBarProps extends BaseToastProps {\n icon?: ReactNode;\n initialProgressBarValue?: number;\n}\n\ntype ToastVariantsProps =\n | ToastNeutralProps\n | ToastSuccessProps\n | ToastDangerProps\n | ToastProgressBarProps;\n\ninterface ToasterProps extends Pick<\n SonnerToasterProps,\n 'position' | 'visibleToasts' | 'className'\n> {\n sonnerToasterProps?: SonnerToasterProps;\n}\n\nconst Toaster = (props: ToasterProps) => {\n const {\n position = 'bottom-left',\n visibleToasts = 1,\n className,\n sonnerToasterProps,\n } = props;\n\n const classes = classNames('ndl-toast-container', className);\n\n return (\n <SonnerToaster\n className={classes}\n position={position}\n visibleToasts={visibleToasts}\n {...sonnerToasterProps}\n />\n );\n};\n\ntype SonnerToast = typeof sonnerToast;\ninterface CustomSonnerToast extends SonnerToast {\n needle: Record<string, { onClose?: (id: ToastId) => void }>;\n}\n\nfunction onCloseCallback(\n callback: ((id: ToastId) => void) | undefined,\n id: ToastId,\n) {\n if (callback) {\n callback(id);\n // Cleanup\n delete (sonnerToast as CustomSonnerToast).needle[id];\n }\n}\n\ntype ToastElement = ToastVariantsProps & {\n icon: ReactNode;\n id: ToastId;\n variant: ToastVariants;\n text: ReactNode;\n initialProgressBarValue?: number;\n isControlled?: boolean;\n};\n\nconst Toast = ({\n icon,\n id,\n text,\n variant,\n isCloseable,\n onClose,\n actionLabel,\n onAction,\n shouldCloseOnAction,\n initialProgressBarValue,\n isControlled,\n htmlAttributes,\n ref,\n ...restProps\n}: ToastElement) => {\n const isProgressBar = variant === 'progress-bar';\n\n const handleOnClose = () => {\n if (isControlled === true) {\n onCloseCallback(onClose, id);\n return;\n }\n sonnerToast.dismiss(id);\n onCloseCallback(onClose, id);\n };\n\n const handleOnAction = () => {\n if (onAction) {\n onAction(id);\n }\n if (shouldCloseOnAction === true) {\n sonnerToast.dismiss(id);\n onCloseCallback(onClose, id);\n }\n };\n\n return (\n <div\n id={String(id)}\n className=\"ndl-toast\"\n tabIndex={-1}\n ref={ref}\n data-variant={variant}\n data-testid=\"ndl-toast\"\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-toast-content\" tabIndex={-1}>\n {icon && (\n <div className={`ndl-toast-icon ndl-toast-${variant}`}>{icon}</div>\n )}\n <div className=\"ndl-toast-text\">{text}</div>\n {actionLabel && (\n <OutlinedButton\n className=\"ndl-toast-action\"\n size=\"small\"\n onClick={handleOnAction}\n >\n {actionLabel}\n </OutlinedButton>\n )}\n {(isCloseable || actionLabel || isProgressBar) && (\n <CleanIconButton\n className=\"ndl-toast-close-button\"\n onClick={handleOnClose}\n description={null}\n size=\"small\"\n htmlAttributes={{\n 'aria-label': 'Close',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </div>\n {isProgressBar && (\n <ProgressBar size=\"small\" value={initialProgressBarValue ?? 0} />\n )}\n </div>\n );\n};\n\nfunction getProps(\n onClose: ((id: ToastId) => void) | undefined,\n shouldAutoClose: boolean | undefined,\n onAutoClose: ((id: ToastId) => void) | undefined,\n onAction: ((id: ToastId) => void) | undefined,\n sonnerToastProps: SonnerExternalToast | undefined,\n variant: ToastVariants,\n) {\n const isProgressBar = variant === 'progress-bar';\n // https://sonner.emilkowal.ski/toast#api-reference\n return {\n duration:\n !isProgressBar && shouldAutoClose ? (!onAction ? 5000 : 8000) : Infinity,\n unstyled: true,\n onDismiss: (toast: SonnerToastT) => {\n onCloseCallback(onClose, toast.id);\n },\n onAutoClose: (toast: SonnerToastT) => {\n if (onAutoClose) {\n return onAutoClose(toast.id);\n }\n },\n ...sonnerToastProps,\n };\n}\n\nfunction createToast(\n text: ReactNode,\n props: ToastVariantsProps,\n variant: ToastVariants,\n icon: ReactNode,\n) {\n const {\n ref,\n sonnerToastProps = {},\n onClose,\n shouldAutoClose,\n onAutoClose,\n onAction,\n ...restProps\n } = props;\n\n const { id: sonnerToastPropsId } = sonnerToastProps;\n sonnerToastProps.id = sonnerToastPropsId ?? `ndl-toast-${Date.now()}`;\n\n // Unfortunately calling sonnerToast.dismiss does not trigger the onDismiss\n // callback (weird). So we need to save the onClose callback and call it manually\n // when calling dismiss manually as we want an onClose callback.\n // https://sonner.emilkowal.ski/toast#on-close-callback\n // https://github.com/emilkowalski/sonner/blob/main/src/index.tsx#L320\n // https://github.com/emilkowalski/sonner/blob/main/src/index.tsx#L359\n (sonnerToast as CustomSonnerToast).needle = {\n [String(sonnerToastProps.id)]: {\n onClose,\n },\n };\n\n return sonnerToast.custom(\n (id: ToastId) => (\n <Toast\n {...restProps}\n ref={ref}\n id={id}\n text={text}\n variant={variant}\n icon={icon}\n onClose={onClose}\n onAction={onAction}\n />\n ),\n {\n ...getProps(\n onClose,\n shouldAutoClose,\n onAutoClose,\n onAction,\n sonnerToastProps,\n variant,\n ),\n },\n );\n}\n\n// eslint-disable-next-line no-redeclare\ninterface Toast {\n neutral: (text: ReactNode, props?: ToastNeutralProps) => ToastId;\n success: (text: ReactNode, props?: ToastSuccessProps) => ToastId;\n danger: (text: ReactNode, props?: ToastDangerProps) => ToastId;\n progressBar: (text: ReactNode, props?: ToastProgressBarProps) => ToastId;\n updateProgressBarValue: (id: ToastId, value: number) => void;\n close: (id: ToastId) => void;\n sonnerToast: typeof sonnerToast;\n}\n\nconst toast: Toast = {\n close: (id) => {\n sonnerToast.dismiss(id);\n onCloseCallback((sonnerToast as CustomSonnerToast).needle[id]?.onClose, id);\n },\n danger: (text: ReactNode, props = {}) =>\n createToast(text, props, 'danger', <ExclamationCircleIconSolid />),\n neutral: (text, props = {}) => {\n const { icon, ...restProps } = props;\n return createToast(text, restProps, 'neutral', icon);\n },\n progressBar: (text: ReactNode, props = {}) => {\n const { icon, ...restProps } = props;\n return createToast(text, restProps, 'progress-bar', icon);\n },\n sonnerToast,\n success: (text: ReactNode, props = {}) => {\n const icon = <CheckCircleIconSolid />;\n return createToast(text, props, 'success', icon);\n },\n updateProgressBarValue: (id, givenValue) => {\n const value = givenValue > 100 ? 100 : givenValue < 0 ? 0 : givenValue;\n\n // Unable to use the sonner toast.update on custom toasts.\n const widthValue = `${value}%`;\n const toastElement = document.getElementById(String(id)) as HTMLDivElement;\n\n if (!toastElement) {\n return;\n }\n\n const progressBarContainerElement = toastElement.querySelector(\n '.ndl-progress-bar-container',\n ) as HTMLDivElement;\n progressBarContainerElement.ariaValueNow = String(value);\n const progressBarElement = progressBarContainerElement.querySelector(\n '.ndl-progress-bar',\n ) as HTMLDivElement;\n\n if (!progressBarContainerElement) {\n return;\n }\n\n progressBarElement.style.setProperty('width', widthValue);\n }, // If devs wish to directly access sonner toast.\n};\n\nexport { Toaster, toast };\nexport type {\n ToasterProps,\n ToastVariants,\n ToastCommandVariants,\n ToastNeutralProps,\n ToastSuccessProps,\n ToastDangerProps,\n ToastProgressBarProps,\n ToastVariantsProps,\n ToastElement,\n ToastId,\n};\n"]}
1
+ {"version":3,"file":"Toast.js","sourceRoot":"","sources":["../../../src/toast/Toast.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAEpC,mCAMgB;AAGhB,4DAAuD;AACvD,4FAAyF;AACzF,wGAAqG;AACrG,oFAAiF;AACjF,wDAAoD;AACpD,kDAA8C;AA6D9C,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;IACtC,MAAM,EACJ,QAAQ,GAAG,aAAa,EACxB,aAAa,GAAG,CAAC,EACjB,SAAS,EACT,kBAAkB,GACnB,GAAG,KAAK,CAAC;IAEV,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IAE7D,OAAO,CACL,uBAAC,gBAAa,kBACZ,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,IACxB,kBAAkB,EACtB,CACH,CAAC;AACJ,CAAC,CAAC;AA2PO,0BAAO;AApPhB,SAAS,eAAe,CACtB,QAA6C,EAC7C,EAAW;IAEX,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,EAAE,CAAC,CAAC;QACb,UAAU;QACV,OAAQ,cAAiC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAWD,MAAM,KAAK,GAAG,CAAC,EAeA,EAAE,EAAE;QAfJ,EACb,IAAI,EACJ,EAAE,EACF,IAAI,EACJ,OAAO,EACP,WAAW,EACX,OAAO,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,CACZ,CAAC;QACpB,2BAA2B,CAAC,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,kBAAkB,GAAG,2BAA2B,CAAC,aAAa,CAClE,mBAAmB,CACF,CAAC;QAEpB,IAAI,CAAC,2BAA2B,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC,EAAE,gDAAgD;CACpD,CAAC;AAEgB,sBAAK","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { type ReactNode } from 'react';\nimport {\n type ExternalToast as SonnerExternalToast,\n toast as sonnerToast,\n Toaster as SonnerToaster,\n type ToasterProps as SonnerToasterProps,\n type ToastT as SonnerToastT,\n} from 'sonner';\n\nimport { type CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { CheckCircleIconSolid } from '../icons/generated/heroIcons/CheckCircleIconSolid';\nimport { ExclamationCircleIconSolid } from '../icons/generated/heroIcons/ExclamationCircleIconSolid';\nimport { XMarkIconOutline } from '../icons/generated/heroIcons/XMarkIconOutline';\nimport { OutlinedButton } from '../outlined-button';\nimport { ProgressBar } from '../progress-bar';\n\ntype ToastVariants = 'neutral' | 'success' | 'danger' | 'progress-bar';\n\ntype ToastCommandVariants = 'neutral' | 'success' | 'danger' | 'progressBar';\n\ntype ToastId = string | number;\n\ntype BaseToastProps = CommonProps<\n 'div',\n {\n /** If `true` a close button will be displayed in the toast. */\n isCloseable?: boolean;\n /** If `true` the toast will close when the action button is triggered. */\n shouldCloseOnAction?: boolean;\n /** Function that will be called when the toast is closed. */\n onClose?: (id: ToastId) => void;\n /** If true the toast will close automatically after a certain time. */\n shouldAutoClose?: boolean;\n /** Function that will be called when the toast is automatically closed. */\n onAutoClose?: (id: ToastId) => void;\n /** If set an action button will be displayed. The value here will be displayed\n * in the action button. If this is set the toast property `shouldAutoClose` will\n * automatically be set to `false` unless overridden. */\n actionLabel?: string;\n /** Function that will be called when the action button is clicked. */\n onAction?: (id: ToastId) => void;\n /** If a dev wishes to set the underlying framework props (Sonner Toast).\n * https://sonner.emilkowal.ski/toast#api-reference */\n sonnerToastProps?: SonnerExternalToast;\n /** If true the toast is controlled by the parent. */\n isControlled?: boolean;\n }\n>;\n\ninterface ToastNeutralProps extends BaseToastProps {\n icon?: ReactNode;\n}\n// oxlint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface ToastSuccessProps extends BaseToastProps {}\n// oxlint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface ToastDangerProps extends BaseToastProps {}\n\ninterface ToastProgressBarProps extends BaseToastProps {\n icon?: ReactNode;\n initialProgressBarValue?: number;\n}\n\ntype ToastVariantsProps =\n | ToastNeutralProps\n | ToastSuccessProps\n | ToastDangerProps\n | ToastProgressBarProps;\n\ninterface ToasterProps extends Pick<\n SonnerToasterProps,\n 'position' | 'visibleToasts' | 'className'\n> {\n sonnerToasterProps?: SonnerToasterProps;\n}\n\nconst Toaster = (props: ToasterProps) => {\n const {\n position = 'bottom-left',\n visibleToasts = 1,\n className,\n sonnerToasterProps,\n } = props;\n\n const classes = classNames('ndl-toast-container', className);\n\n return (\n <SonnerToaster\n className={classes}\n position={position}\n visibleToasts={visibleToasts}\n {...sonnerToasterProps}\n />\n );\n};\n\ntype SonnerToast = typeof sonnerToast;\ninterface CustomSonnerToast extends SonnerToast {\n needle: Record<string, { onClose?: (id: ToastId) => void }>;\n}\n\nfunction onCloseCallback(\n callback: ((id: ToastId) => void) | undefined,\n id: ToastId,\n) {\n if (callback) {\n callback(id);\n // Cleanup\n delete (sonnerToast as CustomSonnerToast).needle[id];\n }\n}\n\ntype ToastElement = ToastVariantsProps & {\n icon: ReactNode;\n id: ToastId;\n variant: ToastVariants;\n text: ReactNode;\n initialProgressBarValue?: number;\n isControlled?: boolean;\n};\n\nconst Toast = ({\n icon,\n id,\n text,\n variant,\n isCloseable,\n onClose,\n actionLabel,\n onAction,\n shouldCloseOnAction,\n initialProgressBarValue,\n isControlled,\n htmlAttributes,\n ref,\n ...restProps\n}: ToastElement) => {\n const isProgressBar = variant === 'progress-bar';\n\n const handleOnClose = () => {\n if (isControlled === true) {\n onCloseCallback(onClose, id);\n return;\n }\n sonnerToast.dismiss(id);\n onCloseCallback(onClose, id);\n };\n\n const handleOnAction = () => {\n if (onAction) {\n onAction(id);\n }\n if (shouldCloseOnAction === true) {\n sonnerToast.dismiss(id);\n onCloseCallback(onClose, id);\n }\n };\n\n return (\n <div\n id={String(id)}\n className=\"ndl-toast\"\n tabIndex={-1}\n ref={ref}\n data-variant={variant}\n data-testid=\"ndl-toast\"\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-toast-content\" tabIndex={-1}>\n {icon && (\n <div className={`ndl-toast-icon ndl-toast-${variant}`}>{icon}</div>\n )}\n <div className=\"ndl-toast-text\">{text}</div>\n {actionLabel && (\n <OutlinedButton\n className=\"ndl-toast-action\"\n size=\"small\"\n onClick={handleOnAction}\n >\n {actionLabel}\n </OutlinedButton>\n )}\n {(isCloseable || actionLabel || isProgressBar) && (\n <CleanIconButton\n className=\"ndl-toast-close-button\"\n onClick={handleOnClose}\n description={null}\n size=\"small\"\n htmlAttributes={{\n 'aria-label': 'Close',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </div>\n {isProgressBar && (\n <ProgressBar size=\"small\" value={initialProgressBarValue ?? 0} />\n )}\n </div>\n );\n};\n\nfunction getProps(\n onClose: ((id: ToastId) => void) | undefined,\n shouldAutoClose: boolean | undefined,\n onAutoClose: ((id: ToastId) => void) | undefined,\n onAction: ((id: ToastId) => void) | undefined,\n sonnerToastProps: SonnerExternalToast | undefined,\n variant: ToastVariants,\n) {\n const isProgressBar = variant === 'progress-bar';\n // https://sonner.emilkowal.ski/toast#api-reference\n return {\n duration:\n !isProgressBar && shouldAutoClose ? (!onAction ? 5000 : 8000) : Infinity,\n onAutoClose: (toast: SonnerToastT) => {\n if (onAutoClose) {\n return onAutoClose(toast.id);\n }\n },\n onDismiss: (toast: SonnerToastT) => {\n onCloseCallback(onClose, toast.id);\n },\n unstyled: true,\n ...sonnerToastProps,\n };\n}\n\nfunction createToast(\n text: ReactNode,\n props: ToastVariantsProps,\n variant: ToastVariants,\n icon: ReactNode,\n) {\n const {\n ref,\n sonnerToastProps = {},\n onClose,\n shouldAutoClose,\n onAutoClose,\n onAction,\n ...restProps\n } = props;\n\n const { id: sonnerToastPropsId } = sonnerToastProps;\n sonnerToastProps.id = sonnerToastPropsId ?? `ndl-toast-${Date.now()}`;\n\n // Unfortunately calling sonnerToast.dismiss does not trigger the onDismiss\n // callback (weird). So we need to save the onClose callback and call it manually\n // when calling dismiss manually as we want an onClose callback.\n // https://sonner.emilkowal.ski/toast#on-close-callback\n // https://github.com/emilkowalski/sonner/blob/main/src/index.tsx#L320\n // https://github.com/emilkowalski/sonner/blob/main/src/index.tsx#L359\n (sonnerToast as CustomSonnerToast).needle = {\n [String(sonnerToastProps.id)]: {\n onClose,\n },\n };\n\n return sonnerToast.custom(\n (id: ToastId) => (\n <Toast\n {...restProps}\n ref={ref}\n id={id}\n text={text}\n variant={variant}\n icon={icon}\n onClose={onClose}\n onAction={onAction}\n />\n ),\n {\n ...getProps(\n onClose,\n shouldAutoClose,\n onAutoClose,\n onAction,\n sonnerToastProps,\n variant,\n ),\n },\n );\n}\n\n// eslint-disable-next-line no-redeclare\ninterface Toast {\n neutral: (text: ReactNode, props?: ToastNeutralProps) => ToastId;\n success: (text: ReactNode, props?: ToastSuccessProps) => ToastId;\n danger: (text: ReactNode, props?: ToastDangerProps) => ToastId;\n progressBar: (text: ReactNode, props?: ToastProgressBarProps) => ToastId;\n updateProgressBarValue: (id: ToastId, value: number) => void;\n close: (id: ToastId) => void;\n sonnerToast: typeof sonnerToast;\n}\n\nconst toast: Toast = {\n close: (id) => {\n sonnerToast.dismiss(id);\n onCloseCallback((sonnerToast as CustomSonnerToast).needle[id]?.onClose, id);\n },\n danger: (text: ReactNode, props = {}) =>\n createToast(text, props, 'danger', <ExclamationCircleIconSolid />),\n neutral: (text, props = {}) => {\n const { icon, ...restProps } = props;\n return createToast(text, restProps, 'neutral', icon);\n },\n progressBar: (text: ReactNode, props = {}) => {\n const { icon, ...restProps } = props;\n return createToast(text, restProps, 'progress-bar', icon);\n },\n sonnerToast,\n success: (text: ReactNode, props = {}) => {\n const icon = <CheckCircleIconSolid />;\n return createToast(text, props, 'success', icon);\n },\n updateProgressBarValue: (id, givenValue) => {\n const value = givenValue > 100 ? 100 : givenValue < 0 ? 0 : givenValue;\n\n // Unable to use the sonner toast.update on custom toasts.\n const widthValue = `${value}%`;\n const toastElement = document.getElementById(String(id)) as HTMLDivElement;\n\n if (!toastElement) {\n return;\n }\n\n const progressBarContainerElement = toastElement.querySelector(\n '.ndl-progress-bar-container',\n ) as HTMLDivElement;\n progressBarContainerElement.ariaValueNow = String(value);\n const progressBarElement = progressBarContainerElement.querySelector(\n '.ndl-progress-bar',\n ) as HTMLDivElement;\n\n if (!progressBarContainerElement) {\n return;\n }\n\n progressBarElement.style.setProperty('width', widthValue);\n }, // If devs wish to directly access sonner toast.\n};\n\nexport { Toaster, toast };\nexport type {\n ToasterProps,\n ToastVariants,\n ToastCommandVariants,\n ToastNeutralProps,\n ToastSuccessProps,\n ToastDangerProps,\n ToastProgressBarProps,\n ToastVariantsProps,\n ToastElement,\n ToastId,\n};\n"]}
@@ -37,6 +37,7 @@ import { memo, useMemo, useRef } from 'react';
37
37
  import { defaultRehypePlugins, Streamdown } from 'streamdown';
38
38
  import { Languages } from '../../code-block/code-languages';
39
39
  import { CodePreview } from '../code-preview';
40
+ import { safeHref } from './safe-href';
40
41
  const STREAMDOWN_PLACEHOLDER_PROTOCOL = 'streamdown:';
41
42
  const CLOBBER_PREFIX = 'user-content-';
42
43
  const CLOBBERABLE_PROPERTIES = [
@@ -69,14 +70,124 @@ const prefixClobberableProperties = (node) => {
69
70
  * Prefixing after sanitization keeps already prefixed footnote ids intact.
70
71
  */
71
72
  const rehypePrefixClobberableProperties = () => prefixClobberableProperties;
73
+ /**
74
+ * Strip unsafe `href`/`src` before rehype-harden. Harden 1.1.x with wildcard
75
+ * prefixes rewrites network-path URLs (e.g. `//evil.example/path` → `/path`),
76
+ * which would bypass `safeHref` in the React overrides.
77
+ */
78
+ const stripUnsafeUrlProperty = (properties, key) => {
79
+ const value = properties[key];
80
+ if (typeof value !== 'string') {
81
+ return;
82
+ }
83
+ // Leave streaming placeholders for harden / the React override.
84
+ if (value.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)) {
85
+ return;
86
+ }
87
+ if (safeHref(value) === undefined) {
88
+ delete properties[key];
89
+ }
90
+ };
91
+ /**
92
+ * A `srcSet` is safe only when every comma-separated URL candidate is safe.
93
+ * Descriptors (`1x`, `2x`, `480w`, etc.) do not affect the URL check.
94
+ */
95
+ const stripUnsafeSrcSet = (properties) => {
96
+ const value = properties.srcSet;
97
+ if (typeof value !== 'string') {
98
+ delete properties.srcSet;
99
+ return;
100
+ }
101
+ const candidates = value.split(',');
102
+ const isSafe = candidates.length > 0 &&
103
+ candidates.every((candidate) => {
104
+ const [url] = candidate.trim().split(/\s+/, 1);
105
+ return url !== undefined && safeHref(url) !== undefined;
106
+ });
107
+ if (!isSafe) {
108
+ delete properties.srcSet;
109
+ }
110
+ };
111
+ const rejectUnsafeUrls = (node) => {
112
+ var _a;
113
+ if (node.type === 'element' && node.properties !== undefined) {
114
+ if (node.tagName === 'a') {
115
+ stripUnsafeUrlProperty(node.properties, 'href');
116
+ }
117
+ else if (node.tagName === 'img') {
118
+ stripUnsafeUrlProperty(node.properties, 'src');
119
+ }
120
+ else if (node.tagName === 'source') {
121
+ stripUnsafeSrcSet(node.properties);
122
+ }
123
+ }
124
+ (_a = node.children) === null || _a === void 0 ? void 0 : _a.forEach(rejectUnsafeUrls);
125
+ };
126
+ const rehypeRejectUnsafeUrls = () => rejectUnsafeUrls;
127
+ const withPluginOptions = (plugin, options) => {
128
+ if (Array.isArray(plugin)) {
129
+ const existingOptions = typeof plugin[1] === 'object' &&
130
+ plugin[1] !== null &&
131
+ !Array.isArray(plugin[1])
132
+ ? plugin[1]
133
+ : {};
134
+ return [plugin[0], Object.assign(Object.assign({}, existingOptions), options)];
135
+ }
136
+ return [plugin, options];
137
+ };
138
+ // Streamdown 2.7 defaults: raw, sanitize, harden (katex is no longer included).
72
139
  const rehypePlugins = [
73
- ...Object.values(defaultRehypePlugins),
140
+ defaultRehypePlugins.raw,
141
+ defaultRehypePlugins.sanitize,
142
+ // Must run before harden so network-path URLs are not rewritten to paths.
143
+ rehypeRejectUnsafeUrls,
144
+ // text-only: incomplete streamdown: URLs that harden rejects must not surface
145
+ // as visible " [blocked]" markers from the default indicator policy.
146
+ withPluginOptions(defaultRehypePlugins.harden, {
147
+ linkBlockPolicy: 'text-only',
148
+ imageBlockPolicy: 'text-only',
149
+ }),
74
150
  rehypePrefixClobberableProperties,
75
151
  ];
152
+ const ALLOWED_PROP = /^(className|id|name|title|aria-|data-|role)/;
153
+ const pickSafeProps = (props) => Object.fromEntries(Object.entries(props).filter(([key]) => ALLOWED_PROP.test(key)));
154
+ /**
155
+ * Absolute `http:` and `https:` URLs are external when their origin differs
156
+ * from the page. Same-origin absolute URLs, relative paths, fragments, and
157
+ * `mailto:` stay internal. Visual only — both still open in a new tab.
158
+ */
159
+ const isExternalHref = (href) => {
160
+ if (!/^https?:/i.test(href)) {
161
+ return false;
162
+ }
163
+ if (typeof window === 'undefined') {
164
+ return true;
165
+ }
166
+ try {
167
+ return new URL(href).origin !== window.location.origin;
168
+ }
169
+ catch (_a) {
170
+ return true;
171
+ }
172
+ };
76
173
  /**
77
174
  * The component is used to display the response from an LLM.
78
175
  * It handles markdown rendering and streaming.
79
176
  *
177
+ * @remarks
178
+ * Treat `children` as untrusted. Link and image URLs are limited to `http:`,
179
+ * `https:`, `mailto:`, and same-origin relative or fragment paths. Unsafe
180
+ * schemes (for example `javascript:`) and network-path URLs (for example
181
+ * `//evil.example`) render as plain text for links and are omitted for images.
182
+ * Markdown attributes are allow-listed so event handlers cannot reach the DOM.
183
+ * Allowed links open in a new tab with a fixed `rel="noopener noreferrer"`
184
+ * (`target` and `rel` from markdown are ignored). Absolute `http:` and
185
+ * `https:` links use `TextLink` `type="external"` when their origin differs
186
+ * from the page, and `type="internal"` when it matches. Relative, fragment,
187
+ * and `mailto:` links use `type="internal"`.
188
+ * Ids and related attributes from model output are prefixed with
189
+ * `user-content-` to avoid colliding with the host document.
190
+ *
80
191
  * @alpha - Changes to this component may be breaking.
81
192
  */
82
193
  const Response = memo((_a) => {
@@ -123,7 +234,16 @@ const Response = memo((_a) => {
123
234
  if ((href === null || href === void 0 ? void 0 : href.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)) === true) {
124
235
  return _jsx("span", { className: className, children: children });
125
236
  }
126
- return (_jsx(TextLink, { type: "internal", className: className, href: href, htmlAttributes: props, children: children }));
237
+ const cleanHref = safeHref(href);
238
+ if (cleanHref === undefined) {
239
+ // Unsafe or unknown scheme: render text, not a clickable link.
240
+ return _jsx("span", { className: className, children: children });
241
+ }
242
+ return (_jsx(TextLink, { type: isExternalHref(cleanHref) ? 'external' : 'internal', className: className, href: cleanHref,
243
+ // Harden sets target="_blank" on every allowed link. Re-apply
244
+ // it here: TextLink's internal type defaults to the same tab,
245
+ // and the allow-list drops `target` and `rel` from markdown.
246
+ target: "_blank", htmlAttributes: Object.assign(Object.assign({}, pickSafeProps(props)), { rel: 'noopener noreferrer' }), children: children }));
127
247
  },
128
248
  // oxlint-disable-next-line no-unused-vars
129
249
  h1: (_a) => {
@@ -255,7 +375,11 @@ const Response = memo((_a) => {
255
375
  src.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)) {
256
376
  return null;
257
377
  }
258
- return (_jsx("img", Object.assign({ className: classNames(className), src: src, alt: alt }, props)));
378
+ const cleanSrc = safeHref(src);
379
+ if (cleanSrc === undefined) {
380
+ return null;
381
+ }
382
+ return (_jsx("img", Object.assign({ className: classNames(className), src: cleanSrc, alt: alt }, pickSafeProps(props))));
259
383
  },
260
384
  }), []);
261
385
  return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('ndl-ai-response', className) }, restProps, htmlAttributes, { children: _jsx(Streamdown, { isAnimating: isAnimating, parseIncompleteMarkdown: isAnimating, components: components, rehypePlugins: rehypePlugins, children: children }) })));
@@ -1 +1 @@
1
- {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../../src/ai/response/Response.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,2BAA2B;AAC3B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG9D,OAAO,EAAqB,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,+BAA+B,GAAG,aAAa,CAAC;AAEtD,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,MAAM,sBAAsB,GAAG;IAC7B,IAAI;IAC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IACT,CACP,CAAC;AACJ,CAAC,EACD,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CACpE,CAAC;AAEF,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n// oxlint-disable sort-keys\nimport { Code, TextLink, Typography } from '@neo4j-ndl/react';\nimport classNames from 'classnames';\nimport { memo, useMemo, useRef } from 'react';\nimport { defaultRehypePlugins, Streamdown } from 'streamdown';\n\nimport { type CommonProps } from '../../_common/types';\nimport { type LanguageProp, Languages } from '../../code-block/code-languages';\nimport { CodePreview } from '../code-preview';\n\nconst STREAMDOWN_PLACEHOLDER_PROTOCOL = 'streamdown:';\n\nconst CLOBBER_PREFIX = 'user-content-';\nconst CLOBBERABLE_PROPERTIES = [\n 'id',\n 'name',\n 'ariaDescribedBy',\n 'ariaLabelledBy',\n];\n\ntype HastNode = {\n type: string;\n properties?: Record<string, unknown>;\n children?: HastNode[];\n};\n\nconst prefixClobberValue = (value: unknown) =>\n typeof value === 'string' && !value.startsWith(CLOBBER_PREFIX)\n ? `${CLOBBER_PREFIX}${value}`\n : value;\n\nconst prefixClobberableProperties = (node: HastNode) => {\n if (node.type === 'element' && node.properties !== undefined) {\n for (const key of CLOBBERABLE_PROPERTIES) {\n const value = node.properties[key];\n if (value === undefined || value === null) {\n continue;\n }\n node.properties[key] = Array.isArray(value)\n ? value.map(prefixClobberValue)\n : prefixClobberValue(value);\n }\n }\n node.children?.forEach(prefixClobberableProperties);\n};\n\n/**\n * Streamdown 2 sanitizes with an empty `clobberPrefix`, which lets ids and\n * names from model output collide with the host document (DOM clobbering).\n * Prefixing after sanitization keeps already prefixed footnote ids intact.\n */\nconst rehypePrefixClobberableProperties = () => prefixClobberableProperties;\n\nconst rehypePlugins = [\n ...Object.values(defaultRehypePlugins),\n rehypePrefixClobberableProperties,\n];\n\ntype ResponseProps = {\n /** The response from the AI */\n children: string;\n /** Whether the response is animating */\n isAnimating?: React.ComponentProps<typeof Streamdown>['isAnimating'];\n};\n\n/**\n * The component is used to display the response from an LLM.\n * It handles markdown rendering and streaming.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst Response = memo(\n ({\n className,\n children,\n isAnimating = false,\n ref,\n style,\n htmlAttributes,\n ...restProps\n }: CommonProps<'div', ResponseProps>) => {\n // Use a ref to store the current markdown content so we can check for unclosed fences\n // without recreating the components object on every render\n const childrenRef = useRef(children);\n childrenRef.current = children;\n\n const components: React.ComponentProps<typeof Streamdown>['components'] =\n useMemo(\n () => ({\n // oxlint-disable-next-line no-unused-vars\n ol: ({ node, children, className, ref: _ref, ...props }) => (\n <ol className={className} {...props}>\n {children}\n </ol>\n ),\n // oxlint-disable-next-line no-unused-vars\n ul: ({ node, children, className, ref: _ref, ...props }) => (\n <ul className={classNames(className)} {...props}>\n {children}\n </ul>\n ),\n // oxlint-disable-next-line no-unused-vars\n li: ({ node, children, className, ref: _ref, ...props }) => (\n <li className={className} {...props}>\n {children}\n </li>\n ),\n // oxlint-disable-next-line no-unused-vars\n hr: ({ node, className, ref: _ref, ...props }) => (\n <hr className={classNames(className)} {...props} />\n ),\n // oxlint-disable-next-line no-unused-vars\n strong: ({\n node: _node,\n children,\n className,\n style,\n ref: _ref,\n ...props\n }) => (\n <Typography\n as=\"strong\"\n variant=\"body-medium\"\n className={className}\n style={{ ...style, fontWeight: 'bold' }}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars\n em: ({ node, children, className, style, ref: _ref, ...props }) => (\n <Typography\n as=\"em\"\n variant=\"body-medium\"\n className={className}\n style={{ ...style, fontStyle: 'italic' }}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars, id-length\n a: ({ node: _node, children, className, href, ...props }) => {\n // Streamdown marks links whose URL is still streaming with a placeholder href\n if (href?.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL) === true) {\n return <span className={className}>{children}</span>;\n }\n return (\n <TextLink\n type=\"internal\"\n className={className}\n href={href}\n htmlAttributes={props}\n >\n {children}\n </TextLink>\n );\n },\n // oxlint-disable-next-line no-unused-vars\n h1: ({ node, children, className, ...props }) => (\n <h1 className={className} {...props}>\n {children}\n </h1>\n ),\n // oxlint-disable-next-line no-unused-vars\n h2: ({ node, children, className, ...props }) => (\n <h2 className={className} {...props}>\n {children}\n </h2>\n ),\n // oxlint-disable-next-line no-unused-vars\n h3: ({ node, children, className, ...props }) => (\n <h3 className={className} {...props}>\n {children}\n </h3>\n ),\n // oxlint-disable-next-line no-unused-vars\n h4: ({ node, children, className, ...props }) => (\n <h4 className={className} {...props}>\n {children}\n </h4>\n ),\n // oxlint-disable-next-line no-unused-vars\n h5: ({ node, children, className, ...props }) => (\n <h5 className={className} {...props}>\n {children}\n </h5>\n ),\n // oxlint-disable-next-line no-unused-vars\n h6: ({ node, children, className, ...props }) => (\n <h6 className={className} {...props}>\n {children}\n </h6>\n ),\n // oxlint-disable-next-line no-unused-vars\n table: ({ node, children, className, ref: _ref, ...props }) => (\n <div className=\"ndl-ai-response-table-wrapper\">\n <table className={className} {...props}>\n {children}\n </table>\n </div>\n ),\n // oxlint-disable-next-line no-unused-vars\n thead: ({ node, children, className, ref: _ref, ...props }) => (\n <thead className={className} {...props}>\n {children}\n </thead>\n ),\n // oxlint-disable-next-line no-unused-vars\n tbody: ({ node, children, className, ref: _ref, ...props }) => (\n <tbody className={className} {...props}>\n {children}\n </tbody>\n ),\n // oxlint-disable-next-line no-unused-vars\n tr: ({ node, children, className, ref: _ref, ...props }) => (\n <tr className={className} {...props}>\n {children}\n </tr>\n ),\n // oxlint-disable-next-line no-unused-vars\n th: ({ node, children, className, ref: _ref, ...props }) => (\n <th className={className} {...props}>\n {children}\n </th>\n ),\n // oxlint-disable-next-line no-unused-vars\n td: ({ node, children, className, ref: _ref, ...props }) => (\n <td className={className} {...props}>\n {children}\n </td>\n ),\n // oxlint-disable-next-line no-unused-vars\n sup: ({ node, children, className, ref: _ref, ...props }) => (\n <sup className={className} {...props}>\n {children}\n </sup>\n ),\n // oxlint-disable-next-line no-unused-vars\n sub: ({ node, children, className, ref: _ref, ...props }) => (\n <sub className={className} {...props}>\n {children}\n </sub>\n ),\n // oxlint-disable-next-line no-unused-vars\n blockquote: ({ node, children, className, ref: _ref, ...props }) => (\n <blockquote className={classNames(className)} {...props}>\n {children}\n </blockquote>\n ),\n code: ({ node, className, children: codeChildren, ...props }) => {\n const isInline =\n node?.position?.start.line === node?.position?.end.line;\n\n const nodeClassNamesRaw = node?.properties?.className;\n const nodeClassNamesArray: string[] = [];\n\n if (typeof nodeClassNamesRaw === 'string') {\n nodeClassNamesArray.push.apply(\n nodeClassNamesArray,\n nodeClassNamesRaw.split(' '),\n );\n } else if (Array.isArray(nodeClassNamesRaw)) {\n nodeClassNamesArray.push.apply(\n nodeClassNamesArray,\n nodeClassNamesRaw as string[],\n );\n }\n\n let language: LanguageProp | 'text' = 'text';\n const rawLanguage = nodeClassNamesArray.find((string: string) =>\n string.startsWith('language-'),\n );\n if (rawLanguage !== undefined) {\n language =\n (rawLanguage.replace('language-', '') as LanguageProp) ??\n 'text';\n }\n language = (Languages as readonly string[]).includes(language)\n ? (language as LanguageProp)\n : 'text';\n if (isInline) {\n return (\n <Code\n isRunnable={false}\n className={className}\n htmlAttributes={props}\n >\n {codeChildren}\n </Code>\n );\n }\n if (typeof codeChildren === 'string') {\n // Check if code fences are balanced in the markdown\n // If there are an odd number of fences, it means there's an unclosed code block\n const fenceMatches = childrenRef.current.match(/```/g);\n const fenceCount = fenceMatches ? fenceMatches.length : 0;\n const hasUnclosedFence = fenceCount % 2 !== 0;\n\n // Show loading state when there's an unclosed fence (code block is streaming)\n const isCodeBlockLoading = hasUnclosedFence;\n return (\n <CodePreview\n key={props.key}\n code={codeChildren}\n isLoading={isCodeBlockLoading}\n language={language}\n className={className}\n htmlAttributes={{\n ...props,\n }}\n />\n );\n } else {\n return <code className={className}>{codeChildren}</code>;\n }\n },\n // oxlint-disable-next-line no-unused-vars\n pre: ({ node, className, children, ref: _ref, ...props }) => {\n return (\n <pre className={className} {...props}>\n {children}\n </pre>\n );\n },\n // oxlint-disable-next-line no-unused-vars, id-length\n p: ({ node: _node, children, className, ref: _ref, ...props }) => (\n <Typography\n as=\"p\"\n variant=\"body-medium\"\n className={classNames(className)}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars\n img: ({ node, className, src, alt, ref: _ref, ...props }) => {\n if (\n typeof src === 'string' &&\n src.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)\n ) {\n return null;\n }\n return (\n <img\n className={classNames(className)}\n src={src}\n alt={alt}\n {...props}\n />\n );\n },\n }),\n [],\n );\n\n return (\n <div\n ref={ref}\n style={style}\n className={classNames('ndl-ai-response', className)}\n {...restProps}\n {...htmlAttributes}\n >\n <Streamdown\n isAnimating={isAnimating}\n parseIncompleteMarkdown={isAnimating}\n components={components}\n rehypePlugins={rehypePlugins}\n >\n {children}\n </Streamdown>\n </div>\n );\n },\n (prevProps, nextProps) => prevProps.children === nextProps.children,\n);\n\nResponse.displayName = 'Response';\n\nexport { Response };\n"]}
1
+ {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../../src/ai/response/Response.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;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U,CAAC,+BAA+B,CAAC,EAC/C,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC/B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,CACL,4BACE,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,EAChC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,GAAG,IACJ,aAAa,CAAQ,KAAK,CAAC,EAC/B,CACH,CAAC;QACJ,CAAC;KACF,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO,CACL,4BACE,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,IAC/C,SAAS,EACT,cAAc,cAElB,KAAC,UAAU,IACT,WAAW,EAAE,WAAW,EACxB,uBAAuB,EAAE,WAAW,EACpC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,YAE3B,QAAQ,GACE,IACT,CACP,CAAC;AACJ,CAAC,EACD,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CACpE,CAAC;AAEF,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\n// oxlint-disable sort-keys\nimport { Code, TextLink, Typography } from '@neo4j-ndl/react';\nimport classNames from 'classnames';\nimport { memo, useMemo, useRef } from 'react';\nimport { defaultRehypePlugins, Streamdown } from 'streamdown';\n\nimport { type CommonProps, type HtmlAttributes } from '../../_common/types';\nimport { type LanguageProp, Languages } from '../../code-block/code-languages';\nimport { CodePreview } from '../code-preview';\nimport { safeHref } from './safe-href';\n\nconst STREAMDOWN_PLACEHOLDER_PROTOCOL = 'streamdown:';\n\nconst CLOBBER_PREFIX = 'user-content-';\nconst CLOBBERABLE_PROPERTIES = [\n 'id',\n 'name',\n 'ariaDescribedBy',\n 'ariaLabelledBy',\n];\n\ntype HastNode = {\n type: string;\n tagName?: string;\n properties?: Record<string, unknown>;\n children?: HastNode[];\n};\n\nconst prefixClobberValue = (value: unknown) =>\n typeof value === 'string' && !value.startsWith(CLOBBER_PREFIX)\n ? `${CLOBBER_PREFIX}${value}`\n : value;\n\nconst prefixClobberableProperties = (node: HastNode) => {\n if (node.type === 'element' && node.properties !== undefined) {\n for (const key of CLOBBERABLE_PROPERTIES) {\n const value = node.properties[key];\n if (value === undefined || value === null) {\n continue;\n }\n node.properties[key] = Array.isArray(value)\n ? value.map(prefixClobberValue)\n : prefixClobberValue(value);\n }\n }\n node.children?.forEach(prefixClobberableProperties);\n};\n\n/**\n * Streamdown 2 sanitizes with an empty `clobberPrefix`, which lets ids and\n * names from model output collide with the host document (DOM clobbering).\n * Prefixing after sanitization keeps already prefixed footnote ids intact.\n */\nconst rehypePrefixClobberableProperties = () => prefixClobberableProperties;\n\n/**\n * Strip unsafe `href`/`src` before rehype-harden. Harden 1.1.x with wildcard\n * prefixes rewrites network-path URLs (e.g. `//evil.example/path` → `/path`),\n * which would bypass `safeHref` in the React overrides.\n */\nconst stripUnsafeUrlProperty = (\n properties: Record<string, unknown>,\n key: 'href' | 'src',\n) => {\n const value = properties[key];\n if (typeof value !== 'string') {\n return;\n }\n // Leave streaming placeholders for harden / the React override.\n if (value.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)) {\n return;\n }\n if (safeHref(value) === undefined) {\n delete properties[key];\n }\n};\n\n/**\n * A `srcSet` is safe only when every comma-separated URL candidate is safe.\n * Descriptors (`1x`, `2x`, `480w`, etc.) do not affect the URL check.\n */\nconst stripUnsafeSrcSet = (properties: Record<string, unknown>) => {\n const value = properties.srcSet;\n if (typeof value !== 'string') {\n delete properties.srcSet;\n return;\n }\n\n const candidates = value.split(',');\n const isSafe =\n candidates.length > 0 &&\n candidates.every((candidate) => {\n const [url] = candidate.trim().split(/\\s+/, 1);\n return url !== undefined && safeHref(url) !== undefined;\n });\n\n if (!isSafe) {\n delete properties.srcSet;\n }\n};\n\nconst rejectUnsafeUrls = (node: HastNode) => {\n if (node.type === 'element' && node.properties !== undefined) {\n if (node.tagName === 'a') {\n stripUnsafeUrlProperty(node.properties, 'href');\n } else if (node.tagName === 'img') {\n stripUnsafeUrlProperty(node.properties, 'src');\n } else if (node.tagName === 'source') {\n stripUnsafeSrcSet(node.properties);\n }\n }\n node.children?.forEach(rejectUnsafeUrls);\n};\n\nconst rehypeRejectUnsafeUrls = () => rejectUnsafeUrls;\n\nconst withPluginOptions = (\n plugin: (typeof defaultRehypePlugins)[string],\n options: Record<string, unknown>,\n): NonNullable<\n React.ComponentProps<typeof Streamdown>['rehypePlugins']\n>[number] => {\n if (Array.isArray(plugin)) {\n const existingOptions =\n typeof plugin[1] === 'object' &&\n plugin[1] !== null &&\n !Array.isArray(plugin[1])\n ? plugin[1]\n : {};\n return [plugin[0], { ...existingOptions, ...options }] as NonNullable<\n React.ComponentProps<typeof Streamdown>['rehypePlugins']\n >[number];\n }\n return [plugin, options] as NonNullable<\n React.ComponentProps<typeof Streamdown>['rehypePlugins']\n >[number];\n};\n\n// Streamdown 2.7 defaults: raw, sanitize, harden (katex is no longer included).\nconst rehypePlugins: NonNullable<\n React.ComponentProps<typeof Streamdown>['rehypePlugins']\n> = [\n defaultRehypePlugins.raw,\n defaultRehypePlugins.sanitize,\n // Must run before harden so network-path URLs are not rewritten to paths.\n rehypeRejectUnsafeUrls,\n // text-only: incomplete streamdown: URLs that harden rejects must not surface\n // as visible \" [blocked]\" markers from the default indicator policy.\n withPluginOptions(defaultRehypePlugins.harden, {\n linkBlockPolicy: 'text-only',\n imageBlockPolicy: 'text-only',\n }),\n rehypePrefixClobberableProperties,\n];\n\ntype ResponseProps = {\n /** Markdown content from the AI. URLs and attributes are sanitized before render. */\n children: string;\n /** Whether the response is animating */\n isAnimating?: React.ComponentProps<typeof Streamdown>['isAnimating'];\n};\n\nconst ALLOWED_PROP = /^(className|id|name|title|aria-|data-|role)/;\n\nconst pickSafeProps = <T extends React.ElementType>(\n props: Record<string, unknown>,\n): HtmlAttributes<T> =>\n Object.fromEntries(\n Object.entries(props).filter(([key]) => ALLOWED_PROP.test(key)),\n ) as HtmlAttributes<T>;\n\n/**\n * Absolute `http:` and `https:` URLs are external when their origin differs\n * from the page. Same-origin absolute URLs, relative paths, fragments, and\n * `mailto:` stay internal. Visual only — both still open in a new tab.\n */\nconst isExternalHref = (href: string): boolean => {\n if (!/^https?:/i.test(href)) {\n return false;\n }\n if (typeof window === 'undefined') {\n return true;\n }\n try {\n return new URL(href).origin !== window.location.origin;\n } catch {\n return true;\n }\n};\n\n/**\n * The component is used to display the response from an LLM.\n * It handles markdown rendering and streaming.\n *\n * @remarks\n * Treat `children` as untrusted. Link and image URLs are limited to `http:`,\n * `https:`, `mailto:`, and same-origin relative or fragment paths. Unsafe\n * schemes (for example `javascript:`) and network-path URLs (for example\n * `//evil.example`) render as plain text for links and are omitted for images.\n * Markdown attributes are allow-listed so event handlers cannot reach the DOM.\n * Allowed links open in a new tab with a fixed `rel=\"noopener noreferrer\"`\n * (`target` and `rel` from markdown are ignored). Absolute `http:` and\n * `https:` links use `TextLink` `type=\"external\"` when their origin differs\n * from the page, and `type=\"internal\"` when it matches. Relative, fragment,\n * and `mailto:` links use `type=\"internal\"`.\n * Ids and related attributes from model output are prefixed with\n * `user-content-` to avoid colliding with the host document.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst Response = memo(\n ({\n className,\n children,\n isAnimating = false,\n ref,\n style,\n htmlAttributes,\n ...restProps\n }: CommonProps<'div', ResponseProps>) => {\n // Use a ref to store the current markdown content so we can check for unclosed fences\n // without recreating the components object on every render\n const childrenRef = useRef(children);\n childrenRef.current = children;\n\n const components: React.ComponentProps<typeof Streamdown>['components'] =\n useMemo(\n () => ({\n // oxlint-disable-next-line no-unused-vars\n ol: ({ node, children, className, ref: _ref, ...props }) => (\n <ol className={className} {...props}>\n {children}\n </ol>\n ),\n // oxlint-disable-next-line no-unused-vars\n ul: ({ node, children, className, ref: _ref, ...props }) => (\n <ul className={classNames(className)} {...props}>\n {children}\n </ul>\n ),\n // oxlint-disable-next-line no-unused-vars\n li: ({ node, children, className, ref: _ref, ...props }) => (\n <li className={className} {...props}>\n {children}\n </li>\n ),\n // oxlint-disable-next-line no-unused-vars\n hr: ({ node, className, ref: _ref, ...props }) => (\n <hr className={classNames(className)} {...props} />\n ),\n // oxlint-disable-next-line no-unused-vars\n strong: ({\n node: _node,\n children,\n className,\n style,\n ref: _ref,\n ...props\n }) => (\n <Typography\n as=\"strong\"\n variant=\"body-medium\"\n className={className}\n style={{ ...style, fontWeight: 'bold' }}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars\n em: ({ node, children, className, style, ref: _ref, ...props }) => (\n <Typography\n as=\"em\"\n variant=\"body-medium\"\n className={className}\n style={{ ...style, fontStyle: 'italic' }}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars, id-length\n a: ({ node: _node, children, className, href, ...props }) => {\n // Streamdown marks links whose URL is still streaming with a placeholder href\n if (href?.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL) === true) {\n return <span className={className}>{children}</span>;\n }\n const cleanHref = safeHref(href);\n if (cleanHref === undefined) {\n // Unsafe or unknown scheme: render text, not a clickable link.\n return <span className={className}>{children}</span>;\n }\n return (\n <TextLink\n type={isExternalHref(cleanHref) ? 'external' : 'internal'}\n className={className}\n href={cleanHref}\n // Harden sets target=\"_blank\" on every allowed link. Re-apply\n // it here: TextLink's internal type defaults to the same tab,\n // and the allow-list drops `target` and `rel` from markdown.\n target=\"_blank\"\n htmlAttributes={{\n ...pickSafeProps<'a'>(props),\n rel: 'noopener noreferrer',\n }}\n >\n {children}\n </TextLink>\n );\n },\n // oxlint-disable-next-line no-unused-vars\n h1: ({ node, children, className, ...props }) => (\n <h1 className={className} {...props}>\n {children}\n </h1>\n ),\n // oxlint-disable-next-line no-unused-vars\n h2: ({ node, children, className, ...props }) => (\n <h2 className={className} {...props}>\n {children}\n </h2>\n ),\n // oxlint-disable-next-line no-unused-vars\n h3: ({ node, children, className, ...props }) => (\n <h3 className={className} {...props}>\n {children}\n </h3>\n ),\n // oxlint-disable-next-line no-unused-vars\n h4: ({ node, children, className, ...props }) => (\n <h4 className={className} {...props}>\n {children}\n </h4>\n ),\n // oxlint-disable-next-line no-unused-vars\n h5: ({ node, children, className, ...props }) => (\n <h5 className={className} {...props}>\n {children}\n </h5>\n ),\n // oxlint-disable-next-line no-unused-vars\n h6: ({ node, children, className, ...props }) => (\n <h6 className={className} {...props}>\n {children}\n </h6>\n ),\n // oxlint-disable-next-line no-unused-vars\n table: ({ node, children, className, ref: _ref, ...props }) => (\n <div className=\"ndl-ai-response-table-wrapper\">\n <table className={className} {...props}>\n {children}\n </table>\n </div>\n ),\n // oxlint-disable-next-line no-unused-vars\n thead: ({ node, children, className, ref: _ref, ...props }) => (\n <thead className={className} {...props}>\n {children}\n </thead>\n ),\n // oxlint-disable-next-line no-unused-vars\n tbody: ({ node, children, className, ref: _ref, ...props }) => (\n <tbody className={className} {...props}>\n {children}\n </tbody>\n ),\n // oxlint-disable-next-line no-unused-vars\n tr: ({ node, children, className, ref: _ref, ...props }) => (\n <tr className={className} {...props}>\n {children}\n </tr>\n ),\n // oxlint-disable-next-line no-unused-vars\n th: ({ node, children, className, ref: _ref, ...props }) => (\n <th className={className} {...props}>\n {children}\n </th>\n ),\n // oxlint-disable-next-line no-unused-vars\n td: ({ node, children, className, ref: _ref, ...props }) => (\n <td className={className} {...props}>\n {children}\n </td>\n ),\n // oxlint-disable-next-line no-unused-vars\n sup: ({ node, children, className, ref: _ref, ...props }) => (\n <sup className={className} {...props}>\n {children}\n </sup>\n ),\n // oxlint-disable-next-line no-unused-vars\n sub: ({ node, children, className, ref: _ref, ...props }) => (\n <sub className={className} {...props}>\n {children}\n </sub>\n ),\n // oxlint-disable-next-line no-unused-vars\n blockquote: ({ node, children, className, ref: _ref, ...props }) => (\n <blockquote className={classNames(className)} {...props}>\n {children}\n </blockquote>\n ),\n code: ({ node, className, children: codeChildren, ...props }) => {\n const isInline =\n node?.position?.start.line === node?.position?.end.line;\n\n const nodeClassNamesRaw = node?.properties?.className;\n const nodeClassNamesArray: string[] = [];\n\n if (typeof nodeClassNamesRaw === 'string') {\n nodeClassNamesArray.push.apply(\n nodeClassNamesArray,\n nodeClassNamesRaw.split(' '),\n );\n } else if (Array.isArray(nodeClassNamesRaw)) {\n nodeClassNamesArray.push.apply(\n nodeClassNamesArray,\n nodeClassNamesRaw as string[],\n );\n }\n\n let language: LanguageProp | 'text' = 'text';\n const rawLanguage = nodeClassNamesArray.find((string: string) =>\n string.startsWith('language-'),\n );\n if (rawLanguage !== undefined) {\n language =\n (rawLanguage.replace('language-', '') as LanguageProp) ??\n 'text';\n }\n language = (Languages as readonly string[]).includes(language)\n ? (language as LanguageProp)\n : 'text';\n if (isInline) {\n return (\n <Code\n isRunnable={false}\n className={className}\n htmlAttributes={props}\n >\n {codeChildren}\n </Code>\n );\n }\n if (typeof codeChildren === 'string') {\n // Check if code fences are balanced in the markdown\n // If there are an odd number of fences, it means there's an unclosed code block\n const fenceMatches = childrenRef.current.match(/```/g);\n const fenceCount = fenceMatches ? fenceMatches.length : 0;\n const hasUnclosedFence = fenceCount % 2 !== 0;\n\n // Show loading state when there's an unclosed fence (code block is streaming)\n const isCodeBlockLoading = hasUnclosedFence;\n return (\n <CodePreview\n key={props.key}\n code={codeChildren}\n isLoading={isCodeBlockLoading}\n language={language}\n className={className}\n htmlAttributes={{\n ...props,\n }}\n />\n );\n } else {\n return <code className={className}>{codeChildren}</code>;\n }\n },\n // oxlint-disable-next-line no-unused-vars\n pre: ({ node, className, children, ref: _ref, ...props }) => {\n return (\n <pre className={className} {...props}>\n {children}\n </pre>\n );\n },\n // oxlint-disable-next-line no-unused-vars, id-length\n p: ({ node: _node, children, className, ref: _ref, ...props }) => (\n <Typography\n as=\"p\"\n variant=\"body-medium\"\n className={classNames(className)}\n {...props}\n >\n {children}\n </Typography>\n ),\n // oxlint-disable-next-line no-unused-vars\n img: ({ node, className, src, alt, ref: _ref, ...props }) => {\n if (\n typeof src === 'string' &&\n src.startsWith(STREAMDOWN_PLACEHOLDER_PROTOCOL)\n ) {\n return null;\n }\n const cleanSrc = safeHref(src);\n if (cleanSrc === undefined) {\n return null;\n }\n return (\n <img\n className={classNames(className)}\n src={cleanSrc}\n alt={alt}\n {...pickSafeProps<'img'>(props)}\n />\n );\n },\n }),\n [],\n );\n\n return (\n <div\n ref={ref}\n style={style}\n className={classNames('ndl-ai-response', className)}\n {...restProps}\n {...htmlAttributes}\n >\n <Streamdown\n isAnimating={isAnimating}\n parseIncompleteMarkdown={isAnimating}\n components={components}\n rehypePlugins={rehypePlugins}\n >\n {children}\n </Streamdown>\n </div>\n );\n },\n (prevProps, nextProps) => prevProps.children === nextProps.children,\n);\n\nResponse.displayName = 'Response';\n\nexport { Response };\n"]}
@@ -0,0 +1,104 @@
1
+ /*!
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ const SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:']);
22
+ /** Dummy https origin used only to classify relative vs absolute URLs. */
23
+ const DUMMY_BASE = 'https://safe.invalid/';
24
+ /** True when the string contains C0 controls or DEL (can obfuscate schemes). */
25
+ const hasControlCharacter = (value) => {
26
+ for (let index = 0; index < value.length; index++) {
27
+ const code = value.charCodeAt(index);
28
+ if (code <= 0x1f || code === 0x7f) {
29
+ return true;
30
+ }
31
+ }
32
+ return false;
33
+ };
34
+ /** Scheme / path / host only — excludes query and fragment. */
35
+ const structuralPrefix = (value) => {
36
+ const queryIndex = value.indexOf('?');
37
+ const fragmentIndex = value.indexOf('#');
38
+ let end = value.length;
39
+ if (queryIndex !== -1) {
40
+ end = Math.min(end, queryIndex);
41
+ }
42
+ if (fragmentIndex !== -1) {
43
+ end = Math.min(end, fragmentIndex);
44
+ }
45
+ return value.slice(0, end);
46
+ };
47
+ const tryDecode = (value) => {
48
+ try {
49
+ return decodeURIComponent(value);
50
+ }
51
+ catch (_a) {
52
+ return value;
53
+ }
54
+ };
55
+ /**
56
+ * Returns a URL safe to use as an anchor `href` or image `src`, or `undefined`
57
+ * when the value must not be rendered as a navigable/fetchable URL.
58
+ */
59
+ export const safeHref = (href) => {
60
+ if (!href) {
61
+ return undefined;
62
+ }
63
+ const trimmed = href.trim();
64
+ if (!trimmed) {
65
+ return undefined;
66
+ }
67
+ // Control characters can obfuscate schemes (e.g. java\nscript:).
68
+ if (hasControlCharacter(trimmed)) {
69
+ return undefined;
70
+ }
71
+ // Decode only the structural prefix so query/body percent-encoding (e.g.
72
+ // mailto ?body=…%0D%0A… or ?q=%5C) is not treated as URL structure.
73
+ const structure = structuralPrefix(trimmed);
74
+ const decodedStructure = tryDecode(structure);
75
+ if (hasControlCharacter(decodedStructure)) {
76
+ return undefined;
77
+ }
78
+ // Network-path / backslash forms resolve or normalize cross-origin.
79
+ if (/^[/\\]{2}/.test(trimmed) ||
80
+ /^[/\\]{2}/.test(structure) ||
81
+ /^[/\\]{2}/.test(decodedStructure) ||
82
+ structure.includes('\\') ||
83
+ decodedStructure.includes('\\')) {
84
+ return undefined;
85
+ }
86
+ let parsed;
87
+ try {
88
+ parsed = new URL(trimmed, DUMMY_BASE);
89
+ }
90
+ catch (_a) {
91
+ return undefined;
92
+ }
93
+ const hasExplicitScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed);
94
+ if (hasExplicitScheme) {
95
+ return SAFE_PROTOCOLS.has(parsed.protocol) ? trimmed : undefined;
96
+ }
97
+ // Path-/query-/fragment-relative (including bare paths like docs/page):
98
+ // must resolve against the dummy origin, not a different host.
99
+ if (parsed.origin !== new URL(DUMMY_BASE).origin) {
100
+ return undefined;
101
+ }
102
+ return trimmed;
103
+ };
104
+ //# sourceMappingURL=safe-href.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-href.js","sourceRoot":"","sources":["../../../../src/ai/response/safe-href.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAC/D,0EAA0E;AAC1E,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAW,EAAE;IACrD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAA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,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["/*!\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nconst SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:']);\n/** Dummy https origin used only to classify relative vs absolute URLs. */\nconst DUMMY_BASE = 'https://safe.invalid/';\n\n/** True when the string contains C0 controls or DEL (can obfuscate schemes). */\nconst hasControlCharacter = (value: string): boolean => {\n for (let index = 0; index < value.length; index++) {\n const code = value.charCodeAt(index);\n if (code <= 0x1f || code === 0x7f) {\n return true;\n }\n }\n return false;\n};\n\n/** Scheme / path / host only — excludes query and fragment. */\nconst structuralPrefix = (value: string): string => {\n const queryIndex = value.indexOf('?');\n const fragmentIndex = value.indexOf('#');\n let end = value.length;\n if (queryIndex !== -1) {\n end = Math.min(end, queryIndex);\n }\n if (fragmentIndex !== -1) {\n end = Math.min(end, fragmentIndex);\n }\n return value.slice(0, end);\n};\n\nconst tryDecode = (value: string): string => {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n};\n\n/**\n * Returns a URL safe to use as an anchor `href` or image `src`, or `undefined`\n * when the value must not be rendered as a navigable/fetchable URL.\n */\nexport const safeHref = (href?: string): string | undefined => {\n if (!href) {\n return undefined;\n }\n const trimmed = href.trim();\n if (!trimmed) {\n return undefined;\n }\n\n // Control characters can obfuscate schemes (e.g. java\\nscript:).\n if (hasControlCharacter(trimmed)) {\n return undefined;\n }\n\n // Decode only the structural prefix so query/body percent-encoding (e.g.\n // mailto ?body=…%0D%0A… or ?q=%5C) is not treated as URL structure.\n const structure = structuralPrefix(trimmed);\n const decodedStructure = tryDecode(structure);\n if (hasControlCharacter(decodedStructure)) {\n return undefined;\n }\n\n // Network-path / backslash forms resolve or normalize cross-origin.\n if (\n /^[/\\\\]{2}/.test(trimmed) ||\n /^[/\\\\]{2}/.test(structure) ||\n /^[/\\\\]{2}/.test(decodedStructure) ||\n structure.includes('\\\\') ||\n decodedStructure.includes('\\\\')\n ) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(trimmed, DUMMY_BASE);\n } catch {\n return undefined;\n }\n\n const hasExplicitScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed);\n\n if (hasExplicitScheme) {\n return SAFE_PROTOCOLS.has(parsed.protocol) ? trimmed : undefined;\n }\n\n // Path-/query-/fragment-relative (including bare paths like docs/page):\n // must resolve against the dummy origin, not a different host.\n if (parsed.origin !== new URL(DUMMY_BASE).origin) {\n return undefined;\n }\n\n return trimmed;\n};\n"]}