1 line
17 KiB
JSON
1 line
17 KiB
JSON
{"ast":null,"code":"'use client';\n\nimport _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nfunction areEqual(a, b) {\n return a === b;\n}\nconst EMPTY_OBJECT = {};\nconst NOOP = () => {};\n\n/**\n * Gets the current state augmented with controlled values from the outside.\n * If a state item has a corresponding controlled value, it will be used instead of the internal state.\n */\nfunction getControlledState(internalState, controlledProps) {\n const augmentedState = _extends({}, internalState);\n Object.keys(controlledProps).forEach(key => {\n if (controlledProps[key] !== undefined) {\n augmentedState[key] = controlledProps[key];\n }\n });\n return augmentedState;\n}\n/**\n * Defines an effect that compares the next state with the previous state and calls\n * the `onStateChange` callback if the state has changed.\n * The comparison is done based on the `stateComparers` parameter.\n */\nfunction useStateChangeDetection(parameters) {\n const {\n nextState,\n initialState,\n stateComparers,\n onStateChange,\n controlledProps,\n lastActionRef\n } = parameters;\n const internalPreviousStateRef = React.useRef(initialState);\n React.useEffect(() => {\n if (lastActionRef.current === null) {\n // Detect changes only if an action has been dispatched.\n return;\n }\n const previousState = getControlledState(internalPreviousStateRef.current, controlledProps);\n Object.keys(nextState).forEach(key => {\n var _stateComparers$key;\n // go through all state keys and compare them with the previous state\n const stateComparer = (_stateComparers$key = stateComparers[key]) != null ? _stateComparers$key : areEqual;\n const nextStateItem = nextState[key];\n const previousStateItem = previousState[key];\n if (previousStateItem == null && nextStateItem != null || previousStateItem != null && nextStateItem == null || previousStateItem != null && nextStateItem != null && !stateComparer(nextStateItem, previousStateItem)) {\n var _event, _type;\n onStateChange == null || onStateChange((_event = lastActionRef.current.event) != null ? _event : null, key, nextStateItem, (_type = lastActionRef.current.type) != null ? _type : '', nextState);\n }\n });\n internalPreviousStateRef.current = nextState;\n lastActionRef.current = null;\n }, [internalPreviousStateRef, nextState, lastActionRef, onStateChange, stateComparers, controlledProps]);\n}\n\n/**\n * The alternative to `React.useReducer` that lets you control the state from the outside.\n *\n * 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.\n * It also supports partially controlled state, when some state items are controlled and some are not.\n *\n * The controlled state items are provided via the `controlledProps` parameter.\n * When a reducer action is dispatched, the internal state is updated with the new values.\n * A change event (`onStateChange`) is then triggered (for each changed state item) if the new state is different from the previous state.\n * This event can be used to update the controlled values.\n *\n * The comparison of the previous and next states is done using the `stateComparers` parameter.\n * If a state item has a corresponding comparer, it will be used to determine if the state has changed.\n * 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.\n *\n * An additional feature is the `actionContext` parameter. It allows you to add additional properties to every action object,\n * similarly to how React context is implicitly available to every component.\n *\n * @template State - The type of the state calculated by the reducer.\n * @template Action - The type of the actions that can be dispatched.\n * @template ActionContext - The type of the additional properties that will be added to every action object.\n *\n * @ignore - internal hook.\n */\nexport function useControllableReducer(parameters) {\n const lastActionRef = React.useRef(null);\n const {\n reducer,\n initialState,\n controlledProps = EMPTY_OBJECT,\n stateComparers = EMPTY_OBJECT,\n onStateChange = NOOP,\n actionContext,\n componentName = ''\n } = parameters;\n const controlledPropsRef = React.useRef(controlledProps);\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n Object.keys(controlledProps).forEach(key => {\n if (controlledPropsRef.current[key] !== undefined && controlledProps[key] === undefined) {\n console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing a controlled prop to be uncontrolled: ${key}`);\n }\n if (controlledPropsRef.current[key] === undefined && controlledProps[key] !== undefined) {\n console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing an uncontrolled prop to be controlled: ${key}`);\n }\n });\n }, [controlledProps, componentName]);\n }\n\n // The reducer that is passed to React.useReducer is wrapped with a function that augments the state with controlled values.\n const reducerWithControlledState = React.useCallback((state, action) => {\n lastActionRef.current = action;\n const controlledState = getControlledState(state, controlledProps);\n const newState = reducer(controlledState, action);\n return newState;\n }, [controlledProps, reducer]);\n const [nextState, dispatch] = React.useReducer(reducerWithControlledState, initialState);\n\n // The action that is passed to dispatch is augmented with the actionContext.\n const dispatchWithContext = React.useCallback(action => {\n dispatch(_extends({}, action, {\n context: actionContext\n }));\n }, [actionContext]);\n useStateChangeDetection({\n nextState,\n initialState,\n stateComparers: stateComparers != null ? stateComparers : EMPTY_OBJECT,\n onStateChange: onStateChange != null ? onStateChange : NOOP,\n controlledProps,\n lastActionRef\n });\n return [getControlledState(nextState, controlledProps), dispatchWithContext];\n}","map":{"version":3,"names":["_extends","React","areEqual","a","b","EMPTY_OBJECT","NOOP","getControlledState","internalState","controlledProps","augmentedState","Object","keys","forEach","key","undefined","useStateChangeDetection","parameters","nextState","initialState","stateComparers","onStateChange","lastActionRef","internalPreviousStateRef","useRef","useEffect","current","previousState","_stateComparers$key","stateComparer","nextStateItem","previousStateItem","_event","_type","event","type","useControllableReducer","reducer","actionContext","componentName","controlledPropsRef","process","env","NODE_ENV","console","error","reducerWithControlledState","useCallback","state","action","controlledState","newState","dispatch","useReducer","dispatchWithContext","context"],"sources":["/home/gnx/Desktop/ETB/ETB-FrontEnd/node_modules/@mui/base/utils/useControllableReducer.js"],"sourcesContent":["'use client';\n\nimport _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nfunction areEqual(a, b) {\n return a === b;\n}\nconst EMPTY_OBJECT = {};\nconst NOOP = () => {};\n\n/**\n * Gets the current state augmented with controlled values from the outside.\n * If a state item has a corresponding controlled value, it will be used instead of the internal state.\n */\nfunction getControlledState(internalState, controlledProps) {\n const augmentedState = _extends({}, internalState);\n Object.keys(controlledProps).forEach(key => {\n if (controlledProps[key] !== undefined) {\n augmentedState[key] = controlledProps[key];\n }\n });\n return augmentedState;\n}\n/**\n * Defines an effect that compares the next state with the previous state and calls\n * the `onStateChange` callback if the state has changed.\n * The comparison is done based on the `stateComparers` parameter.\n */\nfunction useStateChangeDetection(parameters) {\n const {\n nextState,\n initialState,\n stateComparers,\n onStateChange,\n controlledProps,\n lastActionRef\n } = parameters;\n const internalPreviousStateRef = React.useRef(initialState);\n React.useEffect(() => {\n if (lastActionRef.current === null) {\n // Detect changes only if an action has been dispatched.\n return;\n }\n const previousState = getControlledState(internalPreviousStateRef.current, controlledProps);\n Object.keys(nextState).forEach(key => {\n var _stateComparers$key;\n // go through all state keys and compare them with the previous state\n const stateComparer = (_stateComparers$key = stateComparers[key]) != null ? _stateComparers$key : areEqual;\n const nextStateItem = nextState[key];\n const previousStateItem = previousState[key];\n if (previousStateItem == null && nextStateItem != null || previousStateItem != null && nextStateItem == null || previousStateItem != null && nextStateItem != null && !stateComparer(nextStateItem, previousStateItem)) {\n var _event, _type;\n onStateChange == null || onStateChange((_event = lastActionRef.current.event) != null ? _event : null, key, nextStateItem, (_type = lastActionRef.current.type) != null ? _type : '', nextState);\n }\n });\n internalPreviousStateRef.current = nextState;\n lastActionRef.current = null;\n }, [internalPreviousStateRef, nextState, lastActionRef, onStateChange, stateComparers, controlledProps]);\n}\n\n/**\n * The alternative to `React.useReducer` that lets you control the state from the outside.\n *\n * 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.\n * It also supports partially controlled state, when some state items are controlled and some are not.\n *\n * The controlled state items are provided via the `controlledProps` parameter.\n * When a reducer action is dispatched, the internal state is updated with the new values.\n * A change event (`onStateChange`) is then triggered (for each changed state item) if the new state is different from the previous state.\n * This event can be used to update the controlled values.\n *\n * The comparison of the previous and next states is done using the `stateComparers` parameter.\n * If a state item has a corresponding comparer, it will be used to determine if the state has changed.\n * 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.\n *\n * An additional feature is the `actionContext` parameter. It allows you to add additional properties to every action object,\n * similarly to how React context is implicitly available to every component.\n *\n * @template State - The type of the state calculated by the reducer.\n * @template Action - The type of the actions that can be dispatched.\n * @template ActionContext - The type of the additional properties that will be added to every action object.\n *\n * @ignore - internal hook.\n */\nexport function useControllableReducer(parameters) {\n const lastActionRef = React.useRef(null);\n const {\n reducer,\n initialState,\n controlledProps = EMPTY_OBJECT,\n stateComparers = EMPTY_OBJECT,\n onStateChange = NOOP,\n actionContext,\n componentName = ''\n } = parameters;\n const controlledPropsRef = React.useRef(controlledProps);\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n Object.keys(controlledProps).forEach(key => {\n if (controlledPropsRef.current[key] !== undefined && controlledProps[key] === undefined) {\n console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing a controlled prop to be uncontrolled: ${key}`);\n }\n if (controlledPropsRef.current[key] === undefined && controlledProps[key] !== undefined) {\n console.error(`useControllableReducer: ${componentName ? `The ${componentName} component` : 'A component'} is changing an uncontrolled prop to be controlled: ${key}`);\n }\n });\n }, [controlledProps, componentName]);\n }\n\n // The reducer that is passed to React.useReducer is wrapped with a function that augments the state with controlled values.\n const reducerWithControlledState = React.useCallback((state, action) => {\n lastActionRef.current = action;\n const controlledState = getControlledState(state, controlledProps);\n const newState = reducer(controlledState, action);\n return newState;\n }, [controlledProps, reducer]);\n const [nextState, dispatch] = React.useReducer(reducerWithControlledState, initialState);\n\n // The action that is passed to dispatch is augmented with the actionContext.\n const dispatchWithContext = React.useCallback(action => {\n dispatch(_extends({}, action, {\n context: actionContext\n }));\n }, [actionContext]);\n useStateChangeDetection({\n nextState,\n initialState,\n stateComparers: stateComparers != null ? stateComparers : EMPTY_OBJECT,\n onStateChange: onStateChange != null ? onStateChange : NOOP,\n controlledProps,\n lastActionRef\n });\n return [getControlledState(nextState, controlledProps), dispatchWithContext];\n}"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQA,CAACC,CAAC,EAAEC,CAAC,EAAE;EACtB,OAAOD,CAAC,KAAKC,CAAC;AAChB;AACA,MAAMC,YAAY,GAAG,CAAC,CAAC;AACvB,MAAMC,IAA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