@neo4j-ndl/react 4.3.3 → 4.3.5
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/lib/cjs/_common/utils.js +9 -1
- package/lib/cjs/_common/utils.js.map +1 -1
- package/lib/cjs/ai/prompt/Prompt.js +7 -5
- package/lib/cjs/ai/prompt/Prompt.js.map +1 -1
- package/lib/cjs/ai/prompt/stories/prompt-advanced.story.js +4 -6
- package/lib/cjs/ai/prompt/stories/prompt-advanced.story.js.map +1 -1
- package/lib/cjs/ai/prompt/stories/prompt-default.story.js +4 -6
- package/lib/cjs/ai/prompt/stories/prompt-default.story.js.map +1 -1
- package/lib/cjs/ai/response/stories/response-full-example.story.js +20 -22
- package/lib/cjs/ai/response/stories/response-full-example.story.js.map +1 -1
- package/lib/cjs/text-link/TextLink.js +3 -4
- package/lib/cjs/text-link/TextLink.js.map +1 -1
- package/lib/esm/_common/utils.js +7 -0
- package/lib/esm/_common/utils.js.map +1 -1
- package/lib/esm/ai/prompt/Prompt.js +7 -5
- package/lib/esm/ai/prompt/Prompt.js.map +1 -1
- package/lib/esm/ai/prompt/stories/prompt-advanced.story.js +4 -6
- package/lib/esm/ai/prompt/stories/prompt-advanced.story.js.map +1 -1
- package/lib/esm/ai/prompt/stories/prompt-default.story.js +4 -6
- package/lib/esm/ai/prompt/stories/prompt-default.story.js.map +1 -1
- package/lib/esm/ai/response/stories/response-full-example.story.js +20 -22
- package/lib/esm/ai/response/stories/response-full-example.story.js.map +1 -1
- package/lib/esm/text-link/TextLink.js +3 -4
- package/lib/esm/text-link/TextLink.js.map +1 -1
- package/lib/types/_common/utils.d.ts +1 -0
- package/lib/types/_common/utils.d.ts.map +1 -1
- package/lib/types/ai/prompt/Prompt.d.ts +3 -1
- package/lib/types/ai/prompt/Prompt.d.ts.map +1 -1
- package/lib/types/ai/prompt/stories/prompt-advanced.story.d.ts.map +1 -1
- package/lib/types/ai/prompt/stories/prompt-default.story.d.ts.map +1 -1
- package/lib/types/ai/response/stories/response-full-example.story.d.ts.map +1 -1
- package/lib/types/text-link/TextLink.d.ts +1 -1
- package/lib/types/text-link/TextLink.d.ts.map +1 -1
- package/package.json +4 -5
package/lib/cjs/_common/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRadius = exports.RadiusDefaults = exports.getSpacing = exports.SpacingDefaults = exports.convertHexToRGB = exports.findFocusableSibling = exports.findFocusableChildren = exports.randomId = exports.useOnClickOutside = exports.useDocumentScrollToggle = exports.needleWarningMessage = exports.removeSpaces = exports.removeNewlines = void 0;
|
|
3
|
+
exports.parseRgbString = exports.getRadius = exports.RadiusDefaults = exports.getSpacing = exports.SpacingDefaults = exports.convertHexToRGB = exports.findFocusableSibling = exports.findFocusableChildren = exports.randomId = exports.useOnClickOutside = exports.useDocumentScrollToggle = exports.needleWarningMessage = exports.removeSpaces = exports.removeNewlines = void 0;
|
|
4
4
|
exports.isRefObject = isRefObject;
|
|
5
5
|
exports.findUntil = findUntil;
|
|
6
6
|
/**
|
|
@@ -202,4 +202,12 @@ const getRadius = (spacing, property) => {
|
|
|
202
202
|
: undefined;
|
|
203
203
|
};
|
|
204
204
|
exports.getRadius = getRadius;
|
|
205
|
+
const parseRgbString = (rgbString) => {
|
|
206
|
+
const match = rgbString.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
207
|
+
if (!match) {
|
|
208
|
+
throw new Error(`Unable to parse RGB color: ${rgbString}`);
|
|
209
|
+
}
|
|
210
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
211
|
+
};
|
|
212
|
+
exports.parseRgbString = parseRgbString;
|
|
205
213
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":";;;AAoHA,kCAI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C,aAAM,CAAC,KAAK,CAAC,OAAO,IAAI,uBAAe,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEW,QAAA,cAAc,GAAG;IAC5B,YAAY,EAAE,SAAS;CACxB,CAAC;AAEK,MAAM,SAAS,GAAG,CACvB,OAA2B,EAC3B,QAAqC,EACrC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,aAAM,CAAC,YAAY,CAAC,OAAO,IAAI,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,SAAS,aAOpB","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 { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":";;;AAoHA,kCAIC;AAWD,8BA6BC;AAhKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,0CAAyC;AACzC,iCAMe;AAIR,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAC9C,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AADzB,QAAA,cAAc,kBACW;AAEtC,qCAAqC;AAC9B,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,MA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C,YAAY,CAAC,OAAO,IAAI,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,SAAS,aAOpB;AAEK,MAAM,cAAc,GAAG,CAAC,SAAiB,EAA4B,EAAE;IAC5E,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","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 { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n\nexport const parseRgbString = (rgbString: string): [number, number, number] => {\n const match = rgbString.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/);\n if (!match) {\n throw new Error(`Unable to parse RGB color: ${rgbString}`);\n }\n return [Number(match[1]), Number(match[2]), Number(match[3])];\n};\n"]}
|
|
@@ -48,7 +48,7 @@ const react_2 = require("react");
|
|
|
48
48
|
* @alpha - Changes to this component may be breaking.
|
|
49
49
|
*/
|
|
50
50
|
const PromptComponent = (_a) => {
|
|
51
|
-
var { value, onChange, maxRows = 5, isRunningPrompt = false, onSubmitPrompt, isSubmitDisabled = false, topContent, bottomContent, disclaimer = 'All information should be verified.', className, style, htmlAttributes, ref, textareaProps } = _a, restProps = __rest(_a, ["value", "onChange", "maxRows", "isRunningPrompt", "onSubmitPrompt", "isSubmitDisabled", "topContent", "bottomContent", "disclaimer", "className", "style", "htmlAttributes", "ref", "textareaProps"]);
|
|
51
|
+
var { value, onChange, maxRows = 5, isRunningPrompt = false, onSubmitPrompt, onCancelPrompt, isSubmitDisabled = false, topContent, bottomContent, disclaimer = 'All information should be verified.', className, style, htmlAttributes, ref, textareaProps } = _a, restProps = __rest(_a, ["value", "onChange", "maxRows", "isRunningPrompt", "onSubmitPrompt", "onCancelPrompt", "isSubmitDisabled", "topContent", "bottomContent", "disclaimer", "className", "style", "htmlAttributes", "ref", "textareaProps"]);
|
|
52
52
|
const classes = (0, classnames_1.default)('ndl-ai-prompt', className);
|
|
53
53
|
const textareaRef = (0, react_2.useRef)(null);
|
|
54
54
|
const textareaAboveRef = (0, react_2.useRef)(null);
|
|
@@ -130,13 +130,15 @@ const PromptComponent = (_a) => {
|
|
|
130
130
|
!e.shiftKey &&
|
|
131
131
|
isSubmitDisabled !== true) {
|
|
132
132
|
e.preventDefault();
|
|
133
|
-
|
|
133
|
+
if (isRunningPrompt !== true) {
|
|
134
|
+
onSubmitPrompt === null || onSubmitPrompt === void 0 ? void 0 : onSubmitPrompt(e);
|
|
135
|
+
}
|
|
134
136
|
}
|
|
135
|
-
} }, textareaProps)), (0, jsx_runtime_1.jsxs)("div", { className: "ndl-ai-prompt-textarea-below", children: [Boolean(bottomContent) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-ai-prompt-textarea-below-leading", children: bottomContent })), (0, jsx_runtime_1.jsx)(SumbitPromptButton, { isDisabled: isSubmitDisabled, isRunningPrompt: isRunningPrompt,
|
|
137
|
+
} }, textareaProps)), (0, jsx_runtime_1.jsxs)("div", { className: "ndl-ai-prompt-textarea-below", children: [Boolean(bottomContent) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-ai-prompt-textarea-below-leading", children: bottomContent })), (0, jsx_runtime_1.jsx)(SumbitPromptButton, { isDisabled: isSubmitDisabled, isRunningPrompt: isRunningPrompt, onSubmit: onSubmitPrompt, onCancel: onCancelPrompt })] })] }) }), Boolean(disclaimer) && ((0, jsx_runtime_1.jsx)(react_1.Typography, { variant: "body-small", className: "ndl-ai-prompt-footer", children: disclaimer }))] })));
|
|
136
138
|
};
|
|
137
|
-
const SumbitPromptButton = ({
|
|
139
|
+
const SumbitPromptButton = ({ onSubmit, onCancel, isDisabled, isRunningPrompt, }) => {
|
|
138
140
|
const description = isRunningPrompt === true ? 'Cancel' : 'Send';
|
|
139
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.CleanIconButton, { className: "ndl-ai-prompt-submit-button", description: description, size: "medium", onClick:
|
|
141
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.CleanIconButton, { className: "ndl-ai-prompt-submit-button", description: description, size: "medium", onClick: isRunningPrompt === true ? onCancel : onSubmit, isDisabled: isDisabled, children: [(0, jsx_runtime_1.jsx)(icons_1.ArrowSmallUpIconOutline, { style: {
|
|
140
142
|
opacity: isRunningPrompt === true ? 0 : 1,
|
|
141
143
|
position: isRunningPrompt === true ? 'absolute' : 'relative',
|
|
142
144
|
transform: isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prompt.js","sourceRoot":"","sources":["../../../../src/ai/prompt/Prompt.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4CAK0B;AAC1B,kDAIgC;AAChC,4DAAoC;AACpC,iCAAiE;AA+BjE;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,EAgBS,EAAE,EAAE;QAhBb,EACvB,KAAK,EACL,QA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G,CAAC,EAC3C,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,SAAS,YAEb,YAAY,GACE,EACjB,uBAAC,YAAI,IACH,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,EACnC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAC,wBAAwB,YAElC,uBAAC,YAAI,CAAC,KAAK,cACR,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,uBAAC,YAAI,CAAC,IAAI,IAER,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EACtC,aAAa,EACX,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,MAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,uBAAC,wBAAgB,KAAG,CAAC,CAAC,CAAC,IAAI,IAJxD,MAAM,CAAC,KAAK,CAMjB,CACH,CAAC,GACS,GACR,IACN,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC;AAEM,wBAAM","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\nimport {\n CleanIconButton,\n DropdownButton,\n Menu,\n Typography,\n} from '@neo4j-ndl/react';\nimport {\n ArrowSmallUpIconOutline,\n CheckIconOutline,\n StopCircleIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport classNames from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { CommonProps, HtmlAttributes } from '../../_common/types';\n\ntype PromptProps = {\n /** The prompt text */\n value?: React.ComponentPropsWithoutRef<'textarea'>['value'];\n /** Callback function called when the prompt text changes */\n onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;\n /** Whether the submit button is disabled */\n isSubmitDisabled?: boolean;\n /** Maximum number of rows the textarea can expand to */\n maxRows?: number;\n /** Whether the submit button is \"running\". Shows a stop icon when true. */\n isRunningPrompt?: boolean;\n /** Callback function called when the submit button is clicked */\n onSubmitPrompt?: (\n e:\n | React.KeyboardEvent<HTMLTextAreaElement>\n | React.MouseEvent<HTMLButtonElement, MouseEvent>,\n ) => void;\n /** Content to display above the textarea */\n topContent?: React.ReactNode;\n /** Content to display below the textarea */\n bottomContent?: React.ReactNode;\n /** Disclaimer to display below the component */\n disclaimer?: React.ReactNode;\n /** Props for the textarea element */\n textareaProps?: HtmlAttributes<'textarea'>;\n};\n\n/**\n * The component is used to display the prompt input for an LLM.\n * It includes a textarea for the user to enter their prompt and a submit button.\n * It can also display content above and below the textarea, like uploaded files or a select for changing agents.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst PromptComponent = ({\n value,\n onChange,\n maxRows = 5,\n isRunningPrompt = false,\n onSubmitPrompt,\n isSubmitDisabled = false,\n topContent,\n bottomContent,\n disclaimer = 'All information should be verified.',\n className,\n style,\n htmlAttributes,\n ref,\n textareaProps,\n ...restProps\n}: CommonProps<'div', PromptProps>) => {\n const classes = classNames('ndl-ai-prompt', className);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const textareaAboveRef = useRef<HTMLDivElement>(null);\n const [lineHeight, setLineHeight] = useState(0);\n\n /** File overflow stuff */\n useEffect(() => {\n let rafId: number | null = null;\n\n const checkOverflow = () => {\n if (textareaAboveRef.current !== null) {\n const element = textareaAboveRef.current;\n const maxHeight = parseFloat(\n getComputedStyle(element).maxHeight.replace('px', ''),\n );\n const scrollHeight = element.scrollHeight;\n\n if (scrollHeight > maxHeight) {\n element.classList.add('ndl-can-scroll');\n } else {\n element.classList.remove('ndl-can-scroll');\n }\n }\n };\n\n const debouncedCheck = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(checkOverflow);\n };\n\n // Initial check\n checkOverflow();\n\n const resizeObserver = new ResizeObserver(debouncedCheck);\n const mutationObserver = new MutationObserver(debouncedCheck);\n\n if (textareaAboveRef.current !== null) {\n resizeObserver.observe(textareaAboveRef.current);\n mutationObserver.observe(textareaAboveRef.current, {\n childList: true,\n subtree: true,\n });\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, []);\n\n /** Textarea stuff */\n useEffect(() => {\n if (textareaRef.current !== null) {\n const computed = window.getComputedStyle(textareaRef.current);\n setLineHeight(parseInt(computed.lineHeight));\n }\n }, []);\n\n const adjustTextareaHeight = useCallback(() => {\n const ta = textareaRef.current;\n\n if (ta !== null && lineHeight > 0) {\n // Reset height so scrollHeight measures correctly\n ta.style.height = 'auto';\n\n const maxHeight = lineHeight * maxRows;\n\n if (ta.scrollHeight <= maxHeight) {\n ta.style.overflowY = 'hidden';\n ta.style.height = `${ta.scrollHeight}px`;\n } else {\n ta.style.overflowY = 'auto';\n ta.style.height = `${maxHeight}px`;\n }\n }\n }, [lineHeight, maxRows]);\n\n // Adjust height when prompt value changes (including when cleared)\n useEffect(() => {\n adjustTextareaHeight();\n }, [value, adjustTextareaHeight]);\n\n const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n adjustTextareaHeight();\n onChange?.(e);\n };\n\n return (\n <div\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-ai-prompt-wrapper\">\n <div className=\"ndl-ai-prompt-wrapper-inner\">\n {Boolean(topContent) && (\n <div\n className=\"ndl-ai-prompt-textarea-above\"\n ref={textareaAboveRef}\n >\n {topContent}\n </div>\n )}\n <textarea\n placeholder=\"Ask anything\"\n className=\"ndl-ai-prompt-textarea\"\n rows={1}\n onChange={handleInput}\n value={value}\n ref={textareaRef}\n onKeyDown={(e) => {\n if (\n e.key === 'Enter' &&\n !e.shiftKey &&\n isSubmitDisabled !== true\n ) {\n e.preventDefault();\n onSubmitPrompt?.(e);\n }\n }}\n {...textareaProps}\n />\n <div className=\"ndl-ai-prompt-textarea-below\">\n {Boolean(bottomContent) && (\n <div className=\"ndl-ai-prompt-textarea-below-leading\">\n {bottomContent}\n </div>\n )}\n <SumbitPromptButton\n isDisabled={isSubmitDisabled}\n isRunningPrompt={isRunningPrompt}\n onClick={onSubmitPrompt}\n />\n </div>\n </div>\n </div>\n {Boolean(disclaimer) && (\n <Typography variant=\"body-small\" className=\"ndl-ai-prompt-footer\">\n {disclaimer}\n </Typography>\n )}\n </div>\n );\n};\n\nconst SumbitPromptButton = ({\n onClick,\n isDisabled,\n isRunningPrompt,\n}: {\n isDisabled?: boolean;\n isRunningPrompt?: boolean;\n onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n}) => {\n const description = isRunningPrompt === true ? 'Cancel' : 'Send';\n\n return (\n <CleanIconButton\n className=\"ndl-ai-prompt-submit-button\"\n description={description}\n size=\"medium\"\n onClick={onClick}\n isDisabled={isDisabled}\n >\n <ArrowSmallUpIconOutline\n style={{\n opacity: isRunningPrompt === true ? 0 : 1,\n position: isRunningPrompt === true ? 'absolute' : 'relative',\n transform:\n isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',\n }}\n />\n <StopCircleIconOutline\n style={{\n opacity: isRunningPrompt === true ? 1 : 0,\n position: isRunningPrompt === true ? 'relative' : 'absolute',\n }}\n />\n </CleanIconButton>\n );\n};\n\ntype AgentSelectProps = {\n value: { label: React.ReactNode; value: string };\n options: Array<{ label: React.ReactNode; value: string }>;\n onChange: (option: { label: React.ReactNode; value: string }) => void;\n};\n\nconst AgentSelect = ({ value, options = [], onChange }: AgentSelectProps) => {\n const anchorRef = useRef<HTMLButtonElement>(null);\n const [isMenuOpen, setIsMenuOpen] = useState(false);\n\n const displayLabel = value?.label ?? options[0]?.label ?? '';\n\n const handleItemClick = (option: {\n label: React.ReactNode;\n value: string;\n }) => {\n onChange?.(option);\n setIsMenuOpen(false);\n };\n\n return (\n <>\n <DropdownButton\n size=\"small\"\n className=\"ndl-ai-prompt-dropdown-button\"\n onClick={() => setIsMenuOpen((old) => !old)}\n isOpen={isMenuOpen}\n ref={anchorRef}\n >\n {displayLabel}\n </DropdownButton>\n <Menu\n isOpen={isMenuOpen}\n onClose={() => setIsMenuOpen(false)}\n anchorRef={anchorRef}\n placement=\"top-start-bottom-start\"\n >\n <Menu.Items>\n {options.map((option) => (\n <Menu.Item\n key={option.value}\n title={option.label}\n onClick={() => handleItemClick(option)}\n leadingVisual={\n value?.value === option.value ? <CheckIconOutline /> : null\n }\n />\n ))}\n </Menu.Items>\n </Menu>\n </>\n );\n};\n\nconst Prompt = Object.assign(PromptComponent, {\n Select: AgentSelect,\n});\n\nexport { Prompt };\n"]}
|
|
1
|
+
{"version":3,"file":"Prompt.js","sourceRoot":"","sources":["../../../../src/ai/prompt/Prompt.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4CAK0B;AAC1B,kDAIgC;AAChC,4DAAoC;AACpC,iCAAiE;AAiCjE;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,EAiBS,EAAE,EAAE;QAjBb,EACvB,KAAK,EACL,QAAQ,EACR,OAAO,GAAG,CAAC,EACX,eAAe,GAAG,KAAK,EACvB,cAAc,EACd,cAAc,EACd,gBAAgB,GAAG,KAAK,EACxB,UAAU,EACV,aAAa,EACb,UA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AC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAC3C,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,SAAS,YAEb,YAAY,GACE,EACjB,uBAAC,YAAI,IACH,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,EACnC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAC,wBAAwB,YAElC,uBAAC,YAAI,CAAC,KAAK,cACR,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,uBAAC,YAAI,CAAC,IAAI,IAER,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EACtC,aAAa,EACX,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,MAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,uBAAC,wBAAgB,KAAG,CAAC,CAAC,CAAC,IAAI,IAJxD,MAAM,CAAC,KAAK,CAMjB,CACH,CAAC,GACS,GACR,IACN,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC;AAEM,wBAAM","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\nimport {\n CleanIconButton,\n DropdownButton,\n Menu,\n Typography,\n} from '@neo4j-ndl/react';\nimport {\n ArrowSmallUpIconOutline,\n CheckIconOutline,\n StopCircleIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport classNames from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { CommonProps, HtmlAttributes } from '../../_common/types';\n\ntype PromptProps = {\n /** The prompt text */\n value?: React.ComponentPropsWithoutRef<'textarea'>['value'];\n /** Callback function called when the prompt text changes */\n onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;\n /** Whether the submit button is disabled */\n isSubmitDisabled?: boolean;\n /** Maximum number of rows the textarea can expand to */\n maxRows?: number;\n /** Whether the submit button is \"running\". Shows a stop icon when true. */\n isRunningPrompt?: boolean;\n /** Callback function called when the submit button is clicked */\n onSubmitPrompt?: (\n e:\n | React.KeyboardEvent<HTMLTextAreaElement>\n | React.MouseEvent<HTMLButtonElement, MouseEvent>,\n ) => void;\n /** Callback function called when the cancel button is clicked */\n onCancelPrompt?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n /** Content to display above the textarea */\n topContent?: React.ReactNode;\n /** Content to display below the textarea */\n bottomContent?: React.ReactNode;\n /** Disclaimer to display below the component */\n disclaimer?: React.ReactNode;\n /** Props for the textarea element */\n textareaProps?: HtmlAttributes<'textarea'>;\n};\n\n/**\n * The component is used to display the prompt input for an LLM.\n * It includes a textarea for the user to enter their prompt and a submit button.\n * It can also display content above and below the textarea, like uploaded files or a select for changing agents.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst PromptComponent = ({\n value,\n onChange,\n maxRows = 5,\n isRunningPrompt = false,\n onSubmitPrompt,\n onCancelPrompt,\n isSubmitDisabled = false,\n topContent,\n bottomContent,\n disclaimer = 'All information should be verified.',\n className,\n style,\n htmlAttributes,\n ref,\n textareaProps,\n ...restProps\n}: CommonProps<'div', PromptProps>) => {\n const classes = classNames('ndl-ai-prompt', className);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const textareaAboveRef = useRef<HTMLDivElement>(null);\n const [lineHeight, setLineHeight] = useState(0);\n\n /** File overflow stuff */\n useEffect(() => {\n let rafId: number | null = null;\n\n const checkOverflow = () => {\n if (textareaAboveRef.current !== null) {\n const element = textareaAboveRef.current;\n const maxHeight = parseFloat(\n getComputedStyle(element).maxHeight.replace('px', ''),\n );\n const scrollHeight = element.scrollHeight;\n\n if (scrollHeight > maxHeight) {\n element.classList.add('ndl-can-scroll');\n } else {\n element.classList.remove('ndl-can-scroll');\n }\n }\n };\n\n const debouncedCheck = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(checkOverflow);\n };\n\n // Initial check\n checkOverflow();\n\n const resizeObserver = new ResizeObserver(debouncedCheck);\n const mutationObserver = new MutationObserver(debouncedCheck);\n\n if (textareaAboveRef.current !== null) {\n resizeObserver.observe(textareaAboveRef.current);\n mutationObserver.observe(textareaAboveRef.current, {\n childList: true,\n subtree: true,\n });\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, []);\n\n /** Textarea stuff */\n useEffect(() => {\n if (textareaRef.current !== null) {\n const computed = window.getComputedStyle(textareaRef.current);\n setLineHeight(parseInt(computed.lineHeight));\n }\n }, []);\n\n const adjustTextareaHeight = useCallback(() => {\n const ta = textareaRef.current;\n\n if (ta !== null && lineHeight > 0) {\n // Reset height so scrollHeight measures correctly\n ta.style.height = 'auto';\n\n const maxHeight = lineHeight * maxRows;\n\n if (ta.scrollHeight <= maxHeight) {\n ta.style.overflowY = 'hidden';\n ta.style.height = `${ta.scrollHeight}px`;\n } else {\n ta.style.overflowY = 'auto';\n ta.style.height = `${maxHeight}px`;\n }\n }\n }, [lineHeight, maxRows]);\n\n // Adjust height when prompt value changes (including when cleared)\n useEffect(() => {\n adjustTextareaHeight();\n }, [value, adjustTextareaHeight]);\n\n const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n adjustTextareaHeight();\n onChange?.(e);\n };\n\n return (\n <div\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-ai-prompt-wrapper\">\n <div className=\"ndl-ai-prompt-wrapper-inner\">\n {Boolean(topContent) && (\n <div\n className=\"ndl-ai-prompt-textarea-above\"\n ref={textareaAboveRef}\n >\n {topContent}\n </div>\n )}\n <textarea\n placeholder=\"Ask anything\"\n className=\"ndl-ai-prompt-textarea\"\n rows={1}\n onChange={handleInput}\n value={value}\n ref={textareaRef}\n onKeyDown={(e) => {\n if (\n e.key === 'Enter' &&\n !e.shiftKey &&\n isSubmitDisabled !== true\n ) {\n e.preventDefault();\n\n if (isRunningPrompt !== true) {\n onSubmitPrompt?.(e);\n }\n }\n }}\n {...textareaProps}\n />\n <div className=\"ndl-ai-prompt-textarea-below\">\n {Boolean(bottomContent) && (\n <div className=\"ndl-ai-prompt-textarea-below-leading\">\n {bottomContent}\n </div>\n )}\n <SumbitPromptButton\n isDisabled={isSubmitDisabled}\n isRunningPrompt={isRunningPrompt}\n onSubmit={onSubmitPrompt}\n onCancel={onCancelPrompt}\n />\n </div>\n </div>\n </div>\n {Boolean(disclaimer) && (\n <Typography variant=\"body-small\" className=\"ndl-ai-prompt-footer\">\n {disclaimer}\n </Typography>\n )}\n </div>\n );\n};\n\nconst SumbitPromptButton = ({\n onSubmit,\n onCancel,\n isDisabled,\n isRunningPrompt,\n}: {\n isDisabled?: boolean;\n isRunningPrompt?: boolean;\n onSubmit?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n onCancel?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n}) => {\n const description = isRunningPrompt === true ? 'Cancel' : 'Send';\n\n return (\n <CleanIconButton\n className=\"ndl-ai-prompt-submit-button\"\n description={description}\n size=\"medium\"\n onClick={isRunningPrompt === true ? onCancel : onSubmit}\n isDisabled={isDisabled}\n >\n <ArrowSmallUpIconOutline\n style={{\n opacity: isRunningPrompt === true ? 0 : 1,\n position: isRunningPrompt === true ? 'absolute' : 'relative',\n transform:\n isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',\n }}\n />\n <StopCircleIconOutline\n style={{\n opacity: isRunningPrompt === true ? 1 : 0,\n position: isRunningPrompt === true ? 'relative' : 'absolute',\n }}\n />\n </CleanIconButton>\n );\n};\n\ntype AgentSelectProps = {\n value: { label: React.ReactNode; value: string };\n options: Array<{ label: React.ReactNode; value: string }>;\n onChange: (option: { label: React.ReactNode; value: string }) => void;\n};\n\nconst AgentSelect = ({ value, options = [], onChange }: AgentSelectProps) => {\n const anchorRef = useRef<HTMLButtonElement>(null);\n const [isMenuOpen, setIsMenuOpen] = useState(false);\n\n const displayLabel = value?.label ?? options[0]?.label ?? '';\n\n const handleItemClick = (option: {\n label: React.ReactNode;\n value: string;\n }) => {\n onChange?.(option);\n setIsMenuOpen(false);\n };\n\n return (\n <>\n <DropdownButton\n size=\"small\"\n className=\"ndl-ai-prompt-dropdown-button\"\n onClick={() => setIsMenuOpen((old) => !old)}\n isOpen={isMenuOpen}\n ref={anchorRef}\n >\n {displayLabel}\n </DropdownButton>\n <Menu\n isOpen={isMenuOpen}\n onClose={() => setIsMenuOpen(false)}\n anchorRef={anchorRef}\n placement=\"top-start-bottom-start\"\n >\n <Menu.Items>\n {options.map((option) => (\n <Menu.Item\n key={option.value}\n title={option.label}\n onClick={() => handleItemClick(option)}\n leadingVisual={\n value?.value === option.value ? <CheckIconOutline /> : null\n }\n />\n ))}\n </Menu.Items>\n </Menu>\n </>\n );\n};\n\nconst Prompt = Object.assign(PromptComponent, {\n Select: AgentSelect,\n});\n\nexport { Prompt };\n"]}
|
|
@@ -36,13 +36,11 @@ const Component = () => {
|
|
|
36
36
|
const [selectedOption, setSelectedOption] = (0, react_2.useState)(options[0]);
|
|
37
37
|
const [prompt, setPrompt] = (0, react_2.useState)('');
|
|
38
38
|
const handleSubmitPrompt = () => {
|
|
39
|
-
setIsRunningPrompt(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
setPrompt('');
|
|
43
|
-
}
|
|
39
|
+
setIsRunningPrompt(true);
|
|
40
|
+
alert(`You submitted the following prompt: ${prompt}`);
|
|
41
|
+
setPrompt('');
|
|
44
42
|
};
|
|
45
|
-
return ((0, jsx_runtime_1.jsx)(ai_1.Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, topContent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ai_1.FileTag, { isLoading: true, icon: (0, jsx_runtime_1.jsx)(icons_1.DocumentIconOutline, {}), fileName: "Science Fiction Bestsellers", fileType: "pdf", isRemovable: true, onClick: () => {
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ai_1.Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, onCancelPrompt: () => setIsRunningPrompt(false), topContent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ai_1.FileTag, { isLoading: true, icon: (0, jsx_runtime_1.jsx)(icons_1.DocumentIconOutline, {}), fileName: "Science Fiction Bestsellers", fileType: "pdf", isRemovable: true, onClick: () => {
|
|
46
44
|
console.info('remove file');
|
|
47
45
|
} }), (0, jsx_runtime_1.jsx)(ai_1.ImageTag, { isLoading: true, src: "https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", alt: "Landscape image", fileName: "Landscape image", fileType: "jpg", isRemovable: true, onClick: () => {
|
|
48
46
|
console.info('remove image');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-advanced.story.js","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-advanced.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAAmD;AACnD,4CAAgE;AAChE,kDAA8E;AAC9E,iCAAiC;AAEjC,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAqD;QAChE,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE;QACrC,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,EAAE;QAClD,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,EAAE;KACnD,CAAC;IACF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IAEzC,MAAM,kBAAkB,GAAG,GAAG,EAAE;QAC9B,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"prompt-advanced.story.js","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-advanced.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAAmD;AACnD,4CAAgE;AAChE,kDAA8E;AAC9E,iCAAiC;AAEjC,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAqD;QAChE,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE;QACrC,EAAE,KAAK,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ACZ,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC,GACD,EACF,uBAAC,YAAO,IACN,IAAI,EAAE,uBAAC,2BAAmB,KAAG,EAC7B,QAAQ,EAAC,6BAA6B,EACtC,QAAQ,EAAC,KAAK,EACd,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,GAAG,EAAE;wBACZ,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC9B,CAAC,GACD,EACF,uBAAC,aAAQ,IACP,GAAG,EAAC,8KAA8K,EAClL,GAAG,EAAC,iBAAiB,EACrB,QAAQ,EAAC,iBAAiB,EAC1B,QAAQ,EAAC,KAAK,EACd,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,GAAG,EAAE;wBACZ,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC,GACD,IACD,EAEL,aAAa,EACX,6DACE,uBAAC,WAAM,CAAC,MAAM,IACZ,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,iBAAiB,GAC3B,EACF,uBAAC,uBAAe,IAAC,WAAW,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,YACnD,uBAAC,uBAAe,KAAG,GACH,IACjB,GAEL,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,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\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { CleanIconButton } from '@neo4j-ndl/react';\nimport { FileTag, ImageTag, Prompt } from '@neo4j-ndl/react/ai';\nimport { DocumentIconOutline, PlusIconOutline } from '@neo4j-ndl/react/icons';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [isRunningPrompt, setIsRunningPrompt] = useState(false);\n const options: Array<{ label: React.ReactNode; value: string }> = [\n { label: 'Neo4j AI', value: 'neo4j' },\n { label: 'Special Agent', value: 'special-agent' },\n { label: 'Another Agent', value: 'another-agent' },\n ];\n const [selectedOption, setSelectedOption] = useState(options[0]);\n const [prompt, setPrompt] = useState('');\n\n const handleSubmitPrompt = () => {\n setIsRunningPrompt(true);\n alert(`You submitted the following prompt: ${prompt}`);\n setPrompt('');\n };\n\n return (\n <Prompt\n isRunningPrompt={isRunningPrompt}\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={handleSubmitPrompt}\n onCancelPrompt={() => setIsRunningPrompt(false)}\n topContent={\n <>\n <FileTag\n isLoading={true}\n icon={<DocumentIconOutline />}\n fileName=\"Science Fiction Bestsellers\"\n fileType=\"pdf\"\n isRemovable={true}\n onClick={() => {\n console.info('remove file');\n }}\n />\n <ImageTag\n isLoading={true}\n src=\"https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"Landscape image\"\n fileName=\"Landscape image\"\n fileType=\"jpg\"\n isRemovable={true}\n onClick={() => {\n console.info('remove image');\n }}\n />\n <FileTag\n icon={<DocumentIconOutline />}\n fileName=\"Science Fiction Bestsellers\"\n fileType=\"pdf\"\n isRemovable={true}\n onClick={() => {\n console.info('remove file');\n }}\n />\n <ImageTag\n src=\"https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"Landscape image\"\n fileName=\"Landscape image\"\n fileType=\"jpg\"\n isRemovable={true}\n onClick={() => {\n console.info('remove image');\n }}\n />\n </>\n }\n bottomContent={\n <>\n <Prompt.Select\n value={selectedOption}\n options={options}\n onChange={setSelectedOption}\n />\n <CleanIconButton description=\"Add stuff\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n </>\n }\n />\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -28,13 +28,11 @@ const Component = () => {
|
|
|
28
28
|
const [prompt, setPrompt] = (0, react_1.useState)('');
|
|
29
29
|
const [isRunningPrompt, setIsRunningPrompt] = (0, react_1.useState)(false);
|
|
30
30
|
const handleSubmitPrompt = () => {
|
|
31
|
-
setIsRunningPrompt(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setPrompt('');
|
|
35
|
-
}
|
|
31
|
+
setIsRunningPrompt(true);
|
|
32
|
+
alert(`You submitted the following prompt: ${prompt}`);
|
|
33
|
+
setPrompt('');
|
|
36
34
|
};
|
|
37
|
-
return ((0, jsx_runtime_1.jsx)(ai_1.Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt }));
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(ai_1.Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, onCancelPrompt: () => setIsRunningPrompt(false) }));
|
|
38
36
|
};
|
|
39
37
|
exports.default = Component;
|
|
40
38
|
//# sourceMappingURL=prompt-default.story.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-default.story.js","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-default.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmB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ourcesContent":["/**\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\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { Prompt } from '@neo4j-ndl/react/ai';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [prompt, setPrompt] = useState('');\n const [isRunningPrompt, setIsRunningPrompt] = useState(false);\n\n const handleSubmitPrompt = () => {\n setIsRunningPrompt(true);\n alert(`You submitted the following prompt: ${prompt}`);\n setPrompt('');\n };\n\n return (\n <Prompt\n isRunningPrompt={isRunningPrompt}\n value={prompt}\n onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>\n setPrompt(e.target.value)\n }\n onSubmitPrompt={handleSubmitPrompt}\n onCancelPrompt={() => setIsRunningPrompt(false)}\n />\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -67,28 +67,26 @@ const Component = () => {
|
|
|
67
67
|
(0, react_2.useEffect)(() => {
|
|
68
68
|
scrollToBottom();
|
|
69
69
|
}, [messages, isThinking]);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (intervalRef.current) {
|
|
77
|
-
clearInterval(intervalRef.current);
|
|
78
|
-
}
|
|
79
|
-
setIsThinking(false);
|
|
80
|
-
setIsStreaming(false);
|
|
81
|
-
// Mark the last message as done if stopped
|
|
82
|
-
setMessages((prev) => {
|
|
83
|
-
const newMessages = [...prev];
|
|
84
|
-
const lastMessage = newMessages[newMessages.length - 1];
|
|
85
|
-
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
|
|
86
|
-
lastMessage.done = true;
|
|
87
|
-
}
|
|
88
|
-
return newMessages;
|
|
89
|
-
});
|
|
90
|
-
return;
|
|
70
|
+
const handleCancel = () => {
|
|
71
|
+
if (timeoutRef.current) {
|
|
72
|
+
clearTimeout(timeoutRef.current);
|
|
73
|
+
}
|
|
74
|
+
if (intervalRef.current) {
|
|
75
|
+
clearInterval(intervalRef.current);
|
|
91
76
|
}
|
|
77
|
+
setIsThinking(false);
|
|
78
|
+
setIsStreaming(false);
|
|
79
|
+
// Mark the last message as done if stopped
|
|
80
|
+
setMessages((prev) => {
|
|
81
|
+
const newMessages = [...prev];
|
|
82
|
+
const lastMessage = newMessages[newMessages.length - 1];
|
|
83
|
+
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
|
|
84
|
+
lastMessage.done = true;
|
|
85
|
+
}
|
|
86
|
+
return newMessages;
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const handleSend = (overridePrompt) => {
|
|
92
90
|
const textToSend = overridePrompt || prompt;
|
|
93
91
|
if (!textToSend.trim()) {
|
|
94
92
|
return;
|
|
@@ -155,7 +153,7 @@ const Component = () => {
|
|
|
155
153
|
}, children: "Generate a report" })] }), (0, jsx_runtime_1.jsxs)(react_1.Typography, { variant: "body-medium", children: ["You can also drag and drop files here, or", ' ', (0, jsx_runtime_1.jsx)(react_1.TextLink, { as: "button", type: "internal-underline", children: "browse" }), ". Supports CVG, MOV, PDF"] })] }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-col n-gap-4 n-pb-4", children: [messages.map((msg, idx) => ((0, jsx_runtime_1.jsx)("div", { className: `n-flex ${msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'}`, children: msg.role === 'user' ? ((0, jsx_runtime_1.jsx)("div", { className: "n-max-w-[85%]", children: (0, jsx_runtime_1.jsx)(ai_1.UserBubble, { avatarProps: {
|
|
156
154
|
name: 'NM',
|
|
157
155
|
type: 'letters',
|
|
158
|
-
}, children: msg.content }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: "n-w-full n-flex n-flex-col n-gap-2", children: [msg.thinkingTime !== undefined && ((0, jsx_runtime_1.jsx)(ai_1.Thinking, { isThinking: false, thinkingMs: msg.thinkingTime })), (0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-col n-gap-2", children: [(0, jsx_runtime_1.jsx)(ai_1.Response, { children: msg.content }), msg.done === true && ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-row n-gap-1.5", children: [(0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Dislike", children: (0, jsx_runtime_1.jsx)(icons_1.HandThumbDownIconOutline, {}) }), (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Re-run", children: (0, jsx_runtime_1.jsx)(icons_1.ArrowPathIconOutline, {}) }), (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Copy", children: (0, jsx_runtime_1.jsx)(icons_1.Square2StackIconOutline, {}) })] }))] })] })) }, idx))), isThinking && (0, jsx_runtime_1.jsx)(ai_1.Thinking, { isThinking: true }), (0, jsx_runtime_1.jsx)("div", { ref: messagesEndRef })] })) }), (0, jsx_runtime_1.jsx)("div", { className: "n-px-4 n-pt-4 n-pb-1 n-mt-auto", children: (0, jsx_runtime_1.jsx)(ai_1.Prompt, { value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: () => handleSend(), isRunningPrompt: isThinking || isStreaming, isSubmitDisabled: prompt.length === 0 && !(isThinking || isStreaming), bottomContent: (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { description: "Add files", size: "small", children: (0, jsx_runtime_1.jsx)(icons_1.PlusIconOutline, {}) }) }) })] }) }));
|
|
156
|
+
}, children: msg.content }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: "n-w-full n-flex n-flex-col n-gap-2", children: [msg.thinkingTime !== undefined && ((0, jsx_runtime_1.jsx)(ai_1.Thinking, { isThinking: false, thinkingMs: msg.thinkingTime })), (0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-col n-gap-2", children: [(0, jsx_runtime_1.jsx)(ai_1.Response, { children: msg.content }), msg.done === true && ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-row n-gap-1.5", children: [(0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Dislike", children: (0, jsx_runtime_1.jsx)(icons_1.HandThumbDownIconOutline, {}) }), (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Re-run", children: (0, jsx_runtime_1.jsx)(icons_1.ArrowPathIconOutline, {}) }), (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { size: "small", description: "Copy", children: (0, jsx_runtime_1.jsx)(icons_1.Square2StackIconOutline, {}) })] }))] })] })) }, idx))), isThinking && (0, jsx_runtime_1.jsx)(ai_1.Thinking, { isThinking: true }), (0, jsx_runtime_1.jsx)("div", { ref: messagesEndRef })] })) }), (0, jsx_runtime_1.jsx)("div", { className: "n-px-4 n-pt-4 n-pb-1 n-mt-auto", children: (0, jsx_runtime_1.jsx)(ai_1.Prompt, { value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: () => handleSend(), onCancelPrompt: handleCancel, isRunningPrompt: isThinking || isStreaming, isSubmitDisabled: prompt.length === 0 && !(isThinking || isStreaming), bottomContent: (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { description: "Add files", size: "small", children: (0, jsx_runtime_1.jsx)(icons_1.PlusIconOutline, {}) }) }) })] }) }));
|
|
159
157
|
};
|
|
160
158
|
exports.Component = Component;
|
|
161
159
|
exports.default = exports.Component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-full-example.story.js","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":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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 { CleanIconButton, TextLink, Typography } from '@neo4j-ndl/react';\nimport {\n Prompt,\n Response,\n Suggestion,\n Thinking,\n UserBubble,\n} from '@neo4j-ndl/react/ai';\nimport {\n ArrowPathIconOutline,\n Cog6ToothIconOutline,\n HandThumbDownIconOutline,\n PlusIconOutline,\n Square2StackIconOutline,\n XMarkIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport { useEffect, useRef, useState } from 'react';\n\nconst FAKE_RESPONSES = [\n `Here is a simple response with some **bold text** and *italics*.`,\n `Here is a list of items:\n- Item 1\n- Item 2\n- Item 3`,\n `Here is a code block example:\n\n\\`\\`\\`typescript\nconst greeting = \"Hello World\";\nconsole.log(greeting);\n\\`\\`\\`\n`,\n `# Heading 1\n## Heading 2\n### Heading 3\n\nSome text under headings.`,\n `You can also use tables:\n\n| Header 1 | Header 2 |\n|Data 1|Data 2|\n|Data 3|Data 4|\n`,\n];\n\nexport const Component = () => {\n const [messages, setMessages] = useState<\n {\n role: 'user' | 'assistant';\n content: string;\n thinkingTime?: number;\n done?: boolean;\n }[]\n >([]);\n const [prompt, setPrompt] = useState('');\n const [isThinking, setIsThinking] = useState(false);\n const [isStreaming, setIsStreaming] = useState(false);\n const [responseIndex, setResponseIndex] = useState(0);\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n\n const scrollToBottom = () => {\n messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages, isThinking]);\n\n const handleSend = (overridePrompt?: string) => {\n // Handle Stop\n if (isThinking || isStreaming) {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsThinking(false);\n setIsStreaming(false);\n\n // Mark the last message as done if stopped\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage?.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n return;\n }\n\n const textToSend = overridePrompt || prompt;\n\n if (!textToSend.trim()) {\n return;\n }\n\n setMessages((prev) => [...prev, { content: textToSend, role: 'user' }]);\n setPrompt('');\n setIsThinking(true);\n const startTime = Date.now();\n\n // Simulate network delay (thinking time)\n timeoutRef.current = setTimeout(() => {\n const endTime = Date.now();\n const thinkingTime = endTime - startTime;\n setIsThinking(false);\n setIsStreaming(true);\n\n const responseText = FAKE_RESPONSES[responseIndex];\n setResponseIndex((prev) => (prev + 1) % FAKE_RESPONSES.length);\n\n let currentText = '';\n setMessages((prev) => [\n ...prev,\n { content: '', done: false, role: 'assistant', thinkingTime },\n ]);\n\n // Simulate streaming\n intervalRef.current = setInterval(() => {\n if (currentText.length < responseText.length) {\n // Add a few characters at a time to simulate chunks\n // Ensure we don't split newlines incorrectly if that's an issue,\n // but simple slicing should be fine as long as the source has \\n.\n const chunk = responseText.slice(\n currentText.length,\n currentText.length + 2,\n );\n currentText += chunk;\n\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.content = currentText;\n }\n return newMessages;\n });\n } else {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsStreaming(false);\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n }\n }, 50);\n }, 2000);\n };\n\n return (\n <section className=\"n-h-screen\">\n <div className=\"n-w-[440px] n-h-full n-flex n-flex-col n-bg-neutral-bg-weak\">\n <div className=\"n-flex n-flex-row n-border-b n-border-neutral-border-weak n-p-3\">\n <div className=\"n-ml-auto\">\n <CleanIconButton description=\"settings\" tooltipProps={{}}>\n <Cog6ToothIconOutline />\n </CleanIconButton>\n <CleanIconButton description=\"close\">\n <XMarkIconOutline />\n </CleanIconButton>\n </div>\n </div>\n <div className=\"n-p-4 n-flex n-flex-col n-grow n-overflow-y-auto\">\n {messages.length === 0 ? (\n <div className=\"n-flex n-flex-col \">\n <div className=\"n-flex n-flex-col n-gap-12\">\n <Typography variant=\"display\">\n Hi [User], how can I help you today?\n </Typography>\n <div className=\"n-flex n-flex-col n-gap-4\">\n <Typography variant=\"body-medium\">Suggestions</Typography>\n <Suggestion\n isPrimary\n onClick={() => {\n handleSend('I want to import data');\n }}\n >\n I want to import data\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Create an AI agent');\n }}\n >\n Create an AI agent\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Invite project members');\n }}\n >\n Invite project members\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Generate a report');\n }}\n >\n Generate a report\n </Suggestion>\n </div>\n <Typography variant=\"body-medium\">\n You can also drag and drop files here, or{' '}\n <TextLink as=\"button\" type=\"internal-underline\">\n browse\n </TextLink>\n . Supports CVG, MOV, PDF\n </Typography>\n </div>\n </div>\n ) : (\n <div className=\"n-flex n-flex-col n-gap-4 n-pb-4\">\n {messages.map((msg, idx) => (\n <div\n key={idx}\n className={`n-flex ${\n msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'\n }`}\n >\n {msg.role === 'user' ? (\n <div className=\"n-max-w-[85%]\">\n <UserBubble\n avatarProps={{\n name: 'NM',\n type: 'letters',\n }}\n >\n {msg.content}\n </UserBubble>\n </div>\n ) : (\n <div className=\"n-w-full n-flex n-flex-col n-gap-2\">\n {msg.thinkingTime !== undefined && (\n <Thinking\n isThinking={false}\n thinkingMs={msg.thinkingTime}\n />\n )}\n <div className=\"n-flex n-flex-col n-gap-2\">\n <Response>{msg.content}</Response>\n\n {msg.done === true && (\n <div className=\"n-flex n-flex-row n-gap-1.5\">\n <CleanIconButton size=\"small\" description=\"Dislike\">\n <HandThumbDownIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Re-run\">\n <ArrowPathIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Copy\">\n <Square2StackIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n </div>\n )}\n </div>\n ))}\n {isThinking && <Thinking isThinking={true} />}\n <div ref={messagesEndRef} />\n </div>\n )}\n </div>\n <div className=\"n-px-4 n-pt-4 n-pb-1 n-mt-auto\">\n <Prompt\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={() => handleSend()}\n isRunningPrompt={isThinking || isStreaming}\n isSubmitDisabled={\n prompt.length === 0 && !(isThinking || isStreaming)\n }\n bottomContent={\n <CleanIconButton description=\"Add files\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n }\n />\n </div>\n </div>\n </section>\n );\n};\n\nexport default Component;\n"]}
|
|
1
|
+
{"version":3,"file":"response-full-example.story.js","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4CAAyE;AACzE,4CAM6B;AAC7B,kDAOgC;AAChC,iCAAoD;AAEpD,MAAM,cAAc,GAAG;IACrB,kEAAkE;IAClE;;;SAGO;IACP;;;;;;CAMD;IACC;;;;0BAIwB;IACxB;;;;;CAKD;CACA,CAAC;AAEK,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAOtC,EAAE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,EAAC,OAAO,EAAC,WAAW,EAAC,MAAM,YAC9C,uBAAC,+BAAuB,KAAG,GACX,IACd,CACP,IACG,IACF,CACP,IA1CI,GAAG,CA2CJ,CACP,CAAC,EACD,UAAU,IAAI,uBAAC,aAAQ,IAAC,UAAU,EAAE,IAAI,GAAI,EAC7C,gCAAK,GAAG,EAAE,cAAc,GAAI,IACxB,CACP,GACG,EACN,gCAAK,SAAS,EAAC,gCAAgC,YAC7C,uBAAC,WAAM,IACL,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,cAAc,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,EAClC,cAAc,EAAE,YAAY,EAC5B,eAAe,EAAE,UAAU,IAAI,WAAW,EAC1C,gBAAgB,EACd,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,EAErD,aAAa,EACX,uBAAC,uBAAe,IAAC,WAAW,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,YACnD,uBAAC,uBAAe,KAAG,GACH,GAEpB,GACE,IACF,GACE,CACX,CAAC;AACJ,CAAC,CAAC;AAvPW,QAAA,SAAS,aAuPpB;AAEF,kBAAe,iBAAS,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 */\nimport { CleanIconButton, TextLink, Typography } from '@neo4j-ndl/react';\nimport {\n Prompt,\n Response,\n Suggestion,\n Thinking,\n UserBubble,\n} from '@neo4j-ndl/react/ai';\nimport {\n ArrowPathIconOutline,\n Cog6ToothIconOutline,\n HandThumbDownIconOutline,\n PlusIconOutline,\n Square2StackIconOutline,\n XMarkIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport { useEffect, useRef, useState } from 'react';\n\nconst FAKE_RESPONSES = [\n `Here is a simple response with some **bold text** and *italics*.`,\n `Here is a list of items:\n- Item 1\n- Item 2\n- Item 3`,\n `Here is a code block example:\n\n\\`\\`\\`typescript\nconst greeting = \"Hello World\";\nconsole.log(greeting);\n\\`\\`\\`\n`,\n `# Heading 1\n## Heading 2\n### Heading 3\n\nSome text under headings.`,\n `You can also use tables:\n\n| Header 1 | Header 2 |\n|Data 1|Data 2|\n|Data 3|Data 4|\n`,\n];\n\nexport const Component = () => {\n const [messages, setMessages] = useState<\n {\n role: 'user' | 'assistant';\n content: string;\n thinkingTime?: number;\n done?: boolean;\n }[]\n >([]);\n const [prompt, setPrompt] = useState('');\n const [isThinking, setIsThinking] = useState(false);\n const [isStreaming, setIsStreaming] = useState(false);\n const [responseIndex, setResponseIndex] = useState(0);\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n\n const scrollToBottom = () => {\n messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages, isThinking]);\n\n const handleCancel = () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsThinking(false);\n setIsStreaming(false);\n\n // Mark the last message as done if stopped\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage?.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n };\n\n const handleSend = (overridePrompt?: string) => {\n const textToSend = overridePrompt || prompt;\n\n if (!textToSend.trim()) {\n return;\n }\n\n setMessages((prev) => [...prev, { content: textToSend, role: 'user' }]);\n setPrompt('');\n setIsThinking(true);\n const startTime = Date.now();\n\n // Simulate network delay (thinking time)\n timeoutRef.current = setTimeout(() => {\n const endTime = Date.now();\n const thinkingTime = endTime - startTime;\n setIsThinking(false);\n setIsStreaming(true);\n\n const responseText = FAKE_RESPONSES[responseIndex];\n setResponseIndex((prev) => (prev + 1) % FAKE_RESPONSES.length);\n\n let currentText = '';\n setMessages((prev) => [\n ...prev,\n { content: '', done: false, role: 'assistant', thinkingTime },\n ]);\n\n // Simulate streaming\n intervalRef.current = setInterval(() => {\n if (currentText.length < responseText.length) {\n // Add a few characters at a time to simulate chunks\n // Ensure we don't split newlines incorrectly if that's an issue,\n // but simple slicing should be fine as long as the source has \\n.\n const chunk = responseText.slice(\n currentText.length,\n currentText.length + 2,\n );\n currentText += chunk;\n\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.content = currentText;\n }\n return newMessages;\n });\n } else {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsStreaming(false);\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n }\n }, 50);\n }, 2000);\n };\n\n return (\n <section className=\"n-h-screen\">\n <div className=\"n-w-[440px] n-h-full n-flex n-flex-col n-bg-neutral-bg-weak\">\n <div className=\"n-flex n-flex-row n-border-b n-border-neutral-border-weak n-p-3\">\n <div className=\"n-ml-auto\">\n <CleanIconButton description=\"settings\" tooltipProps={{}}>\n <Cog6ToothIconOutline />\n </CleanIconButton>\n <CleanIconButton description=\"close\">\n <XMarkIconOutline />\n </CleanIconButton>\n </div>\n </div>\n <div className=\"n-p-4 n-flex n-flex-col n-grow n-overflow-y-auto\">\n {messages.length === 0 ? (\n <div className=\"n-flex n-flex-col \">\n <div className=\"n-flex n-flex-col n-gap-12\">\n <Typography variant=\"display\">\n Hi [User], how can I help you today?\n </Typography>\n <div className=\"n-flex n-flex-col n-gap-4\">\n <Typography variant=\"body-medium\">Suggestions</Typography>\n <Suggestion\n isPrimary\n onClick={() => {\n handleSend('I want to import data');\n }}\n >\n I want to import data\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Create an AI agent');\n }}\n >\n Create an AI agent\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Invite project members');\n }}\n >\n Invite project members\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Generate a report');\n }}\n >\n Generate a report\n </Suggestion>\n </div>\n <Typography variant=\"body-medium\">\n You can also drag and drop files here, or{' '}\n <TextLink as=\"button\" type=\"internal-underline\">\n browse\n </TextLink>\n . Supports CVG, MOV, PDF\n </Typography>\n </div>\n </div>\n ) : (\n <div className=\"n-flex n-flex-col n-gap-4 n-pb-4\">\n {messages.map((msg, idx) => (\n <div\n key={idx}\n className={`n-flex ${\n msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'\n }`}\n >\n {msg.role === 'user' ? (\n <div className=\"n-max-w-[85%]\">\n <UserBubble\n avatarProps={{\n name: 'NM',\n type: 'letters',\n }}\n >\n {msg.content}\n </UserBubble>\n </div>\n ) : (\n <div className=\"n-w-full n-flex n-flex-col n-gap-2\">\n {msg.thinkingTime !== undefined && (\n <Thinking\n isThinking={false}\n thinkingMs={msg.thinkingTime}\n />\n )}\n <div className=\"n-flex n-flex-col n-gap-2\">\n <Response>{msg.content}</Response>\n\n {msg.done === true && (\n <div className=\"n-flex n-flex-row n-gap-1.5\">\n <CleanIconButton size=\"small\" description=\"Dislike\">\n <HandThumbDownIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Re-run\">\n <ArrowPathIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Copy\">\n <Square2StackIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n </div>\n )}\n </div>\n ))}\n {isThinking && <Thinking isThinking={true} />}\n <div ref={messagesEndRef} />\n </div>\n )}\n </div>\n <div className=\"n-px-4 n-pt-4 n-pb-1 n-mt-auto\">\n <Prompt\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={() => handleSend()}\n onCancelPrompt={handleCancel}\n isRunningPrompt={isThinking || isStreaming}\n isSubmitDisabled={\n prompt.length === 0 && !(isThinking || isStreaming)\n }\n bottomContent={\n <CleanIconButton description=\"Add files\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n }\n />\n </div>\n </div>\n </section>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -39,15 +39,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
39
39
|
const classnames_1 = __importDefault(require("classnames"));
|
|
40
40
|
const icons_1 = require("../icons");
|
|
41
41
|
const TextLink = (_a) => {
|
|
42
|
-
var { children, href, type = 'internal', as, className, target, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "href", "type", "as", "className", "target", "style", "htmlAttributes", "ref"]);
|
|
43
|
-
const
|
|
44
|
-
const Component = as || 'a';
|
|
42
|
+
var { children, href, type = 'internal', as, className, target = type === 'external' ? '_blank' : '', style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "href", "type", "as", "className", "target", "style", "htmlAttributes", "ref"]);
|
|
43
|
+
const Component = as !== null && as !== void 0 ? as : 'a';
|
|
45
44
|
const classes = (0, classnames_1.default)('ndl-text-link', className, {
|
|
46
45
|
'ndl-external-link': type === 'external',
|
|
47
46
|
'ndl-internal-icon': type === 'internal-icon',
|
|
48
47
|
'ndl-internal-underline': type === 'internal-underline',
|
|
49
48
|
});
|
|
50
|
-
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, href: href, ref: ref, style: style
|
|
49
|
+
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, href: href, ref: ref, style: style, target: target }, restProps, htmlAttributes, { children: [children, type === 'external' && ((0, jsx_runtime_1.jsx)(icons_1.ArrowUpRightIconOutline, { className: "ndl-external-link-icon" })), type === 'internal-icon' && ((0, jsx_runtime_1.jsx)(icons_1.ChevronRightIconOutline, { className: "ndl-external-link-icon" }))] })));
|
|
51
50
|
};
|
|
52
51
|
exports.TextLink = TextLink;
|
|
53
52
|
//# sourceMappingURL=TextLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLink.js","sourceRoot":"","sources":["../../../src/text-link/TextLink.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAIpC,oCAA4E;AAgCrE,MAAM,QAAQ,GAAG,CAAoC,EAWjB,EAAE,EAAE;QAXa,EAC1D,QAAQ,EACR,IAAI,EACJ,IAAI,GAAG,UAAU,EACjB,EAAE,EACF,SAAS,EACT,MAAM,
|
|
1
|
+
{"version":3,"file":"TextLink.js","sourceRoot":"","sources":["../../../src/text-link/TextLink.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAIpC,oCAA4E;AAgCrE,MAAM,QAAQ,GAAG,CAAoC,EAWjB,EAAE,EAAE;QAXa,EAC1D,QAAQ,EACR,IAAI,EACJ,IAAI,GAAG,UAAU,EACjB,EAAE,EACF,SAAS,EACT,MAAM,GAAG,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAC5C,KAAK,EACL,cAAc,EACd,GAAG,OAEsC,EADtC,SAAS,cAV8C,2FAW3D,CADa;IAEZ,MAAM,SAAS,GAAsB,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,GAAG,CAAC;IAE/C,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,eAAe,EAAE,SAAS,EAAE;QACrD,mBAAmB,EAAE,IAAI,KAAK,UAAU;QACxC,mBAAmB,EAAE,IAAI,KAAK,eAAe;QAC7C,wBAAwB,EAAE,IAAI,KAAK,oBAAoB;KACxD,CAAC,CAAC;IAEH,OAAO,CACL,wBAAC,SAAS,kBACR,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,IACV,SAAS,EACT,cAAc,eAEjB,QAAQ,EACR,IAAI,KAAK,UAAU,IAAI,CACtB,uBAAC,+BAAuB,IAAC,SAAS,EAAC,wBAAwB,GAAG,CAC/D,EACA,IAAI,KAAK,eAAe,IAAI,CAC3B,uBAAC,+BAAuB,IAAC,SAAS,EAAC,wBAAwB,GAAG,CAC/D,KACS,CACb,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,QAAQ,YAuCnB","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 React from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { ArrowUpRightIconOutline, ChevronRightIconOutline } from '../icons';\n\ntype TextLinkType =\n | 'internal'\n | 'internal-underline'\n | 'internal-icon'\n | 'external';\n\ntype TextLinkProps = {\n /** The content displayed inside the link */\n children: React.ReactNode;\n\n /** The URL the link points to */\n href?: string;\n\n /**\n * The type of the text link\n * - 'internal': a link to another page within the application\n * - 'internal-underline': a link to another page within the application with an underline and support for text color\n * - 'internal-icon': a link to another page within the application with an icon\n * - 'external': a link to an external website\n * @default 'internal'\n */\n type?: TextLinkType;\n\n /** Specifies where to open the linked document. If omitted and `type` is `\"external\"` it defaults to `\"_blank\"`. */\n target?: HTMLAnchorElement['target'];\n\n /** Additional class name */\n className?: string;\n};\n\nexport const TextLink = <T extends React.ElementType = 'a'>({\n children,\n href,\n type = 'internal',\n as,\n className,\n target = type === 'external' ? '_blank' : '',\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, TextLinkProps>) => {\n const Component: React.ElementType = as ?? 'a';\n\n const classes = classNames('ndl-text-link', className, {\n 'ndl-external-link': type === 'external',\n 'ndl-internal-icon': type === 'internal-icon',\n 'ndl-internal-underline': type === 'internal-underline',\n });\n\n return (\n <Component\n className={classes}\n href={href}\n ref={ref}\n style={style}\n target={target}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n {type === 'external' && (\n <ArrowUpRightIconOutline className=\"ndl-external-link-icon\" />\n )}\n {type === 'internal-icon' && (\n <ChevronRightIconOutline className=\"ndl-external-link-icon\" />\n )}\n </Component>\n );\n};\n"]}
|
package/lib/esm/_common/utils.js
CHANGED
|
@@ -186,4 +186,11 @@ export const getRadius = (spacing, property) => {
|
|
|
186
186
|
? tokens.borderRadius[spacing || RadiusDefaults[property]]
|
|
187
187
|
: undefined;
|
|
188
188
|
};
|
|
189
|
+
export const parseRgbString = (rgbString) => {
|
|
190
|
+
const match = rgbString.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
191
|
+
if (!match) {
|
|
192
|
+
throw new Error(`Unable to parse RGB color: ${rgbString}`);
|
|
193
|
+
}
|
|
194
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
195
|
+
};
|
|
189
196
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.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e,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,SAAS;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAA2B,EAC3B,QAAqC,EACrC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;AAChB,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 */\nimport { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAGL,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAC;AAIf,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAC9C,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAEtC,qCAAqC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAA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C,SAAiB,EAA4B,EAAE;IAC5E,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,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 */\nimport { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n\nexport const parseRgbString = (rgbString: string): [number, number, number] => {\n const match = rgbString.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/);\n if (!match) {\n throw new Error(`Unable to parse RGB color: ${rgbString}`);\n }\n return [Number(match[1]), Number(match[2]), Number(match[3])];\n};\n"]}
|
|
@@ -42,7 +42,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
42
42
|
* @alpha - Changes to this component may be breaking.
|
|
43
43
|
*/
|
|
44
44
|
const PromptComponent = (_a) => {
|
|
45
|
-
var { value, onChange, maxRows = 5, isRunningPrompt = false, onSubmitPrompt, isSubmitDisabled = false, topContent, bottomContent, disclaimer = 'All information should be verified.', className, style, htmlAttributes, ref, textareaProps } = _a, restProps = __rest(_a, ["value", "onChange", "maxRows", "isRunningPrompt", "onSubmitPrompt", "isSubmitDisabled", "topContent", "bottomContent", "disclaimer", "className", "style", "htmlAttributes", "ref", "textareaProps"]);
|
|
45
|
+
var { value, onChange, maxRows = 5, isRunningPrompt = false, onSubmitPrompt, onCancelPrompt, isSubmitDisabled = false, topContent, bottomContent, disclaimer = 'All information should be verified.', className, style, htmlAttributes, ref, textareaProps } = _a, restProps = __rest(_a, ["value", "onChange", "maxRows", "isRunningPrompt", "onSubmitPrompt", "onCancelPrompt", "isSubmitDisabled", "topContent", "bottomContent", "disclaimer", "className", "style", "htmlAttributes", "ref", "textareaProps"]);
|
|
46
46
|
const classes = classNames('ndl-ai-prompt', className);
|
|
47
47
|
const textareaRef = useRef(null);
|
|
48
48
|
const textareaAboveRef = useRef(null);
|
|
@@ -124,13 +124,15 @@ const PromptComponent = (_a) => {
|
|
|
124
124
|
!e.shiftKey &&
|
|
125
125
|
isSubmitDisabled !== true) {
|
|
126
126
|
e.preventDefault();
|
|
127
|
-
|
|
127
|
+
if (isRunningPrompt !== true) {
|
|
128
|
+
onSubmitPrompt === null || onSubmitPrompt === void 0 ? void 0 : onSubmitPrompt(e);
|
|
129
|
+
}
|
|
128
130
|
}
|
|
129
|
-
} }, textareaProps)), _jsxs("div", { className: "ndl-ai-prompt-textarea-below", children: [Boolean(bottomContent) && (_jsx("div", { className: "ndl-ai-prompt-textarea-below-leading", children: bottomContent })), _jsx(SumbitPromptButton, { isDisabled: isSubmitDisabled, isRunningPrompt: isRunningPrompt,
|
|
131
|
+
} }, textareaProps)), _jsxs("div", { className: "ndl-ai-prompt-textarea-below", children: [Boolean(bottomContent) && (_jsx("div", { className: "ndl-ai-prompt-textarea-below-leading", children: bottomContent })), _jsx(SumbitPromptButton, { isDisabled: isSubmitDisabled, isRunningPrompt: isRunningPrompt, onSubmit: onSubmitPrompt, onCancel: onCancelPrompt })] })] }) }), Boolean(disclaimer) && (_jsx(Typography, { variant: "body-small", className: "ndl-ai-prompt-footer", children: disclaimer }))] })));
|
|
130
132
|
};
|
|
131
|
-
const SumbitPromptButton = ({
|
|
133
|
+
const SumbitPromptButton = ({ onSubmit, onCancel, isDisabled, isRunningPrompt, }) => {
|
|
132
134
|
const description = isRunningPrompt === true ? 'Cancel' : 'Send';
|
|
133
|
-
return (_jsxs(CleanIconButton, { className: "ndl-ai-prompt-submit-button", description: description, size: "medium", onClick:
|
|
135
|
+
return (_jsxs(CleanIconButton, { className: "ndl-ai-prompt-submit-button", description: description, size: "medium", onClick: isRunningPrompt === true ? onCancel : onSubmit, isDisabled: isDisabled, children: [_jsx(ArrowSmallUpIconOutline, { style: {
|
|
134
136
|
opacity: isRunningPrompt === true ? 0 : 1,
|
|
135
137
|
position: isRunningPrompt === true ? 'absolute' : 'relative',
|
|
136
138
|
transform: isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prompt.js","sourceRoot":"","sources":["../../../../src/ai/prompt/Prompt.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,IAAI,EACJ,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA+BjE;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,EAgBS,EAAE,EAAE;QAhBb,EACvB,KAAK,EACL,QAAQ,EACR,OAAO,GAAG,CAAC,EACX,eAAe,GAAG,KAAK,EACvB,cAAc,EACd,gBAAgB,GAAG,KAAK,EACxB,UAAU,EACV,aAAa,EACb,UAAU,GAAG,qCAAqC,EAClD,SAAS,EACT,KAA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I,CAAC,KAAK,cACR,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,KAAC,IAAI,CAAC,IAAI,IAER,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EACtC,aAAa,EACX,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,MAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAC,gBAAgB,KAAG,CAAC,CAAC,CAAC,IAAI,IAJxD,MAAM,CAAC,KAAK,CAMjB,CACH,CAAC,GACS,GACR,IACN,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,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\nimport {\n CleanIconButton,\n DropdownButton,\n Menu,\n Typography,\n} from '@neo4j-ndl/react';\nimport {\n ArrowSmallUpIconOutline,\n CheckIconOutline,\n StopCircleIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport classNames from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { CommonProps, HtmlAttributes } from '../../_common/types';\n\ntype PromptProps = {\n /** The prompt text */\n value?: React.ComponentPropsWithoutRef<'textarea'>['value'];\n /** Callback function called when the prompt text changes */\n onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;\n /** Whether the submit button is disabled */\n isSubmitDisabled?: boolean;\n /** Maximum number of rows the textarea can expand to */\n maxRows?: number;\n /** Whether the submit button is \"running\". Shows a stop icon when true. */\n isRunningPrompt?: boolean;\n /** Callback function called when the submit button is clicked */\n onSubmitPrompt?: (\n e:\n | React.KeyboardEvent<HTMLTextAreaElement>\n | React.MouseEvent<HTMLButtonElement, MouseEvent>,\n ) => void;\n /** Content to display above the textarea */\n topContent?: React.ReactNode;\n /** Content to display below the textarea */\n bottomContent?: React.ReactNode;\n /** Disclaimer to display below the component */\n disclaimer?: React.ReactNode;\n /** Props for the textarea element */\n textareaProps?: HtmlAttributes<'textarea'>;\n};\n\n/**\n * The component is used to display the prompt input for an LLM.\n * It includes a textarea for the user to enter their prompt and a submit button.\n * It can also display content above and below the textarea, like uploaded files or a select for changing agents.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst PromptComponent = ({\n value,\n onChange,\n maxRows = 5,\n isRunningPrompt = false,\n onSubmitPrompt,\n isSubmitDisabled = false,\n topContent,\n bottomContent,\n disclaimer = 'All information should be verified.',\n className,\n style,\n htmlAttributes,\n ref,\n textareaProps,\n ...restProps\n}: CommonProps<'div', PromptProps>) => {\n const classes = classNames('ndl-ai-prompt', className);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const textareaAboveRef = useRef<HTMLDivElement>(null);\n const [lineHeight, setLineHeight] = useState(0);\n\n /** File overflow stuff */\n useEffect(() => {\n let rafId: number | null = null;\n\n const checkOverflow = () => {\n if (textareaAboveRef.current !== null) {\n const element = textareaAboveRef.current;\n const maxHeight = parseFloat(\n getComputedStyle(element).maxHeight.replace('px', ''),\n );\n const scrollHeight = element.scrollHeight;\n\n if (scrollHeight > maxHeight) {\n element.classList.add('ndl-can-scroll');\n } else {\n element.classList.remove('ndl-can-scroll');\n }\n }\n };\n\n const debouncedCheck = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(checkOverflow);\n };\n\n // Initial check\n checkOverflow();\n\n const resizeObserver = new ResizeObserver(debouncedCheck);\n const mutationObserver = new MutationObserver(debouncedCheck);\n\n if (textareaAboveRef.current !== null) {\n resizeObserver.observe(textareaAboveRef.current);\n mutationObserver.observe(textareaAboveRef.current, {\n childList: true,\n subtree: true,\n });\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, []);\n\n /** Textarea stuff */\n useEffect(() => {\n if (textareaRef.current !== null) {\n const computed = window.getComputedStyle(textareaRef.current);\n setLineHeight(parseInt(computed.lineHeight));\n }\n }, []);\n\n const adjustTextareaHeight = useCallback(() => {\n const ta = textareaRef.current;\n\n if (ta !== null && lineHeight > 0) {\n // Reset height so scrollHeight measures correctly\n ta.style.height = 'auto';\n\n const maxHeight = lineHeight * maxRows;\n\n if (ta.scrollHeight <= maxHeight) {\n ta.style.overflowY = 'hidden';\n ta.style.height = `${ta.scrollHeight}px`;\n } else {\n ta.style.overflowY = 'auto';\n ta.style.height = `${maxHeight}px`;\n }\n }\n }, [lineHeight, maxRows]);\n\n // Adjust height when prompt value changes (including when cleared)\n useEffect(() => {\n adjustTextareaHeight();\n }, [value, adjustTextareaHeight]);\n\n const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n adjustTextareaHeight();\n onChange?.(e);\n };\n\n return (\n <div\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-ai-prompt-wrapper\">\n <div className=\"ndl-ai-prompt-wrapper-inner\">\n {Boolean(topContent) && (\n <div\n className=\"ndl-ai-prompt-textarea-above\"\n ref={textareaAboveRef}\n >\n {topContent}\n </div>\n )}\n <textarea\n placeholder=\"Ask anything\"\n className=\"ndl-ai-prompt-textarea\"\n rows={1}\n onChange={handleInput}\n value={value}\n ref={textareaRef}\n onKeyDown={(e) => {\n if (\n e.key === 'Enter' &&\n !e.shiftKey &&\n isSubmitDisabled !== true\n ) {\n e.preventDefault();\n onSubmitPrompt?.(e);\n }\n }}\n {...textareaProps}\n />\n <div className=\"ndl-ai-prompt-textarea-below\">\n {Boolean(bottomContent) && (\n <div className=\"ndl-ai-prompt-textarea-below-leading\">\n {bottomContent}\n </div>\n )}\n <SumbitPromptButton\n isDisabled={isSubmitDisabled}\n isRunningPrompt={isRunningPrompt}\n onClick={onSubmitPrompt}\n />\n </div>\n </div>\n </div>\n {Boolean(disclaimer) && (\n <Typography variant=\"body-small\" className=\"ndl-ai-prompt-footer\">\n {disclaimer}\n </Typography>\n )}\n </div>\n );\n};\n\nconst SumbitPromptButton = ({\n onClick,\n isDisabled,\n isRunningPrompt,\n}: {\n isDisabled?: boolean;\n isRunningPrompt?: boolean;\n onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n}) => {\n const description = isRunningPrompt === true ? 'Cancel' : 'Send';\n\n return (\n <CleanIconButton\n className=\"ndl-ai-prompt-submit-button\"\n description={description}\n size=\"medium\"\n onClick={onClick}\n isDisabled={isDisabled}\n >\n <ArrowSmallUpIconOutline\n style={{\n opacity: isRunningPrompt === true ? 0 : 1,\n position: isRunningPrompt === true ? 'absolute' : 'relative',\n transform:\n isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',\n }}\n />\n <StopCircleIconOutline\n style={{\n opacity: isRunningPrompt === true ? 1 : 0,\n position: isRunningPrompt === true ? 'relative' : 'absolute',\n }}\n />\n </CleanIconButton>\n );\n};\n\ntype AgentSelectProps = {\n value: { label: React.ReactNode; value: string };\n options: Array<{ label: React.ReactNode; value: string }>;\n onChange: (option: { label: React.ReactNode; value: string }) => void;\n};\n\nconst AgentSelect = ({ value, options = [], onChange }: AgentSelectProps) => {\n const anchorRef = useRef<HTMLButtonElement>(null);\n const [isMenuOpen, setIsMenuOpen] = useState(false);\n\n const displayLabel = value?.label ?? options[0]?.label ?? '';\n\n const handleItemClick = (option: {\n label: React.ReactNode;\n value: string;\n }) => {\n onChange?.(option);\n setIsMenuOpen(false);\n };\n\n return (\n <>\n <DropdownButton\n size=\"small\"\n className=\"ndl-ai-prompt-dropdown-button\"\n onClick={() => setIsMenuOpen((old) => !old)}\n isOpen={isMenuOpen}\n ref={anchorRef}\n >\n {displayLabel}\n </DropdownButton>\n <Menu\n isOpen={isMenuOpen}\n onClose={() => setIsMenuOpen(false)}\n anchorRef={anchorRef}\n placement=\"top-start-bottom-start\"\n >\n <Menu.Items>\n {options.map((option) => (\n <Menu.Item\n key={option.value}\n title={option.label}\n onClick={() => handleItemClick(option)}\n leadingVisual={\n value?.value === option.value ? <CheckIconOutline /> : null\n }\n />\n ))}\n </Menu.Items>\n </Menu>\n </>\n );\n};\n\nconst Prompt = Object.assign(PromptComponent, {\n Select: AgentSelect,\n});\n\nexport { Prompt };\n"]}
|
|
1
|
+
{"version":3,"file":"Prompt.js","sourceRoot":"","sources":["../../../../src/ai/prompt/Prompt.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,IAAI,EACJ,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAiCjE;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,EAiBS,EAAE,EAAE;QAjBb,EACvB,KAAK,EACL,QAAQ,EACR,OAAO,GAAG,CAAC,EACX,eAAe,GAAG,KAAK,EACvB,cAAc,EACd,cAAc,EACd,gBAAgB,GAAG,KAAK,EACxB,UAAU,EACV,aAAa,EACb,UAAU,G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AAE,SAAS,YAEb,YAAY,GACE,EACjB,KAAC,IAAI,IACH,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,EACnC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAC,wBAAwB,YAElC,KAAC,IAAI,CAAC,KAAK,cACR,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,KAAC,IAAI,CAAC,IAAI,IAER,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EACtC,aAAa,EACX,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,MAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAC,gBAAgB,KAAG,CAAC,CAAC,CAAC,IAAI,IAJxD,MAAM,CAAC,KAAK,CAMjB,CACH,CAAC,GACS,GACR,IACN,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,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\nimport {\n CleanIconButton,\n DropdownButton,\n Menu,\n Typography,\n} from '@neo4j-ndl/react';\nimport {\n ArrowSmallUpIconOutline,\n CheckIconOutline,\n StopCircleIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport classNames from 'classnames';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { CommonProps, HtmlAttributes } from '../../_common/types';\n\ntype PromptProps = {\n /** The prompt text */\n value?: React.ComponentPropsWithoutRef<'textarea'>['value'];\n /** Callback function called when the prompt text changes */\n onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;\n /** Whether the submit button is disabled */\n isSubmitDisabled?: boolean;\n /** Maximum number of rows the textarea can expand to */\n maxRows?: number;\n /** Whether the submit button is \"running\". Shows a stop icon when true. */\n isRunningPrompt?: boolean;\n /** Callback function called when the submit button is clicked */\n onSubmitPrompt?: (\n e:\n | React.KeyboardEvent<HTMLTextAreaElement>\n | React.MouseEvent<HTMLButtonElement, MouseEvent>,\n ) => void;\n /** Callback function called when the cancel button is clicked */\n onCancelPrompt?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n /** Content to display above the textarea */\n topContent?: React.ReactNode;\n /** Content to display below the textarea */\n bottomContent?: React.ReactNode;\n /** Disclaimer to display below the component */\n disclaimer?: React.ReactNode;\n /** Props for the textarea element */\n textareaProps?: HtmlAttributes<'textarea'>;\n};\n\n/**\n * The component is used to display the prompt input for an LLM.\n * It includes a textarea for the user to enter their prompt and a submit button.\n * It can also display content above and below the textarea, like uploaded files or a select for changing agents.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst PromptComponent = ({\n value,\n onChange,\n maxRows = 5,\n isRunningPrompt = false,\n onSubmitPrompt,\n onCancelPrompt,\n isSubmitDisabled = false,\n topContent,\n bottomContent,\n disclaimer = 'All information should be verified.',\n className,\n style,\n htmlAttributes,\n ref,\n textareaProps,\n ...restProps\n}: CommonProps<'div', PromptProps>) => {\n const classes = classNames('ndl-ai-prompt', className);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const textareaAboveRef = useRef<HTMLDivElement>(null);\n const [lineHeight, setLineHeight] = useState(0);\n\n /** File overflow stuff */\n useEffect(() => {\n let rafId: number | null = null;\n\n const checkOverflow = () => {\n if (textareaAboveRef.current !== null) {\n const element = textareaAboveRef.current;\n const maxHeight = parseFloat(\n getComputedStyle(element).maxHeight.replace('px', ''),\n );\n const scrollHeight = element.scrollHeight;\n\n if (scrollHeight > maxHeight) {\n element.classList.add('ndl-can-scroll');\n } else {\n element.classList.remove('ndl-can-scroll');\n }\n }\n };\n\n const debouncedCheck = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(checkOverflow);\n };\n\n // Initial check\n checkOverflow();\n\n const resizeObserver = new ResizeObserver(debouncedCheck);\n const mutationObserver = new MutationObserver(debouncedCheck);\n\n if (textareaAboveRef.current !== null) {\n resizeObserver.observe(textareaAboveRef.current);\n mutationObserver.observe(textareaAboveRef.current, {\n childList: true,\n subtree: true,\n });\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, []);\n\n /** Textarea stuff */\n useEffect(() => {\n if (textareaRef.current !== null) {\n const computed = window.getComputedStyle(textareaRef.current);\n setLineHeight(parseInt(computed.lineHeight));\n }\n }, []);\n\n const adjustTextareaHeight = useCallback(() => {\n const ta = textareaRef.current;\n\n if (ta !== null && lineHeight > 0) {\n // Reset height so scrollHeight measures correctly\n ta.style.height = 'auto';\n\n const maxHeight = lineHeight * maxRows;\n\n if (ta.scrollHeight <= maxHeight) {\n ta.style.overflowY = 'hidden';\n ta.style.height = `${ta.scrollHeight}px`;\n } else {\n ta.style.overflowY = 'auto';\n ta.style.height = `${maxHeight}px`;\n }\n }\n }, [lineHeight, maxRows]);\n\n // Adjust height when prompt value changes (including when cleared)\n useEffect(() => {\n adjustTextareaHeight();\n }, [value, adjustTextareaHeight]);\n\n const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n adjustTextareaHeight();\n onChange?.(e);\n };\n\n return (\n <div\n ref={ref}\n className={classes}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-ai-prompt-wrapper\">\n <div className=\"ndl-ai-prompt-wrapper-inner\">\n {Boolean(topContent) && (\n <div\n className=\"ndl-ai-prompt-textarea-above\"\n ref={textareaAboveRef}\n >\n {topContent}\n </div>\n )}\n <textarea\n placeholder=\"Ask anything\"\n className=\"ndl-ai-prompt-textarea\"\n rows={1}\n onChange={handleInput}\n value={value}\n ref={textareaRef}\n onKeyDown={(e) => {\n if (\n e.key === 'Enter' &&\n !e.shiftKey &&\n isSubmitDisabled !== true\n ) {\n e.preventDefault();\n\n if (isRunningPrompt !== true) {\n onSubmitPrompt?.(e);\n }\n }\n }}\n {...textareaProps}\n />\n <div className=\"ndl-ai-prompt-textarea-below\">\n {Boolean(bottomContent) && (\n <div className=\"ndl-ai-prompt-textarea-below-leading\">\n {bottomContent}\n </div>\n )}\n <SumbitPromptButton\n isDisabled={isSubmitDisabled}\n isRunningPrompt={isRunningPrompt}\n onSubmit={onSubmitPrompt}\n onCancel={onCancelPrompt}\n />\n </div>\n </div>\n </div>\n {Boolean(disclaimer) && (\n <Typography variant=\"body-small\" className=\"ndl-ai-prompt-footer\">\n {disclaimer}\n </Typography>\n )}\n </div>\n );\n};\n\nconst SumbitPromptButton = ({\n onSubmit,\n onCancel,\n isDisabled,\n isRunningPrompt,\n}: {\n isDisabled?: boolean;\n isRunningPrompt?: boolean;\n onSubmit?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n onCancel?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n}) => {\n const description = isRunningPrompt === true ? 'Cancel' : 'Send';\n\n return (\n <CleanIconButton\n className=\"ndl-ai-prompt-submit-button\"\n description={description}\n size=\"medium\"\n onClick={isRunningPrompt === true ? onCancel : onSubmit}\n isDisabled={isDisabled}\n >\n <ArrowSmallUpIconOutline\n style={{\n opacity: isRunningPrompt === true ? 0 : 1,\n position: isRunningPrompt === true ? 'absolute' : 'relative',\n transform:\n isRunningPrompt === true ? 'translateY(-8px)' : 'translateY(0)',\n }}\n />\n <StopCircleIconOutline\n style={{\n opacity: isRunningPrompt === true ? 1 : 0,\n position: isRunningPrompt === true ? 'relative' : 'absolute',\n }}\n />\n </CleanIconButton>\n );\n};\n\ntype AgentSelectProps = {\n value: { label: React.ReactNode; value: string };\n options: Array<{ label: React.ReactNode; value: string }>;\n onChange: (option: { label: React.ReactNode; value: string }) => void;\n};\n\nconst AgentSelect = ({ value, options = [], onChange }: AgentSelectProps) => {\n const anchorRef = useRef<HTMLButtonElement>(null);\n const [isMenuOpen, setIsMenuOpen] = useState(false);\n\n const displayLabel = value?.label ?? options[0]?.label ?? '';\n\n const handleItemClick = (option: {\n label: React.ReactNode;\n value: string;\n }) => {\n onChange?.(option);\n setIsMenuOpen(false);\n };\n\n return (\n <>\n <DropdownButton\n size=\"small\"\n className=\"ndl-ai-prompt-dropdown-button\"\n onClick={() => setIsMenuOpen((old) => !old)}\n isOpen={isMenuOpen}\n ref={anchorRef}\n >\n {displayLabel}\n </DropdownButton>\n <Menu\n isOpen={isMenuOpen}\n onClose={() => setIsMenuOpen(false)}\n anchorRef={anchorRef}\n placement=\"top-start-bottom-start\"\n >\n <Menu.Items>\n {options.map((option) => (\n <Menu.Item\n key={option.value}\n title={option.label}\n onClick={() => handleItemClick(option)}\n leadingVisual={\n value?.value === option.value ? <CheckIconOutline /> : null\n }\n />\n ))}\n </Menu.Items>\n </Menu>\n </>\n );\n};\n\nconst Prompt = Object.assign(PromptComponent, {\n Select: AgentSelect,\n});\n\nexport { Prompt };\n"]}
|
|
@@ -34,13 +34,11 @@ const Component = () => {
|
|
|
34
34
|
const [selectedOption, setSelectedOption] = useState(options[0]);
|
|
35
35
|
const [prompt, setPrompt] = useState('');
|
|
36
36
|
const handleSubmitPrompt = () => {
|
|
37
|
-
setIsRunningPrompt(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
setPrompt('');
|
|
41
|
-
}
|
|
37
|
+
setIsRunningPrompt(true);
|
|
38
|
+
alert(`You submitted the following prompt: ${prompt}`);
|
|
39
|
+
setPrompt('');
|
|
42
40
|
};
|
|
43
|
-
return (_jsx(Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, topContent: _jsxs(_Fragment, { children: [_jsx(FileTag, { isLoading: true, icon: _jsx(DocumentIconOutline, {}), fileName: "Science Fiction Bestsellers", fileType: "pdf", isRemovable: true, onClick: () => {
|
|
41
|
+
return (_jsx(Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, onCancelPrompt: () => setIsRunningPrompt(false), topContent: _jsxs(_Fragment, { children: [_jsx(FileTag, { isLoading: true, icon: _jsx(DocumentIconOutline, {}), fileName: "Science Fiction Bestsellers", fileType: "pdf", isRemovable: true, onClick: () => {
|
|
44
42
|
console.info('remove file');
|
|
45
43
|
} }), _jsx(ImageTag, { isLoading: true, src: "https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", alt: "Landscape image", fileName: "Landscape image", fileType: "jpg", isRemovable: true, onClick: () => {
|
|
46
44
|
console.info('remove image');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-advanced.story.js","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-advanced.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,eAA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E,IAAI,EACjB,OAAO,EAAE,GAAG,EAAE;wBACZ,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC,GACD,EACF,KAAC,OAAO,IACN,IAAI,EAAE,KAAC,mBAAmB,KAAG,EAC7B,QAAQ,EAAC,6BAA6B,EACtC,QAAQ,EAAC,KAAK,EACd,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,GAAG,EAAE;wBACZ,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC9B,CAAC,GACD,EACF,KAAC,QAAQ,IACP,GAAG,EAAC,8KAA8K,EAClL,GAAG,EAAC,iBAAiB,EACrB,QAAQ,EAAC,iBAAiB,EAC1B,QAAQ,EAAC,KAAK,EACd,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE,GAAG,EAAE;wBACZ,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC,GACD,IACD,EAEL,aAAa,EACX,8BACE,KAAC,MAAM,CAAC,MAAM,IACZ,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,iBAAiB,GAC3B,EACF,KAAC,eAAe,IAAC,WAAW,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,YACnD,KAAC,eAAe,KAAG,GACH,IACjB,GAEL,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,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\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { CleanIconButton } from '@neo4j-ndl/react';\nimport { FileTag, ImageTag, Prompt } from '@neo4j-ndl/react/ai';\nimport { DocumentIconOutline, PlusIconOutline } from '@neo4j-ndl/react/icons';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [isRunningPrompt, setIsRunningPrompt] = useState(false);\n const options: Array<{ label: React.ReactNode; value: string }> = [\n { label: 'Neo4j AI', value: 'neo4j' },\n { label: 'Special Agent', value: 'special-agent' },\n { label: 'Another Agent', value: 'another-agent' },\n ];\n const [selectedOption, setSelectedOption] = useState(options[0]);\n const [prompt, setPrompt] = useState('');\n\n const handleSubmitPrompt = () => {\n setIsRunningPrompt(true);\n alert(`You submitted the following prompt: ${prompt}`);\n setPrompt('');\n };\n\n return (\n <Prompt\n isRunningPrompt={isRunningPrompt}\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={handleSubmitPrompt}\n onCancelPrompt={() => setIsRunningPrompt(false)}\n topContent={\n <>\n <FileTag\n isLoading={true}\n icon={<DocumentIconOutline />}\n fileName=\"Science Fiction Bestsellers\"\n fileType=\"pdf\"\n isRemovable={true}\n onClick={() => {\n console.info('remove file');\n }}\n />\n <ImageTag\n isLoading={true}\n src=\"https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"Landscape image\"\n fileName=\"Landscape image\"\n fileType=\"jpg\"\n isRemovable={true}\n onClick={() => {\n console.info('remove image');\n }}\n />\n <FileTag\n icon={<DocumentIconOutline />}\n fileName=\"Science Fiction Bestsellers\"\n fileType=\"pdf\"\n isRemovable={true}\n onClick={() => {\n console.info('remove file');\n }}\n />\n <ImageTag\n src=\"https://plus.unsplash.com/premium_photo-1676496046182-356a6a0ed002?q=80&w=2952&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"Landscape image\"\n fileName=\"Landscape image\"\n fileType=\"jpg\"\n isRemovable={true}\n onClick={() => {\n console.info('remove image');\n }}\n />\n </>\n }\n bottomContent={\n <>\n <Prompt.Select\n value={selectedOption}\n options={options}\n onChange={setSelectedOption}\n />\n <CleanIconButton description=\"Add stuff\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n </>\n }\n />\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -26,13 +26,11 @@ const Component = () => {
|
|
|
26
26
|
const [prompt, setPrompt] = useState('');
|
|
27
27
|
const [isRunningPrompt, setIsRunningPrompt] = useState(false);
|
|
28
28
|
const handleSubmitPrompt = () => {
|
|
29
|
-
setIsRunningPrompt(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
setPrompt('');
|
|
33
|
-
}
|
|
29
|
+
setIsRunningPrompt(true);
|
|
30
|
+
alert(`You submitted the following prompt: ${prompt}`);
|
|
31
|
+
setPrompt('');
|
|
34
32
|
};
|
|
35
|
-
return (_jsx(Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt }));
|
|
33
|
+
return (_jsx(Prompt, { isRunningPrompt: isRunningPrompt, value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: handleSubmitPrompt, onCancelPrompt: () => setIsRunningPrompt(false) }));
|
|
36
34
|
};
|
|
37
35
|
export default Component;
|
|
38
36
|
//# sourceMappingURL=prompt-default.story.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-default.story.js","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-default.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAEjD,OA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CAAC,kBAAkB,CAAC,KAAK,CAAC,GAC/C,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,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\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { Prompt } from '@neo4j-ndl/react/ai';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [prompt, setPrompt] = useState('');\n const [isRunningPrompt, setIsRunningPrompt] = useState(false);\n\n const handleSubmitPrompt = () => {\n setIsRunningPrompt(true);\n alert(`You submitted the following prompt: ${prompt}`);\n setPrompt('');\n };\n\n return (\n <Prompt\n isRunningPrompt={isRunningPrompt}\n value={prompt}\n onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>\n setPrompt(e.target.value)\n }\n onSubmitPrompt={handleSubmitPrompt}\n onCancelPrompt={() => setIsRunningPrompt(false)}\n />\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -64,28 +64,26 @@ export const Component = () => {
|
|
|
64
64
|
useEffect(() => {
|
|
65
65
|
scrollToBottom();
|
|
66
66
|
}, [messages, isThinking]);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (intervalRef.current) {
|
|
74
|
-
clearInterval(intervalRef.current);
|
|
75
|
-
}
|
|
76
|
-
setIsThinking(false);
|
|
77
|
-
setIsStreaming(false);
|
|
78
|
-
// Mark the last message as done if stopped
|
|
79
|
-
setMessages((prev) => {
|
|
80
|
-
const newMessages = [...prev];
|
|
81
|
-
const lastMessage = newMessages[newMessages.length - 1];
|
|
82
|
-
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
|
|
83
|
-
lastMessage.done = true;
|
|
84
|
-
}
|
|
85
|
-
return newMessages;
|
|
86
|
-
});
|
|
87
|
-
return;
|
|
67
|
+
const handleCancel = () => {
|
|
68
|
+
if (timeoutRef.current) {
|
|
69
|
+
clearTimeout(timeoutRef.current);
|
|
70
|
+
}
|
|
71
|
+
if (intervalRef.current) {
|
|
72
|
+
clearInterval(intervalRef.current);
|
|
88
73
|
}
|
|
74
|
+
setIsThinking(false);
|
|
75
|
+
setIsStreaming(false);
|
|
76
|
+
// Mark the last message as done if stopped
|
|
77
|
+
setMessages((prev) => {
|
|
78
|
+
const newMessages = [...prev];
|
|
79
|
+
const lastMessage = newMessages[newMessages.length - 1];
|
|
80
|
+
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
|
|
81
|
+
lastMessage.done = true;
|
|
82
|
+
}
|
|
83
|
+
return newMessages;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const handleSend = (overridePrompt) => {
|
|
89
87
|
const textToSend = overridePrompt || prompt;
|
|
90
88
|
if (!textToSend.trim()) {
|
|
91
89
|
return;
|
|
@@ -152,7 +150,7 @@ export const Component = () => {
|
|
|
152
150
|
}, children: "Generate a report" })] }), _jsxs(Typography, { variant: "body-medium", children: ["You can also drag and drop files here, or", ' ', _jsx(TextLink, { as: "button", type: "internal-underline", children: "browse" }), ". Supports CVG, MOV, PDF"] })] }) })) : (_jsxs("div", { className: "n-flex n-flex-col n-gap-4 n-pb-4", children: [messages.map((msg, idx) => (_jsx("div", { className: `n-flex ${msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'}`, children: msg.role === 'user' ? (_jsx("div", { className: "n-max-w-[85%]", children: _jsx(UserBubble, { avatarProps: {
|
|
153
151
|
name: 'NM',
|
|
154
152
|
type: 'letters',
|
|
155
|
-
}, children: msg.content }) })) : (_jsxs("div", { className: "n-w-full n-flex n-flex-col n-gap-2", children: [msg.thinkingTime !== undefined && (_jsx(Thinking, { isThinking: false, thinkingMs: msg.thinkingTime })), _jsxs("div", { className: "n-flex n-flex-col n-gap-2", children: [_jsx(Response, { children: msg.content }), msg.done === true && (_jsxs("div", { className: "n-flex n-flex-row n-gap-1.5", children: [_jsx(CleanIconButton, { size: "small", description: "Dislike", children: _jsx(HandThumbDownIconOutline, {}) }), _jsx(CleanIconButton, { size: "small", description: "Re-run", children: _jsx(ArrowPathIconOutline, {}) }), _jsx(CleanIconButton, { size: "small", description: "Copy", children: _jsx(Square2StackIconOutline, {}) })] }))] })] })) }, idx))), isThinking && _jsx(Thinking, { isThinking: true }), _jsx("div", { ref: messagesEndRef })] })) }), _jsx("div", { className: "n-px-4 n-pt-4 n-pb-1 n-mt-auto", children: _jsx(Prompt, { value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: () => handleSend(), isRunningPrompt: isThinking || isStreaming, isSubmitDisabled: prompt.length === 0 && !(isThinking || isStreaming), bottomContent: _jsx(CleanIconButton, { description: "Add files", size: "small", children: _jsx(PlusIconOutline, {}) }) }) })] }) }));
|
|
153
|
+
}, children: msg.content }) })) : (_jsxs("div", { className: "n-w-full n-flex n-flex-col n-gap-2", children: [msg.thinkingTime !== undefined && (_jsx(Thinking, { isThinking: false, thinkingMs: msg.thinkingTime })), _jsxs("div", { className: "n-flex n-flex-col n-gap-2", children: [_jsx(Response, { children: msg.content }), msg.done === true && (_jsxs("div", { className: "n-flex n-flex-row n-gap-1.5", children: [_jsx(CleanIconButton, { size: "small", description: "Dislike", children: _jsx(HandThumbDownIconOutline, {}) }), _jsx(CleanIconButton, { size: "small", description: "Re-run", children: _jsx(ArrowPathIconOutline, {}) }), _jsx(CleanIconButton, { size: "small", description: "Copy", children: _jsx(Square2StackIconOutline, {}) })] }))] })] })) }, idx))), isThinking && _jsx(Thinking, { isThinking: true }), _jsx("div", { ref: messagesEndRef })] })) }), _jsx("div", { className: "n-px-4 n-pt-4 n-pb-1 n-mt-auto", children: _jsx(Prompt, { value: prompt, onChange: (e) => setPrompt(e.target.value), onSubmitPrompt: () => handleSend(), onCancelPrompt: handleCancel, isRunningPrompt: isThinking || isStreaming, isSubmitDisabled: prompt.length === 0 && !(isThinking || isStreaming), bottomContent: _jsx(CleanIconButton, { description: "Add files", size: "small", children: _jsx(PlusIconOutline, {}) }) }) })] }) }));
|
|
156
154
|
};
|
|
157
155
|
export default Component;
|
|
158
156
|
//# sourceMappingURL=response-full-example.story.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-full-example.story.js","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,MAAM,EACN,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,MAAM,cAAc,GAAG;IACrB,kEAAkE;IAClE;;;SAGO;IACP;;;;;;CAMD;IACC;;;;0BAIwB;IACxB;;;;;CAKD;CACA,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAOtC,EAAE,CAAC,CAAC;IACN,MAAM,CAAC,MAAM,EAA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,CACP,CAAC,EACD,UAAU,IAAI,KAAC,QAAQ,IAAC,UAAU,EAAE,IAAI,GAAI,EAC7C,cAAK,GAAG,EAAE,cAAc,GAAI,IACxB,CACP,GACG,EACN,cAAK,SAAS,EAAC,gCAAgC,YAC7C,KAAC,MAAM,IACL,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,cAAc,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,EAClC,eAAe,EAAE,UAAU,IAAI,WAAW,EAC1C,gBAAgB,EACd,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,EAErD,aAAa,EACX,KAAC,eAAe,IAAC,WAAW,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,YACnD,KAAC,eAAe,KAAG,GACH,GAEpB,GACE,IACF,GACE,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,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 */\nimport { CleanIconButton, TextLink, Typography } from '@neo4j-ndl/react';\nimport {\n Prompt,\n Response,\n Suggestion,\n Thinking,\n UserBubble,\n} from '@neo4j-ndl/react/ai';\nimport {\n ArrowPathIconOutline,\n Cog6ToothIconOutline,\n HandThumbDownIconOutline,\n PlusIconOutline,\n Square2StackIconOutline,\n XMarkIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport { useEffect, useRef, useState } from 'react';\n\nconst FAKE_RESPONSES = [\n `Here is a simple response with some **bold text** and *italics*.`,\n `Here is a list of items:\n- Item 1\n- Item 2\n- Item 3`,\n `Here is a code block example:\n\n\\`\\`\\`typescript\nconst greeting = \"Hello World\";\nconsole.log(greeting);\n\\`\\`\\`\n`,\n `# Heading 1\n## Heading 2\n### Heading 3\n\nSome text under headings.`,\n `You can also use tables:\n\n| Header 1 | Header 2 |\n|Data 1|Data 2|\n|Data 3|Data 4|\n`,\n];\n\nexport const Component = () => {\n const [messages, setMessages] = useState<\n {\n role: 'user' | 'assistant';\n content: string;\n thinkingTime?: number;\n done?: boolean;\n }[]\n >([]);\n const [prompt, setPrompt] = useState('');\n const [isThinking, setIsThinking] = useState(false);\n const [isStreaming, setIsStreaming] = useState(false);\n const [responseIndex, setResponseIndex] = useState(0);\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n\n const scrollToBottom = () => {\n messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages, isThinking]);\n\n const handleSend = (overridePrompt?: string) => {\n // Handle Stop\n if (isThinking || isStreaming) {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsThinking(false);\n setIsStreaming(false);\n\n // Mark the last message as done if stopped\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage?.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n return;\n }\n\n const textToSend = overridePrompt || prompt;\n\n if (!textToSend.trim()) {\n return;\n }\n\n setMessages((prev) => [...prev, { content: textToSend, role: 'user' }]);\n setPrompt('');\n setIsThinking(true);\n const startTime = Date.now();\n\n // Simulate network delay (thinking time)\n timeoutRef.current = setTimeout(() => {\n const endTime = Date.now();\n const thinkingTime = endTime - startTime;\n setIsThinking(false);\n setIsStreaming(true);\n\n const responseText = FAKE_RESPONSES[responseIndex];\n setResponseIndex((prev) => (prev + 1) % FAKE_RESPONSES.length);\n\n let currentText = '';\n setMessages((prev) => [\n ...prev,\n { content: '', done: false, role: 'assistant', thinkingTime },\n ]);\n\n // Simulate streaming\n intervalRef.current = setInterval(() => {\n if (currentText.length < responseText.length) {\n // Add a few characters at a time to simulate chunks\n // Ensure we don't split newlines incorrectly if that's an issue,\n // but simple slicing should be fine as long as the source has \\n.\n const chunk = responseText.slice(\n currentText.length,\n currentText.length + 2,\n );\n currentText += chunk;\n\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.content = currentText;\n }\n return newMessages;\n });\n } else {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsStreaming(false);\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n }\n }, 50);\n }, 2000);\n };\n\n return (\n <section className=\"n-h-screen\">\n <div className=\"n-w-[440px] n-h-full n-flex n-flex-col n-bg-neutral-bg-weak\">\n <div className=\"n-flex n-flex-row n-border-b n-border-neutral-border-weak n-p-3\">\n <div className=\"n-ml-auto\">\n <CleanIconButton description=\"settings\" tooltipProps={{}}>\n <Cog6ToothIconOutline />\n </CleanIconButton>\n <CleanIconButton description=\"close\">\n <XMarkIconOutline />\n </CleanIconButton>\n </div>\n </div>\n <div className=\"n-p-4 n-flex n-flex-col n-grow n-overflow-y-auto\">\n {messages.length === 0 ? (\n <div className=\"n-flex n-flex-col \">\n <div className=\"n-flex n-flex-col n-gap-12\">\n <Typography variant=\"display\">\n Hi [User], how can I help you today?\n </Typography>\n <div className=\"n-flex n-flex-col n-gap-4\">\n <Typography variant=\"body-medium\">Suggestions</Typography>\n <Suggestion\n isPrimary\n onClick={() => {\n handleSend('I want to import data');\n }}\n >\n I want to import data\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Create an AI agent');\n }}\n >\n Create an AI agent\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Invite project members');\n }}\n >\n Invite project members\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Generate a report');\n }}\n >\n Generate a report\n </Suggestion>\n </div>\n <Typography variant=\"body-medium\">\n You can also drag and drop files here, or{' '}\n <TextLink as=\"button\" type=\"internal-underline\">\n browse\n </TextLink>\n . Supports CVG, MOV, PDF\n </Typography>\n </div>\n </div>\n ) : (\n <div className=\"n-flex n-flex-col n-gap-4 n-pb-4\">\n {messages.map((msg, idx) => (\n <div\n key={idx}\n className={`n-flex ${\n msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'\n }`}\n >\n {msg.role === 'user' ? (\n <div className=\"n-max-w-[85%]\">\n <UserBubble\n avatarProps={{\n name: 'NM',\n type: 'letters',\n }}\n >\n {msg.content}\n </UserBubble>\n </div>\n ) : (\n <div className=\"n-w-full n-flex n-flex-col n-gap-2\">\n {msg.thinkingTime !== undefined && (\n <Thinking\n isThinking={false}\n thinkingMs={msg.thinkingTime}\n />\n )}\n <div className=\"n-flex n-flex-col n-gap-2\">\n <Response>{msg.content}</Response>\n\n {msg.done === true && (\n <div className=\"n-flex n-flex-row n-gap-1.5\">\n <CleanIconButton size=\"small\" description=\"Dislike\">\n <HandThumbDownIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Re-run\">\n <ArrowPathIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Copy\">\n <Square2StackIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n </div>\n )}\n </div>\n ))}\n {isThinking && <Thinking isThinking={true} />}\n <div ref={messagesEndRef} />\n </div>\n )}\n </div>\n <div className=\"n-px-4 n-pt-4 n-pb-1 n-mt-auto\">\n <Prompt\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={() => handleSend()}\n isRunningPrompt={isThinking || isStreaming}\n isSubmitDisabled={\n prompt.length === 0 && !(isThinking || isStreaming)\n }\n bottomContent={\n <CleanIconButton description=\"Add files\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n }\n />\n </div>\n </div>\n </section>\n );\n};\n\nexport default Component;\n"]}
|
|
1
|
+
{"version":3,"file":"response-full-example.story.js","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,MAAM,EACN,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,MAAM,cAAc,GAAG;IACrB,kEAAkE;IAClE;;;SAGO;IACP;;;;;;CAMD;IACC;;;;0BAIwB;IACxB;;;;;CAKD;CACA,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAOtC,EAAE,CAAC,CAAC;IACN,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,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QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,cAAc,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,EAClC,cAAc,EAAE,YAAY,EAC5B,eAAe,EAAE,UAAU,IAAI,WAAW,EAC1C,gBAAgB,EACd,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,EAErD,aAAa,EACX,KAAC,eAAe,IAAC,WAAW,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,YACnD,KAAC,eAAe,KAAG,GACH,GAEpB,GACE,IACF,GACE,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,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 */\nimport { CleanIconButton, TextLink, Typography } from '@neo4j-ndl/react';\nimport {\n Prompt,\n Response,\n Suggestion,\n Thinking,\n UserBubble,\n} from '@neo4j-ndl/react/ai';\nimport {\n ArrowPathIconOutline,\n Cog6ToothIconOutline,\n HandThumbDownIconOutline,\n PlusIconOutline,\n Square2StackIconOutline,\n XMarkIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport { useEffect, useRef, useState } from 'react';\n\nconst FAKE_RESPONSES = [\n `Here is a simple response with some **bold text** and *italics*.`,\n `Here is a list of items:\n- Item 1\n- Item 2\n- Item 3`,\n `Here is a code block example:\n\n\\`\\`\\`typescript\nconst greeting = \"Hello World\";\nconsole.log(greeting);\n\\`\\`\\`\n`,\n `# Heading 1\n## Heading 2\n### Heading 3\n\nSome text under headings.`,\n `You can also use tables:\n\n| Header 1 | Header 2 |\n|Data 1|Data 2|\n|Data 3|Data 4|\n`,\n];\n\nexport const Component = () => {\n const [messages, setMessages] = useState<\n {\n role: 'user' | 'assistant';\n content: string;\n thinkingTime?: number;\n done?: boolean;\n }[]\n >([]);\n const [prompt, setPrompt] = useState('');\n const [isThinking, setIsThinking] = useState(false);\n const [isStreaming, setIsStreaming] = useState(false);\n const [responseIndex, setResponseIndex] = useState(0);\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n\n const scrollToBottom = () => {\n messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages, isThinking]);\n\n const handleCancel = () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsThinking(false);\n setIsStreaming(false);\n\n // Mark the last message as done if stopped\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage?.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n };\n\n const handleSend = (overridePrompt?: string) => {\n const textToSend = overridePrompt || prompt;\n\n if (!textToSend.trim()) {\n return;\n }\n\n setMessages((prev) => [...prev, { content: textToSend, role: 'user' }]);\n setPrompt('');\n setIsThinking(true);\n const startTime = Date.now();\n\n // Simulate network delay (thinking time)\n timeoutRef.current = setTimeout(() => {\n const endTime = Date.now();\n const thinkingTime = endTime - startTime;\n setIsThinking(false);\n setIsStreaming(true);\n\n const responseText = FAKE_RESPONSES[responseIndex];\n setResponseIndex((prev) => (prev + 1) % FAKE_RESPONSES.length);\n\n let currentText = '';\n setMessages((prev) => [\n ...prev,\n { content: '', done: false, role: 'assistant', thinkingTime },\n ]);\n\n // Simulate streaming\n intervalRef.current = setInterval(() => {\n if (currentText.length < responseText.length) {\n // Add a few characters at a time to simulate chunks\n // Ensure we don't split newlines incorrectly if that's an issue,\n // but simple slicing should be fine as long as the source has \\n.\n const chunk = responseText.slice(\n currentText.length,\n currentText.length + 2,\n );\n currentText += chunk;\n\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.content = currentText;\n }\n return newMessages;\n });\n } else {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n setIsStreaming(false);\n setMessages((prev) => {\n const newMessages = [...prev];\n const lastMessage = newMessages[newMessages.length - 1];\n if (lastMessage.role === 'assistant') {\n lastMessage.done = true;\n }\n return newMessages;\n });\n }\n }, 50);\n }, 2000);\n };\n\n return (\n <section className=\"n-h-screen\">\n <div className=\"n-w-[440px] n-h-full n-flex n-flex-col n-bg-neutral-bg-weak\">\n <div className=\"n-flex n-flex-row n-border-b n-border-neutral-border-weak n-p-3\">\n <div className=\"n-ml-auto\">\n <CleanIconButton description=\"settings\" tooltipProps={{}}>\n <Cog6ToothIconOutline />\n </CleanIconButton>\n <CleanIconButton description=\"close\">\n <XMarkIconOutline />\n </CleanIconButton>\n </div>\n </div>\n <div className=\"n-p-4 n-flex n-flex-col n-grow n-overflow-y-auto\">\n {messages.length === 0 ? (\n <div className=\"n-flex n-flex-col \">\n <div className=\"n-flex n-flex-col n-gap-12\">\n <Typography variant=\"display\">\n Hi [User], how can I help you today?\n </Typography>\n <div className=\"n-flex n-flex-col n-gap-4\">\n <Typography variant=\"body-medium\">Suggestions</Typography>\n <Suggestion\n isPrimary\n onClick={() => {\n handleSend('I want to import data');\n }}\n >\n I want to import data\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Create an AI agent');\n }}\n >\n Create an AI agent\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Invite project members');\n }}\n >\n Invite project members\n </Suggestion>\n <Suggestion\n onClick={() => {\n handleSend('Generate a report');\n }}\n >\n Generate a report\n </Suggestion>\n </div>\n <Typography variant=\"body-medium\">\n You can also drag and drop files here, or{' '}\n <TextLink as=\"button\" type=\"internal-underline\">\n browse\n </TextLink>\n . Supports CVG, MOV, PDF\n </Typography>\n </div>\n </div>\n ) : (\n <div className=\"n-flex n-flex-col n-gap-4 n-pb-4\">\n {messages.map((msg, idx) => (\n <div\n key={idx}\n className={`n-flex ${\n msg.role === 'user' ? 'n-justify-end' : 'n-justify-start'\n }`}\n >\n {msg.role === 'user' ? (\n <div className=\"n-max-w-[85%]\">\n <UserBubble\n avatarProps={{\n name: 'NM',\n type: 'letters',\n }}\n >\n {msg.content}\n </UserBubble>\n </div>\n ) : (\n <div className=\"n-w-full n-flex n-flex-col n-gap-2\">\n {msg.thinkingTime !== undefined && (\n <Thinking\n isThinking={false}\n thinkingMs={msg.thinkingTime}\n />\n )}\n <div className=\"n-flex n-flex-col n-gap-2\">\n <Response>{msg.content}</Response>\n\n {msg.done === true && (\n <div className=\"n-flex n-flex-row n-gap-1.5\">\n <CleanIconButton size=\"small\" description=\"Dislike\">\n <HandThumbDownIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Re-run\">\n <ArrowPathIconOutline />\n </CleanIconButton>\n <CleanIconButton size=\"small\" description=\"Copy\">\n <Square2StackIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n </div>\n )}\n </div>\n ))}\n {isThinking && <Thinking isThinking={true} />}\n <div ref={messagesEndRef} />\n </div>\n )}\n </div>\n <div className=\"n-px-4 n-pt-4 n-pb-1 n-mt-auto\">\n <Prompt\n value={prompt}\n onChange={(e) => setPrompt(e.target.value)}\n onSubmitPrompt={() => handleSend()}\n onCancelPrompt={handleCancel}\n isRunningPrompt={isThinking || isStreaming}\n isSubmitDisabled={\n prompt.length === 0 && !(isThinking || isStreaming)\n }\n bottomContent={\n <CleanIconButton description=\"Add files\" size=\"small\">\n <PlusIconOutline />\n </CleanIconButton>\n }\n />\n </div>\n </div>\n </section>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -33,14 +33,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
33
33
|
import classNames from 'classnames';
|
|
34
34
|
import { ArrowUpRightIconOutline, ChevronRightIconOutline } from '../icons';
|
|
35
35
|
export const TextLink = (_a) => {
|
|
36
|
-
var { children, href, type = 'internal', as, className, target, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "href", "type", "as", "className", "target", "style", "htmlAttributes", "ref"]);
|
|
37
|
-
const
|
|
38
|
-
const Component = as || 'a';
|
|
36
|
+
var { children, href, type = 'internal', as, className, target = type === 'external' ? '_blank' : '', style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "href", "type", "as", "className", "target", "style", "htmlAttributes", "ref"]);
|
|
37
|
+
const Component = as !== null && as !== void 0 ? as : 'a';
|
|
39
38
|
const classes = classNames('ndl-text-link', className, {
|
|
40
39
|
'ndl-external-link': type === 'external',
|
|
41
40
|
'ndl-internal-icon': type === 'internal-icon',
|
|
42
41
|
'ndl-internal-underline': type === 'internal-underline',
|
|
43
42
|
});
|
|
44
|
-
return (_jsxs(Component, Object.assign({ className: classes, href: href, ref: ref, style: style
|
|
43
|
+
return (_jsxs(Component, Object.assign({ className: classes, href: href, ref: ref, style: style, target: target }, restProps, htmlAttributes, { children: [children, type === 'external' && (_jsx(ArrowUpRightIconOutline, { className: "ndl-external-link-icon" })), type === 'internal-icon' && (_jsx(ChevronRightIconOutline, { className: "ndl-external-link-icon" }))] })));
|
|
45
44
|
};
|
|
46
45
|
//# sourceMappingURL=TextLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLink.js","sourceRoot":"","sources":["../../../src/text-link/TextLink.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAm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,cAAc,eAEjB,QAAQ,EACR,IAAI,KAAK,UAAU,IAAI,CACtB,KAAC,uBAAuB,IAAC,SAAS,EAAC,wBAAwB,GAAG,CAC/D,EACA,IAAI,KAAK,eAAe,IAAI,CAC3B,KAAC,uBAAuB,IAAC,SAAS,EAAC,wBAAwB,GAAG,CAC/D,KACS,CACb,CAAC;AACJ,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 */\nimport classNames from 'classnames';\nimport type React from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { ArrowUpRightIconOutline, ChevronRightIconOutline } from '../icons';\n\ntype TextLinkType =\n | 'internal'\n | 'internal-underline'\n | 'internal-icon'\n | 'external';\n\ntype TextLinkProps = {\n /** The content displayed inside the link */\n children: React.ReactNode;\n\n /** The URL the link points to */\n href?: string;\n\n /**\n * The type of the text link\n * - 'internal': a link to another page within the application\n * - 'internal-underline': a link to another page within the application with an underline and support for text color\n * - 'internal-icon': a link to another page within the application with an icon\n * - 'external': a link to an external website\n * @default 'internal'\n */\n type?: TextLinkType;\n\n /** Specifies where to open the linked document. If omitted and `type` is `\"external\"` it defaults to `\"_blank\"`. */\n target?: HTMLAnchorElement['target'];\n\n /** Additional class name */\n className?: string;\n};\n\nexport const TextLink = <T extends React.ElementType = 'a'>({\n children,\n href,\n type = 'internal',\n as,\n className,\n target = type === 'external' ? '_blank' : '',\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, TextLinkProps>) => {\n const Component: React.ElementType = as ?? 'a';\n\n const classes = classNames('ndl-text-link', className, {\n 'ndl-external-link': type === 'external',\n 'ndl-internal-icon': type === 'internal-icon',\n 'ndl-internal-underline': type === 'internal-underline',\n });\n\n return (\n <Component\n className={classes}\n href={href}\n ref={ref}\n style={style}\n target={target}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n {type === 'external' && (\n <ArrowUpRightIconOutline className=\"ndl-external-link-icon\" />\n )}\n {type === 'internal-icon' && (\n <ChevronRightIconOutline className=\"ndl-external-link-icon\" />\n )}\n </Component>\n );\n};\n"]}
|
|
@@ -85,4 +85,5 @@ export declare const RadiusDefaults: {
|
|
|
85
85
|
borderRadius: undefined;
|
|
86
86
|
};
|
|
87
87
|
export declare const getRadius: (spacing: Radius | undefined, property: keyof typeof RadiusDefaults) => string | undefined;
|
|
88
|
+
export declare const parseRgbString: (rgbString: string) => [number, number, number];
|
|
88
89
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EAIhB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE/C,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,WACP,CAAC;AAEtC,qCAAqC;AACrC,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,WACP,CAAC;AAEpC,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,SACV,CAAC;AAa3C;;;GAGG;AACH,eAAO,MAAM,uBAAuB,kBAGL,OAAO,QAAO,QAAQ,SAYpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,GAAG,WAAW,EACnE,KAAK,KAAK,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KAAK,MAAM,WAQ1C,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;CAQlB,CAAC;AAEX,eAAO,MAAM,UAAU,GACrB,SAAS,OAAO,GAAG,SAAS,EAC5B,UAAU,MAAM,OAAO,eAAe,uBAKvC,CAAC;AAEF,eAAO,MAAM,cAAc;;CAE1B,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,GAAG,SAAS,EAC3B,UAAU,MAAM,OAAO,cAAc,uBAKtC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAMzE,CAAC"}
|
|
@@ -32,6 +32,8 @@ type PromptProps = {
|
|
|
32
32
|
isRunningPrompt?: boolean;
|
|
33
33
|
/** Callback function called when the submit button is clicked */
|
|
34
34
|
onSubmitPrompt?: (e: React.KeyboardEvent<HTMLTextAreaElement> | React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
35
|
+
/** Callback function called when the cancel button is clicked */
|
|
36
|
+
onCancelPrompt?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
35
37
|
/** Content to display above the textarea */
|
|
36
38
|
topContent?: React.ReactNode;
|
|
37
39
|
/** Content to display below the textarea */
|
|
@@ -55,7 +57,7 @@ type AgentSelectProps = {
|
|
|
55
57
|
value: string;
|
|
56
58
|
}) => void;
|
|
57
59
|
};
|
|
58
|
-
declare const Prompt: (({ value, onChange, maxRows, isRunningPrompt, onSubmitPrompt, isSubmitDisabled, topContent, bottomContent, disclaimer, className, style, htmlAttributes, ref, textareaProps, ...restProps }: CommonProps<"div", PromptProps>) => import("react/jsx-runtime").JSX.Element) & {
|
|
60
|
+
declare const Prompt: (({ value, onChange, maxRows, isRunningPrompt, onSubmitPrompt, onCancelPrompt, isSubmitDisabled, topContent, bottomContent, disclaimer, className, style, htmlAttributes, ref, textareaProps, ...restProps }: CommonProps<"div", PromptProps>) => import("react/jsx-runtime").JSX.Element) & {
|
|
59
61
|
Select: ({ value, options, onChange }: AgentSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
60
62
|
};
|
|
61
63
|
export { Prompt };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src/ai/prompt/Prompt.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAgBH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvE,KAAK,WAAW,GAAG;IACjB,sBAAsB;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;IAC5D,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IAC/D,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iEAAiE;IACjE,cAAc,CAAC,EAAE,CACf,CAAC,EACG,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,GACxC,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,KAChD,IAAI,CAAC;IACV,4CAA4C;IAC5C,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,4CAA4C;IAC5C,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,gDAAgD;IAChD,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,qCAAqC;IACrC,aAAa,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CAC5C,CAAC;
|
|
1
|
+
{"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../../../../src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,CAAC;IACjD,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACvE,CAAC;AAkDF,QAAA,MAAM,MAAM,gNA3PT,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC;2CA2MsB,gBAAgB;CAkDtE,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-advanced.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-advanced.story.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAOjD,QAAA,MAAM,SAAS,+
|
|
1
|
+
{"version":3,"file":"prompt-advanced.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-advanced.story.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAOjD,QAAA,MAAM,SAAS,+CAiFd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-default.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-default.story.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAKjD,QAAA,MAAM,SAAS,+
|
|
1
|
+
{"version":3,"file":"prompt-default.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/prompt/stories/prompt-default.story.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAKjD,QAAA,MAAM,SAAS,+CAqBd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-full-example.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":[],"mappings":"AAgEA,eAAO,MAAM,SAAS,+
|
|
1
|
+
{"version":3,"file":"response-full-example.story.d.ts","sourceRoot":"","sources":["../../../../../src/ai/response/stories/response-full-example.story.tsx"],"names":[],"mappings":"AAgEA,eAAO,MAAM,SAAS,+CAuPrB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -37,7 +37,7 @@ type TextLinkProps = {
|
|
|
37
37
|
*/
|
|
38
38
|
type?: TextLinkType;
|
|
39
39
|
/** Specifies where to open the linked document. If omitted and `type` is `"external"` it defaults to `"_blank"`. */
|
|
40
|
-
target?:
|
|
40
|
+
target?: HTMLAnchorElement['target'];
|
|
41
41
|
/** Additional class name */
|
|
42
42
|
className?: string;
|
|
43
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLink.d.ts","sourceRoot":"","sources":["../../../src/text-link/TextLink.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG/D,KAAK,YAAY,GACb,UAAU,GACV,oBAAoB,GACpB,eAAe,GACf,UAAU,CAAC;AAEf,KAAK,aAAa,GAAG;IACnB,4CAA4C;IAC5C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IAEpB,oHAAoH;IACpH,MAAM,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"TextLink.d.ts","sourceRoot":"","sources":["../../../src/text-link/TextLink.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG/D,KAAK,YAAY,GACb,UAAU,GACV,oBAAoB,GACpB,eAAe,GACf,UAAU,CAAC;AAEf,KAAK,aAAa,GAAG;IACnB,4CAA4C;IAC5C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IAEpB,oHAAoH;IACpH,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAErC,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,EAAE,2FAWzD,sBAAsB,CAAC,CAAC,EAAE,aAAa,CAAC,4CA4B1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-ndl/react",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React implementation of Neo4j Design System",
|
|
6
6
|
"keywords": [
|
|
@@ -66,11 +66,10 @@
|
|
|
66
66
|
"@types/tinycolor2": "1.4.6",
|
|
67
67
|
"@types/yargs": "17.0.33",
|
|
68
68
|
"@vitejs/plugin-react": "5.0.2",
|
|
69
|
+
"a11y-contrast-color": "1.1.0",
|
|
69
70
|
"ajv": "8.17.1",
|
|
70
71
|
"chromatic": "13.3.0",
|
|
71
|
-
"happo
|
|
72
|
-
"happo-playwright": "4.0.3",
|
|
73
|
-
"happo.io": "13.0.0",
|
|
72
|
+
"happo": "6.2.0",
|
|
74
73
|
"jsdom": "26.1.0",
|
|
75
74
|
"leva": "0.10.0",
|
|
76
75
|
"react": "19.2.1",
|
|
@@ -86,7 +85,7 @@
|
|
|
86
85
|
"@tanstack/react-table": "8.21.3",
|
|
87
86
|
"react": ">=19.0.0",
|
|
88
87
|
"react-dom": ">=19.0.0",
|
|
89
|
-
"@neo4j-ndl/base": "^4.3.
|
|
88
|
+
"@neo4j-ndl/base": "^4.3.3"
|
|
90
89
|
},
|
|
91
90
|
"dependencies": {
|
|
92
91
|
"@dnd-kit/core": "6.3.1",
|