UNPKG

3.56 kBSource Map (JSON)View Raw
1{"version":3,"file":"elem.js","sources":["../../src/elem.js"],"sourcesContent":["import {select} from \"d3-selection\";\nimport {transition} from \"d3-transition\";\n\nimport {default as attrize} from \"./attrize\";\n\n/**\n @function elem\n @desc Manages the enter/update/exit pattern for a single DOM element.\n @param {String} selector A D3 selector, which must include the tagname and a class and/or ID.\n @param {Object} params Additional parameters.\n @param {Boolean} [params.condition = true] Whether or not the element should be rendered (or removed).\n @param {Object} [params.enter = {}] A collection of key/value pairs that map to attributes to be given on enter.\n @param {Object} [params.exit = {}] A collection of key/value pairs that map to attributes to be given on exit.\n @param {D3Selection} [params.parent = d3.select(\"body\")] The parent element for this new element to be appended to.\n @param {D3Transition} [params.transition = d3.transition().duration(0)] The transition to use when animated the different life cycle stages.\n @param {Object} [params.update = {}] A collection of key/value pairs that map to attributes to be given on update.\n*/\nexport default function(selector, p) {\n\n // overrides default params\n p = Object.assign({}, {\n condition: true,\n enter: {},\n exit: {},\n parent: select(\"body\"),\n transition: transition().duration(0),\n update: {}\n }, p);\n\n const className = (/\\.([^#]+)/g).exec(selector),\n id = (/#([^\\.]+)/g).exec(selector),\n tag = (/^([^.^#]+)/g).exec(selector)[1];\n\n const elem = p.parent.selectAll(selector.includes(\":\") ? selector.split(\":\")[1] : selector)\n .data(p.condition ? [null] : []);\n\n const enter = elem.enter().append(tag).call(attrize, p.enter);\n\n if (id) enter.attr(\"id\", id[1]);\n if (className) enter.attr(\"class\", className[1]);\n\n elem.exit().transition(p.transition).call(attrize, p.exit).remove();\n\n const update = enter.merge(elem);\n update.transition(p.transition).call(attrize, p.update);\n\n return update;\n\n}\n"],"names":["const"],"mappings":"AAAA,QAAQ,MAAM,OAAO,cAAc,CAAC;AACpC,QAAQ,UAAU,OAAO,eAAe,CAAC;;AAEzC,QAAQ,OAAO,IAAI,OAAO,OAAO,WAAW,CAAC;;;;;;;;;;;;;;AAc7C,eAAe,SAAS,QAAQ,EAAE,CAAC,EAAE;;;EAGn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