@neo4j-ndl/react 4.2.12 → 4.2.13

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.
@@ -60,6 +60,9 @@ const CodeBlockWrapper = (_a) => {
60
60
  }, []);
61
61
  (0, react_1.useLayoutEffect)(() => {
62
62
  var _a, _b, _c, _d;
63
+ if (maxHeight === undefined) {
64
+ return;
65
+ }
63
66
  if (((_b = (_a = syntaxHighlighterWrapperRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) !== null && _b !== void 0 ? _b : 0) >=
64
67
  ((_d = (_c = syntaxHighlighterWrapperRef.current) === null || _c === void 0 ? void 0 : _c.scrollHeight) !== null && _d !== void 0 ? _d : 0)) {
65
68
  setContainerHeight(`fit-content`);
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockWrapper.js","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AAEpC,iCAAqE;AAErE,4DAAuD;AACvD,oCAAwE;AAgBxE,MAAM,cAAc,GAAG,KAAK,CAAC;AAEtB,MAAM,gBAAgB,GAAG,CAE9B,EAeiD,EAAE,EAAE;;QAfrD,EACA,EAAE,EACF,SAAS,EACT,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,UAAU,EACV,OAAO,EACP,sBAAsB,EACtB,yBAAyB,EACzB,SAAS,EACT,KAAK,EACL,GAAG,EACH,cAAc,OAEmC,EAD9C,SAAS,cAdZ,iLAeD,CADa;IAEZ,MAAM,SAAS,GAAsB,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,cAAc,CAAC;IAE1D,MAAM,2BAA2B,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAEjE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,SAAS,IAAI,CAAC,CAAC;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AC,CAQN,CACH,CAAC;gBACJ,CAAC,CAAC,GACE,EACL,sBAAsB,IAAI,CACzB,gCAAK,SAAS,EAAC,8BAA8B,YAC3C,uBAAC,mCAAe,IACd,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAC/C,YAAY,EAAE;wBACZ,IAAI,EAAE;4BACJ,2BAA2B,EAAE,IAAI;yBAClC;qBACF,EACD,OAAO,EAAE,GAAG,EAAE;wBACZ,IAAI,UAAU,EAAE,CAAC;4BACf,kBAAkB,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC;4BACrC,aAAa,CAAC,KAAK,CAAC,CAAC;wBACvB,CAAC;6BAAM,CAAC;4BACN,kBAAkB,CAAC,aAAa,CAAC,CAAC;4BAClC,aAAa,CAAC,IAAI,CAAC,CAAC;wBACtB,CAAC;oBACH,CAAC,YAEA,UAAU,CAAC,CAAC,CAAC,uBAAC,4BAAoB,KAAG,CAAC,CAAC,CAAC,uBAAC,8BAAsB,KAAG,GACnD,GACd,CACP,KACS,CACb,CAAC;AACJ,CAAC,CAAC;AA9IW,QAAA,gBAAgB,oBA8I3B","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';\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react';\n\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ChevronDownIconOutline, ChevronUpIconOutline } from '../icons';\nimport { type PolymorphicCommonProps } from './types';\n\nexport interface CodeBlockWrapperProps {\n maxHeight?: number;\n code: string;\n heading?: string | React.ReactNode;\n children: React.ReactNode;\n isDisabled?: boolean;\n actions?: React.ComponentPropsWithoutRef<typeof CleanIconButton<'button'>>[];\n shouldShowExpandButton: boolean;\n setShouldShowExpandButton: React.Dispatch<React.SetStateAction<boolean>>;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst defaultElement = 'div';\n\nexport const CodeBlockWrapper = <\n T extends React.ElementType = typeof defaultElement,\n>({\n as,\n maxHeight,\n code,\n heading,\n children,\n isDisabled,\n actions,\n shouldShowExpandButton,\n setShouldShowExpandButton,\n className,\n style,\n ref,\n htmlAttributes,\n ...restProps\n}: PolymorphicCommonProps<T, CodeBlockWrapperProps>) => {\n const Component: React.ElementType = as ?? defaultElement;\n\n const syntaxHighlighterWrapperRef = useRef<HTMLDivElement>(null);\n\n const [containerHeight, setContainerHeight] = useState(`${maxHeight}px`);\n const [isExpanded, setIsExpanded] = useState(maxHeight === undefined);\n\n useEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0) <=\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0)\n ) {\n setIsExpanded(true);\n } else {\n setIsExpanded(false);\n }\n }, []);\n\n useLayoutEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0) >=\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0)\n ) {\n setContainerHeight(`fit-content`);\n setShouldShowExpandButton(false);\n } else {\n setContainerHeight(`${maxHeight}px`);\n setShouldShowExpandButton(true);\n }\n }, [maxHeight, code, setShouldShowExpandButton]);\n\n return (\n <Component\n ref={ref}\n className={classNames('ndl-code-block-container', className)}\n style={{ height: containerHeight, ...style }}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"n-flex n-flex-col n-h-full\">\n {Boolean(heading) === true && (\n <div\n className={classNames('ndl-code-block-title', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n maxWidth: `calc(100% - ${(actions?.length ?? 0) * 36 + 20}px)`,\n }}\n data-testid=\"ndl-code-block-title\"\n >\n {heading}\n </div>\n )}\n <div\n className={classNames('ndl-code-content-container', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n height:\n Boolean(heading) === true ? 'calc(100% - 24px - 12px)' : '100%',\n }}\n >\n {/* Pseudo element on the left to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n <div\n ref={syntaxHighlighterWrapperRef}\n className=\"ndl-highlight-wrapper\"\n role=\"textbox\"\n aria-label=\"Code snippet\"\n tabIndex={0}\n >\n {children}\n </div>\n {/* Pseudo element on the right to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n </div>\n </div>\n <div\n className={classNames('ndl-code-block-actions', {\n 'ndl-disabled': isDisabled,\n })}\n >\n {actions?.map((iconButtonProps, i) => {\n const { htmlAttributes, description, ...restCleanIconButtonProps } =\n iconButtonProps;\n return (\n <CleanIconButton\n key={i}\n description={`${description ?? 'CodeBlock Action'}`}\n isDisabled={isDisabled}\n htmlAttributes={{\n 'data-testid': `ndl-action-button-${i}`,\n ...htmlAttributes,\n }}\n {...restCleanIconButtonProps}\n />\n );\n })}\n </div>\n {shouldShowExpandButton && (\n <div className=\"ndl-code-block-expand-button\">\n <CleanIconButton\n description={isExpanded ? 'Collapse' : 'Expand'}\n tooltipProps={{\n root: {\n shouldCloseOnReferenceClick: true,\n },\n }}\n onClick={() => {\n if (isExpanded) {\n setContainerHeight(`${maxHeight}px`);\n setIsExpanded(false);\n } else {\n setContainerHeight(`fit-content`);\n setIsExpanded(true);\n }\n }}\n >\n {isExpanded ? <ChevronUpIconOutline /> : <ChevronDownIconOutline />}\n </CleanIconButton>\n </div>\n )}\n </Component>\n );\n};\n"]}
1
+ {"version":3,"file":"CodeBlockWrapper.js","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":";;;;;;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,CAAC;oBACH,CAAC,YAEA,UAAU,CAAC,CAAC,CAAC,uBAAC,4BAAoB,KAAG,CAAC,CAAC,CAAC,uBAAC,8BAAsB,KAAG,GACnD,GACd,CACP,KACS,CACb,CAAC;AACJ,CAAC,CAAC;AAlJW,QAAA,gBAAgB,oBAkJ3B","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';\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react';\n\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ChevronDownIconOutline, ChevronUpIconOutline } from '../icons';\nimport { type PolymorphicCommonProps } from './types';\n\nexport interface CodeBlockWrapperProps {\n maxHeight?: number;\n code: string;\n heading?: string | React.ReactNode;\n children: React.ReactNode;\n isDisabled?: boolean;\n actions?: React.ComponentPropsWithoutRef<typeof CleanIconButton<'button'>>[];\n shouldShowExpandButton: boolean;\n setShouldShowExpandButton: React.Dispatch<React.SetStateAction<boolean>>;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst defaultElement = 'div';\n\nexport const CodeBlockWrapper = <\n T extends React.ElementType = typeof defaultElement,\n>({\n as,\n maxHeight,\n code,\n heading,\n children,\n isDisabled,\n actions,\n shouldShowExpandButton,\n setShouldShowExpandButton,\n className,\n style,\n ref,\n htmlAttributes,\n ...restProps\n}: PolymorphicCommonProps<T, CodeBlockWrapperProps>) => {\n const Component: React.ElementType = as ?? defaultElement;\n\n const syntaxHighlighterWrapperRef = useRef<HTMLDivElement>(null);\n\n const [containerHeight, setContainerHeight] = useState(`${maxHeight}px`);\n const [isExpanded, setIsExpanded] = useState(maxHeight === undefined);\n\n useEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0) <=\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0)\n ) {\n setIsExpanded(true);\n } else {\n setIsExpanded(false);\n }\n }, []);\n\n useLayoutEffect(() => {\n if (maxHeight === undefined) {\n return;\n }\n\n if (\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0) >=\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0)\n ) {\n setContainerHeight(`fit-content`);\n setShouldShowExpandButton(false);\n } else {\n setContainerHeight(`${maxHeight}px`);\n setShouldShowExpandButton(true);\n }\n }, [maxHeight, code, setShouldShowExpandButton]);\n\n return (\n <Component\n ref={ref}\n className={classNames('ndl-code-block-container', className)}\n style={{ height: containerHeight, ...style }}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"n-flex n-flex-col n-h-full\">\n {Boolean(heading) === true && (\n <div\n className={classNames('ndl-code-block-title', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n maxWidth: `calc(100% - ${(actions?.length ?? 0) * 36 + 20}px)`,\n }}\n data-testid=\"ndl-code-block-title\"\n >\n {heading}\n </div>\n )}\n <div\n className={classNames('ndl-code-content-container', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n height:\n Boolean(heading) === true ? 'calc(100% - 24px - 12px)' : '100%',\n }}\n >\n {/* Pseudo element on the left to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n <div\n ref={syntaxHighlighterWrapperRef}\n className=\"ndl-highlight-wrapper\"\n role=\"textbox\"\n aria-label=\"Code snippet\"\n tabIndex={0}\n >\n {children}\n </div>\n {/* Pseudo element on the right to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n </div>\n </div>\n <div\n className={classNames('ndl-code-block-actions', {\n 'ndl-disabled': isDisabled,\n })}\n >\n {actions?.map((iconButtonProps, i) => {\n const { htmlAttributes, description, ...restCleanIconButtonProps } =\n iconButtonProps;\n return (\n <CleanIconButton\n key={i}\n description={`${description ?? 'CodeBlock Action'}`}\n isDisabled={isDisabled}\n htmlAttributes={{\n 'data-testid': `ndl-action-button-${i}`,\n ...htmlAttributes,\n }}\n {...restCleanIconButtonProps}\n />\n );\n })}\n </div>\n {shouldShowExpandButton && (\n <div className=\"ndl-code-block-expand-button\">\n <CleanIconButton\n description={isExpanded ? 'Collapse' : 'Expand'}\n tooltipProps={{\n root: {\n shouldCloseOnReferenceClick: true,\n },\n }}\n onClick={() => {\n if (isExpanded) {\n setContainerHeight(`${maxHeight}px`);\n setIsExpanded(false);\n } else {\n setContainerHeight(`fit-content`);\n setIsExpanded(true);\n }\n }}\n >\n {isExpanded ? <ChevronUpIconOutline /> : <ChevronDownIconOutline />}\n </CleanIconButton>\n </div>\n )}\n </Component>\n );\n};\n"]}
@@ -54,6 +54,9 @@ export const CodeBlockWrapper = (_a) => {
54
54
  }, []);
55
55
  useLayoutEffect(() => {
56
56
  var _a, _b, _c, _d;
57
+ if (maxHeight === undefined) {
58
+ return;
59
+ }
57
60
  if (((_b = (_a = syntaxHighlighterWrapperRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) !== null && _b !== void 0 ? _b : 0) >=
58
61
  ((_d = (_c = syntaxHighlighterWrapperRef.current) === null || _c === void 0 ? void 0 : _c.scrollHeight) !== null && _d !== void 0 ? _d : 0)) {
59
62
  setContainerHeight(`fit-content`);
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockWrapper.js","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAA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AC,KAAC,sBAAsB,KAAG,GACnD,GACd,CACP,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';\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react';\n\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ChevronDownIconOutline, ChevronUpIconOutline } from '../icons';\nimport { type PolymorphicCommonProps } from './types';\n\nexport interface CodeBlockWrapperProps {\n maxHeight?: number;\n code: string;\n heading?: string | React.ReactNode;\n children: React.ReactNode;\n isDisabled?: boolean;\n actions?: React.ComponentPropsWithoutRef<typeof CleanIconButton<'button'>>[];\n shouldShowExpandButton: boolean;\n setShouldShowExpandButton: React.Dispatch<React.SetStateAction<boolean>>;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst defaultElement = 'div';\n\nexport const CodeBlockWrapper = <\n T extends React.ElementType = typeof defaultElement,\n>({\n as,\n maxHeight,\n code,\n heading,\n children,\n isDisabled,\n actions,\n shouldShowExpandButton,\n setShouldShowExpandButton,\n className,\n style,\n ref,\n htmlAttributes,\n ...restProps\n}: PolymorphicCommonProps<T, CodeBlockWrapperProps>) => {\n const Component: React.ElementType = as ?? defaultElement;\n\n const syntaxHighlighterWrapperRef = useRef<HTMLDivElement>(null);\n\n const [containerHeight, setContainerHeight] = useState(`${maxHeight}px`);\n const [isExpanded, setIsExpanded] = useState(maxHeight === undefined);\n\n useEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0) <=\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0)\n ) {\n setIsExpanded(true);\n } else {\n setIsExpanded(false);\n }\n }, []);\n\n useLayoutEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0) >=\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0)\n ) {\n setContainerHeight(`fit-content`);\n setShouldShowExpandButton(false);\n } else {\n setContainerHeight(`${maxHeight}px`);\n setShouldShowExpandButton(true);\n }\n }, [maxHeight, code, setShouldShowExpandButton]);\n\n return (\n <Component\n ref={ref}\n className={classNames('ndl-code-block-container', className)}\n style={{ height: containerHeight, ...style }}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"n-flex n-flex-col n-h-full\">\n {Boolean(heading) === true && (\n <div\n className={classNames('ndl-code-block-title', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n maxWidth: `calc(100% - ${(actions?.length ?? 0) * 36 + 20}px)`,\n }}\n data-testid=\"ndl-code-block-title\"\n >\n {heading}\n </div>\n )}\n <div\n className={classNames('ndl-code-content-container', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n height:\n Boolean(heading) === true ? 'calc(100% - 24px - 12px)' : '100%',\n }}\n >\n {/* Pseudo element on the left to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n <div\n ref={syntaxHighlighterWrapperRef}\n className=\"ndl-highlight-wrapper\"\n role=\"textbox\"\n aria-label=\"Code snippet\"\n tabIndex={0}\n >\n {children}\n </div>\n {/* Pseudo element on the right to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n </div>\n </div>\n <div\n className={classNames('ndl-code-block-actions', {\n 'ndl-disabled': isDisabled,\n })}\n >\n {actions?.map((iconButtonProps, i) => {\n const { htmlAttributes, description, ...restCleanIconButtonProps } =\n iconButtonProps;\n return (\n <CleanIconButton\n key={i}\n description={`${description ?? 'CodeBlock Action'}`}\n isDisabled={isDisabled}\n htmlAttributes={{\n 'data-testid': `ndl-action-button-${i}`,\n ...htmlAttributes,\n }}\n {...restCleanIconButtonProps}\n />\n );\n })}\n </div>\n {shouldShowExpandButton && (\n <div className=\"ndl-code-block-expand-button\">\n <CleanIconButton\n description={isExpanded ? 'Collapse' : 'Expand'}\n tooltipProps={{\n root: {\n shouldCloseOnReferenceClick: true,\n },\n }}\n onClick={() => {\n if (isExpanded) {\n setContainerHeight(`${maxHeight}px`);\n setIsExpanded(false);\n } else {\n setContainerHeight(`fit-content`);\n setIsExpanded(true);\n }\n }}\n >\n {isExpanded ? <ChevronUpIconOutline /> : <ChevronDownIconOutline />}\n </CleanIconButton>\n </div>\n )}\n </Component>\n );\n};\n"]}
1
+ {"version":3,"file":"CodeBlockWrapper.js","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAgBxE,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAE9B,EAeiD,EAAE,EAAE;;QAfrD,EACA,EAAE,EACF,SAAS,EACT,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,UAAU,EACV,OAAO,EACP,sBAAsB,EACtB,yBAAyB,EACzB,SAAS,EACT,KAAK,EACL,GAAG,EACH,cAAc,OAEmC,EAD9C,SAAS,cAdZ,iLAeD,CADa;IAEZ,MAAM,SAAS,GAAsB,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,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GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,kBAAkB,EAAE,EACnD,UAAU,EAAE,UAAU,EACtB,cAAc,kBACZ,aAAa,EAAE,qBAAqB,CAAC,EAAE,IACpC,cAAc,KAEf,wBAAwB,GAPvB,CAAC,CAQN,CACH,CAAC;gBACJ,CAAC,CAAC,GACE,EACL,sBAAsB,IAAI,CACzB,cAAK,SAAS,EAAC,8BAA8B,YAC3C,KAAC,eAAe,IACd,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAC/C,YAAY,EAAE;wBACZ,IAAI,EAAE;4BACJ,2BAA2B,EAAE,IAAI;yBAClC;qBACF,EACD,OAAO,EAAE,GAAG,EAAE;wBACZ,IAAI,UAAU,EAAE,CAAC;4BACf,kBAAkB,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC;4BACrC,aAAa,CAAC,KAAK,CAAC,CAAC;wBACvB,CAAC;6BAAM,CAAC;4BACN,kBAAkB,CAAC,aAAa,CAAC,CAAC;4BAClC,aAAa,CAAC,IAAI,CAAC,CAAC;wBACtB,CAAC;oBACH,CAAC,YAEA,UAAU,CAAC,CAAC,CAAC,KAAC,oBAAoB,KAAG,CAAC,CAAC,CAAC,KAAC,sBAAsB,KAAG,GACnD,GACd,CACP,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';\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react';\n\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ChevronDownIconOutline, ChevronUpIconOutline } from '../icons';\nimport { type PolymorphicCommonProps } from './types';\n\nexport interface CodeBlockWrapperProps {\n maxHeight?: number;\n code: string;\n heading?: string | React.ReactNode;\n children: React.ReactNode;\n isDisabled?: boolean;\n actions?: React.ComponentPropsWithoutRef<typeof CleanIconButton<'button'>>[];\n shouldShowExpandButton: boolean;\n setShouldShowExpandButton: React.Dispatch<React.SetStateAction<boolean>>;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst defaultElement = 'div';\n\nexport const CodeBlockWrapper = <\n T extends React.ElementType = typeof defaultElement,\n>({\n as,\n maxHeight,\n code,\n heading,\n children,\n isDisabled,\n actions,\n shouldShowExpandButton,\n setShouldShowExpandButton,\n className,\n style,\n ref,\n htmlAttributes,\n ...restProps\n}: PolymorphicCommonProps<T, CodeBlockWrapperProps>) => {\n const Component: React.ElementType = as ?? defaultElement;\n\n const syntaxHighlighterWrapperRef = useRef<HTMLDivElement>(null);\n\n const [containerHeight, setContainerHeight] = useState(`${maxHeight}px`);\n const [isExpanded, setIsExpanded] = useState(maxHeight === undefined);\n\n useEffect(() => {\n if (\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0) <=\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0)\n ) {\n setIsExpanded(true);\n } else {\n setIsExpanded(false);\n }\n }, []);\n\n useLayoutEffect(() => {\n if (maxHeight === undefined) {\n return;\n }\n\n if (\n (syntaxHighlighterWrapperRef.current?.clientHeight ?? 0) >=\n (syntaxHighlighterWrapperRef.current?.scrollHeight ?? 0)\n ) {\n setContainerHeight(`fit-content`);\n setShouldShowExpandButton(false);\n } else {\n setContainerHeight(`${maxHeight}px`);\n setShouldShowExpandButton(true);\n }\n }, [maxHeight, code, setShouldShowExpandButton]);\n\n return (\n <Component\n ref={ref}\n className={classNames('ndl-code-block-container', className)}\n style={{ height: containerHeight, ...style }}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"n-flex n-flex-col n-h-full\">\n {Boolean(heading) === true && (\n <div\n className={classNames('ndl-code-block-title', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n maxWidth: `calc(100% - ${(actions?.length ?? 0) * 36 + 20}px)`,\n }}\n data-testid=\"ndl-code-block-title\"\n >\n {heading}\n </div>\n )}\n <div\n className={classNames('ndl-code-content-container', {\n 'ndl-disabled': isDisabled,\n })}\n style={{\n height:\n Boolean(heading) === true ? 'calc(100% - 24px - 12px)' : '100%',\n }}\n >\n {/* Pseudo element on the left to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n <div\n ref={syntaxHighlighterWrapperRef}\n className=\"ndl-highlight-wrapper\"\n role=\"textbox\"\n aria-label=\"Code snippet\"\n tabIndex={0}\n >\n {children}\n </div>\n {/* Pseudo element on the right to steal the editor focus when clicking outside */}\n <div className=\"ndl-code-pseudo-element\"></div>\n </div>\n </div>\n <div\n className={classNames('ndl-code-block-actions', {\n 'ndl-disabled': isDisabled,\n })}\n >\n {actions?.map((iconButtonProps, i) => {\n const { htmlAttributes, description, ...restCleanIconButtonProps } =\n iconButtonProps;\n return (\n <CleanIconButton\n key={i}\n description={`${description ?? 'CodeBlock Action'}`}\n isDisabled={isDisabled}\n htmlAttributes={{\n 'data-testid': `ndl-action-button-${i}`,\n ...htmlAttributes,\n }}\n {...restCleanIconButtonProps}\n />\n );\n })}\n </div>\n {shouldShowExpandButton && (\n <div className=\"ndl-code-block-expand-button\">\n <CleanIconButton\n description={isExpanded ? 'Collapse' : 'Expand'}\n tooltipProps={{\n root: {\n shouldCloseOnReferenceClick: true,\n },\n }}\n onClick={() => {\n if (isExpanded) {\n setContainerHeight(`${maxHeight}px`);\n setIsExpanded(false);\n } else {\n setContainerHeight(`fit-content`);\n setIsExpanded(true);\n }\n }}\n >\n {isExpanded ? <ChevronUpIconOutline /> : <ChevronDownIconOutline />}\n </CleanIconButton>\n </div>\n )}\n </Component>\n );\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockWrapper.d.ts","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC,wBAAwB,CAAC,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC7E,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,QAAA,MAAM,cAAc,QAAQ,CAAC;AAE7B,eAAO,MAAM,gBAAgB,GAC3B,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,OAAO,cAAc,EACnD,yKAeC,sBAAsB,CAAC,CAAC,EAAE,qBAAqB,CAAC,4CA6HlD,CAAC"}
1
+ {"version":3,"file":"CodeBlockWrapper.d.ts","sourceRoot":"","sources":["../../../src/_common/CodeBlockWrapper.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC,wBAAwB,CAAC,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC7E,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,QAAA,MAAM,cAAc,QAAQ,CAAC;AAE7B,eAAO,MAAM,gBAAgB,GAC3B,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,OAAO,cAAc,EACnD,yKAeC,sBAAsB,CAAC,CAAC,EAAE,qBAAqB,CAAC,4CAiIlD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-ndl/react",
3
- "version": "4.2.12",
3
+ "version": "4.2.13",
4
4
  "sideEffects": false,
5
5
  "description": "React implementation of Neo4j Design System",
6
6
  "keywords": [