{"id":19521251,"url":"https://github.com/x-kom/component-trace-element-finder","last_synced_at":"2025-07-29T01:37:40.640Z","repository":{"id":57204816,"uuid":"170687837","full_name":"x-kom/component-trace-element-finder","owner":"x-kom","description":"Simple helper functions for finding DOM elements through \"component trace\"","archived":false,"fork":false,"pushed_at":"2019-02-18T15:11:31.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T20:50:26.524Z","etag":null,"topics":["data-attributes","dom-selection","html","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/x-kom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-14T12:28:21.000Z","updated_at":"2021-03-06T14:30:38.000Z","dependencies_parsed_at":"2022-09-18T00:42:06.872Z","dependency_job_id":null,"html_url":"https://github.com/x-kom/component-trace-element-finder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/x-kom/component-trace-element-finder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-kom%2Fcomponent-trace-element-finder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-kom%2Fcomponent-trace-element-finder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-kom%2Fcomponent-trace-element-finder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-kom%2Fcomponent-trace-element-finder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x-kom","download_url":"https://codeload.github.com/x-kom/component-trace-element-finder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-kom%2Fcomponent-trace-element-finder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267616844,"owners_count":24116169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-attributes","dom-selection","html","testing"],"created_at":"2024-11-11T00:30:05.852Z","updated_at":"2025-07-29T01:37:40.613Z","avatar_url":"https://github.com/x-kom.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# component-trace-element-finder\nSimple functions that help finding DOM elements through \"component trace\".\n\n### React - babel plugin\nTo get it working you can simply use [babel-plugin-react-component-trace-data-attr](https://github.com/x-kom/babel-plugin-react-component-trace-data-attr) with default `separator` and `attribute` options.\n\n### Manual usage\nYou can also manually add `data-component-trace` attributes to your dom elements and separate the component names using single space.\n\n## API\n| Method name | Description |\n|-------------|-------------|\n| **`findAllComponentsByTrace`**\u003cbr\u003e\u003ccode\u003e(name: string, parent?: Element \u0026#124; Document)\u003c/code\u003e | Returns all elements that have `name` in their trace. Use `parent` to search only within the given element. |\n| **`findTopComponentsByTrace`**\u003cbr\u003e\u003ccode\u003e(name: string, parent?: Element \u0026#124; Document)\u003c/code\u003e | Returns all elements that have `name` in their trace but **are not contained** within elements that have `name` in their trace too. Use `parent` to search only within the given element. |\n\n## Example\nConsider the following HTML markup\n```html\n\u003ch1 data-component-trace=\"component second-component header-of-component\"\u003e\n  \u003cspan data-component-trace=\"component second-component header-of-component icon\"\u003e\n    🌠\n  \u003cspan\u003e\n  Witness me\n\u003c/h1\u003e\n\u003cdiv data-component-trace=\"component second-component content-of-component\"\u003e\n  \u003cspan data-component-trace=\"component second-component content-of-component icon\"\u003e\n    💥\n  \u003cspan\u003e\n  What a day, what a lovely day!\n\u003c/div\u003e\n```\n\nIf you call \n```js\nfindAllComponentsByTrace('second-component')\n```\nyou will get a set with all shown elements: `h1`, `div` and two `span`s. However when you change the function to \n```js\nfindTopComponentsByTrace('second-component')\n```\nyou will get only `h1` and `div`, since `span`s are inside the `h1`/`div` and thus are not considered a \"top\" component here.\n\nYou can use parent to search for an element iside any other given element\n```js\nconst header = findTopComponentsByTrace('header-of-component');\nconst iconInHeader = findTopComponentsByTrace('icon', header[0]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-kom%2Fcomponent-trace-element-finder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx-kom%2Fcomponent-trace-element-finder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-kom%2Fcomponent-trace-element-finder/lists"}