Skip to content

Commit

Permalink
chore: export all comments code
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Nov 27, 2024
1 parent cd28b53 commit 877e015
Show file tree
Hide file tree
Showing 38 changed files with 238 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {Fragment, useMemo} from 'react'

import {Tooltip} from '../../../ui-components'

/**
* @internal
*/
export interface CommentBreadcrumbsProps {
titlePath: string[]
maxLength: number
Expand All @@ -27,6 +30,9 @@ const renderItem = (item: string, index: number) => {
)
}

/**
* @internal
*/
export function CommentBreadcrumbs(props: CommentBreadcrumbsProps) {
const {titlePath, maxLength} = props

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {forwardRef, type Ref, type SVGProps} from 'react'

/**
* @internal
*/
export const CommentDisabledIcon = forwardRef(function Icon(
props: SVGProps<SVGSVGElement>,
ref: Ref<SVGSVGElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {forwardRef, type Ref, type SVGProps} from 'react'

// A slightly (arguably) more optically centered version of the current <CommentIcon> provided by @sanity/icons
// @todo: remove this and replace with an updated version from @sanity/icons
/**
* @internal
*/
export const CommentIcon = forwardRef(function Icon(
props: SVGProps<SVGSVGElement>,
ref: Ref<SVGSVGElement>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {forwardRef, type Ref, type SVGProps} from 'react'

/**
* @internal
*/
export const MentionIcon = forwardRef(function Icon(
props: SVGProps<SVGSVGElement>,
ref: Ref<SVGSVGElement>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {forwardRef, type Ref, type SVGProps} from 'react'

/**
* @internal
*/
export const ReactionIcon = forwardRef(function Icon(
props: SVGProps<SVGSVGElement>,
ref: Ref<SVGSVGElement>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {forwardRef, type Ref, type SVGProps} from 'react'

/**
* @internal
*/
export const SendIcon = forwardRef(function Icon(
props: SVGProps<SVGSVGElement>,
ref: Ref<SVGSVGElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ export interface CommentsListProps {
onDelete: (id: string) => void
onEdit: (id: string, payload: CommentUpdatePayload) => void
onNewThreadCreate: (payload: CommentBaseCreatePayload) => void
/**
* @internal
*/
onPathSelect?: (nextPath: CommentsSelectedPath) => void
onReactionSelect?: (id: string, reaction: CommentReactionOption) => void
onReply: (payload: CommentBaseCreatePayload) => void
onStatusChange?: (id: string, status: CommentStatus) => void
readOnly?: boolean
/**
* @internal
*/
selectedPath: CommentsSelectedPath | null
status: CommentStatus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const GhostButton = styled.button`
left: 0;
`

/**
* @internal
*/
export interface CommentsListItemProps {
avatarConfig?: {
avatarSize: AvatarSize
Expand Down Expand Up @@ -119,6 +122,9 @@ export interface CommentsListItemProps {
replies: CommentDocument[] | undefined
}

/**
* @internal
*/
export const CommentsListItem = memo(function CommentsListItem(props: CommentsListItemProps) {
const {
avatarConfig = DEFAULT_AVATAR_CONFIG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ interface CommentsListItemReferencedValueProps {
value: CommentDocument['contentSnapshot']
}

/**
* @internal
*/
export function CommentsListItemReferencedValue(props: CommentsListItemReferencedValueProps) {
const {hasReferencedValue, value} = props

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface CommentsOnboardingPopoverProps extends Omit<PopoverProps, 'content'> {
onDismiss: () => void
}

/**
* @internal
*/
export function CommentsOnboardingPopover(props: CommentsOnboardingPopoverProps) {
const {onDismiss} = props
const {t} = useTranslation(commentsLocaleNamespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {css, styled} from 'styled-components'

import {COMMENTS_HIGHLIGHT_HUE_KEY} from '../../constants'

/**
* @internal
*/
export const HighlightSpan = styled.span(({theme}: {theme: Theme}) => {
const isDark = theme.sanity.v2?.color._dark

Expand Down Expand Up @@ -66,6 +69,9 @@ interface CommentInlineHighlightSpanProps {
isNested?: boolean
}

/**
* @internal
*/
export const CommentInlineHighlightSpan = forwardRef(function CommentInlineHighlightSpan(
props: CommentInlineHighlightSpanProps & React.HTMLProps<HTMLSpanElement>,
ref: React.Ref<HTMLSpanElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const SCROLL_INTO_VIEW_OPTIONS: ScrollIntoViewOptions = {
inline: 'center',
}

/**
* @internal
*/
export interface CommentInputProps {
currentUser: CurrentUser
expandOnFocus?: boolean
Expand Down Expand Up @@ -61,6 +64,9 @@ interface CommentDiscardDialogController {
close: () => void
}

/**
* @internal
*/
export interface CommentInputHandle {
blur: () => void
discardDialogController: CommentDiscardDialogController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {type UserListWithPermissionsHookValue} from '../../../../hooks'
import {hasCommentMessageValue, useCommentHasChanged} from '../../../helpers'
import {type CommentMessage} from '../../../types'

/**
* @internal
*/
export interface CommentInputContextValue {
canSubmit?: boolean
closeMentions: () => void
Expand Down Expand Up @@ -39,6 +42,9 @@ interface CommentInputProviderProps {
value: CommentMessage
}

/**
* @internal
*/
export function CommentInputProvider(props: CommentInputProviderProps) {
const {
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const PlaceholderWrapper = styled.span((props) => {
`
})

/**
* @internal
*/
export const StyledPopover = styled(Popover)(({theme}) => {
const {space, radius} = theme.sanity

Expand Down Expand Up @@ -69,10 +72,16 @@ interface EditableProps {
renderBlock: RenderBlockFunction
}

/**
* @internal
*/
export interface EditableHandle {
setShowMentionOptions: (show: boolean) => void
}

/**
* @internal
*/
export function Editable(props: EditableProps) {
const {t} = useTranslation(commentsLocaleNamespace)
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {TransparentCard} from './TransparentCard.styled'
* [':name2:', [{shortName: ':name2:', userId: 'user1'}]
* ]
*```
* @internal
* @hidden
*/
function groupReactionsByName(reactions: CommentReactionItem[]) {
const grouped = reactions.reduce(
Expand Down Expand Up @@ -82,6 +84,10 @@ interface CommentReactionsBarProps {
mode: CommentsUIMode
}

/**
* @internal
* @hidden
*/
export const CommentReactionsBar = memo(function CommentReactionsBar(
props: CommentReactionsBarProps,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ interface CommentReactionsMenuProps {
onSelect: (option: CommentReactionOption) => void
}

/**
* @internal
* @hidden
*/
export function CommentReactionsMenu(props: CommentReactionsMenuProps) {
const {options, onSelect} = props
const {t} = useTranslation(commentsLocaleNamespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {CommentReactionsMenu} from './CommentReactionsMenu'

const POPOVER_FALLBACK_PLACEMENTS: PopoverProps['fallbackPlacements'] = ['top', 'bottom']

/**
* @internal
* @hidden
*/
export interface CommentReactionsMenuButtonProps {
mode: CommentsUIMode
onMenuClose?: () => void
Expand All @@ -23,6 +27,10 @@ export interface CommentReactionsMenuButtonProps {
}) => React.ReactElement
}

/**
* @internal
* @hidden
*/
export function CommentReactionsMenuButton(props: CommentReactionsMenuButtonProps) {
const {onMenuClose, onMenuOpen, onSelect, options, readOnly, renderMenuButton, mode} = props
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ interface CommentReactionsUsersTooltipProps {
userIds: string[]
}

/**
* @internal
* @hidden
*/
export function CommentReactionsUsersTooltip(props: CommentReactionsUsersTooltipProps) {
const {children, ...restProps} = props

Expand Down Expand Up @@ -135,6 +139,10 @@ function FormattedUserList({currentUserId, userIds}: {currentUserId: string; use
return elements
}

/**
* @internal
* @hidden
*/
export function CommentReactionsUsersTooltipContent(
props: Omit<CommentReactionsUsersTooltipProps, 'children'>,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ interface CommentsUpsellPanelProps {
onSecondaryClick: () => void
}

/**
* @internal
* @hidden
*/
export function CommentsUpsellPanel(props: CommentsUpsellPanelProps) {
const {data, onPrimaryClick, onSecondaryClick} = props
return (
Expand Down
12 changes: 12 additions & 0 deletions packages/sanity/src/core/comments/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import {type CommentReactionOption, type CommentReactionShortNames} from './type
*/
export const COMMENTS_INSPECTOR_NAME = 'sanity/comments'

/**
* @internal
* @hidden
*/
export const COMMENTS_HIGHLIGHT_HUE_KEY: ColorHueKey = 'yellow'

/**
* @internal
* @hidden
*/
// These should not be alphabetized as the current order is intentional
export const COMMENT_REACTION_OPTIONS: CommentReactionOption[] = [
{
Expand Down Expand Up @@ -38,6 +46,10 @@ export const COMMENT_REACTION_OPTIONS: CommentReactionOption[] = [
},
]

/**
* @internal
* @hidden
*/
export const COMMENT_REACTION_EMOJIS: Record<CommentReactionShortNames, string> = {
':-1:': '👎',
':+1:': '👍',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ interface CommentsOnboardingProviderProps {
children: ReactNode
}

/**
* @internal
* @hidden
*/
export function CommentsOnboardingProvider(props: CommentsOnboardingProviderProps) {
const {children} = props
const [dismissed, setDismissed] = useState<boolean>(getLocalStorage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ interface CommentsSelectedPathProviderProps {
children: React.ReactNode
}

/**
* @internal
* @hidden
*/
export const CommentsSelectedPathProvider = memo(function CommentsSelectedPathProvider(
props: CommentsSelectedPathProviderProps,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/**
* @internal
* @hidden
*/
export interface CommentsSelectedPath {
origin: 'form' | 'inspector' | 'url'
fieldPath: string | null
threadId: string | null
}

/**
* @internal
* @hidden
*/
export interface CommentsSelectedPathContextValue {
setSelectedPath: (nextSelectedPath: CommentsSelectedPath | null) => void
selectedPath: CommentsSelectedPath | null
Expand Down
10 changes: 10 additions & 0 deletions packages/sanity/src/core/comments/context/upsell/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import {type UpsellDialogViewedInfo} from '../../../studio'
import {type UpsellData} from '../../../studio/upsell/types'

/**
* @beta
* @hidden
*/
export interface CommentsUpsellContextValue {
upsellDialogOpen: boolean
/**
* @internal
*/
handleOpenDialog: (source: UpsellDialogViewedInfo['source']) => void
upsellData: UpsellData | null
telemetryLogs: {
dialogSecondaryClicked: () => void
dialogPrimaryClicked: () => void
/**
* @internal
*/
panelViewed: (source: UpsellDialogViewedInfo['source']) => void
panelDismissed: () => void
panelPrimaryClicked: () => void
Expand Down
Loading

0 comments on commit 877e015

Please sign in to comment.