UNPKG

create-dan

Version:

Dan frameworks

1 lines 15.4 kB
{"ast":null,"code":"\"use strict\";\n\nvar _Set = require(\"@babel/runtime-corejs2/core-js/set\");\n\nvar _Object$defineProperty = require(\"@babel/runtime-corejs2/core-js/object/define-property\");\n\nvar __importDefault = this && this.__importDefault || function (mod) {\n return mod && mod.__esModule ? mod : {\n \"default\": mod\n };\n};\n\n_Object$defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nconst react_1 = __importDefault(require(\"react\"));\n\nconst side_effect_1 = __importDefault(require(\"./side-effect\"));\n\nconst amp_context_1 = require(\"./amp-context\");\n\nconst head_manager_context_1 = require(\"./head-manager-context\");\n\nconst amp_1 = require(\"./amp\");\n\nfunction defaultHead(inAmpMode = false) {\n const head = [react_1.default.createElement(\"meta\", {\n charSet: \"utf-8\"\n })];\n\n if (!inAmpMode) {\n head.push(react_1.default.createElement(\"meta\", {\n name: \"viewport\",\n content: \"width=device-width,minimum-scale=1,initial-scale=1\"\n }));\n }\n\n return head;\n}\n\nexports.defaultHead = defaultHead;\n\nfunction onlyReactElement(list, child) {\n // React children can be \"string\" or \"number\" in this case we ignore them for backwards compat\n if (typeof child === 'string' || typeof child === 'number') {\n return list;\n } // Adds support for React.Fragment\n\n\n if (child.type === react_1.default.Fragment) {\n return list.concat(react_1.default.Children.toArray(child.props.children).reduce((fragmentList, fragmentChild) => {\n if (typeof fragmentChild === 'string' || typeof fragmentChild === 'number') {\n return fragmentList;\n }\n\n return fragmentList.concat(fragmentChild);\n }, []));\n }\n\n return list.concat(child);\n}\n\nconst METATYPES = ['name', 'httpEquiv', 'charSet', 'itemProp'];\n/*\n returns a function for filtering head child elements\n which shouldn't be duplicated, like <title/>\n Also adds support for deduplicated `key` properties\n*/\n\nfunction unique() {\n const keys = new _Set();\n const tags = new _Set();\n const metaTypes = new _Set();\n const metaCategories = {};\n return h => {\n let unique = true;\n\n if (h.key && typeof h.key !== 'number' && h.key.indexOf('$') > 0) {\n const key = h.key.slice(h.key.indexOf('$') + 1);\n\n if (keys.has(key)) {\n unique = false;\n } else {\n keys.add(key);\n }\n } // eslint-disable-next-line default-case\n\n\n switch (h.type) {\n case 'title':\n case 'base':\n if (tags.has(h.type)) {\n unique = false;\n } else {\n tags.add(h.type);\n }\n\n break;\n\n case 'meta':\n for (let i = 0, len = METATYPES.length; i < len; i++) {\n const metatype = METATYPES[i];\n if (!h.props.hasOwnProperty(metatype)) continue;\n\n if (metatype === 'charSet') {\n if (metaTypes.has(metatype)) {\n unique = false;\n } else {\n metaTypes.add(metatype);\n }\n } else {\n const category = h.props[metatype];\n const categories = metaCategories[metatype] || new _Set();\n\n if (categories.has(category)) {\n unique = false;\n } else {\n categories.add(category);\n metaCategories[metatype] = categories;\n }\n }\n }\n\n break;\n }\n\n return unique;\n };\n}\n/**\n *\n * @param headElement List of multiple <Head> instances\n */\n\n\nfunction reduceComponents(headElements, props) {\n return headElements.reduce((list, headElement) => {\n const headElementChildren = react_1.default.Children.toArray(headElement.props.children);\n return list.concat(headElementChildren);\n }, []).reduce(onlyReactElement, []).reverse().concat(defaultHead(props.inAmpMode)).filter(unique()).reverse().map((c, i) => {\n const key = c.key || i;\n return react_1.default.cloneElement(c, {\n key\n });\n });\n}\n\nconst Effect = side_effect_1.default();\n/**\n * This component injects elements to `<head>` of your page.\n * To avoid duplicated `tags` in `<head>` you can use the `key` property, which will make sure every tag is only rendered once.\n */\n\nfunction Head({\n children\n}) {\n return react_1.default.createElement(amp_context_1.AmpStateContext.Consumer, null, ampState => react_1.default.createElement(head_manager_context_1.HeadManagerContext.Consumer, null, updateHead => react_1.default.createElement(Effect, {\n reduceComponentsToState: reduceComponents,\n handleStateChange: updateHead,\n inAmpMode: amp_1.isInAmpMode(ampState)\n }, children)));\n}\n\nHead.rewind = Effect.rewind;\nexports.default = Head;","map":{"version":3,"sources":["/Users/sbourgal/Documents/Projets/DAN/dan-framework/template/node_modules/next/dist/next-server/lib/head.js"],"names":["__importDefault","mod","__esModule","exports","value","react_1","require","side_effect_1","amp_context_1","head_manager_context_1","amp_1","defaultHead","inAmpMode","head","default","createElement","charSet","push","name","content","onlyReactElement","list","child","type","Fragment","concat","Children","toArray","props","children","reduce","fragmentList","fragmentChild","METATYPES","unique","keys","tags","metaTypes","metaCategories","h","key","indexOf","slice","has","add","i","len","length","metatype","hasOwnProperty","category","categories","reduceComponents","headElements","headElement","headElementChildren","reverse","filter","map","c","cloneElement","Effect","Head","AmpStateContext","Consumer","ampState","HeadManagerContext","updateHead","reduceComponentsToState","handleStateChange","isInAmpMode","rewind"],"mappings":"AAAA;;;;;;AACA,IAAIA,eAAe,GAAI,QAAQ,KAAKA,eAAd,IAAkC,UAAUC,GAAV,EAAe;AACnE,SAAQA,GAAG,IAAIA,GAAG,CAACC,UAAZ,GAA0BD,GAA1B,GAAgC;AAAE,eAAWA;AAAb,GAAvC;AACH,CAFD;;AAGA,uBAAsBE,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,MAAMC,OAAO,GAAGL,eAAe,CAACM,OAAO,CAAC,OAAD,CAAR,CAA/B;;AACA,MAAMC,aAAa,GAAGP,eAAe,CAACM,OAAO,CAAC,eAAD,CAAR,CAArC;;AACA,MAAME,aAAa,GAAGF,OAAO,CAAC,eAAD,CAA7B;;AACA,MAAMG,sBAAsB,GAAGH,OAAO,CAAC,wBAAD,CAAtC;;AACA,MAAMI,KAAK,GAAGJ,OAAO,CAAC,OAAD,CAArB;;AACA,SAASK,WAAT,CAAqBC,SAAS,GAAG,KAAjC,EAAwC;AACpC,QAAMC,IAAI,GAAG,CAACR,OAAO,CAACS,OAAR,CAAgBC,aAAhB,CAA8B,MAA9B,EAAsC;AAAEC,IAAAA,OAAO,EAAE;AAAX,GAAtC,CAAD,CAAb;;AACA,MAAI,CAACJ,SAAL,EAAgB;AACZC,IAAAA,IAAI,CAACI,IAAL,CAAUZ,OAAO,CAACS,OAAR,CAAgBC,aAAhB,CAA8B,MAA9B,EAAsC;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AAhB,CAA8BP,aAAa,CAACuD,eAAd,CAA8BC,QAA5D,EAAsE,IAAtE,EAA4EC,QAAQ,IAAK5D,OAAO,CAACS,OAAR,CAAgBC,aAAhB,CAA8BN,sBAAsB,CAACyD,kBAAvB,CAA0CF,QAAxE,EAAkF,IAAlF,EAAwFG,UAAU,IAAK9D,OAAO,CAACS,OAAR,CAAgBC,aAAhB,CAA8B8C,MAA9B,EAAsC;AAAEO,IAAAA,uBAAuB,EAAEhB,gBAA3B;AAA6CiB,IAAAA,iBAAiB,EAAEF,UAAhE;AAA4EvD,IAAAA,SAAS,EAAEF,KAAK,CAAC4D,WAAN,CAAkBL,QAAlB;AAAvF,GAAtC,EAA4JpC,QAA5J,CAAvG,CAAzF,CAAR;AACH;;AACDiC,IAAI,CAACS,MAAL,GAAcV,MAAM,CAACU,MAArB;AACApE,OAAO,CAACW,OAAR,GAAkBgD,IAAlB","sourcesContent":["\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst react_1 = __importDefault(require(\"react\"));\nconst side_effect_1 = __importDefault(require(\"./side-effect\"));\nconst amp_context_1 = require(\"./amp-context\");\nconst head_manager_context_1 = require(\"./head-manager-context\");\nconst amp_1 = require(\"./amp\");\nfunction defaultHead(inAmpMode = false) {\n const head = [react_1.default.createElement(\"meta\", { charSet: \"utf-8\" })];\n if (!inAmpMode) {\n head.push(react_1.default.createElement(\"meta\", { name: \"viewport\", content: \"width=device-width,minimum-scale=1,initial-scale=1\" }));\n }\n return head;\n}\nexports.defaultHead = defaultHead;\nfunction onlyReactElement(list, child) {\n // React children can be \"string\" or \"number\" in this case we ignore them for backwards compat\n if (typeof child === 'string' || typeof child === 'number') {\n return list;\n }\n // Adds support for React.Fragment\n if (child.type === react_1.default.Fragment) {\n return list.concat(react_1.default.Children.toArray(child.props.children).reduce((fragmentList, fragmentChild) => {\n if (typeof fragmentChild === 'string' ||\n typeof fragmentChild === 'number') {\n return fragmentList;\n }\n return fragmentList.concat(fragmentChild);\n }, []));\n }\n return list.concat(child);\n}\nconst METATYPES = ['name', 'httpEquiv', 'charSet', 'itemProp'];\n/*\n returns a function for filtering head child elements\n which shouldn't be duplicated, like <title/>\n Also adds support for deduplicated `key` properties\n*/\nfunction unique() {\n const keys = new Set();\n const tags = new Set();\n const metaTypes = new Set();\n const metaCategories = {};\n return (h) => {\n let unique = true;\n if (h.key && typeof h.key !== 'number' && h.key.indexOf('$') > 0) {\n const key = h.key.slice(h.key.indexOf('$') + 1);\n if (keys.has(key)) {\n unique = false;\n }\n else {\n keys.add(key);\n }\n }\n // eslint-disable-next-line default-case\n switch (h.type) {\n case 'title':\n case 'base':\n if (tags.has(h.type)) {\n unique = false;\n }\n else {\n tags.add(h.type);\n }\n break;\n case 'meta':\n for (let i = 0, len = METATYPES.length; i < len; i++) {\n const metatype = METATYPES[i];\n if (!h.props.hasOwnProperty(metatype))\n continue;\n if (metatype === 'charSet') {\n if (metaTypes.has(metatype)) {\n unique = false;\n }\n else {\n metaTypes.add(metatype);\n }\n }\n else {\n const category = h.props[metatype];\n const categories = metaCategories[metatype] || new Set();\n if (categories.has(category)) {\n unique = false;\n }\n else {\n categories.add(category);\n metaCategories[metatype] = categories;\n }\n }\n }\n break;\n }\n return unique;\n };\n}\n/**\n *\n * @param headElement List of multiple <Head> instances\n */\nfunction reduceComponents(headElements, props) {\n return headElements\n .reduce((list, headElement) => {\n const headElementChildren = react_1.default.Children.toArray(headElement.props.children);\n return list.concat(headElementChildren);\n }, [])\n .reduce(onlyReactElement, [])\n .reverse()\n .concat(defaultHead(props.inAmpMode))\n .filter(unique())\n .reverse()\n .map((c, i) => {\n const key = c.key || i;\n return react_1.default.cloneElement(c, { key });\n });\n}\nconst Effect = side_effect_1.default();\n/**\n * This component injects elements to `<head>` of your page.\n * To avoid duplicated `tags` in `<head>` you can use the `key` property, which will make sure every tag is only rendered once.\n */\nfunction Head({ children }) {\n return (react_1.default.createElement(amp_context_1.AmpStateContext.Consumer, null, ampState => (react_1.default.createElement(head_manager_context_1.HeadManagerContext.Consumer, null, updateHead => (react_1.default.createElement(Effect, { reduceComponentsToState: reduceComponents, handleStateChange: updateHead, inAmpMode: amp_1.isInAmpMode(ampState) }, children))))));\n}\nHead.rewind = Effect.rewind;\nexports.default = Head;\n"]},"metadata":{},"sourceType":"script"}