1 line
13 KiB
JSON
1 line
13 KiB
JSON
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nconst _excluded = [\"stateId\"];\nimport * as React from 'react';\nimport { GridSignature } from '../utils/useGridApiEventHandler';\nimport { useGridApiMethod } from '../utils';\nimport { isFunction } from '../../utils/utils';\nexport const useGridStateInitialization = (apiRef, props) => {\n const controlStateMapRef = React.useRef({});\n const [, rawForceUpdate] = React.useState();\n const registerControlState = React.useCallback(controlStateItem => {\n const {\n stateId\n } = controlStateItem,\n others = _objectWithoutPropertiesLoose(controlStateItem, _excluded);\n controlStateMapRef.current[stateId] = _extends({}, others, {\n stateId\n });\n }, []);\n const setState = React.useCallback((state, reason) => {\n let newState;\n if (isFunction(state)) {\n newState = state(apiRef.current.state);\n } else {\n newState = state;\n }\n if (apiRef.current.state === newState) {\n return false;\n }\n let ignoreSetState = false; // Apply the control state constraints\n\n const updatedControlStateIds = [];\n Object.keys(controlStateMapRef.current).forEach(stateId => {\n const controlState = controlStateMapRef.current[stateId];\n const oldSubState = controlState.stateSelector(apiRef.current.state, apiRef.current.instanceId);\n const newSubState = controlState.stateSelector(newState, apiRef.current.instanceId);\n if (newSubState === oldSubState) {\n return;\n }\n updatedControlStateIds.push({\n stateId: controlState.stateId,\n hasPropChanged: newSubState !== controlState.propModel\n }); // The state is controlled, the prop should always win\n\n if (controlState.propModel !== undefined && newSubState !== controlState.propModel) {\n ignoreSetState = true;\n }\n });\n if (updatedControlStateIds.length > 1) {\n // Each hook modify its own state, and it should not leak\n // Events are here to forward to other hooks and apply changes.\n // You are trying to update several states in a no isolated way.\n throw new Error(`You're not allowed to update several sub-state in one transaction. You already updated ${updatedControlStateIds[0].stateId}, therefore, you're not allowed to update ${updatedControlStateIds.map(el => el.stateId).join(', ')} in the same transaction.`);\n }\n if (!ignoreSetState) {\n // We always assign it as we mutate rows for perf reason.\n apiRef.current.state = newState;\n if (apiRef.current.publishEvent) {\n apiRef.current.publishEvent('stateChange', newState);\n }\n }\n if (updatedControlStateIds.length === 1) {\n const {\n stateId,\n hasPropChanged\n } = updatedControlStateIds[0];\n const controlState = controlStateMapRef.current[stateId];\n const model = controlState.stateSelector(newState, apiRef.current.instanceId);\n if (controlState.propOnChange && hasPropChanged) {\n const details = props.signature === GridSignature.DataGridPro ? {\n api: apiRef.current,\n reason\n } : {\n reason\n };\n controlState.propOnChange(model, details);\n }\n if (!ignoreSetState) {\n apiRef.current.publishEvent(controlState.changeEvent, model, {\n reason\n });\n }\n }\n return !ignoreSetState;\n }, [apiRef, props.signature]);\n const updateControlState = React.useCallback((key, state, reason) => {\n return apiRef.current.setState(previousState => {\n return _extends({}, previousState, {\n [key]: state(previousState[key])\n });\n }, reason);\n }, [apiRef]);\n const forceUpdate = React.useCallback(() => rawForceUpdate(() => apiRef.current.state), [apiRef]);\n const stateApi = {\n setState,\n forceUpdate,\n unstable_updateControlState: updateControlState,\n unstable_registerControlState: registerControlState\n };\n useGridApiMethod(apiRef, stateApi, 'GridStateApi');\n};","map":{"version":3,"names":["_extends","_objectWithoutPropertiesLoose","_excluded","React","GridSignature","useGridApiMethod","isFunction","useGridStateInitialization","apiRef","props","controlStateMapRef","useRef","rawForceUpdate","useState","registerControlState","useCallback","controlStateItem","stateId","others","current","setState","state","reason","newState","ignoreSetState","updatedControlStateIds","Object","keys","forEach","controlState","oldSubState","stateSelector","instanceId","newSubState","push","hasPropChanged","propModel","undefined","length","Error","map","el","join","publishEvent","model","propOnChange","details","signature","DataGridPro","api","changeEvent","updateControlState","key","previousState","forceUpdate","stateApi","unstable_updateControlState","unstable_registerControlState"],"sources":["/home/gnx/Desktop/ETB/ETB-FrontEnd/node_modules/@mui/x-data-grid/hooks/core/useGridStateInitialization.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nconst _excluded = [\"stateId\"];\nimport * as React from 'react';\nimport { GridSignature } from '../utils/useGridApiEventHandler';\nimport { useGridApiMethod } from '../utils';\nimport { isFunction } from '../../utils/utils';\nexport const useGridStateInitialization = (apiRef, props) => {\n const controlStateMapRef = React.useRef({});\n const [, rawForceUpdate] = React.useState();\n const registerControlState = React.useCallback(controlStateItem => {\n const {\n stateId\n } = controlStateItem,\n others = _objectWithoutPropertiesLoose(controlStateItem, _excluded);\n\n controlStateMapRef.current[stateId] = _extends({}, others, {\n stateId\n });\n }, []);\n const setState = React.useCallback((state, reason) => {\n let newState;\n\n if (isFunction(state)) {\n newState = state(apiRef.current.state);\n } else {\n newState = state;\n }\n\n if (apiRef.current.state === newState) {\n return false;\n }\n\n let ignoreSetState = false; // Apply the control state constraints\n\n const updatedControlStateIds = [];\n Object.keys(controlStateMapRef.current).forEach(stateId => {\n const controlState = controlStateMapRef.current[stateId];\n const oldSubState = controlState.stateSelector(apiRef.current.state, apiRef.current.instanceId);\n const newSubState = controlState.stateSelector(newState, apiRef.current.instanceId);\n\n if (newSubState === oldSubState) {\n return;\n }\n\n updatedControlStateIds.push({\n stateId: controlState.stateId,\n hasPropChanged: newSubState !== controlState.propModel\n }); // The state is controlled, the prop should always win\n\n if (controlState.propModel !== undefined && newSubState !== controlState.propModel) {\n ignoreSetState = true;\n }\n });\n\n if (updatedControlStateIds.length > 1) {\n // Each hook modify its own state, and it should not leak\n // Events are here to forward to other hooks and apply changes.\n // You are trying to update several states in a no isolated way.\n throw new Error(`You're not allowed to update several sub-state in one transaction. You already updated ${updatedControlStateIds[0].stateId}, therefore, you're not allowed to update ${updatedControlStateIds.map(el => el.stateId).join(', ')} in the same transaction.`);\n }\n\n if (!ignoreSetState) {\n // We always assign it as we mutate rows for perf reason.\n apiRef.current.state = newState;\n\n if (apiRef.current.publishEvent) {\n apiRef.current.publishEvent('stateChange', newState);\n }\n }\n\n if (updatedControlStateIds.length === 1) {\n const {\n stateId,\n hasPropChanged\n } = updatedControlStateIds[0];\n const controlState = controlStateMapRef.current[stateId];\n const model = controlState.stateSelector(newState, apiRef.current.instanceId);\n\n if (controlState.propOnChange && hasPropChanged) {\n const details = props.signature === GridSignature.DataGridPro ? {\n api: apiRef.current,\n reason\n } : {\n reason\n };\n controlState.propOnChange(model, details);\n }\n\n if (!ignoreSetState) {\n apiRef.current.publishEvent(controlState.changeEvent, model, {\n reason\n });\n }\n }\n\n return !ignoreSetState;\n }, [apiRef, props.signature]);\n const updateControlState = React.useCallback((key, state, reason) => {\n return apiRef.current.setState(previousState => {\n return _extends({}, previousState, {\n [key]: state(previousState[key])\n });\n }, reason);\n }, [apiRef]);\n const forceUpdate = React.useCallback(() => rawForceUpdate(() => apiRef.current.state), [apiRef]);\n const stateApi = {\n setState,\n forceUpdate,\n unstable_updateControlState: updateControlState,\n unstable_registerControlState: registerControlState\n };\n useGridApiMethod(apiRef, stateApi, 'GridStateApi');\n};"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAOC,6BAA6B,MAAM,yDAAyD;AACnG,MAAMC,SAAS,GAAG,CAAC,SAAS,CAAC;AAC7B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,aAAa,QAAQ,iCAAiC;AAC/D,SAASC,gBAAgB,QAAQ,UAAU;AAC3C,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,OAAO,MAAMC,0BAA0B,GAAGA,CAACC,MAAM,EAAEC,KAAK,KAAK;EAC3D,MAAMC,kBAAkB,GAAGP,KAAK,CAACQ,MAAM,CAAC,CAAC,CAAC,CAAC;EAC3C,MAAM,GAAGC,cAAc,CAAC,GAAGT,KAAK,CAACU,QAAQ,CAAC,CAAC;EAC3C,MAAMC,oBAAoB,GAAGX,KAAK,CAACY,WAAW,CAACC,gBAAgB,IAAI;IACjE,MAAM;QACJC;MACF,CAAC,GAAGD,gBAAgB;MACdE,MAAM,GAAGjB,6BAA6B,CAACe,gBAAgB,EAAEd,SAAS,CAAC;IA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