{"version":3,"file":"preact-transition-group.mjs","sources":["../src/util.js","../src/TransitionChildMapping.js","../src/TransitionGroup.js"],"sourcesContent":["import { h } from 'preact';\n\nexport function assign(obj, props) {\n\tfor (let i in props) if (props.hasOwnProperty(i)) obj[i] = props[i];\n\treturn obj;\n}\n\nexport function getKey(vnode, fallback) {\n\tlet key = vnode && vnode.key;\n\treturn key===null || key===undefined ? fallback : key;\n}\n\nexport function linkRef(component, name) {\n\tlet cache = component._ptgLinkedRefs || (component._ptgLinkedRefs = {});\n\treturn cache[name] || (cache[name] = c => {\n\t\tcomponent.refs[name] = c;\n\t});\n}\n","/**\n * Copyright 2013-2014, 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 *\tAdditional credit to the Author of rc-css-transition-group: https://github.com/yiminghe\n *\tFile originally extracted from the React source, converted to ES6 by https://github.com/developit\n */\n\nimport { getKey } from './util';\n\n\nexport function getChildMapping(children) {\n\tlet out = {};\n\tfor (let i=0; i<children.length; i++) {\n\t\tif (children[i]!=null) {\n\t\t\tlet key = getKey(children[i], i.toString(36));\n\t\t\tout[key] = children[i];\n\t\t}\n\t}\n\treturn out;\n}\n\n\nexport function mergeChildMappings(prev, next) {\n\tprev = prev || {};\n\tnext = next || {};\n\n\tlet getValueForKey = key => next.hasOwnProperty(key) ? next[key] : prev[key];\n\n\t// For each key of `next`, the list of keys to insert before that key in\n\t// the combined list\n\tlet nextKeysPending = {};\n\n\tlet pendingKeys = [];\n\tfor (let prevKey in prev) {\n\t\tif (next.hasOwnProperty(prevKey)) {\n\t\t\tif (pendingKeys.length) {\n\t\t\t\tnextKeysPending[prevKey] = pendingKeys;\n\t\t\t\tpendingKeys = [];\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tpendingKeys.push(prevKey);\n\t\t}\n\t}\n\n\tlet childMapping = {};\n\tfor (let nextKey in next) {\n\t\tif (nextKeysPending.hasOwnProperty(nextKey)) {\n\t\t\tfor (let i=0; i<nextKeysPending[nextKey].length; i++) {\n\t\t\t\tlet pendingNextKey = nextKeysPending[nextKey][i];\n\t\t\t\tchildMapping[nextKeysPending[nextKey][i]] = getValueForKey(pendingNextKey);\n\t\t\t}\n\t\t}\n\t\tchildMapping[nextKey] = getValueForKey(nextKey);\n\t}\n\n\t// Finally, add the keys which didn't appear before any key in `next`\n\tfor (let i=0; i<pendingKeys.length; i++) {\n\t\tchildMapping[pendingKeys[i]] = getValueForKey(pendingKeys[i]);\n\t}\n\n\treturn childMapping;\n}\n","import { h, Component, cloneElement, toChildArray } from 'preact';\nimport { getChildMapping, mergeChildMappings } from './TransitionChildMapping';\nimport { assign, linkRef } from './util';\n\n\nconst identity = i => i;\n\nexport class TransitionGroup extends Component {\n\tconstructor(props, context) {\n\t\tsuper(props, context);\n\n\t\tthis.refs = {};\n\n\t\tthis.state = {\n\t\t\tchildren: getChildMapping(toChildArray(toChildArray(this.props.children)) || [])\n\t\t};\n\n\t\tthis.performAppear = this.performAppear.bind(this);\n\t\tthis.performEnter = this.performEnter.bind(this);\n\t\tthis.performLeave = this.performLeave.bind(this);\n\t}\n\n\tcomponentWillMount() {\n\t\tthis.currentlyTransitioningKeys = {};\n\t\tthis.keysToAbortLeave = [];\n\t\tthis.keysToEnter = [];\n\t\tthis.keysToLeave = [];\n\t}\n\n\tcomponentDidMount() {\n\t\tlet initialChildMapping = this.state.children;\n\t\tfor (let key in initialChildMapping) {\n\t\t\tif (initialChildMapping[key]) {\n\t\t\t\t// this.performAppear(getKey(initialChildMapping[key], key));\n\t\t\t\tthis.performAppear(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tcomponentWillReceiveProps(nextProps) {\n\t\tlet nextChildMapping = getChildMapping(toChildArray(nextProps.children) || []);\n\t\tlet prevChildMapping = this.state.children;\n\n\t\tthis.setState(prevState => ({\n\t\t\tchildren: mergeChildMappings(prevState.children, nextChildMapping)\n\t\t}));\n\n\t\tlet key;\n\n\t\tfor (key in nextChildMapping) if (nextChildMapping.hasOwnProperty(key)) {\n\t\t\tlet hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key);\n\t\t\t// We should re-enter the component and abort its leave function\n\t\t\tif (nextChildMapping[key] && hasPrev && this.currentlyTransitioningKeys[key]) {\n\t\t\t\tthis.keysToEnter.push(key);\n\t\t\t\tthis.keysToAbortLeave.push(key);\n\t\t\t}\n\t\t\telse if (nextChildMapping[key] && !hasPrev && !this.currentlyTransitioningKeys[key]) {\n\t\t\t\tthis.keysToEnter.push(key);\n\t\t\t}\n\t\t}\n\n\t\tfor (key in prevChildMapping) if (prevChildMapping.hasOwnProperty(key)) {\n\t\t\tlet hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key);\n\t\t\tif (prevChildMapping[key] && !hasNext && !this.currentlyTransitioningKeys[key]) {\n\t\t\t\tthis.keysToLeave.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tcomponentDidUpdate() {\n\t\tlet keysToEnter = this.keysToEnter;\n\t\tthis.keysToEnter = [];\n\t\tkeysToEnter.forEach(this.performEnter);\n\n\t\tlet keysToLeave = this.keysToLeave;\n\t\tthis.keysToLeave = [];\n\t\tkeysToLeave.forEach(this.performLeave);\n\t}\n\n\t_finishAbort(key) {\n\t\tconst idx = this.keysToAbortLeave.indexOf(key);\n\t\tif (idx !== -1) {\n\t\t\tthis.keysToAbortLeave.splice(idx, 1);\n\t\t}\n\t}\n\n\tperformAppear(key) {\n\t\tthis.currentlyTransitioningKeys[key] = true;\n\n\t\tlet component = this.refs[key];\n\n\t\tif (component.componentWillAppear) {\n\t\t\tcomponent.componentWillAppear(this._handleDoneAppearing.bind(this, key));\n\t\t}\n\t\telse {\n\t\t\tthis._handleDoneAppearing(key);\n\t\t}\n\t}\n\n\t_handleDoneAppearing(key) {\n\t\tlet component = this.refs[key];\n\t\tif (component.componentDidAppear) {\n\t\t\tcomponent.componentDidAppear();\n\t\t}\n\n\t\tdelete this.currentlyTransitioningKeys[key];\n\t\tthis._finishAbort(key);\n\n\t\tlet currentChildMapping = getChildMapping(toChildArray(this.props.children) || []);\n\n\t\tif (!currentChildMapping || !currentChildMapping.hasOwnProperty(key)) {\n\t\t\t// This was removed before it had fully appeared. Remove it.\n\t\t\tthis.performLeave(key);\n\t\t}\n\t}\n\n\tperformEnter(key) {\n\t\tthis.currentlyTransitioningKeys[key] = true;\n\n\t\tlet component = this.refs[key];\n\n\t\tif (component.componentWillEnter) {\n\t\t\tcomponent.componentWillEnter(this._handleDoneEntering.bind(this, key));\n\t\t}\n\t\telse {\n\t\t\tthis._handleDoneEntering(key);\n\t\t}\n\t}\n\n\t_handleDoneEntering(key) {\n\t\tlet component = this.refs[key];\n\t\tif (component.componentDidEnter) {\n\t\t\tcomponent.componentDidEnter();\n\t\t}\n\n\t\tdelete this.currentlyTransitioningKeys[key];\n\t\tthis._finishAbort(key);\n\n\t\tlet currentChildMapping = getChildMapping(toChildArray(this.props.children) || []);\n\n\t\tif (!currentChildMapping || !currentChildMapping.hasOwnProperty(key)) {\n\t\t\t// This was removed before it had fully entered. Remove it.\n\t\t\tthis.performLeave(key);\n\t\t}\n\t}\n\n\tperformLeave(key) {\n\t\t// If we should immediately abort this leave function,\n\t\t// don't run the leave transition at all.\n\t\tconst idx = this.keysToAbortLeave.indexOf(key);\n\t\tif (idx !== -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentlyTransitioningKeys[key] = true;\n\n\t\tlet component = this.refs[key];\n\t\tif (component.componentWillLeave) {\n\t\t\tcomponent.componentWillLeave(this._handleDoneLeaving.bind(this, key));\n\t\t}\n\t\telse {\n\t\t\t// Note that this is somewhat dangerous b/c it calls setState()\n\t\t\t// again, effectively mutating the component before all the work\n\t\t\t// is done.\n\t\t\tthis._handleDoneLeaving(key);\n\t\t}\n\t}\n\n\t_handleDoneLeaving(key) {\n\t\t// If we should immediately abort the leave,\n\t\t// then skip this altogether\n\t\tconst idx = this.keysToAbortLeave.indexOf(key);\n\t\tif (idx !== -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet component = this.refs[key];\n\n\t\tif (component.componentDidLeave) {\n\t\t\tcomponent.componentDidLeave();\n\t\t}\n\n\t\tdelete this.currentlyTransitioningKeys[key];\n\n\t\tlet currentChildMapping = getChildMapping(toChildArray(this.props.children) || []);\n\n\t\tif (currentChildMapping && currentChildMapping.hasOwnProperty(key)) {\n\t\t\t// This entered again before it fully left. Add it again.\n\t\t\tthis.performEnter(key);\n\t\t}\n\t\telse {\n\t\t\tlet children = assign({}, this.state.children);\n\t\t\tdelete children[key];\n\t\t\tthis.setState({ children });\n\t\t}\n\t}\n\n\trender({ childFactory, transitionLeave, transitionName, transitionAppear, transitionEnter, transitionLeaveTimeout, transitionEnterTimeout, transitionAppearTimeout, component, ...props }, { children }) {\n\t\t// TODO: we could get rid of the need for the wrapper node\n\t\t// by cloning a single child\n\t\tlet childrenToRender = [];\n\t\tfor (let key in children) if (children.hasOwnProperty(key)) {\n\t\t\tlet child = children[key];\n\t\t\tif (child) {\n\t\t\t\tlet ref = linkRef(this, key),\n\t\t\t\t\tel = cloneElement(childFactory(child), { ref, key });\n\t\t\t\tchildrenToRender.push(el);\n\t\t\t}\n\t\t}\n\n\t\treturn h(component, props, childrenToRender);\n\t}\n}\n\nTransitionGroup.defaultProps = {\n\tcomponent: 'span',\n\tchildFactory: identity\n};\n"],"names":["linkRef","component","name","cache","_ptgLinkedRefs","c","refs","getChildMapping","children","out","i","length","vnode","fallback","toString","key","mergeChildMappings","prev","next","getValueForKey","hasOwnProperty","nextKeysPending","pendingKeys","prevKey","push","childMapping","nextKey","TransitionGroup","props","context","_this","state","toChildArray","performAppear","bind","performEnter","performLeave","componentWillMount","this","currentlyTransitioningKeys","keysToAbortLeave","keysToEnter","keysToLeave","componentDidMount","initialChildMapping","componentWillReceiveProps","nextProps","nextChildMapping","prevChildMapping","setState","prevState","hasPrev","hasNext","componentDidUpdate","forEach","_finishAbort","idx","indexOf","splice","componentWillAppear","_handleDoneAppearing","componentDidAppear","currentChildMapping","componentWillEnter","_handleDoneEntering","componentDidEnter","componentWillLeave","_handleDoneLeaving","componentDidLeave","obj","assign","render","childFactory","childrenToRender","child","ref","el","cloneElement","h","Component","defaultProps"],"mappings":"kNAYgBA,EAAQC,EAAWC,GAClC,IAAIC,EAAQF,EAAUG,IAAmBH,EAAUG,EAAiB,IACpE,OAAOD,EAAMD,KAAUC,EAAMD,GAAQ,SAAAG,GACpCJ,EAAUK,KAAKJ,GAAQG,aCATE,EAAgBC,GAE/B,IADA,IAAIC,EAAM,GACDC,EAAE,EAAGA,EAAEF,EAASG,OAAQD,IACf,MAAbF,EAASE,KAEZD,GDboBG,ECYHJ,EAASE,GDZCG,ECYGH,EAAEI,SAAS,SDXvCC,EAAAA,EAAMH,GAASA,EAAMG,IAClBA,MAAAA,EAAgCF,EAAWE,ICWrCP,EAASE,QDbAE,EAAOC,EACzBE,ECeJ,OAAON,EAIR,SAAgBO,EAAmBC,EAAMC,GACxCD,EAAOA,GAAQ,GACfC,EAAOA,GAAQ,GAEf,IAAIC,EAAiB,SAAAJ,UAAOG,EAAKE,eAAeL,GAAOG,EAAKH,GAAOE,EAAKF,IAIpEM,EAAkB,GAElBC,EAAc,GAClB,IAAK,IAAIC,KAAWN,EACfC,EAAKE,eAAeG,GACnBD,EAAYX,SACfU,EAAgBE,GAAWD,EAC3BA,EAAc,IAIfA,EAAYE,KAAKD,GAInB,IAAIE,EAAe,GACnB,IAAK,IAAIC,KAAWR,EAAM,CACzB,GAAIG,EAAgBD,eAAeM,GAClC,IAAK,IAAIhB,EAAE,EAAGA,EAAEW,EAAgBK,GAASf,OAAQD,IAEhDe,EAAaJ,EAAgBK,GAAShB,IAAMS,EADvBE,EAAgBK,GAAShB,IAIhDe,EAAaC,GAAWP,EAAeO,GAIxC,IAAK,IAAIhB,EAAE,EAAGA,EAAEY,EAAYX,OAAQD,IACnCe,EAAaH,EAAYZ,IAAMS,EAAeG,EAAYZ,IAG3D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