Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/04xxx/module_4941.js (118.4 MB)
433 lines
15 KiB
TypeScript
433 lines
15 KiB
TypeScript
// Module ID: 8380
|
|
// Function ID: 8381
|
|
// Name: ComponentStateContext
|
|
// Dependencies: [32, 19, 8198, 4396, 2041, 2105, 5625, 1372, 8381, 21, 1978, 4987, 4985, 504, 8234, 7509, 8383, 8384, 573, 5203, 4980, 2]
|
|
// Exports: ComponentStateContextProvider, useComponentContainerId, useComponentError, useComponentState, useComponentStateContext
|
|
|
|
// Module 8380 (ComponentStateContext)
|
|
import DispatcherDefault from "Dispatcher" /* 573 */;
|
|
import Server from "Server" /* 1978 */;
|
|
import InteractionComponentTypes from "InteractionComponentTypes" /* 4987 */;
|
|
import useMountEffectDefault from "useMountEffect" /* 5203 */;
|
|
import InteractionUtils from "InteractionUtils" /* 8384 */;
|
|
import _slicedToArray from "module_32" /* 32 */;
|
|
import noop from "module_19" /* 19 */;
|
|
import InteractionStore from "InteractionStore" /* 8198 */;
|
|
import LurkingStore from "LurkingStore" /* 4396 */;
|
|
import ChannelStore from "ChannelStore" /* 2041 */;
|
|
import GuildMemberStore from "GuildMemberStore" /* 2105 */;
|
|
import GuildVerificationStore from "GuildVerificationStore" /* 5625 */;
|
|
import UserStore from "UserStore" /* 1372 */;
|
|
import LocalInteractionComponentStateStore from "LocalInteractionComponentStateStore" /* 8381 */;
|
|
|
|
require = fn;
|
|
function isInteractionComponent(type) {
|
|
type = type.type;
|
|
if (Server.ComponentType.BUTTON === type) {
|
|
return type.style !== tmp(1978).ButtonStyle.LINK;
|
|
} else {
|
|
if (tmp(1978).ComponentType.STRING_SELECT !== type) {
|
|
if (tmp(1978).ComponentType.USER_SELECT !== type) {
|
|
if (tmp(1978).ComponentType.ROLE_SELECT !== type) {
|
|
if (tmp(1978).ComponentType.MENTIONABLE_SELECT !== type) {
|
|
if (tmp(1978).ComponentType.CHANNEL_SELECT !== type) {
|
|
if (tmp(1978).ComponentType.ACTION_ROW !== type) {
|
|
const TEXT_INPUT = tmp(1978).ComponentType.TEXT_INPUT;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
function getActionComponentState(interaction, id, shouldDisableInteractiveComponents) {
|
|
let flag = shouldDisableInteractiveComponents;
|
|
if (shouldDisableInteractiveComponents === undefined) {
|
|
flag = false;
|
|
}
|
|
let LOADING = InteractionComponentTypes.ActionComponentState.NORMAL;
|
|
let tmp3 = null != interaction;
|
|
if (tmp3) {
|
|
tmp3 = interaction.state !== tmp(4985).InteractionState.FAILED;
|
|
}
|
|
let DISABLED = LOADING;
|
|
if (!tmp3) {
|
|
if (flag) {
|
|
flag = isInteractionComponent(id);
|
|
}
|
|
if (flag) {
|
|
DISABLED = tmp(4987).ActionComponentState.DISABLED;
|
|
}
|
|
return DISABLED;
|
|
} else {
|
|
if (interaction.data.interactionType !== tmp(1978).InteractionTypes.MESSAGE_COMPONENT) {
|
|
if (isInteractionComponent(id)) {
|
|
LOADING = tmp(4987).ActionComponentState.DISABLED;
|
|
}
|
|
}
|
|
LOADING = tmp(4987).ActionComponentState.LOADING;
|
|
}
|
|
}
|
|
function useShouldDisableInteractiveComponents(channel_id) {
|
|
const channel = ChannelStore.getChannel(channel_id);
|
|
const items = [GuildVerificationStore];
|
|
const items1 = [channel];
|
|
const stateFromStores = channel(504).useStateFromStores(items, () => {
|
|
let guild_id;
|
|
if (channel != null) {
|
|
guild_id = tmp.guild_id;
|
|
}
|
|
let canChatInGuildResult = null == guild_id;
|
|
if (!canChatInGuildResult) {
|
|
canChatInGuildResult = GuildVerificationStore.canChatInGuild(tmp.guild_id);
|
|
}
|
|
return canChatInGuildResult;
|
|
}, items1);
|
|
const obj2 = channel(504);
|
|
const items2 = [LurkingStore];
|
|
const items3 = [channel];
|
|
const stateFromStores1 = channel(504).useStateFromStores(items2, () => {
|
|
let guild_id;
|
|
if (channel != null) {
|
|
guild_id = tmp.guild_id;
|
|
}
|
|
let isLurkingResult = null != guild_id;
|
|
if (isLurkingResult) {
|
|
isLurkingResult = LurkingStore.isLurking(tmp.guild_id);
|
|
}
|
|
return isLurkingResult;
|
|
}, items3);
|
|
const obj3 = channel(504);
|
|
const items4 = [GuildMemberStore, UserStore];
|
|
const stateFromStores2 = channel(504).useStateFromStores(items4, () => {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
let guild_id;
|
|
if (channel != null) {
|
|
guild_id = tmp2.guild_id;
|
|
}
|
|
let flag = null;
|
|
if (null != guild_id) {
|
|
flag = null;
|
|
if (null != currentUser) {
|
|
let guild_id1;
|
|
if (tmp2 != null) {
|
|
guild_id1 = tmp2.guild_id;
|
|
}
|
|
const member = GuildMemberStore.getMember(guild_id1, currentUser.id);
|
|
let isPending;
|
|
if (member != null) {
|
|
isPending = member.isPending;
|
|
}
|
|
flag = isPending;
|
|
}
|
|
}
|
|
if (flag == null) {
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
});
|
|
const obj4 = channel(504);
|
|
let guild_id;
|
|
if (channel != null) {
|
|
guild_id = channel.guild_id;
|
|
}
|
|
const obj5 = channel(8234);
|
|
const isThreadModerator = channel(7509).useIsThreadModerator(channel);
|
|
const tmpResult = channel(7509);
|
|
let tmp9 = !stateFromStores;
|
|
const canUnarchiveThread = channel(7509).useCanUnarchiveThread(channel);
|
|
if (stateFromStores) {
|
|
tmp9 = stateFromStores1;
|
|
}
|
|
if (!tmp9) {
|
|
tmp9 = stateFromStores2;
|
|
}
|
|
if (!tmp9) {
|
|
let isLockedThreadResult;
|
|
if (channel != null) {
|
|
isLockedThreadResult = channel.isLockedThread();
|
|
}
|
|
if (isLockedThreadResult) {
|
|
isLockedThreadResult = !isThreadModerator;
|
|
}
|
|
tmp9 = isLockedThreadResult;
|
|
}
|
|
if (!tmp9) {
|
|
let isArchivedThreadResult;
|
|
if (channel != null) {
|
|
isArchivedThreadResult = channel.isArchivedThread();
|
|
}
|
|
if (isArchivedThreadResult) {
|
|
isArchivedThreadResult = !canUnarchiveThread;
|
|
}
|
|
tmp9 = isArchivedThreadResult;
|
|
}
|
|
if (!tmp9) {
|
|
tmp9 = _slicedToArray(obj5.useCurrentUserCommunicationDisabled(guild_id), 2)[1];
|
|
}
|
|
return tmp9;
|
|
}
|
|
function useComponentStateForMessage(channel_id, arg1, id) {
|
|
_require = channel_id;
|
|
const items = [LocalInteractionComponentStateStore];
|
|
const stateFromStores = require("initialize").useStateFromStores(items, () => LocalInteractionComponentStateStore.getInteractionComponentState(channel_id.id, id.id));
|
|
let obj = require("initialize");
|
|
const items1 = [InteractionStore];
|
|
const items2 = [channel_id];
|
|
const stateFromStores1 = require("initialize").useStateFromStores(items1, () => InteractionStore.getInteraction(closure_0), items2);
|
|
const tmp3 = useShouldDisableInteractiveComponents(channel_id.channel_id) || arg1;
|
|
closure_129_0 = id;
|
|
closure_129_1 = stateFromStores;
|
|
const context = noop.useContext(closure_18);
|
|
closure_129_2 = context;
|
|
const items3 = [id, context];
|
|
callback = noop.useCallback((arg0) => {
|
|
let str = "message";
|
|
if (null != closure_2.modal) {
|
|
str = "modal";
|
|
}
|
|
const tmpResult = id(closure_2[16])(id, arg0, str);
|
|
id = tmpResult;
|
|
const setValidationErrors = closure_2.setValidationErrors;
|
|
if (setValidationErrors != null) {
|
|
setValidationErrors((arg0) => {
|
|
const obj = {};
|
|
const merged = Object.assign(arg0);
|
|
obj[id.id] = id;
|
|
return obj;
|
|
});
|
|
}
|
|
return null == tmpResult;
|
|
}, items3);
|
|
closure_129_3 = callback;
|
|
const items4 = [context.validators, callback, stateFromStores, id.id];
|
|
const effect = noop.useEffect(() => {
|
|
function currentValidate() {
|
|
return stateFromStores(id);
|
|
}
|
|
validators = validators.validators;
|
|
if (validators != null) {
|
|
validators.add(currentValidate);
|
|
}
|
|
return () => {
|
|
validators = validators.validators;
|
|
if (validators != null) {
|
|
validators.delete(currentValidate);
|
|
}
|
|
};
|
|
}, items4);
|
|
const validationErrors = context.validationErrors;
|
|
let tmp7;
|
|
if (validationErrors != null) {
|
|
tmp7 = validationErrors[id.id];
|
|
}
|
|
if (tmp7 == null) {
|
|
tmp7 = null;
|
|
}
|
|
id = channel_id.applicationId;
|
|
if (id == null) {
|
|
id = channel_id.author.id;
|
|
}
|
|
const obj4 = { state: stateFromStores, executeStateUpdate: null, isDisabled: null, visualState: null, error: null };
|
|
const items5 = [, , , , , , , ];
|
|
({ channel_id: arr6[0], flags: arr6[1], id: arr6[2] } = channel_id);
|
|
({ customId: arr6[3], type: arr6[4], id: arr6[5] } = id);
|
|
items5[6] = id;
|
|
items5[7] = callback;
|
|
obj4.executeStateUpdate = noop.useCallback((localState) => {
|
|
if (callback(localState)) {
|
|
const channel = ChannelStore.getChannel(channel_id.channel_id);
|
|
let tmp5 = null != channel;
|
|
if (tmp5) {
|
|
tmp5 = null != id.customId;
|
|
}
|
|
if (tmp5) {
|
|
const obj3 = { componentType: id.type, messageId: null, messageFlags: null, customId: null, componentId: null, applicationId: null, channelId: null, guildId: null, localState: null };
|
|
({ id: obj2.messageId, flags: obj2.messageFlags } = channel_id);
|
|
({ customId: obj2.customId, id: obj2.componentId } = id);
|
|
obj3.applicationId = id;
|
|
({ id: obj2.channelId, guild_id: obj2.guildId } = channel);
|
|
obj3.localState = localState;
|
|
const result = InteractionUtils.executeMessageComponentInteraction(obj3);
|
|
}
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}, items5);
|
|
let tmp8 = tmp3;
|
|
if (tmp3) {
|
|
tmp8 = isInteractionComponent(id);
|
|
}
|
|
obj4.isDisabled = tmp8;
|
|
obj4.visualState = getActionComponentState(stateFromStores1, id, tmp3);
|
|
obj4.error = tmp7;
|
|
return obj4;
|
|
}
|
|
function useComponentStateForModal(customId, id, arg2) {
|
|
_require = customId;
|
|
importDefault = id;
|
|
dependencyMap = arg2;
|
|
const items = [LocalInteractionComponentStateStore];
|
|
let stateFromStores = require("initialize").useStateFromStores(items, () => LocalInteractionComponentStateStore.getInteractionComponentState(customId.customId, id.id));
|
|
closure_129_0 = id;
|
|
closure_129_1 = stateFromStores;
|
|
const context = callback.useContext(closure_18);
|
|
closure_129_2 = context;
|
|
const items1 = [id, context];
|
|
callback = callback.useCallback((arg0) => {
|
|
let str = "message";
|
|
if (null != closure_2.modal) {
|
|
str = "modal";
|
|
}
|
|
const tmpResult = id(closure_2[16])(id, arg0, str);
|
|
id = tmpResult;
|
|
const setValidationErrors = closure_2.setValidationErrors;
|
|
if (setValidationErrors != null) {
|
|
setValidationErrors((arg0) => {
|
|
const obj = {};
|
|
const merged = Object.assign(arg0);
|
|
obj[id.id] = id;
|
|
return obj;
|
|
});
|
|
}
|
|
return null == tmpResult;
|
|
}, items1);
|
|
closure_129_3 = callback;
|
|
const items2 = [context.validators, callback, stateFromStores, id.id];
|
|
const effect = callback.useEffect(() => {
|
|
function currentValidate() {
|
|
return stateFromStores(id);
|
|
}
|
|
validators = validators.validators;
|
|
if (validators != null) {
|
|
validators.add(currentValidate);
|
|
}
|
|
return () => {
|
|
validators = validators.validators;
|
|
if (validators != null) {
|
|
validators.delete(currentValidate);
|
|
}
|
|
};
|
|
}, items2);
|
|
const validationErrors = context.validationErrors;
|
|
let tmp7;
|
|
if (validationErrors != null) {
|
|
tmp7 = validationErrors[id.id];
|
|
}
|
|
if (tmp7 == null) {
|
|
tmp7 = null;
|
|
}
|
|
const items3 = [customId.customId, id.id, callback];
|
|
const callback1 = callback.useCallback((state) => {
|
|
let tmp = null == state;
|
|
if (!tmp) {
|
|
const obj2 = { type: "SET_INTERACTION_COMPONENT_STATE", rootContainerId: customId.customId, componentId: id.id, state };
|
|
DispatcherDefault.dispatch(obj2);
|
|
tmp = callback(state);
|
|
}
|
|
return tmp;
|
|
}, items3);
|
|
useMountEffectDefault(() => {
|
|
if (null == stateFromStores) {
|
|
callback1(closure_2);
|
|
}
|
|
});
|
|
if (stateFromStores == null) {
|
|
stateFromStores = stateFromStores(callback.useState(arg2), 1)[0];
|
|
}
|
|
if (stateFromStores == null) {
|
|
stateFromStores = null;
|
|
}
|
|
let obj = require("initialize");
|
|
return { state: stateFromStores, executeStateUpdate: callback1, isDisabled: false, visualState: require("InteractionComponentTypes").ActionComponentState.NORMAL, error: tmp7 };
|
|
}
|
|
const jsx = fn(21).jsx;
|
|
const redux = noop.createContext(null);
|
|
const size = fn(2);
|
|
let result = size.fileFinishedImporting("modules/interaction_components/ComponentStateContext.tsx");
|
|
|
|
export { getActionComponentState };
|
|
export { useShouldDisableInteractiveComponents };
|
|
export const ComponentStateContextProvider = function ComponentStateContextProvider(children) {
|
|
const message = children.message;
|
|
const modal = children.modal;
|
|
const applicationWidget = children.applicationWidget;
|
|
const validators = children.validators;
|
|
const validationErrors = children.validationErrors;
|
|
const setValidationErrors = children.setValidationErrors;
|
|
let flag = children.shouldDisableInteractiveComponents;
|
|
if (flag === undefined) {
|
|
flag = false;
|
|
}
|
|
const items = [message, modal, applicationWidget, flag, validators, validationErrors, setValidationErrors];
|
|
return <redux.Provider value={validationErrors.useMemo(() => {
|
|
if (null != ApplicationWidget) {
|
|
const obj5 = { useComponentState: useComponentStateForMessage.bind(null, tmp, flag), channelId: null, containerId: null, message: null, validators: null, getParents: null };
|
|
({ channel_id: obj3.channelId, id: obj3.containerId } = tmp);
|
|
obj5.message = tmp;
|
|
obj5.validators = validators;
|
|
obj5.getParents = function getParents(arg0) {
|
|
return message(applicationWidget[20]).getParents(ApplicationWidget.components, arg0);
|
|
};
|
|
return obj5;
|
|
} else if (null != modal) {
|
|
const obj6 = { useComponentState: useComponentStateForModal.bind(null, tmp18), channelId: null, containerId: null, modal: null, validators: null, validationErrors: null, setValidationErrors: null, getParents: null };
|
|
({ channelId: obj2.channelId, customId: obj2.containerId } = tmp18);
|
|
obj6.modal = tmp18;
|
|
obj6.validators = validators;
|
|
obj6.validationErrors = validationErrors;
|
|
obj6.setValidationErrors = setValidationErrors;
|
|
obj6.getParents = function getParents(arg0) {
|
|
return message(applicationWidget[20]).getParents(components.components, arg0);
|
|
};
|
|
return obj6;
|
|
} else if (null != applicationWidget) {
|
|
const obj = { useComponentState: null, containerId: null, applicationWidget: null, validators: null, validationErrors: null, setValidationErrors: null, getParents: null };
|
|
ApplicationWidget = "ApplicationWidget";
|
|
obj.useComponentState = () => {
|
|
const error = new Error("" + ApplicationWidget + " does not support state");
|
|
throw error;
|
|
};
|
|
const _HermesInternal = HermesInternal;
|
|
obj.containerId = "app-widget-" + tmp19.applicationId;
|
|
obj.applicationWidget = tmp19;
|
|
obj.validators = validators;
|
|
obj.validationErrors = validationErrors;
|
|
obj.setValidationErrors = setValidationErrors;
|
|
obj.getParents = () => {
|
|
const error = new Error("" + "ApplicationWidget" + " does not support parents");
|
|
throw error;
|
|
};
|
|
return obj;
|
|
} else {
|
|
const _Error = Error;
|
|
let error = new Error("ComponentStateContextProvider requires at least one of message, modal, or applicationWidget");
|
|
throw error;
|
|
}
|
|
}, items)}>{arg0.children}</redux.Provider>;
|
|
};
|
|
export const useComponentState = function useComponentState(type, arg1) {
|
|
const context = noop.useContext(closure_18);
|
|
return context.useComponentState(type, arg1);
|
|
};
|
|
export const useComponentStateContext = function useComponentStateContext() {
|
|
return noop.useContext(closure_18);
|
|
};
|
|
export const useComponentContainerId = function useComponentContainerId() {
|
|
return noop.useContext(closure_18).containerId;
|
|
};
|
|
export const useComponentError = function useComponentError(component) {
|
|
const validationErrors = noop.useContext(closure_18).validationErrors;
|
|
let tmp;
|
|
if (validationErrors != null) {
|
|
tmp = validationErrors[component.id];
|
|
}
|
|
if (tmp == null) {
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
};
|