UNPKG

rn-web-cli

Version:

React Native for Web

1 lines 10.9 kB
{"version":3,"sources":["node_modules\\react-dom\\lib\\ReactDOMComponentTree.js"],"names":["_prodInvariant","require","DOMProperty","ReactDOMComponentFlags","invariant","ATTR_NAME","ID_ATTRIBUTE_NAME","Flags","internalInstanceKey","Math","random","toString","slice","shouldPrecacheNode","node","nodeID","nodeType","getAttribute","String","nodeValue","getRenderedHostOrTextFromComponent","component","rendered","_renderedComponent","precacheNode","inst","hostInst","_hostNode","uncacheNode","precacheChildNodes","_flags","hasCachedChildNodes","children","_renderedChildren","childNode","firstChild","outer","name","hasOwnProperty","childInst","childID","_domID","nextSibling","process","env","NODE_ENV","getClosestInstanceFromNode","parents","push","parentNode","closest","pop","length","getInstanceFromNode","getNodeFromInstance","undefined","_hostParent","ReactDOMComponentTree","module","exports"],"mappings":";;;;;;;;;;AAUA;;AAEA,GAAIA,gBAAiBC,QAAQ,sBAAR,CAArB;;AAEA,GAAIC,aAAcD,QAAQ,eAAR,CAAlB;AACA,GAAIE,wBAAyBF,QAAQ,0BAAR,CAA7B;;AAEA,GAAIG,WAAYH,QAAQ,oBAAR,CAAhB;;AAEA,GAAII,WAAYH,YAAYI,iBAA5B;AACA,GAAIC,OAAQJ,sBAAZ;;AAEA,GAAIK,qBAAsB,2BAA6BC,KAAKC,MAAL,GAAcC,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAvD;;;;;AAKA,QAASC,mBAAT,CAA4BC,IAA5B,CAAkCC,MAAlC,CAA0C;AACxC,MAAOD,MAAKE,QAAL,GAAkB,CAAlB,EAAuBF,KAAKG,YAAL,CAAkBZ,SAAlB,IAAiCa,OAAOH,MAAP,CAAxD,EAA0ED,KAAKE,QAAL,GAAkB,CAAlB,EAAuBF,KAAKK,SAAL,GAAmB,gBAAkBJ,MAAlB,CAA2B,GAA/I,EAAsJD,KAAKE,QAAL,GAAkB,CAAlB,EAAuBF,KAAKK,SAAL,GAAmB,iBAAmBJ,M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AwCzC,UAAU,KAAV,CAAiB,wCAAjB,CAAxC,CAAqGJ,eAAe,IAAf,CAAvI,CAA8J,IAAK,EAAnK;;AAEA,GAAIyB,KAAKE,SAAT,CAAoB;AAClB,MAAOF,MAAKE,SAAZ;AACD;;;AAGD,GAAIoB,SAAU,EAAd;AACA,MAAO,CAACtB,KAAKE,SAAb,CAAwB;AACtBoB,QAAQC,IAAR,CAAavB,IAAb;AACA,CAACA,KAAK+B,WAAN,CAAoBb,QAAQC,GAAR,CAAYC,QAAZ,GAAyB,YAAzB,CAAwCzC,UAAU,KAAV,CAAiB,0DAAjB,CAAxC,CAAuHJ,eAAe,IAAf,CAA3I,CAAkK,IAAK,EAAvK;AACAyB,KAAOA,KAAK+B,WAAZ;AACD;;;;AAID,KAAOT,QAAQK,MAAf,CAAuB3B,KAAOsB,QAAQI,GAAR,EAA9B,CAA6C;AAC3CtB,mBAAmBJ,IAAnB,CAAyBA,KAAKE,SAA9B;AACD;;AAED,MAAOF,MAAKE,SAAZ;AACD;;AAED,GAAI8B,uBAAwB;AAC1BX,2BAA4BA,0BADF;AAE1BO,oBAAqBA,mBAFK;AAG1BC,oBAAqBA,mBAHK;AAI1BzB,mBAAoBA,kBAJM;AAK1BL,aAAcA,YALY;AAM1BI,YAAaA,WANa,CAA5B;;;AASA8B,OAAOC,OAAP,CAAiBF,qBAAjB","file":"ReactDOMComponentTree.js","sourceRoot":"d:/Work/Office/react-native-on-web/cli/tmpl/project","sourcesContent":["/**\n * Copyright 2013-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n *\n */\n\n'use strict';\n\nvar _prodInvariant = require('./reactProdInvariant');\n\nvar DOMProperty = require('./DOMProperty');\nvar ReactDOMComponentFlags = require('./ReactDOMComponentFlags');\n\nvar invariant = require('fbjs/lib/invariant');\n\nvar ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;\nvar Flags = ReactDOMComponentFlags;\n\nvar internalInstanceKey = '__reactInternalInstance$' + Math.random().toString(36).slice(2);\n\n/**\n * Check if a given node should be cached.\n */\nfunction shouldPrecacheNode(node, nodeID) {\n return node.nodeType === 1 && node.getAttribute(ATTR_NAME) === String(nodeID) || node.nodeType === 8 && node.nodeValue === ' react-text: ' + nodeID + ' ' || node.nodeType === 8 && node.nodeValue === ' react-empty: ' + nodeID + ' ';\n}\n\n/**\n * Drill down (through composites and empty components) until we get a host or\n * host text component.\n *\n * This is pretty polymorphic but unavoidable with the current structure we have\n * for `_renderedChildren`.\n */\nfunction getRenderedHostOrTextFromComponent(component) {\n var rendered;\n while (rendered = component._renderedComponent) {\n component = rendered;\n }\n return component;\n}\n\n/**\n * Populate `_hostNode` on the rendered host/text component with the given\n * DOM node. The passed `inst` can be a composite.\n */\nfunction precacheNode(inst, node) {\n var hostInst = getRenderedHostOrTextFromComponent(inst);\n hostInst._hostNode = node;\n node[internalInstanceKey] = hostInst;\n}\n\nfunction uncacheNode(inst) {\n var node = inst._hostNode;\n if (node) {\n delete node[internalInstanceKey];\n inst._hostNode = null;\n }\n}\n\n/**\n * Populate `_hostNode` on each child of `inst`, assuming that the children\n * match up with the DOM (element) children of `node`.\n *\n * We cache entire levels at once to avoid an n^2 problem where we access the\n * children of a node sequentially and have to walk from the start to our target\n * node every time.\n *\n * Since we update `_renderedChildren` and the actual DOM at (slightly)\n * different times, we could race here and see a newer `_renderedChildren` than\n * the DOM nodes we see. To avoid this, ReactMultiChild calls\n * `prepareToManageChildren` before we change `_renderedChildren`, at which\n * time the container's child nodes are always cached (until it unmounts).\n */\nfunction precacheChildNodes(inst, node) {\n if (inst._flags & Flags.hasCachedChildNodes) {\n return;\n }\n var children = inst._renderedChildren;\n var childNode = node.firstChild;\n outer: for (var name in children) {\n if (!children.hasOwnProperty(name)) {\n continue;\n }\n var childInst = children[name];\n var childID = getRenderedHostOrTextFromComponent(childInst)._domID;\n if (childID === 0) {\n // We're currently unmounting this child in ReactMultiChild; skip it.\n continue;\n }\n // We assume the child nodes are in the same order as the child instances.\n for (; childNode !== null; childNode = childNode.nextSibling) {\n if (shouldPrecacheNode(childNode, childID)) {\n precacheNode(childInst, childNode);\n continue outer;\n }\n }\n // We reached the end of the DOM children without finding an ID match.\n !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unable to find element with ID %s.', childID) : _prodInvariant('32', childID) : void 0;\n }\n inst._flags |= Flags.hasCachedChildNodes;\n}\n\n/**\n * Given a DOM node, return the closest ReactDOMComponent or\n * ReactDOMTextComponent instance ancestor.\n */\nfunction getClosestInstanceFromNode(node) {\n if (node[internalInstanceKey]) {\n return node[internalInstanceKey];\n }\n\n // Walk up the tree until we find an ancestor whose instance we have cached.\n var parents = [];\n while (!node[internalInstanceKey]) {\n parents.push(node);\n if (node.parentNode) {\n node = node.parentNode;\n } else {\n // Top of the tree. This node must not be part of a React tree (or is\n // unmounted, potentially).\n return null;\n }\n }\n\n var closest;\n var inst;\n for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) {\n closest = inst;\n if (parents.length) {\n precacheChildNodes(inst, node);\n }\n }\n\n return closest;\n}\n\n/**\n * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent\n * instance, or null if the node was not rendered by this React.\n */\nfunction getInstanceFromNode(node) {\n var inst = getClosestInstanceFromNode(node);\n if (inst != null && inst._hostNode === node) {\n return inst;\n } else {\n return null;\n }\n}\n\n/**\n * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding\n * DOM node.\n */\nfunction getNodeFromInstance(inst) {\n // Without this first invariant, passing a non-DOM-component triggers the next\n // invariant for a missing parent, which is super confusing.\n !(inst._hostNode !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;\n\n if (inst._hostNode) {\n return inst._hostNode;\n }\n\n // Walk up the tree until we find an ancestor whose DOM node we have cached.\n var parents = [];\n while (!inst._hostNode) {\n parents.push(inst);\n !inst._hostParent ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React DOM tree root should always have a node reference.') : _prodInvariant('34') : void 0;\n inst = inst._hostParent;\n }\n\n // Now parents contains each ancestor that does *not* have a cached native\n // node, and `inst` is the deepest ancestor that does.\n for (; parents.length; inst = parents.pop()) {\n precacheChildNodes(inst, inst._hostNode);\n }\n\n return inst._hostNode;\n}\n\nvar ReactDOMComponentTree = {\n getClosestInstanceFromNode: getClosestInstanceFromNode,\n getInstanceFromNode: getInstanceFromNode,\n getNodeFromInstance: getNodeFromInstance,\n precacheChildNodes: precacheChildNodes,\n precacheNode: precacheNode,\n uncacheNode: uncacheNode\n};\n\nmodule.exports = ReactDOMComponentTree;"]}