@activecollab/components 2.0.493 → 2.0.495

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cjs/components/EditableContent/EditableContent.js +12 -19
  2. package/dist/cjs/components/EditableContent/EditableContent.js.map +1 -1
  3. package/dist/cjs/components/EditableContent/Styles.js +16 -1
  4. package/dist/cjs/components/EditableContent/Styles.js.map +1 -1
  5. package/dist/cjs/components/EditableContent/useHoverSuppression.js +34 -0
  6. package/dist/cjs/components/EditableContent/useHoverSuppression.js.map +1 -0
  7. package/dist/cjs/components/EditableText/EditableText.js +65 -60
  8. package/dist/cjs/components/EditableText/EditableText.js.map +1 -1
  9. package/dist/cjs/components/EditableText/useEditableText.js +90 -0
  10. package/dist/cjs/components/EditableText/useEditableText.js.map +1 -0
  11. package/dist/cjs/components/EmptySlate/EmptySlate.js +28 -3
  12. package/dist/cjs/components/EmptySlate/EmptySlate.js.map +1 -1
  13. package/dist/cjs/components/EmptySlate/EmptySlate.styles.js +4 -1
  14. package/dist/cjs/components/EmptySlate/EmptySlate.styles.js.map +1 -1
  15. package/dist/esm/components/EditableContent/EditableContent.d.ts.map +1 -1
  16. package/dist/esm/components/EditableContent/EditableContent.js +13 -13
  17. package/dist/esm/components/EditableContent/EditableContent.js.map +1 -1
  18. package/dist/esm/components/EditableContent/Styles.d.ts +9 -0
  19. package/dist/esm/components/EditableContent/Styles.d.ts.map +1 -1
  20. package/dist/esm/components/EditableContent/Styles.js +15 -0
  21. package/dist/esm/components/EditableContent/Styles.js.map +1 -1
  22. package/dist/esm/components/EditableContent/useHoverSuppression.d.ts +9 -0
  23. package/dist/esm/components/EditableContent/useHoverSuppression.d.ts.map +1 -0
  24. package/dist/esm/components/EditableContent/useHoverSuppression.js +20 -0
  25. package/dist/esm/components/EditableContent/useHoverSuppression.js.map +1 -0
  26. package/dist/esm/components/EditableText/EditableText.d.ts +2 -0
  27. package/dist/esm/components/EditableText/EditableText.d.ts.map +1 -1
  28. package/dist/esm/components/EditableText/EditableText.js +67 -54
  29. package/dist/esm/components/EditableText/EditableText.js.map +1 -1
  30. package/dist/esm/components/EditableText/useEditableText.d.ts +18 -0
  31. package/dist/esm/components/EditableText/useEditableText.d.ts.map +1 -0
  32. package/dist/esm/components/EditableText/useEditableText.js +74 -0
  33. package/dist/esm/components/EditableText/useEditableText.js.map +1 -0
  34. package/dist/esm/components/EmptySlate/EmptySlate.d.ts.map +1 -1
  35. package/dist/esm/components/EmptySlate/EmptySlate.js +16 -2
  36. package/dist/esm/components/EmptySlate/EmptySlate.js.map +1 -1
  37. package/dist/esm/components/EmptySlate/EmptySlate.styles.d.ts +3 -1
  38. package/dist/esm/components/EmptySlate/EmptySlate.styles.d.ts.map +1 -1
  39. package/dist/esm/components/EmptySlate/EmptySlate.styles.js +4 -1
  40. package/dist/esm/components/EmptySlate/EmptySlate.styles.js.map +1 -1
  41. package/dist/index.js +187 -45
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.min.js +1 -1
  44. package/dist/index.min.js.map +1 -1
  45. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"EditableText.js","names":["React","forwardRef","useCallback","useEffect","useRef","useState","classNames","EditableContent","StyledDiv","StyledMultilineSpan","StyledTextareaSpan","EditableText","_ref","ref","onSave","onCancel","value","inputProps","allowEmptyString","_ref$multiline","multiline","_ref$submitOnMetaEnte","submitOnMetaEnter","_ref$variant","variant","weight","_ref$disabled","disabled","invalid","wrapRef","children","props","_objectWithoutPropertiesLoose","_excluded","_useState","currentValue","setCurrentValue","_useState2","prevValue","setPrevValue","escapeRef","intTextareaRef","handleBlur","e","current","target","trim","length","scrollLeft","handleFocus","textarea","setSelectionRange","handleKeyDown","key","blur","metaKey","ctrlKey","preventDefault","stopPropagation","handleChange","createElement","_extends","$multiline","forwardedAs","$disabled","className","onClick","focus","String","replace","onFocus","onBlur","onKeyDown","onChange","placeholder","rows","type","displayName"],"sources":["../../../../src/components/EditableText/EditableText.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport classNames from \"classnames\";\n\nimport {\n EditableContent,\n EditableContentInterface,\n} from \"../EditableContent/EditableContent\";\nimport {\n StyledDiv,\n StyledMultilineSpan,\n StyledTextareaSpan,\n} from \"../EditableContent/Styles\";\n\nexport interface EditableTextInterface extends EditableContentInterface {\n /** Value to display. */\n value?: string | null;\n /** Optional callback called on enter, click outside and tab. */\n onSave?: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n /** Optional callback called on input reset. */\n onCancel?: (e) => void;\n /** If true, setting empty value will save it, instead of revert to previous value. */\n allowEmptyString?: boolean;\n /** If true, shows a textarea instead of input for multiline editing. */\n multiline?: boolean;\n /** If true, Cmd/Ctrl+Enter commits a multiline edit (plain Enter keeps inserting a newline). */\n submitOnMetaEnter?: boolean;\n /** Children content to display */\n children?: React.ReactNode;\n}\n\nexport const EditableText = forwardRef<HTMLDivElement, EditableTextInterface>(\n (\n {\n onSave,\n onCancel,\n value,\n inputProps,\n allowEmptyString,\n multiline = false,\n submitOnMetaEnter = false,\n variant = \"Body 2\",\n weight,\n disabled = false,\n invalid,\n wrapRef,\n children,\n ...props\n },\n ref\n ) => {\n const [currentValue, setCurrentValue] = useState(value);\n const [prevValue, setPrevValue] = useState(value);\n const escapeRef = useRef(false);\n const intTextareaRef = useRef<HTMLTextAreaElement>(null);\n\n useEffect(() => {\n if (currentValue !== value) {\n setCurrentValue(value);\n setPrevValue(value);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value]);\n\n const handleBlur = useCallback(\n (e) => {\n if (escapeRef.current) {\n setCurrentValue(prevValue);\n escapeRef.current = false;\n } else {\n if (\n e.target.value.trim().length > 0 &&\n prevValue !== e.target.value\n ) {\n setPrevValue(e.target.value);\n setCurrentValue(e.target.value);\n typeof onSave === \"function\" && onSave(e);\n } else {\n !allowEmptyString\n ? setCurrentValue(prevValue)\n : typeof onSave === \"function\" &&\n prevValue !== e.target.value &&\n onSave(e);\n }\n }\n // Reset scroll position for textarea\n if (multiline && intTextareaRef?.current) {\n intTextareaRef.current.scrollLeft = 0;\n }\n },\n [allowEmptyString, onSave, prevValue, multiline]\n );\n\n const handleFocus = useCallback(\n (e) => {\n if (multiline) {\n const textarea = e.target;\n const length = textarea.value.length;\n textarea.setSelectionRange(length, length);\n }\n },\n [multiline]\n );\n\n const handleKeyDown = useCallback(\n (e) => {\n if (e.key === \"Enter\" && !multiline) {\n e.target.blur();\n }\n if (\n e.key === \"Enter\" &&\n multiline &&\n submitOnMetaEnter &&\n (e.metaKey || e.ctrlKey)\n ) {\n e.preventDefault();\n e.target.blur();\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n escapeRef.current = true;\n e.target.blur();\n typeof onCancel === \"function\" && onCancel(e);\n }\n },\n [onCancel, multiline, submitOnMetaEnter]\n );\n\n const handleChange = useCallback((e) => {\n setCurrentValue(e.target.value);\n }, []);\n\n if (multiline) {\n return (\n <StyledDiv ref={ref || wrapRef} {...props} $multiline={multiline}>\n <StyledMultilineSpan\n variant={variant}\n forwardedAs=\"span\"\n weight={weight}\n $disabled={disabled}\n invalid={invalid}\n className=\"presentation\"\n onClick={() => {\n if (!disabled && intTextareaRef.current) {\n intTextareaRef.current.focus();\n }\n }}\n >\n {children\n ? children\n : String(currentValue || \"\").replace(/\\n/g, \" \")}\n </StyledMultilineSpan>\n <StyledTextareaSpan\n ref={intTextareaRef}\n forwardedAs=\"textarea\"\n variant={variant}\n weight={weight}\n value={currentValue ?? \"\"}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n disabled={disabled}\n invalid={invalid}\n data-form-type=\"other\"\n placeholder={inputProps?.placeholder}\n className={classNames(\"c-textarea\", inputProps?.className)}\n rows={3}\n {...inputProps}\n />\n </StyledDiv>\n );\n }\n\n return (\n <EditableContent\n {...props}\n variant={variant}\n weight={weight}\n disabled={disabled}\n invalid={invalid}\n wrapRef={wrapRef}\n ref={ref}\n inputProps={{\n ...inputProps,\n value: currentValue ?? \"\",\n onBlur: handleBlur,\n onKeyDown: handleKeyDown,\n onChange: handleChange,\n type: \"text\",\n className: classNames(\"c-input\", inputProps?.className),\n }}\n >\n {children}\n </EditableContent>\n );\n }\n);\n\nEditableText.displayName = \"EditableText\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAEVC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,eAAe,QAEV,oCAAoC;AAC3C,SACEC,SAAS,EACTC,mBAAmB,EACnBC,kBAAkB,QACb,2BAA2B;AAmBlC,OAAO,MAAMC,YAAY,gBAAGV,UAAU,CACpC,CAAAW,IAAA,EAiBEC,GAAG,KACA;EAAA,IAhBDC,MAAM,GAAAF,IAAA,CAANE,MAAM;IACNC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,KAAK,GAAAJ,IAAA,CAALI,KAAK;IACLC,UAAU,GAAAL,IAAA,CAAVK,UAAU;IACVC,gBAAgB,GAAAN,IAAA,CAAhBM,gBAAgB;IAAAC,cAAA,GAAAP,IAAA,CAChBQ,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,KAAK,GAAAA,cAAA;IAAAE,qBAAA,GAAAT,IAAA,CACjBU,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA;IAAAE,YAAA,GAAAX,IAAA,CACzBY,OAAO;IAAPA,OAAO,GAAAD,YAAA,cAAG,QAAQ,GAAAA,YAAA;IAClBE,MAAM,GAAAb,IAAA,CAANa,MAAM;IAAAC,aAAA,GAAAd,IAAA,CACNe,QAAQ;IAARA,QAAQ,GAAAD,aAAA,cAAG,KAAK,GAAAA,aAAA;IAChBE,OAAO,GAAAhB,IAAA,CAA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AAErB,WAAY;MACrBsB,MAAM,EAAE7B,UAAW;MACnB8B,SAAS,EAAEpB,aAAc;MACzBqB,QAAQ,EAAEd,YAAa;MACvBhC,QAAQ,EAAEA,QAAS;MACnBC,OAAO,EAAEA,OAAQ;MACjB,kBAAe,OAAO;MACtB8C,WAAW,EAAEzD,UAAU,oBAAVA,UAAU,CAAEyD,WAAY;MACrCT,SAAS,EAAE3D,UAAU,CAAC,YAAY,EAAEW,UAAU,oBAAVA,UAAU,CAAEgD,SAAS,CAAE;MAC3DU,IAAI,EAAE;IAAE,GACJ1D,UAAU,CACf,CACQ,CAAC;EAEhB;EAEA,oBACEjB,KAAA,CAAA4D,aAAA,CAACrD,eAAe,EAAAsD,QAAA,KACV9B,KAAK;IACTP,OAAO,EAAEA,OAAQ;IACjBC,MAAM,EAAEA,MAAO;IACfE,QAAQ,EAAEA,QAAS;IACnBC,OAAO,EAAEA,OAAQ;IACjBC,OAAO,EAAEA,OAAQ;IACjBhB,GAAG,EAAEA,GAAI;IACTI,UAAU,EAAA4C,QAAA,KACL5C,UAAU;MACbD,KAAK,EAAEmB,YAAY,WAAZA,YAAY,GAAI,EAAE;MACzBoC,MAAM,EAAE7B,UAAU;MAClB8B,SAAS,EAAEpB,aAAa;MACxBqB,QAAQ,EAAEd,YAAY;MACtBiB,IAAI,EAAE,MAAM;MACZX,SAAS,EAAE3D,UAAU,CAAC,SAAS,EAAEW,UAAU,oBAAVA,UAAU,CAAEgD,SAAS;IAAC;EACvD,IAEDnC,QACc,CAAC;AAEtB,CACF,CAAC;AAEDnB,YAAY,CAACkE,WAAW,GAAG,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"EditableText.js","names":["React","forwardRef","useCallback","useRef","classNames","useEditableText","EditableContent","StyledDiv","StyledMultilineSpan","StyledTextareaSpan","StyledWrapRoot","StyledWrapSpan","StyledWrapTextarea","useHoverSuppression","EditableText","_ref","ref","onSave","onCancel","value","inputProps","allowEmptyString","_ref$multiline","multiline","_ref$submitOnMetaEnte","submitOnMetaEnter","_ref$wrap","wrap","_ref$variant","variant","weight","_ref$disabled","disabled","invalid","wrapRef","children","props","_objectWithoutPropertiesLoose","_excluded","mode","_useEditableText","currentValue","handleBlur","handleKeyDown","handleChange","_useHoverSuppression","hoverSuppressed","suppressHoverOnKey","releaseHover","intTextareaRef","handleFocus","e","textarea","target","length","setSelectionRange","handleWrapKeyDown","_ref2","onMouseLeave","wrapProps","_excluded2","handleWrapMouseLeave","text","String","createElement","_extends","forwardedAs","$disabled","className","undefined","placeholder","rows","onFocus","onBlur","onKeyDown","onChange","$multiline","onClick","current","focus","replace","type","displayName"],"sources":["../../../../src/components/EditableText/EditableText.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n forwardRef,\n Ref,\n useCallback,\n useRef,\n} from \"react\";\n\nimport classNames from \"classnames\";\n\nimport { useEditableText } from \"./useEditableText\";\nimport {\n EditableContent,\n EditableContentInterface,\n} from \"../EditableContent/EditableContent\";\nimport {\n StyledDiv,\n StyledMultilineSpan,\n StyledTextareaSpan,\n StyledWrapRoot,\n StyledWrapSpan,\n StyledWrapTextarea,\n} from \"../EditableContent/Styles\";\nimport { useHoverSuppression } from \"../EditableContent/useHoverSuppression\";\n\nexport interface EditableTextInterface extends EditableContentInterface {\n /** Value to display. */\n value?: string | null;\n /** Optional callback called on enter, click outside and tab. */\n onSave?: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n /** Optional callback called on input reset. */\n onCancel?: (e) => void;\n /** If true, setting empty value will save it, instead of revert to previous value. */\n allowEmptyString?: boolean;\n /** If true, shows a textarea instead of input for multiline editing. */\n multiline?: boolean;\n /** If true, Cmd/Ctrl+Enter commits a multiline edit (plain Enter keeps inserting a newline). */\n submitOnMetaEnter?: boolean;\n /** If true, the field is as wide as its text, wraps at the container width and grows down. Enter commits, the value never holds a line break. */\n wrap?: boolean;\n /** Children content to display */\n children?: React.ReactNode;\n}\n\nexport const EditableText = forwardRef<HTMLDivElement, EditableTextInterface>(\n (\n {\n onSave,\n onCancel,\n value,\n inputProps,\n allowEmptyString,\n multiline = false,\n submitOnMetaEnter = false,\n wrap = false,\n variant = \"Body 2\",\n weight,\n disabled = false,\n invalid,\n wrapRef,\n children,\n ...props\n },\n ref\n ) => {\n const mode = wrap ? \"wrap\" : multiline ? \"multiline\" : \"single\";\n const { currentValue, handleBlur, handleKeyDown, handleChange } =\n useEditableText({\n value,\n onSave,\n onCancel,\n allowEmptyString,\n submitOnMetaEnter,\n mode,\n });\n const { hoverSuppressed, suppressHoverOnKey, releaseHover } =\n useHoverSuppression();\n const intTextareaRef = useRef<HTMLTextAreaElement>(null);\n\n const handleFocus = useCallback(\n (e) => {\n if (multiline) {\n const textarea = e.target;\n const length = textarea.value.length;\n textarea.setSelectionRange(length, length);\n }\n },\n [multiline]\n );\n\n const handleWrapKeyDown = useCallback(\n (e) => {\n suppressHoverOnKey(e);\n handleKeyDown(e);\n },\n [handleKeyDown, suppressHoverOnKey]\n );\n\n const { onMouseLeave, ...wrapProps } =\n props as React.ComponentPropsWithoutRef<\"span\">;\n\n const handleWrapMouseLeave = useCallback(\n (e) => {\n releaseHover();\n typeof onMouseLeave === \"function\" && onMouseLeave(e);\n },\n [onMouseLeave, releaseHover]\n );\n\n if (wrap) {\n const text = String(currentValue ?? \"\");\n\n return (\n <StyledWrapRoot\n ref={(ref || wrapRef) as Ref<HTMLSpanElement>}\n {...wrapProps}\n onMouseLeave={handleWrapMouseLeave}\n >\n <StyledWrapSpan\n variant={variant}\n forwardedAs=\"span\"\n weight={weight}\n $disabled={disabled}\n className=\"presentation\"\n aria-hidden={disabled ? undefined : true}\n >\n {children\n ? children\n : `${text || (!disabled && inputProps?.placeholder) || \"\"} `}\n </StyledWrapSpan>\n <StyledWrapTextarea\n {...inputProps}\n ref={intTextareaRef}\n forwardedAs=\"textarea\"\n variant={variant}\n weight={weight}\n rows={1}\n value={text}\n onFocus={releaseHover}\n onBlur={handleBlur}\n onKeyDown={handleWrapKeyDown}\n onChange={handleChange}\n disabled={disabled}\n invalid={invalid}\n data-form-type=\"other\"\n data-hover-suppressed={hoverSuppressed}\n className={classNames(\"c-textarea\", inputProps?.className)}\n />\n </StyledWrapRoot>\n );\n }\n\n if (multiline) {\n return (\n <StyledDiv ref={ref || wrapRef} {...props} $multiline={multiline}>\n <StyledMultilineSpan\n variant={variant}\n forwardedAs=\"span\"\n weight={weight}\n $disabled={disabled}\n invalid={invalid}\n className=\"presentation\"\n onClick={() => {\n if (!disabled && intTextareaRef.current) {\n intTextareaRef.current.focus();\n }\n }}\n >\n {children\n ? children\n : String(currentValue || \"\").replace(/\\n/g, \" \")}\n </StyledMultilineSpan>\n <StyledTextareaSpan\n ref={intTextareaRef}\n forwardedAs=\"textarea\"\n variant={variant}\n weight={weight}\n value={currentValue ?? \"\"}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n disabled={disabled}\n invalid={invalid}\n data-form-type=\"other\"\n placeholder={inputProps?.placeholder}\n className={classNames(\"c-textarea\", inputProps?.className)}\n rows={3}\n {...inputProps}\n />\n </StyledDiv>\n );\n }\n\n return (\n <EditableContent\n {...props}\n variant={variant}\n weight={weight}\n disabled={disabled}\n invalid={invalid}\n wrapRef={wrapRef}\n ref={ref}\n inputProps={{\n ...inputProps,\n value: currentValue ?? \"\",\n onBlur: handleBlur,\n onKeyDown: handleKeyDown,\n onChange: handleChange,\n type: \"text\",\n className: classNames(\"c-input\", inputProps?.className),\n }}\n >\n {children}\n </EditableContent>\n );\n }\n);\n\nEditableText.displayName = \"EditableText\";\n"],"mappings":";;;;AAAA,OAAOA,KAAK,IAEVC,UAAU,EAEVC,WAAW,EACXC,MAAM,QACD,OAAO;AAEd,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SACEC,eAAe,QAEV,oCAAoC;AAC3C,SACEC,SAAS,EACTC,mBAAmB,EACnBC,kBAAkB,EAClBC,cAAc,EACdC,cAAc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EA,oBACEpB,KAAA,CAAAgE,aAAA,CAAC1D,eAAe,EAAA2D,QAAA,KACV7B,KAAK;IACTP,OAAO,EAAEA,OAAQ;IACjBC,MAAM,EAAEA,MAAO;IACfE,QAAQ,EAAEA,QAAS;IACnBC,OAAO,EAAEA,OAAQ;IACjBC,OAAO,EAAEA,OAAQ;IACjBlB,GAAG,EAAEA,GAAI;IACTI,UAAU,EAAA6C,QAAA,KACL7C,UAAU;MACbD,KAAK,EAAEsB,YAAY,WAAZA,YAAY,GAAI,EAAE;MACzBgC,MAAM,EAAE/B,UAAU;MAClBgC,SAAS,EAAE/B,aAAa;MACxBgC,QAAQ,EAAE/B,YAAY;MACtBqC,IAAI,EAAE,MAAM;MACZb,SAAS,EAAEhE,UAAU,CAAC,SAAS,EAAEgB,UAAU,oBAAVA,UAAU,CAAEgD,SAAS;IAAC;EACvD,IAEDjC,QACc,CAAC;AAEtB,CACF,CAAC;AAEDrB,YAAY,CAACoE,WAAW,GAAG,cAAc","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import { ChangeEvent } from "react";
2
+ export type EditableTextMode = "single" | "multiline" | "wrap";
3
+ interface UseEditableTextArgs {
4
+ value?: string | null;
5
+ onSave?: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
6
+ onCancel?: (e: any) => void;
7
+ allowEmptyString?: boolean;
8
+ submitOnMetaEnter?: boolean;
9
+ mode: EditableTextMode;
10
+ }
11
+ export declare const useEditableText: ({ value, onSave, onCancel, allowEmptyString, submitOnMetaEnter, mode, }: UseEditableTextArgs) => {
12
+ currentValue: string | null | undefined;
13
+ handleBlur: (e: any) => void;
14
+ handleKeyDown: (e: any) => void;
15
+ handleChange: (e: any) => void;
16
+ };
17
+ export {};
18
+ //# sourceMappingURL=useEditableText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditableText.d.ts","sourceRoot":"","sources":["../../../../src/components/EditableText/useEditableText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4C,MAAM,OAAO,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAE/D,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,IAAI,CAAC;IAC1E,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAA,KAAK,IAAI,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAID,eAAO,MAAM,eAAe,GAAI,yEAO7B,mBAAmB;;;;;CA+ErB,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ const withoutLineBreaks = text => text.replace(/\s*[\r\n]+\s*/g, " ");
3
+ export const useEditableText = _ref => {
4
+ let value = _ref.value,
5
+ onSave = _ref.onSave,
6
+ onCancel = _ref.onCancel,
7
+ allowEmptyString = _ref.allowEmptyString,
8
+ _ref$submitOnMetaEnte = _ref.submitOnMetaEnter,
9
+ submitOnMetaEnter = _ref$submitOnMetaEnte === void 0 ? false : _ref$submitOnMetaEnte,
10
+ mode = _ref.mode;
11
+ const _useState = useState(value),
12
+ currentValue = _useState[0],
13
+ setCurrentValue = _useState[1];
14
+ const _useState2 = useState(value),
15
+ prevValue = _useState2[0],
16
+ setPrevValue = _useState2[1];
17
+ const escapeRef = useRef(false);
18
+ const multiline = mode === "multiline";
19
+ useEffect(() => {
20
+ if (currentValue !== value) {
21
+ setCurrentValue(value);
22
+ setPrevValue(value);
23
+ }
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
+ }, [value]);
26
+ const handleBlur = useCallback(e => {
27
+ if (escapeRef.current) {
28
+ setCurrentValue(prevValue);
29
+ escapeRef.current = false;
30
+ } else {
31
+ if (e.target.value.trim().length > 0 && prevValue !== e.target.value) {
32
+ setPrevValue(e.target.value);
33
+ setCurrentValue(e.target.value);
34
+ typeof onSave === "function" && onSave(e);
35
+ } else {
36
+ !allowEmptyString ? setCurrentValue(prevValue) : typeof onSave === "function" && prevValue !== e.target.value && onSave(e);
37
+ }
38
+ }
39
+ if (mode !== "single") {
40
+ e.target.scrollLeft = 0;
41
+ }
42
+ if (mode === "wrap") {
43
+ e.target.scrollTop = 0;
44
+ }
45
+ }, [allowEmptyString, onSave, prevValue, mode]);
46
+ const handleKeyDown = useCallback(e => {
47
+ if (e.key === "Enter" && !multiline) {
48
+ // A textarea must not get the line break.
49
+ mode === "wrap" && e.preventDefault();
50
+ e.target.blur();
51
+ }
52
+ if (e.key === "Enter" && multiline && submitOnMetaEnter && (e.metaKey || e.ctrlKey)) {
53
+ e.preventDefault();
54
+ e.target.blur();
55
+ }
56
+ if (e.key === "Escape") {
57
+ e.preventDefault();
58
+ e.stopPropagation();
59
+ escapeRef.current = true;
60
+ e.target.blur();
61
+ typeof onCancel === "function" && onCancel(e);
62
+ }
63
+ }, [onCancel, multiline, mode, submitOnMetaEnter]);
64
+ const handleChange = useCallback(e => {
65
+ setCurrentValue(mode === "wrap" ? withoutLineBreaks(e.target.value) : e.target.value);
66
+ }, [mode]);
67
+ return {
68
+ currentValue,
69
+ handleBlur,
70
+ handleKeyDown,
71
+ handleChange
72
+ };
73
+ };
74
+ //# sourceMappingURL=useEditableText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditableText.js","names":["useCallback","useEffect","useRef","useState","withoutLineBreaks","text","replace","useEditableText","_ref","value","onSave","onCancel","allowEmptyString","_ref$submitOnMetaEnte","submitOnMetaEnter","mode","_useState","currentValue","setCurrentValue","_useState2","prevValue","setPrevValue","escapeRef","multiline","handleBlur","e","current","target","trim","length","scrollLeft","scrollTop","handleKeyDown","key","preventDefault","blur","metaKey","ctrlKey","stopPropagation","handleChange"],"sources":["../../../../src/components/EditableText/useEditableText.ts"],"sourcesContent":["import { ChangeEvent, useCallback, useEffect, useRef, useState } from \"react\";\n\nexport type EditableTextMode = \"single\" | \"multiline\" | \"wrap\";\n\ninterface UseEditableTextArgs {\n value?: string | null;\n onSave?: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n onCancel?: (e) => void;\n allowEmptyString?: boolean;\n submitOnMetaEnter?: boolean;\n mode: EditableTextMode;\n}\n\nconst withoutLineBreaks = (text: string) => text.replace(/\\s*[\\r\\n]+\\s*/g, \" \");\n\nexport const useEditableText = ({\n value,\n onSave,\n onCancel,\n allowEmptyString,\n submitOnMetaEnter = false,\n mode,\n}: UseEditableTextArgs) => {\n const [currentValue, setCurrentValue] = useState(value);\n const [prevValue, setPrevValue] = useState(value);\n const escapeRef = useRef(false);\n const multiline = mode === \"multiline\";\n\n useEffect(() => {\n if (currentValue !== value) {\n setCurrentValue(value);\n setPrevValue(value);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value]);\n\n const handleBlur = useCallback(\n (e) => {\n if (escapeRef.current) {\n setCurrentValue(prevValue);\n escapeRef.current = false;\n } else {\n if (e.target.value.trim().length > 0 && prevValue !== e.target.value) {\n setPrevValue(e.target.value);\n setCurrentValue(e.target.value);\n typeof onSave === \"function\" && onSave(e);\n } else {\n !allowEmptyString\n ? setCurrentValue(prevValue)\n : typeof onSave === \"function\" &&\n prevValue !== e.target.value &&\n onSave(e);\n }\n }\n if (mode !== \"single\") {\n e.target.scrollLeft = 0;\n }\n if (mode === \"wrap\") {\n e.target.scrollTop = 0;\n }\n },\n [allowEmptyString, onSave, prevValue, mode]\n );\n\n const handleKeyDown = useCallback(\n (e) => {\n if (e.key === \"Enter\" && !multiline) {\n // A textarea must not get the line break.\n mode === \"wrap\" && e.preventDefault();\n e.target.blur();\n }\n if (\n e.key === \"Enter\" &&\n multiline &&\n submitOnMetaEnter &&\n (e.metaKey || e.ctrlKey)\n ) {\n e.preventDefault();\n e.target.blur();\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n escapeRef.current = true;\n e.target.blur();\n typeof onCancel === \"function\" && onCancel(e);\n }\n },\n [onCancel, multiline, mode, submitOnMetaEnter]\n );\n\n const handleChange = useCallback(\n (e) => {\n setCurrentValue(\n mode === \"wrap\" ? withoutLineBreaks(e.target.value) : e.target.value\n );\n },\n [mode]\n );\n\n return { currentValue, handleBlur, handleKeyDown, handleChange };\n};\n"],"mappings":"AAAA,SAAsBA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAa7E,MAAMC,iBAAiB,GAAIC,IAAY,IAAKA,IAAI,CAACC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;AAE/E,OAAO,MAAMC,eAAe,GAAGC,IAAA,IAOJ;EAAA,IANzBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IACLC,MAAM,GAAAF,IAAA,CAANE,MAAM;IACNC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,gBAAgB,GAAAJ,IAAA,CAAhBI,gBAAgB;IAAAC,qBAAA,GAAAL,IAAA,CAChBM,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA;IACzBE,IAAI,GAAAP,IAAA,CAAJO,IAAI;EAEJ,MAAAC,SAAA,GAAwCb,QAAQ,CAACM,KAAK,CAAC;IAAhDQ,YAAY,GAAAD,SAAA;IAAEE,eAAe,GAAAF,SAAA;EACpC,MAAAG,UAAA,GAAkChB,QAAQ,CAACM,KAAK,CAAC;IAA1CW,SAAS,GAAAD,UAAA;IAAEE,YAAY,GAAAF,UAAA;EAC9B,MAAMG,SAAS,GAAGpB,MAAM,CAAC,KAAK,CAAC;EAC/B,MAAMqB,SAAS,GAAGR,IAAI,KAAK,WAAW;EAEtCd,SAAS,CAAC,MAAM;IACd,IAAIgB,YAAY,KAAKR,KAAK,EAAE;MAC1BS,eAAe,CA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CAAC,CAACS,cAAc,CAAC,CAAC;MACrCT,CAAC,CAACE,MAAM,CAACQ,IAAI,CAAC,CAAC;IACjB;IACA,IACEV,CAAC,CAACQ,GAAG,KAAK,OAAO,IACjBV,SAAS,IACTT,iBAAiB,KAChBW,CAAC,CAACW,OAAO,IAAIX,CAAC,CAACY,OAAO,CAAC,EACxB;MACAZ,CAAC,CAACS,cAAc,CAAC,CAAC;MAClBT,CAAC,CAACE,MAAM,CAACQ,IAAI,CAAC,CAAC;IACjB;IACA,IAAIV,CAAC,CAACQ,GAAG,KAAK,QAAQ,EAAE;MACtBR,CAAC,CAACS,cAAc,CAAC,CAAC;MAClBT,CAAC,CAACa,eAAe,CAAC,CAAC;MACnBhB,SAAS,CAACI,OAAO,GAAG,IAAI;MACxBD,CAAC,CAACE,MAAM,CAACQ,IAAI,CAAC,CAAC;MACf,OAAOxB,QAAQ,KAAK,UAAU,IAAIA,QAAQ,CAACc,CAAC,CAAC;IAC/C;EACF,CAAC,EACD,CAACd,QAAQ,EAAEY,SAAS,EAAER,IAAI,EAAED,iBAAiB,CAC/C,CAAC;EAED,MAAMyB,YAAY,GAAGvC,WAAW,CAC7ByB,CAAC,IAAK;IACLP,eAAe,CACbH,IAAI,KAAK,MAAM,GAAGX,iBAAiB,CAACqB,CAAC,CAACE,MAAM,CAAClB,KAAK,CAAC,GAAGgB,CAAC,CAACE,MAAM,CAAClB,KACjE,CAAC;EACH,CAAC,EACD,CAACM,IAAI,CACP,CAAC;EAED,OAAO;IAAEE,YAAY;IAAEO,UAAU;IAAEQ,aAAa;IAAEO;EAAa,CAAC;AAClE,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"EmptySlate.d.ts","sourceRoot":"","sources":["../../../../src/components/EmptySlate/EmptySlate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAW9C,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,UAAU;0DAOpB,eAAe;;;;;;;;;CAkBjB,CAAC"}
1
+ {"version":3,"file":"EmptySlate.d.ts","sourceRoot":"","sources":["../../../../src/components/EmptySlate/EmptySlate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,cAAc,EAKf,MAAM,OAAO,CAAC;AAWf,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,eAAO,MAAM,UAAU;0DAOpB,eAAe;;;;;;;;;CAmCjB,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["title", "description", "src", "alt", "children"];
4
- import React from "react";
4
+ import React, { useCallback, useLayoutEffect, useRef, useState } from "react";
5
5
  import { Container, Description, SubContainer, Title, StyledImg } from "./EmptySlate.styles";
6
6
  import { EmptySlateFooter } from "./EmptySlateFooter";
7
+ const isAlreadyLoaded = image => !!image && image.complete && image.naturalWidth > 0;
7
8
  export const EmptySlate = _ref => {
8
9
  let title = _ref.title,
9
10
  description = _ref.description,
@@ -11,11 +12,24 @@ export const EmptySlate = _ref => {
11
12
  alt = _ref.alt,
12
13
  children = _ref.children,
13
14
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
15
+ const imageRef = useRef(null);
16
+ const _useState = useState(),
17
+ loadedSrc = _useState[0],
18
+ setLoadedSrc = _useState[1];
19
+ const markLoaded = useCallback(() => setLoadedSrc(src), [src]);
20
+ useLayoutEffect(() => {
21
+ if (isAlreadyLoaded(imageRef.current)) {
22
+ markLoaded();
23
+ }
24
+ }, [markLoaded]);
14
25
  return /*#__PURE__*/React.createElement(Container, _extends({}, rest, {
15
26
  role: "status"
16
27
  }), /*#__PURE__*/React.createElement(StyledImg, {
28
+ ref: imageRef,
17
29
  src: src,
18
- alt: alt
30
+ alt: alt,
31
+ onLoad: markLoaded,
32
+ $loaded: loadedSrc === src
19
33
  }), /*#__PURE__*/React.createElement(SubContainer, null, /*#__PURE__*/React.createElement(Title, {
20
34
  weight: "light",
21
35
  variant: "Title 1"
@@ -1 +1 @@
1
- {"version":3,"file":"EmptySlate.js","names":["React","Container","Description","SubContainer","Title","StyledImg","EmptySlateFooter","EmptySlate","_ref","title","description","src","alt","children","rest","_objectWithoutPropertiesLoose","_excluded","createElement","_extends","role","weight","variant","color","Footer","displayName"],"sources":["../../../../src/components/EmptySlate/EmptySlate.tsx"],"sourcesContent":["import React, { HTMLAttributes } from \"react\";\n\nimport {\n Container,\n Description,\n SubContainer,\n Title,\n StyledImg,\n} from \"./EmptySlate.styles\";\nimport { EmptySlateFooter } from \"./EmptySlateFooter\";\n\nexport interface EmptySlateProps extends HTMLAttributes<HTMLDivElement> {\n src: string;\n alt: string;\n title: string;\n description?: string;\n}\n\nexport const EmptySlate = ({\n title,\n description,\n src,\n alt,\n children,\n ...rest\n}: EmptySlateProps) => {\n return (\n <Container {...rest} role=\"status\">\n <StyledImg src={src} alt={alt} />\n <SubContainer>\n <Title weight=\"light\" variant=\"Title 1\">\n {title}\n </Title>\n {description && (\n <Description color=\"tertiary\" variant=\"Body 1\">\n {description}\n </Description>\n )}\n\n {children}\n </SubContainer>\n </Container>\n );\n};\n\nEmptySlate.Footer = EmptySlateFooter;\n\nEmptySlate.displayName = \"EmptySlate\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAA0B,OAAO;AAE7C,SACEC,SAAS,EACTC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,SAAS,QACJ,qBAAqB;AAC5B,SAASC,gBAAgB,QAAQ,oBAAoB;AASrD,OAAO,MAAMC,UAAU,GAAGC,IAAA,IAOH;EAAA,IANrBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IACLC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IACXC,GAAG,GAAAH,IAAA,CAAHG,GAAG;IACHC,GAAG,GAAAJ,IAAA,CAAHI,GAAG;IACHC,QAAQ,GAAAL,IAAA,CAARK,QAAQ;IACLC,IAAI,GAAAC,6BAAA,CAAAP,IAAA,EAAAQ,SAAA;EAEP,oBACEhB,KAAA,CAAAiB,aAAA,CAAChB,SAAS,EAAAiB,QAAA,KAAKJ,IAAI;IAAEK,IAAI,EAAC;EAAQ,iBAChCnB,KAAA,CAAAiB,aAAA,CAACZ,SAAS;IAACM,GAAG,EAAEA,GAAI;IAACC,GAAG,EAAEA;EAAI,CAAE,CAAC,eACjCZ,KAAA,CAAAiB,aAAA,CAACd,YAAY,qBACXH,KAAA,CAAAiB,aAAA,CAACb,KAAK;IAACgB,MAAM,EAAC,OAAO;IAACC,OAAO,EAAC;EAAS,GACpCZ,KACI,CAAC,EACPC,WAAW,iBACVV,KAAA,CAAAiB,aAAA,CAACf,WAAW;IAACoB,KAAK,EAAC,UAAU;IAACD,OAAO,EAAC;EAAQ,GAC3CX,WACU,CACd,EAEAG,QACW,CACL,CAAC;AAEhB,CAAC;AAEDN,UAAU,CAACgB,MAAM,GAAGjB,gBAAgB;AAEpCC,UAAU,CAACiB,WAAW,GAAG,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"EmptySlate.js","names":["React","useCallback","useLayoutEffect","useRef","useState","Container","Description","SubContainer","Title","StyledImg","EmptySlateFooter","isAlreadyLoaded","image","complete","naturalWidth","EmptySlate","_ref","title","description","src","alt","children","rest","_objectWithoutPropertiesLoose","_excluded","imageRef","_useState","loadedSrc","setLoadedSrc","markLoaded","current","createElement","_extends","role","ref","onLoad","$loaded","weight","variant","color","Footer","displayName"],"sources":["../../../../src/components/EmptySlate/EmptySlate.tsx"],"sourcesContent":["import React, {\n HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\nimport {\n Container,\n Description,\n SubContainer,\n Title,\n StyledImg,\n} from \"./EmptySlate.styles\";\nimport { EmptySlateFooter } from \"./EmptySlateFooter\";\n\nexport interface EmptySlateProps extends HTMLAttributes<HTMLDivElement> {\n src: string;\n alt: string;\n title: string;\n description?: string;\n}\n\nconst isAlreadyLoaded = (image: HTMLImageElement | null) =>\n !!image && image.complete && image.naturalWidth > 0;\n\nexport const EmptySlate = ({\n title,\n description,\n src,\n alt,\n children,\n ...rest\n}: EmptySlateProps) => {\n const imageRef = useRef<HTMLImageElement>(null);\n const [loadedSrc, setLoadedSrc] = useState<string>();\n\n const markLoaded = useCallback(() => setLoadedSrc(src), [src]);\n\n useLayoutEffect(() => {\n if (isAlreadyLoaded(imageRef.current)) {\n markLoaded();\n }\n }, [markLoaded]);\n\n return (\n <Container {...rest} role=\"status\">\n <StyledImg\n ref={imageRef}\n src={src}\n alt={alt}\n onLoad={markLoaded}\n $loaded={loadedSrc === src}\n />\n <SubContainer>\n <Title weight=\"light\" variant=\"Title 1\">\n {title}\n </Title>\n {description && (\n <Description color=\"tertiary\" variant=\"Body 1\">\n {description}\n </Description>\n )}\n\n {children}\n </SubContainer>\n </Container>\n );\n};\n\nEmptySlate.Footer = EmptySlateFooter;\n\nEmptySlate.displayName = \"EmptySlate\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAEVC,WAAW,EACXC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SACEC,SAAS,EACTC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,SAAS,QACJ,qBAAqB;AAC5B,SAASC,gBAAgB,QAAQ,oBAAoB;AASrD,MAAMC,eAAe,GAAIC,KAA8B,IACrD,CAAC,CAACA,KAAK,IAAIA,KAAK,CAACC,QAAQ,IA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AAA+B,aAAA,CAACzB,WAAW;IAACiC,KAAK,EAAC,UAAU;IAACD,OAAO,EAAC;EAAQ,GAC3CpB,WACU,CACd,EAEAG,QACW,CACL,CAAC;AAEhB,CAAC;AAEDN,UAAU,CAACyB,MAAM,GAAG9B,gBAAgB;AAEpCK,UAAU,CAAC0B,WAAW,GAAG,YAAY","ignoreList":[]}
@@ -1,6 +1,8 @@
1
1
  export declare const Container: import("styled-components").StyledComponent<"div", any, {}, never>;
2
2
  export declare const SubContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
3
- export declare const StyledImg: import("styled-components").StyledComponent<"img", any, {}, never>;
3
+ export declare const StyledImg: import("styled-components").StyledComponent<"img", any, {
4
+ $loaded: boolean;
5
+ }, never>;
4
6
  export declare const Title: import("styled-components").StyledComponent<import("../Typography/Typography").TypographyComponent & {
5
7
  displayName?: string;
6
8
  }, any, {}, never>;
@@ -1 +1 @@
1
- {"version":3,"file":"EmptySlate.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/EmptySlate/EmptySlate.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,oEAWrB,CAAC;AAEF,eAAO,MAAM,YAAY,oEAYxB,CAAC;AAEF,eAAO,MAAM,SAAS,oEAGrB,CAAC;AAEF,eAAO,MAAM,KAAK;;kBAOjB,CAAC;AAEF,eAAO,MAAM,WAAW;;kBAMvB,CAAC;AAEF,eAAO,MAAM,eAAe,oEAU3B,CAAC"}
1
+ {"version":3,"file":"EmptySlate.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/EmptySlate/EmptySlate.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,oEAWrB,CAAC;AAEF,eAAO,MAAM,YAAY,oEAYxB,CAAC;AAEF,eAAO,MAAM,SAAS;aAAyB,OAAO;SAIrD,CAAC;AAEF,eAAO,MAAM,KAAK;;kBAOjB,CAAC;AAEF,eAAO,MAAM,WAAW;;kBAMvB,CAAC;AAEF,eAAO,MAAM,eAAe,oEAU3B,CAAC"}
@@ -12,7 +12,10 @@ export const SubContainer = styled.div.withConfig({
12
12
  export const StyledImg = styled.img.withConfig({
13
13
  displayName: "EmptySlatestyles__StyledImg",
14
14
  componentId: "sc-jfbqky-2"
15
- })(["width:280px;height:280px;"]);
15
+ })(["width:280px;height:280px;visibility:", ";"], _ref => {
16
+ let $loaded = _ref.$loaded;
17
+ return $loaded ? "visible" : "hidden";
18
+ });
16
19
  export const Title = styled(Typography).withConfig({
17
20
  displayName: "EmptySlatestyles__Title",
18
21
  componentId: "sc-jfbqky-3"
@@ -1 +1 @@
1
- {"version":3,"file":"EmptySlate.styles.js","names":["styled","screen","Typography","Container","div","withConfig","displayName","componentId","lg","SubContainer","StyledImg","img","Title","Description","FooterContainer"],"sources":["../../../../src/components/EmptySlate/EmptySlate.styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { screen } from \"../BreakPoints\";\nimport { Typography } from \"../Typography/Typography\";\n\nexport const Container = styled.div`\n display: flex;\n align-items: center;\n flex-direction: column;\n justify-content: center;\n text-align: center;\n gap: 24px;\n\n ${screen.lg} {\n flex-direction: row;\n }\n`;\n\nexport const SubContainer = styled.div`\n display: flex;\n align-items: center;\n flex-direction: column;\n justify-content: center;\n max-width: 400px;\n padding-left: 20px;\n padding-right: 20px;\n\n ${screen.lg} {\n align-items: flex-start;\n }\n`;\n\nexport const StyledImg = styled.img`\n width: 280px;\n height: 280px;\n`;\n\nexport const Title = styled(Typography)`\n margin-block-end: 8px;\n text-align: center;\n\n ${screen.lg} {\n text-align: start;\n }\n`;\n\nexport const Description = styled(Typography)`\n text-align: center;\n\n ${screen.lg} {\n text-align: start;\n }\n`;\n\nexport const FooterContainer = styled.div`\n margin-block-start: 24px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n align-items: center;\n\n ${screen.lg} {\n flex-direction: row;\n }\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,UAAU,QAAQ,0BAA0B;AAErD,OAAO,MAAMC,SAAS,GAAGH,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,0IAQ/BN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMC,YAAY,GAAGT,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,wKASlCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAME,SAAS,GAAGV,MAAM,CAACW,GAAG,CAAAN,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,iCAGlC;AAED,OAAO,MAAMK,KAAK,GAAGZ,MAAM,CAACE,UAAU,CAAC,CAAAG,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,uEAInCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMK,WAAW,GAAGb,MAAM,CAACE,UAAU,CAAC,CAAAG,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,kDAGzCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMM,eAAe,GAAGd,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yHAOrCN,MAAM,CAACO,EAAE,CAGZ","ignoreList":[]}
1
+ {"version":3,"file":"EmptySlate.styles.js","names":["styled","screen","Typography","Container","div","withConfig","displayName","componentId","lg","SubContainer","StyledImg","img","_ref","$loaded","Title","Description","FooterContainer"],"sources":["../../../../src/components/EmptySlate/EmptySlate.styles.ts"],"sourcesContent":["import styled from \"styled-components\";\n\nimport { screen } from \"../BreakPoints\";\nimport { Typography } from \"../Typography/Typography\";\n\nexport const Container = styled.div`\n display: flex;\n align-items: center;\n flex-direction: column;\n justify-content: center;\n text-align: center;\n gap: 24px;\n\n ${screen.lg} {\n flex-direction: row;\n }\n`;\n\nexport const SubContainer = styled.div`\n display: flex;\n align-items: center;\n flex-direction: column;\n justify-content: center;\n max-width: 400px;\n padding-left: 20px;\n padding-right: 20px;\n\n ${screen.lg} {\n align-items: flex-start;\n }\n`;\n\nexport const StyledImg = styled.img<{ $loaded: boolean }>`\n width: 280px;\n height: 280px;\n visibility: ${({ $loaded }) => ($loaded ? \"visible\" : \"hidden\")};\n`;\n\nexport const Title = styled(Typography)`\n margin-block-end: 8px;\n text-align: center;\n\n ${screen.lg} {\n text-align: start;\n }\n`;\n\nexport const Description = styled(Typography)`\n text-align: center;\n\n ${screen.lg} {\n text-align: start;\n }\n`;\n\nexport const FooterContainer = styled.div`\n margin-block-start: 24px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n align-items: center;\n\n ${screen.lg} {\n flex-direction: row;\n }\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,UAAU,QAAQ,0BAA0B;AAErD,OAAO,MAAMC,SAAS,GAAGH,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,0IAQ/BN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMC,YAAY,GAAGT,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,wKASlCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAME,SAAS,GAAGV,MAAM,CAACW,GAAG,CAAAN,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,kDAGnBK,IAAA;EAAA,IAAGC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAAA,OAAQA,OAAO,GAAG,SAAS,GAAG,QAAQ;AAAA,CAAC,CAChE;AAED,OAAO,MAAMC,KAAK,GAAGd,MAAM,CAACE,UAAU,CAAC,CAAAG,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,uEAInCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMO,WAAW,GAAGf,MAAM,CAACE,UAAU,CAAC,CAAAG,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,kDAGzCN,MAAM,CAACO,EAAE,CAGZ;AAED,OAAO,MAAMQ,eAAe,GAAGhB,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yHAOrCN,MAAM,CAACO,EAAE,CAGZ","ignoreList":[]}
package/dist/index.js CHANGED
@@ -29649,6 +29649,42 @@
29649
29649
  return invalid && styled.css(["border-color:var(--red-alert) !important;"]);
29650
29650
  });
29651
29651
  StyledTextareaSpan.displayName = "StyledTextareaSpan";
29652
+ var StyledWrapRoot = styled__default["default"].span.withConfig({
29653
+ displayName: "Styles__StyledWrapRoot",
29654
+ componentId: "sc-1wapx2a-5"
29655
+ })(["", " ", " position:relative;display:inline-block;vertical-align:top;min-width:10px;max-width:100%;"], FontStyle, BoxSizingStyle);
29656
+ StyledWrapRoot.displayName = "StyledWrapRoot";
29657
+ var StyledWrapSpan = styled__default["default"](StyledSpan).withConfig({
29658
+ displayName: "Styles__StyledWrapSpan",
29659
+ componentId: "sc-1wapx2a-6"
29660
+ })(["overflow:visible;text-overflow:clip;white-space:pre-wrap;overflow-wrap:anywhere;"]);
29661
+ StyledWrapSpan.displayName = "StyledWrapSpan";
29662
+ var StyledWrapTextarea = styled__default["default"](StyledInput$2).withConfig({
29663
+ displayName: "Styles__StyledWrapTextarea",
29664
+ componentId: "sc-1wapx2a-7"
29665
+ })(["height:100%;margin:0;resize:none;white-space:pre-wrap;overflow-wrap:anywhere;&,&:focus-within{overflow:hidden;}"]);
29666
+ StyledWrapTextarea.displayName = "StyledWrapTextarea";
29667
+
29668
+ /** Holds back the hover look after Enter or Escape, until the pointer leaves or the field gets focus. */
29669
+ var useHoverSuppression = function useHoverSuppression() {
29670
+ var _useState = React.useState(false),
29671
+ _useState2 = _slicedToArray(_useState, 2),
29672
+ suppressHover = _useState2[0],
29673
+ setSuppressHover = _useState2[1];
29674
+ var suppressHoverOnKey = React.useCallback(function (evt) {
29675
+ if (evt.key === "Enter" || evt.key === "Escape") {
29676
+ setSuppressHover(true);
29677
+ }
29678
+ }, []);
29679
+ var releaseHover = React.useCallback(function () {
29680
+ return setSuppressHover(false);
29681
+ }, []);
29682
+ return {
29683
+ hoverSuppressed: suppressHover ? "" : undefined,
29684
+ suppressHoverOnKey,
29685
+ releaseHover
29686
+ };
29687
+ };
29652
29688
 
29653
29689
  var _excluded$k = ["className", "variant", "weight", "disabled", "inputProps", "wrapRef", "children", "invalid", "onMouseLeave"];
29654
29690
  var EditableContent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
@@ -29666,10 +29702,10 @@
29666
29702
  props = _objectWithoutProperties(_ref, _excluded$k);
29667
29703
  var intInputRef = React.useRef(null);
29668
29704
  var handleRef = useForkRef(ref, intInputRef);
29669
- var _useState = React.useState(false),
29670
- _useState2 = _slicedToArray(_useState, 2),
29671
- suppressHover = _useState2[0],
29672
- setSuppressHover = _useState2[1];
29705
+ var _useHoverSuppression = useHoverSuppression(),
29706
+ hoverSuppressed = _useHoverSuppression.hoverSuppressed,
29707
+ suppressHoverOnKey = _useHoverSuppression.suppressHoverOnKey,
29708
+ releaseHover = _useHoverSuppression.releaseHover;
29673
29709
  var handleBlur = React.useCallback(function (evt) {
29674
29710
  if (intInputRef !== null && intInputRef !== void 0 && intInputRef.current) {
29675
29711
  intInputRef.current.scrollLeft = 0;
@@ -29677,19 +29713,17 @@
29677
29713
  typeof (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === "function" && (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur(evt));
29678
29714
  }, [inputProps]);
29679
29715
  var handleKeyDown = React.useCallback(function (evt) {
29680
- if (evt.key === "Enter" || evt.key === "Escape") {
29681
- setSuppressHover(true);
29682
- }
29716
+ suppressHoverOnKey(evt);
29683
29717
  typeof (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) === "function" && inputProps.onKeyDown(evt);
29684
- }, [inputProps]);
29718
+ }, [inputProps, suppressHoverOnKey]);
29685
29719
  var handleFocus = React.useCallback(function (evt) {
29686
- setSuppressHover(false);
29720
+ releaseHover();
29687
29721
  typeof (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === "function" && inputProps.onFocus(evt);
29688
- }, [inputProps]);
29722
+ }, [inputProps, releaseHover]);
29689
29723
  var handleMouseLeave = React.useCallback(function (evt) {
29690
- setSuppressHover(false);
29724
+ releaseHover();
29691
29725
  typeof onMouseLeave === "function" && onMouseLeave(evt);
29692
- }, [onMouseLeave]);
29726
+ }, [onMouseLeave, releaseHover]);
29693
29727
  return /*#__PURE__*/React__default["default"].createElement(StyledDiv, _extends({
29694
29728
  className: className,
29695
29729
  ref: wrapRef
@@ -29712,32 +29746,23 @@
29712
29746
  onFocus: handleFocus,
29713
29747
  disabled: disabled,
29714
29748
  "data-form-type": "other",
29715
- "data-hover-suppressed": suppressHover ? "" : undefined,
29749
+ "data-hover-suppressed": hoverSuppressed,
29716
29750
  invalid: invalid
29717
29751
  })));
29718
29752
  });
29719
29753
  EditableContent.displayName = "EditableContent";
29720
29754
 
29721
- var _excluded$j = ["onSave", "onCancel", "value", "inputProps", "allowEmptyString", "multiline", "submitOnMetaEnter", "variant", "weight", "disabled", "invalid", "wrapRef", "children"];
29722
- var EditableText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
29723
- var onSave = _ref.onSave,
29755
+ var withoutLineBreaks = function withoutLineBreaks(text) {
29756
+ return text.replace(/\s*[\r\n]+\s*/g, " ");
29757
+ };
29758
+ var useEditableText = function useEditableText(_ref) {
29759
+ var value = _ref.value,
29760
+ onSave = _ref.onSave,
29724
29761
  onCancel = _ref.onCancel,
29725
- value = _ref.value,
29726
- inputProps = _ref.inputProps,
29727
29762
  allowEmptyString = _ref.allowEmptyString,
29728
- _ref$multiline = _ref.multiline,
29729
- multiline = _ref$multiline === void 0 ? false : _ref$multiline,
29730
29763
  _ref$submitOnMetaEnte = _ref.submitOnMetaEnter,
29731
29764
  submitOnMetaEnter = _ref$submitOnMetaEnte === void 0 ? false : _ref$submitOnMetaEnte,
29732
- _ref$variant = _ref.variant,
29733
- variant = _ref$variant === void 0 ? "Body 2" : _ref$variant,
29734
- weight = _ref.weight,
29735
- _ref$disabled = _ref.disabled,
29736
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
29737
- invalid = _ref.invalid,
29738
- wrapRef = _ref.wrapRef,
29739
- children = _ref.children,
29740
- props = _objectWithoutProperties(_ref, _excluded$j);
29765
+ mode = _ref.mode;
29741
29766
  var _useState = React.useState(value),
29742
29767
  _useState2 = _slicedToArray(_useState, 2),
29743
29768
  currentValue = _useState2[0],
@@ -29747,7 +29772,7 @@
29747
29772
  prevValue = _useState4[0],
29748
29773
  setPrevValue = _useState4[1];
29749
29774
  var escapeRef = React.useRef(false);
29750
- var intTextareaRef = React.useRef(null);
29775
+ var multiline = mode === "multiline";
29751
29776
  React.useEffect(function () {
29752
29777
  if (currentValue !== value) {
29753
29778
  setCurrentValue(value);
@@ -29768,20 +29793,17 @@
29768
29793
  !allowEmptyString ? setCurrentValue(prevValue) : typeof onSave === "function" && prevValue !== e.target.value && onSave(e);
29769
29794
  }
29770
29795
  }
29771
- // Reset scroll position for textarea
29772
- if (multiline && intTextareaRef !== null && intTextareaRef !== void 0 && intTextareaRef.current) {
29773
- intTextareaRef.current.scrollLeft = 0;
29796
+ if (mode !== "single") {
29797
+ e.target.scrollLeft = 0;
29774
29798
  }
29775
- }, [allowEmptyString, onSave, prevValue, multiline]);
29776
- var handleFocus = React.useCallback(function (e) {
29777
- if (multiline) {
29778
- var textarea = e.target;
29779
- var length = textarea.value.length;
29780
- textarea.setSelectionRange(length, length);
29799
+ if (mode === "wrap") {
29800
+ e.target.scrollTop = 0;
29781
29801
  }
29782
- }, [multiline]);
29802
+ }, [allowEmptyString, onSave, prevValue, mode]);
29783
29803
  var handleKeyDown = React.useCallback(function (e) {
29784
29804
  if (e.key === "Enter" && !multiline) {
29805
+ // A textarea must not get the line break.
29806
+ mode === "wrap" && e.preventDefault();
29785
29807
  e.target.blur();
29786
29808
  }
29787
29809
  if (e.key === "Enter" && multiline && submitOnMetaEnter && (e.metaKey || e.ctrlKey)) {
@@ -29795,10 +29817,108 @@
29795
29817
  e.target.blur();
29796
29818
  typeof onCancel === "function" && onCancel(e);
29797
29819
  }
29798
- }, [onCancel, multiline, submitOnMetaEnter]);
29820
+ }, [onCancel, multiline, mode, submitOnMetaEnter]);
29799
29821
  var handleChange = React.useCallback(function (e) {
29800
- setCurrentValue(e.target.value);
29801
- }, []);
29822
+ setCurrentValue(mode === "wrap" ? withoutLineBreaks(e.target.value) : e.target.value);
29823
+ }, [mode]);
29824
+ return {
29825
+ currentValue,
29826
+ handleBlur,
29827
+ handleKeyDown,
29828
+ handleChange
29829
+ };
29830
+ };
29831
+
29832
+ var _excluded$j = ["onSave", "onCancel", "value", "inputProps", "allowEmptyString", "multiline", "submitOnMetaEnter", "wrap", "variant", "weight", "disabled", "invalid", "wrapRef", "children"],
29833
+ _excluded2 = ["onMouseLeave"];
29834
+ var EditableText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
29835
+ var onSave = _ref.onSave,
29836
+ onCancel = _ref.onCancel,
29837
+ value = _ref.value,
29838
+ inputProps = _ref.inputProps,
29839
+ allowEmptyString = _ref.allowEmptyString,
29840
+ _ref$multiline = _ref.multiline,
29841
+ multiline = _ref$multiline === void 0 ? false : _ref$multiline,
29842
+ _ref$submitOnMetaEnte = _ref.submitOnMetaEnter,
29843
+ submitOnMetaEnter = _ref$submitOnMetaEnte === void 0 ? false : _ref$submitOnMetaEnte,
29844
+ _ref$wrap = _ref.wrap,
29845
+ wrap = _ref$wrap === void 0 ? false : _ref$wrap,
29846
+ _ref$variant = _ref.variant,
29847
+ variant = _ref$variant === void 0 ? "Body 2" : _ref$variant,
29848
+ weight = _ref.weight,
29849
+ _ref$disabled = _ref.disabled,
29850
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
29851
+ invalid = _ref.invalid,
29852
+ wrapRef = _ref.wrapRef,
29853
+ children = _ref.children,
29854
+ props = _objectWithoutProperties(_ref, _excluded$j);
29855
+ var mode = wrap ? "wrap" : multiline ? "multiline" : "single";
29856
+ var _useEditableText = useEditableText({
29857
+ value,
29858
+ onSave,
29859
+ onCancel,
29860
+ allowEmptyString,
29861
+ submitOnMetaEnter,
29862
+ mode
29863
+ }),
29864
+ currentValue = _useEditableText.currentValue,
29865
+ handleBlur = _useEditableText.handleBlur,
29866
+ handleKeyDown = _useEditableText.handleKeyDown,
29867
+ handleChange = _useEditableText.handleChange;
29868
+ var _useHoverSuppression = useHoverSuppression(),
29869
+ hoverSuppressed = _useHoverSuppression.hoverSuppressed,
29870
+ suppressHoverOnKey = _useHoverSuppression.suppressHoverOnKey,
29871
+ releaseHover = _useHoverSuppression.releaseHover;
29872
+ var intTextareaRef = React.useRef(null);
29873
+ var handleFocus = React.useCallback(function (e) {
29874
+ if (multiline) {
29875
+ var textarea = e.target;
29876
+ var length = textarea.value.length;
29877
+ textarea.setSelectionRange(length, length);
29878
+ }
29879
+ }, [multiline]);
29880
+ var handleWrapKeyDown = React.useCallback(function (e) {
29881
+ suppressHoverOnKey(e);
29882
+ handleKeyDown(e);
29883
+ }, [handleKeyDown, suppressHoverOnKey]);
29884
+ var _ref2 = props,
29885
+ onMouseLeave = _ref2.onMouseLeave,
29886
+ wrapProps = _objectWithoutProperties(_ref2, _excluded2);
29887
+ var handleWrapMouseLeave = React.useCallback(function (e) {
29888
+ releaseHover();
29889
+ typeof onMouseLeave === "function" && onMouseLeave(e);
29890
+ }, [onMouseLeave, releaseHover]);
29891
+ if (wrap) {
29892
+ var text = String(currentValue !== null && currentValue !== void 0 ? currentValue : "");
29893
+ return /*#__PURE__*/React__default["default"].createElement(StyledWrapRoot, _extends({
29894
+ ref: ref || wrapRef
29895
+ }, wrapProps, {
29896
+ onMouseLeave: handleWrapMouseLeave
29897
+ }), /*#__PURE__*/React__default["default"].createElement(StyledWrapSpan, {
29898
+ variant: variant,
29899
+ forwardedAs: "span",
29900
+ weight: weight,
29901
+ $disabled: disabled,
29902
+ className: "presentation",
29903
+ "aria-hidden": disabled ? undefined : true
29904
+ }, children ? children : "".concat(text || !disabled && (inputProps === null || inputProps === void 0 ? void 0 : inputProps.placeholder) || "", " ")), /*#__PURE__*/React__default["default"].createElement(StyledWrapTextarea, _extends({}, inputProps, {
29905
+ ref: intTextareaRef,
29906
+ forwardedAs: "textarea",
29907
+ variant: variant,
29908
+ weight: weight,
29909
+ rows: 1,
29910
+ value: text,
29911
+ onFocus: releaseHover,
29912
+ onBlur: handleBlur,
29913
+ onKeyDown: handleWrapKeyDown,
29914
+ onChange: handleChange,
29915
+ disabled: disabled,
29916
+ invalid: invalid,
29917
+ "data-form-type": "other",
29918
+ "data-hover-suppressed": hoverSuppressed,
29919
+ className: classnames__default["default"]("c-textarea", inputProps === null || inputProps === void 0 ? void 0 : inputProps.className)
29920
+ })));
29921
+ }
29802
29922
  if (multiline) {
29803
29923
  return /*#__PURE__*/React__default["default"].createElement(StyledDiv, _extends({
29804
29924
  ref: ref || wrapRef
@@ -31665,7 +31785,10 @@
31665
31785
  var StyledImg = styled__default["default"].img.withConfig({
31666
31786
  displayName: "EmptySlatestyles__StyledImg",
31667
31787
  componentId: "sc-jfbqky-2"
31668
- })(["width:280px;height:280px;"]);
31788
+ })(["width:280px;height:280px;visibility:", ";"], function (_ref) {
31789
+ var $loaded = _ref.$loaded;
31790
+ return $loaded ? "visible" : "hidden";
31791
+ });
31669
31792
  var Title = styled__default["default"](Typography).withConfig({
31670
31793
  displayName: "EmptySlatestyles__Title",
31671
31794
  componentId: "sc-jfbqky-3"
@@ -31691,6 +31814,9 @@
31691
31814
  EmptySlateFooter.displayName = "EmptySlateFooter";
31692
31815
 
31693
31816
  var _excluded$5 = ["title", "description", "src", "alt", "children"];
31817
+ var isAlreadyLoaded = function isAlreadyLoaded(image) {
31818
+ return !!image && image.complete && image.naturalWidth > 0;
31819
+ };
31694
31820
  var EmptySlate = function EmptySlate(_ref) {
31695
31821
  var title = _ref.title,
31696
31822
  description = _ref.description,
@@ -31698,11 +31824,27 @@
31698
31824
  alt = _ref.alt,
31699
31825
  children = _ref.children,
31700
31826
  rest = _objectWithoutProperties(_ref, _excluded$5);
31827
+ var imageRef = React.useRef(null);
31828
+ var _useState = React.useState(),
31829
+ _useState2 = _slicedToArray(_useState, 2),
31830
+ loadedSrc = _useState2[0],
31831
+ setLoadedSrc = _useState2[1];
31832
+ var markLoaded = React.useCallback(function () {
31833
+ return setLoadedSrc(src);
31834
+ }, [src]);
31835
+ React.useLayoutEffect(function () {
31836
+ if (isAlreadyLoaded(imageRef.current)) {
31837
+ markLoaded();
31838
+ }
31839
+ }, [markLoaded]);
31701
31840
  return /*#__PURE__*/React__default["default"].createElement(Container, _extends({}, rest, {
31702
31841
  role: "status"
31703
31842
  }), /*#__PURE__*/React__default["default"].createElement(StyledImg, {
31843
+ ref: imageRef,
31704
31844
  src: src,
31705
- alt: alt
31845
+ alt: alt,
31846
+ onLoad: markLoaded,
31847
+ $loaded: loadedSrc === src
31706
31848
  }), /*#__PURE__*/React__default["default"].createElement(SubContainer, null, /*#__PURE__*/React__default["default"].createElement(Title, {
31707
31849
  weight: "light",
31708
31850
  variant: "Title 1"