Skip to content

Commit b76f569

Browse files
committed
feat: extend UserInputComponent to include valueData in user syntax segments
1 parent c744e90 commit b76f569

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/packages/ce/src/user/components/UserInputComponent.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface UserInputComponentProps extends TextInputProps {
2121
filter?: (user: User, index: number) => boolean
2222
}
2323

24+
export type UserSyntaxSegment = InputSyntaxSegment & { valueData?: User }
25+
2426
export const UserInputComponent: React.FC<UserInputComponentProps> = (props) => {
2527

2628
const {filter = () => true, ...rest} = props
@@ -43,15 +45,19 @@ export const UserInputComponent: React.FC<UserInputComponentProps> = (props) =>
4345
const transformSyntax = (
4446
_?: string | null,
4547
appliedParts: (InputSuggestion | any)[] = [],
46-
): InputSyntaxSegment[] => {
48+
): UserSyntaxSegment[] => {
4749

4850
let cursor = 0
4951

5052
return appliedParts.map((part: string | InputSuggestion, index) => {
5153
if (typeof part === "object") {
5254
const segment = {
5355
type: "block",
54-
value: part.valueData,
56+
// value must stay the raw suggestion value (username) so pictor can
57+
// re-match the segment to its token on re-serialization; the User
58+
// object travels alongside in valueData
59+
value: part.value,
60+
valueData: part.valueData,
5561
start: cursor,
5662
end: cursor + part.value.length,
5763
visualLength: 1,
@@ -81,7 +87,7 @@ export const UserInputComponent: React.FC<UserInputComponentProps> = (props) =>
8187
}
8288
cursor += textString.length
8389
return {}
84-
}) as InputSyntaxSegment[]
90+
}) as UserSyntaxSegment[]
8591
}
8692

8793
return <TextInput placeholder={"Enter users"}

0 commit comments

Comments
 (0)