pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ClassNameConfigurator = ClassNameConfigurator;
exports.useClassNamesOverride = useClassNamesOverride;
var React = _interopRequireWildcard(require("react"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const defaultContextValue = {
disableDefaultClasses: false
};
const ClassNameConfiguratorContext = /*#__PURE__*/React.createContext(defaultContextValue);
if (process.env.NODE_ENV !== 'production') {
ClassNameConfiguratorContext.displayName = 'ClassNameConfiguratorContext';
}
/**
* @ignore - internal hook.
*
* Wraps the `generateUtilityClass` function and controls how the classes are generated.
* Currently it only affects whether the classes are applied or not.
*
* @returns Function to be called with the `generateUtilityClass` function specific to a component to generate the classes.
*/
function useClassNamesOverride(generateUtilityClass) {
const {
disableDefaultClasses
} = React.useContext(ClassNameConfiguratorContext);
return slot => {
if (disableDefaultClasses) {
return '';
}
return generateUtilityClass(slot);
};
}
/**
* Allows to configure the components within to not apply any built-in classes.
*/
function ClassNameConfigurator(props) {
const {
disableDefaultClasses,
children
} = props;
const contextValue = React.useMemo(() => ({
disableDefaultClasses: disableDefaultClasses != null ? disableDefaultClasses : false
}), [disableDefaultClasses]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ClassNameConfiguratorContext.Provider, {
value: contextValue,
children: children
});
}
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
+30
View File
@@ -0,0 +1,30 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.appendOwnerState = appendOwnerState;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _isHostComponent = require("./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
*/
function appendOwnerState(elementType, otherProps, ownerState) {
if (elementType === undefined || (0, _isHostComponent.isHostComponent)(elementType)) {
return otherProps;
}
return (0, _extends2.default)({}, otherProps, {
ownerState: (0, _extends2.default)({}, otherProps.ownerState, ownerState)
});
}
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.areArraysEqual = areArraysEqual;
function areArraysEqual(array1, array2, itemComparer = (a, b) => a === b) {
return array1.length === array2.length && array1.every((value, index) => itemComparer(value, array2[index]));
}
+29
View File
@@ -0,0 +1,29 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineHooksSlotProps = combineHooksSlotProps;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
/**
* Combines the two get*Props functions from Base UI hooks into one.
* Useful when a hook uses two other hooks behind the scenes
* (such as useSelect that depends on useList and useButton for its root slot).
*
* The resulting function will return the combined props.
* They are merged from left to right, similarly to how Object.assign works.
*
* The getSecondProps function will receive the result of the getFirstProps function as its argument,
* so its event handlers can call the previous handlers and act depending on its result.
*
* @param getFirstProps - A getter function that returns the props for the first slot. It receives the external event handlers as its argument.
* @param getSecondProps - A getter function that returns the props for the second slot. It receives the result of the getFirstProps function as its argument.
*/
function combineHooksSlotProps(getFirstProps, getSecondProps) {
return function getCombinedProps(external = {}) {
const firstResult = (0, _extends2.default)({}, external, getFirstProps(external));
const result = (0, _extends2.default)({}, firstResult, getSecondProps(firstResult));
return result;
};
}
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractEventHandlers = extractEventHandlers;
/**
* 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.
*/
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;
}
+112
View File
@@ -0,0 +1,112 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
appendOwnerState: true,
areArraysEqual: true,
ClassNameConfigurator: true,
extractEventHandlers: true,
isHostComponent: true,
resolveComponentProps: true,
useRootElementName: true,
useSlotProps: true,
mergeSlotProps: true,
prepareForSlot: true
};
Object.defineProperty(exports, "ClassNameConfigurator", {
enumerable: true,
get: function () {
return _ClassNameConfigurator.ClassNameConfigurator;
}
});
Object.defineProperty(exports, "appendOwnerState", {
enumerable: true,
get: function () {
return _appendOwnerState.appendOwnerState;
}
});
Object.defineProperty(exports, "areArraysEqual", {
enumerable: true,
get: function () {
return _areArraysEqual.areArraysEqual;
}
});
Object.defineProperty(exports, "extractEventHandlers", {
enumerable: true,
get: function () {
return _extractEventHandlers.extractEventHandlers;
}
});
Object.defineProperty(exports, "isHostComponent", {
enumerable: true,
get: function () {
return _isHostComponent.isHostComponent;
}
});
Object.defineProperty(exports, "mergeSlotProps", {
enumerable: true,
get: function () {
return _mergeSlotProps.mergeSlotProps;
}
});
Object.defineProperty(exports, "prepareForSlot", {
enumerable: true,
get: function () {
return _prepareForSlot.prepareForSlot;
}
});
Object.defineProperty(exports, "resolveComponentProps", {
enumerable: true,
get: function () {
return _resolveComponentProps.resolveComponentProps;
}
});
Object.defineProperty(exports, "useRootElementName", {
enumerable: true,
get: function () {
return _useRootElementName.useRootElementName;
}
});
Object.defineProperty(exports, "useSlotProps", {
enumerable: true,
get: function () {
return _useSlotProps.useSlotProps;
}
});
var _appendOwnerState = require("./appendOwnerState");
var _areArraysEqual = require("./areArraysEqual");
var _ClassNameConfigurator = require("./ClassNameConfigurator");
var _extractEventHandlers = require("./extractEventHandlers");
var _isHostComponent = require("./isHostComponent");
var _resolveComponentProps = require("./resolveComponentProps");
var _useRootElementName = require("./useRootElementName");
var _useSlotProps = require("./useSlotProps");
var _mergeSlotProps = require("./mergeSlotProps");
var _prepareForSlot = require("./prepareForSlot");
var _PolymorphicComponent = require("./PolymorphicComponent");
Object.keys(_PolymorphicComponent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _PolymorphicComponent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _PolymorphicComponent[key];
}
});
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _types[key];
}
});
});
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isHostComponent = isHostComponent;
/**
* Determines if a given element is a DOM element name (i.e. not a React component).
*/
function isHostComponent(element) {
return typeof element === 'string';
}
+76
View File
@@ -0,0 +1,76 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mergeSlotProps = mergeSlotProps;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _clsx = _interopRequireDefault(require("clsx"));
var _extractEventHandlers = require("./extractEventHandlers");
var _omitEventHandlers = require("./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
*/
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 = (0, _clsx.default)(additionalProps == null ? void 0 : additionalProps.className, className, externalForwardedProps == null ? void 0 : externalForwardedProps.className, externalSlotProps == null ? void 0 : externalSlotProps.className);
const mergedStyle = (0, _extends2.default)({}, additionalProps == null ? void 0 : additionalProps.style, externalForwardedProps == null ? void 0 : externalForwardedProps.style, externalSlotProps == null ? void 0 : externalSlotProps.style);
const props = (0, _extends2.default)({}, 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 = (0, _extractEventHandlers.extractEventHandlers)((0, _extends2.default)({}, externalForwardedProps, externalSlotProps));
const componentsPropsWithoutEventHandlers = (0, _omitEventHandlers.omitEventHandlers)(externalSlotProps);
const otherPropsWithoutEventHandlers = (0, _omitEventHandlers.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 = (0, _clsx.default)(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 = (0, _extends2.default)({}, 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 = (0, _extends2.default)({}, 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
};
}
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.omitEventHandlers = omitEventHandlers;
/**
* 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.
*/
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;
}
+21
View File
@@ -0,0 +1,21 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prepareForSlot = prepareForSlot;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
const _excluded = ["ownerState"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function prepareForSlot(Component) {
return /*#__PURE__*/React.forwardRef(function Slot(props, ref) {
const other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({}, other, {
ref
}));
});
}
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveComponentProps = resolveComponentProps;
/**
* If `componentProps` is a function, calls it with the provided `ownerState`.
* Otherwise, just returns `componentProps`.
*/
function resolveComponentProps(componentProps, ownerState, slotState) {
if (typeof componentProps === 'function') {
return componentProps(ownerState, slotState);
}
return componentProps;
}
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
+143
View File
@@ -0,0 +1,143 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useControllableReducer = useControllableReducer;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function areEqual(a, b) {
return a === b;
}
const EMPTY_OBJECT = {};
const NOOP = () => {};
/**
* Gets the current state augmented with controlled values from the outside.
* If a state item has a corresponding controlled value, it will be used instead of the internal state.
*/
function getControlledState(internalState, controlledProps) {
const augmentedState = (0, _extends2.default)({}, internalState);
Object.keys(controlledProps).forEach(key => {
if (controlledProps[key] !== undefined) {
augmentedState[key] = controlledProps[key];
}
});
return augmentedState;
}
/**
* Defines an effect that compares the next state with the previous state and calls
* the `onStateChange` callback if the state has changed.
* The comparison is done based on the `stateComparers` parameter.
*/
function useStateChangeDetection(parameters) {
const {
nextState,
initialState,
stateComparers,
onStateChange,
controlledProps,
lastActionRef
} = parameters;
const internalPreviousStateRef = React.useRef(initialState);
React.useEffect(() => {
if (lastActionRef.current === null) {
// Detect changes only if an action has been dispatched.
return;
}
const previousState = getControlledState(internalPreviousStateRef.current, controlledProps);
Object.keys(nextState).forEach(key => {
var _stateComparers$key;
// go through all state keys and compare them with the previous state
const stateComparer = (_stateComparers$key = stateComparers[key]) != null ? _stateComparers$key : areEqual;
const nextStateItem = nextState[key];
const previousStateItem = previousState[key];
if (previousStateItem == null && nextStateItem != null || previousStateItem != null && nextStateItem == null || previousStateItem != null && nextStateItem != null && !stateComparer(nextStateItem, previousStateItem)) {
var _event, _type;
onStateChange == null || onStateChange((_event = lastActionRef.current.event) != null ? _event : null, key, nextStateItem, (_type = lastActionRef.current.type) != null ? _type : '', nextState);
}
});
internalPreviousStateRef.current = nextState;
lastActionRef.current = null;
}, [internalPreviousStateRef, nextState, lastActionRef, onStateChange, stateComparers, controlledProps]);
}
/**
* The alternative to `React.useReducer` that lets you control the state from the outside.
*
* It can be used in an uncontrolled mode, similar to `React.useReducer`, or in a controlled mode, when the state is controlled by the props.
* It also supports partially controlled state, when some state items are controlled and some are not.
*
* The controlled state items are provided via the `controlledProps` parameter.
* When a reducer action is dispatched, the internal state is updated with the new values.
* A change event (`onStateChange`) is then triggered (for each changed state item) if the new state is different from the previous state.
* This event can be used to update the controlled values.
*
* The comparison of the previous and next states is done using the `stateComparers` parameter.
* If a state item has a corresponding comparer, it will be used to determine if the state has changed.
* This is useful when the state item is an object and you want to compare only a subset of its properties or if it's an array and you want to compare its contents.
*
* An additional feature is the `actionContext` parameter. It allows you to add additional properties to every action object,
* similarly to how React context is implicitly available to every component.
*
* @template State - The type of the state calculated by the reducer.
* @template Action - The type of the actions that can be dispatched.
* @template ActionContext - The type of the additional properties that will be added to every action object.
*
* @ignore - internal hook.
*/
function useControllableReducer(parameters) {
const lastActionRef = React.useRef(null);
const {
reducer,
initialState,
controlledProps = EMPTY_OBJECT,
stateComparers = EMPTY_OBJECT,
onStateChange = NOOP,
actionContext,
componentName = ''
} = parameters;
const controlledPropsRef = React.useRef(controlledProps);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
Object.keys(controlledProps).forEach(key => {
if (controlledPropsRef.current[key] !== undefined && controlledProps[key] === undefined) {
console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing a controlled prop to be uncontrolled: ${key}`);
}
if (controlledPropsRef.current[key] === undefined && controlledProps[key] !== undefined) {
console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing an uncontrolled prop to be controlled: ${key}`);
}
});
}, [controlledProps, componentName]);
}
// The reducer that is passed to React.useReducer is wrapped with a function that augments the state with controlled values.
const reducerWithControlledState = React.useCallback((state, action) => {
lastActionRef.current = action;
const controlledState = getControlledState(state, controlledProps);
const newState = reducer(controlledState, action);
return newState;
}, [controlledProps, reducer]);
const [nextState, dispatch] = React.useReducer(reducerWithControlledState, initialState);
// The action that is passed to dispatch is augmented with the actionContext.
const dispatchWithContext = React.useCallback(action => {
dispatch((0, _extends2.default)({}, action, {
context: actionContext
}));
}, [actionContext]);
useStateChangeDetection({
nextState,
initialState,
stateComparers: stateComparers != null ? stateComparers : EMPTY_OBJECT,
onStateChange: onStateChange != null ? onStateChange : NOOP,
controlledProps,
lastActionRef
});
return [getControlledState(nextState, controlledProps), dispatchWithContext];
}
+5
View File
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
+19
View File
@@ -0,0 +1,19 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useForcedRerendering = useForcedRerendering;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* @ignore - internal hook.
*/
function useForcedRerendering() {
const [, setState] = React.useState({});
return React.useCallback(() => {
setState({});
}, []);
}
+50
View File
@@ -0,0 +1,50 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createMessageBus = createMessageBus;
exports.useMessageBus = useMessageBus;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function createMessageBus() {
const listeners = new Map();
function subscribe(topic, callback) {
let topicListeners = listeners.get(topic);
if (!topicListeners) {
topicListeners = new Set([callback]);
listeners.set(topic, topicListeners);
} else {
topicListeners.add(callback);
}
return () => {
topicListeners.delete(callback);
if (topicListeners.size === 0) {
listeners.delete(topic);
}
};
}
function publish(topic, ...args) {
const topicListeners = listeners.get(topic);
if (topicListeners) {
topicListeners.forEach(callback => callback(...args));
}
}
return {
subscribe,
publish
};
}
/**
* @ignore - internal hook.
*/
function useMessageBus() {
const bus = React.useRef();
if (!bus.current) {
bus.current = createMessageBus();
}
return bus.current;
}
+35
View File
@@ -0,0 +1,35 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useRootElementName = useRootElementName;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* @ignore - do not document.
*
* Use this function determine the host element correctly on the server (in a SSR context, for example Next.js)
*/
function useRootElementName(parameters) {
const {
rootElementName: rootElementNameProp = '',
componentName
} = parameters;
const [rootElementName, setRootElementName] = React.useState(rootElementNameProp.toUpperCase());
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
if (rootElementNameProp && rootElementName !== rootElementNameProp.toUpperCase()) {
console.error(`useRootElementName: the \`rootElementName\` prop of ${componentName ? `the ${componentName} component` : 'a component'} expected the '${rootElementNameProp}' element, but a '${rootElementName.toLowerCase()}' was rendered instead`, 'This may cause hydration issues in an SSR context, for example in a Next.js app');
}
}, [rootElementNameProp, rootElementName, componentName]);
}
const updateRootElementName = React.useCallback(instance => {
var _instance$tagName;
setRootElementName((_instance$tagName = instance == null ? void 0 : instance.tagName) != null ? _instance$tagName : '');
}, []);
return [rootElementName, updateRootElementName];
}
+45
View File
@@ -0,0 +1,45 @@
"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useSlotProps = useSlotProps;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _utils = require("@mui/utils");
var _appendOwnerState = require("./appendOwnerState");
var _mergeSlotProps = require("./mergeSlotProps");
var _resolveComponentProps = require("./resolveComponentProps");
const _excluded = ["elementType", "externalSlotProps", "ownerState", "skipResolvingSlotProps"];
/**
* @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.
*/
function useSlotProps(parameters) {
var _parameters$additiona;
const {
elementType,
externalSlotProps,
ownerState,
skipResolvingSlotProps = false
} = parameters,
rest = (0, _objectWithoutPropertiesLoose2.default)(parameters, _excluded);
const resolvedComponentsProps = skipResolvingSlotProps ? {} : (0, _resolveComponentProps.resolveComponentProps)(externalSlotProps, ownerState);
const {
props: mergedProps,
internalRef
} = (0, _mergeSlotProps.mergeSlotProps)((0, _extends2.default)({}, rest, {
externalSlotProps: resolvedComponentsProps
}));
const ref = (0, _utils.unstable_useForkRef)(internalRef, resolvedComponentsProps == null ? void 0 : resolvedComponentsProps.ref, (_parameters$additiona = parameters.additionalProps) == null ? void 0 : _parameters$additiona.ref);
const props = (0, _appendOwnerState.appendOwnerState)(elementType, (0, _extends2.default)({}, mergedProps, {
ref
}), ownerState);
return props;
}
+42
View File
@@ -0,0 +1,42 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useTextNavigation = useTextNavigation;
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const TEXT_NAVIGATION_RESET_TIMEOUT = 500; // milliseconds
/**
* @ignore - internal hook.
*
* Provides a handler for text navigation.
* It's used to navigate a list by typing the first letters of the options.
*
* @param callback A function to be called when the navigation should be performed.
* @returns A function to be used in a keydown event handler.
*/
function useTextNavigation(callback) {
const textCriteriaRef = React.useRef({
searchString: '',
lastTime: null
});
return React.useCallback(event => {
if (event.key.length === 1 && event.key !== ' ') {
const textCriteria = textCriteriaRef.current;
const lowerKey = event.key.toLowerCase();
const currentTime = performance.now();
if (textCriteria.searchString.length > 0 && textCriteria.lastTime && currentTime - textCriteria.lastTime > TEXT_NAVIGATION_RESET_TIMEOUT) {
textCriteria.searchString = lowerKey;
} else if (textCriteria.searchString.length !== 1 || lowerKey !== textCriteria.searchString) {
// If there is just one character in the buffer and the key is the same, do not append
textCriteria.searchString += lowerKey;
}
textCriteria.lastTime = currentTime;
callback(textCriteria.searchString, event);
}
}, [callback]);
}