UNPKG

next-csrf

Version:

CSRF mitigation library for Next.js

1 lines 5.75 kB
{"ast":null,"code":"\"use strict\";\n\nvar _toConsumableArray = require(\"@babel/runtime/helpers/toConsumableArray\");\n\nvar _classCallCheck = require(\"@babel/runtime/helpers/classCallCheck\");\n\nvar _createClass = require(\"@babel/runtime/helpers/createClass\");\n\nvar _assertThisInitialized = require(\"@babel/runtime/helpers/assertThisInitialized\");\n\nvar _inherits = require(\"@babel/runtime/helpers/inherits\");\n\nvar _possibleConstructorReturn = require(\"@babel/runtime/helpers/possibleConstructorReturn\");\n\nvar _getPrototypeOf = require(\"@babel/runtime/helpers/getPrototypeOf\");\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nexports.__esModule = true;\nexports[\"default\"] = void 0;\n\nvar _react = require(\"react\");\n\nvar isServer = false;\n\nvar _default = /*#__PURE__*/function (_react$Component) {\n _inherits(_default, _react$Component);\n\n var _super = _createSuper(_default);\n\n function _default(props) {\n var _this;\n\n _classCallCheck(this, _default);\n\n _this = _super.call(this, props);\n _this._hasHeadManager = void 0;\n\n _this.emitChange = function () {\n if (_this._hasHeadManager) {\n _this.props.headManager.updateHead(_this.props.reduceComponentsToState(_toConsumableArray(_this.props.headManager.mountedInstances), _this.props));\n }\n };\n\n _this._hasHeadManager = _this.props.headManager && _this.props.headManager.mountedInstances;\n\n if (isServer && _this._hasHeadManager) {\n _this.props.headManager.mountedInstances.add(_assertThisInitialized(_this));\n\n _this.emitChange();\n }\n\n return _this;\n }\n\n _createClass(_default, [{\n key: \"componentDidMount\",\n value: function componentDidMount() {\n if (this._hasHeadManager) {\n this.props.headManager.mountedInstances.add(this);\n }\n\n this.emitChange();\n }\n }, {\n key: \"componentDidUpdate\",\n value: function componentDidUpdate() {\n this.emitChange();\n }\n }, {\n key: \"componentWillUnmount\",\n value: function componentWillUnmount() {\n if (this._hasHeadManager) {\n this.props.headManager.mountedInstances[\"delete\"](this);\n }\n\n this.emitChange();\n }\n }, {\n key: \"render\",\n value: function render() {\n return null;\n }\n }]);\n\n return _default;\n}(_react.Component);\n\nexports[\"default\"] = _default;","map":{"version":3,"sources":["../../../next-server/lib/side-effect.tsx"],"names":["isServer","Component","_hasHeadManager","emitChange","constructor","componentDidMount","componentDidUpdate","componentWillUnmount","render"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,MAAA,GAAA,OAAA,CAAA,OAAA,CAAA;;AAEA,IAAMA,QAAN,QAAA;;IAce,Q;;;;;AAcbI,oBAAW,KAAXA,EAAwB;AAAA;;AAAA;;AACtB,8BAAA,KAAA;AADsB,UAbhBF,eAagB,GAAA,KAAA,CAAA;;AAAA,UAXxBC,UAWwB,GAXX,YAAY;AACvB,UAAI,MAAJ,eAAA,EAA0B;AACxB,cAAA,KAAA,CAAA,WAAA,CAAA,UAAA,CACE,MAAA,KAAA,CAAA,uBAAA,oBACM,MAAA,KAAA,CAAA,WAAA,CADN,gBAAA,GAEE,MAHJ,KACE,CADF;AAOH;AAEuB,KAAA;;AAEtB,UAAA,eAAA,GACE,MAAA,KAAA,CAAA,WAAA,IAA0B,MAAA,KAAA,CAAA,WAAA,CAD5B,gBAAA;;AAGA,QAAIH,QAAQ,IAAI,MAAhB,eAAA,EAAsC;AACpC,YAAA,KAAA,CAAA,WAAA,CAAA,gBAAA,CAAA,GAAA;;AACA,YAAA,UAAA;AAEH;;AATuB;AAUxBK;;;;WAAAA,6BAAoB;AAClB,UAAI,KAAJ,eAAA,EAA0B;AACxB,aAAA,KAAA,CAAA,WAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,IAAA;AAEF;;AAAA,WAAA,UAAA;AAEFC;;;WAAAA,8BAAqB;AACnB,WAAA,UAAA;AAEFC;;;WAAAA,gCAAuB;AACrB,UAAI,KAAJ,eAAA,EAA0B;AACxB,aAAA,KAAA,CAAA,WAAA,CAAA,gBAAA,WAAA,IAAA;AAEF;;AAAA,WAAA,UAAA;AAGFC;;;WAAAA,kBAAS;AACP,aAAA,IAAA;AAzCoD;;;;EAA3BP,MAAAA,CAAAA,S","sourcesContent":["import React, { Component } from 'react'\n\nconst isServer = typeof window === 'undefined'\n\ntype State = JSX.Element[] | undefined\n\ntype SideEffectProps = {\n reduceComponentsToState: <T>(\n components: Array<React.ReactElement<any>>,\n props: T\n ) => State\n handleStateChange?: (state: State) => void\n headManager: any\n inAmpMode?: boolean\n}\n\nexport default class extends Component<SideEffectProps> {\n private _hasHeadManager: boolean\n\n emitChange = (): void => {\n if (this._hasHeadManager) {\n this.props.headManager.updateHead(\n this.props.reduceComponentsToState(\n [...this.props.headManager.mountedInstances],\n this.props\n )\n )\n }\n }\n\n constructor(props: any) {\n super(props)\n this._hasHeadManager =\n this.props.headManager && this.props.headManager.mountedInstances\n\n if (isServer && this._hasHeadManager) {\n this.props.headManager.mountedInstances.add(this)\n this.emitChange()\n }\n }\n componentDidMount() {\n if (this._hasHeadManager) {\n this.props.headManager.mountedInstances.add(this)\n }\n this.emitChange()\n }\n componentDidUpdate() {\n this.emitChange()\n }\n componentWillUnmount() {\n if (this._hasHeadManager) {\n this.props.headManager.mountedInstances.delete(this)\n }\n this.emitChange()\n }\n\n render() {\n return null\n }\n}\n"]},"metadata":{},"sourceType":"script"}