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:
+24
@@ -0,0 +1,24 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import { isHostComponent } from './isHostComponent';
|
||||
|
||||
/**
|
||||
* Type of the ownerState based on the type of an element it applies to.
|
||||
* This resolves to the provided OwnerState for React components and `undefined` for host components.
|
||||
* Falls back to `OwnerState | undefined` when the exact type can't be determined in development time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Appends the ownerState object to the props, merging with the existing one if necessary.
|
||||
*
|
||||
* @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node or undefined, `ownerState` is not applied.
|
||||
* @param otherProps Props of the element.
|
||||
* @param ownerState
|
||||
*/
|
||||
export function appendOwnerState(elementType, otherProps, ownerState) {
|
||||
if (elementType === undefined || isHostComponent(elementType)) {
|
||||
return otherProps;
|
||||
}
|
||||
return _extends({}, otherProps, {
|
||||
ownerState: _extends({}, otherProps.ownerState, ownerState)
|
||||
});
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Extracts event handlers from a given object.
|
||||
* A prop is considered an event handler if it is a function and its name starts with `on`.
|
||||
*
|
||||
* @param object An object to extract event handlers from.
|
||||
* @param excludeKeys An array of keys to exclude from the returned object.
|
||||
*/
|
||||
export function extractEventHandlers(object, excludeKeys = []) {
|
||||
if (object === undefined) {
|
||||
return {};
|
||||
}
|
||||
const result = {};
|
||||
Object.keys(object).filter(prop => prop.match(/^on[A-Z]/) && typeof object[prop] === 'function' && !excludeKeys.includes(prop)).forEach(prop => {
|
||||
result[prop] = object[prop];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Determines if a given element is a DOM element name (i.e. not a React component).
|
||||
*/
|
||||
export function isHostComponent(element) {
|
||||
return typeof element === 'string';
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import clsx from 'clsx';
|
||||
import { extractEventHandlers } from './extractEventHandlers';
|
||||
import { omitEventHandlers } from './omitEventHandlers';
|
||||
/**
|
||||
* Merges the slot component internal props (usually coming from a hook)
|
||||
* with the externally provided ones.
|
||||
*
|
||||
* The merge order is (the latter overrides the former):
|
||||
* 1. The internal props (specified as a getter function to work with get*Props hook result)
|
||||
* 2. Additional props (specified internally on a Base UI component)
|
||||
* 3. External props specified on the owner component. These should only be used on a root slot.
|
||||
* 4. External props specified in the `slotProps.*` prop.
|
||||
* 5. The `className` prop - combined from all the above.
|
||||
* @param parameters
|
||||
* @returns
|
||||
*/
|
||||
export function mergeSlotProps(parameters) {
|
||||
const {
|
||||
getSlotProps,
|
||||
additionalProps,
|
||||
externalSlotProps,
|
||||
externalForwardedProps,
|
||||
className
|
||||
} = parameters;
|
||||
if (!getSlotProps) {
|
||||
// The simpler case - getSlotProps is not defined, so no internal event handlers are defined,
|
||||
// so we can simply merge all the props without having to worry about extracting event handlers.
|
||||
const joinedClasses = clsx(additionalProps == null ? void 0 : additionalProps.className, className, externalForwardedProps == null ? void 0 : externalForwardedProps.className, externalSlotProps == null ? void 0 : externalSlotProps.className);
|
||||
const mergedStyle = _extends({}, additionalProps == null ? void 0 : additionalProps.style, externalForwardedProps == null ? void 0 : externalForwardedProps.style, externalSlotProps == null ? void 0 : externalSlotProps.style);
|
||||
const props = _extends({}, additionalProps, externalForwardedProps, externalSlotProps);
|
||||
if (joinedClasses.length > 0) {
|
||||
props.className = joinedClasses;
|
||||
}
|
||||
if (Object.keys(mergedStyle).length > 0) {
|
||||
props.style = mergedStyle;
|
||||
}
|
||||
return {
|
||||
props,
|
||||
internalRef: undefined
|
||||
};
|
||||
}
|
||||
|
||||
// In this case, getSlotProps is responsible for calling the external event handlers.
|
||||
// We don't need to include them in the merged props because of this.
|
||||
|
||||
const eventHandlers = extractEventHandlers(_extends({}, externalForwardedProps, externalSlotProps));
|
||||
const componentsPropsWithoutEventHandlers = omitEventHandlers(externalSlotProps);
|
||||
const otherPropsWithoutEventHandlers = omitEventHandlers(externalForwardedProps);
|
||||
const internalSlotProps = getSlotProps(eventHandlers);
|
||||
|
||||
// The order of classes is important here.
|
||||
// Emotion (that we use in libraries consuming Base UI) depends on this order
|
||||
// to properly override style. It requires the most important classes to be last
|
||||
// (see https://github.com/mui/material-ui/pull/33205) for the related discussion.
|
||||
const joinedClasses = clsx(internalSlotProps == null ? void 0 : internalSlotProps.className, additionalProps == null ? void 0 : additionalProps.className, className, externalForwardedProps == null ? void 0 : externalForwardedProps.className, externalSlotProps == null ? void 0 : externalSlotProps.className);
|
||||
const mergedStyle = _extends({}, internalSlotProps == null ? void 0 : internalSlotProps.style, additionalProps == null ? void 0 : additionalProps.style, externalForwardedProps == null ? void 0 : externalForwardedProps.style, externalSlotProps == null ? void 0 : externalSlotProps.style);
|
||||
const props = _extends({}, internalSlotProps, additionalProps, otherPropsWithoutEventHandlers, componentsPropsWithoutEventHandlers);
|
||||
if (joinedClasses.length > 0) {
|
||||
props.className = joinedClasses;
|
||||
}
|
||||
if (Object.keys(mergedStyle).length > 0) {
|
||||
props.style = mergedStyle;
|
||||
}
|
||||
return {
|
||||
props,
|
||||
internalRef: internalSlotProps.ref
|
||||
};
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Removes event handlers from the given object.
|
||||
* A field is considered an event handler if it is a function with a name beginning with `on`.
|
||||
*
|
||||
* @param object Object to remove event handlers from.
|
||||
* @returns Object with event handlers removed.
|
||||
*/
|
||||
export function omitEventHandlers(object) {
|
||||
if (object === undefined) {
|
||||
return {};
|
||||
}
|
||||
const result = {};
|
||||
Object.keys(object).filter(prop => !(prop.match(/^on[A-Z]/) && typeof object[prop] === 'function')).forEach(prop => {
|
||||
result[prop] = object[prop];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* If `componentProps` is a function, calls it with the provided `ownerState`.
|
||||
* Otherwise, just returns `componentProps`.
|
||||
*/
|
||||
export function resolveComponentProps(componentProps, ownerState, slotState) {
|
||||
if (typeof componentProps === 'function') {
|
||||
return componentProps(ownerState, slotState);
|
||||
}
|
||||
return componentProps;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["elementType", "externalSlotProps", "ownerState", "skipResolvingSlotProps"];
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { appendOwnerState } from './appendOwnerState';
|
||||
import { mergeSlotProps } from './mergeSlotProps';
|
||||
import { resolveComponentProps } from './resolveComponentProps';
|
||||
/**
|
||||
* @ignore - do not document.
|
||||
* Builds the props to be passed into the slot of an unstyled component.
|
||||
* It merges the internal props of the component with the ones supplied by the user, allowing to customize the behavior.
|
||||
* If the slot component is not a host component, it also merges in the `ownerState`.
|
||||
*
|
||||
* @param parameters.getSlotProps - A function that returns the props to be passed to the slot component.
|
||||
*/
|
||||
export function useSlotProps(parameters) {
|
||||
var _parameters$additiona;
|
||||
const {
|
||||
elementType,
|
||||
externalSlotProps,
|
||||
ownerState,
|
||||
skipResolvingSlotProps = false
|
||||
} = parameters,
|
||||
rest = _objectWithoutPropertiesLoose(parameters, _excluded);
|
||||
const resolvedComponentsProps = skipResolvingSlotProps ? {} : resolveComponentProps(externalSlotProps, ownerState);
|
||||
const {
|
||||
props: mergedProps,
|
||||
internalRef
|
||||
} = mergeSlotProps(_extends({}, rest, {
|
||||
externalSlotProps: resolvedComponentsProps
|
||||
}));
|
||||
const ref = useForkRef(internalRef, resolvedComponentsProps == null ? void 0 : resolvedComponentsProps.ref, (_parameters$additiona = parameters.additionalProps) == null ? void 0 : _parameters$additiona.ref);
|
||||
const props = appendOwnerState(elementType, _extends({}, mergedProps, {
|
||||
ref
|
||||
}), ownerState);
|
||||
return props;
|
||||
}
|
||||
Reference in New Issue
Block a user