@contentstack/live-preview-utils
Version:
Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.
1 lines • 12.1 kB
Source Map (JSON)
{"version":3,"sources":["../../../../../../src/visualBuilder/components/Collab/ThreadPopup/CommentTextArea.tsx"],"sourcesContent":["/** @jsxImportSource preact */\nimport React from \"preact/compat\";\nimport { useEffect } from \"preact/hooks\";\nimport { useCommentTextArea } from \"../../../hooks/useCommentTextArea\";\nimport { collabStyles, flexAlignCenter } from \"../../../collab.style\";\nimport {\n ICommentTextAreaProps,\n IMentionList,\n} from \"../../../types/collab.types\";\nimport classNames from \"classnames\";\nimport Tooltip from \"../Tooltip/Tooltip\";\n\nconst ErrorIndicator: React.FC<{ errorMessage: string }> = ({\n errorMessage,\n}) => (\n <div\n className={classNames(\n \"collab-thread-input-indicator--error\",\n collabStyles()[\"collab-thread-input-indicator--error\"]\n )}\n >\n {errorMessage}\n </div>\n);\n\nconst CharacterCounter: React.FC<{\n currentLength: number;\n maxLength: number;\n}> = ({ currentLength, maxLength }) => (\n <div\n className={classNames(\n \"collab-thread-input-indicator--count\",\n collabStyles()[\"collab-thread-input-indicator--count\"]\n )}\n >\n {currentLength}/{maxLength}\n </div>\n);\n\nconst MentionSuggestionsList: React.FC<{\n filteredUsers: IMentionList[];\n selectedIndex: number;\n cursorPosition: { top: number; showAbove: boolean };\n inputRef: React.RefObject<HTMLTextAreaElement>;\n listRef: React.RefObject<HTMLUListElement>;\n itemRefs: React.MutableRefObject<(HTMLLIElement | null)[]>;\n insertMention: (user: IMentionList) => void;\n handleKeyDown: (event: KeyboardEvent) => void;\n}> = ({\n filteredUsers,\n selectedIndex,\n cursorPosition,\n inputRef,\n listRef,\n itemRefs,\n insertMention,\n handleKeyDown,\n}) => {\n if (filteredUsers.length === 0) return null;\n\n return (\n <ul\n className={classNames(\n \"collab-thread-body--input--textarea--suggestionsList\",\n collabStyles()[\n \"collab-thread-body--input--textarea--suggestionsList\"\n ]\n )}\n style={{\n ...(cursorPosition.showAbove\n ? {\n bottom: `${window.innerHeight - (inputRef.current?.getBoundingClientRect().top || 0) - cursorPosition.top}px`,\n top: \"auto\",\n }\n : {\n top: `${(inputRef.current?.getBoundingClientRect().top || 0) + cursorPosition.top}px`,\n }),\n }}\n ref={listRef}\n >\n {filteredUsers.map((user, index) => (\n <li\n key={user.uid}\n onClick={() => insertMention(user)}\n className={classNames(\n \"collab-thread-body--input--textarea--suggestionsList--item\",\n collabStyles()[\n \"collab-thread-body--input--textarea--suggestionsList--item\"\n ],\n index === selectedIndex\n ? collabStyles()[\n \"collab-thread-body--input--textarea--suggestionsList--item-selected\"\n ]\n : \"\"\n )}\n ref={(el) => {\n itemRefs.current[index] = el;\n }}\n onKeyDown={(e) =>\n e.key === \"Enter\"\n ? insertMention(user)\n : handleKeyDown(e as KeyboardEvent)\n }\n tabIndex={-1}\n aria-selected={index === selectedIndex}\n >\n {user.display === user.email ? (\n user.display.length > 20 ? (\n <Tooltip content={user.display || \"\"}>\n {(user.display || \"\").substring(0, 18) + \"...\"}\n </Tooltip>\n ) : (\n user.display\n )\n ) : (\n <Tooltip\n content={user.display + \" - \" + user.email || \"\"}\n >\n {user.display.length > 20\n ? (user.display || \"\").substring(0, 18) + \"...\"\n : user.display}\n </Tooltip>\n )}\n </li>\n ))}\n </ul>\n );\n};\n\nconst CommentTextArea: React.FC<ICommentTextAreaProps> = React.memo(\n ({ userState, handleOnSaveRef, comment, onClose }) => {\n const {\n state,\n error,\n showSuggestions,\n cursorPosition,\n selectedIndex,\n filteredUsers,\n inputRef,\n listRef,\n itemRefs,\n handleInputChange,\n handleKeyDown,\n handleSubmit,\n insertMention,\n maxMessageLength,\n } = useCommentTextArea(userState, comment, onClose);\n\n const onChangeHandler = (event: Event) =>\n handleInputChange(event as any);\n const onKeyDownHandler = (event: KeyboardEvent) =>\n handleKeyDown(event as any);\n\n useEffect(() => {\n handleOnSaveRef.current = handleSubmit;\n }, [handleSubmit, handleOnSaveRef]);\n\n return (\n <div\n className={classNames(\n \"collab-thread-body--input--wrapper\",\n collabStyles()[\"collab-thread-body--input--wrapper\"]\n )}\n >\n <div\n className={classNames(\n \"collab-thread-body--input\",\n collabStyles()[\"collab-thread-body--input\"]\n )}\n >\n <div\n className={classNames(\n \"collab-thread-body--input--textarea--wrapper\",\n collabStyles()[\n \"collab-thread-body--input--textarea--wrapper\"\n ]\n )}\n >\n <textarea\n name=\"collab-thread-body--input--textarea\"\n id=\"collab-thread-body--input--textarea\"\n rows={1}\n className={classNames(\n \"collab-thread-body--input--textarea\",\n collabStyles()[\n \"collab-thread-body--input--textarea\"\n ]\n )}\n value={state.message}\n onChange={onChangeHandler}\n onKeyDown={onKeyDownHandler}\n maxLength={maxMessageLength}\n placeholder=\"Enter a comment or tag others using “@”\"\n ref={inputRef}\n />\n {showSuggestions && (\n <MentionSuggestionsList\n filteredUsers={filteredUsers}\n selectedIndex={selectedIndex}\n cursorPosition={cursorPosition}\n inputRef={inputRef}\n listRef={listRef}\n itemRefs={itemRefs}\n insertMention={insertMention}\n handleKeyDown={handleKeyDown}\n />\n )}\n </div>\n </div>\n\n <div\n className={classNames(\n \"collab-thread-input-indicator--wrapper\",\n \"flex-v-center\",\n collabStyles()[\n \"collab-thread-input-indicator--wrapper\"\n ],\n flexAlignCenter\n )}\n >\n <ErrorIndicator errorMessage={error.message} />\n <CharacterCounter\n currentLength={state.message.length}\n maxLength={maxMessageLength}\n />\n </div>\n </div>\n );\n }\n);\n\nexport default CommentTextArea;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAkB;AAClB,mBAA0B;AAC1B,gCAAmC;AACnC,oBAA8C;AAK9C,wBAAuB;AACvB,qBAAoB;AAKhB;AAHJ,IAAM,iBAAqD,CAAC;AAAA,EACxD;AACJ,MACI;AAAA,EAAC;AAAA;AAAA,IACG,eAAW,kBAAAA;AAAA,MACP;AAAA,UACA,4BAAa,EAAE,sCAA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