UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 2.03 kB
{"version":3,"file":"children.js","names":[],"sources":["esm/utils/children.js"],"sourcesContent":["import {\n isValidElement\n} from \"react\";\nfunction isChildOfType(element, type) {\n return isValidElement(element) && element.type === type;\n}\nfunction getFirstChildOfType(children, type) {\n const childArray = Array.isArray(children) ? children : [children];\n for (const child of childArray) {\n if (isChildOfType(child, type)) {\n return child;\n }\n }\n return void 0;\n}\nfunction getAllChildrenOfType(children, type) {\n const childArray = Array.isArray(children) ? children : [children];\n return childArray.filter(\n (child) => isChildOfType(child, type)\n );\n}\nfunction getAllChildrenNotOfType(children, type) {\n const childArray = Array.isArray(children) ? children : [children];\n return childArray.filter((child) => !isChildOfType(child, type));\n}\nfunction filterAllowedChildrenElements(children, allowedTypes) {\n const childArray = Array.isArray(children) ? children : [children];\n return childArray.filter(\n (child) => isValidElement(child) && allowedTypes.some((type) => child.type === type)\n );\n}\nexport {\n filterAllowedChildrenElements,\n getAllChildrenNotOfType,\n getAllChildrenOfType,\n getFirstChildOfType,\n isChildOfType\n};\n//# sourceMappingURL=children.js.map\n"],"mappings":";;;AAGA,SAAS,cAAc,SAAS,MAAM;CACpC,OAAO,eAAe,OAAO,KAAK,QAAQ,SAAS;AACrD;AACA,SAAS,oBAAoB,UAAU,MAAM;CAC3C,MAAM,aAAa,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;CACjE,KAAK,MAAM,SAAS,YAAY;EAC9B,IAAI,cAAc,OAAO,IAAI,GAAG;GAC9B,OAAO;EACT;CACF;CACA,OAAO,KAAK;AACd;AACA,SAAS,qBAAqB,UAAU,MAAM;CAC5C,MAAM,aAAa,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;CACjE,OAAO,WAAW,QACf,UAAU,cAAc,OAAO,IAAI,CACtC;AACF;AACA,SAAS,wBAAwB,UAAU,MAAM;CAC/C,MAAM,aAAa,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;CACjE,OAAO,WAAW,QAAQ,UAAU,CAAC,cAAc,OAAO,IAAI,CAAC;AACjE;AACA,SAAS,8BAA8B,UAAU,cAAc;CAC7D,MAAM,aAAa,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;CACjE,OAAO,WAAW,QACf,UAAU,eAAe,KAAK,KAAK,aAAa,MAAM,SAAS,MAAM,SAAS,IAAI,CACrF;AACF"}