decord/source/modules/autocompleter/native/AutocompleteUtils.tsx

233 lines
8 KiB
TypeScript
Raw Normal View History

// Module ID: 10390
// Function ID: 10391
// Name: autocompleter/AutocompleteUtils
// Dependencies: [19, 17, 1961, 2012, 4285, 1371, 1074, 10391, 5081, 21, 4636, 576, 4789, 5103, 5523, 4481, 8722, 2]
2026-09-02 09:53:35 +00:00
// Exports: findAutoInsertOnSpaceToken, findWordStart, getAutocompleteResultText, getItemLayout, getItemSeparator, getMentionTextWithUser, getPrefix, getQuery, isSingleLineRun, isSpaceJustTypedAtCaret, isUnbrokenRun, isWhitespaceSeparatingBoundary
2026-07-20 16:05:17 +00:00
// Module 10390 (autocompleter/AutocompleteUtils)
import nativeDefault from "native" /* 576 */;
import UserUtilsDefault from "UserUtils" /* 4481 */;
import useChannelName from "useChannelName" /* 4789 */;
import TimestampUtils from "TimestampUtils" /* 5103 */;
import FormDividerDefault from "FormDivider" /* 8722 */;
import noop from "module_19" /* 19 */;
import GuildChannelStore from "GuildChannelStore" /* 2012 */;
import RelationshipStore from "RelationshipStore" /* 4285 */;
import UserStore from "UserStore" /* 1371 */;
2026-07-23 10:11:24 +00:00
require = fn;
2026-07-20 16:05:17 +00:00
function AutocompleteFormDivider() {
const tmp = closure_17();
return jsx(FormDividerDefault, { style: closure_17().itemDivider });
2026-07-20 16:05:17 +00:00
}
let closure_3 = fn(1961).isGuildSelectableChannelType;
const Constants = fn(1074);
({ AutoCompleteResultTypes: closure_7, WHITESPACE_RE: closure_8 } = Constants);
const ApplicationCommandsConstants = fn(10391);
({ AUTOCOMPLETE_EMOJI_ROW_HEIGHT: closure_9, AUTOCOMPLETE_ROW_HEIGHT: c10 } = ApplicationCommandsConstants);
const ChannelAutocompleteConstants = fn(5081);
({ CHANNEL_SENTINEL: closure_11, EMOJI_SENTINEL: closure_12, GAME_MENTION_SENTINEL: map1, MENTION_SENTINEL: closure_14 } = ChannelAutocompleteConstants);
const jsx = fn(21).jsx;
const hairlineWidth = fn(17).StyleSheet.hairlineWidth;
const createStyles = fn(4636);
const obj2 = { itemDivider: { marginLeft: 16, backgroundColor: nativeDefault.colors.BORDER_SUBTLE } };
let closure_17 = createStyles.createStyles(obj2);
2026-09-02 09:53:35 +00:00
const re19 = /[\r\n]/;
const size = fn(2);
let result = size.fileFinishedImporting("modules/autocompleter/native/AutocompleteUtils.tsx");
2026-07-20 16:05:17 +00:00
export const getItemLayout = function getItemLayout(arg0, index) {
let type;
2026-07-29 08:29:29 +00:00
if (arg0 != null) {
if (arg0[index] != null) {
2026-07-20 16:05:17 +00:00
type = tmp2.type;
}
}
const tmp3 = type === constants.EMOJI ? React7 : closure_1_10;
const obj = { length: tmp3, offset: null, index };
2026-07-20 16:05:17 +00:00
const result = index * tmp3;
obj.offset = result + Math.max(0, (index - 1) * hairlineWidth);
return obj;
2026-07-20 16:05:17 +00:00
};
export const getAutocompleteResultText = function getAutocompleteResultText(type, channel, set) {
if (null != set) {
if (!set.has(type.type)) {
2026-07-20 16:05:17 +00:00
return "";
}
}
type = type.type;
2026-07-24 07:16:23 +00:00
if (constants.USER === type) {
2026-07-29 08:29:29 +00:00
const user = type.user;
2026-09-02 09:53:35 +00:00
if (obj6.hasSameRoleAsUsername(channel, user)) {
2026-07-29 08:29:29 +00:00
const _HermesInternal9 = HermesInternal;
2026-09-02 09:53:35 +00:00
let combined = "" + tmp36 + user.tag;
2026-07-29 08:29:29 +00:00
} else {
const _HermesInternal8 = HermesInternal;
combined = "" + tmp36 + UserUtilsDefault.getUserTag(user);
const tmp34Result = UserUtilsDefault;
2026-07-29 08:29:29 +00:00
}
return combined;
} else if (tmp.GLOBAL === type) {
2026-07-20 16:05:17 +00:00
return type.text;
2026-07-29 08:29:29 +00:00
} else if (tmp.ROLE === type) {
2026-07-24 07:16:23 +00:00
const _HermesInternal7 = HermesInternal;
return "" + closure_1_14 + type.name;
2026-07-29 08:29:29 +00:00
} else if (tmp.CHANNEL === type) {
2026-07-20 16:05:17 +00:00
channel = type.channel;
if (channel.isThread()) {
const obj4 = useChannelName;
2026-07-24 07:16:23 +00:00
const _HermesInternal6 = HermesInternal;
return "#\"" + obj4.escapeChannelName(useChannelName.computeChannelName(type.channel, UserStore, RelationshipStore)) + "\"";
2026-07-20 16:05:17 +00:00
} else {
const channel2 = type.channel;
2026-07-20 16:05:17 +00:00
const guildId = channel2.getGuildId();
if (null != guildId) {
if (closure_3(type.channel.type)) {
const tmp18 = GuildChannelStore.getTextChannelNameDisambiguations(guildId)[type.channel.id];
2026-07-20 16:05:17 +00:00
let name;
2026-09-02 09:53:35 +00:00
if (tmp18 != null) {
name = tmp18.name;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (name == null) {
name = useChannelName.computeChannelName(type.channel, UserStore, RelationshipStore);
2026-07-20 16:05:17 +00:00
}
2026-07-24 07:16:23 +00:00
const _HermesInternal5 = HermesInternal;
return "" + closure_1_11 + name;
2026-07-20 16:05:17 +00:00
}
}
2026-07-24 07:16:23 +00:00
const _HermesInternal4 = HermesInternal;
return "" + closure_1_11 + useChannelName.computeChannelName(type.channel, UserStore, RelationshipStore);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else if (tmp.GAME_MENTION === type) {
2026-07-24 07:16:23 +00:00
const _HermesInternal3 = HermesInternal;
return "" + map1 + type.game.name;
2026-09-02 09:53:35 +00:00
} else if (tmp.TIMESTAMP_MENTION === type) {
return TimestampUtils.unparseTimestamp(type.mention.timestamp, type.mention.format);
2026-07-29 08:29:29 +00:00
} else if (tmp.EMOJI === type) {
2026-07-20 16:05:17 +00:00
const _HermesInternal2 = HermesInternal;
return "" + closure_1_12 + type.name + ":";
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
if (tmp.EMOJI_PREMIUM_UPSELL !== type) {
if (tmp.SLASH !== type) {
if (tmp.CHOICE === type) {
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal;
return "" + type.choice.displayName;
} else {
return "";
}
}
}
return "";
}
};
2026-07-29 08:29:29 +00:00
export const getMentionTextWithUser = function getMentionTextWithUser(messageChannel, user) {
if (obj.hasSameRoleAsUsername(messageChannel, user)) {
const _HermesInternal2 = HermesInternal;
let combined = "" + tmp3 + user.tag;
} else {
const _HermesInternal = HermesInternal;
combined = "" + tmp3 + UserUtilsDefault.getUserTag(user);
const tmpResult = UserUtilsDefault;
2026-07-29 08:29:29 +00:00
}
return combined;
};
2026-07-20 16:05:17 +00:00
export const getItemSeparator = function getItemSeparator() {
return <AutocompleteFormDivider />;
};
export const getPrefix = function getPrefix(substr1) {
return substr1[0];
};
export const getQuery = function getQuery(arr) {
return arr.slice(1).toLowerCase();
};
export const isWhitespaceSeparatingBoundary = function isWhitespaceSeparatingBoundary(seenText, lastIndexOfResult) {
let isMatch = 0 === lastIndexOfResult;
2026-07-24 07:16:23 +00:00
if (!isMatch) {
isMatch = regex.test(seenText[lastIndexOfResult - 1]);
2026-07-24 07:16:23 +00:00
}
return isMatch;
};
2026-09-02 09:53:35 +00:00
export const isUnbrokenRun = function isUnbrokenRun(arr, sum, arg2) {
return !regex.test(arr.slice(sum, arg2));
};
export const isSingleLineRun = function isSingleLineRun(arr, sum, arg2) {
return !re19.test(arr.slice(sum, arg2));
2026-07-24 07:16:23 +00:00
};
2026-08-04 08:36:32 +00:00
export const findWordStart = function findWordStart(arg0, arg1) {
let tmp = arg1;
if (arg1 > 0) {
let tmp4 = arg1;
tmp = arg1;
if (!regex.test(arg0[arg1 - 1])) {
const diff = tmp4 - 1;
tmp = diff;
while (diff > 0) {
tmp4 = diff;
tmp = diff;
if (regex.test(arg0[diff - 1])) {
break;
}
}
}
}
return tmp;
};
export const isSpaceJustTypedAtCaret = function isSpaceJustTypedAtCaret(text, selectionEnd, c22, selectionEnd2) {
let sum = selectionEnd2;
if (selectionEnd2 === selectionEnd + 1) {
if (c22.length === text.length + 1) {
if (" " === c22[sum - 1]) {
2026-08-04 08:36:32 +00:00
let num = 0;
if (0 < selectionEnd) {
while (c22[num] === text[num]) {
2026-08-04 08:36:32 +00:00
num = num + 1;
}
return false;
}
if (sum < c22.length) {
while (c22[sum] === text[sum - 1]) {
2026-08-04 08:36:32 +00:00
sum = sum + 1;
}
return false;
}
return true;
}
}
}
return false;
};
export const findAutoInsertOnSpaceToken = function findAutoInsertOnSpaceToken(c22, selectionEnd, arg2) {
if (selectionEnd >= arg2.length + 2) {
if (" " === c22[selectionEnd - 1]) {
const diff = selectionEnd - 1;
2026-08-04 08:36:32 +00:00
let tmp3 = diff;
if (0 < diff) {
let tmp2 = diff;
tmp3 = diff;
if (!regex.test(c22[diff - 1])) {
2026-08-04 08:36:32 +00:00
const diff1 = tmp2 - 1;
tmp3 = diff1;
while (0 < diff1) {
tmp2 = diff1;
tmp3 = diff1;
if (regex.test(c22[diff1 - 1])) {
2026-08-04 08:36:32 +00:00
break;
}
}
}
}
if (c22.startsWith(arg2, tmp3)) {
if (c22.lastIndexOf(arg2, diff - arg2.length) !== tmp3) {
2026-08-04 08:36:32 +00:00
return null;
} else {
const obj = { tokenStart: tmp3, trigger: c22.slice(tmp3 + arg2.length, diff) };
2026-08-04 08:36:32 +00:00
return obj;
}
} else {
return null;
}
}
}
return null;
};