@vibe/core 3.77.1-alpha-59987.0 → 3.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,10 @@ export interface EditableTypographyImplementationProps {
16
16
  * Callback fired when the component is clicked.
17
17
  */
18
18
  onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;
19
+ /**
20
+ * Callback fired when a key is pressed inside the input/textarea element.
21
+ */
22
+ onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
19
23
  /**
20
24
  * If true, the text is read-only and cannot be edited.
21
25
  */
@@ -7417,6 +7417,15 @@
7417
7417
  "name": "(event: any) => void"
7418
7418
  }
7419
7419
  },
7420
+ "onKeyDown": {
7421
+ "defaultValue": null,
7422
+ "description": "Callback fired when a key is pressed inside the input/textarea element.",
7423
+ "name": "onKeyDown",
7424
+ "required": false,
7425
+ "type": {
7426
+ "name": "(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void"
7427
+ }
7428
+ },
7420
7429
  "readOnly": {
7421
7430
  "defaultValue": null,
7422
7431
  "description": "If true, the text is read-only and cannot be edited.",
@@ -7603,6 +7612,15 @@
7603
7612
  "name": "(event: any) => void"
7604
7613
  }
7605
7614
  },
7615
+ "onKeyDown": {
7616
+ "defaultValue": null,
7617
+ "description": "Callback fired when a key is pressed inside the input/textarea element.",
7618
+ "name": "onKeyDown",
7619
+ "required": false,
7620
+ "type": {
7621
+ "name": "(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void"
7622
+ }
7623
+ },
7606
7624
  "readOnly": {
7607
7625
  "defaultValue": null,
7608
7626
  "description": "If true, the text is read-only and cannot be edited.",
@@ -16,6 +16,10 @@ export interface EditableTypographyImplementationProps {
16
16
  * Callback fired when the component is clicked.
17
17
  */
18
18
  onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;
19
+ /**
20
+ * Callback fired when a key is pressed inside the input/textarea element.
21
+ */
22
+ onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
19
23
  /**
20
24
  * If true, the text is read-only and cannot be edited.
21
25
  */
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as n,useRef as l,useState as r,useEffect as a}from"react";import i from"classnames";import s from"../../hooks/useMergeRef.js";import u from"./EditableTypography.module.scss.js";import{keyCodes as c}from"../../constants/keyCodes.js";import"../../constants/sizes.js";import{useKeyboardButtonPressedFunc as p}from"../../hooks/useKeyboardButtonPressedFunc.js";import d from"../../hooks/usePrevious/index.js";import f from"../../hooks/ssr/useIsomorphicLayoutEffect.js";var m=n((function(n,m){var v=n.id,h=n.className,y=n["data-testid"],g=n.value,E=n.onClick,b=n.onChange,P=n.readOnly,C=void 0!==P&&P,x=n.ariaLabel,k=void 0===x?"":x,j=n.placeholder,w=n.clearable,N=n.typographyClassName,D=n.component,B=n.isEditMode,K=n.autoSelectTextOnEditMode,T=n.onEditModeChange,M=n.tooltipProps,R=n.type,S=n.weight,A=n.multiline,H=void 0!==A&&A,I=l(null),L=s(m,I),O=r(B||!1),_=e(O,2),z=_[0],F=_[1],q=r(g),G=e(q,2),J=G[0],Q=G[1],U=d(g),V=l(null),W=l(null);function X(e){C||z||(e.preventDefault(),Y(!0))}function Y(e){null==T||T(e),F(e)}function Z(){(Y(!1),g!==J)&&(J||w&&j?(Q(J),null==b||b(J)):Q(g))}function $(){Z()}function ee(e){if(!e.nativeEvent.isComposing){if(e.key===c.ENTER){if(H&&e.shiftKey)return;e.preventDefault(),e.stopPropagation(),Z()}e.key===c.ESCAPE&&(e.preventDefault(),e.stopPropagation(),Y(!1),Q(g))}}function te(e){Q(e.target.value)}a((function(){z||g===U||g===J||Q(g)}),[U,z,g,J]),a((function(){F(B)}),[B]);var oe=p(X);return a((function(){var e,t;z&&(!function(){var e,t;if(null===(t=null===(e=V.current)||void 0===e?void 0:e.focus)||void 0===t||t.call(e),V.current){var o=V.current,n=o.value.length;o.setSelectionRange(n,n)}}(),K&&(null===(t=null===(e=V.current)||void 0===e?void 0:e.select)||void 0===t||t.call(e)))}),[K,z]),f((function(){var e;if(W.current){var t=W.current.getBoundingClientRect();if(null===(e=null==V?void 0:V.current)||void 0===e||e.style.setProperty("--input-width","".concat(t.width,"px")),H){var o=null==V?void 0:V.current;null==o||o.style.setProperty("--input-height","auto"),null==o||o.style.setProperty("--input-height","".concat(o.scrollHeight+2,"px"))}}}),[J,z]),o.createElement("div",{ref:L,id:v,"aria-label":k,"data-testid":y,className:i(u.editableTypography,h),role:z?null:"button",onClick:function(e){null==E||E(e),X(e)},onKeyDown:oe},z&&(H?o.createElement("textarea",{ref:V,className:i(u.textarea,N),value:J,onChange:te,onKeyDown:ee,onBlur:$,"aria-label":k,placeholder:j,role:"textbox",rows:1}):o.createElement("input",{ref:V,className:i(u.input,N),value:J,onChange:te,onKeyDown:ee,onBlur:$,"aria-label":k,placeholder:j,role:"input"})),o.createElement(D,{ref:W,"aria-hidden":z,className:i(u.typography,N,t(t(t(t({},u.hidden,z),u.disabled,C),u.placeholder,!J&&j),u.multiline,!z&&H)),tabIndex:0,tooltipProps:M,weight:S,type:R,ellipsis:!H},J||j))}));export{m as default};
1
+ import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as n,useRef as l,useState as r,useEffect as a}from"react";import i from"classnames";import s from"../../hooks/useMergeRef.js";import u from"./EditableTypography.module.scss.js";import{keyCodes as c}from"../../constants/keyCodes.js";import"../../constants/sizes.js";import{useKeyboardButtonPressedFunc as p}from"../../hooks/useKeyboardButtonPressedFunc.js";import d from"../../hooks/usePrevious/index.js";import f from"../../hooks/ssr/useIsomorphicLayoutEffect.js";var m=n((function(n,m){var v=n.id,h=n.className,y=n["data-testid"],g=n.value,E=n.onChange,b=n.onClick,P=n.onKeyDown,C=n.readOnly,x=void 0!==C&&C,k=n.ariaLabel,w=void 0===k?"":k,j=n.placeholder,D=n.clearable,N=n.typographyClassName,K=n.component,B=n.isEditMode,T=n.autoSelectTextOnEditMode,M=n.onEditModeChange,R=n.tooltipProps,S=n.type,A=n.weight,H=n.multiline,I=void 0!==H&&H,L=l(null),O=s(m,L),_=r(B||!1),z=e(_,2),F=z[0],q=z[1],G=r(g),J=e(G,2),Q=J[0],U=J[1],V=d(g),W=l(null),X=l(null);function Y(e){x||F||(e.preventDefault(),Z(!0))}function Z(e){null==M||M(e),q(e)}function $(){(Z(!1),g!==Q)&&(Q||D&&j?(U(Q),null==E||E(Q)):U(g))}function ee(){$()}function te(e){if(!e.nativeEvent.isComposing){if(e.key===c.ENTER){if(I&&e.shiftKey)return;e.preventDefault(),e.stopPropagation(),$()}e.key===c.ESCAPE&&(e.preventDefault(),e.stopPropagation(),Z(!1),U(g)),null==P||P(e)}}function oe(e){U(e.target.value)}a((function(){F||g===V||g===Q||U(g)}),[V,F,g,Q]),a((function(){q(B)}),[B]);var ne=p(Y);return a((function(){var e,t;F&&(!function(){var e,t;if(null===(t=null===(e=W.current)||void 0===e?void 0:e.focus)||void 0===t||t.call(e),W.current){var o=W.current,n=o.value.length;o.setSelectionRange(n,n)}}(),T&&(null===(t=null===(e=W.current)||void 0===e?void 0:e.select)||void 0===t||t.call(e)))}),[T,F]),f((function(){var e;if(X.current){var t=X.current.getBoundingClientRect();if(null===(e=null==W?void 0:W.current)||void 0===e||e.style.setProperty("--input-width","".concat(t.width,"px")),I){var o=null==W?void 0:W.current;null==o||o.style.setProperty("--input-height","auto"),null==o||o.style.setProperty("--input-height","".concat(o.scrollHeight+2,"px"))}}}),[Q,F]),o.createElement("div",{ref:O,id:v,"aria-label":w,"data-testid":y,className:i(u.editableTypography,h),role:F?null:"button",onClick:function(e){null==b||b(e),Y(e)},onKeyDown:ne},F&&(I?o.createElement("textarea",{ref:W,className:i(u.textarea,N),value:Q,onChange:oe,onKeyDown:te,onBlur:ee,"aria-label":w,placeholder:j,role:"textbox",rows:1}):o.createElement("input",{ref:W,className:i(u.input,N),value:Q,onChange:oe,onKeyDown:te,onBlur:ee,"aria-label":w,placeholder:j,role:"input"})),o.createElement(K,{ref:X,"aria-hidden":F,className:i(u.typography,N,t(t(t(t({},u.hidden,F),u.disabled,x),u.placeholder,!Q&&j),u.multiline,!F&&I)),tabIndex:0,tooltipProps:R,weight:A,type:S,ellipsis:!I},Q||j))}));export{m as default};
2
2
  //# sourceMappingURL=EditableTypography.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditableTypography.js","sources":["../../../../../src/components/EditableTypography/EditableTypography.tsx"],"sourcesContent":["import React, { type ElementType, forwardRef, useEffect, useRef, useState } from \"react\";\nimport cx from \"classnames\";\nimport useMergeRef from \"../../hooks/useMergeRef\";\nimport { type VibeComponentProps } from \"../../types\";\nimport styles from \"./EditableTypography.module.scss\";\nimport { keyCodes } from \"../../constants\";\nimport { useKeyboardButtonPressedFunc } from \"../../hooks/useKeyboardButtonPressedFunc\";\nimport { type TooltipProps } from \"../Tooltip\";\nimport usePrevious from \"../../hooks/usePrevious\";\nimport { type TextType, type TextWeight } from \"../Text\";\nimport { type HeadingType, type HeadingWeight } from \"../Heading\";\nimport useIsomorphicLayoutEffect from \"../../hooks/ssr/useIsomorphicLayoutEffect\";\n\nexport interface EditableTypographyImplementationProps {\n /**\n * The current value of the text.\n */\n value: string;\n /**\n * Callback fired when the value changes.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the component is clicked.\n */\n onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;\n /**\n * If true, the text is read-only and cannot be edited.\n */\n readOnly?: boolean;\n /**\n * Placeholder text displayed when the value is empty.\n */\n placeholder?: string;\n /**\n * The label of the component for accessibility.\n */\n ariaLabel?: string;\n /**\n * Controls whether the component is in edit mode.\n */\n isEditMode?: boolean;\n /**\n * If true, automatically selects all text when entering edit mode.\n */\n autoSelectTextOnEditMode?: boolean;\n /**\n * Callback fired when the edit mode changes.\n */\n onEditModeChange?: (isEditMode: boolean) => void;\n /**\n * Props to customize the tooltip.\n */\n tooltipProps?: Partial<TooltipProps>;\n}\n\nexport interface EditableTypographyProps extends VibeComponentProps, EditableTypographyImplementationProps {\n /**\n * The typography component used in view mode.\n */\n component: ElementType;\n /**\n * Class name applied to the typography component.\n */\n typographyClassName: string;\n /**\n * If true, shows the placeholder when empty.\n */\n clearable?: boolean;\n /**\n * The text or heading type.\n */\n type?: TextType | HeadingType;\n /**\n * The text or heading weight.\n */\n weight?: TextWeight | HeadingWeight;\n /**\n * If true, enables multi-line editing.\n */\n multiline?: boolean;\n}\n\nconst PADDING_OFFSET = 2;\n\nconst EditableTypography = forwardRef(\n (\n {\n id,\n className,\n \"data-testid\": dataTestId,\n value,\n onClick,\n onChange,\n readOnly = false,\n ariaLabel = \"\",\n placeholder,\n clearable,\n typographyClassName,\n component: TypographyComponent,\n isEditMode,\n autoSelectTextOnEditMode,\n onEditModeChange,\n tooltipProps,\n type,\n weight,\n multiline = false\n }: EditableTypographyProps,\n ref: React.ForwardedRef<HTMLElement>\n ) => {\n const componentRef = useRef(null);\n const mergedRef = useMergeRef(ref, componentRef);\n\n const [isEditing, setIsEditing] = useState(isEditMode || false);\n const [inputValue, setInputValue] = useState(value);\n\n const prevValue = usePrevious(value);\n\n const inputRef = useRef(null);\n const typographyRef = useRef(null);\n\n useEffect(() => {\n if (!isEditing && value !== prevValue && value !== inputValue) {\n setInputValue(value);\n }\n }, [prevValue, isEditing, value, inputValue]);\n\n useEffect(() => {\n setIsEditing(isEditMode);\n }, [isEditMode]);\n\n function onTypographyClick(event: React.KeyboardEvent | React.MouseEvent) {\n onClick?.(event);\n toggleEditMode(event);\n }\n\n function toggleEditMode(event: React.KeyboardEvent | React.MouseEvent) {\n if (readOnly || isEditing) {\n return;\n }\n event.preventDefault();\n handleEditModeChange(true);\n }\n\n function handleEditModeChange(value: boolean) {\n onEditModeChange?.(value);\n setIsEditing(value);\n }\n\n function handleInputValueChange() {\n handleEditModeChange(false);\n\n if (value === inputValue) {\n return;\n }\n\n const shouldShowPlaceholderWhenEmpty = clearable && placeholder;\n if (!inputValue && !shouldShowPlaceholderWhenEmpty) {\n setInputValue(value);\n return;\n }\n setInputValue(inputValue);\n onChange?.(inputValue);\n }\n\n function handleBlur() {\n handleInputValueChange();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n if (event.nativeEvent.isComposing) {\n return;\n }\n\n if (event.key === keyCodes.ENTER) {\n if (multiline && event.shiftKey) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n handleInputValueChange();\n }\n if (event.key === keyCodes.ESCAPE) {\n event.preventDefault();\n event.stopPropagation();\n handleEditModeChange(false);\n setInputValue(value);\n }\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {\n setInputValue(event.target.value);\n }\n\n const toggleKeyboardEditMode = useKeyboardButtonPressedFunc(toggleEditMode);\n\n function focus() {\n inputRef.current?.focus?.();\n\n if (inputRef.current) {\n const inputElement = inputRef.current as HTMLInputElement | HTMLTextAreaElement;\n const textLength = inputElement.value.length;\n inputElement.setSelectionRange(textLength, textLength);\n }\n }\n\n function selectAllInputText() {\n inputRef.current?.select?.();\n }\n\n useEffect(() => {\n if (!isEditing) return;\n focus();\n if (autoSelectTextOnEditMode) {\n selectAllInputText();\n }\n }, [autoSelectTextOnEditMode, isEditing]);\n\n useIsomorphicLayoutEffect(() => {\n if (!typographyRef.current) {\n return;\n }\n\n const { width } = typographyRef.current.getBoundingClientRect();\n inputRef?.current?.style.setProperty(\"--input-width\", `${width}px`);\n\n if (multiline) {\n const textareaElement = inputRef?.current as HTMLTextAreaElement;\n textareaElement?.style.setProperty(\"--input-height\", \"auto\");\n textareaElement?.style.setProperty(\"--input-height\", `${textareaElement.scrollHeight + PADDING_OFFSET}px`);\n }\n }, [inputValue, isEditing]);\n\n return (\n <div\n ref={mergedRef}\n id={id}\n aria-label={ariaLabel}\n data-testid={dataTestId}\n className={cx(styles.editableTypography, className)}\n role={isEditing ? null : \"button\"}\n onClick={onTypographyClick}\n onKeyDown={toggleKeyboardEditMode}\n >\n {isEditing &&\n (multiline ? (\n <textarea\n ref={inputRef}\n className={cx(styles.textarea, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"textbox\"\n rows={1}\n />\n ) : (\n <input\n ref={inputRef}\n className={cx(styles.input, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"input\"\n />\n ))}\n <TypographyComponent\n ref={typographyRef}\n aria-hidden={isEditing}\n className={cx(styles.typography, typographyClassName, {\n [styles.hidden]: isEditing,\n [styles.disabled]: readOnly,\n [styles.placeholder]: !inputValue && placeholder,\n [styles.multiline]: !isEditing && multiline\n })}\n tabIndex={0}\n tooltipProps={tooltipProps}\n weight={weight}\n type={type}\n ellipsis={!multiline}\n >\n {inputValue || placeholder}\n </TypographyComponent>\n </div>\n );\n }\n);\n\nexport default EditableTypography;\n"],"names":["EditableTypography","forwardRef","_ref","ref","id","className","dataTestId","value","onClick","onChange","_ref$readOnly","readOnly","_ref$ariaLabel","ariaLabel","placeholder","clearable","typographyClassName","TypographyComponent","component","isEditMode","autoSelectTextOnEditMode","onEditModeChange","tooltipProps","type","weight","_ref$multiline","multiline","componentRef","useRef","mergedRef","useMergeRef","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useState3","_useState4","inputValue","setInputValue","prevValue","usePrevious","inputRef","typographyRef","toggleEditMode","event","preventDefault","handleEditModeChange","handleInputValueChange","handleBlur","handleKeyDown","nativeEvent","isComposing","key","keyCodes","ENTER","shiftKey","stopPropagation","ESCAPE","handleChange","target","useEffect","toggleKeyboardEditMode","useKeyboardButtonPressedFunc","_b","current","_a","focus","inputElement","textLength","length","setSelectionRange","select","useIsomorphicLayoutEffect","_typographyRef$curren","getBoundingClientRect","style","setProperty","concat","width","textareaElement","scrollHeight","React","createElement","cx","styles","editableTypography","role","onKeyDown","textarea","onBlur","rows","input","typography","_defineProperty","hidden","disabled","tabIndex","ellipsis"],"mappings":"wkBAmFA,IAEMA,EAAqBC,GACzB,SAAAC,EAsBEC,GACE,IArBAC,EAAEF,EAAFE,GACAC,EAASH,EAATG,UACeC,EAAUJ,EAAzB,eACAK,EAAKL,EAALK,MACAC,EAAON,EAAPM,QACAC,EAAQP,EAARO,SAAQC,EAAAR,EACRS,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAAAV,EAChBW,UAAAA,OAAY,IAAHD,EAAG,GAAEA,EACdE,EAAWZ,EAAXY,YACAC,EAASb,EAATa,UACAC,EAAmBd,EAAnBc,oBACWC,EAAmBf,EAA9BgB,UACAC,EAAUjB,EAAViB,WACAC,EAAwBlB,EAAxBkB,yBACAC,EAAgBnB,EAAhBmB,iBACAC,EAAYpB,EAAZoB,aACAC,EAAIrB,EAAJqB,KACAC,EAAMtB,EAANsB,OAAMC,EAAAvB,EACNwB,UAAAA,OAAY,IAAHD,GAAQA,EAIbE,EAAeC,EAAO,MACtBC,EAAYC,EAAY3B,EAAKwB,GAEnCI,EAAkCC,EAASb,IAAc,GAAMc,EAAAC,EAAAH,EAAA,GAAxDI,EAASF,EAAA,GAAEG,EAAYH,EAAA,GAC9BI,EAAoCL,EAASzB,GAAM+B,EAAAJ,EAAAG,EAAA,GAA5CE,EAAUD,EAAA,GAAEE,EAAaF,EAAA,GAE1BG,EAAYC,EAAYnC,GAExBoC,EAAWf,EAAO,MAClBgB,EAAgBhB,EAAO,MAiB7B,SAASiB,EAAeC,GAClBnC,GAAYwB,IAGhBW,EAAMC,iBACNC,GAAqB,GACvB,CAEA,SAASA,EAAqBzC,GAC5Bc,SAAAA,EAAmBd,GACnB6B,EAAa7B,EACf,CAEA,SAAS0C,KACPD,GAAqB,GAEjBzC,IAAU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aAAA,EAAAA,EAAUuB,QAClCe,SAAAA,EAAiBJ,MAAMC,YAAY,iBAAkB,QACrDG,SAAAA,EAAiBJ,MAAMC,YAAY,iBAAgB,GAAAC,OAAKE,EAAgBC,aAnJzD,EAmJsF,MACtG,CATA,CAUH,GAAG,CAAC3C,EAAYJ,IAGdgD,EACEC,cAAA,MAAA,CAAAjF,IAAK0B,EACLzB,GAAIA,eACQS,EAAS,cACRP,EACbD,UAAWgF,EAAGC,EAAOC,mBAAoBlF,GACzCmF,KAAMrD,EAAY,KAAO,SACzB3B,QA/GJ,SAA2BsC,GACzBtC,SAAAA,EAAUsC,GACVD,EAAeC,EACjB,EA6GI2C,UAAW1B,IAEV5B,IACET,EACCyD,EACEC,cAAA,WAAA,CAAAjF,IAAKwC,EACLtC,UAAWgF,EAAGC,EAAOI,SAAU1E,GAC/BT,MAAOgC,EACP9B,SAAUmD,GACV6B,UAAWtC,GACXwC,OAAQzC,eACIrC,EACZC,YAAaA,EACb0E,KAAK,UACLI,KAAM,IAGRT,EACEC,cAAA,QAAA,CAAAjF,IAAKwC,EACLtC,UAAWgF,EAAGC,EAAOO,MAAO7E,GAC5BT,MAAOgC,EACP9B,SAAUmD,GACV6B,UAAWtC,GACXwC,OAAQzC,EAAU,aACNrC,EACZC,YAAaA,EACb0E,KAAK,WAGXL,EAAAC,cAACnE,EACC,CAAAd,IAAKyC,gBACQT,EACb9B,UAAWgF,EAAGC,EAAOQ,WAAY9E,EAAmB+E,EAAAA,EAAAA,EAAAA,KACjDT,EAAOU,OAAS7D,GAChBmD,EAAOW,SAAWtF,GAClB2E,EAAOxE,aAAeyB,GAAczB,GACpCwE,EAAO5D,WAAaS,GAAaT,IAEpCwE,SAAU,EACV5E,aAAcA,EACdE,OAAQA,EACRD,KAAMA,EACN4E,UAAWzE,GAEVa,GAAczB,GAIvB"}
1
+ {"version":3,"file":"EditableTypography.js","sources":["../../../../../src/components/EditableTypography/EditableTypography.tsx"],"sourcesContent":["import React, { type ElementType, forwardRef, useEffect, useRef, useState } from \"react\";\nimport cx from \"classnames\";\nimport useMergeRef from \"../../hooks/useMergeRef\";\nimport { type VibeComponentProps } from \"../../types\";\nimport styles from \"./EditableTypography.module.scss\";\nimport { keyCodes } from \"../../constants\";\nimport { useKeyboardButtonPressedFunc } from \"../../hooks/useKeyboardButtonPressedFunc\";\nimport { type TooltipProps } from \"../Tooltip\";\nimport usePrevious from \"../../hooks/usePrevious\";\nimport { type TextType, type TextWeight } from \"../Text\";\nimport { type HeadingType, type HeadingWeight } from \"../Heading\";\nimport useIsomorphicLayoutEffect from \"../../hooks/ssr/useIsomorphicLayoutEffect\";\n\nexport interface EditableTypographyImplementationProps {\n /**\n * The current value of the text.\n */\n value: string;\n /**\n * Callback fired when the value changes.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the component is clicked.\n */\n onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;\n /**\n * Callback fired when a key is pressed inside the input/textarea element.\n */\n onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n /**\n * If true, the text is read-only and cannot be edited.\n */\n readOnly?: boolean;\n /**\n * Placeholder text displayed when the value is empty.\n */\n placeholder?: string;\n /**\n * The label of the component for accessibility.\n */\n ariaLabel?: string;\n /**\n * Controls whether the component is in edit mode.\n */\n isEditMode?: boolean;\n /**\n * If true, automatically selects all text when entering edit mode.\n */\n autoSelectTextOnEditMode?: boolean;\n /**\n * Callback fired when the edit mode changes.\n */\n onEditModeChange?: (isEditMode: boolean) => void;\n /**\n * Props to customize the tooltip.\n */\n tooltipProps?: Partial<TooltipProps>;\n}\n\nexport interface EditableTypographyProps extends VibeComponentProps, EditableTypographyImplementationProps {\n /**\n * The typography component used in view mode.\n */\n component: ElementType;\n /**\n * Class name applied to the typography component.\n */\n typographyClassName: string;\n /**\n * If true, shows the placeholder when empty.\n */\n clearable?: boolean;\n /**\n * The text or heading type.\n */\n type?: TextType | HeadingType;\n /**\n * The text or heading weight.\n */\n weight?: TextWeight | HeadingWeight;\n /**\n * If true, enables multi-line editing.\n */\n multiline?: boolean;\n}\n\nconst PADDING_OFFSET = 2;\n\nconst EditableTypography = forwardRef(\n (\n {\n id,\n className,\n \"data-testid\": dataTestId,\n value,\n onChange,\n onClick,\n onKeyDown,\n readOnly = false,\n ariaLabel = \"\",\n placeholder,\n clearable,\n typographyClassName,\n component: TypographyComponent,\n isEditMode,\n autoSelectTextOnEditMode,\n onEditModeChange,\n tooltipProps,\n type,\n weight,\n multiline = false\n }: EditableTypographyProps,\n ref: React.ForwardedRef<HTMLElement>\n ) => {\n const componentRef = useRef(null);\n const mergedRef = useMergeRef(ref, componentRef);\n\n const [isEditing, setIsEditing] = useState(isEditMode || false);\n const [inputValue, setInputValue] = useState(value);\n\n const prevValue = usePrevious(value);\n\n const inputRef = useRef(null);\n const typographyRef = useRef(null);\n\n useEffect(() => {\n if (!isEditing && value !== prevValue && value !== inputValue) {\n setInputValue(value);\n }\n }, [prevValue, isEditing, value, inputValue]);\n\n useEffect(() => {\n setIsEditing(isEditMode);\n }, [isEditMode]);\n\n function onTypographyClick(event: React.KeyboardEvent | React.MouseEvent) {\n onClick?.(event);\n toggleEditMode(event);\n }\n\n function toggleEditMode(event: React.KeyboardEvent | React.MouseEvent) {\n if (readOnly || isEditing) {\n return;\n }\n event.preventDefault();\n handleEditModeChange(true);\n }\n\n function handleEditModeChange(value: boolean) {\n onEditModeChange?.(value);\n setIsEditing(value);\n }\n\n function handleInputValueChange() {\n handleEditModeChange(false);\n\n if (value === inputValue) {\n return;\n }\n\n const shouldShowPlaceholderWhenEmpty = clearable && placeholder;\n if (!inputValue && !shouldShowPlaceholderWhenEmpty) {\n setInputValue(value);\n return;\n }\n setInputValue(inputValue);\n onChange?.(inputValue);\n }\n\n function handleBlur() {\n handleInputValueChange();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n if (event.nativeEvent.isComposing) {\n return;\n }\n\n if (event.key === keyCodes.ENTER) {\n if (multiline && event.shiftKey) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n handleInputValueChange();\n }\n if (event.key === keyCodes.ESCAPE) {\n event.preventDefault();\n event.stopPropagation();\n handleEditModeChange(false);\n setInputValue(value);\n }\n\n onKeyDown?.(event);\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {\n setInputValue(event.target.value);\n }\n\n const toggleKeyboardEditMode = useKeyboardButtonPressedFunc(toggleEditMode);\n\n function focus() {\n inputRef.current?.focus?.();\n\n if (inputRef.current) {\n const inputElement = inputRef.current as HTMLInputElement | HTMLTextAreaElement;\n const textLength = inputElement.value.length;\n inputElement.setSelectionRange(textLength, textLength);\n }\n }\n\n function selectAllInputText() {\n inputRef.current?.select?.();\n }\n\n useEffect(() => {\n if (!isEditing) return;\n focus();\n if (autoSelectTextOnEditMode) {\n selectAllInputText();\n }\n }, [autoSelectTextOnEditMode, isEditing]);\n\n useIsomorphicLayoutEffect(() => {\n if (!typographyRef.current) {\n return;\n }\n\n const { width } = typographyRef.current.getBoundingClientRect();\n inputRef?.current?.style.setProperty(\"--input-width\", `${width}px`);\n\n if (multiline) {\n const textareaElement = inputRef?.current as HTMLTextAreaElement;\n textareaElement?.style.setProperty(\"--input-height\", \"auto\");\n textareaElement?.style.setProperty(\"--input-height\", `${textareaElement.scrollHeight + PADDING_OFFSET}px`);\n }\n }, [inputValue, isEditing]);\n\n return (\n <div\n ref={mergedRef}\n id={id}\n aria-label={ariaLabel}\n data-testid={dataTestId}\n className={cx(styles.editableTypography, className)}\n role={isEditing ? null : \"button\"}\n onClick={onTypographyClick}\n onKeyDown={toggleKeyboardEditMode}\n >\n {isEditing &&\n (multiline ? (\n <textarea\n ref={inputRef}\n className={cx(styles.textarea, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"textbox\"\n rows={1}\n />\n ) : (\n <input\n ref={inputRef}\n className={cx(styles.input, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"input\"\n />\n ))}\n <TypographyComponent\n ref={typographyRef}\n aria-hidden={isEditing}\n className={cx(styles.typography, typographyClassName, {\n [styles.hidden]: isEditing,\n [styles.disabled]: readOnly,\n [styles.placeholder]: !inputValue && placeholder,\n [styles.multiline]: !isEditing && multiline\n })}\n tabIndex={0}\n tooltipProps={tooltipProps}\n weight={weight}\n type={type}\n ellipsis={!multiline}\n >\n {inputValue || placeholder}\n </TypographyComponent>\n </div>\n );\n }\n);\n\nexport default EditableTypography;\n"],"names":["EditableTypography","forwardRef","_ref","ref","id","className","dataTestId","value","onChange","onClick","onKeyDown","_ref$readOnly","readOnly","_ref$ariaLabel","ariaLabel","placeholder","clearable","typographyClassName","TypographyComponent","component","isEditMode","autoSelectTextOnEditMode","onEditModeChange","tooltipProps","type","weight","_ref$multiline","multiline","componentRef","useRef","mergedRef","useMergeRef","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useState3","_useState4","inputValue","setInputValue","prevValue","usePrevious","inputRef","typographyRef","toggleEditMode","event","preventDefault","handleEditModeChange","handleInputValueChange","handleBlur","handleKeyDown","nativeEvent","isComposing","key","keyCodes","ENTER","shiftKey","stopPropagation","ESCAPE","handleChange","target","useEffect","toggleKeyboardEditMode","useKeyboardButtonPressedFunc","_b","current","_a","focus","inputElement","textLength","length","setSelectionRange","select","useIsomorphicLayoutEffect","_typographyRef$curren","getBoundingClientRect","style","setProperty","concat","width","textareaElement","scrollHeight","React","createElement","cx","styles","editableTypography","role","textarea","onBlur","rows","input","typography","_defineProperty","hidden","disabled","tabIndex","ellipsis"],"mappings":"wkBAuFA,IAEMA,EAAqBC,GACzB,SAAAC,EAuBEC,GACE,IAtBAC,EAAEF,EAAFE,GACAC,EAASH,EAATG,UACeC,EAAUJ,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B,GAAIA,eACQU,EAAS,cACRR,EACbD,UAAWiF,EAAGC,EAAOC,mBAAoBnF,GACzCoF,KAAMrD,EAAY,KAAO,SACzB3B,QAjHJ,SAA2BsC,GACzBtC,SAAAA,EAAUsC,GACVD,EAAeC,EACjB,EA+GIrC,UAAWsD,IAEV5B,IACET,EACCyD,EACEC,cAAA,WAAA,CAAAlF,IAAKyC,EACLvC,UAAWiF,EAAGC,EAAOG,SAAUzE,GAC/BV,MAAOiC,EACPhC,SAAUqD,GACVnD,UAAW0C,GACXuC,OAAQxC,gBACIrC,EACZC,YAAaA,EACb0E,KAAK,UACLG,KAAM,IAGRR,EACEC,cAAA,QAAA,CAAAlF,IAAKyC,EACLvC,UAAWiF,EAAGC,EAAOM,MAAO5E,GAC5BV,MAAOiC,EACPhC,SAAUqD,GACVnD,UAAW0C,GACXuC,OAAQxC,GAAU,aACNrC,EACZC,YAAaA,EACb0E,KAAK,WAGXL,EAAAC,cAACnE,EACC,CAAAf,IAAK0C,gBACQT,EACb/B,UAAWiF,EAAGC,EAAOO,WAAY7E,EAAmB8E,EAAAA,EAAAA,EAAAA,KACjDR,EAAOS,OAAS5D,GAChBmD,EAAOU,SAAWrF,GAClB2E,EAAOxE,aAAeyB,GAAczB,GACpCwE,EAAO5D,WAAaS,GAAaT,IAEpCuE,SAAU,EACV3E,aAAcA,EACdE,OAAQA,EACRD,KAAMA,EACN2E,UAAWxE,GAEVa,GAAczB,GAIvB"}
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as n,useRef as l,useState as r,useEffect as a}from"react";import i from"classnames";import s from"../../hooks/useMergeRef.js";import u from"./EditableTypography.module.scss.js";import{keyCodes as c}from"../../constants/keyCodes.js";import"../../constants/sizes.js";import{useKeyboardButtonPressedFunc as p}from"../../hooks/useKeyboardButtonPressedFunc.js";import d from"../../hooks/usePrevious/index.js";import f from"../../hooks/ssr/useIsomorphicLayoutEffect.js";var m=n((function(n,m){var v=n.id,h=n.className,y=n["data-testid"],g=n.value,E=n.onClick,b=n.onChange,P=n.readOnly,C=void 0!==P&&P,x=n.ariaLabel,k=void 0===x?"":x,j=n.placeholder,w=n.clearable,N=n.typographyClassName,D=n.component,B=n.isEditMode,K=n.autoSelectTextOnEditMode,T=n.onEditModeChange,M=n.tooltipProps,R=n.type,S=n.weight,A=n.multiline,H=void 0!==A&&A,I=l(null),L=s(m,I),O=r(B||!1),_=e(O,2),z=_[0],F=_[1],q=r(g),G=e(q,2),J=G[0],Q=G[1],U=d(g),V=l(null),W=l(null);function X(e){C||z||(e.preventDefault(),Y(!0))}function Y(e){null==T||T(e),F(e)}function Z(){(Y(!1),g!==J)&&(J||w&&j?(Q(J),null==b||b(J)):Q(g))}function $(){Z()}function ee(e){if(!e.nativeEvent.isComposing){if(e.key===c.ENTER){if(H&&e.shiftKey)return;e.preventDefault(),e.stopPropagation(),Z()}e.key===c.ESCAPE&&(e.preventDefault(),e.stopPropagation(),Y(!1),Q(g))}}function te(e){Q(e.target.value)}a((function(){z||g===U||g===J||Q(g)}),[U,z,g,J]),a((function(){F(B)}),[B]);var oe=p(X);return a((function(){var e,t;z&&(!function(){var e,t;if(null===(t=null===(e=V.current)||void 0===e?void 0:e.focus)||void 0===t||t.call(e),V.current){var o=V.current,n=o.value.length;o.setSelectionRange(n,n)}}(),K&&(null===(t=null===(e=V.current)||void 0===e?void 0:e.select)||void 0===t||t.call(e)))}),[K,z]),f((function(){var e;if(W.current){var t=W.current.getBoundingClientRect();if(null===(e=null==V?void 0:V.current)||void 0===e||e.style.setProperty("--input-width","".concat(t.width,"px")),H){var o=null==V?void 0:V.current;null==o||o.style.setProperty("--input-height","auto"),null==o||o.style.setProperty("--input-height","".concat(o.scrollHeight+2,"px"))}}}),[J,z]),o.createElement("div",{ref:L,id:v,"aria-label":k,"data-testid":y,className:i(u.editableTypography,h),role:z?null:"button",onClick:function(e){null==E||E(e),X(e)},onKeyDown:oe},z&&(H?o.createElement("textarea",{ref:V,className:i(u.textarea,N),value:J,onChange:te,onKeyDown:ee,onBlur:$,"aria-label":k,placeholder:j,role:"textbox",rows:1}):o.createElement("input",{ref:V,className:i(u.input,N),value:J,onChange:te,onKeyDown:ee,onBlur:$,"aria-label":k,placeholder:j,role:"input"})),o.createElement(D,{ref:W,"aria-hidden":z,className:i(u.typography,N,t(t(t(t({},u.hidden,z),u.disabled,C),u.placeholder,!J&&j),u.multiline,!z&&H)),tabIndex:0,tooltipProps:M,weight:S,type:R,ellipsis:!H},J||j))}));export{m as default};
1
+ import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import o,{forwardRef as n,useRef as l,useState as r,useEffect as a}from"react";import i from"classnames";import s from"../../hooks/useMergeRef.js";import u from"./EditableTypography.module.scss.js";import{keyCodes as c}from"../../constants/keyCodes.js";import"../../constants/sizes.js";import{useKeyboardButtonPressedFunc as p}from"../../hooks/useKeyboardButtonPressedFunc.js";import d from"../../hooks/usePrevious/index.js";import f from"../../hooks/ssr/useIsomorphicLayoutEffect.js";var m=n((function(n,m){var v=n.id,h=n.className,y=n["data-testid"],g=n.value,E=n.onChange,b=n.onClick,P=n.onKeyDown,C=n.readOnly,x=void 0!==C&&C,k=n.ariaLabel,w=void 0===k?"":k,j=n.placeholder,D=n.clearable,N=n.typographyClassName,K=n.component,B=n.isEditMode,T=n.autoSelectTextOnEditMode,M=n.onEditModeChange,R=n.tooltipProps,S=n.type,A=n.weight,H=n.multiline,I=void 0!==H&&H,L=l(null),O=s(m,L),_=r(B||!1),z=e(_,2),F=z[0],q=z[1],G=r(g),J=e(G,2),Q=J[0],U=J[1],V=d(g),W=l(null),X=l(null);function Y(e){x||F||(e.preventDefault(),Z(!0))}function Z(e){null==M||M(e),q(e)}function $(){(Z(!1),g!==Q)&&(Q||D&&j?(U(Q),null==E||E(Q)):U(g))}function ee(){$()}function te(e){if(!e.nativeEvent.isComposing){if(e.key===c.ENTER){if(I&&e.shiftKey)return;e.preventDefault(),e.stopPropagation(),$()}e.key===c.ESCAPE&&(e.preventDefault(),e.stopPropagation(),Z(!1),U(g)),null==P||P(e)}}function oe(e){U(e.target.value)}a((function(){F||g===V||g===Q||U(g)}),[V,F,g,Q]),a((function(){q(B)}),[B]);var ne=p(Y);return a((function(){var e,t;F&&(!function(){var e,t;if(null===(t=null===(e=W.current)||void 0===e?void 0:e.focus)||void 0===t||t.call(e),W.current){var o=W.current,n=o.value.length;o.setSelectionRange(n,n)}}(),T&&(null===(t=null===(e=W.current)||void 0===e?void 0:e.select)||void 0===t||t.call(e)))}),[T,F]),f((function(){var e;if(X.current){var t=X.current.getBoundingClientRect();if(null===(e=null==W?void 0:W.current)||void 0===e||e.style.setProperty("--input-width","".concat(t.width,"px")),I){var o=null==W?void 0:W.current;null==o||o.style.setProperty("--input-height","auto"),null==o||o.style.setProperty("--input-height","".concat(o.scrollHeight+2,"px"))}}}),[Q,F]),o.createElement("div",{ref:O,id:v,"aria-label":w,"data-testid":y,className:i(u.editableTypography,h),role:F?null:"button",onClick:function(e){null==b||b(e),Y(e)},onKeyDown:ne},F&&(I?o.createElement("textarea",{ref:W,className:i(u.textarea,N),value:Q,onChange:oe,onKeyDown:te,onBlur:ee,"aria-label":w,placeholder:j,role:"textbox",rows:1}):o.createElement("input",{ref:W,className:i(u.input,N),value:Q,onChange:oe,onKeyDown:te,onBlur:ee,"aria-label":w,placeholder:j,role:"input"})),o.createElement(K,{ref:X,"aria-hidden":F,className:i(u.typography,N,t(t(t(t({},u.hidden,F),u.disabled,x),u.placeholder,!Q&&j),u.multiline,!F&&I)),tabIndex:0,tooltipProps:R,weight:A,type:S,ellipsis:!I},Q||j))}));export{m as default};
2
2
  //# sourceMappingURL=EditableTypography.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditableTypography.js","sources":["../../../../src/components/EditableTypography/EditableTypography.tsx"],"sourcesContent":["import React, { type ElementType, forwardRef, useEffect, useRef, useState } from \"react\";\nimport cx from \"classnames\";\nimport useMergeRef from \"../../hooks/useMergeRef\";\nimport { type VibeComponentProps } from \"../../types\";\nimport styles from \"./EditableTypography.module.scss\";\nimport { keyCodes } from \"../../constants\";\nimport { useKeyboardButtonPressedFunc } from \"../../hooks/useKeyboardButtonPressedFunc\";\nimport { type TooltipProps } from \"../Tooltip\";\nimport usePrevious from \"../../hooks/usePrevious\";\nimport { type TextType, type TextWeight } from \"../Text\";\nimport { type HeadingType, type HeadingWeight } from \"../Heading\";\nimport useIsomorphicLayoutEffect from \"../../hooks/ssr/useIsomorphicLayoutEffect\";\n\nexport interface EditableTypographyImplementationProps {\n /**\n * The current value of the text.\n */\n value: string;\n /**\n * Callback fired when the value changes.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the component is clicked.\n */\n onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;\n /**\n * If true, the text is read-only and cannot be edited.\n */\n readOnly?: boolean;\n /**\n * Placeholder text displayed when the value is empty.\n */\n placeholder?: string;\n /**\n * The label of the component for accessibility.\n */\n ariaLabel?: string;\n /**\n * Controls whether the component is in edit mode.\n */\n isEditMode?: boolean;\n /**\n * If true, automatically selects all text when entering edit mode.\n */\n autoSelectTextOnEditMode?: boolean;\n /**\n * Callback fired when the edit mode changes.\n */\n onEditModeChange?: (isEditMode: boolean) => void;\n /**\n * Props to customize the tooltip.\n */\n tooltipProps?: Partial<TooltipProps>;\n}\n\nexport interface EditableTypographyProps extends VibeComponentProps, EditableTypographyImplementationProps {\n /**\n * The typography component used in view mode.\n */\n component: ElementType;\n /**\n * Class name applied to the typography component.\n */\n typographyClassName: string;\n /**\n * If true, shows the placeholder when empty.\n */\n clearable?: boolean;\n /**\n * The text or heading type.\n */\n type?: TextType | HeadingType;\n /**\n * The text or heading weight.\n */\n weight?: TextWeight | HeadingWeight;\n /**\n * If true, enables multi-line editing.\n */\n multiline?: boolean;\n}\n\nconst PADDING_OFFSET = 2;\n\nconst EditableTypography = forwardRef(\n (\n {\n id,\n className,\n \"data-testid\": dataTestId,\n value,\n onClick,\n onChange,\n readOnly = false,\n ariaLabel = \"\",\n placeholder,\n clearable,\n typographyClassName,\n component: TypographyComponent,\n isEditMode,\n autoSelectTextOnEditMode,\n onEditModeChange,\n tooltipProps,\n type,\n weight,\n multiline = false\n }: EditableTypographyProps,\n ref: React.ForwardedRef<HTMLElement>\n ) => {\n const componentRef = useRef(null);\n const mergedRef = useMergeRef(ref, componentRef);\n\n const [isEditing, setIsEditing] = useState(isEditMode || false);\n const [inputValue, setInputValue] = useState(value);\n\n const prevValue = usePrevious(value);\n\n const inputRef = useRef(null);\n const typographyRef = useRef(null);\n\n useEffect(() => {\n if (!isEditing && value !== prevValue && value !== inputValue) {\n setInputValue(value);\n }\n }, [prevValue, isEditing, value, inputValue]);\n\n useEffect(() => {\n setIsEditing(isEditMode);\n }, [isEditMode]);\n\n function onTypographyClick(event: React.KeyboardEvent | React.MouseEvent) {\n onClick?.(event);\n toggleEditMode(event);\n }\n\n function toggleEditMode(event: React.KeyboardEvent | React.MouseEvent) {\n if (readOnly || isEditing) {\n return;\n }\n event.preventDefault();\n handleEditModeChange(true);\n }\n\n function handleEditModeChange(value: boolean) {\n onEditModeChange?.(value);\n setIsEditing(value);\n }\n\n function handleInputValueChange() {\n handleEditModeChange(false);\n\n if (value === inputValue) {\n return;\n }\n\n const shouldShowPlaceholderWhenEmpty = clearable && placeholder;\n if (!inputValue && !shouldShowPlaceholderWhenEmpty) {\n setInputValue(value);\n return;\n }\n setInputValue(inputValue);\n onChange?.(inputValue);\n }\n\n function handleBlur() {\n handleInputValueChange();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n if (event.nativeEvent.isComposing) {\n return;\n }\n\n if (event.key === keyCodes.ENTER) {\n if (multiline && event.shiftKey) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n handleInputValueChange();\n }\n if (event.key === keyCodes.ESCAPE) {\n event.preventDefault();\n event.stopPropagation();\n handleEditModeChange(false);\n setInputValue(value);\n }\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {\n setInputValue(event.target.value);\n }\n\n const toggleKeyboardEditMode = useKeyboardButtonPressedFunc(toggleEditMode);\n\n function focus() {\n inputRef.current?.focus?.();\n\n if (inputRef.current) {\n const inputElement = inputRef.current as HTMLInputElement | HTMLTextAreaElement;\n const textLength = inputElement.value.length;\n inputElement.setSelectionRange(textLength, textLength);\n }\n }\n\n function selectAllInputText() {\n inputRef.current?.select?.();\n }\n\n useEffect(() => {\n if (!isEditing) return;\n focus();\n if (autoSelectTextOnEditMode) {\n selectAllInputText();\n }\n }, [autoSelectTextOnEditMode, isEditing]);\n\n useIsomorphicLayoutEffect(() => {\n if (!typographyRef.current) {\n return;\n }\n\n const { width } = typographyRef.current.getBoundingClientRect();\n inputRef?.current?.style.setProperty(\"--input-width\", `${width}px`);\n\n if (multiline) {\n const textareaElement = inputRef?.current as HTMLTextAreaElement;\n textareaElement?.style.setProperty(\"--input-height\", \"auto\");\n textareaElement?.style.setProperty(\"--input-height\", `${textareaElement.scrollHeight + PADDING_OFFSET}px`);\n }\n }, [inputValue, isEditing]);\n\n return (\n <div\n ref={mergedRef}\n id={id}\n aria-label={ariaLabel}\n data-testid={dataTestId}\n className={cx(styles.editableTypography, className)}\n role={isEditing ? null : \"button\"}\n onClick={onTypographyClick}\n onKeyDown={toggleKeyboardEditMode}\n >\n {isEditing &&\n (multiline ? (\n <textarea\n ref={inputRef}\n className={cx(styles.textarea, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"textbox\"\n rows={1}\n />\n ) : (\n <input\n ref={inputRef}\n className={cx(styles.input, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"input\"\n />\n ))}\n <TypographyComponent\n ref={typographyRef}\n aria-hidden={isEditing}\n className={cx(styles.typography, typographyClassName, {\n [styles.hidden]: isEditing,\n [styles.disabled]: readOnly,\n [styles.placeholder]: !inputValue && placeholder,\n [styles.multiline]: !isEditing && multiline\n })}\n tabIndex={0}\n tooltipProps={tooltipProps}\n weight={weight}\n type={type}\n ellipsis={!multiline}\n >\n {inputValue || placeholder}\n </TypographyComponent>\n </div>\n );\n }\n);\n\nexport default EditableTypography;\n"],"names":["EditableTypography","forwardRef","_ref","ref","id","className","dataTestId","value","onClick","onChange","_ref$readOnly","readOnly","_ref$ariaLabel","ariaLabel","placeholder","clearable","typographyClassName","TypographyComponent","component","isEditMode","autoSelectTextOnEditMode","onEditModeChange","tooltipProps","type","weight","_ref$multiline","multiline","componentRef","useRef","mergedRef","useMergeRef","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useState3","_useState4","inputValue","setInputValue","prevValue","usePrevious","inputRef","typographyRef","toggleEditMode","event","preventDefault","handleEditModeChange","handleInputValueChange","handleBlur","handleKeyDown","nativeEvent","isComposing","key","keyCodes","ENTER","shiftKey","stopPropagation","ESCAPE","handleChange","target","useEffect","toggleKeyboardEditMode","useKeyboardButtonPressedFunc","_b","current","_a","focus","inputElement","textLength","length","setSelectionRange","select","useIsomorphicLayoutEffect","_typographyRef$curren","getBoundingClientRect","style","setProperty","concat","width","textareaElement","scrollHeight","React","createElement","cx","styles","editableTypography","role","onKeyDown","textarea","onBlur","rows","input","typography","_defineProperty","hidden","disabled","tabIndex","ellipsis"],"mappings":"wkBAmFA,IAEMA,EAAqBC,GACzB,SAAAC,EAsBEC,GACE,IArBAC,EAAEF,EAAFE,GACAC,EAASH,EAATG,UACeC,EAAUJ,EAAzB,eACAK,EAAKL,EAALK,MACAC,EAAON,EAAPM,QACAC,EAAQP,EAARO,SAAQC,EAAAR,EACRS,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAAAV,EAChBW,UAAAA,OAAY,IAAHD,EAAG,GAAEA,EACd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AA,WAAA,CAAAjF,IAAKwC,EACLtC,UAAWgF,EAAGC,EAAOI,SAAU1E,GAC/BT,MAAOgC,EACP9B,SAAUmD,GACV6B,UAAWtC,GACXwC,OAAQzC,eACIrC,EACZC,YAAaA,EACb0E,KAAK,UACLI,KAAM,IAGRT,EACEC,cAAA,QAAA,CAAAjF,IAAKwC,EACLtC,UAAWgF,EAAGC,EAAOO,MAAO7E,GAC5BT,MAAOgC,EACP9B,SAAUmD,GACV6B,UAAWtC,GACXwC,OAAQzC,EAAU,aACNrC,EACZC,YAAaA,EACb0E,KAAK,WAGXL,EAAAC,cAACnE,EACC,CAAAd,IAAKyC,gBACQT,EACb9B,UAAWgF,EAAGC,EAAOQ,WAAY9E,EAAmB+E,EAAAA,EAAAA,EAAAA,KACjDT,EAAOU,OAAS7D,GAChBmD,EAAOW,SAAWtF,GAClB2E,EAAOxE,aAAeyB,GAAczB,GACpCwE,EAAO5D,WAAaS,GAAaT,IAEpCwE,SAAU,EACV5E,aAAcA,EACdE,OAAQA,EACRD,KAAMA,EACN4E,UAAWzE,GAEVa,GAAczB,GAIvB"}
1
+ {"version":3,"file":"EditableTypography.js","sources":["../../../../src/components/EditableTypography/EditableTypography.tsx"],"sourcesContent":["import React, { type ElementType, forwardRef, useEffect, useRef, useState } from \"react\";\nimport cx from \"classnames\";\nimport useMergeRef from \"../../hooks/useMergeRef\";\nimport { type VibeComponentProps } from \"../../types\";\nimport styles from \"./EditableTypography.module.scss\";\nimport { keyCodes } from \"../../constants\";\nimport { useKeyboardButtonPressedFunc } from \"../../hooks/useKeyboardButtonPressedFunc\";\nimport { type TooltipProps } from \"../Tooltip\";\nimport usePrevious from \"../../hooks/usePrevious\";\nimport { type TextType, type TextWeight } from \"../Text\";\nimport { type HeadingType, type HeadingWeight } from \"../Heading\";\nimport useIsomorphicLayoutEffect from \"../../hooks/ssr/useIsomorphicLayoutEffect\";\n\nexport interface EditableTypographyImplementationProps {\n /**\n * The current value of the text.\n */\n value: string;\n /**\n * Callback fired when the value changes.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the component is clicked.\n */\n onClick?: (event: React.KeyboardEvent | React.MouseEvent) => void;\n /**\n * Callback fired when a key is pressed inside the input/textarea element.\n */\n onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n /**\n * If true, the text is read-only and cannot be edited.\n */\n readOnly?: boolean;\n /**\n * Placeholder text displayed when the value is empty.\n */\n placeholder?: string;\n /**\n * The label of the component for accessibility.\n */\n ariaLabel?: string;\n /**\n * Controls whether the component is in edit mode.\n */\n isEditMode?: boolean;\n /**\n * If true, automatically selects all text when entering edit mode.\n */\n autoSelectTextOnEditMode?: boolean;\n /**\n * Callback fired when the edit mode changes.\n */\n onEditModeChange?: (isEditMode: boolean) => void;\n /**\n * Props to customize the tooltip.\n */\n tooltipProps?: Partial<TooltipProps>;\n}\n\nexport interface EditableTypographyProps extends VibeComponentProps, EditableTypographyImplementationProps {\n /**\n * The typography component used in view mode.\n */\n component: ElementType;\n /**\n * Class name applied to the typography component.\n */\n typographyClassName: string;\n /**\n * If true, shows the placeholder when empty.\n */\n clearable?: boolean;\n /**\n * The text or heading type.\n */\n type?: TextType | HeadingType;\n /**\n * The text or heading weight.\n */\n weight?: TextWeight | HeadingWeight;\n /**\n * If true, enables multi-line editing.\n */\n multiline?: boolean;\n}\n\nconst PADDING_OFFSET = 2;\n\nconst EditableTypography = forwardRef(\n (\n {\n id,\n className,\n \"data-testid\": dataTestId,\n value,\n onChange,\n onClick,\n onKeyDown,\n readOnly = false,\n ariaLabel = \"\",\n placeholder,\n clearable,\n typographyClassName,\n component: TypographyComponent,\n isEditMode,\n autoSelectTextOnEditMode,\n onEditModeChange,\n tooltipProps,\n type,\n weight,\n multiline = false\n }: EditableTypographyProps,\n ref: React.ForwardedRef<HTMLElement>\n ) => {\n const componentRef = useRef(null);\n const mergedRef = useMergeRef(ref, componentRef);\n\n const [isEditing, setIsEditing] = useState(isEditMode || false);\n const [inputValue, setInputValue] = useState(value);\n\n const prevValue = usePrevious(value);\n\n const inputRef = useRef(null);\n const typographyRef = useRef(null);\n\n useEffect(() => {\n if (!isEditing && value !== prevValue && value !== inputValue) {\n setInputValue(value);\n }\n }, [prevValue, isEditing, value, inputValue]);\n\n useEffect(() => {\n setIsEditing(isEditMode);\n }, [isEditMode]);\n\n function onTypographyClick(event: React.KeyboardEvent | React.MouseEvent) {\n onClick?.(event);\n toggleEditMode(event);\n }\n\n function toggleEditMode(event: React.KeyboardEvent | React.MouseEvent) {\n if (readOnly || isEditing) {\n return;\n }\n event.preventDefault();\n handleEditModeChange(true);\n }\n\n function handleEditModeChange(value: boolean) {\n onEditModeChange?.(value);\n setIsEditing(value);\n }\n\n function handleInputValueChange() {\n handleEditModeChange(false);\n\n if (value === inputValue) {\n return;\n }\n\n const shouldShowPlaceholderWhenEmpty = clearable && placeholder;\n if (!inputValue && !shouldShowPlaceholderWhenEmpty) {\n setInputValue(value);\n return;\n }\n setInputValue(inputValue);\n onChange?.(inputValue);\n }\n\n function handleBlur() {\n handleInputValueChange();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n if (event.nativeEvent.isComposing) {\n return;\n }\n\n if (event.key === keyCodes.ENTER) {\n if (multiline && event.shiftKey) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n handleInputValueChange();\n }\n if (event.key === keyCodes.ESCAPE) {\n event.preventDefault();\n event.stopPropagation();\n handleEditModeChange(false);\n setInputValue(value);\n }\n\n onKeyDown?.(event);\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {\n setInputValue(event.target.value);\n }\n\n const toggleKeyboardEditMode = useKeyboardButtonPressedFunc(toggleEditMode);\n\n function focus() {\n inputRef.current?.focus?.();\n\n if (inputRef.current) {\n const inputElement = inputRef.current as HTMLInputElement | HTMLTextAreaElement;\n const textLength = inputElement.value.length;\n inputElement.setSelectionRange(textLength, textLength);\n }\n }\n\n function selectAllInputText() {\n inputRef.current?.select?.();\n }\n\n useEffect(() => {\n if (!isEditing) return;\n focus();\n if (autoSelectTextOnEditMode) {\n selectAllInputText();\n }\n }, [autoSelectTextOnEditMode, isEditing]);\n\n useIsomorphicLayoutEffect(() => {\n if (!typographyRef.current) {\n return;\n }\n\n const { width } = typographyRef.current.getBoundingClientRect();\n inputRef?.current?.style.setProperty(\"--input-width\", `${width}px`);\n\n if (multiline) {\n const textareaElement = inputRef?.current as HTMLTextAreaElement;\n textareaElement?.style.setProperty(\"--input-height\", \"auto\");\n textareaElement?.style.setProperty(\"--input-height\", `${textareaElement.scrollHeight + PADDING_OFFSET}px`);\n }\n }, [inputValue, isEditing]);\n\n return (\n <div\n ref={mergedRef}\n id={id}\n aria-label={ariaLabel}\n data-testid={dataTestId}\n className={cx(styles.editableTypography, className)}\n role={isEditing ? null : \"button\"}\n onClick={onTypographyClick}\n onKeyDown={toggleKeyboardEditMode}\n >\n {isEditing &&\n (multiline ? (\n <textarea\n ref={inputRef}\n className={cx(styles.textarea, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"textbox\"\n rows={1}\n />\n ) : (\n <input\n ref={inputRef}\n className={cx(styles.input, typographyClassName)}\n value={inputValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n aria-label={ariaLabel}\n placeholder={placeholder}\n role=\"input\"\n />\n ))}\n <TypographyComponent\n ref={typographyRef}\n aria-hidden={isEditing}\n className={cx(styles.typography, typographyClassName, {\n [styles.hidden]: isEditing,\n [styles.disabled]: readOnly,\n [styles.placeholder]: !inputValue && placeholder,\n [styles.multiline]: !isEditing && multiline\n })}\n tabIndex={0}\n tooltipProps={tooltipProps}\n weight={weight}\n type={type}\n ellipsis={!multiline}\n >\n {inputValue || placeholder}\n </TypographyComponent>\n </div>\n );\n }\n);\n\nexport default EditableTypography;\n"],"names":["EditableTypography","forwardRef","_ref","ref","id","className","dataTestId","value","onChange","onClick","onKeyDown","_ref$readOnly","readOnly","_ref$ariaLabel","ariaLabel","placeholder","clearable","typographyClassName","TypographyComponent","component","isEditMode","autoSelectTextOnEditMode","onEditModeChange","tooltipProps","type","weight","_ref$multiline","multiline","componentRef","useRef","mergedRef","useMergeRef","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useState3","_useState4","inputValue","setInputValue","prevValue","usePrevious","inputRef","typographyRef","toggleEditMode","event","preventDefault","handleEditModeChange","handleInputValueChange","handleBlur","handleKeyDown","nativeEvent","isComposing","key","keyCodes","ENTER","shiftKey","stopPropagation","ESCAPE","handleChange","target","useEffect","toggleKeyboardEditMode","useKeyboardButtonPressedFunc","_b","current","_a","focus","inputElement","textLength","length","setSelectionRange","select","useIsomorphicLayoutEffect","_typographyRef$curren","getBoundingClientRect","style","setProperty","concat","width","textareaElement","scrollHeight","React","createElement","cx","styles","editableTypography","role","textarea","onBlur","rows","input","typography","_defineProperty","hidden","disabled","tabIndex","ellipsis"],"mappings":"wkBAuFA,IAEMA,EAAqBC,GACzB,SAAAC,EAuBEC,GACE,IAtBAC,EAAEF,EAAFE,GACAC,EAASH,EAATG,UACeC,EAAUJ,EAAzB,eACAK,EAAKL,EAALK,MACAC,EAAQN,EAARM,SACAC,EAAOP,EAAPO,QACAC,EAASR,EAATQ,UAASC,EAAAT,EACTU,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAAAX,EAChBY,UAAAA,OAAY,IAAHD,EAAG,GAAEA,EACdE,EAAWb,EAAXa,YACAC,EAASd,EAATc,UACAC,EAAmBf,EAAnBe,oBACWC,EAAmBhB,EAA9BiB,UACAC,EAAUlB,EAAVkB,WACAC,EAAwBnB,EAAxBmB,yBACAC,EAAgBpB,EAAhBoB,iBACAC,EAAYrB,EAAZqB,aACAC,EAAItB,EAAJsB,KACAC,EAAMvB,EAANuB,OAAMC,EAAAxB,EACNyB,UAAAA,OAAY,I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AAOM,MAAO5E,GAC5BV,MAAOiC,EACPhC,SAAUqD,GACVnD,UAAW0C,GACXuC,OAAQxC,GAAU,aACNrC,EACZC,YAAaA,EACb0E,KAAK,WAGXL,EAAAC,cAACnE,EACC,CAAAf,IAAK0C,gBACQT,EACb/B,UAAWiF,EAAGC,EAAOO,WAAY7E,EAAmB8E,EAAAA,EAAAA,EAAAA,KACjDR,EAAOS,OAAS5D,GAChBmD,EAAOU,SAAWrF,GAClB2E,EAAOxE,aAAeyB,GAAczB,GACpCwE,EAAO5D,WAAaS,GAAaT,IAEpCuE,SAAU,EACV3E,aAAcA,EACdE,OAAQA,EACRD,KAAMA,EACN2E,UAAWxE,GAEVa,GAAczB,GAIvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe/core",
3
- "version": "3.77.1-alpha-59987.0",
3
+ "version": "3.78.0",
4
4
  "description": "Official monday.com UI resources for application development in React.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -90,15 +90,15 @@
90
90
  },
91
91
  "dependencies": {
92
92
  "@popperjs/core": "2.11.6",
93
- "@vibe/base": "3.0.2-alpha-59987.0",
94
- "@vibe/button": "3.0.7-alpha-59987.0",
95
- "@vibe/dialog": "3.0.1-alpha-59987.0",
96
- "@vibe/hooks": "3.0.1-alpha-59987.0",
97
- "@vibe/icon": "3.0.7-alpha-59987.0",
93
+ "@vibe/base": "3.0.2",
94
+ "@vibe/button": "3.0.7",
95
+ "@vibe/dialog": "3.0.1",
96
+ "@vibe/hooks": "3.0.1",
97
+ "@vibe/icon": "3.0.7",
98
98
  "@vibe/icons": "1.11.1",
99
- "@vibe/layer": "3.0.1-alpha-59987.0",
100
- "@vibe/loader": "3.0.7-alpha-59987.0",
101
- "@vibe/shared": "3.0.7-alpha-59987.0",
99
+ "@vibe/layer": "3.0.1",
100
+ "@vibe/loader": "3.0.7",
101
+ "@vibe/shared": "3.0.7",
102
102
  "a11y-dialog": "^7.5.2",
103
103
  "body-scroll-lock": "^4.0.0-beta.0",
104
104
  "browserslist-config-monday": "1.0.6",
@@ -277,5 +277,5 @@
277
277
  "browserslist": [
278
278
  "extends browserslist-config-monday"
279
279
  ],
280
- "gitHead": "d0bf35495b743196a3ea2bb97304fc904860e598"
280
+ "gitHead": "539bbe029ee0681a566973a4b560ec9bed089b33"
281
281
  }