Grabbed dndbeyond's source code

```
~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js
```
This commit is contained in:
2025-05-28 11:50:03 -07:00
commit 8df9031d27
3592 changed files with 319051 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
import {
DESKTOP_COMPONENT_START_WIDTH,
DESKTOP_LARGE_COMPONENT_START_WIDTH,
TABLET_COMPONENT_START_WIDTH,
} from "../../CharacterSheet/config";
import * as actionTypes from "../actions/appEnv/actionTypes";
import { AppEnvAction } from "../actions/appEnv/typings";
import { AppEnvState } from "../stores/typings";
export enum StyleSizeTypeEnum {
NONE = 0,
MOBILE = 1,
TABLET = 2,
DESKTOP = 3,
DESKTOP_LARGE = 4,
}
export const initialEnvState: AppEnvState = {
authEndpoint: null,
username: null,
userId: -1,
userRoles: [],
characterId: null,
characterEndpoint: "",
characterServiceBaseUrl: null,
isMobile: true,
isReadonly: true,
canOverrideReadOnly: false,
redirect: "",
diceEnabled: false,
diceFeatureConfiguration: {
enabled: true,
menu: true,
assetBaseLocation: "",
trackingId: "",
apiEndpoint: "",
},
gameLog: {
isOpen: false,
lastMessageTime: 0,
apiEndpoint: "",
ddbApiEndpoint: "",
},
dimensions: {
styleSizeType: StyleSizeTypeEnum.NONE,
window: {
width: 0,
height: 0,
},
sheet: {
width: 0,
height: 0,
},
},
characterSlots: {
characterSlotLimit: null,
activeCharacterCount: 0,
lockedCharacterCount: 0,
allCharactersLocked: false,
},
};
function appEnv(
state: AppEnvState = initialEnvState,
action: AppEnvAction
): AppEnvState {
switch (action.type) {
case actionTypes.DATA_SET:
return {
...state,
...action.payload,
};
case actionTypes.MOBILE_SET:
return {
...state,
isMobile: action.payload.isMobile,
};
case actionTypes.DIMENSIONS_SET: {
let styleSizeType: StyleSizeTypeEnum = StyleSizeTypeEnum.NONE;
const windowWidth = action.payload.dimensions.window.width;
if (windowWidth >= DESKTOP_LARGE_COMPONENT_START_WIDTH) {
styleSizeType = StyleSizeTypeEnum.DESKTOP_LARGE;
} else if (windowWidth >= DESKTOP_COMPONENT_START_WIDTH) {
styleSizeType = StyleSizeTypeEnum.DESKTOP;
} else if (windowWidth >= TABLET_COMPONENT_START_WIDTH) {
styleSizeType = StyleSizeTypeEnum.TABLET;
} else {
styleSizeType = StyleSizeTypeEnum.MOBILE;
}
return {
...state,
dimensions: {
...action.payload.dimensions,
styleSizeType,
},
};
}
default:
// not implemented
}
return state;
}
export default appEnv;
@@ -0,0 +1,29 @@
import { appInfoActionTypes } from "../actions/appInfo";
import { AppInfoAction } from "../actions/appInfo/typings";
import { AppInfoState } from "../stores/typings";
const initialState: AppInfoState = {
error: null,
};
function appInfo(
state: AppInfoState = initialState,
action: AppInfoAction
): AppInfoState {
switch (action.type) {
case appInfoActionTypes.ERROR_SET:
return {
...state,
error: {
type: action.payload.appErrorType,
errorId: action.payload.errorId,
},
};
default:
// not implemented
}
return state;
}
export default appInfo;
@@ -0,0 +1,215 @@
import {
RollGroupContract,
RollResultContract,
DiceRolls,
} from "@dndbeyond/character-rules-engine/es";
import * as actionTypes from "../actions/rollResult/actionTypes";
import { RollResultAction } from "../actions/rollResult/typings";
import {
RollResultComponentGroupsState,
RollResultState,
} from "../stores/typings";
const initialRollState: RollResultContract = {
rollKey: "",
nextRollKey: null,
assignedValue: null,
rollTotal: null,
rollValues: [],
};
function rollReducer(
state: RollResultContract = initialRollState,
action: RollResultAction
): RollResultContract {
switch (action.type) {
case actionTypes.ROLL_RESULT_DICE_ROLL_SET_COMMIT:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_DICE_ROLL_SET: {
return {
...state,
...action.payload.properties,
};
}
case actionTypes.ROLL_RESULT_GROUP_RESET_COMMIT: {
return DiceRolls.simulateRollResultContract({
rollKey: state.rollKey,
nextRollKey: state.nextRollKey,
});
}
default:
//not implemented
}
return state;
}
const initialGroupRollsState: Array<RollResultContract> = [];
function groupRollsReducer(
state: Array<RollResultContract> = initialGroupRollsState,
action: RollResultAction
): Array<RollResultContract> {
switch (action.type) {
case actionTypes.ROLL_RESULT_GROUP_RESET_COMMIT: {
return state.map((roll) => rollReducer(roll, action));
}
case actionTypes.ROLL_RESULT_DICE_ROLL_SET_COMMIT:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_DICE_ROLL_SET: {
const rollIdx = state.findIndex(
(roll) => roll.rollKey === action.payload.rollKey
);
return [
...state.slice(0, rollIdx),
rollReducer(state[rollIdx], action),
...state.slice(rollIdx + 1),
];
}
default:
//not implemented
}
return state;
}
const initialGroupState: RollGroupContract = {
componentKey: "",
groupKey: "",
nextGroupKey: null,
rollResults: [],
};
function groupReducer(
state: RollGroupContract = initialGroupState,
action: RollResultAction
): RollGroupContract {
switch (action.type) {
case actionTypes.ROLL_RESULT_GROUP_DICE_ROLLS_SET_COMMIT:
return {
...state,
rollResults: action.payload.rollResults,
};
case actionTypes.ROLL_RESULT_GROUP_ORDER_SET_COMMIT:
return {
...state,
nextGroupKey: action.payload.nextGroupKey,
};
case actionTypes.ROLL_RESULT_GROUP_RESET_COMMIT:
case actionTypes.ROLL_RESULT_DICE_ROLL_SET_COMMIT:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_DICE_ROLL_SET:
return {
...state,
rollResults: groupRollsReducer(state.rollResults, action),
};
default:
// not implemented
}
return state;
}
const initialComponentGroupsState: RollResultComponentGroupsState = [];
function componentGroupsReducer(
state: RollResultComponentGroupsState = initialComponentGroupsState,
action: RollResultAction
): RollResultComponentGroupsState {
switch (action.type) {
case actionTypes.ROLL_RESULT_COMPONENT_GROUPS_SET_COMMIT:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_GROUPS_SET: {
return [...action.payload.groups];
}
case actionTypes.ROLL_RESULT_GROUP_ADD_COMMIT:
return [...state, action.payload.group];
case actionTypes.ROLL_RESULT_GROUP_REMOVE_COMMIT:
return state.filter(
(group) => group.groupKey !== action.payload.groupKey
);
case actionTypes.ROLL_RESULT_GROUP_DICE_ROLLS_SET_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_ORDER_SET_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_RESET_COMMIT:
case actionTypes.ROLL_RESULT_DICE_ROLL_SET_COMMIT:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_DICE_ROLL_SET: {
const groupIndex = state.findIndex(
(group) => group.groupKey === action.payload.groupKey
);
return [
...state.slice(0, groupIndex),
groupReducer(state[groupIndex], action),
...state.slice(groupIndex + 1),
];
}
default:
// not implemented
}
return state;
}
const initialRollResultState: RollResultState = {
data: {},
simulatedData: {},
dataStatus: {},
};
function rollResult(
state: RollResultState = initialRollResultState,
action: RollResultAction
): RollResultState {
switch (action.type) {
case actionTypes.ROLL_RESULT_COMPONENT_GROUPS_SET_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_ADD_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_DICE_ROLLS_SET_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_ORDER_SET_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_REMOVE_COMMIT:
case actionTypes.ROLL_RESULT_GROUP_RESET_COMMIT:
case actionTypes.ROLL_RESULT_DICE_ROLL_SET_COMMIT: {
return {
...state,
data: {
...state.data,
[action.payload.componentKey]: componentGroupsReducer(
state.data[action.payload.componentKey],
action
),
},
};
}
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_GROUPS_SET:
case actionTypes.ROLL_RESULT_COMPONENT_SIMULATED_DICE_ROLL_SET: {
return {
...state,
simulatedData: {
...state.simulatedData,
[action.payload.componentKey]: componentGroupsReducer(
state.simulatedData[action.payload.componentKey],
action
),
},
};
}
case actionTypes.ROLL_RESULT_DICE_ROLL_STATUS_SET: {
return {
...state,
dataStatus: {
...state.dataStatus,
[action.payload.rollKey]: action.payload.loadingStatus,
},
};
}
default:
// not implemented
}
return state;
}
export default rollResult;
@@ -0,0 +1,109 @@
import * as actionTypes from "../actions/toastMessage/actionTypes";
import { ToastMessageAction } from "../actions/toastMessage/typings";
import {
MessageState,
ToastMessageMetaState,
ToastMessageState,
ToastState,
} from "../stores/typings";
const initialMessagePayloadState: ToastState = {
title: "",
message: "",
};
/**
*
* @param state
* @param action
*/
function messagePayload(
state: ToastState = initialMessagePayloadState,
action: ToastMessageAction
): ToastState {
switch (action.type) {
case actionTypes.ADD_MESSAGE:
return {
...state,
...action.payload.toast,
};
}
return state;
}
const initialMessageMetaState: ToastMessageMetaState = {
level: "info",
autoDismiss: 5,
dismissible: true,
position: "bc",
};
/**
*
* @param state
* @param action
*/
function messageMeta(
state: ToastMessageMetaState = initialMessageMetaState,
action: ToastMessageAction
): ToastMessageMetaState {
switch (action.type) {
case actionTypes.ADD_MESSAGE:
return {
...state,
...action.payload.meta,
};
}
return state;
}
const initialMessageState: MessageState = {
payload: initialMessagePayloadState,
meta: {},
};
function message(
state: MessageState = initialMessageState,
action: ToastMessageAction
): MessageState {
switch (action.type) {
case actionTypes.ADD_MESSAGE:
return {
...state,
payload: messagePayload(undefined, action),
meta: messageMeta(undefined, action),
};
}
return state;
}
let messageId: number = 0;
/**
*
* @param state
* @param action
*/
function toastMessage(
state: ToastMessageState = {},
action: ToastMessageAction
): ToastMessageState {
switch (action.type) {
case actionTypes.ADD_MESSAGE:
messageId++;
return {
[messageId]: message(undefined, action),
};
case actionTypes.REMOVE_MESSAGE:
let newState: ToastMessageState = {};
Object.keys(state).forEach((messageId) => {
if (messageId !== action.payload.id) {
newState[messageId] = state[messageId];
}
});
return newState;
}
return state;
}
export default toastMessage;